source: imaps-frontend/node_modules/@babel/preset-env/lib/normalize-options.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 7.6 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.checkDuplicateIncludeExcludes = void 0;
7exports.default = normalizeOptions;
8exports.normalizeCoreJSOption = normalizeCoreJSOption;
9exports.validateUseBuiltInsOption = exports.validateModulesOption = exports.normalizePluginName = void 0;
10var _semver = require("semver");
11var _pluginsCompatData = require("./plugins-compat-data.js");
12var _moduleTransformations = require("./module-transformations.js");
13var _options = require("./options.js");
14var _helperValidatorOption = require("@babel/helper-validator-option");
15var _babel7Plugins = require("./polyfills/babel-7-plugins.cjs");
16const corejs3Polyfills = require("core-js-compat/data.json");
17const v = new _helperValidatorOption.OptionValidator("@babel/preset-env");
18const allPluginsList = Object.keys(_pluginsCompatData.plugins);
19const modulePlugins = ["transform-dynamic-import", ...Object.keys(_moduleTransformations.default).map(m => _moduleTransformations.default[m])];
20const getValidIncludesAndExcludes = (type, corejs) => {
21 const set = new Set(allPluginsList);
22 if (type === "exclude") modulePlugins.map(set.add, set);
23 if (corejs) {
24 if (corejs === 2) {
25 Object.keys(_babel7Plugins.corejs2Polyfills).map(set.add, set);
26 set.add("web.timers").add("web.immediate").add("web.dom.iterable");
27 } else {
28 Object.keys(corejs3Polyfills).map(set.add, set);
29 }
30 }
31 return Array.from(set);
32};
33function flatMap(array, fn) {
34 return Array.prototype.concat.apply([], array.map(fn));
35}
36const normalizePluginName = plugin => plugin.replace(/^(?:@babel\/|babel-)(?:plugin-)?/, "");
37exports.normalizePluginName = normalizePluginName;
38const expandIncludesAndExcludes = (filterList = [], type, corejs) => {
39 if (filterList.length === 0) return [];
40 const filterableItems = getValidIncludesAndExcludes(type, corejs);
41 const invalidFilters = [];
42 const selectedPlugins = flatMap(filterList, filter => {
43 let re;
44 if (typeof filter === "string") {
45 try {
46 re = new RegExp(`^${normalizePluginName(filter)}$`);
47 } catch (_) {
48 invalidFilters.push(filter);
49 return [];
50 }
51 } else {
52 re = filter;
53 }
54 const items = filterableItems.filter(item => {
55 return re.test(item) || re.test(item.replace(/^transform-/, "proposal-"));
56 });
57 if (items.length === 0) invalidFilters.push(filter);
58 return items;
59 });
60 v.invariant(invalidFilters.length === 0, `The plugins/built-ins '${invalidFilters.join(", ")}' passed to the '${type}' option are not
61 valid. Please check data/[plugin-features|built-in-features].js in babel-preset-env`);
62 return selectedPlugins;
63};
64const checkDuplicateIncludeExcludes = (include = [], exclude = []) => {
65 const duplicates = include.filter(opt => exclude.includes(opt));
66 v.invariant(duplicates.length === 0, `The plugins/built-ins '${duplicates.join(", ")}' were found in both the "include" and
67 "exclude" options.`);
68};
69exports.checkDuplicateIncludeExcludes = checkDuplicateIncludeExcludes;
70const normalizeTargets = targets => {
71 if (typeof targets === "string" || Array.isArray(targets)) {
72 return {
73 browsers: targets
74 };
75 }
76 return Object.assign({}, targets);
77};
78const validateModulesOption = (modulesOpt = _options.ModulesOption.auto) => {
79 v.invariant(_options.ModulesOption[modulesOpt.toString()] || modulesOpt === _options.ModulesOption.false, `The 'modules' option must be one of \n` + ` - 'false' to indicate no module processing\n` + ` - a specific module type: 'commonjs', 'amd', 'umd', 'systemjs'` + ` - 'auto' (default) which will automatically select 'false' if the current\n` + ` process is known to support ES module syntax, or "commonjs" otherwise\n`);
80 return modulesOpt;
81};
82exports.validateModulesOption = validateModulesOption;
83const validateUseBuiltInsOption = (builtInsOpt = false) => {
84 v.invariant(_options.UseBuiltInsOption[builtInsOpt.toString()] || builtInsOpt === _options.UseBuiltInsOption.false, `The 'useBuiltIns' option must be either
85 'false' (default) to indicate no polyfill,
86 '"entry"' to indicate replacing the entry polyfill, or
87 '"usage"' to import only used polyfills per file`);
88 return builtInsOpt;
89};
90exports.validateUseBuiltInsOption = validateUseBuiltInsOption;
91function normalizeCoreJSOption(corejs, useBuiltIns) {
92 let proposals = false;
93 let rawVersion;
94 if (useBuiltIns && corejs === undefined) {
95 {
96 rawVersion = 2;
97 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");
98 }
99 } else if (typeof corejs === "object" && corejs !== null) {
100 rawVersion = corejs.version;
101 proposals = Boolean(corejs.proposals);
102 } else {
103 rawVersion = corejs;
104 }
105 const version = rawVersion ? _semver.coerce(String(rawVersion)) : false;
106 if (version) {
107 if (useBuiltIns) {
108 {
109 if (version.major < 2 || version.major > 3) {
110 throw new RangeError("Invalid Option: The version passed to `corejs` is invalid. Currently, " + "only core-js@2 and core-js@3 are supported.");
111 }
112 }
113 } else {
114 console.warn("\nWARNING (@babel/preset-env): The `corejs` option only has an effect when the `useBuiltIns` option is not `false`\n");
115 }
116 }
117 return {
118 version,
119 proposals
120 };
121}
122function normalizeOptions(opts) {
123 v.validateTopLevelOptions(opts, _options.TopLevelOptions);
124 const useBuiltIns = validateUseBuiltInsOption(opts.useBuiltIns);
125 const corejs = normalizeCoreJSOption(opts.corejs, useBuiltIns);
126 const include = expandIncludesAndExcludes(opts.include, _options.TopLevelOptions.include, !!corejs.version && corejs.version.major);
127 const exclude = expandIncludesAndExcludes(opts.exclude, _options.TopLevelOptions.exclude, !!corejs.version && corejs.version.major);
128 checkDuplicateIncludeExcludes(include, exclude);
129 {
130 v.validateBooleanOption("loose", opts.loose);
131 v.validateBooleanOption("spec", opts.spec);
132 }
133 return {
134 bugfixes: v.validateBooleanOption(_options.TopLevelOptions.bugfixes, opts.bugfixes, false),
135 configPath: v.validateStringOption(_options.TopLevelOptions.configPath, opts.configPath, process.cwd()),
136 corejs,
137 debug: v.validateBooleanOption(_options.TopLevelOptions.debug, opts.debug, false),
138 include,
139 exclude,
140 forceAllTransforms: v.validateBooleanOption(_options.TopLevelOptions.forceAllTransforms, opts.forceAllTransforms, false),
141 ignoreBrowserslistConfig: v.validateBooleanOption(_options.TopLevelOptions.ignoreBrowserslistConfig, opts.ignoreBrowserslistConfig, false),
142 modules: validateModulesOption(opts.modules),
143 shippedProposals: v.validateBooleanOption(_options.TopLevelOptions.shippedProposals, opts.shippedProposals, false),
144 targets: normalizeTargets(opts.targets),
145 useBuiltIns: useBuiltIns,
146 browserslistEnv: v.validateStringOption(_options.TopLevelOptions.browserslistEnv, opts.browserslistEnv)
147 };
148}
149
150//# sourceMappingURL=normalize-options.js.map
Note: See TracBrowser for help on using the repository browser.