diff options
author | 2023-07-21 01:35:06 -0700 | |
---|---|---|
committer | 2023-07-21 01:35:06 -0700 | |
commit | aa1ad7f009173ae01e41f005c563b902f53906c3 (patch) | |
tree | 90bde80bcbdf99055fdd705d4832eb9ad56c62b8 /src | |
parent | 21bb3b2bdd39297395c59e8fe49ae73c8dfc2bb7 (diff) | |
download | bun-aa1ad7f009173ae01e41f005c563b902f53906c3.tar.gz bun-aa1ad7f009173ae01e41f005c563b902f53906c3.tar.zst bun-aa1ad7f009173ae01e41f005c563b902f53906c3.zip |
string escape edgecase (#3717)bun-v0.7.0
* fix edgecase when joining rope strings with backtick
* bonus bugfix in ts decorator
* Update transpiler.test.js
* Fix test
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/js_parser.zig | 5 | ||||
-rw-r--r-- | src/js_printer.zig | 13 |
2 files changed, 16 insertions, 2 deletions
diff --git a/src/js_parser.zig b/src/js_parser.zig index f5dda75f0..6390dfdba 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -213,6 +213,8 @@ fn foldStringAddition(lhs: Expr, rhs: Expr) ?Expr { rhs_clone.data.e_string, ); + orig.prefer_template = orig.prefer_template or rhs_clone.data.e_string.prefer_template; + return Expr.init(E.String, orig, lhs.loc); } }, @@ -19517,7 +19519,8 @@ fn NewParser_( .e_number => |k| p.newExpr(E.Number{ .value = k.value }, loc), .e_string => |k| p.newExpr(E.String{ .data = k.data }, loc), .e_index => |k| p.newExpr(E.Index{ .target = k.target, .index = k.index }, loc), - else => unreachable, + .e_private_identifier => |k| p.newExpr(E.PrivateIdentifier{ .ref = k.ref }, loc), + else => bun.unreachablePanic("Unexpected AST node type {any}", .{prop.key.?}), }; const descriptor_kind: f64 = if (!prop.flags.contains(.is_method)) 2 else 1; diff --git a/src/js_printer.zig b/src/js_printer.zig index 08a1cb5c1..1f920327c 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -2592,7 +2592,7 @@ fn NewPrinter( p.addSourceMapping(expr.loc); // If this was originally a template literal, print it as one as long as we're not minifying - if (e.prefer_template) { + if (e.prefer_template and !p.options.minify_syntax) { p.print("`"); p.printStringContent(e, '`'); p.print("`"); @@ -3065,6 +3065,17 @@ fn NewPrinter( while (i < len) { switch (utf8[i]) { '\\' => i += 2, + '$' => { + if (comptime c == '`') { + p.print(utf8[0..i]); + p.print("\\$"); + utf8 = utf8[i + 1 ..]; + len = utf8.len; + i = 0; + } else { + i += 1; + } + }, c => { p.print(utf8[0..i]); p.print("\\" ++ &[_]u8{c}); |