Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Raise recoverable error for type members with invalid modifiers (#12785)
- Loading branch information
1 parent
8063fde
commit c22e72e
Showing
5 changed files
with
268 additions
and
5 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
9 changes: 9 additions & 0 deletions
9
packages/babel-parser/test/fixtures/typescript/interface/invalid-modifiers-method/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,9 @@ | ||
interface Foo { | ||
private a(); | ||
public b(); | ||
protected c(); | ||
static d(); | ||
declare e(); | ||
abstract f(); | ||
readonly g(); | ||
} |
121 changes: 121 additions & 0 deletions
121
...ages/babel-parser/test/fixtures/typescript/interface/invalid-modifiers-method/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,121 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":124,"loc":{"start":{"line":1,"column":0},"end":{"line":9,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: 'private' modifier cannot appear on a type member. (2:2)", | ||
"SyntaxError: 'public' modifier cannot appear on a type member. (3:2)", | ||
"SyntaxError: 'protected' modifier cannot appear on a type member. (4:2)", | ||
"SyntaxError: 'static' modifier cannot appear on a type member. (5:2)", | ||
"SyntaxError: 'declare' modifier cannot appear on a type member. (6:2)", | ||
"SyntaxError: 'abstract' modifier cannot appear on a type member. (7:2)", | ||
"SyntaxError: 'readonly' modifier can only appear on a property declaration or index signature. (8:2)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":124,"loc":{"start":{"line":1,"column":0},"end":{"line":9,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "TSInterfaceDeclaration", | ||
"start":0,"end":124,"loc":{"start":{"line":1,"column":0},"end":{"line":9,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":10,"end":13,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":13},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
}, | ||
"body": { | ||
"type": "TSInterfaceBody", | ||
"start":14,"end":124,"loc":{"start":{"line":1,"column":14},"end":{"line":9,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "TSMethodSignature", | ||
"start":18,"end":30,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":14}}, | ||
"accessibility": "private", | ||
"key": { | ||
"type": "Identifier", | ||
"start":26,"end":27,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11},"identifierName":"a"}, | ||
"name": "a" | ||
}, | ||
"computed": false, | ||
"parameters": [] | ||
}, | ||
{ | ||
"type": "TSMethodSignature", | ||
"start":33,"end":44,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":13}}, | ||
"accessibility": "public", | ||
"key": { | ||
"type": "Identifier", | ||
"start":40,"end":41,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":10},"identifierName":"b"}, | ||
"name": "b" | ||
}, | ||
"computed": false, | ||
"parameters": [] | ||
}, | ||
{ | ||
"type": "TSMethodSignature", | ||
"start":47,"end":61,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":16}}, | ||
"accessibility": "protected", | ||
"key": { | ||
"type": "Identifier", | ||
"start":57,"end":58,"loc":{"start":{"line":4,"column":12},"end":{"line":4,"column":13},"identifierName":"c"}, | ||
"name": "c" | ||
}, | ||
"computed": false, | ||
"parameters": [] | ||
}, | ||
{ | ||
"type": "TSMethodSignature", | ||
"start":64,"end":75,"loc":{"start":{"line":5,"column":2},"end":{"line":5,"column":13}}, | ||
"static": true, | ||
"key": { | ||
"type": "Identifier", | ||
"start":71,"end":72,"loc":{"start":{"line":5,"column":9},"end":{"line":5,"column":10},"identifierName":"d"}, | ||
"name": "d" | ||
}, | ||
"computed": false, | ||
"parameters": [] | ||
}, | ||
{ | ||
"type": "TSMethodSignature", | ||
"start":78,"end":90,"loc":{"start":{"line":6,"column":2},"end":{"line":6,"column":14}}, | ||
"declare": true, | ||
"key": { | ||
"type": "Identifier", | ||
"start":86,"end":87,"loc":{"start":{"line":6,"column":10},"end":{"line":6,"column":11},"identifierName":"e"}, | ||
"name": "e" | ||
}, | ||
"computed": false, | ||
"parameters": [] | ||
}, | ||
{ | ||
"type": "TSMethodSignature", | ||
"start":93,"end":106,"loc":{"start":{"line":7,"column":2},"end":{"line":7,"column":15}}, | ||
"abstract": true, | ||
"key": { | ||
"type": "Identifier", | ||
"start":102,"end":103,"loc":{"start":{"line":7,"column":11},"end":{"line":7,"column":12},"identifierName":"f"}, | ||
"name": "f" | ||
}, | ||
"computed": false, | ||
"parameters": [] | ||
}, | ||
{ | ||
"type": "TSMethodSignature", | ||
"start":109,"end":122,"loc":{"start":{"line":8,"column":2},"end":{"line":8,"column":15}}, | ||
"readonly": true, | ||
"key": { | ||
"type": "Identifier", | ||
"start":118,"end":119,"loc":{"start":{"line":8,"column":11},"end":{"line":8,"column":12},"identifierName":"g"}, | ||
"name": "g" | ||
}, | ||
"computed": false, | ||
"parameters": [] | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/babel-parser/test/fixtures/typescript/interface/invalid-modifiers-property/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,8 @@ | ||
interface Foo { | ||
private a; | ||
public b; | ||
protected c; | ||
static d; | ||
declare e; | ||
abstract f; | ||
} |
102 changes: 102 additions & 0 deletions
102
...es/babel-parser/test/fixtures/typescript/interface/invalid-modifiers-property/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,102 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":96,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: 'private' modifier cannot appear on a type member. (2:2)", | ||
"SyntaxError: 'public' modifier cannot appear on a type member. (3:2)", | ||
"SyntaxError: 'protected' modifier cannot appear on a type member. (4:2)", | ||
"SyntaxError: 'static' modifier cannot appear on a type member. (5:2)", | ||
"SyntaxError: 'declare' modifier cannot appear on a type member. (6:2)", | ||
"SyntaxError: 'abstract' modifier cannot appear on a type member. (7:2)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":96,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "TSInterfaceDeclaration", | ||
"start":0,"end":96,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":10,"end":13,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":13},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
}, | ||
"body": { | ||
"type": "TSInterfaceBody", | ||
"start":14,"end":96,"loc":{"start":{"line":1,"column":14},"end":{"line":8,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "TSPropertySignature", | ||
"start":18,"end":28,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":12}}, | ||
"accessibility": "private", | ||
"key": { | ||
"type": "Identifier", | ||
"start":26,"end":27,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11},"identifierName":"a"}, | ||
"name": "a" | ||
}, | ||
"computed": false | ||
}, | ||
{ | ||
"type": "TSPropertySignature", | ||
"start":31,"end":40,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":11}}, | ||
"accessibility": "public", | ||
"key": { | ||
"type": "Identifier", | ||
"start":38,"end":39,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":10},"identifierName":"b"}, | ||
"name": "b" | ||
}, | ||
"computed": false | ||
}, | ||
{ | ||
"type": "TSPropertySignature", | ||
"start":43,"end":55,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":14}}, | ||
"accessibility": "protected", | ||
"key": { | ||
"type": "Identifier", | ||
"start":53,"end":54,"loc":{"start":{"line":4,"column":12},"end":{"line":4,"column":13},"identifierName":"c"}, | ||
"name": "c" | ||
}, | ||
"computed": false | ||
}, | ||
{ | ||
"type": "TSPropertySignature", | ||
"start":58,"end":67,"loc":{"start":{"line":5,"column":2},"end":{"line":5,"column":11}}, | ||
"static": true, | ||
"key": { | ||
"type": "Identifier", | ||
"start":65,"end":66,"loc":{"start":{"line":5,"column":9},"end":{"line":5,"column":10},"identifierName":"d"}, | ||
"name": "d" | ||
}, | ||
"computed": false | ||
}, | ||
{ | ||
"type": "TSPropertySignature", | ||
"start":70,"end":80,"loc":{"start":{"line":6,"column":2},"end":{"line":6,"column":12}}, | ||
"declare": true, | ||
"key": { | ||
"type": "Identifier", | ||
"start":78,"end":79,"loc":{"start":{"line":6,"column":10},"end":{"line":6,"column":11},"identifierName":"e"}, | ||
"name": "e" | ||
}, | ||
"computed": false | ||
}, | ||
{ | ||
"type": "TSPropertySignature", | ||
"start":83,"end":94,"loc":{"start":{"line":7,"column":2},"end":{"line":7,"column":13}}, | ||
"abstract": true, | ||
"key": { | ||
"type": "Identifier", | ||
"start":92,"end":93,"loc":{"start":{"line":7,"column":11},"end":{"line":7,"column":12},"identifierName":"f"}, | ||
"name": "f" | ||
}, | ||
"computed": false | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |