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 JS Module Blocks proposal #12469
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
0f2915b
Add parser support
sosukesuzuki ce9deb3
Add generator support
sosukesuzuki 1607faa
Add types support
sosukesuzuki cfc2745
Add plugin-syntax-js-module-blocks
sosukesuzuki 6e331df
Rename "jsModuleBlocks" => "moduleBlocks"
sosukesuzuki c3e531e
Enter new prodParam scope
sosukesuzuki 05fcff9
this.inModule is true in module blocks
sosukesuzuki fa86755
Parse body of module blocks as Program
sosukesuzuki a9a049a
Enter new class scope when parse module blocks
sosukesuzuki 1f77d24
Fix type for babel-generator
sosukesuzuki 079fa6d
Generate functions related to module expressions
sosukesuzuki 7f66470
Import ClassScopeHandler
sosukesuzuki 15887b1
Avoid lookahead
sosukesuzuki bbc18af
Use expect instead of eat
sosukesuzuki db36c7d
Introduce initializeScopes
sosukesuzuki 647b654
Add another tests
sosukesuzuki a4236ce
Remove unnnecesary ternary
sosukesuzuki 905ae07
Use try...finally
sosukesuzuki 68485ee
Fix scope
sosukesuzuki 129ba3b
Reuse initializeScopes
sosukesuzuki ab4d1ee
Fix lint problem
sosukesuzuki a156184
Add comment to mention forward-declaration
sosukesuzuki bf8153b
Address reviews
sosukesuzuki e53f5fe
Add more tests
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
6 changes: 6 additions & 0 deletions
6
packages/babel-generator/test/fixtures/types/ModuleExpression/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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const m = module { export const foo = "foo" }; | ||
module { | ||
foo; | ||
bar; | ||
}; | ||
foo(module {}); |
4 changes: 4 additions & 0 deletions
4
packages/babel-generator/test/fixtures/types/ModuleExpression/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,4 @@ | ||
{ | ||
"plugins": ["moduleBlocks"], | ||
"sourceType": "module" | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/babel-generator/test/fixtures/types/ModuleExpression/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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const m = module { | ||
export const foo = "foo"; | ||
}; | ||
module { | ||
foo; | ||
bar; | ||
}; | ||
foo(module {}); |
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
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
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
1 change: 1 addition & 0 deletions
1
...er/test/fixtures/experimental/module-blocks/invalid-await-label-in-module-blocks/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 |
---|---|---|
@@ -0,0 +1 @@ | ||
module { await: 3 }; |
4 changes: 4 additions & 0 deletions
4
...est/fixtures/experimental/module-blocks/invalid-await-label-in-module-blocks/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,4 @@ | ||
{ | ||
"sourceType": "script", | ||
"plugins": ["moduleBlocks"] | ||
} |
55 changes: 55 additions & 0 deletions
55
...test/fixtures/experimental/module-blocks/invalid-await-label-in-module-blocks/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,55 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}}, | ||
"errors": [ | ||
"SyntaxError: Unexpected reserved word 'await' (1:9)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}}, | ||
"expression": { | ||
"type": "ModuleExpression", | ||
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}}, | ||
"body": { | ||
"type": "Program", | ||
"start":9,"end":19,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":19}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "LabeledStatement", | ||
"start":9,"end":17,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":17}}, | ||
"body": { | ||
"type": "ExpressionStatement", | ||
"start":16,"end":17,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":17}}, | ||
"expression": { | ||
"type": "NumericLiteral", | ||
"start":16,"end":17,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":17}}, | ||
"extra": { | ||
"rawValue": 3, | ||
"raw": "3" | ||
}, | ||
"value": 3 | ||
} | ||
}, | ||
"label": { | ||
"type": "Identifier", | ||
"start":9,"end":14,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":14},"identifierName":"await"}, | ||
"name": "await" | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...l-parser/test/fixtures/experimental/module-blocks/invalid-class-in-module-blocks/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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class B { | ||
#p() { | ||
module { | ||
class C { [this.#p]; } | ||
}; | ||
} | ||
} |
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: no need to comment this. It was only needed for class fields because Flow didn't support the
declare
keyword.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.
If remove this comment, ESLint warns:
Sorry I'm not familiar with Flow, what should we do?
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.
It's ok like this then.