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
Improve syntax error for class fields in ambient context #12108
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/typescript/class/declare-initializer/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,3 @@ | ||
declare class C { | ||
field = "field"; | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/babel-parser/test/fixtures/typescript/class/declare-initializer/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,53 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":38,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: Initializers are not allowed in ambient contexts. (2:8)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":38,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":38,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"declare": true, | ||
"id": { | ||
"type": "Identifier", | ||
"start":14,"end":15,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":15},"identifierName":"C"}, | ||
"name": "C" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":16,"end":38,"loc":{"start":{"line":1,"column":16},"end":{"line":3,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ClassProperty", | ||
"start":20,"end":36,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":18}}, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":20,"end":25,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":7},"identifierName":"field"}, | ||
"name": "field" | ||
}, | ||
"computed": false, | ||
"value": { | ||
"type": "StringLiteral", | ||
"start":28,"end":35,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":17}}, | ||
"extra": { | ||
"rawValue": "field", | ||
"raw": "\"field\"" | ||
}, | ||
"value": "field" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/babel-parser/test/fixtures/typescript/declare/module-class/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,5 @@ | ||
declare module m { | ||
class C { | ||
field = "field"; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/typescript/declare/module-class/options.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,3 @@ | ||
{ | ||
"plugins": ["typescript", "classProperties"] | ||
} |
68 changes: 68 additions & 0 deletions
68
packages/babel-parser/test/fixtures/typescript/declare/module-class/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,68 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":57,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: Initializers are not allowed in ambient contexts. (3:10)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":57,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "TSModuleDeclaration", | ||
"start":0,"end":57,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":15,"end":16,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":16},"identifierName":"m"}, | ||
"name": "m" | ||
}, | ||
"body": { | ||
"type": "TSModuleBlock", | ||
"start":17,"end":57,"loc":{"start":{"line":1,"column":17},"end":{"line":5,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":21,"end":55,"loc":{"start":{"line":2,"column":2},"end":{"line":4,"column":3}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":27,"end":28,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":9},"identifierName":"C"}, | ||
"name": "C" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":29,"end":55,"loc":{"start":{"line":2,"column":10},"end":{"line":4,"column":3}}, | ||
"body": [ | ||
{ | ||
"type": "ClassProperty", | ||
"start":35,"end":51,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":20}}, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":35,"end":40,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":9},"identifierName":"field"}, | ||
"name": "field" | ||
}, | ||
"computed": false, | ||
"value": { | ||
"type": "StringLiteral", | ||
"start":43,"end":50,"loc":{"start":{"line":3,"column":12},"end":{"line":3,"column":19}}, | ||
"extra": { | ||
"rawValue": "field", | ||
"raw": "\"field\"" | ||
}, | ||
"value": "field" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
] | ||
}, | ||
"declare": true | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions
6
packages/babel-parser/test/fixtures/typescript/declare/namespace-class/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,6 @@ | ||
declare namespace m { | ||
class C { | ||
field = "field"; | ||
} | ||
} | ||
|
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/typescript/declare/namespace-class/options.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,3 @@ | ||
{ | ||
"plugins": ["typescript", "classProperties"] | ||
} |
68 changes: 68 additions & 0 deletions
68
packages/babel-parser/test/fixtures/typescript/declare/namespace-class/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,68 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":60,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: Initializers are not allowed in ambient contexts. (3:10)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":60,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "TSModuleDeclaration", | ||
"start":0,"end":60,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":18,"end":19,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":19},"identifierName":"m"}, | ||
"name": "m" | ||
}, | ||
"body": { | ||
"type": "TSModuleBlock", | ||
"start":20,"end":60,"loc":{"start":{"line":1,"column":20},"end":{"line":5,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":24,"end":58,"loc":{"start":{"line":2,"column":2},"end":{"line":4,"column":3}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":30,"end":31,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":9},"identifierName":"C"}, | ||
"name": "C" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":32,"end":58,"loc":{"start":{"line":2,"column":10},"end":{"line":4,"column":3}}, | ||
"body": [ | ||
{ | ||
"type": "ClassProperty", | ||
"start":38,"end":54,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":20}}, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":38,"end":43,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":9},"identifierName":"field"}, | ||
"name": "field" | ||
}, | ||
"computed": false, | ||
"value": { | ||
"type": "StringLiteral", | ||
"start":46,"end":53,"loc":{"start":{"line":3,"column":12},"end":{"line":3,"column":19}}, | ||
"extra": { | ||
"rawValue": "field", | ||
"raw": "\"field\"" | ||
}, | ||
"value": "field" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
] | ||
}, | ||
"declare": true | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
node.declare
implythis.state.isDeclareContext
? If so we can removenode.declare
checks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No,
this.state.isDeclareContext
is not for class member withdeclare
modifier.EDIT:
I've fixed to use
this.isDeclareContext
for class member withdeclare
modifier at 05ad22c.