Skip to content

feat(typescript-estree): [TS4.3] support overrides on class members #3429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/ast-spec/src/base/ClassPropertyBase.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
abstract class SpecializedComponent extends SomeComponent {
abstract override show();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
abstract class SpecializedComponent extends SomeComponent {
abstract override foo = 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class SpecializedComponent extends SomeComponent {
override show() {
// ...
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class SpecializedComponent extends SomeComponent {
override foo = 1;
}
3 changes: 3 additions & 0 deletions packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,7 @@ Object {
"line": 4,
},
},
"override": false,
"range": Array [
39,
56,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Object {
"line": 8,
},
},
"override": false,
"range": Array [
103,
119,
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
23,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
22,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
19,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
24,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 2,
},
},
"override": false,
"range": Array [
14,
41,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 2,
},
},
"override": false,
"range": Array [
14,
19,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
33,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
26,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
21,
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
25,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
24,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
10,
22,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 2,
},
},
"override": false,
"range": Array [
14,
44,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Object {
"line": 2,
},
},
"override": false,
"range": Array [
14,
36,
Expand Down
Loading