diff options
author | 2023-01-13 12:48:10 -0800 | |
---|---|---|
committer | 2023-01-13 12:48:10 -0800 | |
commit | 88ffdc5fec9d2f99e891fc6a282c940f08428cfb (patch) | |
tree | 7157acfad0165ab242b1844dd3d169d41a8390b7 | |
parent | fab42148e45572c929efd69f0a818eb972b96225 (diff) | |
download | bun-88ffdc5fec9d2f99e891fc6a282c940f08428cfb.tar.gz bun-88ffdc5fec9d2f99e891fc6a282c940f08428cfb.tar.zst bun-88ffdc5fec9d2f99e891fc6a282c940f08428cfb.zip |
[TypeScript transpiler] Fix bug with `export default class implements`
-rw-r--r-- | src/js_parser.zig | 10 | ||||
-rw-r--r-- | test/bun.js/transpiler.test.js | 25 |
2 files changed, 30 insertions, 5 deletions
diff --git a/src/js_parser.zig b/src/js_parser.zig index 86dabc005..fbfaa3a43 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -6782,7 +6782,7 @@ fn NewParser_( fn parseClassStmt(p: *P, loc: logger.Loc, opts: *ParseStatementOptions) !Stmt { var name: ?js_ast.LocRef = null; - var class_keyword = p.lexer.range(); + const class_keyword = p.lexer.range(); if (p.lexer.token == .t_class) { //marksyntaxfeature try p.lexer.next(); @@ -6790,11 +6790,11 @@ fn NewParser_( try p.lexer.expected(.t_class); } - var is_identifier = p.lexer.token == .t_identifier; + const is_identifier = p.lexer.token == .t_identifier; - if (!opts.is_name_optional or (is_identifier and (!is_typescript_enabled or !strings.eqlComptime(p.lexer.identifier, "interface")))) { - var name_loc = p.lexer.loc(); - var name_text = p.lexer.identifier; + if (!opts.is_name_optional or (is_identifier and (!is_typescript_enabled or !strings.eqlComptime(p.lexer.identifier, "implements")))) { + const name_loc = p.lexer.loc(); + const name_text = p.lexer.identifier; try p.lexer.expect(.t_identifier); // We must return here diff --git a/test/bun.js/transpiler.test.js b/test/bun.js/transpiler.test.js index 94c3d52d2..05607091a 100644 --- a/test/bun.js/transpiler.test.js +++ b/test/bun.js/transpiler.test.js @@ -106,6 +106,31 @@ describe("Bun.Transpiler", () => { ts.expectPrinted_("export = {foo: 123}", "module.exports = { foo: 123 }"); }); + it("export default class implements TypeScript regression", () => { + expect( + transpiler + .transformSync( + ` + export default class implements ITest { + async* runTest(path: string): AsyncGenerator<number> { + yield Math.random(); + } + } + `, + "ts", + ) + .trim(), + ).toBe( + ` +export default class { + async* runTest(path) { + yield Math.random(); + } +} + `.trim(), + ); + }); + it("satisfies", () => { ts.expectPrinted_( "const t1 = { a: 1 } satisfies I1;", |