diff --git a/.changeset/wise-laws-wash.md b/.changeset/wise-laws-wash.md new file mode 100644 index 000000000000..815606239bb9 --- /dev/null +++ b/.changeset/wise-laws-wash.md @@ -0,0 +1,6 @@ +--- +swc_core: patch +swc_ecma_codegen: patch +--- + +fix: source map is not working on Sentry diff --git a/crates/swc/tests/fixture/sourcemap/issue-9567/output/index.map b/crates/swc/tests/fixture/sourcemap/issue-9567/output/index.map index 0b0ff1d58ccc..9152b11c11d6 100644 --- a/crates/swc/tests/fixture/sourcemap/issue-9567/output/index.map +++ b/crates/swc/tests/fixture/sourcemap/issue-9567/output/index.map @@ -1,5 +1,5 @@ { - "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", + "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", "names": [ "foo", "span", diff --git a/crates/swc_ecma_codegen/src/lib.rs b/crates/swc_ecma_codegen/src/lib.rs index a522f52b7b35..aa5593bac69a 100644 --- a/crates/swc_ecma_codegen/src/lib.rs +++ b/crates/swc_ecma_codegen/src/lib.rs @@ -1994,8 +1994,13 @@ where .match_indices('\n') .zip(NEW_LINE_TPL_REGEX.find_iter(&raw)) { - self.wr - .add_srcmap(span.lo + BytePos(last_offset_origin as u32))?; + // If the string starts with a newline char, then adding a mark is redundant. + // This catches both "no newlines" and "newline after several chars". + if offset_gen != 0 { + self.wr + .add_srcmap(span.lo + BytePos(last_offset_origin as u32))?; + } + self.wr .write_str_lit(DUMMY_SP, &v[last_offset_gen..=offset_gen])?; last_offset_gen = offset_gen + 1;