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
Add createImportExpressions
parser option
#15682
Merged
nicolo-ribaudo
merged 21 commits into
babel:feat-7.23.0/imports
from
JLHwung:import-expression-ast
Aug 2, 2023
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
984c17a
duplicate dynamic-import test cases
JLHwung 11d7e2d
move invalid-lone-import test case
JLHwung 677fac6
duplicate import-attributes test cases
JLHwung 108673b
add ImportExpression AST node
JLHwung afb7607
implement createImportExpression
JLHwung a3c37d0
update parser test cases
JLHwung 36c5df7
print ImportExpression
JLHwung f38936b
support ImportExpression ast in module transforms
JLHwung 81b8450
fix: return import node for lone import
JLHwung a644aea
add more test cases
JLHwung 1437e7b
set createImportExpression false for legacy import-attr test cases
JLHwung 1ed6a05
Update packages/babel-parser/data/schema.json
JLHwung 5de8194
add test case for importAssertion + createImportExpression: true
JLHwung cb1a0fb
implements https://github.com/estree/estree/pull/307
JLHwung bd590b9
provide compatibility with legacy ESTree AST
JLHwung 5b4b77d
Update packages/babel-parser/src/parser/expression.ts
JLHwung 36848e0
fix: allow new (import(foo))
JLHwung e9e9a96
add types
liuxingbaoyu b901309
rename option name to createImportExpressions
JLHwung edcc9ca
Rename in tests
nicolo-ribaudo 588fb39
Update after rebase
nicolo-ribaudo 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
1 change: 1 addition & 0 deletions
1
packages/babel-generator/test/fixtures/comments/dynamic-import/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 @@ | ||
/*0*/import/*1*/(/*2*/"foo"/*3*/)/*4*/ |
5 changes: 5 additions & 0 deletions
5
packages/babel-generator/test/fixtures/comments/dynamic-import/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,5 @@ | ||
{ | ||
"parserOpts": { | ||
"createImportExpressions": true | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-generator/test/fixtures/comments/dynamic-import/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 @@ | ||
/*0*/import /*1*/( /*2*/"foo" /*3*/); /*4*/ |
1 change: 1 addition & 0 deletions
1
packages/babel-generator/test/fixtures/types/Import-createImportExpression-false/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 @@ | ||
import("module.js"); |
1 change: 1 addition & 0 deletions
1
...ages/babel-generator/test/fixtures/types/Import-createImportExpression-false/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 @@ | ||
{ "parserOpts": { "createImportExpressions": false } } |
1 change: 1 addition & 0 deletions
1
packages/babel-generator/test/fixtures/types/Import-createImportExpression-false/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 @@ | ||
import("module.js"); |
2 changes: 1 addition & 1 deletion
2
packages/babel-generator/test/fixtures/types/Import/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 |
---|---|---|
@@ -1 +1 @@ | ||
{ "plugins": ["dynamicImport"] } | ||
{ "parserOpts": { "createImportExpressions": true } } |
1 change: 1 addition & 0 deletions
1
...babel-generator/test/fixtures/types/ImportAttribute-createImportExpression-false/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 @@ | ||
import("foo.json", { with: { type: "json" } }); |
5 changes: 5 additions & 0 deletions
5
...l-generator/test/fixtures/types/ImportAttribute-createImportExpression-false/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,5 @@ | ||
{ | ||
"plugins": [["importAttributes", { "importAttributesKeyword": "with" }]], | ||
"sourceType": "module", | ||
"parserOpts": { "createImportExpressions": false } | ||
} |
5 changes: 5 additions & 0 deletions
5
...abel-generator/test/fixtures/types/ImportAttribute-createImportExpression-false/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,5 @@ | ||
import("foo.json", { | ||
with: { | ||
type: "json" | ||
} | ||
}); |
1 change: 1 addition & 0 deletions
1
packages/babel-generator/test/fixtures/types/ImportAttribute/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 @@ | ||
import("foo.json", { with: { type: "json" } }); |
5 changes: 5 additions & 0 deletions
5
packages/babel-generator/test/fixtures/types/ImportAttribute/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,5 @@ | ||
{ | ||
"plugins": [["importAttributes", { "importAttributesKeyword": "with" }]], | ||
"sourceType": "module", | ||
"parserOpts": { "createImportExpressions": true } | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/babel-generator/test/fixtures/types/ImportAttribute/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,5 @@ | ||
import("foo.json", { | ||
with: { | ||
type: "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
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
3 changes: 3 additions & 0 deletions
3
...st/fixtures/es2020/dynamic-import-createImportExpression-false/direct-calls-only/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,3 @@ | ||
function failsParse() { | ||
return import.then(); | ||
} |
58 changes: 58 additions & 0 deletions
58
...fixtures/es2020/dynamic-import-createImportExpression-false/direct-calls-only/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,58 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":49,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":49}}, | ||
"errors": [ | ||
"SyntaxError: The only valid meta property for import is import.meta. (2:16)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":49,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":49}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "FunctionDeclaration", | ||
"start":0,"end":49,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":49}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":9,"end":19,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":19,"index":19},"identifierName":"failsParse"}, | ||
"name": "failsParse" | ||
}, | ||
"generator": false, | ||
"async": false, | ||
"params": [], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":22,"end":49,"loc":{"start":{"line":1,"column":22,"index":22},"end":{"line":3,"column":1,"index":49}}, | ||
"body": [ | ||
{ | ||
"type": "ReturnStatement", | ||
"start":26,"end":47,"loc":{"start":{"line":2,"column":2,"index":26},"end":{"line":2,"column":23,"index":47}}, | ||
"argument": { | ||
"type": "CallExpression", | ||
"start":33,"end":46,"loc":{"start":{"line":2,"column":9,"index":33},"end":{"line":2,"column":22,"index":46}}, | ||
"callee": { | ||
"type": "MetaProperty", | ||
"start":33,"end":44,"loc":{"start":{"line":2,"column":9,"index":33},"end":{"line":2,"column":20,"index":44}}, | ||
"meta": { | ||
"type": "Identifier", | ||
"start":33,"end":39,"loc":{"start":{"line":2,"column":9,"index":33},"end":{"line":2,"column":15,"index":39},"identifierName":"import"}, | ||
"name": "import" | ||
}, | ||
"property": { | ||
"type": "Identifier", | ||
"start":40,"end":44,"loc":{"start":{"line":2,"column":16,"index":40},"end":{"line":2,"column":20,"index":44},"identifierName":"then"}, | ||
"name": "then" | ||
} | ||
}, | ||
"arguments": [] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...arser/test/fixtures/es2020/dynamic-import-createImportExpression-false/generator/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,3 @@ | ||
function* a() { | ||
yield import('http'); | ||
} |
60 changes: 60 additions & 0 deletions
60
...er/test/fixtures/es2020/dynamic-import-createImportExpression-false/generator/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,60 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":41,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":41}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":41,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":41}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "FunctionDeclaration", | ||
"start":0,"end":41,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":1,"index":41}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":10,"end":11,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":11,"index":11},"identifierName":"a"}, | ||
"name": "a" | ||
}, | ||
"generator": true, | ||
"async": false, | ||
"params": [], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":14,"end":41,"loc":{"start":{"line":1,"column":14,"index":14},"end":{"line":3,"column":1,"index":41}}, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":18,"end":39,"loc":{"start":{"line":2,"column":2,"index":18},"end":{"line":2,"column":23,"index":39}}, | ||
"expression": { | ||
"type": "YieldExpression", | ||
"start":18,"end":38,"loc":{"start":{"line":2,"column":2,"index":18},"end":{"line":2,"column":22,"index":38}}, | ||
"delegate": false, | ||
"argument": { | ||
"type": "CallExpression", | ||
"start":24,"end":38,"loc":{"start":{"line":2,"column":8,"index":24},"end":{"line":2,"column":22,"index":38}}, | ||
"callee": { | ||
"type": "Import", | ||
"start":24,"end":30,"loc":{"start":{"line":2,"column":8,"index":24},"end":{"line":2,"column":14,"index":30}} | ||
}, | ||
"arguments": [ | ||
{ | ||
"type": "StringLiteral", | ||
"start":31,"end":37,"loc":{"start":{"line":2,"column":15,"index":31},"end":{"line":2,"column":21,"index":37}}, | ||
"extra": { | ||
"rawValue": "http", | ||
"raw": "'http'" | ||
}, | ||
"value": "http" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...test/fixtures/es2020/dynamic-import-createImportExpression-false/inside-function/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,3 @@ | ||
function loadImport(file) { | ||
return import(`test/${file}.js`); | ||
} |
Oops, something went wrong.
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.
Can we maybe avoid this in
BABEL_8_BREAKING
? (in a separate PR)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.
Agreed, it was added for prettier compatibility only.