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
Parse static blocks with typescript plugin #13243
Merged
JLHwung
merged 8 commits into
babel:main
from
sosukesuzuki:static-blocks-with-typescript
May 3, 2021
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b24aa7c
Support static blocks with typescript
sosukesuzuki e40d6da
Add tests
sosukesuzuki a29454f
Reuse isStatic var
sosukesuzuki 02338e6
Disallow parsing static blocks with modifiers
sosukesuzuki 13d8287
Add tests
sosukesuzuki 7db6444
Raise recoverable errors
sosukesuzuki 5549fff
Address review
sosukesuzuki a334b8f
Add tests for static static {}
sosukesuzuki 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
3 changes: 3 additions & 0 deletions
3
...ixtures/typescript/static-blocks/invalid-static-block-with-accessibility-private/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 @@ | ||
class Foo { | ||
static private {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can report a better error, like |
||
} |
40 changes: 40 additions & 0 deletions
40
...ures/typescript/static-blocks/invalid-static-block-with-accessibility-private/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,40 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: 'private' modifier must precede 'static' modifier. (2:9)", | ||
"SyntaxError: Static class blocks cannot have any modifier. (2:19)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":10,"end":33,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "StaticBlock", | ||
"start":14,"end":31,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":19}}, | ||
"static": true, | ||
"accessibility": "private", | ||
"body": [] | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...tures/typescript/static-blocks/invalid-static-block-with-accessibility-protected/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 @@ | ||
class Foo { | ||
static protected {} | ||
} |
40 changes: 40 additions & 0 deletions
40
...es/typescript/static-blocks/invalid-static-block-with-accessibility-protected/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,40 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: 'protected' modifier must precede 'static' modifier. (2:9)", | ||
"SyntaxError: Static class blocks cannot have any modifier. (2:21)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":10,"end":35,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "StaticBlock", | ||
"start":14,"end":33,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":21}}, | ||
"static": true, | ||
"accessibility": "protected", | ||
"body": [] | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...fixtures/typescript/static-blocks/invalid-static-block-with-accessibility-public/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 @@ | ||
class Foo { | ||
static public {} | ||
} |
40 changes: 40 additions & 0 deletions
40
...tures/typescript/static-blocks/invalid-static-block-with-accessibility-public/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,40 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: 'public' modifier must precede 'static' modifier. (2:9)", | ||
"SyntaxError: Static class blocks cannot have any modifier. (2:18)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":10,"end":32,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "StaticBlock", | ||
"start":14,"end":30,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":18}}, | ||
"static": true, | ||
"accessibility": "public", | ||
"body": [] | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...st/fixtures/typescript/static-blocks/invalid-static-block-with-modifier-abstract/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 @@ | ||
class Foo { | ||
abstract static {} | ||
} |
40 changes: 40 additions & 0 deletions
40
...fixtures/typescript/static-blocks/invalid-static-block-with-modifier-abstract/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,40 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":34,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: 'static' modifier cannot be used with 'abstract' modifier. (2:11)", | ||
"SyntaxError: Static class blocks cannot have any modifier. (2:20)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":34,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":34,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":10,"end":34,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "StaticBlock", | ||
"start":14,"end":32,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":20}}, | ||
"abstract": true, | ||
"static": true, | ||
"body": [] | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...st/fixtures/typescript/static-blocks/invalid-static-block-with-modifier-override/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 @@ | ||
class Foo { | ||
override static {} | ||
} |
40 changes: 40 additions & 0 deletions
40
...fixtures/typescript/static-blocks/invalid-static-block-with-modifier-override/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,40 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":34,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: 'static' modifier must precede 'override' modifier. (2:11)", | ||
"SyntaxError: Static class blocks cannot have any modifier. (2:20)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":34,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":34,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":10,"end":34,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "StaticBlock", | ||
"start":14,"end":32,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":20}}, | ||
"override": true, | ||
"static": true, | ||
"body": [] | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...est/fixtures/typescript/static-blocks/invalid-static-blocks-with-modifer-declare/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 @@ | ||
class Foo { | ||
declare static {} | ||
} |
39 changes: 39 additions & 0 deletions
39
.../fixtures/typescript/static-blocks/invalid-static-blocks-with-modifer-declare/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,39 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: Static class blocks cannot have any modifier. (2:19)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":10,"end":33,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "StaticBlock", | ||
"start":14,"end":31,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":19}}, | ||
"declare": true, | ||
"static": true, | ||
"body": [] | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...t/fixtures/typescript/static-blocks/invalid-static-blocks-with-modifier-readonly/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 @@ | ||
class Foo { | ||
readonly static {} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ixtures/typescript/static-blocks/invalid-static-blocks-with-modifier-readonly/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,40 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":34,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: 'static' modifier must precede 'readonly' modifier. (2:11)", | ||
"SyntaxError: Static class blocks cannot have any modifier. (2:20)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":34,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":34,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":10,"end":34,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "StaticBlock", | ||
"start":14,"end":32,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":20}}, | ||
"readonly": true, | ||
"static": true, | ||
"body": [] | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
Oops, something went wrong.
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.
nit-picking: I prefer shorter error codes.