Commit 845512c
authored
fix(es/ast): Fix unicode unpaired surrogates handling (#11144)
**Description:**
This PR reapplied #10987 and
replaced `lone_surrogates: bool` mark with `Wtf8Atom`. `lone_surrogates`
introduced in #10987 is more of
an implicit mark, whereas the use of `Wtf8Atom` makes it more explicit
where users need to explicitly call `to_string_lossy` to get the lossy
UTF-8 result, making a huge difference from the original implementation
where users need to convert `\uFFFDxxx` into the correct unicode.
**BREAKING CHANGE:**
Both `cooked` in `TemplateElement` and `value` in `StringLiteral` are
replaced with `Wtf8Atom` introduced in
#11104.
`Wtf8Atom` does not expose a `to_string` method like the old `Atom`
does. Internally, it stores the code points of the characters. You can
call `code_points()` to get an iterator of the code points or call
`to_string_lossy()` to get an lossy string in which all unpaired
surrogates are replaced with `U+FFFD`(Replacement Character).1 parent dd6f71b commit 845512c
File tree
207 files changed
+5797
-1303
lines changed- .changeset
- .github/workflows
- crates
- hstr
- src
- wtf8
- swc_atoms
- src
- swc_bundler/src
- bundler
- chunk
- import
- swc_common/src
- swc_core/tests/fixture
- stub_napi
- stub_wasm
- swc_ecma_ast/src
- swc_ecma_codegen
- src
- tests/fixture
- issue-10978
- string
- template-literal
- vercel/2
- swc_ecma_compat_es2015/src
- block_scoping
- classes
- swc_ecma_compat_es2018/src
- swc_ecma_compat_es2022/src/class_properties
- swc_ecma_compat_es3/src
- swc_ecma_compiler/src/es2020
- swc_ecma_ext_transforms/src
- swc_ecma_lexer
- src
- common
- lexer
- parser
- lexer
- swc_ecma_lints/src/rules
- swc_ecma_minifier
- fuzz
- src
- compress
- optimize
- pure
- option
- pass
- tests
- fixture/next/swc-4559
- terser/compress/ascii/ascii_only_true_identifier_es5
- swc_ecma_parser
- src
- lexer
- parser
- expr
- jsx
- tests
- common
- jsx/basic
- 22
- string
- template
- test262-error-references/fail
- tsc
- typescript/next/stack-overflow/1
- swc_ecma_preset_env/src
- corejs2
- corejs3
- swc_ecma_quote_macros/src/ast
- swc_ecma_transforms_base/tests
- swc_ecma_transforms_classes/src
- swc_ecma_transforms_module/src
- rewriter
- swc_ecma_transforms_optimization/src
- simplify/expr
- swc_ecma_transforms_proposal/src
- decorators
- legacy
- swc_ecma_transforms_react/src
- display_name
- jsx
- pure_annotations
- swc_ecma_transforms_typescript/src
- swc_ecma_usage_analyzer/src/analyzer
- swc_ecma_utils/src
- swc_ecma_visit/src
- swc_estree_ast/src
- swc_node_bundler/src/loaders
- swc_plugin_backend_tests/tests/fixture/swc_internal_plugin
- src
- swc_plugin_backend_wasmer/src
- swc_typescript/src/fast_dts
- util
- swc/tests
- exec/issues-4xxx/4120
- fixture
- issues-4xxx/4120/1/output
- issues-7xxx/7678/output
- tsc-references
- vercel/full/utf8-1/output
- packages
- core/scripts/npm
- darwin-arm64
- darwin-x64
- linux-arm-gnueabihf
- linux-arm64-gnu
- linux-arm64-musl
- linux-x64-gnu
- linux-x64-musl
- win32-arm64-msvc
- win32-ia32-msvc
- win32-x64-msvc
- helpers
- html/scripts/npm
- darwin-arm64
- darwin-x64
- linux-arm-gnueabihf
- linux-arm64-gnu
- linux-arm64-musl
- linux-x64-gnu
- linux-x64-musl
- win32-arm64-msvc
- win32-ia32-msvc
- win32-x64-msvc
- minifier/scripts/npm
- darwin-arm64
- darwin-x64
- linux-arm-gnueabihf
- linux-arm64-gnu
- linux-arm64-musl
- linux-x64-gnu
- linux-x64-musl
- win32-arm64-msvc
- win32-ia32-msvc
- win32-x64-msvc
- react-compiler/scripts/npm
- darwin-arm64
- darwin-x64
- linux-arm-gnueabihf
- linux-arm64-gnu
- linux-arm64-musl
- linux-x64-gnu
- linux-x64-musl
- win32-arm64-msvc
- win32-ia32-msvc
- win32-x64-msvc
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
207 files changed
+5797
-1303
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
291 | 291 | | |
292 | 292 | | |
293 | 293 | | |
294 | | - | |
| 294 | + | |
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
| |||
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
320 | 325 | | |
321 | 326 | | |
322 | 327 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
104 | 105 | | |
105 | 106 | | |
106 | 107 | | |
| 108 | + | |
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
| |||
369 | 371 | | |
370 | 372 | | |
371 | 373 | | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
372 | 387 | | |
373 | 388 | | |
374 | 389 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
71 | | - | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
79 | | - | |
| 80 | + | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
| |||
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
90 | | - | |
| 91 | + | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
| |||
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
121 | 134 | | |
122 | 135 | | |
123 | 136 | | |
| |||
165 | 178 | | |
166 | 179 | | |
167 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
168 | 198 | | |
169 | 199 | | |
170 | 200 | | |
| |||
313 | 343 | | |
314 | 344 | | |
315 | 345 | | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
316 | 352 | | |
317 | 353 | | |
318 | 354 | | |
| |||
345 | 381 | | |
346 | 382 | | |
347 | 383 | | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
348 | 404 | | |
349 | 405 | | |
350 | 406 | | |
| |||
474 | 530 | | |
475 | 531 | | |
476 | 532 | | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
477 | 539 | | |
478 | 540 | | |
479 | 541 | | |
| |||
547 | 609 | | |
548 | 610 | | |
549 | 611 | | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
550 | 640 | | |
551 | 641 | | |
552 | 642 | | |
| |||
614 | 704 | | |
615 | 705 | | |
616 | 706 | | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
617 | 747 | | |
618 | 748 | | |
619 | 749 | | |
| |||
770 | 900 | | |
771 | 901 | | |
772 | 902 | | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
773 | 921 | | |
774 | 922 | | |
775 | 923 | | |
| |||
824 | 972 | | |
825 | 973 | | |
826 | 974 | | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
827 | 982 | | |
828 | 983 | | |
829 | 984 | | |
| |||
0 commit comments