Skip to content

Commit

Permalink
Breaking: parserOpts.createImportExpressions defaults to true (#16114)
Browse files Browse the repository at this point in the history
* breaking: createImportExpressions defaults to true

* enable createImportExpressions in the build config
  • Loading branch information
JLHwung committed Nov 24, 2023
1 parent 1e9a1d4 commit bd98d8f
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 3 deletions.
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ module.exports = function (api) {
]
.filter(Boolean)
.map(normalize),
parserOpts: {
createImportExpressions: true,
},
presets: [
// presets are applied from right to left
["@babel/env", envOpts],
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const defaultOptions: Options = {
tokens: false,
// Whether to create ImportExpression AST nodes (if false
// `import(foo)` will be parsed as CallExpression(Import, [Identifier(foo)])
createImportExpressions: false,
createImportExpressions: process.env.BABEL_8_BREAKING ? true : false,
// Whether to create ParenthesizedExpression AST nodes (if false
// the parser sets extra.parenthesized on the expression nodes instead).
createParenthesizedExpressions: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"plugins": ["sourcePhaseImports"],
"createImportExpressions": false,
"throws": "'import.source(...)' can only be parsed when using the 'createImportExpressions' option. (1:7)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import.source("foo");
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"plugins": ["sourcePhaseImports"],
"createImportExpressions": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"type": "File",
"start":0,"end":21,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":21,"index":21}},
"program": {
"type": "Program",
"start":0,"end":21,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":21,"index":21}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":21,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":21,"index":21}},
"expression": {
"type": "ImportExpression",
"start":0,"end":20,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":20,"index":20}},
"phase": "source",
"source": {
"type": "StringLiteral",
"start":14,"end":19,"loc":{"start":{"line":1,"column":14,"index":14},"end":{"line":1,"column":19,"index":19}},
"extra": {
"rawValue": "foo",
"raw": "\"foo\""
},
"value": "foo"
}
}
}
],
"directives": []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import.source("foo");
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"BABEL_8_BREAKING": false,
"plugins": ["sourcePhaseImports"],
"throws": "'import.source(...)' can only be parsed when using the 'createImportExpressions' option. (1:7)"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": ["sourcePhaseImports"],
"createImportExpressions": true
"BABEL_8_BREAKING": true,
"plugins": ["sourcePhaseImports"]
}

0 comments on commit bd98d8f

Please sign in to comment.