Skip to content

Commit b45649b

Browse files
authoredAug 7, 2023
fix(es/codegen): Don't strip necessary escape characters (#7687)
**Related issue:** - Closes #7678.
1 parent 0219eeb commit b45649b

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"jsc": {
3+
"parser": {
4+
"syntax": "typescript",
5+
"tsx": false
6+
},
7+
"target": "es2015",
8+
"loose": false,
9+
"minify": {
10+
"compress": false,
11+
"mangle": false
12+
}
13+
},
14+
"module": {
15+
"type": "commonjs"
16+
},
17+
"minify": true,
18+
"isModule": false
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let str = "\\uD83D\\uDC68\\u200D\\uD83D\\uDE80";
2+
3+
let obj = {
4+
"\\uD83D\\uDC68\\u200D\\uD83D\\uDE80": "wrong"
5+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let str="\uD83D\uDC68\\u200D\uD83D\uDE80";let obj={"\uD83D\uDC68\\u200D\uD83D\uDE80":"wrong"};

‎crates/swc_ecma_codegen/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -3770,6 +3770,8 @@ fn get_quoted_utf16(v: &str, ascii_only: bool, target: EsVersion) -> String {
37703770

37713771
inner_iter.next();
37723772
next = inner_iter.peek();
3773+
} else if next != Some(&'D') && next != Some(&'d') {
3774+
buf.push('\\');
37733775
}
37743776

37753777
if let Some(c @ 'D' | c @ 'd') = next {
@@ -3816,8 +3818,10 @@ fn get_quoted_utf16(v: &str, ascii_only: bool, target: EsVersion) -> String {
38163818
iter.next();
38173819
}
38183820
}
3819-
} else {
3821+
} else if is_curly {
38203822
buf.push_str("\\\\");
3823+
} else {
3824+
buf.push('\\');
38213825
}
38223826
}
38233827
_ => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export let str = "\\uD83D\\uDC68\\u200D\\uD83D\\uDE80";
2+
3+
export let obj = {
4+
"\\uD83D\\uDC68\\u200D\\uD83D\\uDE80": "wrong"
5+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export let str = "\\uD83D\\uDC68\\u200D\\uD83D\\uDE80";
2+
export let obj = {
3+
"\\uD83D\\uDC68\\u200D\\uD83D\\uDE80": "wrong"
4+
};

1 commit comments

Comments
 (1)

github-actions[bot] commented on Aug 8, 2023

@github-actions[bot]

Benchmark

Benchmark suite Current: b45649b Previous: 5f97f86 Ratio
es/full/bugs-1 289046 ns/iter (± 9887) 287377 ns/iter (± 4669) 1.01
es/full/minify/libraries/antd 1303875518 ns/iter (± 7991386) 1369103799 ns/iter (± 13825020) 0.95
es/full/minify/libraries/d3 278330200 ns/iter (± 1923912) 290759132 ns/iter (± 5932773) 0.96
es/full/minify/libraries/echarts 1089477446 ns/iter (± 30216552) 1143652605 ns/iter (± 6973858) 0.95
es/full/minify/libraries/jquery 86611396 ns/iter (± 682332) 86033560 ns/iter (± 441560) 1.01
es/full/minify/libraries/lodash 101544180 ns/iter (± 516018) 99851864 ns/iter (± 327884) 1.02
es/full/minify/libraries/moment 50969121 ns/iter (± 140320) 50331691 ns/iter (± 220325) 1.01
es/full/minify/libraries/react 18159756 ns/iter (± 71324) 18046215 ns/iter (± 37587) 1.01
es/full/minify/libraries/terser 223125922 ns/iter (± 3186361) 224073523 ns/iter (± 2376339) 1.00
es/full/minify/libraries/three 427985502 ns/iter (± 14919502) 407355681 ns/iter (± 5755743) 1.05
es/full/minify/libraries/typescript 2806525547 ns/iter (± 59669927) 2789089835 ns/iter (± 29799302) 1.01
es/full/minify/libraries/victory 651972308 ns/iter (± 19422214) 593956811 ns/iter (± 9525575) 1.10
es/full/minify/libraries/vue 128291180 ns/iter (± 1550186) 122505983 ns/iter (± 887766) 1.05
es/full/codegen/es3 35466 ns/iter (± 84) 36190 ns/iter (± 125) 0.98
es/full/codegen/es5 35414 ns/iter (± 80) 36259 ns/iter (± 81) 0.98
es/full/codegen/es2015 35392 ns/iter (± 87) 36213 ns/iter (± 55) 0.98
es/full/codegen/es2016 35422 ns/iter (± 58) 36243 ns/iter (± 66) 0.98
es/full/codegen/es2017 35492 ns/iter (± 154) 36261 ns/iter (± 61) 0.98
es/full/codegen/es2018 35444 ns/iter (± 104) 36209 ns/iter (± 72) 0.98
es/full/codegen/es2019 35368 ns/iter (± 92) 36195 ns/iter (± 80) 0.98
es/full/codegen/es2020 35352 ns/iter (± 90) 36217 ns/iter (± 121) 0.98
es/full/all/es3 174392827 ns/iter (± 1706049) 176363885 ns/iter (± 1415445) 0.99
es/full/all/es5 168417513 ns/iter (± 918337) 168610749 ns/iter (± 1099819) 1.00
es/full/all/es2015 126191250 ns/iter (± 621224) 126932782 ns/iter (± 753377) 0.99
es/full/all/es2016 125970915 ns/iter (± 609549) 124838847 ns/iter (± 626564) 1.01
es/full/all/es2017 124710291 ns/iter (± 745963) 124930939 ns/iter (± 1035055) 1.00
es/full/all/es2018 122113383 ns/iter (± 724426) 122367488 ns/iter (± 537928) 1.00
es/full/all/es2019 121939001 ns/iter (± 692422) 122358254 ns/iter (± 547240) 1.00
es/full/all/es2020 117689753 ns/iter (± 569742) 117512185 ns/iter (± 353091) 1.00
es/full/parser 535124 ns/iter (± 5360) 547793 ns/iter (± 6346) 0.98
es/full/base/fixer 19442 ns/iter (± 97) 18196 ns/iter (± 327) 1.07
es/full/base/resolver_and_hygiene 84412 ns/iter (± 142) 81991 ns/iter (± 128) 1.03
serialization of serde 299 ns/iter (± 0) 292 ns/iter (± 2) 1.02
css/minify/libraries/bootstrap 28803795 ns/iter (± 30044) 29363236 ns/iter (± 76308) 0.98
css/visitor/compare/clone 1637166 ns/iter (± 2437) 1641386 ns/iter (± 12367) 1.00
css/visitor/compare/visit_mut_span 1776774 ns/iter (± 7402) 1777461 ns/iter (± 8779) 1.00
css/visitor/compare/visit_mut_span_panic 1860104 ns/iter (± 5634) 1839919 ns/iter (± 2664) 1.01
css/visitor/compare/fold_span 2604692 ns/iter (± 13475) 2595631 ns/iter (± 10670) 1.00
css/visitor/compare/fold_span_panic 2795901 ns/iter (± 14833) 2769696 ns/iter (± 21919) 1.01
css/lexer/bootstrap_5_1_3 4559234 ns/iter (± 13860) 4433736 ns/iter (± 7023) 1.03
css/lexer/foundation_6_7_4 3844395 ns/iter (± 7945) 3742478 ns/iter (± 952) 1.03
css/lexer/tailwind_3_1_1 731853 ns/iter (± 899) 710881 ns/iter (± 991) 1.03
css/parser/bootstrap_5_1_3 19434040 ns/iter (± 26457) 19404506 ns/iter (± 76110) 1.00
css/parser/foundation_6_7_4 15663553 ns/iter (± 23564) 15347591 ns/iter (± 30812) 1.02
css/parser/tailwind_3_1_1 2994091 ns/iter (± 2535) 2966492 ns/iter (± 2958) 1.01
es/codegen/colors 736894 ns/iter (± 402390) 738993 ns/iter (± 402536) 1.00
es/codegen/large 3144791 ns/iter (± 1665290) 2898352 ns/iter (± 1527524) 1.09
es/codegen/with-parser/colors 45276 ns/iter (± 173) 45157 ns/iter (± 470) 1.00
es/codegen/with-parser/large 489042 ns/iter (± 704) 490511 ns/iter (± 899) 1.00
es/minify/libraries/antd 1155131033 ns/iter (± 14712005) 1218702485 ns/iter (± 22299634) 0.95
es/minify/libraries/d3 242835890 ns/iter (± 458466) 247540712 ns/iter (± 2044717) 0.98
es/minify/libraries/echarts 917438675 ns/iter (± 2549578) 975150149 ns/iter (± 10769275) 0.94
es/minify/libraries/jquery 74823913 ns/iter (± 223740) 75950370 ns/iter (± 247620) 0.99
es/minify/libraries/lodash 89224151 ns/iter (± 255767) 89857985 ns/iter (± 184814) 0.99
es/minify/libraries/moment 44062903 ns/iter (± 44182) 44574283 ns/iter (± 98108) 0.99
es/minify/libraries/react 16190505 ns/iter (± 43341) 16216915 ns/iter (± 78606) 1.00
es/minify/libraries/terser 189019957 ns/iter (± 338140) 192415840 ns/iter (± 1133381) 0.98
es/minify/libraries/three 325320404 ns/iter (± 627027) 335077587 ns/iter (± 5988465) 0.97
es/minify/libraries/typescript 2296086673 ns/iter (± 6087438) 2377148964 ns/iter (± 12717113) 0.97
es/minify/libraries/victory 478372947 ns/iter (± 1126017) 512796767 ns/iter (± 11708183) 0.93
es/minify/libraries/vue 108477009 ns/iter (± 163468) 110196819 ns/iter (± 1483339) 0.98
es/visitor/compare/clone 1932669 ns/iter (± 53010) 1969590 ns/iter (± 9708) 0.98
es/visitor/compare/visit_mut_span 2282096 ns/iter (± 7793) 2306476 ns/iter (± 8430) 0.99
es/visitor/compare/visit_mut_span_panic 2314846 ns/iter (± 5963) 2340121 ns/iter (± 5251) 0.99
es/visitor/compare/fold_span 3325014 ns/iter (± 7673) 3397308 ns/iter (± 13429) 0.98
es/visitor/compare/fold_span_panic 3459309 ns/iter (± 7746) 3507515 ns/iter (± 40173) 0.99
es/lexer/colors 13527 ns/iter (± 33) 13072 ns/iter (± 28) 1.03
es/lexer/angular 6325888 ns/iter (± 9027) 6027601 ns/iter (± 6130) 1.05
es/lexer/backbone 832493 ns/iter (± 520) 795576 ns/iter (± 381) 1.05
es/lexer/jquery 4682687 ns/iter (± 7724) 4417091 ns/iter (± 5874) 1.06
es/lexer/jquery mobile 7148672 ns/iter (± 6909) 6752011 ns/iter (± 35709) 1.06
es/lexer/mootools 3704304 ns/iter (± 8446) 3532909 ns/iter (± 19042) 1.05
es/lexer/underscore 688978 ns/iter (± 1129) 656002 ns/iter (± 1062) 1.05
es/lexer/three 22106176 ns/iter (± 25376) 20919190 ns/iter (± 41316) 1.06
es/lexer/yui 3966716 ns/iter (± 1916) 3711439 ns/iter (± 8438) 1.07
es/parser/colors 27432 ns/iter (± 41) 27562 ns/iter (± 155) 1.00
es/parser/angular 13617178 ns/iter (± 57198) 13507952 ns/iter (± 161149) 1.01
es/parser/backbone 2013804 ns/iter (± 7687) 2006898 ns/iter (± 15516) 1.00
es/parser/jquery 11030759 ns/iter (± 27228) 11091547 ns/iter (± 104142) 0.99
es/parser/jquery mobile 16832324 ns/iter (± 51337) 17080263 ns/iter (± 262721) 0.99
es/parser/mootools 8489082 ns/iter (± 17765) 8413889 ns/iter (± 48315) 1.01
es/parser/underscore 1740223 ns/iter (± 8776) 1725163 ns/iter (± 8806) 1.01
es/parser/three 46909997 ns/iter (± 109992) 49424125 ns/iter (± 462498) 0.95
es/parser/yui 8352723 ns/iter (± 27759) 8316256 ns/iter (± 55240) 1.00
es/preset-env/usage/builtin_type 136349 ns/iter (± 32034) 138096 ns/iter (± 32960) 0.99
es/preset-env/usage/property 16816 ns/iter (± 83) 16780 ns/iter (± 62) 1.00
es/resolver/typescript 89026990 ns/iter (± 775939) 90748742 ns/iter (± 2169318) 0.98
es/fixer/typescript 63306562 ns/iter (± 645314) 64565190 ns/iter (± 1803010) 0.98
es/hygiene/typescript 129923733 ns/iter (± 870022) 135598940 ns/iter (± 1683356) 0.96
es/resolver_with_hygiene/typescript 241035057 ns/iter (± 914554) 252142906 ns/iter (± 2308960) 0.96
es/visitor/base-perf/module_clone 59096 ns/iter (± 715) 59193 ns/iter (± 197) 1.00
es/visitor/base-perf/fold_empty 63189 ns/iter (± 201) 62642 ns/iter (± 345) 1.01
es/visitor/base-perf/fold_noop_impl_all 63148 ns/iter (± 146) 62848 ns/iter (± 387) 1.00
es/visitor/base-perf/fold_noop_impl_vec 63152 ns/iter (± 274) 63529 ns/iter (± 188) 0.99
es/visitor/base-perf/boxing_boxed_clone 56 ns/iter (± 0) 57 ns/iter (± 0) 0.98
es/visitor/base-perf/boxing_unboxed_clone 40 ns/iter (± 0) 43 ns/iter (± 0) 0.93
es/visitor/base-perf/boxing_boxed 109 ns/iter (± 0) 111 ns/iter (± 0) 0.98
es/visitor/base-perf/boxing_unboxed 78 ns/iter (± 0) 77 ns/iter (± 0) 1.01
es/visitor/base-perf/visit_empty 0 ns/iter (± 0) 0 ns/iter (± 0) NaN
es/visitor/base-perf/visit_contains_this 2526 ns/iter (± 25) 2538 ns/iter (± 14) 1.00
es/base/parallel/resolver/typescript 3902247200 ns/iter (± 268834364) 4011581075 ns/iter (± 308634192) 0.97
es/base/parallel/hygiene/typescript 1475092770 ns/iter (± 9535589) 1480359664 ns/iter (± 13892335) 1.00
misc/visitors/time-complexity/time 5 142 ns/iter (± 1) 146 ns/iter (± 1) 0.97
misc/visitors/time-complexity/time 10 363 ns/iter (± 5) 403 ns/iter (± 13) 0.90
misc/visitors/time-complexity/time 15 701 ns/iter (± 28) 687 ns/iter (± 11) 1.02
misc/visitors/time-complexity/time 20 1047 ns/iter (± 4) 1053 ns/iter (± 14) 0.99
misc/visitors/time-complexity/time 40 3590 ns/iter (± 41) 3627 ns/iter (± 289) 0.99
misc/visitors/time-complexity/time 60 7929 ns/iter (± 164) 7221 ns/iter (± 40) 1.10
es/full-target/es2016 234940 ns/iter (± 810) 240811 ns/iter (± 966) 0.98
es/full-target/es2017 224981 ns/iter (± 938) 227823 ns/iter (± 909) 0.99
es/full-target/es2018 212048 ns/iter (± 861) 214990 ns/iter (± 700) 0.99
es2020_nullish_coalescing 71072 ns/iter (± 414) 70758 ns/iter (± 334) 1.00
es2020_optional_chaining 81731 ns/iter (± 196) 81134 ns/iter (± 348) 1.01
es2022_class_properties 120395 ns/iter (± 1417) 119982 ns/iter (± 299) 1.00
es2018_object_rest_spread 74472 ns/iter (± 184) 76111 ns/iter (± 280) 0.98
es2019_optional_catch_binding 64142 ns/iter (± 273) 64345 ns/iter (± 278) 1.00
es2017_async_to_generator 63869 ns/iter (± 195) 64279 ns/iter (± 262) 0.99
es2016_exponentiation 68270 ns/iter (± 109) 68956 ns/iter (± 273) 0.99
es2015_arrow 71339 ns/iter (± 261) 71649 ns/iter (± 213) 1.00
es2015_block_scoped_fn 68294 ns/iter (± 212) 68111 ns/iter (± 220) 1.00
es2015_block_scoping 122703 ns/iter (± 360) 123162 ns/iter (± 487) 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.