aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-04-26 21:07:40 -0700
committerGravatar GitHub <noreply@github.com> 2023-04-26 21:07:40 -0700
commit6c6118e2103c4d6a64b45f4970044277936f0fa4 (patch)
tree64d0dd6a8e19e8b26575fd8fbe991d5b13c866b3
parent55c05c0a1fad507b9be2209dbc26a61ec2e01df3 (diff)
downloadbun-6c6118e2103c4d6a64b45f4970044277936f0fa4.tar.gz
bun-6c6118e2103c4d6a64b45f4970044277936f0fa4.tar.zst
bun-6c6118e2103c4d6a64b45f4970044277936f0fa4.zip
Fixes #2746 (#2748)
* Fixes #2746 * add test --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to '')
-rw-r--r--src/js_lexer_tables.zig8
-rw-r--r--src/js_parser.zig2
-rw-r--r--test/bundler/transpiler.test.js12
3 files changed, 20 insertions, 2 deletions
diff --git a/src/js_lexer_tables.zig b/src/js_lexer_tables.zig
index 7ca41ca28..dcf04573f 100644
--- a/src/js_lexer_tables.zig
+++ b/src/js_lexer_tables.zig
@@ -10,6 +10,9 @@ const ComptimeStringMap = @import("./comptime_string_map.zig").ComptimeStringMap
pub const T = enum(u8) {
t_end_of_file,
+ // close brace is here so that we can do comparisons against EOF or close brace in one branch
+ t_close_brace,
+
t_syntax_error,
// "#!/usr/bin/env node"
@@ -35,7 +38,6 @@ pub const T = enum(u8) {
t_bar,
t_bar_bar,
t_caret,
- t_close_brace,
t_close_bracket,
t_close_paren,
t_colon,
@@ -151,6 +153,10 @@ pub const T = enum(u8) {
},
}
}
+
+ pub fn isCloseBraceOrEOF(self: T) bool {
+ return @enumToInt(self) <= @enumToInt(T.t_close_brace);
+ }
};
pub const Keywords = ComptimeStringMap(T, .{
diff --git a/src/js_parser.zig b/src/js_parser.zig
index 72d75d160..abecc989c 100644
--- a/src/js_parser.zig
+++ b/src/js_parser.zig
@@ -12304,7 +12304,7 @@ fn NewParser_(
const scopeIndex = p.pushScopeForParsePass(.class_body, body_loc) catch unreachable;
var opts = PropertyOpts{ .is_class = true, .allow_ts_decorators = class_opts.allow_ts_decorators, .class_has_extends = extends != null };
- while (p.lexer.token != T.t_close_brace) {
+ while (!p.lexer.token.isCloseBraceOrEOF()) {
if (p.lexer.token == .t_semicolon) {
try p.lexer.next();
continue;
diff --git a/test/bundler/transpiler.test.js b/test/bundler/transpiler.test.js
index 407aaf197..7af8f2d27 100644
--- a/test/bundler/transpiler.test.js
+++ b/test/bundler/transpiler.test.js
@@ -73,6 +73,18 @@ describe("Bun.Transpiler", () => {
ts.expectPrinted_("console.log(`\r\n\r\n\r\n`)", "console.log(`\n\n\n`);\n");
});
+ it("doesn't hang indefinitely #2746", () => {
+ // this test passes by not hanging
+ expect(() =>
+ transpiler.transformSync(`
+ class Test {
+ test() {
+
+ }
+ `),
+ ).toThrow();
+ });
+
describe("property access inlining", () => {
it("bails out with spread", () => {
ts.expectPrinted_("const a = [...b][0];", "const a = [...b][0]");