Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(typescript-estree): [TS4.3] support overrides on class members (#…
  • Loading branch information
bradzacher committed May 23, 2021
1 parent c3942c9 commit 21d1b62
Show file tree
Hide file tree
Showing 115 changed files with 1,773 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/ast-spec/src/base/ClassPropertyBase.ts
Expand Up @@ -21,6 +21,7 @@ interface ClassPropertyBase extends BaseNode {
optional?: boolean;
definite?: boolean;
typeAnnotation?: TSTypeAnnotation;
override?: boolean;
}

export interface ClassPropertyComputedNameBase extends ClassPropertyBase {
Expand Down
1 change: 1 addition & 0 deletions packages/ast-spec/src/base/MethodDefinitionBase.ts
Expand Up @@ -21,6 +21,7 @@ interface MethodDefinitionBase extends BaseNode {
decorators?: Decorator[];
accessibility?: Accessibility;
typeParameters?: TSTypeParameterDeclaration;
override?: boolean;
}

export interface MethodDefinitionComputedNameBase extends MethodDefinitionBase {
Expand Down
@@ -0,0 +1,3 @@
abstract class SpecializedComponent extends SomeComponent {
abstract override show();
}
@@ -0,0 +1,3 @@
abstract class SpecializedComponent extends SomeComponent {
abstract override foo = 1;
}
@@ -0,0 +1,5 @@
class SpecializedComponent extends SomeComponent {
override show() {
// ...
}
}
@@ -0,0 +1,3 @@
class SpecializedComponent extends SomeComponent {
override foo = 1;
}
3 changes: 3 additions & 0 deletions packages/typescript-estree/src/convert.ts
Expand Up @@ -1094,6 +1094,7 @@ export class Converter {
static: hasModifier(SyntaxKind.StaticKeyword, node),
readonly: hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined,
declare: hasModifier(SyntaxKind.DeclareKeyword, node),
override: hasModifier(SyntaxKind.OverrideKeyword, node),
});

if (node.type) {
Expand Down Expand Up @@ -1209,6 +1210,7 @@ export class Converter {
computed: isComputedProperty(node.name),
static: hasModifier(SyntaxKind.StaticKeyword, node),
kind: 'method',
override: hasModifier(SyntaxKind.OverrideKeyword, node),
});

if (node.decorators) {
Expand Down Expand Up @@ -1295,6 +1297,7 @@ export class Converter {
computed: false,
static: isStatic,
kind: isStatic ? 'method' : 'constructor',
override: false,
});

const accessibility = getTSNodeAccessibility(node);
Expand Down
14 changes: 14 additions & 0 deletions packages/typescript-estree/tests/ast-alignment/utils.ts
Expand Up @@ -165,6 +165,13 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any {
node.type = AST_NODE_TYPES.TSAbstractMethodDefinition;
delete node.abstract;
}
/**
* TS 4.3: overrides on class members
* Babel doesn't ever emit a false override flag
*/
if (node.override == null) {
node.override = false;
}
},
ClassProperty(node) {
/**
Expand All @@ -183,6 +190,13 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any {
if (!node.declare) {
node.declare = false;
}
/**
* TS 4.3: overrides on class members
* Babel doesn't ever emit a false override flag
*/
if (node.override == null) {
node.override = false;
}
},
TSExpressionWithTypeArguments(node, parent: any) {
if (parent.type === AST_NODE_TYPES.TSInterfaceDeclaration) {
Expand Down
Expand Up @@ -1679,6 +1679,10 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/abstract-class-with-optional-method.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/abstract-class-with-override-method.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/abstract-class-with-override-property.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/abstract-interface.src 1`] = `
TSError {
"column": 7,
Expand Down Expand Up @@ -1800,6 +1804,10 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-with-optional-property-undefined.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-with-override-method.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-with-override-property.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-with-private-parameter-properties.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-with-property-function.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
Expand Down
Expand Up @@ -1286,6 +1286,7 @@ Object {
"line": 4,
},
},
"override": false,
"range": Array [
39,
56,
Expand Down
Expand Up @@ -38,6 +38,7 @@ Object {
"line": 8,
},
},
"override": false,
"range": Array [
103,
119,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
18,
Expand Down Expand Up @@ -115,6 +116,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
19,
29,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
23,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
22,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
19,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
24,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 2,
},
},
"override": false,
"range": Array [
14,
41,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 2,
},
},
"override": false,
"range": Array [
14,
19,
Expand Down
Expand Up @@ -38,6 +38,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
33,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
26,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
21,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
21,
Expand Down Expand Up @@ -115,6 +116,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
22,
38,
Expand Down Expand Up @@ -193,6 +195,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
39,
56,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
22,
Expand Down Expand Up @@ -115,6 +116,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
24,
37,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
26,
Expand Down Expand Up @@ -116,6 +117,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
27,
46,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
14,
Expand Down Expand Up @@ -115,6 +116,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
15,
20,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
10,
15,
Expand Down Expand Up @@ -115,6 +116,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
16,
21,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
14,
Expand Down Expand Up @@ -115,6 +116,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
15,
20,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
14,
Expand Down Expand Up @@ -115,6 +116,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
14,
19,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
31,
Expand Down Expand Up @@ -115,6 +116,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
32,
54,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
32,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
25,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
24,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
10,
22,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 2,
},
},
"override": false,
"range": Array [
14,
44,
Expand Down
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 2,
},
},
"override": false,
"range": Array [
14,
36,
Expand Down

0 comments on commit 21d1b62

Please sign in to comment.