1 | import corejs2Polyfills from '@babel/compat-data/corejs2-built-ins';
|
---|
2 | import semver from 'semver';
|
---|
3 | import defineProvider from '@babel/helper-define-polyfill-provider';
|
---|
4 | import * as babel from '@babel/core';
|
---|
5 |
|
---|
6 | const define = (name, pure, global = [], meta) => {
|
---|
7 | return {
|
---|
8 | name,
|
---|
9 | pure,
|
---|
10 | global,
|
---|
11 | meta
|
---|
12 | };
|
---|
13 | };
|
---|
14 |
|
---|
15 | const pureAndGlobal = (pure, global, minRuntimeVersion = null) => define(global[0], pure, global, {
|
---|
16 | minRuntimeVersion
|
---|
17 | });
|
---|
18 |
|
---|
19 | const globalOnly = global => define(global[0], null, global);
|
---|
20 |
|
---|
21 | const pureOnly = (pure, name) => define(name, pure, []);
|
---|
22 |
|
---|
23 | const ArrayNatureIterators = ["es6.object.to-string", "es6.array.iterator", "web.dom.iterable"];
|
---|
24 | const CommonIterators = ["es6.string.iterator", ...ArrayNatureIterators];
|
---|
25 | const PromiseDependencies = ["es6.object.to-string", "es6.promise"];
|
---|
26 | const BuiltIns = {
|
---|
27 | DataView: globalOnly(["es6.typed.data-view"]),
|
---|
28 | Float32Array: globalOnly(["es6.typed.float32-array"]),
|
---|
29 | Float64Array: globalOnly(["es6.typed.float64-array"]),
|
---|
30 | Int8Array: globalOnly(["es6.typed.int8-array"]),
|
---|
31 | Int16Array: globalOnly(["es6.typed.int16-array"]),
|
---|
32 | Int32Array: globalOnly(["es6.typed.int32-array"]),
|
---|
33 | Map: pureAndGlobal("map", ["es6.map", ...CommonIterators]),
|
---|
34 | Number: globalOnly(["es6.number.constructor"]),
|
---|
35 | Promise: pureAndGlobal("promise", PromiseDependencies),
|
---|
36 | RegExp: globalOnly(["es6.regexp.constructor"]),
|
---|
37 | Set: pureAndGlobal("set", ["es6.set", ...CommonIterators]),
|
---|
38 | Symbol: pureAndGlobal("symbol", ["es6.symbol"]),
|
---|
39 | Uint8Array: globalOnly(["es6.typed.uint8-array"]),
|
---|
40 | Uint8ClampedArray: globalOnly(["es6.typed.uint8-clamped-array"]),
|
---|
41 | Uint16Array: globalOnly(["es6.typed.uint16-array"]),
|
---|
42 | Uint32Array: globalOnly(["es6.typed.uint32-array"]),
|
---|
43 | WeakMap: pureAndGlobal("weak-map", ["es6.weak-map", ...CommonIterators]),
|
---|
44 | WeakSet: pureAndGlobal("weak-set", ["es6.weak-set", ...CommonIterators]),
|
---|
45 | setImmediate: pureOnly("set-immediate", "web.immediate"),
|
---|
46 | clearImmediate: pureOnly("clear-immediate", "web.immediate"),
|
---|
47 | parseFloat: pureOnly("parse-float", "es6.parse-float"),
|
---|
48 | parseInt: pureOnly("parse-int", "es6.parse-int")
|
---|
49 | };
|
---|
50 | const InstanceProperties = {
|
---|
51 | __defineGetter__: globalOnly(["es7.object.define-getter"]),
|
---|
52 | __defineSetter__: globalOnly(["es7.object.define-setter"]),
|
---|
53 | __lookupGetter__: globalOnly(["es7.object.lookup-getter"]),
|
---|
54 | __lookupSetter__: globalOnly(["es7.object.lookup-setter"]),
|
---|
55 | anchor: globalOnly(["es6.string.anchor"]),
|
---|
56 | big: globalOnly(["es6.string.big"]),
|
---|
57 | bind: globalOnly(["es6.function.bind"]),
|
---|
58 | blink: globalOnly(["es6.string.blink"]),
|
---|
59 | bold: globalOnly(["es6.string.bold"]),
|
---|
60 | codePointAt: globalOnly(["es6.string.code-point-at"]),
|
---|
61 | copyWithin: globalOnly(["es6.array.copy-within"]),
|
---|
62 | endsWith: globalOnly(["es6.string.ends-with"]),
|
---|
63 | entries: globalOnly(ArrayNatureIterators),
|
---|
64 | every: globalOnly(["es6.array.every"]),
|
---|
65 | fill: globalOnly(["es6.array.fill"]),
|
---|
66 | filter: globalOnly(["es6.array.filter"]),
|
---|
67 | finally: globalOnly(["es7.promise.finally", ...PromiseDependencies]),
|
---|
68 | find: globalOnly(["es6.array.find"]),
|
---|
69 | findIndex: globalOnly(["es6.array.find-index"]),
|
---|
70 | fixed: globalOnly(["es6.string.fixed"]),
|
---|
71 | flags: globalOnly(["es6.regexp.flags"]),
|
---|
72 | flatMap: globalOnly(["es7.array.flat-map"]),
|
---|
73 | fontcolor: globalOnly(["es6.string.fontcolor"]),
|
---|
74 | fontsize: globalOnly(["es6.string.fontsize"]),
|
---|
75 | forEach: globalOnly(["es6.array.for-each"]),
|
---|
76 | includes: globalOnly(["es6.string.includes", "es7.array.includes"]),
|
---|
77 | indexOf: globalOnly(["es6.array.index-of"]),
|
---|
78 | italics: globalOnly(["es6.string.italics"]),
|
---|
79 | keys: globalOnly(ArrayNatureIterators),
|
---|
80 | lastIndexOf: globalOnly(["es6.array.last-index-of"]),
|
---|
81 | link: globalOnly(["es6.string.link"]),
|
---|
82 | map: globalOnly(["es6.array.map"]),
|
---|
83 | match: globalOnly(["es6.regexp.match"]),
|
---|
84 | name: globalOnly(["es6.function.name"]),
|
---|
85 | padStart: globalOnly(["es7.string.pad-start"]),
|
---|
86 | padEnd: globalOnly(["es7.string.pad-end"]),
|
---|
87 | reduce: globalOnly(["es6.array.reduce"]),
|
---|
88 | reduceRight: globalOnly(["es6.array.reduce-right"]),
|
---|
89 | repeat: globalOnly(["es6.string.repeat"]),
|
---|
90 | replace: globalOnly(["es6.regexp.replace"]),
|
---|
91 | search: globalOnly(["es6.regexp.search"]),
|
---|
92 | small: globalOnly(["es6.string.small"]),
|
---|
93 | some: globalOnly(["es6.array.some"]),
|
---|
94 | sort: globalOnly(["es6.array.sort"]),
|
---|
95 | split: globalOnly(["es6.regexp.split"]),
|
---|
96 | startsWith: globalOnly(["es6.string.starts-with"]),
|
---|
97 | strike: globalOnly(["es6.string.strike"]),
|
---|
98 | sub: globalOnly(["es6.string.sub"]),
|
---|
99 | sup: globalOnly(["es6.string.sup"]),
|
---|
100 | toISOString: globalOnly(["es6.date.to-iso-string"]),
|
---|
101 | toJSON: globalOnly(["es6.date.to-json"]),
|
---|
102 | toString: globalOnly(["es6.object.to-string", "es6.date.to-string", "es6.regexp.to-string"]),
|
---|
103 | trim: globalOnly(["es6.string.trim"]),
|
---|
104 | trimEnd: globalOnly(["es7.string.trim-right"]),
|
---|
105 | trimLeft: globalOnly(["es7.string.trim-left"]),
|
---|
106 | trimRight: globalOnly(["es7.string.trim-right"]),
|
---|
107 | trimStart: globalOnly(["es7.string.trim-left"]),
|
---|
108 | values: globalOnly(ArrayNatureIterators)
|
---|
109 | }; // This isn't present in older @babel/compat-data versions
|
---|
110 |
|
---|
111 | if ("es6.array.slice" in corejs2Polyfills) {
|
---|
112 | InstanceProperties.slice = globalOnly(["es6.array.slice"]);
|
---|
113 | }
|
---|
114 |
|
---|
115 | const StaticProperties = {
|
---|
116 | Array: {
|
---|
117 | from: pureAndGlobal("array/from", ["es6.symbol", "es6.array.from", ...CommonIterators]),
|
---|
118 | isArray: pureAndGlobal("array/is-array", ["es6.array.is-array"]),
|
---|
119 | of: pureAndGlobal("array/of", ["es6.array.of"])
|
---|
120 | },
|
---|
121 | Date: {
|
---|
122 | now: pureAndGlobal("date/now", ["es6.date.now"])
|
---|
123 | },
|
---|
124 | JSON: {
|
---|
125 | stringify: pureOnly("json/stringify", "es6.symbol")
|
---|
126 | },
|
---|
127 | Math: {
|
---|
128 | // 'Math' was not included in the 7.0.0
|
---|
129 | // release of '@babel/runtime'. See issue https://github.com/babel/babel/pull/8616.
|
---|
130 | acosh: pureAndGlobal("math/acosh", ["es6.math.acosh"], "7.0.1"),
|
---|
131 | asinh: pureAndGlobal("math/asinh", ["es6.math.asinh"], "7.0.1"),
|
---|
132 | atanh: pureAndGlobal("math/atanh", ["es6.math.atanh"], "7.0.1"),
|
---|
133 | cbrt: pureAndGlobal("math/cbrt", ["es6.math.cbrt"], "7.0.1"),
|
---|
134 | clz32: pureAndGlobal("math/clz32", ["es6.math.clz32"], "7.0.1"),
|
---|
135 | cosh: pureAndGlobal("math/cosh", ["es6.math.cosh"], "7.0.1"),
|
---|
136 | expm1: pureAndGlobal("math/expm1", ["es6.math.expm1"], "7.0.1"),
|
---|
137 | fround: pureAndGlobal("math/fround", ["es6.math.fround"], "7.0.1"),
|
---|
138 | hypot: pureAndGlobal("math/hypot", ["es6.math.hypot"], "7.0.1"),
|
---|
139 | imul: pureAndGlobal("math/imul", ["es6.math.imul"], "7.0.1"),
|
---|
140 | log1p: pureAndGlobal("math/log1p", ["es6.math.log1p"], "7.0.1"),
|
---|
141 | log10: pureAndGlobal("math/log10", ["es6.math.log10"], "7.0.1"),
|
---|
142 | log2: pureAndGlobal("math/log2", ["es6.math.log2"], "7.0.1"),
|
---|
143 | sign: pureAndGlobal("math/sign", ["es6.math.sign"], "7.0.1"),
|
---|
144 | sinh: pureAndGlobal("math/sinh", ["es6.math.sinh"], "7.0.1"),
|
---|
145 | tanh: pureAndGlobal("math/tanh", ["es6.math.tanh"], "7.0.1"),
|
---|
146 | trunc: pureAndGlobal("math/trunc", ["es6.math.trunc"], "7.0.1")
|
---|
147 | },
|
---|
148 | Number: {
|
---|
149 | EPSILON: pureAndGlobal("number/epsilon", ["es6.number.epsilon"]),
|
---|
150 | MIN_SAFE_INTEGER: pureAndGlobal("number/min-safe-integer", ["es6.number.min-safe-integer"]),
|
---|
151 | MAX_SAFE_INTEGER: pureAndGlobal("number/max-safe-integer", ["es6.number.max-safe-integer"]),
|
---|
152 | isFinite: pureAndGlobal("number/is-finite", ["es6.number.is-finite"]),
|
---|
153 | isInteger: pureAndGlobal("number/is-integer", ["es6.number.is-integer"]),
|
---|
154 | isSafeInteger: pureAndGlobal("number/is-safe-integer", ["es6.number.is-safe-integer"]),
|
---|
155 | isNaN: pureAndGlobal("number/is-nan", ["es6.number.is-nan"]),
|
---|
156 | parseFloat: pureAndGlobal("number/parse-float", ["es6.number.parse-float"]),
|
---|
157 | parseInt: pureAndGlobal("number/parse-int", ["es6.number.parse-int"])
|
---|
158 | },
|
---|
159 | Object: {
|
---|
160 | assign: pureAndGlobal("object/assign", ["es6.object.assign"]),
|
---|
161 | create: pureAndGlobal("object/create", ["es6.object.create"]),
|
---|
162 | defineProperties: pureAndGlobal("object/define-properties", ["es6.object.define-properties"]),
|
---|
163 | defineProperty: pureAndGlobal("object/define-property", ["es6.object.define-property"]),
|
---|
164 | entries: pureAndGlobal("object/entries", ["es7.object.entries"]),
|
---|
165 | freeze: pureAndGlobal("object/freeze", ["es6.object.freeze"]),
|
---|
166 | getOwnPropertyDescriptor: pureAndGlobal("object/get-own-property-descriptor", ["es6.object.get-own-property-descriptor"]),
|
---|
167 | getOwnPropertyDescriptors: pureAndGlobal("object/get-own-property-descriptors", ["es7.object.get-own-property-descriptors"]),
|
---|
168 | getOwnPropertyNames: pureAndGlobal("object/get-own-property-names", ["es6.object.get-own-property-names"]),
|
---|
169 | getOwnPropertySymbols: pureAndGlobal("object/get-own-property-symbols", ["es6.symbol"]),
|
---|
170 | getPrototypeOf: pureAndGlobal("object/get-prototype-of", ["es6.object.get-prototype-of"]),
|
---|
171 | is: pureAndGlobal("object/is", ["es6.object.is"]),
|
---|
172 | isExtensible: pureAndGlobal("object/is-extensible", ["es6.object.is-extensible"]),
|
---|
173 | isFrozen: pureAndGlobal("object/is-frozen", ["es6.object.is-frozen"]),
|
---|
174 | isSealed: pureAndGlobal("object/is-sealed", ["es6.object.is-sealed"]),
|
---|
175 | keys: pureAndGlobal("object/keys", ["es6.object.keys"]),
|
---|
176 | preventExtensions: pureAndGlobal("object/prevent-extensions", ["es6.object.prevent-extensions"]),
|
---|
177 | seal: pureAndGlobal("object/seal", ["es6.object.seal"]),
|
---|
178 | setPrototypeOf: pureAndGlobal("object/set-prototype-of", ["es6.object.set-prototype-of"]),
|
---|
179 | values: pureAndGlobal("object/values", ["es7.object.values"])
|
---|
180 | },
|
---|
181 | Promise: {
|
---|
182 | all: globalOnly(CommonIterators),
|
---|
183 | race: globalOnly(CommonIterators)
|
---|
184 | },
|
---|
185 | Reflect: {
|
---|
186 | apply: pureAndGlobal("reflect/apply", ["es6.reflect.apply"]),
|
---|
187 | construct: pureAndGlobal("reflect/construct", ["es6.reflect.construct"]),
|
---|
188 | defineProperty: pureAndGlobal("reflect/define-property", ["es6.reflect.define-property"]),
|
---|
189 | deleteProperty: pureAndGlobal("reflect/delete-property", ["es6.reflect.delete-property"]),
|
---|
190 | get: pureAndGlobal("reflect/get", ["es6.reflect.get"]),
|
---|
191 | getOwnPropertyDescriptor: pureAndGlobal("reflect/get-own-property-descriptor", ["es6.reflect.get-own-property-descriptor"]),
|
---|
192 | getPrototypeOf: pureAndGlobal("reflect/get-prototype-of", ["es6.reflect.get-prototype-of"]),
|
---|
193 | has: pureAndGlobal("reflect/has", ["es6.reflect.has"]),
|
---|
194 | isExtensible: pureAndGlobal("reflect/is-extensible", ["es6.reflect.is-extensible"]),
|
---|
195 | ownKeys: pureAndGlobal("reflect/own-keys", ["es6.reflect.own-keys"]),
|
---|
196 | preventExtensions: pureAndGlobal("reflect/prevent-extensions", ["es6.reflect.prevent-extensions"]),
|
---|
197 | set: pureAndGlobal("reflect/set", ["es6.reflect.set"]),
|
---|
198 | setPrototypeOf: pureAndGlobal("reflect/set-prototype-of", ["es6.reflect.set-prototype-of"])
|
---|
199 | },
|
---|
200 | String: {
|
---|
201 | at: pureOnly("string/at", "es7.string.at"),
|
---|
202 | fromCodePoint: pureAndGlobal("string/from-code-point", ["es6.string.from-code-point"]),
|
---|
203 | raw: pureAndGlobal("string/raw", ["es6.string.raw"])
|
---|
204 | },
|
---|
205 | Symbol: {
|
---|
206 | // FIXME: Pure disabled to work around zloirock/core-js#262.
|
---|
207 | asyncIterator: globalOnly(["es6.symbol", "es7.symbol.async-iterator"]),
|
---|
208 | for: pureOnly("symbol/for", "es6.symbol"),
|
---|
209 | hasInstance: pureOnly("symbol/has-instance", "es6.symbol"),
|
---|
210 | isConcatSpreadable: pureOnly("symbol/is-concat-spreadable", "es6.symbol"),
|
---|
211 | iterator: define("es6.symbol", "symbol/iterator", CommonIterators),
|
---|
212 | keyFor: pureOnly("symbol/key-for", "es6.symbol"),
|
---|
213 | match: pureAndGlobal("symbol/match", ["es6.regexp.match"]),
|
---|
214 | replace: pureOnly("symbol/replace", "es6.symbol"),
|
---|
215 | search: pureOnly("symbol/search", "es6.symbol"),
|
---|
216 | species: pureOnly("symbol/species", "es6.symbol"),
|
---|
217 | split: pureOnly("symbol/split", "es6.symbol"),
|
---|
218 | toPrimitive: pureOnly("symbol/to-primitive", "es6.symbol"),
|
---|
219 | toStringTag: pureOnly("symbol/to-string-tag", "es6.symbol"),
|
---|
220 | unscopables: pureOnly("symbol/unscopables", "es6.symbol")
|
---|
221 | }
|
---|
222 | };
|
---|
223 |
|
---|
224 | const webPolyfills = {
|
---|
225 | "web.timers": {},
|
---|
226 | "web.immediate": {},
|
---|
227 | "web.dom.iterable": {}
|
---|
228 | };
|
---|
229 | const purePolyfills = {
|
---|
230 | "es6.parse-float": {},
|
---|
231 | "es6.parse-int": {},
|
---|
232 | "es7.string.at": {}
|
---|
233 | };
|
---|
234 | function addPlatformSpecificPolyfills (targets, method, polyfills) {
|
---|
235 | const targetNames = Object.keys(targets);
|
---|
236 | const isAnyTarget = !targetNames.length;
|
---|
237 | const isWebTarget = targetNames.some(name => name !== "node");
|
---|
238 | return { ...polyfills,
|
---|
239 | ...(method === "usage-pure" ? purePolyfills : null),
|
---|
240 | ...(isAnyTarget || isWebTarget ? webPolyfills : null)
|
---|
241 | };
|
---|
242 | }
|
---|
243 |
|
---|
244 | function hasMinVersion(minVersion, runtimeVersion) {
|
---|
245 | // If the range is unavailable, we're running the script during Babel's
|
---|
246 | // build process, and we want to assume that all versions are satisfied so
|
---|
247 | // that the built output will include all definitions.
|
---|
248 | if (!runtimeVersion || !minVersion) return true; // semver.intersects() has some surprising behavior with comparing ranges
|
---|
249 | // with preprelease versions. We add '^' to ensure that we are always
|
---|
250 | // comparing ranges with ranges, which sidesteps this logic.
|
---|
251 | // For example:
|
---|
252 | //
|
---|
253 | // semver.intersects(`<7.0.1`, "7.0.0-beta.0") // false - surprising
|
---|
254 | // semver.intersects(`<7.0.1`, "^7.0.0-beta.0") // true - expected
|
---|
255 | //
|
---|
256 | // This is because the first falls back to
|
---|
257 | //
|
---|
258 | // semver.satisfies("7.0.0-beta.0", `<7.0.1`) // false - surprising
|
---|
259 | //
|
---|
260 | // and this fails because a prerelease version can only satisfy a range
|
---|
261 | // if it is a prerelease within the same major/minor/patch range.
|
---|
262 | //
|
---|
263 | // Note: If this is found to have issues, please also revist the logic in
|
---|
264 | // babel-core's availableHelper() API.
|
---|
265 |
|
---|
266 | if (semver.valid(runtimeVersion)) runtimeVersion = `^${runtimeVersion}`;
|
---|
267 | return !semver.intersects(`<${minVersion}`, runtimeVersion) && !semver.intersects(`>=8.0.0`, runtimeVersion);
|
---|
268 | }
|
---|
269 |
|
---|
270 | const {
|
---|
271 | types: t
|
---|
272 | } = babel.default || babel;
|
---|
273 | const presetEnvCompat = "#__secret_key__@babel/preset-env__compatibility";
|
---|
274 | const runtimeCompat = "#__secret_key__@babel/runtime__compatibility"; // $FlowIgnore
|
---|
275 |
|
---|
276 | const has = Function.call.bind(Object.hasOwnProperty);
|
---|
277 | var index = defineProvider(function (api, {
|
---|
278 | [presetEnvCompat]: {
|
---|
279 | entryInjectRegenerator
|
---|
280 | } = {},
|
---|
281 | [runtimeCompat]: {
|
---|
282 | useBabelRuntime,
|
---|
283 | runtimeVersion,
|
---|
284 | ext = ".js"
|
---|
285 | } = {}
|
---|
286 | }) {
|
---|
287 | const resolve = api.createMetaResolver({
|
---|
288 | global: BuiltIns,
|
---|
289 | static: StaticProperties,
|
---|
290 | instance: InstanceProperties
|
---|
291 | });
|
---|
292 | const {
|
---|
293 | debug,
|
---|
294 | shouldInjectPolyfill,
|
---|
295 | method
|
---|
296 | } = api;
|
---|
297 | const polyfills = addPlatformSpecificPolyfills(api.targets, method, corejs2Polyfills);
|
---|
298 | const coreJSBase = useBabelRuntime ? `${useBabelRuntime}/core-js` : method === "usage-pure" ? "core-js/library/fn" : "core-js/modules";
|
---|
299 |
|
---|
300 | function inject(name, utils) {
|
---|
301 | if (typeof name === "string") {
|
---|
302 | // Some polyfills aren't always available, for example
|
---|
303 | // web.dom.iterable when targeting node
|
---|
304 | if (has(polyfills, name) && shouldInjectPolyfill(name)) {
|
---|
305 | debug(name);
|
---|
306 | utils.injectGlobalImport(`${coreJSBase}/${name}.js`);
|
---|
307 | }
|
---|
308 |
|
---|
309 | return;
|
---|
310 | }
|
---|
311 |
|
---|
312 | name.forEach(name => inject(name, utils));
|
---|
313 | }
|
---|
314 |
|
---|
315 | function maybeInjectPure(desc, hint, utils) {
|
---|
316 | const {
|
---|
317 | pure,
|
---|
318 | meta,
|
---|
319 | name
|
---|
320 | } = desc;
|
---|
321 | if (!pure || !shouldInjectPolyfill(name)) return;
|
---|
322 |
|
---|
323 | if (runtimeVersion && meta && meta.minRuntimeVersion && !hasMinVersion(meta && meta.minRuntimeVersion, runtimeVersion)) {
|
---|
324 | return;
|
---|
325 | }
|
---|
326 |
|
---|
327 | return utils.injectDefaultImport(`${coreJSBase}/${pure}${ext}`, hint);
|
---|
328 | }
|
---|
329 |
|
---|
330 | return {
|
---|
331 | name: "corejs2",
|
---|
332 | polyfills,
|
---|
333 |
|
---|
334 | entryGlobal(meta, utils, path) {
|
---|
335 | if (meta.kind === "import" && meta.source === "core-js") {
|
---|
336 | debug(null);
|
---|
337 | inject(Object.keys(polyfills), utils);
|
---|
338 |
|
---|
339 | if (entryInjectRegenerator) {
|
---|
340 | utils.injectGlobalImport("regenerator-runtime/runtime.js");
|
---|
341 | }
|
---|
342 |
|
---|
343 | path.remove();
|
---|
344 | }
|
---|
345 | },
|
---|
346 |
|
---|
347 | usageGlobal(meta, utils) {
|
---|
348 | const resolved = resolve(meta);
|
---|
349 | if (!resolved) return;
|
---|
350 | let deps = resolved.desc.global;
|
---|
351 |
|
---|
352 | if (resolved.kind !== "global" && meta.object && meta.placement === "prototype") {
|
---|
353 | const low = meta.object.toLowerCase();
|
---|
354 | deps = deps.filter(m => m.includes(low));
|
---|
355 | }
|
---|
356 |
|
---|
357 | inject(deps, utils);
|
---|
358 | },
|
---|
359 |
|
---|
360 | usagePure(meta, utils, path) {
|
---|
361 | if (meta.kind === "in") {
|
---|
362 | if (meta.key === "Symbol.iterator") {
|
---|
363 | path.replaceWith(t.callExpression(utils.injectDefaultImport(`${coreJSBase}/is-iterable${ext}`, "isIterable"), [path.node.right]));
|
---|
364 | }
|
---|
365 |
|
---|
366 | return;
|
---|
367 | }
|
---|
368 |
|
---|
369 | if (path.parentPath.isUnaryExpression({
|
---|
370 | operator: "delete"
|
---|
371 | })) return;
|
---|
372 |
|
---|
373 | if (meta.kind === "property") {
|
---|
374 | // We can't compile destructuring.
|
---|
375 | if (!path.isMemberExpression()) return;
|
---|
376 | if (!path.isReferenced()) return;
|
---|
377 |
|
---|
378 | if (meta.key === "Symbol.iterator" && shouldInjectPolyfill("es6.symbol") && path.parentPath.isCallExpression({
|
---|
379 | callee: path.node
|
---|
380 | }) && path.parent.arguments.length === 0) {
|
---|
381 | path.parentPath.replaceWith(t.callExpression(utils.injectDefaultImport(`${coreJSBase}/get-iterator${ext}`, "getIterator"), [path.node.object]));
|
---|
382 | path.skip();
|
---|
383 | return;
|
---|
384 | }
|
---|
385 | }
|
---|
386 |
|
---|
387 | const resolved = resolve(meta);
|
---|
388 | if (!resolved) return;
|
---|
389 | const id = maybeInjectPure(resolved.desc, resolved.name, utils);
|
---|
390 | if (id) path.replaceWith(id);
|
---|
391 | },
|
---|
392 |
|
---|
393 | visitor: method === "usage-global" && {
|
---|
394 | // yield*
|
---|
395 | YieldExpression(path) {
|
---|
396 | if (path.node.delegate) {
|
---|
397 | inject("web.dom.iterable", api.getUtils(path));
|
---|
398 | }
|
---|
399 | },
|
---|
400 |
|
---|
401 | // for-of, [a, b] = c
|
---|
402 | "ForOfStatement|ArrayPattern"(path) {
|
---|
403 | CommonIterators.forEach(name => inject(name, api.getUtils(path)));
|
---|
404 | }
|
---|
405 |
|
---|
406 | }
|
---|
407 | };
|
---|
408 | });
|
---|
409 |
|
---|
410 | export default index;
|
---|
411 | //# sourceMappingURL=index.mjs.map
|
---|