diff options
Diffstat (limited to 'node_modules/@babel/preset-env/lib/normalize-options.js')
| -rw-r--r-- | node_modules/@babel/preset-env/lib/normalize-options.js | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/node_modules/@babel/preset-env/lib/normalize-options.js b/node_modules/@babel/preset-env/lib/normalize-options.js index 47088876..f54846d6 100644 --- a/node_modules/@babel/preset-env/lib/normalize-options.js +++ b/node_modules/@babel/preset-env/lib/normalize-options.js @@ -18,7 +18,21 @@ const corejs2DefaultWebIncludes = ["web.timers", "web.immediate", "web.dom.itera const v = new _helperValidatorOption.OptionValidator("@babel/preset-env"); const allPluginsList = Object.keys(_pluginsCompatData.plugins); const modulePlugins = ["transform-dynamic-import", ...Object.keys(_moduleTransformations.default).map(m => _moduleTransformations.default[m])]; -const getValidIncludesAndExcludes = (type, corejs) => Array.from(new Set([...allPluginsList, ...(type === "exclude" ? modulePlugins : []), ...(corejs ? corejs == 2 ? [...Object.keys(_corejs2BuiltIns), ...corejs2DefaultWebIncludes] : Object.keys(_coreJsCompat) : [])])); +const getValidIncludesAndExcludes = (type, corejs) => { + const set = new Set(allPluginsList); + if (type === "exclude") modulePlugins.map(set.add, set); + if (corejs) { + { + if (corejs === 2) { + Object.keys(_corejs2BuiltIns).map(set.add, set); + corejs2DefaultWebIncludes.map(set.add, set); + } else { + Object.keys(_coreJsCompat).map(set.add, set); + } + } + } + return Array.from(set); +}; function flatMap(array, fn) { return Array.prototype.concat.apply([], array.map(fn)); } @@ -81,8 +95,10 @@ function normalizeCoreJSOption(corejs, useBuiltIns) { let proposals = false; let rawVersion; if (useBuiltIns && corejs === undefined) { - rawVersion = 2; - console.warn("\nWARNING (@babel/preset-env): We noticed you're using the `useBuiltIns` option without declaring a " + "core-js version. Currently, we assume version 2.x when no version " + "is passed. Since this default version will likely change in future " + "versions of Babel, we recommend explicitly setting the core-js version " + "you are using via the `corejs` option.\n" + "\nYou should also be sure that the version you pass to the `corejs` " + "option matches the version specified in your `package.json`'s " + "`dependencies` section. If it doesn't, you need to run one of the " + "following commands:\n\n" + " npm install --save core-js@2 npm install --save core-js@3\n" + " yarn add core-js@2 yarn add core-js@3\n\n" + "More info about useBuiltIns: https://babeljs.io/docs/en/babel-preset-env#usebuiltins\n" + "More info about core-js: https://babeljs.io/docs/en/babel-preset-env#corejs"); + { + rawVersion = 2; + console.warn("\nWARNING (@babel/preset-env): We noticed you're using the `useBuiltIns` option without declaring a " + `core-js version. Currently, we assume version 2.x when no version ` + "is passed. Since this default version will likely change in future " + "versions of Babel, we recommend explicitly setting the core-js version " + "you are using via the `corejs` option.\n" + "\nYou should also be sure that the version you pass to the `corejs` " + "option matches the version specified in your `package.json`'s " + "`dependencies` section. If it doesn't, you need to run one of the " + "following commands:\n\n" + " npm install --save core-js@2 npm install --save core-js@3\n" + " yarn add core-js@2 yarn add core-js@3\n\n" + "More info about useBuiltIns: https://babeljs.io/docs/en/babel-preset-env#usebuiltins\n" + "More info about core-js: https://babeljs.io/docs/en/babel-preset-env#corejs"); + } } else if (typeof corejs === "object" && corejs !== null) { rawVersion = corejs.version; proposals = Boolean(corejs.proposals); @@ -90,11 +106,16 @@ function normalizeCoreJSOption(corejs, useBuiltIns) { rawVersion = corejs; } const version = rawVersion ? _semver.coerce(String(rawVersion)) : false; - if (!useBuiltIns && version) { - console.warn("\nWARNING (@babel/preset-env): The `corejs` option only has an effect when the `useBuiltIns` option is not `false`\n"); - } - if (useBuiltIns && (!version || version.major < 2 || version.major > 3)) { - throw new RangeError("Invalid Option: The version passed to `corejs` is invalid. Currently, " + "only core-js@2 and core-js@3 are supported."); + if (version) { + if (useBuiltIns) { + { + if (version.major < 2 || version.major > 3) { + throw new RangeError("Invalid Option: The version passed to `corejs` is invalid. Currently, " + "only core-js@2 and core-js@3 are supported."); + } + } + } else { + console.warn("\nWARNING (@babel/preset-env): The `corejs` option only has an effect when the `useBuiltIns` option is not `false`\n"); + } } return { version, @@ -108,6 +129,10 @@ function normalizeOptions(opts) { const include = expandIncludesAndExcludes(opts.include, _options.TopLevelOptions.include, !!corejs.version && corejs.version.major); const exclude = expandIncludesAndExcludes(opts.exclude, _options.TopLevelOptions.exclude, !!corejs.version && corejs.version.major); checkDuplicateIncludeExcludes(include, exclude); + { + v.validateBooleanOption("loose", opts.loose); + v.validateBooleanOption("spec", opts.spec); + } return { bugfixes: v.validateBooleanOption(_options.TopLevelOptions.bugfixes, opts.bugfixes, false), configPath: v.validateStringOption(_options.TopLevelOptions.configPath, opts.configPath, process.cwd()), @@ -117,10 +142,8 @@ function normalizeOptions(opts) { exclude, forceAllTransforms: v.validateBooleanOption(_options.TopLevelOptions.forceAllTransforms, opts.forceAllTransforms, false), ignoreBrowserslistConfig: v.validateBooleanOption(_options.TopLevelOptions.ignoreBrowserslistConfig, opts.ignoreBrowserslistConfig, false), - loose: v.validateBooleanOption(_options.TopLevelOptions.loose, opts.loose), modules: validateModulesOption(opts.modules), shippedProposals: v.validateBooleanOption(_options.TopLevelOptions.shippedProposals, opts.shippedProposals, false), - spec: v.validateBooleanOption(_options.TopLevelOptions.spec, opts.spec, false), targets: normalizeTargets(opts.targets), useBuiltIns: useBuiltIns, browserslistEnv: v.validateStringOption(_options.TopLevelOptions.browserslistEnv, opts.browserslistEnv) |
