Skip to content
Permalink
Browse files
feat(typescript-estree): [TS4.3] support overrides on class members (#…
  • Loading branch information
bradzacher committed May 23, 2021
1 parent c3942c9 commit 21d1b62a0b84b502d2cf12674b3d141994a3ffd4
Showing with 1,773 additions and 0 deletions.
  1. +1 −0 packages/ast-spec/src/base/ClassPropertyBase.ts
  2. +1 −0 packages/ast-spec/src/base/MethodDefinitionBase.ts
  3. +3 −0 packages/shared-fixtures/fixtures/typescript/basics/abstract-class-with-override-method.src.ts
  4. +3 −0 packages/shared-fixtures/fixtures/typescript/basics/abstract-class-with-override-property.src.ts
  5. +5 −0 packages/shared-fixtures/fixtures/typescript/basics/class-with-override-method.src.ts
  6. +3 −0 packages/shared-fixtures/fixtures/typescript/basics/class-with-override-property.src.ts
  7. +3 −0 packages/typescript-estree/src/convert.ts
  8. +14 −0 packages/typescript-estree/tests/ast-alignment/utils.ts
  9. +8 −0 packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap
  10. +1 −0 packages/typescript-estree/tests/lib/__snapshots__/semanticInfo.test.ts.snap
  11. +1 −0 packages/typescript-estree/tests/snapshots/comments/export-default-anonymous-class.src.js.shot
  12. +2 −0 packages/typescript-estree/tests/snapshots/javascript/classes/class-accessor-properties.src.js.shot
  13. +1 −0 ...ges/typescript-estree/tests/snapshots/javascript/classes/class-computed-static-method.src.js.shot
  14. +1 −0 ...ges/typescript-estree/tests/snapshots/javascript/classes/class-method-named-prototype.src.js.shot
  15. +1 −0 packages/typescript-estree/tests/snapshots/javascript/classes/class-method-named-static.src.js.shot
  16. +1 −0 ...es/typescript-estree/tests/snapshots/javascript/classes/class-method-named-with-space.src.js.shot
  17. +1 −0 packages/typescript-estree/tests/snapshots/javascript/classes/class-one-method-super.src.js.shot
  18. +1 −0 packages/typescript-estree/tests/snapshots/javascript/classes/class-one-method.src.js.shot
  19. +1 −0 ...escript-estree/tests/snapshots/javascript/classes/class-static-method-named-prototype.src.js.shot
  20. +1 −0 ...typescript-estree/tests/snapshots/javascript/classes/class-static-method-named-static.src.js.shot
  21. +1 −0 packages/typescript-estree/tests/snapshots/javascript/classes/class-static-method.src.js.shot
  22. +3 −0 ...stree/tests/snapshots/javascript/classes/class-static-methods-and-accessor-properties.src.js.shot
  23. +2 −0 ...ypescript-estree/tests/snapshots/javascript/classes/class-two-computed-static-methods.src.js.shot
  24. +2 −0 ...ript-estree/tests/snapshots/javascript/classes/class-two-methods-computed-constructor.src.js.shot
  25. +2 −0 packages/typescript-estree/tests/snapshots/javascript/classes/class-two-methods-semi.src.js.shot
  26. +2 −0 ...ges/typescript-estree/tests/snapshots/javascript/classes/class-two-methods-three-semi.src.js.shot
  27. +2 −0 packages/typescript-estree/tests/snapshots/javascript/classes/class-two-methods-two-semi.src.js.shot
  28. +2 −0 packages/typescript-estree/tests/snapshots/javascript/classes/class-two-methods.src.js.shot
  29. +2 −0 ...-estree/tests/snapshots/javascript/classes/class-two-static-methods-named-constructor.src.js.shot
  30. +1 −0 ...ypescript-estree/tests/snapshots/javascript/classes/class-with-constructor-parameters.src.js.shot
  31. +1 −0 ...ypescript-estree/tests/snapshots/javascript/classes/class-with-constructor-with-space.src.js.shot
  32. +1 −0 packages/typescript-estree/tests/snapshots/javascript/classes/class-with-constructor.src.js.shot
  33. +1 −0 ...typescript-estree/tests/snapshots/javascript/classes/invalid-class-setter-declaration.src.js.shot
  34. +1 −0 packages/typescript-estree/tests/snapshots/javascript/defaultParams/class-constructor.src.js.shot
  35. +1 −0 packages/typescript-estree/tests/snapshots/javascript/defaultParams/class-method.src.js.shot
  36. +1 −0 ...script-estree/tests/snapshots/javascript/destructuring/class-constructor-params-array.src.js.shot
  37. +1 −0 ...tree/tests/snapshots/javascript/destructuring/class-constructor-params-defaults-array.src.js.shot
  38. +1 −0 ...ree/tests/snapshots/javascript/destructuring/class-constructor-params-defaults-object.src.js.shot
  39. +1 −0 ...cript-estree/tests/snapshots/javascript/destructuring/class-constructor-params-object.src.js.shot
  40. +1 −0 .../typescript-estree/tests/snapshots/javascript/destructuring/class-method-params-array.src.js.shot
  41. +1 −0 ...pt-estree/tests/snapshots/javascript/destructuring/class-method-params-defaults-array.src.js.shot
  42. +1 −0 ...t-estree/tests/snapshots/javascript/destructuring/class-method-params-defaults-object.src.js.shot
  43. +1 −0 ...typescript-estree/tests/snapshots/javascript/destructuring/class-method-params-object.src.js.shot
  44. +4 −0 packages/typescript-estree/tests/snapshots/javascript/directives/directive-in-class.src.js.shot
  45. +1 −0 packages/typescript-estree/tests/snapshots/javascript/generators/async-generator-method.src.js.shot
  46. +1 −0 packages/typescript-estree/tests/snapshots/javascript/restParams/class-constructor.src.js.shot
  47. +1 −0 packages/typescript-estree/tests/snapshots/javascript/restParams/class-method.src.js.shot
  48. +1 −0 ...ipt-estree/tests/snapshots/typescript/basics/abstract-class-with-abstract-constructor.src.ts.shot
  49. +1 −0 ...pescript-estree/tests/snapshots/typescript/basics/abstract-class-with-abstract-method.src.ts.shot
  50. +2 −0 ...ript-estree/tests/snapshots/typescript/basics/abstract-class-with-abstract-properties.src.ts.shot
  51. +1 −0 ...tree/tests/snapshots/typescript/basics/abstract-class-with-abstract-readonly-property.src.ts.shot
  52. +1 −0 ...ree/tests/snapshots/typescript/basics/abstract-class-with-abstract-static-constructor.src.ts.shot
  53. +5 −0 ...cript-estree/tests/snapshots/typescript/basics/abstract-class-with-declare-properties.src.ts.shot
  54. +1 −0 ...pescript-estree/tests/snapshots/typescript/basics/abstract-class-with-optional-method.src.ts.shot
  55. +396 −0 ...pescript-estree/tests/snapshots/typescript/basics/abstract-class-with-override-method.src.ts.shot
  56. +393 −0 ...script-estree/tests/snapshots/typescript/basics/abstract-class-with-override-property.src.ts.shot
  57. +4 −0 ...ypescript-estree/tests/snapshots/typescript/basics/class-with-accessibility-modifiers.src.ts.shot
  58. +2 −0 ...pescript-estree/tests/snapshots/typescript/basics/class-with-constructor-and-modifier.src.ts.shot
  59. +2 −0 ...cript-estree/tests/snapshots/typescript/basics/class-with-constructor-and-return-type.src.ts.shot
  60. +2 −0 ...t-estree/tests/snapshots/typescript/basics/class-with-constructor-and-type-parameters.src.ts.shot
  61. +7 −0 ...ges/typescript-estree/tests/snapshots/typescript/basics/class-with-declare-properties.src.ts.shot
  62. +1 −0 ...es/typescript-estree/tests/snapshots/typescript/basics/class-with-definite-assignment.src.ts.shot
  63. +1 −0 ...cript-estree/tests/snapshots/typescript/basics/class-with-export-parameter-properties.src.ts.shot
  64. +1 −0 ...typescript-estree/tests/snapshots/typescript/basics/class-with-generic-method-default.src.ts.shot
  65. +1 −0 packages/typescript-estree/tests/snapshots/typescript/basics/class-with-generic-method.src.ts.shot
  66. +3 −0 packages/typescript-estree/tests/snapshots/typescript/basics/class-with-method.src.ts.shot
  67. +9 −0 ...pescript-estree/tests/snapshots/typescript/basics/class-with-optional-computed-method.src.ts.shot
  68. +1 −0 ...script-estree/tests/snapshots/typescript/basics/class-with-optional-computed-property.src.ts.shot
  69. +3 −0 packages/typescript-estree/tests/snapshots/typescript/basics/class-with-optional-methods.src.ts.shot
  70. +9 −0 ...es/typescript-estree/tests/snapshots/typescript/basics/class-with-optional-properties.src.ts.shot
  71. +1 −0 ...cript-estree/tests/snapshots/typescript/basics/class-with-optional-property-undefined.src.ts.shot
  72. +413 −0 packages/typescript-estree/tests/snapshots/typescript/basics/class-with-override-method.src.ts.shot
  73. +356 −0 ...ages/typescript-estree/tests/snapshots/typescript/basics/class-with-override-property.src.ts.shot
  74. +1 −0 ...ript-estree/tests/snapshots/typescript/basics/class-with-private-parameter-properties.src.ts.shot
  75. +2 −0 ...ages/typescript-estree/tests/snapshots/typescript/basics/class-with-property-function.src.ts.shot
  76. +5 −0 packages/typescript-estree/tests/snapshots/typescript/basics/class-with-property-values.src.ts.shot
  77. +1 −0 ...pt-estree/tests/snapshots/typescript/basics/class-with-protected-parameter-properties.src.ts.shot
  78. +1 −0 ...cript-estree/tests/snapshots/typescript/basics/class-with-public-parameter-properties.src.ts.shot
  79. +1 −0 ...ipt-estree/tests/snapshots/typescript/basics/class-with-readonly-parameter-properties.src.ts.shot
  80. +1 −0 ...ages/typescript-estree/tests/snapshots/typescript/basics/class-with-readonly-property.src.ts.shot
  81. +1 −0 ...cript-estree/tests/snapshots/typescript/basics/class-with-static-parameter-properties.src.ts.shot
  82. +2 −0 ...-estree/tests/snapshots/typescript/basics/class-with-two-methods-computed-constructor.src.ts.shot
  83. +1 −0 ...ypescript-estree/tests/snapshots/typescript/basics/declare-class-with-optional-method.src.ts.shot
  84. +4 −0 packages/typescript-estree/tests/snapshots/typescript/basics/keyword-variables.src.ts.shot
  85. +1 −0 ...es/typescript-estree/tests/snapshots/typescript/basics/object-with-escaped-properties.src.ts.shot
  86. +2 −0 packages/typescript-estree/tests/snapshots/typescript/basics/type-assertion-in-method.src.ts.shot
  87. +2 −0 ...pescript-estree/tests/snapshots/typescript/basics/type-assertion-with-guard-in-method.src.ts.shot
  88. +2 −0 packages/typescript-estree/tests/snapshots/typescript/basics/type-guard-in-method.src.ts.shot
  89. +1 −0 packages/typescript-estree/tests/snapshots/typescript/basics/type-reference-comments.src.ts.shot
  90. +1 −0 .../typescript/decorators/accessor-decorators/accessor-decorator-factory-instance-member.src.ts.shot
  91. +1 −0 ...ts/typescript/decorators/accessor-decorators/accessor-decorator-factory-static-member.src.ts.shot
  92. +1 −0 ...napshots/typescript/decorators/accessor-decorators/accessor-decorator-instance-member.src.ts.shot
  93. +1 −0 .../snapshots/typescript/decorators/accessor-decorators/accessor-decorator-static-member.src.ts.shot
  94. +1 −0 ...hots/typescript/decorators/method-decorators/method-decorator-factory-instance-member.src.ts.shot
  95. +1 −0 ...pshots/typescript/decorators/method-decorators/method-decorator-factory-static-member.src.ts.shot
  96. +1 −0 ...ts/snapshots/typescript/decorators/method-decorators/method-decorator-instance-member.src.ts.shot
  97. +1 −0 ...ests/snapshots/typescript/decorators/method-decorators/method-decorator-static-member.src.ts.shot
  98. +1 −0 ...napshots/typescript/decorators/parameter-decorators/parameter-array-pattern-decorator.src.ts.shot
  99. +1 −0 .../snapshots/typescript/decorators/parameter-decorators/parameter-decorator-constructor.src.ts.shot
  100. +1 −0 ...escript/decorators/parameter-decorators/parameter-decorator-decorator-instance-member.src.ts.shot
  101. +1 −0 ...ypescript/decorators/parameter-decorators/parameter-decorator-decorator-static-member.src.ts.shot
  102. +1 −0 ...pshots/typescript/decorators/parameter-decorators/parameter-decorator-instance-member.src.ts.shot
  103. +1 −0 ...napshots/typescript/decorators/parameter-decorators/parameter-decorator-static-member.src.ts.shot
  104. +1 −0 ...apshots/typescript/decorators/parameter-decorators/parameter-object-pattern-decorator.src.ts.shot
  105. +1 −0 ...snapshots/typescript/decorators/parameter-decorators/parameter-rest-element-decorator.src.ts.shot
  106. +2 −0 .../typescript/decorators/property-decorators/property-decorator-factory-instance-member.src.ts.shot
  107. +2 −0 ...ts/typescript/decorators/property-decorators/property-decorator-factory-static-member.src.ts.shot
  108. +2 −0 ...napshots/typescript/decorators/property-decorators/property-decorator-instance-member.src.ts.shot
  109. +2 −0 .../snapshots/typescript/decorators/property-decorators/property-decorator-static-member.src.ts.shot
  110. +1 −0 ...-estree/tests/snapshots/typescript/errorRecovery/empty-type-parameters-in-constructor.src.ts.shot
  111. +1 −0 ...cript-estree/tests/snapshots/typescript/errorRecovery/empty-type-parameters-in-method.src.ts.shot
  112. +1 −0 ...-estree/tests/snapshots/typescript/namespaces-and-modules/module-with-default-exports.src.ts.shot
  113. +1 −0 ...cript-estree/tests/snapshots/typescript/namespaces-and-modules/nested-internal-module.src.ts.shot
  114. +7 −0 packages/typescript-estree/tests/snapshots/typescript/types/this-type-expanded.src.ts.shot
  115. +1 −0 packages/typescript-estree/tests/snapshots/typescript/types/this-type.src.ts.shot
@@ -21,6 +21,7 @@ interface ClassPropertyBase extends BaseNode {
optional?: boolean;
definite?: boolean;
typeAnnotation?: TSTypeAnnotation;
override?: boolean;
}

export interface ClassPropertyComputedNameBase extends ClassPropertyBase {
@@ -21,6 +21,7 @@ interface MethodDefinitionBase extends BaseNode {
decorators?: Decorator[];
accessibility?: Accessibility;
typeParameters?: TSTypeParameterDeclaration;
override?: boolean;
}

export interface MethodDefinitionComputedNameBase extends MethodDefinitionBase {
@@ -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;
}
@@ -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) {
@@ -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) {
@@ -1295,6 +1297,7 @@ export class Converter {
computed: false,
static: isStatic,
kind: isStatic ? 'method' : 'constructor',
override: false,
});

const accessibility = getTSNodeAccessibility(node);
@@ -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) {
/**
@@ -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) {

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

@@ -38,6 +38,7 @@ Object {
"line": 8,
},
},
"override": false,
"range": Array [
103,
119,
@@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
18,
@@ -115,6 +116,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
19,
29,
@@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
23,
@@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
22,
@@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
19,
@@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
24,
@@ -37,6 +37,7 @@ Object {
"line": 2,
},
},
"override": false,
"range": Array [
14,
41,
@@ -37,6 +37,7 @@ Object {
"line": 2,
},
},
"override": false,
"range": Array [
14,
19,
@@ -38,6 +38,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
33,
@@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
26,
@@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
21,
@@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
21,
@@ -115,6 +116,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
22,
38,
@@ -193,6 +195,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
39,
56,
@@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
22,
@@ -115,6 +116,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
24,
37,
@@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
26,
@@ -116,6 +117,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
27,
46,
@@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
14,
@@ -115,6 +116,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
15,
20,
@@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
10,
15,
@@ -115,6 +116,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
16,
21,
@@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
14,
@@ -115,6 +116,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
15,
20,
@@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
14,
@@ -115,6 +116,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
14,
19,
@@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
31,
@@ -115,6 +116,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
32,
54,
@@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
32,
@@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
25,
@@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
9,
24,
@@ -37,6 +37,7 @@ Object {
"line": 1,
},
},
"override": false,
"range": Array [
10,
22,
@@ -37,6 +37,7 @@ Object {
"line": 2,
},
},
"override": false,
"range": Array [
14,
44,
@@ -37,6 +37,7 @@ Object {
"line": 2,
},
},
"override": false,
"range": Array [
14,
36,
Loading

0 comments on commit 21d1b62

Please sign in to comment.