diff --git a/packages/eslint-plugin-typescript/lib/rules/class-name-casing.js b/packages/eslint-plugin-typescript/lib/rules/class-name-casing.js index 52fa66455dde..3b8db844efab 100644 --- a/packages/eslint-plugin-typescript/lib/rules/class-name-casing.js +++ b/packages/eslint-plugin-typescript/lib/rules/class-name-casing.js @@ -54,10 +54,7 @@ module.exports = { switch (decl.type) { case 'ClassDeclaration': case 'ClassExpression': - friendlyName = 'Class'; - break; - case 'TSAbstractClassDeclaration': - friendlyName = 'Abstract class'; + friendlyName = decl.abstract ? 'Abstract class' : 'Class'; break; case 'TSInterfaceDeclaration': friendlyName = 'Interface'; @@ -81,9 +78,7 @@ module.exports = { //---------------------------------------------------------------------- return { - 'ClassDeclaration, TSInterfaceDeclaration, TSAbstractClassDeclaration, ClassExpression'( - node - ) { + 'ClassDeclaration, TSInterfaceDeclaration, ClassExpression'(node) { // class expressions (i.e. export default class {}) are OK if (node.id && !isPascalCase(node.id.name)) { report(node); diff --git a/packages/eslint-plugin-typescript/lib/rules/indent.js b/packages/eslint-plugin-typescript/lib/rules/indent.js index 1fdbe273ee07..a8024145a1c4 100644 --- a/packages/eslint-plugin-typescript/lib/rules/indent.js +++ b/packages/eslint-plugin-typescript/lib/rules/indent.js @@ -29,7 +29,6 @@ const KNOWN_NODES = new Set([ 'TSNullKeyword', // ts specific nodes we want to support - 'TSAbstractClassDeclaration', 'TSAbstractClassProperty', 'TSAbstractMethodDefinition', 'TSArrayType', diff --git a/packages/eslint-plugin-typescript/tests/lib/eslint-rules/no-shadow.js b/packages/eslint-plugin-typescript/tests/lib/eslint-rules/no-shadow.js index 71c6c00f5d9a..23bd827e8c81 100644 --- a/packages/eslint-plugin-typescript/tests/lib/eslint-rules/no-shadow.js +++ b/packages/eslint-plugin-typescript/tests/lib/eslint-rules/no-shadow.js @@ -22,6 +22,11 @@ ruleTester.run('no-shadow', rule, { ` type foo = any; function bar(foo: any) {} + `, + // https://github.com/typescript-eslint/typescript-eslint/issues/20 + ` +export abstract class Foo {} +export class FooBar extends Foo {} ` ], invalid: [] diff --git a/packages/eslint-plugin-typescript/tests/lib/eslint-rules/no-undef.js b/packages/eslint-plugin-typescript/tests/lib/eslint-rules/no-undef.js index 4398d27f24f5..d4bd42a46464 100644 --- a/packages/eslint-plugin-typescript/tests/lib/eslint-rules/no-undef.js +++ b/packages/eslint-plugin-typescript/tests/lib/eslint-rules/no-undef.js @@ -61,6 +61,11 @@ interface Runnable { export type SomeThing = { id: string; } + `, + // https://github.com/typescript-eslint/typescript-eslint/issues/20 + ` +export abstract class Foo {} +export class FooBar extends Foo {} ` ], invalid: [] diff --git a/packages/eslint-plugin-typescript/tests/lib/rules/indent.js b/packages/eslint-plugin-typescript/tests/lib/rules/indent.js index 4ba68b6e80e5..612ce758f2d2 100644 --- a/packages/eslint-plugin-typescript/tests/lib/rules/indent.js +++ b/packages/eslint-plugin-typescript/tests/lib/rules/indent.js @@ -22,7 +22,7 @@ function nonTsTestCase(example) { const individualNodeTests = [ { - node: 'TSAbstractClassDeclaration', + node: 'ClassDeclaration', code: [ ` abstract class Foo { @@ -157,7 +157,7 @@ interface Foo { ] }, { - node: 'TSEmptyBodyDeclareFunction', + node: 'TSDeclareFunction', code: [ ` declare function foo() : { diff --git a/packages/typescript-eslint-parser/src/analyze-scope.ts b/packages/typescript-eslint-parser/src/analyze-scope.ts index 1fd5c553643c..dc17e977683b 100644 --- a/packages/typescript-eslint-parser/src/analyze-scope.ts +++ b/packages/typescript-eslint-parser/src/analyze-scope.ts @@ -202,7 +202,7 @@ class Referencer extends OriginalReferencer { /** * Override. * Visit decorators. - * @param {ClassDeclaration|ClassExpression|TSAbstractClassDeclaration} node The class node to visit. + * @param {ClassDeclaration|ClassExpression} node The class node to visit. * @returns {void} */ visitClass(node: any) { @@ -709,9 +709,6 @@ class Referencer extends OriginalReferencer { this.close(node); } - TSAbstractClassDeclaration(node: any) { - this.ClassDeclaration(node); - } TSAbstractClassProperty(node: any) { this.ClassProperty(node); } diff --git a/packages/typescript-eslint-parser/src/visitor-keys.ts b/packages/typescript-eslint-parser/src/visitor-keys.ts index 0c6586a8a65d..d1dd5e616aeb 100644 --- a/packages/typescript-eslint-parser/src/visitor-keys.ts +++ b/packages/typescript-eslint-parser/src/visitor-keys.ts @@ -36,15 +36,6 @@ export const visitorKeys = eslintVisitorKeys.unionWith({ ClassProperty: ['decorators', 'key', 'typeAnnotation', 'value'], Decorator: ['expression'], TSAbstractClassProperty: ['decorators', 'key', 'typeAnnotation', 'value'], - TSAbstractClassDeclaration: [ - 'decorators', - 'id', - 'typeParameters', - 'superClass', - 'superTypeParameters', - 'implements', - 'body' - ], TSAbstractKeyword: [], TSAbstractMethodDefinition: ['key', 'value'], TSAnyKeyword: [], diff --git a/packages/typescript-eslint-parser/tests/lib/__snapshots__/scope-analysis.ts.snap b/packages/typescript-eslint-parser/tests/lib/__snapshots__/scope-analysis.ts.snap index a6b210ac8583..0644b066632e 100644 --- a/packages/typescript-eslint-parser/tests/lib/__snapshots__/scope-analysis.ts.snap +++ b/packages/typescript-eslint-parser/tests/lib/__snapshots__/scope-analysis.ts.snap @@ -205,7 +205,7 @@ Object { exports[`TypeScript scope analysis sourceType: module tests/fixtures/scope-analysis/abstract-class.ts 1`] = ` Object { - "$id": 3, + "$id": 4, "block": Object { "range": Array [ 0, @@ -215,7 +215,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 2, + "$id": 3, "block": Object { "range": Array [ 0, @@ -225,13 +225,13 @@ Object { }, "childScopes": Array [ Object { - "$id": 1, + "$id": 2, "block": Object { "range": Array [ 0, 68, ], - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, "childScopes": Array [], "functionExpressionScope": false, @@ -240,19 +240,19 @@ Object { "throughReferences": Array [], "type": "class", "upperScope": Object { - "$ref": 2, + "$ref": 3, }, "variableMap": Object { "A": Object { - "$ref": 0, + "$ref": 1, }, }, "variableScope": Object { - "$ref": 2, + "$ref": 3, }, "variables": Array [ Object { - "$id": 0, + "$id": 1, "defs": Array [ Object { "name": Object { @@ -268,7 +268,7 @@ Object { 0, 68, ], - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, "parent": undefined, "type": "ClassName", @@ -288,7 +288,7 @@ Object { "name": "A", "references": Array [], "scope": Object { - "$ref": 1, + "$ref": 2, }, }, ], @@ -300,13 +300,58 @@ Object { "throughReferences": Array [], "type": "module", "upperScope": Object { - "$ref": 3, + "$ref": 4, + }, + "variableMap": Object { + "A": Object { + "$ref": 0, + }, }, - "variableMap": Object {}, "variableScope": Object { - "$ref": 2, + "$ref": 3, }, - "variables": Array [], + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "A", + "range": Array [ + 15, + 16, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 0, + 68, + ], + "type": "ClassDeclaration", + }, + "parent": null, + "type": "ClassName", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "A", + "range": Array [ + 15, + 16, + ], + "type": "Identifier", + }, + ], + "name": "A", + "references": Array [], + "scope": Object { + "$ref": 3, + }, + }, + ], }, ], "functionExpressionScope": false, @@ -317,7 +362,7 @@ Object { "upperScope": null, "variableMap": Object {}, "variableScope": Object { - "$ref": 3, + "$ref": 4, }, "variables": Array [], } @@ -811,7 +856,7 @@ Object { exports[`TypeScript scope analysis sourceType: module tests/fixtures/scope-analysis/class-supper-type.ts 1`] = ` Object { - "$id": 12, + "$id": 13, "block": Object { "range": Array [ 0, @@ -821,7 +866,7 @@ Object { }, "childScopes": Array [ Object { - "$id": 11, + "$id": 12, "block": Object { "range": Array [ 0, @@ -831,13 +876,13 @@ Object { }, "childScopes": Array [ Object { - "$id": 6, + "$id": 7, "block": Object { "range": Array [ 0, 40, ], - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, "childScopes": Array [], "functionExpressionScope": false, @@ -846,19 +891,19 @@ Object { "throughReferences": Array [], "type": "class", "upperScope": Object { - "$ref": 11, + "$ref": 12, }, "variableMap": Object { "Foo": Object { - "$ref": 5, + "$ref": 6, }, }, "variableScope": Object { - "$ref": 11, + "$ref": 12, }, "variables": Array [ Object { - "$id": 5, + "$id": 6, "defs": Array [ Object { "name": Object { @@ -874,7 +919,7 @@ Object { 0, 40, ], - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, "parent": undefined, "type": "ClassName", @@ -894,13 +939,13 @@ Object { "name": "Foo", "references": Array [], "scope": Object { - "$ref": 6, + "$ref": 7, }, }, ], }, Object { - "$id": 8, + "$id": 9, "block": Object { "range": Array [ 42, @@ -915,19 +960,19 @@ Object { "throughReferences": Array [], "type": "class", "upperScope": Object { - "$ref": 11, + "$ref": 12, }, "variableMap": Object { "Foo2": Object { - "$ref": 7, + "$ref": 8, }, }, "variableScope": Object { - "$ref": 11, + "$ref": 12, }, "variables": Array [ Object { - "$id": 7, + "$id": 8, "defs": Array [ Object { "name": Object { @@ -963,13 +1008,13 @@ Object { "name": "Foo2", "references": Array [], "scope": Object { - "$ref": 8, + "$ref": 9, }, }, ], }, Object { - "$id": 10, + "$id": 11, "block": Object { "range": Array [ 84, @@ -984,19 +1029,19 @@ Object { "throughReferences": Array [], "type": "class", "upperScope": Object { - "$ref": 11, + "$ref": 12, }, "variableMap": Object { "Foo3": Object { - "$ref": 9, + "$ref": 10, }, }, "variableScope": Object { - "$ref": 11, + "$ref": 12, }, "variables": Array [ Object { - "$id": 9, + "$id": 10, "defs": Array [ Object { "name": Object { @@ -1032,7 +1077,7 @@ Object { "name": "Foo3", "references": Array [], "scope": Object { - "$ref": 10, + "$ref": 11, }, }, ], @@ -1042,9 +1087,9 @@ Object { "isStrict": true, "references": Array [ Object { - "$id": 2, + "$id": 3, "from": Object { - "$ref": 11, + "$ref": 12, }, "identifier": Object { "name": "Bar", @@ -1059,9 +1104,9 @@ Object { "writeExpr": undefined, }, Object { - "$id": 3, + "$id": 4, "from": Object { - "$ref": 11, + "$ref": 12, }, "identifier": Object { "name": "Bar", @@ -1076,9 +1121,9 @@ Object { "writeExpr": undefined, }, Object { - "$id": 4, + "$id": 5, "from": Object { - "$ref": 11, + "$ref": 12, }, "identifier": Object { "name": "Bar", @@ -1094,34 +1139,77 @@ Object { }, ], "throughReferences": Array [ - Object { - "$ref": 2, - }, Object { "$ref": 3, }, Object { "$ref": 4, }, + Object { + "$ref": 5, + }, ], "type": "module", "upperScope": Object { - "$ref": 12, + "$ref": 13, }, "variableMap": Object { - "Foo2": Object { + "Foo": Object { "$ref": 0, }, - "Foo3": Object { + "Foo2": Object { "$ref": 1, }, + "Foo3": Object { + "$ref": 2, + }, }, "variableScope": Object { - "$ref": 11, + "$ref": 12, }, "variables": Array [ Object { "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "Foo", + "range": Array [ + 15, + 18, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 0, + 40, + ], + "type": "ClassDeclaration", + }, + "parent": null, + "type": "ClassName", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "Foo", + "range": Array [ + 15, + 18, + ], + "type": "Identifier", + }, + ], + "name": "Foo", + "references": Array [], + "scope": Object { + "$ref": 12, + }, + }, + Object { + "$id": 1, "defs": Array [ Object { "name": Object { @@ -1157,11 +1245,11 @@ Object { "name": "Foo2", "references": Array [], "scope": Object { - "$ref": 11, + "$ref": 12, }, }, Object { - "$id": 1, + "$id": 2, "defs": Array [ Object { "name": Object { @@ -1197,7 +1285,7 @@ Object { "name": "Foo3", "references": Array [], "scope": Object { - "$ref": 11, + "$ref": 12, }, }, ], @@ -1207,21 +1295,21 @@ Object { "isStrict": false, "references": Array [], "throughReferences": Array [ - Object { - "$ref": 2, - }, Object { "$ref": 3, }, Object { "$ref": 4, }, + Object { + "$ref": 5, + }, ], "type": "global", "upperScope": null, "variableMap": Object {}, "variableScope": Object { - "$ref": 12, + "$ref": 13, }, "variables": Array [], } @@ -10838,7 +10926,7 @@ Object { exports[`TypeScript scope analysis sourceType: script tests/fixtures/scope-analysis/abstract-class.ts 1`] = ` Object { - "$id": 2, + "$id": 3, "block": Object { "range": Array [ 0, @@ -10848,13 +10936,13 @@ Object { }, "childScopes": Array [ Object { - "$id": 1, + "$id": 2, "block": Object { "range": Array [ 0, 68, ], - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, "childScopes": Array [], "functionExpressionScope": false, @@ -10863,19 +10951,19 @@ Object { "throughReferences": Array [], "type": "class", "upperScope": Object { - "$ref": 2, + "$ref": 3, }, "variableMap": Object { "A": Object { - "$ref": 0, + "$ref": 1, }, }, "variableScope": Object { - "$ref": 2, + "$ref": 3, }, "variables": Array [ Object { - "$id": 0, + "$id": 1, "defs": Array [ Object { "name": Object { @@ -10891,7 +10979,7 @@ Object { 0, 68, ], - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, "parent": undefined, "type": "ClassName", @@ -10911,7 +10999,7 @@ Object { "name": "A", "references": Array [], "scope": Object { - "$ref": 1, + "$ref": 2, }, }, ], @@ -10923,11 +11011,56 @@ Object { "throughReferences": Array [], "type": "global", "upperScope": null, - "variableMap": Object {}, + "variableMap": Object { + "A": Object { + "$ref": 0, + }, + }, "variableScope": Object { - "$ref": 2, + "$ref": 3, }, - "variables": Array [], + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "A", + "range": Array [ + 15, + 16, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 0, + 68, + ], + "type": "ClassDeclaration", + }, + "parent": null, + "type": "ClassName", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "A", + "range": Array [ + 15, + 16, + ], + "type": "Identifier", + }, + ], + "name": "A", + "references": Array [], + "scope": Object { + "$ref": 3, + }, + }, + ], } `; @@ -11365,7 +11498,7 @@ Object { exports[`TypeScript scope analysis sourceType: script tests/fixtures/scope-analysis/class-supper-type.ts 1`] = ` Object { - "$id": 11, + "$id": 12, "block": Object { "range": Array [ 0, @@ -11375,13 +11508,13 @@ Object { }, "childScopes": Array [ Object { - "$id": 6, + "$id": 7, "block": Object { "range": Array [ 0, 40, ], - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, "childScopes": Array [], "functionExpressionScope": false, @@ -11390,19 +11523,19 @@ Object { "throughReferences": Array [], "type": "class", "upperScope": Object { - "$ref": 11, + "$ref": 12, }, "variableMap": Object { "Foo": Object { - "$ref": 5, + "$ref": 6, }, }, "variableScope": Object { - "$ref": 11, + "$ref": 12, }, "variables": Array [ Object { - "$id": 5, + "$id": 6, "defs": Array [ Object { "name": Object { @@ -11418,7 +11551,7 @@ Object { 0, 40, ], - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, "parent": undefined, "type": "ClassName", @@ -11438,13 +11571,13 @@ Object { "name": "Foo", "references": Array [], "scope": Object { - "$ref": 6, + "$ref": 7, }, }, ], }, Object { - "$id": 8, + "$id": 9, "block": Object { "range": Array [ 42, @@ -11459,19 +11592,19 @@ Object { "throughReferences": Array [], "type": "class", "upperScope": Object { - "$ref": 11, + "$ref": 12, }, "variableMap": Object { "Foo2": Object { - "$ref": 7, + "$ref": 8, }, }, "variableScope": Object { - "$ref": 11, + "$ref": 12, }, "variables": Array [ Object { - "$id": 7, + "$id": 8, "defs": Array [ Object { "name": Object { @@ -11507,13 +11640,13 @@ Object { "name": "Foo2", "references": Array [], "scope": Object { - "$ref": 8, + "$ref": 9, }, }, ], }, Object { - "$id": 10, + "$id": 11, "block": Object { "range": Array [ 84, @@ -11528,19 +11661,19 @@ Object { "throughReferences": Array [], "type": "class", "upperScope": Object { - "$ref": 11, + "$ref": 12, }, "variableMap": Object { "Foo3": Object { - "$ref": 9, + "$ref": 10, }, }, "variableScope": Object { - "$ref": 11, + "$ref": 12, }, "variables": Array [ Object { - "$id": 9, + "$id": 10, "defs": Array [ Object { "name": Object { @@ -11576,7 +11709,7 @@ Object { "name": "Foo3", "references": Array [], "scope": Object { - "$ref": 10, + "$ref": 11, }, }, ], @@ -11586,9 +11719,9 @@ Object { "isStrict": false, "references": Array [ Object { - "$id": 2, + "$id": 3, "from": Object { - "$ref": 11, + "$ref": 12, }, "identifier": Object { "name": "Bar", @@ -11603,9 +11736,9 @@ Object { "writeExpr": undefined, }, Object { - "$id": 3, + "$id": 4, "from": Object { - "$ref": 11, + "$ref": 12, }, "identifier": Object { "name": "Bar", @@ -11620,9 +11753,9 @@ Object { "writeExpr": undefined, }, Object { - "$id": 4, + "$id": 5, "from": Object { - "$ref": 11, + "$ref": 12, }, "identifier": Object { "name": "Bar", @@ -11638,32 +11771,75 @@ Object { }, ], "throughReferences": Array [ - Object { - "$ref": 2, - }, Object { "$ref": 3, }, Object { "$ref": 4, }, + Object { + "$ref": 5, + }, ], "type": "global", "upperScope": null, "variableMap": Object { - "Foo2": Object { + "Foo": Object { "$ref": 0, }, - "Foo3": Object { + "Foo2": Object { "$ref": 1, }, + "Foo3": Object { + "$ref": 2, + }, }, "variableScope": Object { - "$ref": 11, + "$ref": 12, }, "variables": Array [ Object { "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "Foo", + "range": Array [ + 15, + 18, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 0, + 40, + ], + "type": "ClassDeclaration", + }, + "parent": null, + "type": "ClassName", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "Foo", + "range": Array [ + 15, + 18, + ], + "type": "Identifier", + }, + ], + "name": "Foo", + "references": Array [], + "scope": Object { + "$ref": 12, + }, + }, + Object { + "$id": 1, "defs": Array [ Object { "name": Object { @@ -11699,11 +11875,11 @@ Object { "name": "Foo2", "references": Array [], "scope": Object { - "$ref": 11, + "$ref": 12, }, }, Object { - "$id": 1, + "$id": 2, "defs": Array [ Object { "name": Object { @@ -11739,7 +11915,7 @@ Object { "name": "Foo3", "references": Array [], "scope": Object { - "$ref": 11, + "$ref": 12, }, }, ], diff --git a/packages/typescript-eslint-parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-eslint-parser/tests/lib/__snapshots__/typescript.ts.snap index 8bb68f2db69b..b1013b958c11 100644 --- a/packages/typescript-eslint-parser/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-eslint-parser/tests/lib/__snapshots__/typescript.ts.snap @@ -709,6 +709,7 @@ Object { "body": Array [ Object { "declaration": Object { + "abstract": true, "body": Object { "body": Array [ Object { @@ -822,7 +823,7 @@ Object { 68, ], "superClass": null, - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, "loc": Object { "end": Object { @@ -1068,6 +1069,7 @@ Object { "body": Array [ Object { "declaration": Object { + "abstract": true, "body": Object { "body": Array [ Object { @@ -1269,7 +1271,7 @@ Object { 86, ], "superClass": null, - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, "loc": Object { "end": Object { @@ -1604,6 +1606,7 @@ exports[`typescript fixtures/basics/abstract-class-with-abstract-properties.src Object { "body": Array [ Object { + "abstract": true, "body": Object { "body": Array [ Object { @@ -1750,7 +1753,7 @@ Object { 62, ], "superClass": null, - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, ], "comments": Array [], @@ -2013,6 +2016,7 @@ exports[`typescript fixtures/basics/abstract-class-with-abstract-readonly-proper Object { "body": Array [ Object { + "abstract": true, "body": Object { "body": Array [ Object { @@ -2123,7 +2127,7 @@ Object { 65, ], "superClass": null, - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, ], "comments": Array [], @@ -2369,6 +2373,7 @@ Object { "body": Array [ Object { "declaration": Object { + "abstract": true, "body": Object { "body": Array [ Object { @@ -2571,7 +2576,7 @@ Object { 78, ], "superClass": null, - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, "loc": Object { "end": Object { @@ -72794,6 +72799,7 @@ exports[`typescript fixtures/declare/abstract-class.src 1`] = ` Object { "body": Array [ Object { + "abstract": true, "body": Object { "body": Array [], "loc": Object { @@ -72846,7 +72852,7 @@ Object { 31, ], "superClass": null, - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, ], "comments": Array [], diff --git a/packages/typescript-estree/src/ast-node-types.ts b/packages/typescript-estree/src/ast-node-types.ts index 58dc30f02d07..a5e69a66d076 100644 --- a/packages/typescript-estree/src/ast-node-types.ts +++ b/packages/typescript-estree/src/ast-node-types.ts @@ -94,7 +94,6 @@ export enum AST_NODE_TYPES { /** * TS-prefixed nodes */ - TSAbstractClassDeclaration = 'TSAbstractClassDeclaration', TSAbstractClassProperty = 'TSAbstractClassProperty', TSAbstractKeyword = 'TSAbstractKeyword', TSAbstractMethodDefinition = 'TSAbstractMethodDefinition', diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index b3315e87f28c..f75547953df8 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -1376,15 +1376,6 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { } if (node.modifiers && node.modifiers.length) { - /** - * TypeScript class declarations can be defined as "abstract" - */ - if (node.kind === SyntaxKind.ClassDeclaration) { - if (hasModifier(SyntaxKind.AbstractKeyword, node)) { - classNodeType = `TSAbstract${classNodeType}`; - } - } - /** * We need check for modifiers, and use the last one, as there * could be multiple before the open brace @@ -1443,6 +1434,13 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { result.implements = implementsClause.types.map(convertChild); } + /** + * TypeScript class declarations can be defined as "abstract" + */ + if (hasModifier(SyntaxKind.AbstractKeyword, node)) { + result.abstract = true; + } + if (hasModifier(SyntaxKind.DeclareKeyword, node)) { result.declare = true; } diff --git a/packages/typescript-estree/tests/ast-alignment/utils.ts b/packages/typescript-estree/tests/ast-alignment/utils.ts index 34c3dabbdc00..77336ee7b5f4 100644 --- a/packages/typescript-estree/tests/ast-alignment/utils.ts +++ b/packages/typescript-estree/tests/ast-alignment/utils.ts @@ -232,16 +232,6 @@ export function preprocessBabylonAST(ast: any): any { }; } }, - /** - * Babel: ClassDeclaration + abstract: true - * ts-estree: TSAbstractClassDeclaration - */ - ClassDeclaration(node: any) { - if (node.abstract) { - node.type = 'TSAbstractClassDeclaration'; - delete node.abstract; - } - }, /** * Babel: ClassProperty + abstract: true * ts-estree: TSAbstractClassProperty diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap index db25a369d225..5ad5989309a8 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -707,6 +707,7 @@ Object { "body": Array [ Object { "declaration": Object { + "abstract": true, "body": Object { "body": Array [ Object { @@ -820,7 +821,7 @@ Object { 68, ], "superClass": null, - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, "loc": Object { "end": Object { @@ -1065,6 +1066,7 @@ Object { "body": Array [ Object { "declaration": Object { + "abstract": true, "body": Object { "body": Array [ Object { @@ -1266,7 +1268,7 @@ Object { 86, ], "superClass": null, - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, "loc": Object { "end": Object { @@ -1600,6 +1602,7 @@ exports[`typescript fixtures/basics/abstract-class-with-abstract-properties.src Object { "body": Array [ Object { + "abstract": true, "body": Object { "body": Array [ Object { @@ -1746,7 +1749,7 @@ Object { 62, ], "superClass": null, - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, ], "loc": Object { @@ -2008,6 +2011,7 @@ exports[`typescript fixtures/basics/abstract-class-with-abstract-readonly-proper Object { "body": Array [ Object { + "abstract": true, "body": Object { "body": Array [ Object { @@ -2118,7 +2122,7 @@ Object { 65, ], "superClass": null, - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, ], "loc": Object { @@ -2363,6 +2367,7 @@ Object { "body": Array [ Object { "declaration": Object { + "abstract": true, "body": Object { "body": Array [ Object { @@ -2565,7 +2570,7 @@ Object { 78, ], "superClass": null, - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, "loc": Object { "end": Object { @@ -72465,6 +72470,7 @@ exports[`typescript fixtures/declare/abstract-class.src 1`] = ` Object { "body": Array [ Object { + "abstract": true, "body": Object { "body": Array [], "loc": Object { @@ -72517,7 +72523,7 @@ Object { 31, ], "superClass": null, - "type": "TSAbstractClassDeclaration", + "type": "ClassDeclaration", }, ], "loc": Object {