Skip to content

Commit cbee0df

Browse files
authored
fix(swc_common): Fix skip condition for sourcemap (#10562)
**Description:** We don't generate `BytePos(0)`, so it was not a big deal for us, but now it matters because external crates are now allowed to generate `BytePos`
1 parent 6ee6974 commit cbee0df

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

.changeset/moody-cows-sleep.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_core: patch
3+
swc_common: patch
4+
---
5+
6+
fix(swc_common): Fix skip condition for sourcemap

crates/swc_common/src/source_map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,16 +1284,16 @@ pub fn build_source_map(
12841284
let mut ch_state = ByteToCharPosState::default();
12851285
let mut line_state = ByteToCharPosState::default();
12861286

1287-
for (orig_pos, lc) in mappings.iter() {
1288-
let pos = files.map_raw_pos(*orig_pos);
1287+
for (raw_pos, lc) in mappings.iter() {
1288+
let pos = files.map_raw_pos(*raw_pos);
12891289

12901290
if pos.is_reserved_for_comments() {
12911291
continue;
12921292
}
12931293

12941294
let lc = *lc;
12951295

1296-
// If pos is same as a DUMMY_SP (eg BytePos(0)) and if line and col are 0;
1296+
// If pos is same as a DUMMY_SP (eg BytePos(0)) or if line and col are 0,
12971297
// ignore the mapping.
12981298
if lc.line == 0 && lc.col == 0 && pos.is_dummy() {
12991299
continue;
@@ -1308,7 +1308,7 @@ pub fn build_source_map(
13081308
let f = match cur_file {
13091309
Some(ref f) if f.start_pos <= pos && pos < f.end_pos => f,
13101310
_ => {
1311-
f = files.try_lookup_source_file(*orig_pos).unwrap();
1311+
f = files.try_lookup_source_file(*raw_pos).unwrap();
13121312
if config.skip(&f.name) {
13131313
continue;
13141314
}

0 commit comments

Comments
 (0)