diff --git a/src/language-js/traverse/visitor-keys.evaluate.js b/src/language-js/traverse/visitor-keys.evaluate.js index 50f079c80..14e9bf55e 100644 --- a/src/language-js/traverse/visitor-keys.evaluate.js +++ b/src/language-js/traverse/visitor-keys.evaluate.js @@ -38,6 +38,9 @@ const excludeVisitorKeys = { // Flow node from Babel TupleTypeAnnotation: ["types"], + + // Babel, `decorators` are invalid + TSDeclareMethod: ["decorators"], }; const excludeNodeTypes = [ diff --git a/tests/format/misc/errors/typescript/modifiers/__snapshots__/format.test.js.snap b/tests/format/misc/errors/typescript/modifiers/__snapshots__/format.test.js.snap index f07d8237b..b44f2fdee 100644 --- a/tests/format/misc/errors/typescript/modifiers/__snapshots__/format.test.js.snap +++ b/tests/format/misc/errors/typescript/modifiers/__snapshots__/format.test.js.snap @@ -3708,20 +3708,20 @@ Cause: A parameter property is only allowed in a constructor implementation." exports[`snippet: #167 [babel-ts] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:33) -> 1 | class Foo {['const' + 'ructor'](private parameter) {}} +> 1 | class Foo {['construct' + 'or'](private parameter) {}} | ^ Cause: A parameter property is only allowed in a constructor implementation. (1:32)" `; exports[`snippet: #167 [oxc-ts] format 1`] = ` "'private' modifier cannot appear on a parameter. (1:33) -> 1 | class Foo {['const' + 'ructor'](private parameter) {}} +> 1 | class Foo {['construct' + 'or'](private parameter) {}} | ^^^^^^^" `; exports[`snippet: #167 [typescript] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:33) -> 1 | class Foo {['const' + 'ructor'](private parameter) {}} +> 1 | class Foo {['construct' + 'or'](private parameter) {}} | ^^^^^^^ Cause: A parameter property is only allowed in a constructor implementation." `; diff --git a/tests/format/misc/errors/typescript/modifiers/format.test.js b/tests/format/misc/errors/typescript/modifiers/format.test.js index d1998ac4f..bf05c81af 100644 --- a/tests/format/misc/errors/typescript/modifiers/format.test.js +++ b/tests/format/misc/errors/typescript/modifiers/format.test.js @@ -124,8 +124,7 @@ runFormatTest( 'class Foo {["constructor"](private parameter) {}}', "class Foo {['constructor'](private parameter) {}}", "class Foo {[`constructor`](private parameter) {}}", - // cspell:disable-next-line - "class Foo {['const' + 'ructor'](private parameter) {}}", + "class Foo {['construct' + 'or'](private parameter) {}}", // `TSPropertySignature` ...POSSIBLE_MODIFIERS.filter((modifier) => modifier !== "readonly").map( diff --git a/tests/format/typescript/decorators/__snapshots__/format.test.js.snap b/tests/format/typescript/decorators/__snapshots__/format.test.js.snap index 05bbdb972..6f9e0e183 100644 --- a/tests/format/typescript/decorators/__snapshots__/format.test.js.snap +++ b/tests/format/typescript/decorators/__snapshots__/format.test.js.snap @@ -1,46 +1,5 @@ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing -exports[`abstract-method.ts [babel-ts] format 1`] = ` -====================================options===================================== -parsers: ["typescript"] -printWidth: 80 - | printWidth -=====================================input====================================== -class A { - @decorator() - abstract method(): Array -} - -=====================================output===================================== -class A { - @decorator() - abstract method(): Array; -} - -================================================================================ -`; - -exports[`abstract-method.ts [oxc-ts] format 1`] = ` -"A decorator can only decorate a method implementation, not an overload. (2:5) - 1 | class A { -> 2 | @decorator() - | ^^^^^^^^^^^^ - 3 | abstract method(): Array - 4 | } - 5 |" -`; - -exports[`abstract-method.ts [typescript] format 1`] = ` -"A decorator can only decorate a method implementation, not an overload. (2:5) - 1 | class A { -> 2 | @decorator() - | ^^^^^^^^^^^^ - 3 | abstract method(): Array - 4 | } - 5 | -Cause: A decorator can only decorate a method implementation, not an overload." -`; - exports[`accessor.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/format/typescript/decorators/abstract-method.ts b/tests/format/typescript/decorators/abstract-method.ts deleted file mode 100644 index b93e1ec3f..000000000 --- a/tests/format/typescript/decorators/abstract-method.ts +++ /dev/null @@ -1,4 +0,0 @@ -class A { - @decorator() - abstract method(): Array -} diff --git a/tests/format/typescript/decorators/format.test.js b/tests/format/typescript/decorators/format.test.js index 91c4c595a..116dcbd78 100644 --- a/tests/format/typescript/decorators/format.test.js +++ b/tests/format/typescript/decorators/format.test.js @@ -1,7 +1 @@ -runFormatTest(import.meta, ["typescript"], { - errors: { - typescript: ["abstract-method.ts"], - "oxc-ts": ["abstract-method.ts"], - "babel-ts": ["issue-9102.ts"], - }, -}); +runFormatTest(import.meta, ["typescript"]); diff --git a/tests/unit/__snapshots__/visitor-keys.js.snap b/tests/unit/__snapshots__/visitor-keys.js.snap index 90d31eeec..8a7dc21e7 100644 --- a/tests/unit/__snapshots__/visitor-keys.js.snap +++ b/tests/unit/__snapshots__/visitor-keys.js.snap @@ -883,7 +883,6 @@ exports[`visitor keys estree 1`] = ` ], "TSDeclareKeyword": [], "TSDeclareMethod": [ - "decorators", "key", "params", "returnType",