aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Dylan Conway <35280289+dylan-conway@users.noreply.github.com> 2023-07-19 15:39:15 -0700
committerGravatar GitHub <noreply@github.com> 2023-07-19 15:39:15 -0700
commitbc28ec39cf6f345374598a64c5ef4697261e9c9e (patch)
tree518889cc66a5024e2a3d696939f906c9ffa889fd
parent568cadb51e971e568f35ac3efe36202e656c0fe6 (diff)
downloadbun-bc28ec39cf6f345374598a64c5ef4697261e9c9e.tar.gz
bun-bc28ec39cf6f345374598a64c5ef4697261e9c9e.tar.zst
bun-bc28ec39cf6f345374598a64c5ef4697261e9c9e.zip
set `did_panic` flag (#3687)
-rw-r--r--src/js_lexer.zig1
-rw-r--r--src/js_parser.zig6
-rw-r--r--test/transpiler/transpiler.test.js7
3 files changed, 13 insertions, 1 deletions
diff --git a/src/js_lexer.zig b/src/js_lexer.zig
index e8b852d0d..a0ad75c7b 100644
--- a/src/js_lexer.zig
+++ b/src/js_lexer.zig
@@ -1793,6 +1793,7 @@ fn NewLexer_(
}
};
+ lexer.did_panic = true;
try lexer.addRangeError(lexer.range(), "Unexpected {s}", .{found}, true);
}
diff --git a/src/js_parser.zig b/src/js_parser.zig
index d20c1a868..2d00654c9 100644
--- a/src/js_parser.zig
+++ b/src/js_parser.zig
@@ -11633,7 +11633,11 @@ fn NewParser_(
error.Backtrack => {
backtrack = true;
},
- else => {},
+ else => {
+ if (p.lexer.did_panic) {
+ backtrack = true;
+ }
+ },
}
if (comptime FnReturnType == anyerror!bool or FnReturnType == anyerror!void)
// we are not using the value
diff --git a/test/transpiler/transpiler.test.js b/test/transpiler/transpiler.test.js
index 3040a9913..f83c00296 100644
--- a/test/transpiler/transpiler.test.js
+++ b/test/transpiler/transpiler.test.js
@@ -106,6 +106,13 @@ describe("Bun.Transpiler", () => {
ts.expectPrinted_("import Foo = Baz.Bar;\nexport default Foo;", "const Foo = Baz.Bar;\nexport default Foo");
});
+ it("ternary should parse correctly when parsing typescript fails", () => {
+ ts.expectPrinted_(
+ "var c = Math.random() ? ({ ...{} }) : ({ ...{} })",
+ "var c = Math.random() ? { ...{} } : { ...{} }",
+ );
+ });
+
it.todo("instantiation expressions", async () => {
const exp = ts.expectPrinted_;
const err = ts.expectParseError;