From d91e8974130735fd43cd9c37d6147fe20f6b3290 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 27 Feb 2022 03:37:31 -0800 Subject: [TS Parser] Implement `constructor(private foo)` Input: ``` class Foo { constructor(public bar: string = "baz") {} bar: number; } ``` Output: ``` class Foo { bar; constructor(bar = "baz") { this.bar = bar; } baz; } ``` --- integration/bunjs-only-snippets/transpiler.test.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'integration/bunjs-only-snippets/transpiler.test.js') diff --git a/integration/bunjs-only-snippets/transpiler.test.js b/integration/bunjs-only-snippets/transpiler.test.js index f510cef74..34120e2d2 100644 --- a/integration/bunjs-only-snippets/transpiler.test.js +++ b/integration/bunjs-only-snippets/transpiler.test.js @@ -765,6 +765,27 @@ describe("Bun.Transpiler", () => { expectPrinted_("delete foo?.bar?.baz", "delete foo?.bar?.baz"); }); + it("useDefineForConst TypeScript class initialization", () => { + var { expectPrinted_ } = ts; + expectPrinted_( + ` +class Foo { + constructor(public x: string = "hey") {} + bar: number; +} +`.trim(), + ` +class Foo { + x; + constructor(x = "hey") { + this.x = x; + } + bar; +} +`.trim() + ); + }); + it("class static blocks", () => { expectPrinted_( "class Foo { static {} }", -- cgit v1.2.3