Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**Description:** This fixes the BytePos -> CharPos calculation necessary for source maps. There were a few issues in the old code: 1. UTF-8 maps 1-3 bytes into 1 UTF-16 char, but 4 bytes into 2 UTF-16 chars 2. The starting offset was not recorded when we reached the end of the `multibyte_chars` iteration 3. The `mappings` can be unordered, meaning we need to restart the UTF-16 offset calculation **Related issue:** - Closes #6552.
- Loading branch information
1 parent
8bee06f
commit a203fdb
Showing
11 changed files
with
243 additions
and
61 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
crates/swc/tests/fixture/sourcemap/issue-6552/input-map/input/.swcrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"sourceMaps": true, | ||
"jsc": { | ||
"parser": { | ||
"syntax": "ecmascript", | ||
"jsx": false | ||
}, | ||
"target": "es5", | ||
"loose": false, | ||
"minify": { | ||
"compress": false, | ||
"mangle": false | ||
} | ||
}, | ||
"module": { | ||
"type": "commonjs" | ||
}, | ||
"minify": true, | ||
"isModule": true | ||
} |
4 changes: 4 additions & 0 deletions
4
crates/swc/tests/fixture/sourcemap/issue-6552/input-map/input/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
crates/swc/tests/fixture/sourcemap/issue-6552/input-map/output/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"use strict";var xxx=", something";console.error("❌ ".concat(message));var bbb=""; |
17 changes: 17 additions & 0 deletions
17
crates/swc/tests/fixture/sourcemap/issue-6552/input-map/output/index.map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"mappings": "AAAA,aAAA,IAAMA,IAAM,cACZC,QAAQC,KAAK,CAAC,AAAC,KAAY,OAARC,UACnB,IAAMC,IAAM", | ||
"names": [ | ||
"xxx", | ||
"console", | ||
"error", | ||
"message", | ||
"bbb" | ||
], | ||
"sources": [ | ||
"../../input/index.js" | ||
], | ||
"sourcesContent": [ | ||
"const xxx = ', something';\nconsole.error(`❌ ${message}`);\nconst bbb = '';\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJ4eHgiLCJjb25zb2xlIiwiZXJyb3IiLCJtZXNzYWdlIiwiYmJiIl0sInNvdXJjZXMiOlsidW5rbm93biJdLCJzb3VyY2VzQ29udGVudCI6WyJjb25zdCB4eHggPSAnLCBzb21ldGhpbmcnXG5jb25zb2xlLmVycm9yKGDinYwgJHttZXNzYWdlfWApO1xuXG5jb25zdCBiYmIgPSAnJ1xuIl0sIm1hcHBpbmdzIjoiQUFBQSxNQUFNQSxHQUFHLEdBQUcsYUFBWjtBQUNBQyxPQUFPLENBQUNDLEtBQVIsQ0FBZSxLQUFJQyxPQUFRLEVBQTNCO0FBRUEsTUFBTUMsR0FBRyxHQUFHLEVBQVoifQ==\n" | ||
], | ||
"version": 3 | ||
} |
20 changes: 20 additions & 0 deletions
20
crates/swc/tests/fixture/sourcemap/issue-6552/no-map/input/.swcrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"sourceMaps": true, | ||
"jsc": { | ||
"parser": { | ||
"syntax": "ecmascript", | ||
"jsx": false | ||
}, | ||
"target": "es5", | ||
"loose": false, | ||
"minify": { | ||
"compress": false, | ||
"mangle": false | ||
} | ||
}, | ||
"module": { | ||
"type": "commonjs" | ||
}, | ||
"minify": true, | ||
"isModule": true | ||
} |
4 changes: 4 additions & 0 deletions
4
crates/swc/tests/fixture/sourcemap/issue-6552/no-map/input/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const xxx = ', something' | ||
console.error(`❌ ${message}`); | ||
|
||
const bbb = '' |
1 change: 1 addition & 0 deletions
1
crates/swc/tests/fixture/sourcemap/issue-6552/no-map/output/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"use strict";var xxx=", something";console.error("❌ ".concat(message));var bbb=""; |
17 changes: 17 additions & 0 deletions
17
crates/swc/tests/fixture/sourcemap/issue-6552/no-map/output/index.map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"mappings": "AAAA,aAAA,IAAMA,IAAM,cACZC,QAAQC,KAAK,CAAC,AAAC,KAAY,OAARC,UAEnB,IAAMC,IAAM", | ||
"names": [ | ||
"xxx", | ||
"console", | ||
"error", | ||
"message", | ||
"bbb" | ||
], | ||
"sources": [ | ||
"../../input/index.js" | ||
], | ||
"sourcesContent": [ | ||
"const xxx = ', something'\nconsole.error(`❌ ${message}`);\n\nconst bbb = ''\n" | ||
], | ||
"version": 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
a203fdb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
es/full/bugs-1
433858
ns/iter (± 60049
)360532
ns/iter (± 22667
)1.20
es/full/minify/libraries/antd
2421609627
ns/iter (± 69302733
)2059896790
ns/iter (± 21826036
)1.18
es/full/minify/libraries/d3
471887492
ns/iter (± 17014566
)472027800
ns/iter (± 23829735
)1.00
es/full/minify/libraries/echarts
2117942431
ns/iter (± 71712587
)1741553955
ns/iter (± 49207818
)1.22
es/full/minify/libraries/jquery
132923529
ns/iter (± 6559938
)109253087
ns/iter (± 2209958
)1.22
es/full/minify/libraries/lodash
152517116
ns/iter (± 5581911
)125198057
ns/iter (± 3714508
)1.22
es/full/minify/libraries/moment
84859642
ns/iter (± 52635634
)64127061
ns/iter (± 7665962
)1.32
es/full/minify/libraries/react
28651895
ns/iter (± 15209523
)21947713
ns/iter (± 460113
)1.31
es/full/minify/libraries/terser
463019636
ns/iter (± 33428381
)331681260
ns/iter (± 15671794
)1.40
es/full/minify/libraries/three
736593634
ns/iter (± 66658898
)612215724
ns/iter (± 23303045
)1.20
es/full/minify/libraries/typescript
4838105034
ns/iter (± 148445746
)3793185807
ns/iter (± 58044728
)1.28
es/full/minify/libraries/victory
1112553848
ns/iter (± 83094318
)982142784
ns/iter (± 84583244
)1.13
es/full/minify/libraries/vue
215182264
ns/iter (± 24983236
)203116835
ns/iter (± 19896332
)1.06
es/full/codegen/es3
41999
ns/iter (± 886
)35936
ns/iter (± 5000
)1.17
es/full/codegen/es5
41891
ns/iter (± 2310
)34247
ns/iter (± 2453
)1.22
es/full/codegen/es2015
41479
ns/iter (± 2752
)34262
ns/iter (± 1185
)1.21
es/full/codegen/es2016
41953
ns/iter (± 5247
)34741
ns/iter (± 1521
)1.21
es/full/codegen/es2017
41691
ns/iter (± 3435
)34367
ns/iter (± 1609
)1.21
es/full/codegen/es2018
43614
ns/iter (± 25098
)34532
ns/iter (± 2530
)1.26
es/full/codegen/es2019
41370
ns/iter (± 4333
)34565
ns/iter (± 1558
)1.20
es/full/codegen/es2020
42106
ns/iter (± 6950
)34832
ns/iter (± 3878
)1.21
es/full/all/es3
237538178
ns/iter (± 28711261
)237315028
ns/iter (± 22871198
)1.00
es/full/all/es5
225625443
ns/iter (± 17751187
)225492813
ns/iter (± 19749924
)1.00
es/full/all/es2015
179765309
ns/iter (± 17404803
)181221843
ns/iter (± 15816575
)0.99
es/full/all/es2016
182401069
ns/iter (± 15335932
)178068147
ns/iter (± 19930294
)1.02
es/full/all/es2017
177936455
ns/iter (± 15811367
)174244091
ns/iter (± 17486793
)1.02
es/full/all/es2018
175847881
ns/iter (± 19239088
)172144942
ns/iter (± 14584821
)1.02
es/full/all/es2019
175094541
ns/iter (± 17610050
)169395980
ns/iter (± 21142491
)1.03
es/full/all/es2020
168017276
ns/iter (± 15066806
)167952429
ns/iter (± 16215571
)1.00
es/full/parser
873718
ns/iter (± 35587
)765715
ns/iter (± 78211
)1.14
es/full/base/fixer
32642
ns/iter (± 1935
)28320
ns/iter (± 5716
)1.15
es/full/base/resolver_and_hygiene
117221
ns/iter (± 3824
)98593
ns/iter (± 21215
)1.19
serialization of ast node
252
ns/iter (± 13
)208
ns/iter (± 7
)1.21
serialization of serde
266
ns/iter (± 20
)222
ns/iter (± 6
)1.20
This comment was automatically generated by workflow using github-action-benchmark.