babel-plugin-polyfill-corejs3 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/index.mjs CHANGED
@@ -5,13 +5,13 @@ import corejsEntries from '../core-js-compat/entries.js';
5
5
  import defineProvider from '@babel/helper-define-polyfill-provider';
6
6
 
7
7
  // This file is automatically generated by scripts/build-corejs3-shipped-proposals.mjs
8
- 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"]);
8
+
9
+ 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"]);
9
10
 
10
11
  const polyfillsOrder = {};
11
12
  Object.keys(corejs3Polyfills).forEach((name, index) => {
12
13
  polyfillsOrder[name] = index;
13
14
  });
14
-
15
15
  const define = (pure, global, name = global[0], exclude) => {
16
16
  return {
17
17
  name,
@@ -20,9 +20,7 @@ const define = (pure, global, name = global[0], exclude) => {
20
20
  exclude
21
21
  };
22
22
  };
23
-
24
23
  const typed = name => define(null, [name, ...TypedArrayDependencies]);
25
-
26
24
  const ArrayNatureIterators = ["es.array.iterator", "web.dom-collections.iterator"];
27
25
  const CommonIterators = ["es.string.iterator", ...ArrayNatureIterators];
28
26
  const ArrayNatureIteratorsWithTag = ["es.object.to-string", ...ArrayNatureIterators];
@@ -38,7 +36,7 @@ const SetDependencies = ["es.set", "esnext.set.add-all", "esnext.set.delete-all"
38
36
  const WeakMapDependencies = ["es.weak-map", "esnext.weak-map.delete-all", "esnext.weak-map.emplace", ...CommonIteratorsWithTag];
39
37
  const WeakSetDependencies = ["es.weak-set", "esnext.weak-set.add-all", "esnext.weak-set.delete-all", ...CommonIteratorsWithTag];
40
38
  const DOMExceptionDependencies = ["web.dom-exception.constructor", "web.dom-exception.stack", "web.dom-exception.to-string-tag", "es.error.to-string"];
41
- const URLSearchParamsDependencies = ["web.url-search-params", "web.url-search-params.size", ...CommonIteratorsWithTag];
39
+ const URLSearchParamsDependencies = ["web.url-search-params", "web.url-search-params.delete", "web.url-search-params.has", "web.url-search-params.size", ...CommonIteratorsWithTag];
42
40
  const AsyncIteratorDependencies = ["esnext.async-iterator.constructor", ...PromiseDependencies];
43
41
  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"];
44
42
  const IteratorDependencies = ["esnext.iterator.constructor", "es.object.to-string"];
@@ -202,6 +200,7 @@ const StaticProperties = {
202
200
  getOwnPropertyNames: define("object/get-own-property-names", ["es.object.get-own-property-names"]),
203
201
  getOwnPropertySymbols: define("object/get-own-property-symbols", ["es.symbol"]),
204
202
  getPrototypeOf: define("object/get-prototype-of", ["es.object.get-prototype-of"]),
203
+ groupBy: define("object/group-by", ["esnext.object.group-by", "es.object.create"]),
205
204
  hasOwn: define("object/has-own", ["es.object.has-own"]),
206
205
  is: define("object/is", ["es.object.is"]),
207
206
  isExtensible: define("object/is-extensible", ["es.object.is-extensible"]),
@@ -218,7 +217,8 @@ const StaticProperties = {
218
217
  allSettled: define(null, ["es.promise.all-settled", ...PromiseDependenciesWithIterators]),
219
218
  any: define(null, ["es.promise.any", "es.aggregate-error", ...PromiseDependenciesWithIterators]),
220
219
  race: define(null, PromiseDependenciesWithIterators),
221
- try: define(null, ["esnext.promise.try", ...PromiseDependenciesWithIterators])
220
+ try: define(null, ["esnext.promise.try", ...PromiseDependencies]),
221
+ withResolvers: define(null, ["esnext.promise.with-resolvers", ...PromiseDependencies])
222
222
  },
223
223
  Reflect: {
224
224
  apply: define("reflect/apply", ["es.reflect.apply"]),
@@ -262,13 +262,15 @@ const StaticProperties = {
262
262
  hasInstance: define("symbol/has-instance", ["es.symbol.has-instance", "es.function.has-instance"]),
263
263
  isConcatSpreadable: define("symbol/is-concat-spreadable", ["es.symbol.is-concat-spreadable", "es.array.concat"]),
264
264
  isRegistered: define("symbol/is-registered", ["esnext.symbol.is-registered", "es.symbol"]),
265
+ isRegisteredSymbol: define("symbol/is-registered-symbol", ["esnext.symbol.is-registered-symbol", "es.symbol"]),
265
266
  isWellKnown: define("symbol/is-well-known", ["esnext.symbol.is-well-known", "es.symbol"]),
267
+ isWellKnownSymbol: define("symbol/is-well-known-symbol", ["esnext.symbol.is-well-known-symbol", "es.symbol"]),
266
268
  iterator: define("symbol/iterator", ["es.symbol.iterator", ...CommonIteratorsWithTag]),
267
269
  keyFor: define("symbol/key-for", [], "es.symbol"),
268
270
  match: define("symbol/match", ["es.symbol.match", "es.string.match"]),
269
271
  matcher: define("symbol/matcher", ["esnext.symbol.matcher"]),
270
272
  matchAll: define("symbol/match-all", ["es.symbol.match-all", "es.string.match-all"]),
271
- metadata: define("symbol/metadata", ["esnext.symbol.metadata"]),
273
+ metadata: define("symbol/metadata", ["esnext.symbol.metadata", "esnext.function.metadata"]),
272
274
  metadataKey: define("symbol/metadata-key", ["esnext.symbol.metadata-key"]),
273
275
  observable: define("symbol/observable", ["esnext.symbol.observable"]),
274
276
  patternMatch: define("symbol/pattern-match", ["esnext.symbol.pattern-match"]),
@@ -308,7 +310,8 @@ const StaticProperties = {
308
310
  };
309
311
  const InstanceProperties = {
310
312
  asIndexedPairs: define("instance/asIndexedPairs", ["esnext.async-iterator.as-indexed-pairs", ...AsyncIteratorDependencies, "esnext.iterator.as-indexed-pairs", ...IteratorDependencies]),
311
- at: define("instance/at", [// TODO: We should introduce overloaded instance methods definition
313
+ at: define("instance/at", [
314
+ // TODO: We should introduce overloaded instance methods definition
312
315
  // Before that is implemented, the `esnext.string.at` must be the first
313
316
  // In pure mode, the provider resolves the descriptor as a "pure" `esnext.string.at`
314
317
  // and treats the compat-data of `esnext.string.at` as the compat-data of
@@ -331,7 +334,8 @@ const InstanceProperties = {
331
334
  emplace: define("instance/emplace", ["esnext.map.emplace", "esnext.weak-map.emplace"]),
332
335
  endsWith: define("instance/ends-with", ["es.string.ends-with"]),
333
336
  entries: define("instance/entries", ArrayNatureIteratorsWithTag),
334
- every: define("instance/every", ["es.array.every", "esnext.async-iterator.every", // TODO: add async iterator dependencies when we support sub-dependencies
337
+ every: define("instance/every", ["es.array.every", "esnext.async-iterator.every",
338
+ // TODO: add async iterator dependencies when we support sub-dependencies
335
339
  // esnext.async-iterator.every depends on es.promise
336
340
  // but we don't want to pull es.promise when esnext.async-iterator is disabled
337
341
  //
@@ -361,7 +365,7 @@ const InstanceProperties = {
361
365
  includes: define("instance/includes", ["es.array.includes", "es.string.includes"]),
362
366
  indexed: define("instance/indexed", ["esnext.async-iterator.indexed", ...AsyncIteratorDependencies, "esnext.iterator.indexed", ...IteratorDependencies]),
363
367
  indexOf: define("instance/index-of", ["es.array.index-of"]),
364
- isWellFormed: define("instance/is-well-formed", ["esnext.string.is-well-formed"]),
368
+ isWellFormed: define("instance/is-well-formed", ["es.string.is-well-formed"]),
365
369
  italic: define(null, ["es.string.italics"]),
366
370
  join: define(null, ["es.array.join"]),
367
371
  keys: define("instance/keys", ArrayNatureIteratorsWithTag),
@@ -410,7 +414,7 @@ const InstanceProperties = {
410
414
  toSorted: define("instance/to-sorted", ["es.array.to-sorted", "es.array.sort"]),
411
415
  toSpliced: define("instance/to-spliced", ["es.array.to-spliced"]),
412
416
  toString: define(null, ["es.object.to-string", "es.error.to-string", "es.date.to-string", "es.regexp.to-string"]),
413
- toWellFormed: define("instance/to-well-formed", ["esnext.string.to-well-formed"]),
417
+ toWellFormed: define("instance/to-well-formed", ["es.string.to-well-formed"]),
414
418
  trim: define("instance/trim", ["es.string.trim"]),
415
419
  trimEnd: define("instance/trim-end", ["es.string.trim-end"]),
416
420
  trimLeft: define("instance/trim-left", ["es.string.trim-start"]),
@@ -436,7 +440,6 @@ function canSkipPolyfill(desc, path) {
436
440
  node,
437
441
  parent
438
442
  } = path;
439
-
440
443
  switch (desc.name) {
441
444
  case "es.string.split":
442
445
  {
@@ -459,7 +462,6 @@ function callMethod(path, id) {
459
462
  object
460
463
  } = path.node;
461
464
  let context1, context2;
462
-
463
465
  if (t$1.isIdentifier(object)) {
464
466
  context1 = object;
465
467
  context2 = t$1.cloneNode(object);
@@ -467,7 +469,6 @@ function callMethod(path, id) {
467
469
  context1 = path.scope.generateDeclaredUidIdentifier("context");
468
470
  context2 = t$1.assignmentExpression("=", t$1.cloneNode(context1), object);
469
471
  }
470
-
471
472
  path.replaceWith(t$1.memberExpression(t$1.callExpression(id, [context2]), t$1.identifier("call")));
472
473
  path.parentPath.unshiftContainer("arguments", context1);
473
474
  }
@@ -475,7 +476,6 @@ function isCoreJSSource(source) {
475
476
  if (typeof source === "string") {
476
477
  source = source.replace(/\\/g, "/").replace(/(\/(index)?)?(\.js)?$/i, "").toLowerCase();
477
478
  }
478
-
479
479
  return Object.prototype.hasOwnProperty.call(corejsEntries, source) && corejsEntries[source];
480
480
  }
481
481
  function coreJSModule(name) {
@@ -488,9 +488,9 @@ function coreJSPureHelper(name, useBabelRuntime, ext) {
488
488
  const {
489
489
  types: t
490
490
  } = _babel.default || _babel;
491
+ const presetEnvCompat = "#__secret_key__@babel/preset-env__compatibility";
491
492
  const runtimeCompat = "#__secret_key__@babel/runtime__compatibility";
492
493
  const uniqueObjects = ["array", "string", "iterator", "async-iterator", "dom-collections"].map(v => new RegExp(`[a-z]*\\.${v}\\..*`));
493
-
494
494
  const esnextFallback = (name, cb) => {
495
495
  if (cb(name)) return true;
496
496
  if (!name.startsWith("es.")) return false;
@@ -498,7 +498,6 @@ const esnextFallback = (name, cb) => {
498
498
  if (!corejs3Polyfills[fallback]) return false;
499
499
  return cb(fallback);
500
500
  };
501
-
502
501
  var index = defineProvider(function ({
503
502
  getUtils,
504
503
  method,
@@ -510,6 +509,9 @@ var index = defineProvider(function ({
510
509
  version = 3,
511
510
  proposals,
512
511
  shippedProposals,
512
+ [presetEnvCompat]: {
513
+ noRuntimeName = false
514
+ } = {},
513
515
  [runtimeCompat]: {
514
516
  useBabelRuntime = false,
515
517
  ext = ".js"
@@ -522,21 +524,17 @@ var index = defineProvider(function ({
522
524
  instance: InstanceProperties
523
525
  });
524
526
  const available = new Set(getModulesListForTargetVersion(version));
525
-
526
527
  function getCoreJSPureBase(useProposalBase) {
527
528
  return useBabelRuntime ? useProposalBase ? `${BABEL_RUNTIME}/core-js` : `${BABEL_RUNTIME}/core-js-stable` : useProposalBase ? "core-js-pure/features" : "core-js-pure/stable";
528
529
  }
529
-
530
530
  function maybeInjectGlobalImpl(name, utils) {
531
531
  if (shouldInjectPolyfill(name)) {
532
532
  debug(name);
533
533
  utils.injectGlobalImport(coreJSModule(name));
534
534
  return true;
535
535
  }
536
-
537
536
  return false;
538
537
  }
539
-
540
538
  function maybeInjectGlobal(names, utils, fallback = true) {
541
539
  for (const name of names) {
542
540
  if (fallback) {
@@ -546,93 +544,75 @@ var index = defineProvider(function ({
546
544
  }
547
545
  }
548
546
  }
549
-
550
547
  function maybeInjectPure(desc, hint, utils, object) {
551
548
  if (desc.pure && !(object && desc.exclude && desc.exclude.includes(object)) && esnextFallback(desc.name, shouldInjectPolyfill)) {
552
549
  const {
553
550
  name
554
551
  } = desc;
555
552
  let useProposalBase = false;
556
-
557
553
  if (proposals || shippedProposals && name.startsWith("esnext.")) {
558
554
  useProposalBase = true;
559
555
  } else if (name.startsWith("es.") && !available.has(name)) {
560
556
  useProposalBase = true;
561
557
  }
562
-
563
558
  const coreJSPureBase = getCoreJSPureBase(useProposalBase);
564
559
  return utils.injectDefaultImport(`${coreJSPureBase}/${desc.pure}${ext}`, hint);
565
560
  }
566
561
  }
567
-
568
562
  function isFeatureStable(name) {
569
563
  if (name.startsWith("esnext.")) {
570
- const esName = `es.${name.slice(7)}`; // If its imaginative esName is not in latest compat data, it means
564
+ const esName = `es.${name.slice(7)}`;
565
+ // If its imaginative esName is not in latest compat data, it means
571
566
  // the proposal is not stage 4
572
-
573
567
  return esName in corejs3Polyfills;
574
568
  }
575
-
576
569
  return true;
577
570
  }
578
-
579
571
  return {
580
572
  name: "corejs3",
581
- runtimeName: BABEL_RUNTIME,
573
+ runtimeName: noRuntimeName ? null : BABEL_RUNTIME,
582
574
  polyfills: corejs3Polyfills,
583
-
584
575
  filterPolyfills(name) {
585
576
  if (!available.has(name)) return false;
586
577
  if (proposals || method === "entry-global") return true;
587
-
588
578
  if (shippedProposals && corejs3ShippedProposalsList.has(name)) {
589
579
  return true;
590
580
  }
591
-
592
581
  return isFeatureStable(name);
593
582
  },
594
-
595
583
  entryGlobal(meta, utils, path) {
596
584
  if (meta.kind !== "import") return;
597
585
  const modules = isCoreJSSource(meta.source);
598
586
  if (!modules) return;
599
-
600
587
  if (modules.length === 1 && meta.source === coreJSModule(modules[0]) && shouldInjectPolyfill(modules[0])) {
601
588
  // Avoid infinite loop: do not replace imports with a new copy of
602
589
  // themselves.
603
590
  debug(null);
604
591
  return;
605
592
  }
606
-
607
593
  const modulesSet = new Set(modules);
608
594
  const filteredModules = modules.filter(module => {
609
595
  if (!module.startsWith("esnext.")) return true;
610
596
  const stable = module.replace("esnext.", "es.");
611
-
612
597
  if (modulesSet.has(stable) && shouldInjectPolyfill(stable)) {
613
598
  return false;
614
599
  }
615
-
616
600
  return true;
617
601
  });
618
602
  maybeInjectGlobal(filteredModules, utils, false);
619
603
  path.remove();
620
604
  },
621
-
622
605
  usageGlobal(meta, utils, path) {
623
606
  const resolved = resolve(meta);
624
607
  if (!resolved) return;
625
608
  if (canSkipPolyfill(resolved.desc, path)) return;
626
609
  let deps = resolved.desc.global;
627
-
628
610
  if (resolved.kind !== "global" && "object" in meta && meta.object && meta.placement === "prototype") {
629
611
  const low = meta.object.toLowerCase();
630
612
  deps = deps.filter(m => uniqueObjects.some(v => v.test(m)) ? m.includes(low) : true);
631
613
  }
632
-
633
614
  maybeInjectGlobal(deps, utils);
634
615
  },
635
-
636
616
  usagePure(meta, utils, path) {
637
617
  if (meta.kind === "in") {
638
618
  if (meta.key === "Symbol.iterator") {
@@ -642,28 +622,23 @@ var index = defineProvider(function ({
642
622
 
643
623
  return;
644
624
  }
645
-
646
625
  if (path.parentPath.isUnaryExpression({
647
626
  operator: "delete"
648
627
  })) return;
649
-
650
628
  if (meta.kind === "property") {
651
629
  // We can't compile destructuring and updateExpression.
652
630
  if (!path.isMemberExpression()) return;
653
631
  if (!path.isReferenced()) return;
654
632
  if (path.parentPath.isUpdateExpression()) return;
655
-
656
633
  if (t.isSuper(path.node.object)) {
657
634
  return;
658
635
  }
659
-
660
636
  if (meta.key === "Symbol.iterator") {
661
637
  if (!shouldInjectPolyfill("es.symbol.iterator")) return;
662
638
  const {
663
639
  parent,
664
640
  node
665
641
  } = path;
666
-
667
642
  if (t.isCallExpression(parent, {
668
643
  callee: node
669
644
  })) {
@@ -676,39 +651,38 @@ var index = defineProvider(function ({
676
651
  } else {
677
652
  path.replaceWith(t.callExpression(utils.injectDefaultImport(coreJSPureHelper("get-iterator-method", useBabelRuntime, ext), "getIteratorMethod"), [path.node.object]));
678
653
  }
679
-
680
654
  return;
681
655
  }
682
656
  }
683
-
684
657
  let resolved = resolve(meta);
685
658
  if (!resolved) return;
686
659
  if (canSkipPolyfill(resolved.desc, path)) return;
687
-
688
660
  if (useBabelRuntime && resolved.desc.pure && resolved.desc.pure.slice(-6) === "/index") {
689
661
  // Remove /index, since it doesn't exist in @babel/runtime-corejs3s
690
- resolved = { ...resolved,
691
- desc: { ...resolved.desc,
662
+ resolved = {
663
+ ...resolved,
664
+ desc: {
665
+ ...resolved.desc,
692
666
  pure: resolved.desc.pure.slice(0, -6)
693
667
  }
694
668
  };
695
669
  }
696
-
697
670
  if (resolved.kind === "global") {
698
671
  const id = maybeInjectPure(resolved.desc, resolved.name, utils);
699
672
  if (id) path.replaceWith(id);
700
673
  } else if (resolved.kind === "static") {
701
- const id = maybeInjectPure(resolved.desc, resolved.name, utils, // @ts-expect-error
674
+ const id = maybeInjectPure(resolved.desc, resolved.name, utils,
675
+ // @ts-expect-error
702
676
  meta.object);
703
677
  if (id) path.replaceWith(id);
704
678
  } else if (resolved.kind === "instance") {
705
- const id = maybeInjectPure(resolved.desc, `${resolved.name}InstanceProperty`, utils, // @ts-expect-error
679
+ const id = maybeInjectPure(resolved.desc, `${resolved.name}InstanceProperty`, utils,
680
+ // @ts-expect-error
706
681
  meta.object);
707
682
  if (!id) return;
708
683
  const {
709
684
  node
710
685
  } = path;
711
-
712
686
  if (t.isCallExpression(path.parent, {
713
687
  callee: node
714
688
  })) {
@@ -718,13 +692,11 @@ var index = defineProvider(function ({
718
692
  }
719
693
  }
720
694
  },
721
-
722
695
  visitor: method === "usage-global" && {
723
696
  // import("foo")
724
697
  CallExpression(path) {
725
698
  if (path.get("callee").isImport()) {
726
699
  const utils = getUtils(path);
727
-
728
700
  if (isWebpack) {
729
701
  // Webpack uses Promise.all to handle dynamic import.
730
702
  maybeInjectGlobal(PromiseDependenciesWithIterators, utils);
@@ -733,33 +705,28 @@ var index = defineProvider(function ({
733
705
  }
734
706
  }
735
707
  },
736
-
737
708
  // (async function () { }).finally(...)
738
709
  Function(path) {
739
710
  if (path.node.async) {
740
711
  maybeInjectGlobal(PromiseDependencies, getUtils(path));
741
712
  }
742
713
  },
743
-
744
714
  // for-of, [a, b] = c
745
715
  "ForOfStatement|ArrayPattern"(path) {
746
716
  maybeInjectGlobal(CommonIterators, getUtils(path));
747
717
  },
748
-
749
718
  // [...spread]
750
719
  SpreadElement(path) {
751
720
  if (!path.parentPath.isObjectExpression()) {
752
721
  maybeInjectGlobal(CommonIterators, getUtils(path));
753
722
  }
754
723
  },
755
-
756
724
  // yield*
757
725
  YieldExpression(path) {
758
726
  if (path.node.delegate) {
759
727
  maybeInjectGlobal(CommonIterators, getUtils(path));
760
728
  }
761
729
  }
762
-
763
730
  }
764
731
  };
765
732
  });