Skip to content

Commit

Permalink
test(es/codegen): Add a JS test for ascii-only mode (#8519)
Browse files Browse the repository at this point in the history
**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
  • Loading branch information
kdy1 authored Jan 19, 2024
1 parent 4b76b8f commit 974c6a0
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
32 changes: 32 additions & 0 deletions crates/swc_ecma_codegen/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 36 additions & 0 deletions node-swc/__tests__/transform/issue_8491_test.mjs
Original file line number Diff line number Diff line change
@@ -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"
});
"
`);
});

0 comments on commit 974c6a0

Please sign in to comment.