diff options
author | 2023-04-12 17:42:56 -0700 | |
---|---|---|
committer | 2023-04-12 17:42:56 -0700 | |
commit | d8d4abb58e1179800e2a72834e6506ec49384a7b (patch) | |
tree | a42bc2c6b8fe38041288e8269145a948332bca9d | |
parent | 4b9b648f8a571a040fa749093b96b5a629cec45d (diff) | |
download | bun-d8d4abb58e1179800e2a72834e6506ec49384a7b.tar.gz bun-d8d4abb58e1179800e2a72834e6506ec49384a7b.tar.zst bun-d8d4abb58e1179800e2a72834e6506ec49384a7b.zip |
don't increment `i` if escaped (#2639)
Diffstat (limited to '')
-rw-r--r-- | src/js_printer.zig | 12 | ||||
-rw-r--r-- | test/bundler/transpiler.test.js | 3 |
2 files changed, 10 insertions, 5 deletions
diff --git a/src/js_printer.zig b/src/js_printer.zig index da6a7fcb7..1bf1fabd2 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -2894,11 +2894,10 @@ fn NewPrinter( // Walk the string searching for quote characters // Escape any we find // Skip over already-escaped strings - while (i < utf8.len) : (i += 1) { + var len = utf8.len; + while (i < len) { switch (utf8[i]) { - '\\' => { - i += 1; - }, + '\\' => i += 2, // We must escape here for JSX string literals that contain unescaped newlines // Those will get transformed into a template string // which can potentially have unescaped $ @@ -2908,17 +2907,20 @@ fn NewPrinter( p.print("\\$"); utf8 = utf8[i + 1 ..]; + len = utf8.len; i = 0; } + i += 1; }, c => { p.print(utf8[0..i]); p.print("\\" ++ &[_]u8{c}); utf8 = utf8[i + 1 ..]; + len = utf8.len; i = 0; }, - else => {}, + else => i += 1, } } if (utf8.len > 0) { diff --git a/test/bundler/transpiler.test.js b/test/bundler/transpiler.test.js index da7a7d00d..cde968f80 100644 --- a/test/bundler/transpiler.test.js +++ b/test/bundler/transpiler.test.js @@ -2952,6 +2952,9 @@ console.log(foo, array); it('`str` + "``"', () => { expectPrinted_('const x = `str` + "``";', "const x = `str\\`\\``"); + expectPrinted_('const x = `` + "`";', "const x = `\\``"); + expectPrinted_('const x = `` + "``";', "const x = `\\`\\``"); + expectPrinted_('const x = "``" + ``;', 'const x = "``"'); }); }); }); |