Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ts] Enforce order for the
override
modifier (#13209)
* [ts] Enforce order for the `override` modifier * generator * Add more checks * Update TS tests
- Loading branch information
1 parent
8433cd0
commit 22b0eb0
Showing
14 changed files
with
682 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
packages/babel-generator/test/fixtures/typescript/class-modifier-override/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
class MyClass extends BaseClass { | ||
override show() {} | ||
override public show() {} | ||
public override show() {} | ||
override size = 5; | ||
override readonly size = 5; | ||
readonly override size = 5; | ||
public static override readonly size = 5; | ||
} |
9 changes: 3 additions & 6 deletions
9
packages/babel-generator/test/fixtures/typescript/class-modifier-override/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
class MyClass extends BaseClass { | ||
override show() {} | ||
|
||
override public show() {} | ||
|
||
override public show() {} | ||
public override show() {} | ||
|
||
override size = 5; | ||
override readonly size = 5; | ||
override readonly size = 5; | ||
} | ||
public static override readonly size = 5; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/babel-parser/test/fixtures/typescript/class/modifiers-incompatible/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
abstract class A extends Base { | ||
static abstract m1(); | ||
abstract static m1(); | ||
|
||
declare override prop1: any; | ||
override declare prop2: any; | ||
} |
118 changes: 118 additions & 0 deletions
118
packages/babel-parser/test/fixtures/typescript/class/modifiers-incompatible/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":144,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: 'static' modifier cannot be used with 'abstract' modifier. (2:9)", | ||
"SyntaxError: 'static' modifier cannot be used with 'abstract' modifier. (3:11)", | ||
"SyntaxError: 'declare' modifier cannot be used with 'override' modifier. (5:10)", | ||
"SyntaxError: 'declare' modifier cannot be used with 'override' modifier. (6:11)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":144,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":144,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, | ||
"abstract": true, | ||
"id": { | ||
"type": "Identifier", | ||
"start":15,"end":16,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":16},"identifierName":"A"}, | ||
"name": "A" | ||
}, | ||
"superClass": { | ||
"type": "Identifier", | ||
"start":25,"end":29,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":29},"identifierName":"Base"}, | ||
"name": "Base" | ||
}, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":30,"end":144,"loc":{"start":{"line":1,"column":30},"end":{"line":7,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "TSDeclareMethod", | ||
"start":34,"end":55,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":23}}, | ||
"static": true, | ||
"abstract": true, | ||
"key": { | ||
"type": "Identifier", | ||
"start":50,"end":52,"loc":{"start":{"line":2,"column":18},"end":{"line":2,"column":20},"identifierName":"m1"}, | ||
"name": "m1" | ||
}, | ||
"computed": false, | ||
"kind": "method", | ||
"id": null, | ||
"generator": false, | ||
"async": false, | ||
"params": [] | ||
}, | ||
{ | ||
"type": "TSDeclareMethod", | ||
"start":58,"end":79,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":23}}, | ||
"abstract": true, | ||
"static": true, | ||
"key": { | ||
"type": "Identifier", | ||
"start":74,"end":76,"loc":{"start":{"line":3,"column":18},"end":{"line":3,"column":20},"identifierName":"m1"}, | ||
"name": "m1" | ||
}, | ||
"computed": false, | ||
"kind": "method", | ||
"id": null, | ||
"generator": false, | ||
"async": false, | ||
"params": [] | ||
}, | ||
{ | ||
"type": "ClassProperty", | ||
"start":83,"end":111,"loc":{"start":{"line":5,"column":2},"end":{"line":5,"column":30}}, | ||
"declare": true, | ||
"override": true, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":100,"end":105,"loc":{"start":{"line":5,"column":19},"end":{"line":5,"column":24},"identifierName":"prop1"}, | ||
"name": "prop1" | ||
}, | ||
"computed": false, | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":105,"end":110,"loc":{"start":{"line":5,"column":24},"end":{"line":5,"column":29}}, | ||
"typeAnnotation": { | ||
"type": "TSAnyKeyword", | ||
"start":107,"end":110,"loc":{"start":{"line":5,"column":26},"end":{"line":5,"column":29}} | ||
} | ||
}, | ||
"value": null | ||
}, | ||
{ | ||
"type": "ClassProperty", | ||
"start":114,"end":142,"loc":{"start":{"line":6,"column":2},"end":{"line":6,"column":30}}, | ||
"override": true, | ||
"declare": true, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":131,"end":136,"loc":{"start":{"line":6,"column":19},"end":{"line":6,"column":24},"identifierName":"prop2"}, | ||
"name": "prop2" | ||
}, | ||
"computed": false, | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":136,"end":141,"loc":{"start":{"line":6,"column":24},"end":{"line":6,"column":29}}, | ||
"typeAnnotation": { | ||
"type": "TSAnyKeyword", | ||
"start":138,"end":141,"loc":{"start":{"line":6,"column":26},"end":{"line":6,"column":29}} | ||
} | ||
}, | ||
"value": null | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/babel-parser/test/fixtures/typescript/class/modifiers-invalid-order/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
abstract class A extends B { | ||
static override m1() {} | ||
override static m2() {} | ||
|
||
override readonly p4; | ||
readonly override p3; | ||
|
||
public override m5() {} | ||
override public m6() {} | ||
|
||
protected override m7() {} | ||
override protected m8() {} | ||
|
||
private override m9() {} | ||
override private m10() {} | ||
|
||
abstract override m12(); | ||
override abstract m11(); | ||
|
||
public static m14() {} | ||
static public m13() {} | ||
|
||
protected static m16() {} | ||
static protected m15() {} | ||
|
||
private static m18() {} | ||
static private m17() {} | ||
} |
Oops, something went wrong.