From 9fee19dc0e42d3c0c895168068b5c865c0e7523f Mon Sep 17 00:00:00 2001 From: syi0808 Date: Wed, 10 Jul 2024 21:02:17 +0900 Subject: [PATCH 1/3] fix: add decoratorAutoAccessors plugin --- parser/tsOptions.js | 1 + 1 file changed, 1 insertion(+) diff --git a/parser/tsOptions.js b/parser/tsOptions.js index 05e249a9..040d185a 100644 --- a/parser/tsOptions.js +++ b/parser/tsOptions.js @@ -19,6 +19,7 @@ module.exports = { tokens: true, plugins: [ 'asyncGenerators', + 'decoratorAutoAccessors', 'bigInt', 'classPrivateMethods', 'classPrivateProperties', From e9a5ea7a6d6dc12b48be3fa608a05c48c21a7c60 Mon Sep 17 00:00:00 2001 From: syi0808 Date: Thu, 11 Jul 2024 09:50:10 +0900 Subject: [PATCH 2/3] test: add test for decorator auto accessor --- .npmignore | 1 + package.json | 1 + parser/__tests__/__snapshots__/tsx-test.js.snap | 1 + .../ts-decorator-auto-accessor.input.ts | 3 +++ .../ts-decorator-auto-accessor.output.ts | 3 +++ test/__tests__/ts-decorator-auto-accessor-test.js | 10 ++++++++++ test/ts-decorator-auto-accessor.js | 7 +++++++ 7 files changed, 26 insertions(+) create mode 100644 test/__testfixtures__/ts-decorator-auto-accessor.input.ts create mode 100644 test/__testfixtures__/ts-decorator-auto-accessor.output.ts create mode 100644 test/__tests__/ts-decorator-auto-accessor-test.js create mode 100644 test/ts-decorator-auto-accessor.js diff --git a/.npmignore b/.npmignore index df200e04..5edfbd7b 100644 --- a/.npmignore +++ b/.npmignore @@ -1,4 +1,5 @@ /docs/ +/test/ /sample/ /recipes/ .gitignore diff --git a/package.json b/package.json index d81a72c5..6658aada 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ }, "jest": { "roots": [ + "test", "src", "bin", "parser", diff --git a/parser/__tests__/__snapshots__/tsx-test.js.snap b/parser/__tests__/__snapshots__/tsx-test.js.snap index 1811f477..1fd8f03a 100644 --- a/parser/__tests__/__snapshots__/tsx-test.js.snap +++ b/parser/__tests__/__snapshots__/tsx-test.js.snap @@ -9,6 +9,7 @@ exports[`tsxParser parse extends the ts config with jsx support 1`] = ` "plugins": [ "jsx", "asyncGenerators", + "decoratorAutoAccessors", "bigInt", "classPrivateMethods", "classPrivateProperties", diff --git a/test/__testfixtures__/ts-decorator-auto-accessor.input.ts b/test/__testfixtures__/ts-decorator-auto-accessor.input.ts new file mode 100644 index 00000000..1e9dde9e --- /dev/null +++ b/test/__testfixtures__/ts-decorator-auto-accessor.input.ts @@ -0,0 +1,3 @@ +export class Test { + public accessor myValue = 10; +} \ No newline at end of file diff --git a/test/__testfixtures__/ts-decorator-auto-accessor.output.ts b/test/__testfixtures__/ts-decorator-auto-accessor.output.ts new file mode 100644 index 00000000..1e9dde9e --- /dev/null +++ b/test/__testfixtures__/ts-decorator-auto-accessor.output.ts @@ -0,0 +1,3 @@ +export class Test { + public accessor myValue = 10; +} \ No newline at end of file diff --git a/test/__tests__/ts-decorator-auto-accessor-test.js b/test/__tests__/ts-decorator-auto-accessor-test.js new file mode 100644 index 00000000..a8ecc541 --- /dev/null +++ b/test/__tests__/ts-decorator-auto-accessor-test.js @@ -0,0 +1,10 @@ +"use strict"; + +jest.autoMockOff(); +const defineTest = require("../../src/testUtils").defineTest; + +describe("should be parse typescript decoratorAutoAccessors correctly", function () { + defineTest(__dirname, "ts-decorator-auto-accessor", null, null, { + parser: "ts", + }); +}); diff --git a/test/ts-decorator-auto-accessor.js b/test/ts-decorator-auto-accessor.js new file mode 100644 index 00000000..a74bd16a --- /dev/null +++ b/test/ts-decorator-auto-accessor.js @@ -0,0 +1,7 @@ +function transformer(file, api) { + const j = api.jscodeshift; + + return j(file.source).toSource(); +} + +module.exports = transformer; From 48e52c5bdc5cf9f330e6d5b72d574b227aae3f01 Mon Sep 17 00:00:00 2001 From: syi0808 Date: Tue, 30 Jul 2024 09:13:25 +0900 Subject: [PATCH 3/3] move test into src --- .../ts-decorator-auto-accessor-test.js | 26 +++++++++++++++++++ .../ts-decorator-auto-accessor.input.ts | 3 --- .../ts-decorator-auto-accessor.output.ts | 3 --- .../ts-decorator-auto-accessor-test.js | 10 ------- test/ts-decorator-auto-accessor.js | 7 ----- 5 files changed, 26 insertions(+), 23 deletions(-) create mode 100644 src/__tests__/ts-decorator-auto-accessor-test.js delete mode 100644 test/__testfixtures__/ts-decorator-auto-accessor.input.ts delete mode 100644 test/__testfixtures__/ts-decorator-auto-accessor.output.ts delete mode 100644 test/__tests__/ts-decorator-auto-accessor-test.js delete mode 100644 test/ts-decorator-auto-accessor.js diff --git a/src/__tests__/ts-decorator-auto-accessor-test.js b/src/__tests__/ts-decorator-auto-accessor-test.js new file mode 100644 index 00000000..3e18275e --- /dev/null +++ b/src/__tests__/ts-decorator-auto-accessor-test.js @@ -0,0 +1,26 @@ +'use strict'; + +function transformer(file, api) { + const j = api.jscodeshift; + + return j(file.source).toSource(); +} + +transformer.parser = 'ts'; + +jest.autoMockOff(); +const defineInlineTest = require('../../src/testUtils').defineInlineTest; + +describe('should be parse typescript decoratorAutoAccessors correctly', function () { + defineInlineTest( + transformer, + {}, + 'export class Test {\n' + + ' public accessor myValue = 10;\n' + + '}\n', + 'export class Test {\n' + + ' public accessor myValue = 10;\n' + + '}', + 'ts-decorator-auto-accessor', + ); +}); diff --git a/test/__testfixtures__/ts-decorator-auto-accessor.input.ts b/test/__testfixtures__/ts-decorator-auto-accessor.input.ts deleted file mode 100644 index 1e9dde9e..00000000 --- a/test/__testfixtures__/ts-decorator-auto-accessor.input.ts +++ /dev/null @@ -1,3 +0,0 @@ -export class Test { - public accessor myValue = 10; -} \ No newline at end of file diff --git a/test/__testfixtures__/ts-decorator-auto-accessor.output.ts b/test/__testfixtures__/ts-decorator-auto-accessor.output.ts deleted file mode 100644 index 1e9dde9e..00000000 --- a/test/__testfixtures__/ts-decorator-auto-accessor.output.ts +++ /dev/null @@ -1,3 +0,0 @@ -export class Test { - public accessor myValue = 10; -} \ No newline at end of file diff --git a/test/__tests__/ts-decorator-auto-accessor-test.js b/test/__tests__/ts-decorator-auto-accessor-test.js deleted file mode 100644 index a8ecc541..00000000 --- a/test/__tests__/ts-decorator-auto-accessor-test.js +++ /dev/null @@ -1,10 +0,0 @@ -"use strict"; - -jest.autoMockOff(); -const defineTest = require("../../src/testUtils").defineTest; - -describe("should be parse typescript decoratorAutoAccessors correctly", function () { - defineTest(__dirname, "ts-decorator-auto-accessor", null, null, { - parser: "ts", - }); -}); diff --git a/test/ts-decorator-auto-accessor.js b/test/ts-decorator-auto-accessor.js deleted file mode 100644 index a74bd16a..00000000 --- a/test/ts-decorator-auto-accessor.js +++ /dev/null @@ -1,7 +0,0 @@ -function transformer(file, api) { - const j = api.jscodeshift; - - return j(file.source).toSource(); -} - -module.exports = transformer;