From dcdbc76d5418a383968d15e32d2eba7a9d2d7e79 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Fri, 17 Mar 2023 09:17:21 +0800 Subject: [PATCH] feat(typescript-estree): throw errors when abstract property has initializer (#6613) Co-authored-by: Josh Goldberg Co-authored-by: Brad Zacher --- .../fixture.ts | 0 .../snapshots/1-TSESTree-Error.shot | 10 ++ .../snapshots/2-Babel-Error.shot | 3 + .../snapshots/3-Alignment-Error.shot | 3 + .../fixture.ts | 3 + .../snapshots/1-TSESTree-Error.shot | 10 ++ .../snapshots/2-Babel-Error.shot | 3 + .../snapshots/3-Alignment-Error.shot | 3 + .../snapshots/1-TSESTree-AST.shot | 101 ------------- .../snapshots/2-TSESTree-Tokens.shot | 136 ------------------ .../snapshots/3-Babel-AST.shot | 99 ------------- .../snapshots/4-Babel-Tokens.shot | 136 ------------------ .../snapshots/5-AST-Alignment-AST.shot | 119 --------------- .../snapshots/6-AST-Alignment-Tokens.shot | 6 - .../snapshots/1-TSESTree-Error.shot | 10 +- .../snapshots/3-Alignment-Error.shot | 2 +- .../tests/fixtures-with-differences-ast.shot | 1 - .../fixtures-with-differences-errors.shot | 2 +- .../naming-convention/cases/property.test.ts | 2 +- packages/typescript-estree/src/convert.ts | 9 +- 20 files changed, 55 insertions(+), 603 deletions(-) rename packages/ast-spec/src/element/AccessorProperty/fixtures/{modifier-abstract-with-value => _error_/modifier-abstract-accessor-with-value}/fixture.ts (100%) create mode 100644 packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-accessor-with-value/snapshots/1-TSESTree-Error.shot create mode 100644 packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-accessor-with-value/snapshots/2-Babel-Error.shot create mode 100644 packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-accessor-with-value/snapshots/3-Alignment-Error.shot create mode 100644 packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-property-with-value/fixture.ts create mode 100644 packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-property-with-value/snapshots/1-TSESTree-Error.shot create mode 100644 packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-property-with-value/snapshots/2-Babel-Error.shot create mode 100644 packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-property-with-value/snapshots/3-Alignment-Error.shot delete mode 100644 packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/1-TSESTree-AST.shot delete mode 100644 packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/2-TSESTree-Tokens.shot delete mode 100644 packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/3-Babel-AST.shot delete mode 100644 packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/4-Babel-Tokens.shot delete mode 100644 packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/5-AST-Alignment-AST.shot delete mode 100644 packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/6-AST-Alignment-Tokens.shot diff --git a/packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/fixture.ts b/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-accessor-with-value/fixture.ts similarity index 100% rename from packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/fixture.ts rename to packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-accessor-with-value/fixture.ts diff --git a/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-accessor-with-value/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-accessor-with-value/snapshots/1-TSESTree-Error.shot new file mode 100644 index 00000000000..77e891766df --- /dev/null +++ b/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-accessor-with-value/snapshots/1-TSESTree-Error.shot @@ -0,0 +1,10 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures element AccessorProperty _error_ modifier-abstract-accessor-with-value TSESTree - Error 1`] = ` +"TSError + 1 | abstract class Foo { +> 2 | abstract accessor foo: number = 1; + | ^ Abstract property cannot have an initializer. + 3 | } + 4 |" +`; diff --git a/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-accessor-with-value/snapshots/2-Babel-Error.shot b/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-accessor-with-value/snapshots/2-Babel-Error.shot new file mode 100644 index 00000000000..f314b35255b --- /dev/null +++ b/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-accessor-with-value/snapshots/2-Babel-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures element AccessorProperty _error_ modifier-abstract-accessor-with-value Babel - Error 1`] = `"NO ERROR"`; diff --git a/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-accessor-with-value/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-accessor-with-value/snapshots/3-Alignment-Error.shot new file mode 100644 index 00000000000..f248419e4f7 --- /dev/null +++ b/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-accessor-with-value/snapshots/3-Alignment-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures element AccessorProperty _error_ modifier-abstract-accessor-with-value Error Alignment 1`] = `"TSESTree errored but Babel didn't"`; diff --git a/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-property-with-value/fixture.ts b/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-property-with-value/fixture.ts new file mode 100644 index 00000000000..de0095c3531 --- /dev/null +++ b/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-property-with-value/fixture.ts @@ -0,0 +1,3 @@ +abstract class Foo { + abstract property = 1; +} diff --git a/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-property-with-value/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-property-with-value/snapshots/1-TSESTree-Error.shot new file mode 100644 index 00000000000..8fc5278de62 --- /dev/null +++ b/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-property-with-value/snapshots/1-TSESTree-Error.shot @@ -0,0 +1,10 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures element AccessorProperty _error_ modifier-abstract-property-with-value TSESTree - Error 1`] = ` +"TSError + 1 | abstract class Foo { +> 2 | abstract property = 1; + | ^ Abstract property cannot have an initializer. + 3 | } + 4 |" +`; diff --git a/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-property-with-value/snapshots/2-Babel-Error.shot b/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-property-with-value/snapshots/2-Babel-Error.shot new file mode 100644 index 00000000000..24fbc900989 --- /dev/null +++ b/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-property-with-value/snapshots/2-Babel-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures element AccessorProperty _error_ modifier-abstract-property-with-value Babel - Error 1`] = `[SyntaxError: Property 'property' cannot have an initializer because it is marked abstract. (2:20)]`; diff --git a/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-property-with-value/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-property-with-value/snapshots/3-Alignment-Error.shot new file mode 100644 index 00000000000..137837e3e8f --- /dev/null +++ b/packages/ast-spec/src/element/AccessorProperty/fixtures/_error_/modifier-abstract-property-with-value/snapshots/3-Alignment-Error.shot @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AST Fixtures element AccessorProperty _error_ modifier-abstract-property-with-value Error Alignment 1`] = `"Both errored"`; diff --git a/packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/1-TSESTree-AST.shot b/packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/1-TSESTree-AST.shot deleted file mode 100644 index dbee0fd62cb..00000000000 --- a/packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/1-TSESTree-AST.shot +++ /dev/null @@ -1,101 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`AST Fixtures element AccessorProperty modifier-abstract-with-value TSESTree - AST 1`] = ` -Program { - type: "Program", - body: [ - ClassDeclaration { - type: "ClassDeclaration", - abstract: true, - body: ClassBody { - type: "ClassBody", - body: [ - TSAbstractAccessorProperty { - type: "TSAbstractAccessorProperty", - computed: false, - declare: false, - decorators: [], - definite: false, - key: Identifier { - type: "Identifier", - decorators: [], - name: "foo", - optional: false, - - range: [41, 44], - loc: { - start: { column: 20, line: 2 }, - end: { column: 23, line: 2 }, - }, - }, - optional: false, - override: false, - readonly: false, - static: false, - typeAnnotation: TSTypeAnnotation { - type: "TSTypeAnnotation", - typeAnnotation: TSNumberKeyword { - type: "TSNumberKeyword", - - range: [46, 52], - loc: { - start: { column: 25, line: 2 }, - end: { column: 31, line: 2 }, - }, - }, - - range: [44, 52], - loc: { - start: { column: 23, line: 2 }, - end: { column: 31, line: 2 }, - }, - }, - value: null, - - range: [23, 57], - loc: { - start: { column: 2, line: 2 }, - end: { column: 36, line: 2 }, - }, - }, - ], - - range: [19, 59], - loc: { - start: { column: 19, line: 1 }, - end: { column: 1, line: 3 }, - }, - }, - declare: false, - decorators: [], - id: Identifier { - type: "Identifier", - decorators: [], - name: "Foo", - optional: false, - - range: [15, 18], - loc: { - start: { column: 15, line: 1 }, - end: { column: 18, line: 1 }, - }, - }, - implements: [], - superClass: null, - - range: [0, 59], - loc: { - start: { column: 0, line: 1 }, - end: { column: 1, line: 3 }, - }, - }, - ], - sourceType: "script", - - range: [0, 60], - loc: { - start: { column: 0, line: 1 }, - end: { column: 0, line: 4 }, - }, -} -`; diff --git a/packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/2-TSESTree-Tokens.shot deleted file mode 100644 index 52b20d04368..00000000000 --- a/packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/2-TSESTree-Tokens.shot +++ /dev/null @@ -1,136 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`AST Fixtures element AccessorProperty modifier-abstract-with-value TSESTree - Tokens 1`] = ` -[ - Identifier { - type: "Identifier", - value: "abstract", - - range: [0, 8], - loc: { - start: { column: 0, line: 1 }, - end: { column: 8, line: 1 }, - }, - }, - Keyword { - type: "Keyword", - value: "class", - - range: [9, 14], - loc: { - start: { column: 9, line: 1 }, - end: { column: 14, line: 1 }, - }, - }, - Identifier { - type: "Identifier", - value: "Foo", - - range: [15, 18], - loc: { - start: { column: 15, line: 1 }, - end: { column: 18, line: 1 }, - }, - }, - Punctuator { - type: "Punctuator", - value: "{", - - range: [19, 20], - loc: { - start: { column: 19, line: 1 }, - end: { column: 20, line: 1 }, - }, - }, - Identifier { - type: "Identifier", - value: "abstract", - - range: [23, 31], - loc: { - start: { column: 2, line: 2 }, - end: { column: 10, line: 2 }, - }, - }, - Identifier { - type: "Identifier", - value: "accessor", - - range: [32, 40], - loc: { - start: { column: 11, line: 2 }, - end: { column: 19, line: 2 }, - }, - }, - Identifier { - type: "Identifier", - value: "foo", - - range: [41, 44], - loc: { - start: { column: 20, line: 2 }, - end: { column: 23, line: 2 }, - }, - }, - Punctuator { - type: "Punctuator", - value: ":", - - range: [44, 45], - loc: { - start: { column: 23, line: 2 }, - end: { column: 24, line: 2 }, - }, - }, - Identifier { - type: "Identifier", - value: "number", - - range: [46, 52], - loc: { - start: { column: 25, line: 2 }, - end: { column: 31, line: 2 }, - }, - }, - Punctuator { - type: "Punctuator", - value: "=", - - range: [53, 54], - loc: { - start: { column: 32, line: 2 }, - end: { column: 33, line: 2 }, - }, - }, - Numeric { - type: "Numeric", - value: "1", - - range: [55, 56], - loc: { - start: { column: 34, line: 2 }, - end: { column: 35, line: 2 }, - }, - }, - Punctuator { - type: "Punctuator", - value: ";", - - range: [56, 57], - loc: { - start: { column: 35, line: 2 }, - end: { column: 36, line: 2 }, - }, - }, - Punctuator { - type: "Punctuator", - value: "}", - - range: [58, 59], - loc: { - start: { column: 0, line: 3 }, - end: { column: 1, line: 3 }, - }, - }, -] -`; diff --git a/packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/3-Babel-AST.shot b/packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/3-Babel-AST.shot deleted file mode 100644 index 94c61988d3b..00000000000 --- a/packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/3-Babel-AST.shot +++ /dev/null @@ -1,99 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`AST Fixtures element AccessorProperty modifier-abstract-with-value Babel - AST 1`] = ` -Program { - type: "Program", - body: [ - ClassDeclaration { - type: "ClassDeclaration", - abstract: true, - body: ClassBody { - type: "ClassBody", - body: [ - ClassAccessorProperty { - type: "ClassAccessorProperty", - abstract: true, - computed: false, - key: Identifier { - type: "Identifier", - name: "foo", - - range: [41, 44], - loc: { - start: { column: 20, line: 2 }, - end: { column: 23, line: 2 }, - }, - }, - static: false, - typeAnnotation: TSTypeAnnotation { - type: "TSTypeAnnotation", - typeAnnotation: TSNumberKeyword { - type: "TSNumberKeyword", - - range: [46, 52], - loc: { - start: { column: 25, line: 2 }, - end: { column: 31, line: 2 }, - }, - }, - - range: [44, 52], - loc: { - start: { column: 23, line: 2 }, - end: { column: 31, line: 2 }, - }, - }, - value: Literal { - type: "Literal", - raw: "1", - value: 1, - - range: [55, 56], - loc: { - start: { column: 34, line: 2 }, - end: { column: 35, line: 2 }, - }, - }, - - range: [23, 57], - loc: { - start: { column: 2, line: 2 }, - end: { column: 36, line: 2 }, - }, - }, - ], - - range: [19, 59], - loc: { - start: { column: 19, line: 1 }, - end: { column: 1, line: 3 }, - }, - }, - id: Identifier { - type: "Identifier", - name: "Foo", - - range: [15, 18], - loc: { - start: { column: 15, line: 1 }, - end: { column: 18, line: 1 }, - }, - }, - superClass: null, - - range: [0, 59], - loc: { - start: { column: 0, line: 1 }, - end: { column: 1, line: 3 }, - }, - }, - ], - sourceType: "script", - - range: [0, 60], - loc: { - start: { column: 0, line: 1 }, - end: { column: 0, line: 4 }, - }, -} -`; diff --git a/packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/4-Babel-Tokens.shot b/packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/4-Babel-Tokens.shot deleted file mode 100644 index ee7c1781984..00000000000 --- a/packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/4-Babel-Tokens.shot +++ /dev/null @@ -1,136 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`AST Fixtures element AccessorProperty modifier-abstract-with-value Babel - Tokens 1`] = ` -[ - Identifier { - type: "Identifier", - value: "abstract", - - range: [0, 8], - loc: { - start: { column: 0, line: 1 }, - end: { column: 8, line: 1 }, - }, - }, - Keyword { - type: "Keyword", - value: "class", - - range: [9, 14], - loc: { - start: { column: 9, line: 1 }, - end: { column: 14, line: 1 }, - }, - }, - Identifier { - type: "Identifier", - value: "Foo", - - range: [15, 18], - loc: { - start: { column: 15, line: 1 }, - end: { column: 18, line: 1 }, - }, - }, - Punctuator { - type: "Punctuator", - value: "{", - - range: [19, 20], - loc: { - start: { column: 19, line: 1 }, - end: { column: 20, line: 1 }, - }, - }, - Identifier { - type: "Identifier", - value: "abstract", - - range: [23, 31], - loc: { - start: { column: 2, line: 2 }, - end: { column: 10, line: 2 }, - }, - }, - Identifier { - type: "Identifier", - value: "accessor", - - range: [32, 40], - loc: { - start: { column: 11, line: 2 }, - end: { column: 19, line: 2 }, - }, - }, - Identifier { - type: "Identifier", - value: "foo", - - range: [41, 44], - loc: { - start: { column: 20, line: 2 }, - end: { column: 23, line: 2 }, - }, - }, - Punctuator { - type: "Punctuator", - value: ":", - - range: [44, 45], - loc: { - start: { column: 23, line: 2 }, - end: { column: 24, line: 2 }, - }, - }, - Identifier { - type: "Identifier", - value: "number", - - range: [46, 52], - loc: { - start: { column: 25, line: 2 }, - end: { column: 31, line: 2 }, - }, - }, - Punctuator { - type: "Punctuator", - value: "=", - - range: [53, 54], - loc: { - start: { column: 32, line: 2 }, - end: { column: 33, line: 2 }, - }, - }, - Numeric { - type: "Numeric", - value: "1", - - range: [55, 56], - loc: { - start: { column: 34, line: 2 }, - end: { column: 35, line: 2 }, - }, - }, - Punctuator { - type: "Punctuator", - value: ";", - - range: [56, 57], - loc: { - start: { column: 35, line: 2 }, - end: { column: 36, line: 2 }, - }, - }, - Punctuator { - type: "Punctuator", - value: "}", - - range: [58, 59], - loc: { - start: { column: 0, line: 3 }, - end: { column: 1, line: 3 }, - }, - }, -] -`; diff --git a/packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/5-AST-Alignment-AST.shot b/packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/5-AST-Alignment-AST.shot deleted file mode 100644 index 957a65859f2..00000000000 --- a/packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/5-AST-Alignment-AST.shot +++ /dev/null @@ -1,119 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`AST Fixtures element AccessorProperty modifier-abstract-with-value AST Alignment - AST 1`] = ` -"Snapshot Diff: -- TSESTree -+ Babel - - Program { - type: 'Program', - body: Array [ - ClassDeclaration { - type: 'ClassDeclaration', - abstract: true, - body: ClassBody { - type: 'ClassBody', - body: Array [ -- TSAbstractAccessorProperty { -- type: 'TSAbstractAccessorProperty', -+ ClassAccessorProperty { -+ type: 'ClassAccessorProperty', -+ abstract: true, - computed: false, -- declare: false, -- decorators: Array [], -- definite: false, - key: Identifier { - type: 'Identifier', -- decorators: Array [], - name: 'foo', -- optional: false, - - range: [41, 44], - loc: { - start: { column: 20, line: 2 }, - end: { column: 23, line: 2 }, - }, - }, -- optional: false, -- override: false, -- readonly: false, - static: false, - typeAnnotation: TSTypeAnnotation { - type: 'TSTypeAnnotation', - typeAnnotation: TSNumberKeyword { - type: 'TSNumberKeyword', - - range: [46, 52], - loc: { - start: { column: 25, line: 2 }, - end: { column: 31, line: 2 }, - }, - }, - - range: [44, 52], - loc: { - start: { column: 23, line: 2 }, - end: { column: 31, line: 2 }, -+ }, -+ }, -+ value: Literal { -+ type: 'Literal', -+ raw: '1', -+ value: 1, -+ -+ range: [55, 56], -+ loc: { -+ start: { column: 34, line: 2 }, -+ end: { column: 35, line: 2 }, - }, - }, -- value: null, - - range: [23, 57], - loc: { - start: { column: 2, line: 2 }, - end: { column: 36, line: 2 }, - }, - }, - ], - - range: [19, 59], - loc: { - start: { column: 19, line: 1 }, - end: { column: 1, line: 3 }, - }, - }, -- declare: false, -- decorators: Array [], - id: Identifier { - type: 'Identifier', -- decorators: Array [], - name: 'Foo', -- optional: false, - - range: [15, 18], - loc: { - start: { column: 15, line: 1 }, - end: { column: 18, line: 1 }, - }, - }, -- implements: Array [], - superClass: null, - - range: [0, 59], - loc: { - start: { column: 0, line: 1 }, - end: { column: 1, line: 3 }, - }, - }, - ], - sourceType: 'script', - - range: [0, 60], - loc: { - start: { column: 0, line: 1 }, - end: { column: 0, line: 4 }, - }, - }" -`; diff --git a/packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/6-AST-Alignment-Tokens.shot deleted file mode 100644 index fd832b249e4..00000000000 --- a/packages/ast-spec/src/element/AccessorProperty/fixtures/modifier-abstract-with-value/snapshots/6-AST-Alignment-Tokens.shot +++ /dev/null @@ -1,6 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`AST Fixtures element AccessorProperty modifier-abstract-with-value AST Alignment - Token 1`] = ` -"Snapshot Diff: -Compared values have no visual difference." -`; diff --git a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/_error_/abstract-class-with-override-property/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/_error_/abstract-class-with-override-property/snapshots/1-TSESTree-Error.shot index 8afa44f7c60..2c3eef0e00a 100644 --- a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/_error_/abstract-class-with-override-property/snapshots/1-TSESTree-Error.shot +++ b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/_error_/abstract-class-with-override-property/snapshots/1-TSESTree-Error.shot @@ -1,3 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures legacy-fixtures basics _error_ abstract-class-with-override-property TSESTree - Error 1`] = `"NO ERROR"`; +exports[`AST Fixtures legacy-fixtures basics _error_ abstract-class-with-override-property TSESTree - Error 1`] = ` +"TSError + 2 | + 3 | abstract class SpecializedComponent extends SomeComponent { +> 4 | abstract override foo = 1; + | ^ Abstract property cannot have an initializer. + 5 | } + 6 |" +`; diff --git a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/_error_/abstract-class-with-override-property/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/_error_/abstract-class-with-override-property/snapshots/3-Alignment-Error.shot index 6de99caccfc..6afce871c92 100644 --- a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/_error_/abstract-class-with-override-property/snapshots/3-Alignment-Error.shot +++ b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/_error_/abstract-class-with-override-property/snapshots/3-Alignment-Error.shot @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures legacy-fixtures basics _error_ abstract-class-with-override-property Error Alignment 1`] = `"Babel errored but TSESTree didn't"`; +exports[`AST Fixtures legacy-fixtures basics _error_ abstract-class-with-override-property Error Alignment 1`] = `"Both errored"`; diff --git a/packages/ast-spec/tests/fixtures-with-differences-ast.shot b/packages/ast-spec/tests/fixtures-with-differences-ast.shot index d416f5e2d93..c9df60eb374 100644 --- a/packages/ast-spec/tests/fixtures-with-differences-ast.shot +++ b/packages/ast-spec/tests/fixtures-with-differences-ast.shot @@ -105,7 +105,6 @@ Set { "element/AccessorProperty/fixtures/key-number/fixture.ts", "element/AccessorProperty/fixtures/key-private/fixture.ts", "element/AccessorProperty/fixtures/key-string/fixture.ts", - "element/AccessorProperty/fixtures/modifier-abstract-with-value/fixture.ts", "element/AccessorProperty/fixtures/modifier-abstract/fixture.ts", "element/AccessorProperty/fixtures/modifier-declare/fixture.ts", "element/AccessorProperty/fixtures/modifier-override/fixture.ts", diff --git a/packages/ast-spec/tests/fixtures-with-differences-errors.shot b/packages/ast-spec/tests/fixtures-with-differences-errors.shot index 20b5b5200d0..9b90f826002 100644 --- a/packages/ast-spec/tests/fixtures-with-differences-errors.shot +++ b/packages/ast-spec/tests/fixtures-with-differences-errors.shot @@ -22,7 +22,6 @@ exports[`AST Fixtures List fixtures with Error differences 1`] = ` "declaration/TSTypeAliasDeclaration/fixtures/_error_/missing-type-parameter/fixture.ts", "declaration/VariableDeclaration/fixtures/_error_/decorator/fixture.ts", "element/AccessorProperty/fixtures/_error_/modifier-override-with-no-extends/fixture.ts", - "legacy-fixtures/basics/fixtures/_error_/abstract-class-with-override-property/fixture.ts", "legacy-fixtures/basics/fixtures/_error_/await-without-async-function/fixture.ts", "legacy-fixtures/basics/fixtures/_error_/class-private-identifier-field-with-accessibility-error/fixture.ts", "legacy-fixtures/basics/fixtures/_error_/class-with-constructor-and-type-parameters/fixture.ts", @@ -58,6 +57,7 @@ exports[`AST Fixtures List fixtures with Error differences 1`] = ` "TSESTree errored but Babel didn't": Set { "declaration/ExportAllDeclaration/fixtures/_error_/named-non-identifier/fixture.ts", "declaration/ExportNamedDeclaration/fixtures/_error_/aliased-literal/fixture.ts", + "element/AccessorProperty/fixtures/_error_/modifier-abstract-accessor-with-value/fixture.ts", "legacy-fixtures/basics/fixtures/_error_/abstract-class-with-abstract-constructor/fixture.ts", "legacy-fixtures/expressions/fixtures/_error_/instantiation-expression/fixture.ts", }, diff --git a/packages/eslint-plugin/tests/rules/naming-convention/cases/property.test.ts b/packages/eslint-plugin/tests/rules/naming-convention/cases/property.test.ts index 6d8fdf42608..accdfd8d08c 100644 --- a/packages/eslint-plugin/tests/rules/naming-convention/cases/property.test.ts +++ b/packages/eslint-plugin/tests/rules/naming-convention/cases/property.test.ts @@ -8,7 +8,7 @@ createTestCases([ 'class Ignored { private readonly % = 1 }', 'class Ignored { private static % }', 'class Ignored { private static readonly % = 1 }', - 'class Ignored { abstract % = 1 }', + 'class Ignored { abstract % }', 'class Ignored { declare % }', 'class Ignored { #% }', 'class Ignored { static #% }', diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 6bf57f87287..4610d41f665 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -1140,8 +1140,15 @@ export class Converter { case SyntaxKind.PropertyDeclaration: { const isAbstract = hasModifier(SyntaxKind.AbstractKeyword, node); - const isAccessor = hasModifier(SyntaxKind.AccessorKeyword, node); + if (isAbstract && node.initializer) { + this.#throwError( + node.initializer, + `Abstract property cannot have an initializer.`, + ); + } + + const isAccessor = hasModifier(SyntaxKind.AccessorKeyword, node); // eslint-disable-next-line @typescript-eslint/explicit-function-return-type -- TODO - add ignore IIFE option const type = (() => { if (isAccessor) {