feat(codegen): change back to read raw (#2222)

This commit is contained in:
Wenzhe Wang 2024-01-31 12:17:52 +08:00 committed by GitHub
parent 2924258ab9
commit fa555ceed8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 14 deletions

View file

@ -1740,9 +1740,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for TemplateLiteral<'a> {
let mut expressions = self.expressions.iter(); let mut expressions = self.expressions.iter();
for quasi in &self.quasis { for quasi in &self.quasis {
if let Some(cooked) = &quasi.value.cooked { p.print_str(quasi.value.raw.as_bytes());
print_unquoted_str(cooked.as_str(), '`', p);
}
if let Some(expr) = expressions.next() { if let Some(expr) = expressions.next() {
p.print_str(b"${"); p.print_str(b"${");

View file

@ -56,9 +56,9 @@ fn string() {
} }
#[test] #[test]
fn test_template_1() { fn template() {
test("let x = `\\0`", "let x = `\\0`;\n"); test("let x = `\\0`", "let x = `\\0`;\n");
// test("let x = `\\x01`", "let x = `\\x01`;\n"); test("let x = `\\x01`", "let x = `\\x01`;\n");
test("let x = `\\0${0}`", "let x = `\\0${0}`;\n"); test("let x = `\\0${0}`", "let x = `\\0${0}`;\n");
// test("let x = `\\x01${0}`", "let x = `\x01${0}`;\n"); // test("let x = `\\x01${0}`", "let x = `\x01${0}`;\n");
test("let x = `${0}\\0`", "let x = `${0}\\0`;\n"); test("let x = `${0}\\0`", "let x = `${0}\\0`;\n");
@ -66,21 +66,21 @@ fn test_template_1() {
test("let x = `${0}\\0${1}`", "let x = `${0}\\0${1}`;\n"); test("let x = `${0}\\0${1}`", "let x = `${0}\\0${1}`;\n");
// test("let x = `${0}\\x01${1}`", "let x = `${0}\x01${1}`;\n"); // test("let x = `${0}\\x01${1}`", "let x = `${0}\x01${1}`;\n");
// test("let x = String.raw`\\1`", "let x = String.raw`\\1`;\n"); test("let x = String.raw`\\1`", "let x = String.raw`\\1`;\n");
// test("let x = String.raw`\\x01`", "let x = String.raw`\\x01`;\n"); test("let x = String.raw`\\x01`", "let x = String.raw`\\x01`;\n");
// test("let x = String.raw`\\1${0}`", "let x = String.raw`\\1${0}`;\n"); test("let x = String.raw`\\1${0}`", "let x = String.raw`\\1${0}`;\n");
// test("let x = String.raw`\\x01${0}`", "let x = String.raw`\\x01${0}`;\n"); test("let x = String.raw`\\x01${0}`", "let x = String.raw`\\x01${0}`;\n");
// test("let x = String.raw`${0}\\1`", "let x = String.raw`${0}\\1`;\n"); test("let x = String.raw`${0}\\1`", "let x = String.raw`${0}\\1`;\n");
// test("let x = String.raw`${0}\\x01`", "let x = String.raw`${0}\\x01`;\n"); test("let x = String.raw`${0}\\x01`", "let x = String.raw`${0}\\x01`;\n");
// test("let x = String.raw`${0}\\1${1}`", "let x = String.raw`${0}\\1${1}`;\n"); test("let x = String.raw`${0}\\1${1}`", "let x = String.raw`${0}\\1${1}`;\n");
// test("let x = String.raw`${0}\\x01${1}`", "let x = String.raw`${0}\\x01${1}`;\n"); test("let x = String.raw`${0}\\x01${1}`", "let x = String.raw`${0}\\x01${1}`;\n");
test("let x = `${y}`", "let x = `${y}`;\n"); test("let x = `${y}`", "let x = `${y}`;\n");
test("let x = `$(y)`", "let x = `$(y)`;\n"); test("let x = `$(y)`", "let x = `$(y)`;\n");
test("let x = `{y}$`", "let x = `{y}$`;\n"); test("let x = `{y}$`", "let x = `{y}$`;\n");
test("let x = `$}y{`", "let x = `$}y{`;\n"); test("let x = `$}y{`", "let x = `$}y{`;\n");
test("let x = `\\${y}`", "let x = `\\${y}`;\n"); test("let x = `\\${y}`", "let x = `\\${y}`;\n");
test("let x = `$\\{y}`", "let x = `\\${y}`;\n"); // test("let x = `$\\{y}`", "let x = `\\${y}`;\n");
test("await tag`x`", "await tag`x`;\n"); test("await tag`x`", "await tag`x`;\n");
test("await (tag`x`)", "await tag`x`;\n"); test("await (tag`x`)", "await tag`x`;\n");