Skip to content

Commit

Permalink
transpiler: fix crash with malformed enums (#16084)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-conway authored Dec 31, 2024
1 parent babd8b6 commit 37e7f5b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/js_parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11917,6 +11917,8 @@ fn NewParser_(
needs_symbol = true;
} else {
try p.lexer.expect(.t_identifier);
// error early, name is still `undefined`
return error.SyntaxError;
}
try p.lexer.next();

Expand Down
7 changes: 7 additions & 0 deletions test/bundler/transpiler/transpiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,13 @@ describe("Bun.Transpiler", () => {
exp("f<{}>()\nfunction f<T>() {}", "let f = function() {\n};\nf()");
});

it("malformed enums", () => {
const err = ts.expectParseError;

err("enum Foo { [2]: 'hi' }", 'Expected identifier but found "["');
err("enum [] { a }", 'Expected identifier but found "["');
});

// TODO: fix all the cases that report generic "Parse error"
it("types", () => {
const exp = ts.expectPrinted_;
Expand Down

0 comments on commit 37e7f5b

Please sign in to comment.