babel-plugin-polyfill-corejs3
Advanced tools
+25
-62
@@ -8,4 +8,5 @@ import corejs3Polyfills from '../core-js-compat/data.js'; | ||
| // This file is automatically generated by scripts/build-corejs3-shipped-proposals.mjs | ||
| var corejs3ShippedProposalsList = new Set(["esnext.array.from-async", "esnext.array.group", "esnext.array.group-to-map", "esnext.array-buffer.detached", "esnext.array-buffer.transfer", "esnext.array-buffer.transfer-to-fixed-length", "esnext.json.is-raw-json", "esnext.json.parse", "esnext.json.raw-json", "esnext.set.difference.v2", "esnext.set.intersection.v2", "esnext.set.is-disjoint-from.v2", "esnext.set.is-subset-of.v2", "esnext.set.is-superset-of.v2", "esnext.set.symmetric-difference.v2", "esnext.set.union.v2", "esnext.string.is-well-formed", "esnext.string.to-well-formed"]); | ||
| var corejs3ShippedProposalsList = new Set(["esnext.array.from-async", "esnext.array.group", "esnext.array.group-to-map", "esnext.array-buffer.detached", "esnext.array-buffer.transfer", "esnext.array-buffer.transfer-to-fixed-length", "esnext.json.is-raw-json", "esnext.json.parse", "esnext.json.raw-json", "esnext.set.difference.v2", "esnext.set.intersection.v2", "esnext.set.is-disjoint-from.v2", "esnext.set.is-subset-of.v2", "esnext.set.is-superset-of.v2", "esnext.set.symmetric-difference.v2", "esnext.set.union.v2"]); | ||
| const polyfillsOrder = {}; | ||
@@ -15,3 +16,2 @@ Object.keys(corejs3Polyfills).forEach((name, index) => { | ||
| }); | ||
| const define = (pure, global, name = global[0], exclude) => { | ||
@@ -25,5 +25,3 @@ return { | ||
| }; | ||
| const typed = name => define(null, [name, ...TypedArrayDependencies]); | ||
| const ArrayNatureIterators = ["es.array.iterator", "web.dom-collections.iterator"]; | ||
@@ -44,3 +42,3 @@ const CommonIterators = ["es.string.iterator", ...ArrayNatureIterators]; | ||
| const DOMExceptionDependencies = ["web.dom-exception.constructor", "web.dom-exception.stack", "web.dom-exception.to-string-tag", "es.error.to-string"]; | ||
| const URLSearchParamsDependencies = ["web.url-search-params", "web.url-search-params.size", ...CommonIteratorsWithTag]; | ||
| const URLSearchParamsDependencies = ["web.url-search-params", "web.url-search-params.delete", "web.url-search-params.has", "web.url-search-params.size", ...CommonIteratorsWithTag]; | ||
| const AsyncIteratorDependencies = ["esnext.async-iterator.constructor", ...PromiseDependencies]; | ||
@@ -209,2 +207,3 @@ const AsyncIteratorProblemMethods = ["esnext.async-iterator.every", "esnext.async-iterator.filter", "esnext.async-iterator.find", "esnext.async-iterator.flat-map", "esnext.async-iterator.for-each", "esnext.async-iterator.map", "esnext.async-iterator.reduce", "esnext.async-iterator.some"]; | ||
| getPrototypeOf: define("object/get-prototype-of", ["es.object.get-prototype-of"]), | ||
| groupBy: define("object/group-by", ["esnext.object.group-by", "es.object.create"]), | ||
| hasOwn: define("object/has-own", ["es.object.has-own"]), | ||
@@ -226,3 +225,4 @@ is: define("object/is", ["es.object.is"]), | ||
| race: define(null, PromiseDependenciesWithIterators), | ||
| try: define(null, ["esnext.promise.try", ...PromiseDependenciesWithIterators]) | ||
| try: define(null, ["esnext.promise.try", ...PromiseDependencies]), | ||
| withResolvers: define(null, ["esnext.promise.with-resolvers", ...PromiseDependencies]) | ||
| }, | ||
@@ -271,3 +271,5 @@ Reflect: { | ||
| isRegistered: define("symbol/is-registered", ["esnext.symbol.is-registered", "es.symbol"]), | ||
| isRegisteredSymbol: define("symbol/is-registered-symbol", ["esnext.symbol.is-registered-symbol", "es.symbol"]), | ||
| isWellKnown: define("symbol/is-well-known", ["esnext.symbol.is-well-known", "es.symbol"]), | ||
| isWellKnownSymbol: define("symbol/is-well-known-symbol", ["esnext.symbol.is-well-known-symbol", "es.symbol"]), | ||
| iterator: define("symbol/iterator", ["es.symbol.iterator", ...CommonIteratorsWithTag]), | ||
@@ -278,3 +280,3 @@ keyFor: define("symbol/key-for", [], "es.symbol"), | ||
| matchAll: define("symbol/match-all", ["es.symbol.match-all", "es.string.match-all"]), | ||
| metadata: define("symbol/metadata", ["esnext.symbol.metadata"]), | ||
| metadata: define("symbol/metadata", ["esnext.symbol.metadata", "esnext.function.metadata"]), | ||
| metadataKey: define("symbol/metadata-key", ["esnext.symbol.metadata-key"]), | ||
@@ -319,3 +321,4 @@ observable: define("symbol/observable", ["esnext.symbol.observable"]), | ||
| asIndexedPairs: define("instance/asIndexedPairs", ["esnext.async-iterator.as-indexed-pairs", ...AsyncIteratorDependencies, "esnext.iterator.as-indexed-pairs", ...IteratorDependencies]), | ||
| at: define("instance/at", [// TODO: We should introduce overloaded instance methods definition | ||
| at: define("instance/at", [ | ||
| // TODO: We should introduce overloaded instance methods definition | ||
| // Before that is implemented, the `esnext.string.at` must be the first | ||
@@ -343,3 +346,4 @@ // In pure mode, the provider resolves the descriptor as a "pure" `esnext.string.at` | ||
| entries: define("instance/entries", ArrayNatureIteratorsWithTag), | ||
| every: define("instance/every", ["es.array.every", "esnext.async-iterator.every", // TODO: add async iterator dependencies when we support sub-dependencies | ||
| every: define("instance/every", ["es.array.every", "esnext.async-iterator.every", | ||
| // TODO: add async iterator dependencies when we support sub-dependencies | ||
| // esnext.async-iterator.every depends on es.promise | ||
@@ -374,3 +378,3 @@ // but we don't want to pull es.promise when esnext.async-iterator is disabled | ||
| indexOf: define("instance/index-of", ["es.array.index-of"]), | ||
| isWellFormed: define("instance/is-well-formed", ["esnext.string.is-well-formed"]), | ||
| isWellFormed: define("instance/is-well-formed", ["es.string.is-well-formed"]), | ||
| italic: define(null, ["es.string.italics"]), | ||
@@ -424,3 +428,3 @@ join: define(null, ["es.array.join"]), | ||
| toString: define(null, ["es.object.to-string", "es.error.to-string", "es.date.to-string", "es.regexp.to-string"]), | ||
| toWellFormed: define("instance/to-well-formed", ["esnext.string.to-well-formed"]), | ||
| toWellFormed: define("instance/to-well-formed", ["es.string.to-well-formed"]), | ||
| trim: define("instance/trim", ["es.string.trim"]), | ||
@@ -451,3 +455,2 @@ trimEnd: define("instance/trim-end", ["es.string.trim-end"]), | ||
| } = path; | ||
| switch (desc.name) { | ||
@@ -475,3 +478,2 @@ case "es.string.split": | ||
| let context1, context2; | ||
| if (t$1.isIdentifier(object)) { | ||
@@ -484,3 +486,2 @@ context1 = object; | ||
| } | ||
| path.replaceWith(t$1.memberExpression(t$1.callExpression(id, [context2]), t$1.identifier("call"))); | ||
@@ -493,3 +494,2 @@ path.parentPath.unshiftContainer("arguments", context1); | ||
| } | ||
| return Object.prototype.hasOwnProperty.call(corejsEntries, source) && corejsEntries[source]; | ||
@@ -510,3 +510,2 @@ } | ||
| const uniqueObjects = ["array", "string", "iterator", "async-iterator", "dom-collections"].map(v => new RegExp(`[a-z]*\\.${v}\\..*`)); | ||
| const esnextFallback = (name, cb) => { | ||
@@ -519,3 +518,2 @@ if (cb(name)) return true; | ||
| }; | ||
| var index = defineProvider(function ({ | ||
@@ -547,7 +545,5 @@ getUtils, | ||
| const available = new Set(getModulesListForTargetVersion(version)); | ||
| function getCoreJSPureBase(useProposalBase) { | ||
| return useBabelRuntime ? useProposalBase ? `${BABEL_RUNTIME}/core-js` : `${BABEL_RUNTIME}/core-js-stable` : useProposalBase ? "core-js-pure/features" : "core-js-pure/stable"; | ||
| } | ||
| function maybeInjectGlobalImpl(name, utils) { | ||
@@ -559,6 +555,4 @@ if (shouldInjectPolyfill(name)) { | ||
| } | ||
| return false; | ||
| } | ||
| function maybeInjectGlobal(names, utils, fallback = true) { | ||
@@ -573,3 +567,2 @@ for (const name of names) { | ||
| } | ||
| function maybeInjectPure(desc, hint, utils, object) { | ||
@@ -581,3 +574,2 @@ if (desc.pure && !(object && desc.exclude && desc.exclude.includes(object)) && esnextFallback(desc.name, shouldInjectPolyfill)) { | ||
| let useProposalBase = false; | ||
| if (proposals || shippedProposals && name.startsWith("esnext.")) { | ||
@@ -588,3 +580,2 @@ useProposalBase = true; | ||
| } | ||
| const coreJSPureBase = getCoreJSPureBase(useProposalBase); | ||
@@ -594,14 +585,11 @@ return utils.injectDefaultImport(`${coreJSPureBase}/${desc.pure}${ext}`, hint); | ||
| } | ||
| function isFeatureStable(name) { | ||
| if (name.startsWith("esnext.")) { | ||
| const esName = `es.${name.slice(7)}`; // If its imaginative esName is not in latest compat data, it means | ||
| const esName = `es.${name.slice(7)}`; | ||
| // If its imaginative esName is not in latest compat data, it means | ||
| // the proposal is not stage 4 | ||
| return esName in corejs3Polyfills; | ||
| } | ||
| return true; | ||
| } | ||
| return { | ||
@@ -611,14 +599,10 @@ name: "corejs3", | ||
| polyfills: corejs3Polyfills, | ||
| filterPolyfills(name) { | ||
| if (!available.has(name)) return false; | ||
| if (proposals || method === "entry-global") return true; | ||
| if (shippedProposals && corejs3ShippedProposalsList.has(name)) { | ||
| return true; | ||
| } | ||
| return isFeatureStable(name); | ||
| }, | ||
| entryGlobal(meta, utils, path) { | ||
@@ -628,3 +612,2 @@ if (meta.kind !== "import") return; | ||
| if (!modules) return; | ||
| if (modules.length === 1 && meta.source === coreJSModule(modules[0]) && shouldInjectPolyfill(modules[0])) { | ||
@@ -636,3 +619,2 @@ // Avoid infinite loop: do not replace imports with a new copy of | ||
| } | ||
| const modulesSet = new Set(modules); | ||
@@ -642,7 +624,5 @@ const filteredModules = modules.filter(module => { | ||
| const stable = module.replace("esnext.", "es."); | ||
| if (modulesSet.has(stable) && shouldInjectPolyfill(stable)) { | ||
| return false; | ||
| } | ||
| return true; | ||
@@ -653,3 +633,2 @@ }); | ||
| }, | ||
| usageGlobal(meta, utils, path) { | ||
@@ -660,3 +639,2 @@ const resolved = resolve(meta); | ||
| let deps = resolved.desc.global; | ||
| if (resolved.kind !== "global" && "object" in meta && meta.object && meta.placement === "prototype") { | ||
@@ -666,6 +644,4 @@ const low = meta.object.toLowerCase(); | ||
| } | ||
| maybeInjectGlobal(deps, utils); | ||
| }, | ||
| usagePure(meta, utils, path) { | ||
@@ -680,7 +656,5 @@ if (meta.kind === "in") { | ||
| } | ||
| if (path.parentPath.isUnaryExpression({ | ||
| operator: "delete" | ||
| })) return; | ||
| if (meta.kind === "property") { | ||
@@ -691,7 +665,5 @@ // We can't compile destructuring and updateExpression. | ||
| if (path.parentPath.isUpdateExpression()) return; | ||
| if (t.isSuper(path.node.object)) { | ||
| return; | ||
| } | ||
| if (meta.key === "Symbol.iterator") { | ||
@@ -703,3 +675,2 @@ if (!shouldInjectPolyfill("es.symbol.iterator")) return; | ||
| } = path; | ||
| if (t.isCallExpression(parent, { | ||
@@ -717,15 +688,14 @@ callee: node | ||
| } | ||
| return; | ||
| } | ||
| } | ||
| let resolved = resolve(meta); | ||
| if (!resolved) return; | ||
| if (canSkipPolyfill(resolved.desc, path)) return; | ||
| if (useBabelRuntime && resolved.desc.pure && resolved.desc.pure.slice(-6) === "/index") { | ||
| // Remove /index, since it doesn't exist in @babel/runtime-corejs3s | ||
| resolved = { ...resolved, | ||
| desc: { ...resolved.desc, | ||
| resolved = { | ||
| ...resolved, | ||
| desc: { | ||
| ...resolved.desc, | ||
| pure: resolved.desc.pure.slice(0, -6) | ||
@@ -735,3 +705,2 @@ } | ||
| } | ||
| if (resolved.kind === "global") { | ||
@@ -741,7 +710,9 @@ const id = maybeInjectPure(resolved.desc, resolved.name, utils); | ||
| } else if (resolved.kind === "static") { | ||
| const id = maybeInjectPure(resolved.desc, resolved.name, utils, // @ts-expect-error | ||
| const id = maybeInjectPure(resolved.desc, resolved.name, utils, | ||
| // @ts-expect-error | ||
| meta.object); | ||
| if (id) path.replaceWith(id); | ||
| } else if (resolved.kind === "instance") { | ||
| const id = maybeInjectPure(resolved.desc, `${resolved.name}InstanceProperty`, utils, // @ts-expect-error | ||
| const id = maybeInjectPure(resolved.desc, `${resolved.name}InstanceProperty`, utils, | ||
| // @ts-expect-error | ||
| meta.object); | ||
@@ -752,3 +723,2 @@ if (!id) return; | ||
| } = path; | ||
| if (t.isCallExpression(path.parent, { | ||
@@ -763,3 +733,2 @@ callee: node | ||
| }, | ||
| visitor: method === "usage-global" && { | ||
@@ -770,3 +739,2 @@ // import("foo") | ||
| const utils = getUtils(path); | ||
| if (isWebpack) { | ||
@@ -780,3 +748,2 @@ // Webpack uses Promise.all to handle dynamic import. | ||
| }, | ||
| // (async function () { }).finally(...) | ||
@@ -788,3 +755,2 @@ Function(path) { | ||
| }, | ||
| // for-of, [a, b] = c | ||
@@ -794,3 +760,2 @@ "ForOfStatement|ArrayPattern"(path) { | ||
| }, | ||
| // [...spread] | ||
@@ -802,3 +767,2 @@ SpreadElement(path) { | ||
| }, | ||
| // yield* | ||
@@ -810,3 +774,2 @@ YieldExpression(path) { | ||
| } | ||
| } | ||
@@ -813,0 +776,0 @@ }; |
@@ -5,7 +5,4 @@ "use strict"; | ||
| exports.StaticProperties = exports.PromiseDependenciesWithIterators = exports.PromiseDependencies = exports.InstanceProperties = exports.CommonIterators = exports.BuiltIns = void 0; | ||
| var _data = _interopRequireDefault(require("../core-js-compat/data.js")); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| const polyfillsOrder = {}; | ||
@@ -15,3 +12,2 @@ Object.keys(_data.default).forEach((name, index) => { | ||
| }); | ||
| const define = (pure, global, name = global[0], exclude) => { | ||
@@ -25,5 +21,3 @@ return { | ||
| }; | ||
| const typed = name => define(null, [name, ...TypedArrayDependencies]); | ||
| const ArrayNatureIterators = ["es.array.iterator", "web.dom-collections.iterator"]; | ||
@@ -47,3 +41,3 @@ const CommonIterators = ["es.string.iterator", ...ArrayNatureIterators]; | ||
| const DOMExceptionDependencies = ["web.dom-exception.constructor", "web.dom-exception.stack", "web.dom-exception.to-string-tag", "es.error.to-string"]; | ||
| const URLSearchParamsDependencies = ["web.url-search-params", "web.url-search-params.size", ...CommonIteratorsWithTag]; | ||
| const URLSearchParamsDependencies = ["web.url-search-params", "web.url-search-params.delete", "web.url-search-params.has", "web.url-search-params.size", ...CommonIteratorsWithTag]; | ||
| const AsyncIteratorDependencies = ["esnext.async-iterator.constructor", ...PromiseDependencies]; | ||
@@ -213,2 +207,3 @@ const AsyncIteratorProblemMethods = ["esnext.async-iterator.every", "esnext.async-iterator.filter", "esnext.async-iterator.find", "esnext.async-iterator.flat-map", "esnext.async-iterator.for-each", "esnext.async-iterator.map", "esnext.async-iterator.reduce", "esnext.async-iterator.some"]; | ||
| getPrototypeOf: define("object/get-prototype-of", ["es.object.get-prototype-of"]), | ||
| groupBy: define("object/group-by", ["esnext.object.group-by", "es.object.create"]), | ||
| hasOwn: define("object/has-own", ["es.object.has-own"]), | ||
@@ -230,3 +225,4 @@ is: define("object/is", ["es.object.is"]), | ||
| race: define(null, PromiseDependenciesWithIterators), | ||
| try: define(null, ["esnext.promise.try", ...PromiseDependenciesWithIterators]) | ||
| try: define(null, ["esnext.promise.try", ...PromiseDependencies]), | ||
| withResolvers: define(null, ["esnext.promise.with-resolvers", ...PromiseDependencies]) | ||
| }, | ||
@@ -275,3 +271,5 @@ Reflect: { | ||
| isRegistered: define("symbol/is-registered", ["esnext.symbol.is-registered", "es.symbol"]), | ||
| isRegisteredSymbol: define("symbol/is-registered-symbol", ["esnext.symbol.is-registered-symbol", "es.symbol"]), | ||
| isWellKnown: define("symbol/is-well-known", ["esnext.symbol.is-well-known", "es.symbol"]), | ||
| isWellKnownSymbol: define("symbol/is-well-known-symbol", ["esnext.symbol.is-well-known-symbol", "es.symbol"]), | ||
| iterator: define("symbol/iterator", ["es.symbol.iterator", ...CommonIteratorsWithTag]), | ||
@@ -282,3 +280,3 @@ keyFor: define("symbol/key-for", [], "es.symbol"), | ||
| matchAll: define("symbol/match-all", ["es.symbol.match-all", "es.string.match-all"]), | ||
| metadata: define("symbol/metadata", ["esnext.symbol.metadata"]), | ||
| metadata: define("symbol/metadata", ["esnext.symbol.metadata", "esnext.function.metadata"]), | ||
| metadataKey: define("symbol/metadata-key", ["esnext.symbol.metadata-key"]), | ||
@@ -324,3 +322,4 @@ observable: define("symbol/observable", ["esnext.symbol.observable"]), | ||
| asIndexedPairs: define("instance/asIndexedPairs", ["esnext.async-iterator.as-indexed-pairs", ...AsyncIteratorDependencies, "esnext.iterator.as-indexed-pairs", ...IteratorDependencies]), | ||
| at: define("instance/at", [// TODO: We should introduce overloaded instance methods definition | ||
| at: define("instance/at", [ | ||
| // TODO: We should introduce overloaded instance methods definition | ||
| // Before that is implemented, the `esnext.string.at` must be the first | ||
@@ -348,3 +347,4 @@ // In pure mode, the provider resolves the descriptor as a "pure" `esnext.string.at` | ||
| entries: define("instance/entries", ArrayNatureIteratorsWithTag), | ||
| every: define("instance/every", ["es.array.every", "esnext.async-iterator.every", // TODO: add async iterator dependencies when we support sub-dependencies | ||
| every: define("instance/every", ["es.array.every", "esnext.async-iterator.every", | ||
| // TODO: add async iterator dependencies when we support sub-dependencies | ||
| // esnext.async-iterator.every depends on es.promise | ||
@@ -379,3 +379,3 @@ // but we don't want to pull es.promise when esnext.async-iterator is disabled | ||
| indexOf: define("instance/index-of", ["es.array.index-of"]), | ||
| isWellFormed: define("instance/is-well-formed", ["esnext.string.is-well-formed"]), | ||
| isWellFormed: define("instance/is-well-formed", ["es.string.is-well-formed"]), | ||
| italic: define(null, ["es.string.italics"]), | ||
@@ -429,3 +429,3 @@ join: define(null, ["es.array.join"]), | ||
| toString: define(null, ["es.object.to-string", "es.error.to-string", "es.date.to-string", "es.regexp.to-string"]), | ||
| toWellFormed: define("instance/to-well-formed", ["esnext.string.to-well-formed"]), | ||
| toWellFormed: define("instance/to-well-formed", ["es.string.to-well-formed"]), | ||
| trim: define("instance/trim", ["es.string.trim"]), | ||
@@ -432,0 +432,0 @@ trimEnd: define("instance/trim-end", ["es.string.trim-end"]), |
+6
-59
@@ -5,27 +5,14 @@ "use strict"; | ||
| exports.default = void 0; | ||
| var _data = _interopRequireDefault(require("../core-js-compat/data.js")); | ||
| var _shippedProposals = _interopRequireDefault(require("./shipped-proposals")); | ||
| var _getModulesListForTargetVersion = _interopRequireDefault(require("../core-js-compat/get-modules-list-for-target-version.js")); | ||
| var _builtInDefinitions = require("./built-in-definitions"); | ||
| var _usageFilters = _interopRequireDefault(require("./usage-filters")); | ||
| var _babel = _interopRequireWildcard(require("@babel/core")); | ||
| var _utils = require("./utils"); | ||
| var _helperDefinePolyfillProvider = _interopRequireDefault(require("@babel/helper-define-polyfill-provider")); | ||
| function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
| function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
| const { | ||
@@ -37,3 +24,2 @@ types: t | ||
| const uniqueObjects = ["array", "string", "iterator", "async-iterator", "dom-collections"].map(v => new RegExp(`[a-z]*\\.${v}\\..*`)); | ||
| const esnextFallback = (name, cb) => { | ||
@@ -46,3 +32,2 @@ if (cb(name)) return true; | ||
| }; | ||
| var _default = (0, _helperDefinePolyfillProvider.default)(function ({ | ||
@@ -74,7 +59,5 @@ getUtils, | ||
| const available = new Set((0, _getModulesListForTargetVersion.default)(version)); | ||
| function getCoreJSPureBase(useProposalBase) { | ||
| return useBabelRuntime ? useProposalBase ? `${_utils.BABEL_RUNTIME}/core-js` : `${_utils.BABEL_RUNTIME}/core-js-stable` : useProposalBase ? "core-js-pure/features" : "core-js-pure/stable"; | ||
| } | ||
| function maybeInjectGlobalImpl(name, utils) { | ||
@@ -86,6 +69,4 @@ if (shouldInjectPolyfill(name)) { | ||
| } | ||
| return false; | ||
| } | ||
| function maybeInjectGlobal(names, utils, fallback = true) { | ||
@@ -100,3 +81,2 @@ for (const name of names) { | ||
| } | ||
| function maybeInjectPure(desc, hint, utils, object) { | ||
@@ -108,3 +88,2 @@ if (desc.pure && !(object && desc.exclude && desc.exclude.includes(object)) && esnextFallback(desc.name, shouldInjectPolyfill)) { | ||
| let useProposalBase = false; | ||
| if (proposals || shippedProposals && name.startsWith("esnext.")) { | ||
@@ -115,3 +94,2 @@ useProposalBase = true; | ||
| } | ||
| const coreJSPureBase = getCoreJSPureBase(useProposalBase); | ||
@@ -121,14 +99,11 @@ return utils.injectDefaultImport(`${coreJSPureBase}/${desc.pure}${ext}`, hint); | ||
| } | ||
| function isFeatureStable(name) { | ||
| if (name.startsWith("esnext.")) { | ||
| const esName = `es.${name.slice(7)}`; // If its imaginative esName is not in latest compat data, it means | ||
| const esName = `es.${name.slice(7)}`; | ||
| // If its imaginative esName is not in latest compat data, it means | ||
| // the proposal is not stage 4 | ||
| return esName in _data.default; | ||
| } | ||
| return true; | ||
| } | ||
| return { | ||
@@ -138,14 +113,10 @@ name: "corejs3", | ||
| polyfills: _data.default, | ||
| filterPolyfills(name) { | ||
| if (!available.has(name)) return false; | ||
| if (proposals || method === "entry-global") return true; | ||
| if (shippedProposals && _shippedProposals.default.has(name)) { | ||
| return true; | ||
| } | ||
| return isFeatureStable(name); | ||
| }, | ||
| entryGlobal(meta, utils, path) { | ||
@@ -155,3 +126,2 @@ if (meta.kind !== "import") return; | ||
| if (!modules) return; | ||
| if (modules.length === 1 && meta.source === (0, _utils.coreJSModule)(modules[0]) && shouldInjectPolyfill(modules[0])) { | ||
@@ -163,3 +133,2 @@ // Avoid infinite loop: do not replace imports with a new copy of | ||
| } | ||
| const modulesSet = new Set(modules); | ||
@@ -169,7 +138,5 @@ const filteredModules = modules.filter(module => { | ||
| const stable = module.replace("esnext.", "es."); | ||
| if (modulesSet.has(stable) && shouldInjectPolyfill(stable)) { | ||
| return false; | ||
| } | ||
| return true; | ||
@@ -180,3 +147,2 @@ }); | ||
| }, | ||
| usageGlobal(meta, utils, path) { | ||
@@ -187,3 +153,2 @@ const resolved = resolve(meta); | ||
| let deps = resolved.desc.global; | ||
| if (resolved.kind !== "global" && "object" in meta && meta.object && meta.placement === "prototype") { | ||
@@ -193,6 +158,4 @@ const low = meta.object.toLowerCase(); | ||
| } | ||
| maybeInjectGlobal(deps, utils); | ||
| }, | ||
| usagePure(meta, utils, path) { | ||
@@ -207,7 +170,5 @@ if (meta.kind === "in") { | ||
| } | ||
| if (path.parentPath.isUnaryExpression({ | ||
| operator: "delete" | ||
| })) return; | ||
| if (meta.kind === "property") { | ||
@@ -218,7 +179,5 @@ // We can't compile destructuring and updateExpression. | ||
| if (path.parentPath.isUpdateExpression()) return; | ||
| if (t.isSuper(path.node.object)) { | ||
| return; | ||
| } | ||
| if (meta.key === "Symbol.iterator") { | ||
@@ -230,3 +189,2 @@ if (!shouldInjectPolyfill("es.symbol.iterator")) return; | ||
| } = path; | ||
| if (t.isCallExpression(parent, { | ||
@@ -244,11 +202,8 @@ callee: node | ||
| } | ||
| return; | ||
| } | ||
| } | ||
| let resolved = resolve(meta); | ||
| if (!resolved) return; | ||
| if ((0, _usageFilters.default)(resolved.desc, path)) return; | ||
| if (useBabelRuntime && resolved.desc.pure && resolved.desc.pure.slice(-6) === "/index") { | ||
@@ -262,3 +217,2 @@ // Remove /index, since it doesn't exist in @babel/runtime-corejs3s | ||
| } | ||
| if (resolved.kind === "global") { | ||
@@ -268,7 +222,9 @@ const id = maybeInjectPure(resolved.desc, resolved.name, utils); | ||
| } else if (resolved.kind === "static") { | ||
| const id = maybeInjectPure(resolved.desc, resolved.name, utils, // @ts-expect-error | ||
| const id = maybeInjectPure(resolved.desc, resolved.name, utils, | ||
| // @ts-expect-error | ||
| meta.object); | ||
| if (id) path.replaceWith(id); | ||
| } else if (resolved.kind === "instance") { | ||
| const id = maybeInjectPure(resolved.desc, `${resolved.name}InstanceProperty`, utils, // @ts-expect-error | ||
| const id = maybeInjectPure(resolved.desc, `${resolved.name}InstanceProperty`, utils, | ||
| // @ts-expect-error | ||
| meta.object); | ||
@@ -279,3 +235,2 @@ if (!id) return; | ||
| } = path; | ||
| if (t.isCallExpression(path.parent, { | ||
@@ -290,3 +245,2 @@ callee: node | ||
| }, | ||
| visitor: method === "usage-global" && { | ||
@@ -297,3 +251,2 @@ // import("foo") | ||
| const utils = getUtils(path); | ||
| if (isWebpack) { | ||
@@ -307,3 +260,2 @@ // Webpack uses Promise.all to handle dynamic import. | ||
| }, | ||
| // (async function () { }).finally(...) | ||
@@ -315,3 +267,2 @@ Function(path) { | ||
| }, | ||
| // for-of, [a, b] = c | ||
@@ -321,3 +272,2 @@ "ForOfStatement|ArrayPattern"(path) { | ||
| }, | ||
| // [...spread] | ||
@@ -329,3 +279,2 @@ SpreadElement(path) { | ||
| }, | ||
| // yield* | ||
@@ -337,7 +286,5 @@ YieldExpression(path) { | ||
| } | ||
| } | ||
| }; | ||
| }); | ||
| exports.default = _default; |
@@ -5,6 +5,4 @@ "use strict"; | ||
| exports.default = void 0; | ||
| // This file is automatically generated by scripts/build-corejs3-shipped-proposals.mjs | ||
| var _default = new Set(["esnext.array.from-async", "esnext.array.group", "esnext.array.group-to-map", "esnext.array-buffer.detached", "esnext.array-buffer.transfer", "esnext.array-buffer.transfer-to-fixed-length", "esnext.json.is-raw-json", "esnext.json.parse", "esnext.json.raw-json", "esnext.set.difference.v2", "esnext.set.intersection.v2", "esnext.set.is-disjoint-from.v2", "esnext.set.is-subset-of.v2", "esnext.set.is-superset-of.v2", "esnext.set.symmetric-difference.v2", "esnext.set.union.v2", "esnext.string.is-well-formed", "esnext.string.to-well-formed"]); | ||
| var _default = new Set(["esnext.array.from-async", "esnext.array.group", "esnext.array.group-to-map", "esnext.array-buffer.detached", "esnext.array-buffer.transfer", "esnext.array-buffer.transfer-to-fixed-length", "esnext.json.is-raw-json", "esnext.json.parse", "esnext.json.raw-json", "esnext.set.difference.v2", "esnext.set.intersection.v2", "esnext.set.is-disjoint-from.v2", "esnext.set.is-subset-of.v2", "esnext.set.is-superset-of.v2", "esnext.set.symmetric-difference.v2", "esnext.set.union.v2"]); | ||
| exports.default = _default; |
@@ -5,13 +5,8 @@ "use strict"; | ||
| exports.default = canSkipPolyfill; | ||
| var _babel = _interopRequireWildcard(require("@babel/core")); | ||
| function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
| function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
| const { | ||
| types: t | ||
| } = _babel.default || _babel; | ||
| function canSkipPolyfill(desc, path) { | ||
@@ -22,3 +17,2 @@ const { | ||
| } = path; | ||
| switch (desc.name) { | ||
@@ -25,0 +19,0 @@ case "es.string.split": |
+0
-13
@@ -9,13 +9,7 @@ "use strict"; | ||
| exports.isCoreJSSource = isCoreJSSource; | ||
| var _babel = _interopRequireWildcard(require("@babel/core")); | ||
| var _entries = _interopRequireDefault(require("../core-js-compat/entries.js")); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
| function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
| const { | ||
@@ -26,3 +20,2 @@ types: t | ||
| exports.BABEL_RUNTIME = BABEL_RUNTIME; | ||
| function callMethod(path, id) { | ||
@@ -33,3 +26,2 @@ const { | ||
| let context1, context2; | ||
| if (t.isIdentifier(object)) { | ||
@@ -42,7 +34,5 @@ context1 = object; | ||
| } | ||
| path.replaceWith(t.memberExpression(t.callExpression(id, [context2]), t.identifier("call"))); | ||
| path.parentPath.unshiftContainer("arguments", context1); | ||
| } | ||
| function isCoreJSSource(source) { | ||
@@ -52,12 +42,9 @@ if (typeof source === "string") { | ||
| } | ||
| return Object.prototype.hasOwnProperty.call(_entries.default, source) && _entries.default[source]; | ||
| } | ||
| function coreJSModule(name) { | ||
| return `core-js/modules/${name}.js`; | ||
| } | ||
| function coreJSPureHelper(name, useBabelRuntime, ext) { | ||
| return useBabelRuntime ? `${BABEL_RUNTIME}/core-js/${name}${ext}` : `core-js-pure/features/${name}.js`; | ||
| } |
+13
-13
| { | ||
| "name": "babel-plugin-polyfill-corejs3", | ||
| "version": "0.8.1", | ||
| "version": "0.8.2", | ||
| "description": "A Babel plugin to inject imports to core-js@3 polyfills", | ||
@@ -29,15 +29,15 @@ "repository": { | ||
| "dependencies": { | ||
| "@babel/helper-define-polyfill-provider": "^0.4.0", | ||
| "core-js-compat": "^3.30.1" | ||
| "@babel/helper-define-polyfill-provider": "^0.4.1", | ||
| "core-js-compat": "^3.31.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@babel/core": "^7.17.8", | ||
| "@babel/helper-plugin-test-runner": "^7.16.7", | ||
| "@babel/plugin-syntax-dynamic-import": "^7.8.3", | ||
| "@babel/plugin-transform-classes": "^7.16.7", | ||
| "@babel/plugin-transform-for-of": "^7.16.7", | ||
| "@babel/plugin-transform-modules-commonjs": "^7.17.7", | ||
| "@babel/plugin-transform-spread": "^7.16.7", | ||
| "core-js": "^3.30.1", | ||
| "core-js-pure": "^3.30.1" | ||
| "@babel/core": "^7.22.6", | ||
| "@babel/helper-plugin-test-runner": "^7.22.5", | ||
| "@babel/plugin-transform-class-properties": "^7.22.5", | ||
| "@babel/plugin-transform-classes": "^7.22.6", | ||
| "@babel/plugin-transform-for-of": "^7.22.5", | ||
| "@babel/plugin-transform-modules-commonjs": "^7.22.5", | ||
| "@babel/plugin-transform-spread": "^7.22.5", | ||
| "core-js": "^3.31.0", | ||
| "core-js-pure": "^3.31.0" | ||
| }, | ||
@@ -47,3 +47,3 @@ "peerDependencies": { | ||
| }, | ||
| "gitHead": "4b3c67a6a946df756123952a0033dc4426696131" | ||
| "gitHead": "74956db5d547985ac8e60bf1af56f4c61af12e4e" | ||
| } |
Sorry, the diff of this file is too big to display
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
182134
0.54%1521
1.2%