diff options
-rw-r--r-- | src/js_parser.zig | 11 | ||||
-rw-r--r-- | test/bun.js/transpiler.test.js | 51 |
2 files changed, 57 insertions, 5 deletions
diff --git a/src/js_parser.zig b/src/js_parser.zig index c20300daa..ee54a892a 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -16935,12 +16935,13 @@ fn NewParser_( ) []Stmt { switch (stmtorexpr) { .stmt => |stmt| { - if (!stmt.data.s_class.class.has_decorators) { - var stmts = p.allocator.alloc(Stmt, 1) catch unreachable; - stmts[0] = stmt; - return stmts; + if (comptime !is_typescript_enabled) { + if (!stmt.data.s_class.class.has_decorators) { + var stmts = p.allocator.alloc(Stmt, 1) catch unreachable; + stmts[0] = stmt; + return stmts; + } } - var class = &stmt.data.s_class.class; var constructor_function: ?*E.Function = null; diff --git a/test/bun.js/transpiler.test.js b/test/bun.js/transpiler.test.js index dcc7f397a..a51b49235 100644 --- a/test/bun.js/transpiler.test.js +++ b/test/bun.js/transpiler.test.js @@ -80,6 +80,57 @@ describe("Bun.Transpiler", () => { ); }); + it("class constructor", () => { + const fixtures = [ + [ + `class Test { + b: string; + + constructor(private a: string) { + this.b = a; + } + }`, + + ` +class Test { + a; + b; + constructor(a) { + this.b = a; + this.a = a; + } +} + `.trim(), + ], + [ + `class Test extends Bar { + b: string; + + constructor(private a: string) { + super(); + this.b = a; + } + }`, + + ` +class Test extends Bar { + a; + b; + constructor(a) { + super(); + this.b = a; + this.a = a; + } +} + `.trim(), + ], + ]; + + for (const [code, out] of fixtures) { + expect(ts.parsed(code, false, false).trim()).toBe(out); + } + }); + it("import Foo = require('bar')", () => { ts.expectPrinted_( "import React = require('react')", |