source: imaps-frontend/node_modules/babel-plugin-polyfill-corejs2/esm/index.mjs

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

F4 Finalna Verzija

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