Skip to content

Commit

Permalink
rename option name to createImportExpressions
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jul 4, 2023
1 parent a3548f4 commit 1fbc468
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 27 deletions.
@@ -1 +1 @@
{ "parserOpts": { "createImportExpression": true } }
{ "parserOpts": { "createImportExpressions": true } }
2 changes: 1 addition & 1 deletion packages/babel-parser/data/schema.json
Expand Up @@ -68,7 +68,7 @@
"description": "By default, exported identifiers must refer to a declared variable.\nSet this to true to allow export statements to reference undeclared variables.",
"type": "boolean"
},
"createImportExpression": {
"createImportExpressions": {
"description": "By default, `import(foo)` is parsed as `CallExpression(Import, [Identifier(foo)])`.\nSet this to true to parse it as an `ImportExpression` node.",
"type": "boolean",
"default": false
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-parser/src/options.ts
Expand Up @@ -20,7 +20,7 @@ export type Options = {
strictMode: boolean | undefined | null;
ranges: boolean;
tokens: boolean;
createImportExpression: boolean;
createImportExpressions: boolean;
createParenthesizedExpressions: boolean;
errorRecovery: boolean;
attachComment: boolean;
Expand Down 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)])
createImportExpression: false,
createImportExpressions: false,
// Whether to create ParenthesizedExpression AST nodes (if false
// the parser sets extra.parenthesized on the expression nodes instead).
createParenthesizedExpressions: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/parser/expression.ts
Expand Up @@ -1126,7 +1126,7 @@ export default abstract class ExpressionParser extends LValParser {
}

if (this.match(tt.parenL)) {
if (this.options.createImportExpression) {
if (this.options.createImportExpressions) {
return this.parseImportCall(node as Undone<N.ImportExpression>);
} else {
return this.finishNode(node, "Import");
Expand Down
@@ -1,4 +1,4 @@
{
"plugins": ["estree"],
"createImportExpression": false
"createImportExpressions": false
}
@@ -1,6 +1,6 @@
{
"sourceType": "module",
"plugins": [],
"createImportExpression": true,
"createImportExpressions": true,
"throws": "This experimental syntax requires enabling the parser plugin: \"importAttributes\". (1:16)"
}
@@ -1,7 +1,5 @@
{
"createImportExpression": false,
"plugins": [
"importAssertions"
],
"createImportExpressions": false,
"plugins": ["importAssertions"],
"sourceType": "module"
}
@@ -1,5 +1,5 @@
{
"plugins": ["importAssertions"],
"sourceType": "module",
"createImportExpression": false
"createImportExpressions": false
}
@@ -1,7 +1,5 @@
{
"createImportExpression": false,
"plugins": [
["importAttributes", { "deprecatedAssertSyntax": true }]
],
"createImportExpressions": false,
"plugins": [["importAttributes", { "deprecatedAssertSyntax": true }]],
"sourceType": "module"
}
@@ -1,5 +1,5 @@
{
"createImportExpression": true,
"createImportExpressions": true,
"plugins": ["importAttributes"],
"sourceType": "module"
}
@@ -1,4 +1,4 @@
{
"BABEL_8_BREAKING": false,
"createImportExpression": false
"createImportExpressions": false
}
21 changes: 17 additions & 4 deletions packages/babel-parser/typings/babel-parser.d.ts
@@ -1,6 +1,6 @@
// This file is auto-generated! Do not modify it directly.
/* eslint-disable import/no-extraneous-dependencies, @typescript-eslint/consistent-type-imports, prettier/prettier */
import * as _babel_types from '@babel/types';
import * as _babel_types from "@babel/types";

type Plugin =
| "asyncDoExpressions"
Expand Down Expand Up @@ -224,12 +224,11 @@ interface ParserOptions {
* By default, `import(foo)` is parsed as `CallExpression(Import, [Identifier(foo)])`.
* Set this to true to parse it as an `ImportExpression` node.
*/
createImportExpression?: boolean;
createImportExpressions?: boolean;
}

type ParserPlugin = PluginConfig;


declare const tokTypes: {
// todo(flow->ts) real token type
[name: string]: any;
Expand All @@ -244,4 +243,18 @@ type ParseResult<Result> = Result & {
errors: ParseError[];
};

export { DecoratorsPluginOptions, FlowPluginOptions, ParseError, ParseResult, ParserOptions, ParserPlugin, ParserPluginWithOptions, PipelineOperatorPluginOptions, RecordAndTuplePluginOptions, TypeScriptPluginOptions, parse, parseExpression, tokTypes };
export {
DecoratorsPluginOptions,
FlowPluginOptions,
ParseError,
ParseResult,
ParserOptions,
ParserPlugin,
ParserPluginWithOptions,
PipelineOperatorPluginOptions,
RecordAndTuplePluginOptions,
TypeScriptPluginOptions,
parse,
parseExpression,
tokTypes,
};
2 changes: 1 addition & 1 deletion packages/babel-parser/typings/babel-parser.source.d.ts
Expand Up @@ -140,7 +140,7 @@ export interface ParserOptions {
* By default, `import(foo)` is parsed as `CallExpression(Import, [Identifier(foo)])`.
* Set this to true to parse it as an `ImportExpression` node.
*/
createImportExpression?: boolean;
createImportExpressions?: boolean;
}

export type ParserPlugin = import("../src/typings").PluginConfig;
Expand Down
@@ -1,6 +1,6 @@
{
"plugins": ["transform-dynamic-import", "transform-modules-amd"],
"parserOpts": {
"createImportExpression": true
"createImportExpressions": true
}
}
@@ -1,6 +1,6 @@
{
"plugins": ["transform-dynamic-import", "transform-modules-commonjs"],
"parserOpts": {
"createImportExpression": true
"createImportExpressions": true
}
}
@@ -1,6 +1,6 @@
{
"plugins": ["transform-dynamic-import", "transform-modules-systemjs"],
"parserOpts": {
"createImportExpression": true
"createImportExpressions": true
}
}
Expand Up @@ -279,7 +279,7 @@ export default declare<PluginState>((api, options: Options) => {
}
}
} else {
// when createImportExpression is true, we require the dynamic import transform
// when createImportExpressions is true, we require the dynamic import transform
if (!this.file.has("@babel/plugin-proposal-dynamic-import")) {
throw new Error(MISSING_PLUGIN_ERROR);
}
Expand Down

0 comments on commit 1fbc468

Please sign in to comment.