From 6362ff4ba80afc9c887a8817582ae976a05c1d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 10 May 2024 11:23:52 +0900 Subject: [PATCH] fix(es/ast): Pin version of unicodes (#8941) **Description:** https://github.com/swc-project/swc/issues/8940#issuecomment-2102423586 > I found part of the problem: > > U+30FB was added to `ID_Continue` from Unicode version 14 to 15, but v8 is using an older version of unicode ... which I can't find the exact version. > > I spent 2 hours searching for all the missing pieces, I give up. > > Let me back port unicode version 14. **Related issue:** - Closes #8940 --- Cargo.lock | 4 +- Cargo.toml | 2 +- .../fixture/issues-8xxx/8940/input/.swcrc | 64 +++++++++++++++++++ .../tests/fixture/issues-8xxx/8940/input/1.js | 7 ++ .../fixture/issues-8xxx/8940/output/1.js | 7 ++ crates/swc_ecma_codegen/tests/sourcemap.rs | 5 ++ crates/swc_ecma_codegen/tests/test262.rs | 5 ++ .../src/compress/util/mod.rs | 7 +- .../unicode/unicode_props_safari/output.js | 4 +- crates/swc_ecma_parser/tests/test262.rs | 5 ++ .../tests/fixer_test262.rs | 5 ++ 11 files changed, 106 insertions(+), 9 deletions(-) create mode 100644 crates/swc/tests/fixture/issues-8xxx/8940/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-8xxx/8940/input/1.js create mode 100644 crates/swc/tests/fixture/issues-8xxx/8940/output/1.js diff --git a/Cargo.lock b/Cargo.lock index adef045e2573..7dfd97c1e7e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5927,9 +5927,9 @@ checksum = "b1b6def86329695390197b82c1e244a54a131ceb66c996f2088a3876e2ae083f" [[package]] name = "unicode-id-start" -version = "1.1.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8f73150333cb58412db36f2aca8f2875b013049705cc77b94ded70a1ab1f5da" +checksum = "02aebfa694eccbbbffdd92922c7de136b9fe764396d2f10e21bce1681477cfc1" [[package]] name = "unicode-ident" diff --git a/Cargo.toml b/Cargo.toml index 37cd155369be..6cc4837e1bdf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -117,7 +117,7 @@ resolver = "2" tracing-subscriber = "0.3.18" typed-arena = "2.0.1" unicode-id = "0.3" - unicode-id-start = "1.1.2" + unicode-id-start = "=1.0.4" unicode-width = "0.1.4" url = "2.4.0" vergen = { version = "8.0.0", default-features = false } diff --git a/crates/swc/tests/fixture/issues-8xxx/8940/input/.swcrc b/crates/swc/tests/fixture/issues-8xxx/8940/input/.swcrc new file mode 100644 index 000000000000..cbd52e2511b1 --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8940/input/.swcrc @@ -0,0 +1,64 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript", + "tsx": false + }, + "target": "es5", + "loose": false, + "minify": { + "compress": { + "arguments": false, + "arrows": true, + "booleans": true, + "booleans_as_integers": false, + "collapse_vars": true, + "comparisons": true, + "computed_props": true, + "conditionals": true, + "dead_code": true, + "directives": true, + "drop_console": false, + "drop_debugger": true, + "evaluate": true, + "expression": false, + "hoist_funs": false, + "hoist_props": true, + "hoist_vars": false, + "if_return": true, + "join_vars": true, + "keep_classnames": false, + "keep_fargs": true, + "keep_fnames": false, + "keep_infinity": false, + "loops": true, + "negate_iife": true, + "properties": true, + "reduce_funcs": false, + "reduce_vars": false, + "side_effects": true, + "switches": true, + "typeofs": true, + "unsafe": false, + "unsafe_arrows": false, + "unsafe_comps": false, + "unsafe_Function": false, + "unsafe_math": false, + "unsafe_symbols": false, + "unsafe_methods": false, + "unsafe_proto": false, + "unsafe_regexp": false, + "unsafe_undefined": false, + "unused": true, + "const_to_let": true, + "pristine_globals": true + }, + "mangle": false + } + }, + "module": { + "type": "es6" + }, + "minify": false, + "isModule": true +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-8xxx/8940/input/1.js b/crates/swc/tests/fixture/issues-8xxx/8940/input/1.js new file mode 100644 index 000000000000..79a6fe09c8c0 --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8940/input/1.js @@ -0,0 +1,7 @@ +console.log({ + "あ": 1, + "あ・あ": 1, + "・あ": 1, + "・": 1, + "あ・": 1, +}) \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-8xxx/8940/output/1.js b/crates/swc/tests/fixture/issues-8xxx/8940/output/1.js new file mode 100644 index 000000000000..3229a6d622fc --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8940/output/1.js @@ -0,0 +1,7 @@ +console.log({ + あ: 1, + "あ・あ": 1, + "・あ": 1, + "・": 1, + "あ・": 1 +}); diff --git a/crates/swc_ecma_codegen/tests/sourcemap.rs b/crates/swc_ecma_codegen/tests/sourcemap.rs index fbbe43edb688..1fdaec759198 100644 --- a/crates/swc_ecma_codegen/tests/sourcemap.rs +++ b/crates/swc_ecma_codegen/tests/sourcemap.rs @@ -258,6 +258,11 @@ static IGNORED_PASS_TESTS: &[&str] = &[ "bc302492d441d561.js", "be2fd5888f434cbd.js", "f3260491590325af.js", + // Unicode 14 vs 15 + "046a0bb70d03d0cc.js", + "08a39e4289b0c3f3.js", + "300a638d978d0f2c.js", + "44f31660bd715f05.js", ]; #[testing::fixture("../swc_ecma_parser/tests/test262-parser/pass/*.js")] diff --git a/crates/swc_ecma_codegen/tests/test262.rs b/crates/swc_ecma_codegen/tests/test262.rs index f12b0ce8ebcb..6e2b8b68c3ee 100644 --- a/crates/swc_ecma_codegen/tests/test262.rs +++ b/crates/swc_ecma_codegen/tests/test262.rs @@ -64,6 +64,11 @@ const IGNORED_PASS_TESTS: &[&str] = &[ "59ae0289778b80cd.js", "a4d62a651f69d815.js", "c06df922631aeabc.js", + // Unicode 14 vs 15 + "046a0bb70d03d0cc.js", + "08a39e4289b0c3f3.js", + "300a638d978d0f2c.js", + "44f31660bd715f05.js", ]; #[testing::fixture("../swc_ecma_parser/tests/test262-parser/pass/*.js")] diff --git a/crates/swc_ecma_minifier/src/compress/util/mod.rs b/crates/swc_ecma_minifier/src/compress/util/mod.rs index 8b27a9fd594a..78349213130a 100644 --- a/crates/swc_ecma_minifier/src/compress/util/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/util/mod.rs @@ -403,14 +403,11 @@ pub(crate) fn is_primitive<'a>(expr_ctx: &ExprCtx, e: &'a Expr) -> Option<&'a Ex } pub(crate) fn is_valid_identifier(s: &str, ascii_only: bool) -> bool { - if ascii_only { - if s.chars().any(|c| !c.is_ascii()) { - return false; - } + if ascii_only && !s.is_ascii() { + return false; } s.starts_with(Ident::is_valid_start) && s.chars().skip(1).all(Ident::is_valid_continue) - && !s.contains('𝒶') && !s.is_reserved() } diff --git a/crates/swc_ecma_minifier/tests/terser/compress/unicode/unicode_props_safari/output.js b/crates/swc_ecma_minifier/tests/terser/compress/unicode/unicode_props_safari/output.js index dc2c0c25cb25..d06c9236bdb2 100644 --- a/crates/swc_ecma_minifier/tests/terser/compress/unicode/unicode_props_safari/output.js +++ b/crates/swc_ecma_minifier/tests/terser/compress/unicode/unicode_props_safari/output.js @@ -1 +1,3 @@ -console.log({ "𝒶": "foo" }); +console.log({ + 𝒶: "foo" +}); diff --git a/crates/swc_ecma_parser/tests/test262.rs b/crates/swc_ecma_parser/tests/test262.rs index 489435497d98..f706dcbd816d 100644 --- a/crates/swc_ecma_parser/tests/test262.rs +++ b/crates/swc_ecma_parser/tests/test262.rs @@ -79,6 +79,11 @@ const IGNORED_PASS_TESTS: &[&str] = &[ // Wrong test - strict mode "8f8bfb27569ac008.js", "ce569e89a005c02a.js", + // Unicode 14 vs 15 + "046a0bb70d03d0cc.js", + "08a39e4289b0c3f3.js", + "300a638d978d0f2c.js", + "44f31660bd715f05.js", ]; fn add_test Result<(), String> + Send + 'static>( diff --git a/crates/swc_ecma_transforms_base/tests/fixer_test262.rs b/crates/swc_ecma_transforms_base/tests/fixer_test262.rs index 8ba6eba1d57e..982bfeee4700 100644 --- a/crates/swc_ecma_transforms_base/tests/fixer_test262.rs +++ b/crates/swc_ecma_transforms_base/tests/fixer_test262.rs @@ -90,6 +90,11 @@ const IGNORED_PASS_TESTS: &[&str] = &[ "59ae0289778b80cd.js", "a4d62a651f69d815.js", "c06df922631aeabc.js", + // Unicode 14 vs 15 + "046a0bb70d03d0cc.js", + "08a39e4289b0c3f3.js", + "300a638d978d0f2c.js", + "44f31660bd715f05.js", ]; fn add_test Result<(), String> + Send + 'static>(