From 974c6a0036c5ef3e3d12c81c7310758046ff0a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 19 Jan 2024 13:14:11 +0900 Subject: [PATCH] test(es/codegen): Add a JS test for ascii-only mode (#8519) **Description:** The issue was fixed by #8493, but it was not included in the latest release because of the wrong bump comment. **Related issue:** - Closes #8491 --- crates/swc_ecma_codegen/src/tests.rs | 32 +++++++++++++++++ .../__tests__/transform/issue_8491_test.mjs | 36 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 node-swc/__tests__/transform/issue_8491_test.mjs diff --git a/crates/swc_ecma_codegen/src/tests.rs b/crates/swc_ecma_codegen/src/tests.rs index 99087465d686..0903d5df541e 100644 --- a/crates/swc_ecma_codegen/src/tests.rs +++ b/crates/swc_ecma_codegen/src/tests.rs @@ -945,6 +945,38 @@ fn emit_type_import_specifier() { assert_eq!(DebugUsingDisplay(out.trim()), DebugUsingDisplay(to.trim()),); } +#[test] +fn issue_8491_1() { + test_all( + "console.log({aób: 'ó'})", + r#"console.log({ + "a\xf3b": "\xf3" +});"#, + r#"console.log({"a\xf3b":"\xf3"})"#, + Config { + ascii_only: true, + target: EsVersion::Es5, + ..Default::default() + }, + ); +} + +#[test] +fn issue_8491_2() { + test_all( + "console.log({aób: 'ó'})", + r#"console.log({ + "a\xf3b": "\xf3" +});"#, + r#"console.log({"a\xf3b":"\xf3"})"#, + Config { + ascii_only: true, + target: EsVersion::Es2015, + ..Default::default() + }, + ); +} + #[testing::fixture("tests/str-lits/**/*.txt")] fn test_str_lit(input: PathBuf) { test_str_lit_inner(input) diff --git a/node-swc/__tests__/transform/issue_8491_test.mjs b/node-swc/__tests__/transform/issue_8491_test.mjs new file mode 100644 index 000000000000..41edd00002c3 --- /dev/null +++ b/node-swc/__tests__/transform/issue_8491_test.mjs @@ -0,0 +1,36 @@ +import swc from "../../.."; + +it("should transpile decorators", async () => { + const source = `const a = {aób: 'ó'} + + console.log(a)`; + + expect( + swc.transformSync(source, { + jsc: { + parser: { + syntax: "ecmascript", + jsx: false, + }, + target: "es5", + loose: false, + minify: { + compress: true, + format: { + asciiOnly: true, + }, + }, + }, + module: { + type: "es6", + }, + minify: false, + isModule: true, + }).code + ).toMatchInlineSnapshot(` + "console.log({ + "a\\xf3b": "\\xf3" + }); + " + `); +});