Skip to content

Commit 9c90a73

Browse files
authored
fix(es/codegen): Fix source map so it works with Sentry (#9627)
**Description:** Fix web-infra-dev/rspack#7914 The following mapping is redundant and causes an error on Sentry. ![image](https://github.com/user-attachments/assets/0d3067d9-6adb-4434-aa84-6ed73a71fdad) ``` Your source map refers to generated column 79 on line 1, but the source only contains 78 column(s) on that line. ```
1 parent 6e7a009 commit 9c90a73

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

.changeset/wise-laws-wash.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_ecma_codegen: patch
4+
---
5+
6+
fix: source map is not working on Sentry

crates/swc/tests/fixture/sourcemap/issue-9567/output/index.map

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"mappings": "AAAA,SAASA,EAAIC,CAAI,CAAEC,CAAK,EACtBD,EAAKE,SAAS,CAAC,CACXC,QAAS,CAAC,EAAEF,EAAME,OAAO,CAAC,CAAC,EACvBF,EAAMG,IAAI,CACJ,CAAC;AAAE;AAAS;AAC5B;AAAS;AACT;AAAI,GAAG,EAAEH,EAAMG,IAAI,CAAC,CAAC,CACL,QACT,CAAC,AACN,EACF,CACAL",
2+
"mappings": "AAAA,SAASA,EAAIC,CAAI,CAAEC,CAAK,EACtBD,EAAKE,SAAS,CAAC,CACXC,QAAS,CAAC,EAAEF,EAAME,OAAO,CAAC,CAAC,EACvBF,EAAMG,IAAI,CACJ;AAAG;AAAS;AAC5B;AAAS;AACT;AAAI,GAAG,EAAEH,EAAMG,IAAI,CAAC,CAAC,CACL,QACT,CAAC,AACN,EACF,CACAL",
33
"names": [
44
"foo",
55
"span",

crates/swc_ecma_codegen/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,8 +1994,13 @@ where
19941994
.match_indices('\n')
19951995
.zip(NEW_LINE_TPL_REGEX.find_iter(&raw))
19961996
{
1997-
self.wr
1998-
.add_srcmap(span.lo + BytePos(last_offset_origin as u32))?;
1997+
// If the string starts with a newline char, then adding a mark is redundant.
1998+
// This catches both "no newlines" and "newline after several chars".
1999+
if offset_gen != 0 {
2000+
self.wr
2001+
.add_srcmap(span.lo + BytePos(last_offset_origin as u32))?;
2002+
}
2003+
19992004
self.wr
20002005
.write_str_lit(DUMMY_SP, &v[last_offset_gen..=offset_gen])?;
20012006
last_offset_gen = offset_gen + 1;

0 commit comments

Comments
 (0)