aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-20 00:06:27 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-20 00:06:27 -0800
commit3a100af876836fcdbe9b36da0642289284cd6a1b (patch)
tree166c1efa64a89046b00479d426be40bd299fa347
parent7d7b5350147e16bee0c173eef995b6abe6250932 (diff)
downloadbun-3a100af876836fcdbe9b36da0642289284cd6a1b.tar.gz
bun-3a100af876836fcdbe9b36da0642289284cd6a1b.tar.zst
bun-3a100af876836fcdbe9b36da0642289284cd6a1b.zip
Fixes #1855
-rw-r--r--src/js_parser.zig11
-rw-r--r--test/bun.js/transpiler.test.js51
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')",