1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | Object.defineProperty(exports, "isPluginRequired", {
|
7 | enumerable: true,
|
8 | get: function () {
|
9 | return _filterItems.isPluginRequired;
|
10 | }
|
11 | });
|
12 | exports.default = exports.transformIncludesAndExcludes = void 0;
|
13 |
|
14 | var _debug = require("./debug");
|
15 |
|
16 | var _getOptionSpecificExcludes = _interopRequireDefault(require("./get-option-specific-excludes"));
|
17 |
|
18 | var _filterItems = _interopRequireWildcard(require("./filter-items"));
|
19 |
|
20 | var _moduleTransformations = _interopRequireDefault(require("./module-transformations"));
|
21 |
|
22 | var _normalizeOptions = _interopRequireDefault(require("./normalize-options"));
|
23 |
|
24 | var _plugins = _interopRequireDefault(require("../data/plugins.json"));
|
25 |
|
26 | var _shippedProposals = require("../data/shipped-proposals");
|
27 |
|
28 | var _usagePlugin = _interopRequireDefault(require("./polyfills/corejs2/usage-plugin"));
|
29 |
|
30 | var _usagePlugin2 = _interopRequireDefault(require("./polyfills/corejs3/usage-plugin"));
|
31 |
|
32 | var _usagePlugin3 = _interopRequireDefault(require("./polyfills/regenerator/usage-plugin"));
|
33 |
|
34 | var _entryPlugin = _interopRequireDefault(require("./polyfills/corejs2/entry-plugin"));
|
35 |
|
36 | var _entryPlugin2 = _interopRequireDefault(require("./polyfills/corejs3/entry-plugin"));
|
37 |
|
38 | var _entryPlugin3 = _interopRequireDefault(require("./polyfills/regenerator/entry-plugin"));
|
39 |
|
40 | var _targetsParser = _interopRequireDefault(require("./targets-parser"));
|
41 |
|
42 | var _availablePlugins = _interopRequireDefault(require("./available-plugins"));
|
43 |
|
44 | var _utils = require("./utils");
|
45 |
|
46 | function _helperPluginUtils() {
|
47 | const data = require("@babel/helper-plugin-utils");
|
48 |
|
49 | _helperPluginUtils = function () {
|
50 | return data;
|
51 | };
|
52 |
|
53 | return data;
|
54 | }
|
55 |
|
56 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
57 |
|
58 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
59 |
|
60 | const pluginListWithoutProposals = (0, _utils.filterStageFromList)(_plugins.default, _shippedProposals.proposalPlugins);
|
61 |
|
62 | const getPlugin = pluginName => {
|
63 | const plugin = _availablePlugins.default[pluginName];
|
64 |
|
65 | if (!plugin) {
|
66 | throw new Error(`Could not find plugin "${pluginName}". Ensure there is an entry in ./available-plugins.js for it.`);
|
67 | }
|
68 |
|
69 | return plugin;
|
70 | };
|
71 |
|
72 | const transformIncludesAndExcludes = opts => {
|
73 | return opts.reduce((result, opt) => {
|
74 | const target = opt.match(/^(es|es6|es7|esnext|web)\./) ? "builtIns" : "plugins";
|
75 | result[target].add(opt);
|
76 | return result;
|
77 | }, {
|
78 | all: opts,
|
79 | plugins: new Set(),
|
80 | builtIns: new Set()
|
81 | });
|
82 | };
|
83 |
|
84 | exports.transformIncludesAndExcludes = transformIncludesAndExcludes;
|
85 |
|
86 | function supportsStaticESM(caller) {
|
87 | return !!(caller && caller.supportsStaticESM);
|
88 | }
|
89 |
|
90 | var _default = (0, _helperPluginUtils().declare)((api, opts) => {
|
91 | api.assertVersion(7);
|
92 | const {
|
93 | configPath,
|
94 | debug,
|
95 | exclude: optionsExclude,
|
96 | forceAllTransforms,
|
97 | ignoreBrowserslistConfig,
|
98 | include: optionsInclude,
|
99 | loose,
|
100 | modules,
|
101 | shippedProposals,
|
102 | spec,
|
103 | targets: optionsTargets,
|
104 | useBuiltIns,
|
105 | corejs: {
|
106 | version: corejs,
|
107 | proposals
|
108 | }
|
109 | } = (0, _normalizeOptions.default)(opts);
|
110 | let hasUglifyTarget = false;
|
111 |
|
112 | if (optionsTargets && optionsTargets.uglify) {
|
113 | hasUglifyTarget = true;
|
114 | delete optionsTargets.uglify;
|
115 | console.log("");
|
116 | console.log("The uglify target has been deprecated. Set the top level");
|
117 | console.log("option `forceAllTransforms: true` instead.");
|
118 | console.log("");
|
119 | }
|
120 |
|
121 | if (optionsTargets && optionsTargets.esmodules && optionsTargets.browsers) {
|
122 | console.log("");
|
123 | console.log("@babel/preset-env: esmodules and browsers targets have been specified together.");
|
124 | console.log(`\`browsers\` target, \`${optionsTargets.browsers}\` will be ignored.`);
|
125 | console.log("");
|
126 | }
|
127 |
|
128 | const targets = (0, _targetsParser.default)(optionsTargets, {
|
129 | ignoreBrowserslistConfig,
|
130 | configPath
|
131 | });
|
132 | const include = transformIncludesAndExcludes(optionsInclude);
|
133 | const exclude = transformIncludesAndExcludes(optionsExclude);
|
134 | const transformTargets = forceAllTransforms || hasUglifyTarget ? {} : targets;
|
135 | const transformations = (0, _filterItems.default)(shippedProposals ? _plugins.default : pluginListWithoutProposals, include.plugins, exclude.plugins, transformTargets, null, (0, _getOptionSpecificExcludes.default)({
|
136 | loose
|
137 | }), _shippedProposals.pluginSyntaxMap);
|
138 | const plugins = [];
|
139 | const pluginUseBuiltIns = useBuiltIns !== false;
|
140 |
|
141 | if (modules !== false && _moduleTransformations.default[modules] && (modules !== "auto" || !api.caller || !api.caller(supportsStaticESM))) {
|
142 | plugins.push([getPlugin(_moduleTransformations.default[modules]), {
|
143 | loose
|
144 | }]);
|
145 | }
|
146 |
|
147 | transformations.forEach(pluginName => plugins.push([getPlugin(pluginName), {
|
148 | spec,
|
149 | loose,
|
150 | useBuiltIns: pluginUseBuiltIns
|
151 | }]));
|
152 |
|
153 | if (debug) {
|
154 | console.log("@babel/preset-env: `DEBUG` option");
|
155 | console.log("\nUsing targets:");
|
156 | console.log(JSON.stringify((0, _utils.prettifyTargets)(targets), null, 2));
|
157 | console.log(`\nUsing modules transform: ${modules.toString()}`);
|
158 | console.log("\nUsing plugins:");
|
159 | transformations.forEach(transform => {
|
160 | (0, _debug.logPluginOrPolyfill)(transform, targets, _plugins.default);
|
161 | });
|
162 |
|
163 | if (!useBuiltIns) {
|
164 | console.log("\nUsing polyfills: No polyfills were added, since the `useBuiltIns` option was not set.");
|
165 | } else {
|
166 | console.log(`\nUsing polyfills with \`${useBuiltIns}\` option:`);
|
167 | }
|
168 | }
|
169 |
|
170 | if (useBuiltIns === "usage" || useBuiltIns === "entry") {
|
171 | const regenerator = transformations.has("transform-regenerator");
|
172 | const pluginOptions = {
|
173 | corejs,
|
174 | polyfillTargets: targets,
|
175 | include: include.builtIns,
|
176 | exclude: exclude.builtIns,
|
177 | proposals,
|
178 | shippedProposals,
|
179 | regenerator,
|
180 | debug
|
181 | };
|
182 |
|
183 | if (corejs) {
|
184 | if (useBuiltIns === "usage") {
|
185 | if (corejs.major === 2) {
|
186 | plugins.push([_usagePlugin.default, pluginOptions]);
|
187 | } else {
|
188 | plugins.push([_usagePlugin2.default, pluginOptions]);
|
189 | }
|
190 |
|
191 | if (regenerator) {
|
192 | plugins.push([_usagePlugin3.default, pluginOptions]);
|
193 | }
|
194 | } else {
|
195 | if (corejs.major === 2) {
|
196 | plugins.push([_entryPlugin.default, pluginOptions]);
|
197 | } else {
|
198 | plugins.push([_entryPlugin2.default, pluginOptions]);
|
199 |
|
200 | if (!regenerator) {
|
201 | plugins.push([_entryPlugin3.default, pluginOptions]);
|
202 | }
|
203 | }
|
204 | }
|
205 | }
|
206 | }
|
207 |
|
208 | return {
|
209 | plugins
|
210 | };
|
211 | });
|
212 |
|
213 | exports.default = _default; |
\ | No newline at end of file |