From a223e4ea253da5a2de349fe26a4ae9980aaa3bc5 Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Fri, 9 Aug 2024 00:46:13 -0700 Subject: [PATCH] fix: stripe type with class modifiers Fixes: https://github.com/nodejs/node/issues/54282 Upstream: https://github.com/swc-project/swc/pull/9399 --- test/index.test.js | 21 +++++++++++++++++++++ test/snapshots/index.test.js.snapshot | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/test/index.test.js b/test/index.test.js index 4fe2cc1b4..374245a69 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -97,6 +97,27 @@ test("should handle User type and isAdult function", (t) => { t.assert.snapshot(code); }); +test("should handle class modifiers", (t) => { + const inputCode = ` + class PrivateConstructor { + private constructor() {} + public a() {} + protected b() {} + static create() { + return new PrivateConstructor() + } + } + + const ins = PrivateConstructor.create() + console.log(ins) + `; + const { code } = transformSync(inputCode); + t.assert.snapshot(code); + assert.strictEqual(code.includes("private"), false); + assert.strictEqual(code.includes("protected"), false); + assert.strictEqual(code.includes("public"), false); +}); + test("should handle empty source code", (t) => { assert.strictEqual(transformSync().code, ""); assert.throws(() => transformSync({}).code); diff --git a/test/snapshots/index.test.js.snapshot b/test/snapshots/index.test.js.snapshot index fe7c179d9..35fd82a81 100644 --- a/test/snapshots/index.test.js.snapshot +++ b/test/snapshots/index.test.js.snapshot @@ -2,6 +2,10 @@ exports[`should handle User type and isAdult function 1`] = ` "\\n \\n \\n \\n \\n\\n function isAdult(user ) {\\n return user.age >= 18;\\n }\\n " `; +exports[`should handle class modifiers 1`] = ` +"\\n\\t\\tclass PrivateConstructor {\\n\\t\\t private constructor() {}\\n\\t\\t a() {}\\n\\t\\t b() {}\\n\\t\\t static create() {\\n\\t\\t return new PrivateConstructor()\\n\\t\\t }\\n\\t\\t}\\n\\n\\t\\tconst ins = PrivateConstructor.create()\\n\\t\\tconsole.log(ins)\\n\\t" +`; + exports[`should perform type stripping 1`] = ` "const foo = 'bar';" `;