From 96f592de06705ea48134fd4053d2017a005bfae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Wed, 15 Nov 2023 13:00:55 +0900 Subject: [PATCH 1/3] Add a test --- .../fixture/issues-8xxx/8260/input/.swcrc | 22 +++++++++++++++++++ .../tests/fixture/issues-8xxx/8260/input/1.js | 2 ++ 2 files changed, 24 insertions(+) create mode 100644 crates/swc/tests/fixture/issues-8xxx/8260/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-8xxx/8260/input/1.js diff --git a/crates/swc/tests/fixture/issues-8xxx/8260/input/.swcrc b/crates/swc/tests/fixture/issues-8xxx/8260/input/.swcrc new file mode 100644 index 000000000000..773242e0310f --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8260/input/.swcrc @@ -0,0 +1,22 @@ +{ + "jsc": { + "parser": { + "syntax": "ecmascript", + "jsx": false + }, + "target": "es5", + "loose": false, + "minify": { + "compress": false, + "mangle": false, + "format": { + "ascii_only": true + } + }, + }, + "module": { + "type": "es6" + }, + "minify": false, + "isModule": true +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-8xxx/8260/input/1.js b/crates/swc/tests/fixture/issues-8xxx/8260/input/1.js new file mode 100644 index 000000000000..fe8e3a2361d3 --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8260/input/1.js @@ -0,0 +1,2 @@ +function p(µ, σ) { } +console.log(p); \ No newline at end of file From 3f3935e0d1e81e4906723ab43d13e51373006721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Wed, 15 Nov 2023 13:06:26 +0900 Subject: [PATCH 2/3] fix --- crates/swc_ecma_codegen/src/lib.rs | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/crates/swc_ecma_codegen/src/lib.rs b/crates/swc_ecma_codegen/src/lib.rs index c4d33bb47091..4f09a958adc6 100644 --- a/crates/swc_ecma_codegen/src/lib.rs +++ b/crates/swc_ecma_codegen/src/lib.rs @@ -1675,20 +1675,6 @@ where fn emit_prop_name(&mut self, node: &PropName) -> Result { match node { PropName::Ident(ident) => { - if self.cfg.ascii_only && !ident.sym.is_ascii() { - punct!("\""); - self.wr.write_symbol( - DUMMY_SP, - &get_ascii_only_ident( - &handle_invalid_unicodes(&ident.sym), - self.cfg.target, - ), - )?; - punct!("\""); - - return Ok(()); - } - emit!(ident) } PropName::Str(ref n) => emit!(n), @@ -3723,6 +3709,7 @@ fn get_ascii_only_ident(sym: &str, target: EsVersion) -> Cow { return Cow::Borrowed(sym); } + let mut first = true; let mut buf = String::with_capacity(sym.len() + 8); let mut iter = sym.chars().peekable(); @@ -3816,16 +3803,16 @@ fn get_ascii_only_ident(sym: &str, target: EsVersion) -> Cow { '"' => { buf.push('"'); } - '\x01'..='\x0f' => { + '\x01'..='\x0f' if !first => { let _ = write!(buf, "\\x0{:x}", c as u8); } - '\x10'..='\x1f' => { + '\x10'..='\x1f' if !first => { let _ = write!(buf, "\\x{:x}", c as u8); } '\x20'..='\x7e' => { buf.push(c); } - '\u{7f}'..='\u{ff}' => { + '\u{7f}'..='\u{ff}' if !first => { let _ = write!(buf, "\\x{:x}", c as u8); } '\u{2028}' => { @@ -3860,6 +3847,7 @@ fn get_ascii_only_ident(sym: &str, target: EsVersion) -> Cow { } } } + first = false; } Cow::Owned(buf) From 4cd43766c83d568600ce2660121b3baeecfaf84e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Wed, 15 Nov 2023 13:06:55 +0900 Subject: [PATCH 3/3] Update test refs --- .../fixture/issues-7xxx/7240/output/index.js | 4 ++-- .../tests/fixture/issues-7xxx/7805/output/1.js | 16 ++++++++-------- .../tests/fixture/issues-8xxx/8260/output/1.js | 2 ++ 3 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 crates/swc/tests/fixture/issues-8xxx/8260/output/1.js diff --git a/crates/swc/tests/fixture/issues-7xxx/7240/output/index.js b/crates/swc/tests/fixture/issues-7xxx/7240/output/index.js index 708e259f8306..240bd27309fd 100644 --- a/crates/swc/tests/fixture/issues-7xxx/7240/output/index.js +++ b/crates/swc/tests/fixture/issues-7xxx/7240/output/index.js @@ -8,6 +8,6 @@ Object.defineProperty(exports, "__esModule", { } }); var _obj, _default = ((_obj = { - "\u3131": "\u11B0", - "\u3141": "\u11B1" + \u3131: "\u11B0", + \u3141: "\u11B1" })["\u3142"] = "\u11B2", _obj); diff --git a/crates/swc/tests/fixture/issues-7xxx/7805/output/1.js b/crates/swc/tests/fixture/issues-7xxx/7805/output/1.js index b7618cc85343..0ca9c927f069 100644 --- a/crates/swc/tests/fixture/issues-7xxx/7805/output/1.js +++ b/crates/swc/tests/fixture/issues-7xxx/7805/output/1.js @@ -2,17 +2,17 @@ var SUPPORTED_LOCALE = { tr: { regexp: /\u0130|\u0049|\u0049\u0307/g, map: { - "\u0130": "i", + \u0130: "i", I: "\u0131", - "I\u0307": "i" + I\u0307: "i" } }, az: { regexp: /\u0130/g, map: { - "\u0130": "i", + \u0130: "i", I: "\u0131", - "I\u0307": "i" + I\u0307: "i" } }, lt: { @@ -20,10 +20,10 @@ var SUPPORTED_LOCALE = { map: { I: "i\u0307", J: "j\u0307", - "\u012E": "\u012F\u0307", - "\xcc": "i\u0307\u0300", - "\xcd": "i\u0307\u0301", - "\u0128": "i\u0307\u0303" + \u012E: "\u012F\u0307", + \u00CC: "i\u0307\u0300", + \u00CD: "i\u0307\u0301", + \u0128: "i\u0307\u0303" } } }; diff --git a/crates/swc/tests/fixture/issues-8xxx/8260/output/1.js b/crates/swc/tests/fixture/issues-8xxx/8260/output/1.js new file mode 100644 index 000000000000..eb9aa7df1d5e --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8260/output/1.js @@ -0,0 +1,2 @@ +function p(\u00B5, \u03C3) {} +console.log(p);