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/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 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); diff --git a/crates/swc_ecma_codegen/src/lib.rs b/crates/swc_ecma_codegen/src/lib.rs index 441c3a9c396e..7691048a7540 100644 --- a/crates/swc_ecma_codegen/src/lib.rs +++ b/crates/swc_ecma_codegen/src/lib.rs @@ -1657,20 +1657,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), @@ -3705,6 +3691,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(); @@ -3798,16 +3785,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}' => { @@ -3842,6 +3829,7 @@ fn get_ascii_only_ident(sym: &str, target: EsVersion) -> Cow { } } } + first = false; } Cow::Owned(buf)