Skip to content

Commit

Permalink
fix(es/codegen): Fix source map so it works with Sentry (#9627)
Browse files Browse the repository at this point in the history
**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.
```
  • Loading branch information
SyMind authored Oct 10, 2024
1 parent 6e7a009 commit 9c90a73
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/wise-laws-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_core: patch
swc_ecma_codegen: patch
---

fix: source map is not working on Sentry
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 7 additions & 2 deletions crates/swc_ecma_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9c90a73

Please sign in to comment.