From 36aab1267879d476373ff490d8821fda8c1ab6d7 Mon Sep 17 00:00:00 2001 From: Sung Ye In <66503450+syi0808@users.noreply.github.com> Date: Tue, 30 Jul 2024 09:34:41 +0900 Subject: [PATCH] fix: add decoratorAutoAccessors plugin (#594) * fix: add decoratorAutoAccessors plugin * test: add test for decorator auto accessor * move test into src --- .npmignore | 1 + package.json | 1 + .../__tests__/__snapshots__/tsx-test.js.snap | 1 + parser/tsOptions.js | 1 + .../ts-decorator-auto-accessor-test.js | 26 +++++++++++++++++++ 5 files changed, 30 insertions(+) create mode 100644 src/__tests__/ts-decorator-auto-accessor-test.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 32a3f1bb..08c2af46 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,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/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', 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', + ); +});