index.mjs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. import corejs3Polyfills from '../core-js-compat/data.js';
  2. import getModulesListForTargetVersion from '../core-js-compat/get-modules-list-for-target-version.js';
  3. import * as _babel from '@babel/core';
  4. import corejsEntries from '../core-js-compat/entries.js';
  5. import defineProvider from '@babel/helper-define-polyfill-provider';
  6. // This file is automatically generated by scripts/build-corejs3-shipped-proposals.mjs
  7. var corejs3ShippedProposalsList = new Set(["esnext.array.group", "esnext.array.group-to-map", "esnext.array.to-reversed", "esnext.array.to-sorted", "esnext.array.to-spliced", "esnext.array.with", "esnext.typed-array.to-reversed", "esnext.typed-array.to-sorted", "esnext.typed-array.with"]);
  8. const polyfillsOrder = {};
  9. Object.keys(corejs3Polyfills).forEach((name, index) => {
  10. polyfillsOrder[name] = index;
  11. });
  12. const define = (pure, global, name = global[0], exclude) => {
  13. return {
  14. name,
  15. pure,
  16. global: global.sort((a, b) => polyfillsOrder[a] - polyfillsOrder[b]),
  17. exclude
  18. };
  19. };
  20. const typed = name => define(null, [name, ...TypedArrayDependencies]);
  21. const ArrayNatureIterators = ["es.array.iterator", "web.dom-collections.iterator"];
  22. const CommonIterators = ["es.string.iterator", ...ArrayNatureIterators];
  23. const ArrayNatureIteratorsWithTag = ["es.object.to-string", ...ArrayNatureIterators];
  24. const CommonIteratorsWithTag = ["es.object.to-string", ...CommonIterators];
  25. const ErrorDependencies = ["es.error.cause", "es.error.to-string"];
  26. const TypedArrayDependencies = ["es.typed-array.at", "es.typed-array.copy-within", "es.typed-array.every", "es.typed-array.fill", "es.typed-array.filter", "es.typed-array.find", "es.typed-array.find-index", "es.typed-array.find-last", "es.typed-array.find-last-index", "es.typed-array.for-each", "es.typed-array.includes", "es.typed-array.index-of", "es.typed-array.iterator", "es.typed-array.join", "es.typed-array.last-index-of", "es.typed-array.map", "es.typed-array.reduce", "es.typed-array.reduce-right", "es.typed-array.reverse", "es.typed-array.set", "es.typed-array.slice", "es.typed-array.some", "es.typed-array.sort", "es.typed-array.subarray", "es.typed-array.to-locale-string", "es.typed-array.to-string", "es.object.to-string", "es.array.iterator", "es.array-buffer.slice", "esnext.typed-array.filter-reject", "esnext.typed-array.group-by", "esnext.typed-array.to-reversed", "esnext.typed-array.to-sorted", "esnext.typed-array.to-spliced", "esnext.typed-array.unique-by", "esnext.typed-array.with"];
  27. const PromiseDependencies = ["es.promise", "es.object.to-string"];
  28. const PromiseDependenciesWithIterators = [...PromiseDependencies, ...CommonIterators];
  29. const SymbolDependencies = ["es.symbol", "es.symbol.description", "es.object.to-string"];
  30. const MapDependencies = ["es.map", "esnext.map.delete-all", "esnext.map.emplace", "esnext.map.every", "esnext.map.filter", "esnext.map.find", "esnext.map.find-key", "esnext.map.includes", "esnext.map.key-of", "esnext.map.map-keys", "esnext.map.map-values", "esnext.map.merge", "esnext.map.reduce", "esnext.map.some", "esnext.map.update", ...CommonIteratorsWithTag];
  31. const SetDependencies = ["es.set", "esnext.set.add-all", "esnext.set.delete-all", "esnext.set.difference", "esnext.set.every", "esnext.set.filter", "esnext.set.find", "esnext.set.intersection", "esnext.set.is-disjoint-from", "esnext.set.is-subset-of", "esnext.set.is-superset-of", "esnext.set.join", "esnext.set.map", "esnext.set.reduce", "esnext.set.some", "esnext.set.symmetric-difference", "esnext.set.union", ...CommonIteratorsWithTag];
  32. const WeakMapDependencies = ["es.weak-map", "esnext.weak-map.delete-all", "esnext.weak-map.emplace", ...CommonIteratorsWithTag];
  33. const WeakSetDependencies = ["es.weak-set", "esnext.weak-set.add-all", "esnext.weak-set.delete-all", ...CommonIteratorsWithTag];
  34. const DOMExceptionDependencies = ["web.dom-exception.constructor", "web.dom-exception.stack", "web.dom-exception.to-string-tag", "es.error.to-string"];
  35. const URLSearchParamsDependencies = ["web.url-search-params", ...CommonIteratorsWithTag];
  36. const AsyncIteratorDependencies = ["esnext.async-iterator.constructor", ...PromiseDependencies];
  37. 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"];
  38. const IteratorDependencies = ["esnext.iterator.constructor", "es.object.to-string"];
  39. const TypedArrayStaticMethods = {
  40. from: define(null, ["es.typed-array.from"]),
  41. fromAsync: define(null, ["esnext.typed-array.from-async", ...PromiseDependenciesWithIterators]),
  42. of: define(null, ["es.typed-array.of"])
  43. };
  44. const BuiltIns = {
  45. AsyncIterator: define("async-iterator/index", AsyncIteratorDependencies),
  46. AggregateError: define("aggregate-error", ["es.aggregate-error", ...ErrorDependencies, ...CommonIteratorsWithTag, "es.aggregate-error.cause"]),
  47. ArrayBuffer: define(null, ["es.array-buffer.constructor", "es.array-buffer.slice", "es.object.to-string"]),
  48. DataView: define(null, ["es.data-view", "es.array-buffer.slice", "es.object.to-string"]),
  49. Date: define(null, ["es.date.to-string"]),
  50. DOMException: define("dom-exception", DOMExceptionDependencies),
  51. Error: define(null, ErrorDependencies),
  52. EvalError: define(null, ErrorDependencies),
  53. Float32Array: typed("es.typed-array.float32-array"),
  54. Float64Array: typed("es.typed-array.float64-array"),
  55. Int8Array: typed("es.typed-array.int8-array"),
  56. Int16Array: typed("es.typed-array.int16-array"),
  57. Int32Array: typed("es.typed-array.int32-array"),
  58. Iterator: define("iterator/index", IteratorDependencies),
  59. Uint8Array: typed("es.typed-array.uint8-array"),
  60. Uint8ClampedArray: typed("es.typed-array.uint8-clamped-array"),
  61. Uint16Array: typed("es.typed-array.uint16-array"),
  62. Uint32Array: typed("es.typed-array.uint32-array"),
  63. Map: define("map/index", MapDependencies),
  64. Number: define(null, ["es.number.constructor"]),
  65. Observable: define("observable/index", ["esnext.observable", "esnext.symbol.observable", "es.object.to-string", ...CommonIteratorsWithTag]),
  66. Promise: define("promise/index", PromiseDependencies),
  67. RangeError: define(null, ErrorDependencies),
  68. ReferenceError: define(null, ErrorDependencies),
  69. Reflect: define(null, ["es.reflect.to-string-tag", "es.object.to-string"]),
  70. RegExp: define(null, ["es.regexp.constructor", "es.regexp.dot-all", "es.regexp.exec", "es.regexp.sticky", "es.regexp.to-string"]),
  71. Set: define("set/index", SetDependencies),
  72. Symbol: define("symbol/index", SymbolDependencies),
  73. SyntaxError: define(null, ErrorDependencies),
  74. TypeError: define(null, ErrorDependencies),
  75. URIError: define(null, ErrorDependencies),
  76. URL: define("url/index", ["web.url", ...URLSearchParamsDependencies]),
  77. URLSearchParams: define("url-search-params/index", URLSearchParamsDependencies),
  78. WeakMap: define("weak-map/index", WeakMapDependencies),
  79. WeakSet: define("weak-set/index", WeakSetDependencies),
  80. atob: define("atob", ["web.atob", ...DOMExceptionDependencies]),
  81. btoa: define("btoa", ["web.btoa", ...DOMExceptionDependencies]),
  82. clearImmediate: define("clear-immediate", ["web.immediate"]),
  83. compositeKey: define("composite-key", ["esnext.composite-key"]),
  84. compositeSymbol: define("composite-symbol", ["esnext.composite-symbol"]),
  85. escape: define("escape", ["es.escape"]),
  86. fetch: define(null, PromiseDependencies),
  87. globalThis: define("global-this", ["es.global-this"]),
  88. parseFloat: define("parse-float", ["es.parse-float"]),
  89. parseInt: define("parse-int", ["es.parse-int"]),
  90. queueMicrotask: define("queue-microtask", ["web.queue-microtask"]),
  91. setImmediate: define("set-immediate", ["web.immediate"]),
  92. setInterval: define("set-interval", ["web.timers"]),
  93. setTimeout: define("set-timeout", ["web.timers"]),
  94. structuredClone: define("structured-clone", ["web.structured-clone", ...DOMExceptionDependencies, "es.array.iterator", "es.object.keys", "es.object.to-string", "es.map", "es.set"]),
  95. unescape: define("unescape", ["es.unescape"])
  96. };
  97. const StaticProperties = {
  98. AsyncIterator: {
  99. from: define("async-iterator/from", ["esnext.async-iterator.from", ...AsyncIteratorDependencies, ...AsyncIteratorProblemMethods, ...CommonIterators])
  100. },
  101. Array: {
  102. from: define("array/from", ["es.array.from", "es.string.iterator"]),
  103. fromAsync: define("array/from-async", ["esnext.array.from-async", ...PromiseDependenciesWithIterators]),
  104. isArray: define("array/is-array", ["es.array.is-array"]),
  105. isTemplateObject: define("array/is-template-object", ["esnext.array.is-template-object"]),
  106. of: define("array/of", ["es.array.of"])
  107. },
  108. ArrayBuffer: {
  109. isView: define(null, ["es.array-buffer.is-view"])
  110. },
  111. BigInt: {
  112. range: define("bigint/range", ["esnext.bigint.range", "es.object.to-string"])
  113. },
  114. Date: {
  115. now: define("date/now", ["es.date.now"])
  116. },
  117. Function: {
  118. isCallable: define("function/is-callable", ["esnext.function.is-callable"]),
  119. isConstructor: define("function/is-constructor", ["esnext.function.is-constructor"])
  120. },
  121. Iterator: {
  122. from: define("iterator/from", ["esnext.iterator.from", ...IteratorDependencies, ...CommonIterators])
  123. },
  124. JSON: {
  125. stringify: define("json/stringify", ["es.json.stringify"], "es.symbol")
  126. },
  127. Math: {
  128. DEG_PER_RAD: define("math/deg-per-rad", ["esnext.math.deg-per-rad"]),
  129. RAD_PER_DEG: define("math/rad-per-deg", ["esnext.math.rad-per-deg"]),
  130. acosh: define("math/acosh", ["es.math.acosh"]),
  131. asinh: define("math/asinh", ["es.math.asinh"]),
  132. atanh: define("math/atanh", ["es.math.atanh"]),
  133. cbrt: define("math/cbrt", ["es.math.cbrt"]),
  134. clamp: define("math/clamp", ["esnext.math.clamp"]),
  135. clz32: define("math/clz32", ["es.math.clz32"]),
  136. cosh: define("math/cosh", ["es.math.cosh"]),
  137. degrees: define("math/degrees", ["esnext.math.degrees"]),
  138. expm1: define("math/expm1", ["es.math.expm1"]),
  139. fround: define("math/fround", ["es.math.fround"]),
  140. fscale: define("math/fscale", ["esnext.math.fscale"]),
  141. hypot: define("math/hypot", ["es.math.hypot"]),
  142. iaddh: define("math/iaddh", ["esnext.math.iaddh"]),
  143. imul: define("math/imul", ["es.math.imul"]),
  144. imulh: define("math/imulh", ["esnext.math.imulh"]),
  145. isubh: define("math/isubh", ["esnext.math.isubh"]),
  146. log10: define("math/log10", ["es.math.log10"]),
  147. log1p: define("math/log1p", ["es.math.log1p"]),
  148. log2: define("math/log2", ["es.math.log2"]),
  149. radians: define("math/radians", ["esnext.math.radians"]),
  150. scale: define("math/scale", ["esnext.math.scale"]),
  151. seededPRNG: define("math/seeded-prng", ["esnext.math.seeded-prng"]),
  152. sign: define("math/sign", ["es.math.sign"]),
  153. signbit: define("math/signbit", ["esnext.math.signbit"]),
  154. sinh: define("math/sinh", ["es.math.sinh"]),
  155. tanh: define("math/tanh", ["es.math.tanh"]),
  156. trunc: define("math/trunc", ["es.math.trunc"]),
  157. umulh: define("math/umulh", ["esnext.math.umulh"])
  158. },
  159. Map: {
  160. from: define(null, ["esnext.map.from", ...MapDependencies]),
  161. groupBy: define(null, ["esnext.map.group-by", ...MapDependencies]),
  162. keyBy: define(null, ["esnext.map.key-by", ...MapDependencies]),
  163. of: define(null, ["esnext.map.of", ...MapDependencies])
  164. },
  165. Number: {
  166. EPSILON: define("number/epsilon", ["es.number.epsilon"]),
  167. MAX_SAFE_INTEGER: define("number/max-safe-integer", ["es.number.max-safe-integer"]),
  168. MIN_SAFE_INTEGER: define("number/min-safe-integer", ["es.number.min-safe-integer"]),
  169. fromString: define("number/from-string", ["esnext.number.from-string"]),
  170. isFinite: define("number/is-finite", ["es.number.is-finite"]),
  171. isInteger: define("number/is-integer", ["es.number.is-integer"]),
  172. isNaN: define("number/is-nan", ["es.number.is-nan"]),
  173. isSafeInteger: define("number/is-safe-integer", ["es.number.is-safe-integer"]),
  174. parseFloat: define("number/parse-float", ["es.number.parse-float"]),
  175. parseInt: define("number/parse-int", ["es.number.parse-int"]),
  176. range: define("number/range", ["esnext.number.range", "es.object.to-string"])
  177. },
  178. Object: {
  179. assign: define("object/assign", ["es.object.assign"]),
  180. create: define("object/create", ["es.object.create"]),
  181. defineProperties: define("object/define-properties", ["es.object.define-properties"]),
  182. defineProperty: define("object/define-property", ["es.object.define-property"]),
  183. entries: define("object/entries", ["es.object.entries"]),
  184. freeze: define("object/freeze", ["es.object.freeze"]),
  185. fromEntries: define("object/from-entries", ["es.object.from-entries", "es.array.iterator"]),
  186. getOwnPropertyDescriptor: define("object/get-own-property-descriptor", ["es.object.get-own-property-descriptor"]),
  187. getOwnPropertyDescriptors: define("object/get-own-property-descriptors", ["es.object.get-own-property-descriptors"]),
  188. getOwnPropertyNames: define("object/get-own-property-names", ["es.object.get-own-property-names"]),
  189. getOwnPropertySymbols: define("object/get-own-property-symbols", ["es.symbol"]),
  190. getPrototypeOf: define("object/get-prototype-of", ["es.object.get-prototype-of"]),
  191. hasOwn: define("object/has-own", ["es.object.has-own"]),
  192. is: define("object/is", ["es.object.is"]),
  193. isExtensible: define("object/is-extensible", ["es.object.is-extensible"]),
  194. isFrozen: define("object/is-frozen", ["es.object.is-frozen"]),
  195. isSealed: define("object/is-sealed", ["es.object.is-sealed"]),
  196. keys: define("object/keys", ["es.object.keys"]),
  197. preventExtensions: define("object/prevent-extensions", ["es.object.prevent-extensions"]),
  198. seal: define("object/seal", ["es.object.seal"]),
  199. setPrototypeOf: define("object/set-prototype-of", ["es.object.set-prototype-of"]),
  200. values: define("object/values", ["es.object.values"])
  201. },
  202. Promise: {
  203. all: define(null, PromiseDependenciesWithIterators),
  204. allSettled: define(null, ["es.promise.all-settled", ...PromiseDependenciesWithIterators]),
  205. any: define(null, ["es.promise.any", "es.aggregate-error", ...PromiseDependenciesWithIterators]),
  206. race: define(null, PromiseDependenciesWithIterators),
  207. try: define(null, ["esnext.promise.try", ...PromiseDependenciesWithIterators])
  208. },
  209. Reflect: {
  210. apply: define("reflect/apply", ["es.reflect.apply"]),
  211. construct: define("reflect/construct", ["es.reflect.construct"]),
  212. defineMetadata: define("reflect/define-metadata", ["esnext.reflect.define-metadata"]),
  213. defineProperty: define("reflect/define-property", ["es.reflect.define-property"]),
  214. deleteMetadata: define("reflect/delete-metadata", ["esnext.reflect.delete-metadata"]),
  215. deleteProperty: define("reflect/delete-property", ["es.reflect.delete-property"]),
  216. get: define("reflect/get", ["es.reflect.get"]),
  217. getMetadata: define("reflect/get-metadata", ["esnext.reflect.get-metadata"]),
  218. getMetadataKeys: define("reflect/get-metadata-keys", ["esnext.reflect.get-metadata-keys"]),
  219. getOwnMetadata: define("reflect/get-own-metadata", ["esnext.reflect.get-own-metadata"]),
  220. getOwnMetadataKeys: define("reflect/get-own-metadata-keys", ["esnext.reflect.get-own-metadata-keys"]),
  221. getOwnPropertyDescriptor: define("reflect/get-own-property-descriptor", ["es.reflect.get-own-property-descriptor"]),
  222. getPrototypeOf: define("reflect/get-prototype-of", ["es.reflect.get-prototype-of"]),
  223. has: define("reflect/has", ["es.reflect.has"]),
  224. hasMetadata: define("reflect/has-metadata", ["esnext.reflect.has-metadata"]),
  225. hasOwnMetadata: define("reflect/has-own-metadata", ["esnext.reflect.has-own-metadata"]),
  226. isExtensible: define("reflect/is-extensible", ["es.reflect.is-extensible"]),
  227. metadata: define("reflect/metadata", ["esnext.reflect.metadata"]),
  228. ownKeys: define("reflect/own-keys", ["es.reflect.own-keys"]),
  229. preventExtensions: define("reflect/prevent-extensions", ["es.reflect.prevent-extensions"]),
  230. set: define("reflect/set", ["es.reflect.set"]),
  231. setPrototypeOf: define("reflect/set-prototype-of", ["es.reflect.set-prototype-of"])
  232. },
  233. Set: {
  234. from: define(null, ["esnext.set.from", ...SetDependencies]),
  235. of: define(null, ["esnext.set.of", ...SetDependencies])
  236. },
  237. String: {
  238. cooked: define("string/cooked", ["esnext.string.cooked"]),
  239. fromCodePoint: define("string/from-code-point", ["es.string.from-code-point"]),
  240. raw: define("string/raw", ["es.string.raw"])
  241. },
  242. Symbol: {
  243. asyncDispose: define("symbol/async-dispose", ["esnext.symbol.async-dispose"]),
  244. asyncIterator: define("symbol/async-iterator", ["es.symbol.async-iterator"]),
  245. dispose: define("symbol/dispose", ["esnext.symbol.dispose"]),
  246. for: define("symbol/for", [], "es.symbol"),
  247. hasInstance: define("symbol/has-instance", ["es.symbol.has-instance", "es.function.has-instance"]),
  248. isConcatSpreadable: define("symbol/is-concat-spreadable", ["es.symbol.is-concat-spreadable", "es.array.concat"]),
  249. iterator: define("symbol/iterator", ["es.symbol.iterator", ...CommonIteratorsWithTag]),
  250. keyFor: define("symbol/key-for", [], "es.symbol"),
  251. match: define("symbol/match", ["es.symbol.match", "es.string.match"]),
  252. matcher: define("symbol/matcher", ["esnext.symbol.matcher"]),
  253. matchAll: define("symbol/match-all", ["es.symbol.match-all", "es.string.match-all"]),
  254. metadata: define("symbol/metadata", ["esnext.symbol.metadata"]),
  255. metadataKey: define("symbol/metadata-key", ["esnext.symbol.metadata-key"]),
  256. observable: define("symbol/observable", ["esnext.symbol.observable"]),
  257. patternMatch: define("symbol/pattern-match", ["esnext.symbol.pattern-match"]),
  258. replace: define("symbol/replace", ["es.symbol.replace", "es.string.replace"]),
  259. search: define("symbol/search", ["es.symbol.search", "es.string.search"]),
  260. species: define("symbol/species", ["es.symbol.species", "es.array.species"]),
  261. split: define("symbol/split", ["es.symbol.split", "es.string.split"]),
  262. toPrimitive: define("symbol/to-primitive", ["es.symbol.to-primitive", "es.date.to-primitive"]),
  263. toStringTag: define("symbol/to-string-tag", ["es.symbol.to-string-tag", "es.object.to-string", "es.math.to-string-tag", "es.json.to-string-tag"]),
  264. unscopables: define("symbol/unscopables", ["es.symbol.unscopables"])
  265. },
  266. WeakMap: {
  267. from: define(null, ["esnext.weak-map.from", ...WeakMapDependencies]),
  268. of: define(null, ["esnext.weak-map.of", ...WeakMapDependencies])
  269. },
  270. WeakSet: {
  271. from: define(null, ["esnext.weak-set.from", ...WeakSetDependencies]),
  272. of: define(null, ["esnext.weak-set.of", ...WeakSetDependencies])
  273. },
  274. Int8Array: TypedArrayStaticMethods,
  275. Uint8Array: TypedArrayStaticMethods,
  276. Uint8ClampedArray: TypedArrayStaticMethods,
  277. Int16Array: TypedArrayStaticMethods,
  278. Uint16Array: TypedArrayStaticMethods,
  279. Int32Array: TypedArrayStaticMethods,
  280. Uint32Array: TypedArrayStaticMethods,
  281. Float32Array: TypedArrayStaticMethods,
  282. Float64Array: TypedArrayStaticMethods,
  283. WebAssembly: {
  284. CompileError: define(null, ErrorDependencies),
  285. LinkError: define(null, ErrorDependencies),
  286. RuntimeError: define(null, ErrorDependencies)
  287. }
  288. };
  289. const InstanceProperties = {
  290. asIndexedPairs: define("instance/asIndexedPairs", ["esnext.async-iterator.as-indexed-pairs", ...AsyncIteratorDependencies, "esnext.iterator.as-indexed-pairs", ...IteratorDependencies]),
  291. at: define("instance/at", [// TODO: We should introduce overloaded instance methods definition
  292. // Before that is implemented, the `esnext.string.at` must be the first
  293. // In pure mode, the provider resolves the descriptor as a "pure" `esnext.string.at`
  294. // and treats the compat-data of `esnext.string.at` as the compat-data of
  295. // pure import `instance/at`. The first polyfill here should have the lowest corejs
  296. // supported versions.
  297. "esnext.string.at", "es.string.at-alternative", "es.array.at"]),
  298. anchor: define(null, ["es.string.anchor"]),
  299. big: define(null, ["es.string.big"]),
  300. bind: define("instance/bind", ["es.function.bind"]),
  301. blink: define(null, ["es.string.blink"]),
  302. bold: define(null, ["es.string.bold"]),
  303. codePointAt: define("instance/code-point-at", ["es.string.code-point-at"]),
  304. codePoints: define("instance/code-points", ["esnext.string.code-points"]),
  305. concat: define("instance/concat", ["es.array.concat"], undefined, ["String"]),
  306. copyWithin: define("instance/copy-within", ["es.array.copy-within"]),
  307. description: define(null, ["es.symbol", "es.symbol.description"]),
  308. dotAll: define("instance/dot-all", ["es.regexp.dot-all"]),
  309. drop: define("instance/drop", ["esnext.async-iterator.drop", ...AsyncIteratorDependencies, "esnext.iterator.drop", ...IteratorDependencies]),
  310. emplace: define("instance/emplace", ["esnext.map.emplace", "esnext.weak-map.emplace"]),
  311. endsWith: define("instance/ends-with", ["es.string.ends-with"]),
  312. entries: define("instance/entries", ArrayNatureIteratorsWithTag),
  313. every: define("instance/every", ["es.array.every", "esnext.async-iterator.every", // TODO: add async iterator dependencies when we support sub-dependencies
  314. // esnext.async-iterator.every depends on es.promise
  315. // but we don't want to pull es.promise when esnext.async-iterator is disabled
  316. //
  317. // ...AsyncIteratorDependencies
  318. "esnext.iterator.every", ...IteratorDependencies]),
  319. exec: define(null, ["es.regexp.exec"]),
  320. fill: define("instance/fill", ["es.array.fill"]),
  321. filter: define("instance/filter", ["es.array.filter", "esnext.async-iterator.filter", "esnext.iterator.filter", ...IteratorDependencies]),
  322. filterReject: define("instance/filterReject", ["esnext.array.filter-reject"]),
  323. finally: define(null, ["es.promise.finally", ...PromiseDependencies]),
  324. find: define("instance/find", ["es.array.find", "esnext.async-iterator.find", "esnext.iterator.find", ...IteratorDependencies]),
  325. findIndex: define("instance/find-index", ["es.array.find-index"]),
  326. findLast: define("instance/find-last", ["es.array.find-last"]),
  327. findLastIndex: define("instance/find-last-index", ["es.array.find-last-index"]),
  328. fixed: define(null, ["es.string.fixed"]),
  329. flags: define("instance/flags", ["es.regexp.flags"]),
  330. flatMap: define("instance/flat-map", ["es.array.flat-map", "es.array.unscopables.flat-map", "esnext.async-iterator.flat-map", "esnext.iterator.flat-map", ...IteratorDependencies]),
  331. flat: define("instance/flat", ["es.array.flat", "es.array.unscopables.flat"]),
  332. getYear: define(null, ["es.date.get-year"]),
  333. group: define("instance/group", ["esnext.array.group"]),
  334. groupBy: define("instance/group-by", ["esnext.array.group-by"]),
  335. groupByToMap: define("instance/group-by-to-map", ["esnext.array.group-by-to-map", "es.map", "es.object.to-string"]),
  336. groupToMap: define("instance/group-to-map", ["esnext.array.group-to-map", "es.map", "es.object.to-string"]),
  337. fontcolor: define(null, ["es.string.fontcolor"]),
  338. fontsize: define(null, ["es.string.fontsize"]),
  339. forEach: define("instance/for-each", ["es.array.for-each", "esnext.async-iterator.for-each", "esnext.iterator.for-each", ...IteratorDependencies, "web.dom-collections.for-each"]),
  340. includes: define("instance/includes", ["es.array.includes", "es.string.includes"]),
  341. indexed: define("instance/indexed", ["esnext.async-iterator.indexed", ...AsyncIteratorDependencies, "esnext.iterator.indexed", ...IteratorDependencies]),
  342. indexOf: define("instance/index-of", ["es.array.index-of"]),
  343. italic: define(null, ["es.string.italics"]),
  344. join: define(null, ["es.array.join"]),
  345. keys: define("instance/keys", ArrayNatureIteratorsWithTag),
  346. lastIndex: define(null, ["esnext.array.last-index"]),
  347. lastIndexOf: define("instance/last-index-of", ["es.array.last-index-of"]),
  348. lastItem: define(null, ["esnext.array.last-item"]),
  349. link: define(null, ["es.string.link"]),
  350. map: define("instance/map", ["es.array.map", "esnext.async-iterator.map", "esnext.iterator.map"]),
  351. match: define(null, ["es.string.match", "es.regexp.exec"]),
  352. matchAll: define("instance/match-all", ["es.string.match-all", "es.regexp.exec"]),
  353. name: define(null, ["es.function.name"]),
  354. padEnd: define("instance/pad-end", ["es.string.pad-end"]),
  355. padStart: define("instance/pad-start", ["es.string.pad-start"]),
  356. push: define("instance/push", ["es.array.push"]),
  357. reduce: define("instance/reduce", ["es.array.reduce", "esnext.async-iterator.reduce", "esnext.iterator.reduce", ...IteratorDependencies]),
  358. reduceRight: define("instance/reduce-right", ["es.array.reduce-right"]),
  359. repeat: define("instance/repeat", ["es.string.repeat"]),
  360. replace: define(null, ["es.string.replace", "es.regexp.exec"]),
  361. replaceAll: define("instance/replace-all", ["es.string.replace-all", "es.string.replace", "es.regexp.exec"]),
  362. reverse: define("instance/reverse", ["es.array.reverse"]),
  363. search: define(null, ["es.string.search", "es.regexp.exec"]),
  364. setYear: define(null, ["es.date.set-year"]),
  365. slice: define("instance/slice", ["es.array.slice"]),
  366. small: define(null, ["es.string.small"]),
  367. some: define("instance/some", ["es.array.some", "esnext.async-iterator.some", "esnext.iterator.some", ...IteratorDependencies]),
  368. sort: define("instance/sort", ["es.array.sort"]),
  369. splice: define("instance/splice", ["es.array.splice"]),
  370. split: define(null, ["es.string.split", "es.regexp.exec"]),
  371. startsWith: define("instance/starts-with", ["es.string.starts-with"]),
  372. sticky: define("instance/sticky", ["es.regexp.sticky"]),
  373. strike: define(null, ["es.string.strike"]),
  374. sub: define(null, ["es.string.sub"]),
  375. substr: define(null, ["es.string.substr"]),
  376. sup: define(null, ["es.string.sup"]),
  377. take: define("instance/take", ["esnext.async-iterator.take", ...AsyncIteratorDependencies, "esnext.iterator.take", ...IteratorDependencies]),
  378. test: define(null, ["es.regexp.test", "es.regexp.exec"]),
  379. toArray: define("instance/to-array", ["esnext.async-iterator.to-array", ...AsyncIteratorDependencies, "esnext.iterator.to-array", ...IteratorDependencies]),
  380. toAsync: define(null, ["esnext.iterator.to-async", ...IteratorDependencies, ...AsyncIteratorDependencies, ...AsyncIteratorProblemMethods]),
  381. toExponential: define(null, ["es.number.to-exponential"]),
  382. toFixed: define(null, ["es.number.to-fixed"]),
  383. toGMTString: define(null, ["es.date.to-gmt-string"]),
  384. toISOString: define(null, ["es.date.to-iso-string"]),
  385. toJSON: define(null, ["es.date.to-json", "web.url.to-json"]),
  386. toPrecision: define(null, ["es.number.to-precision"]),
  387. toReversed: define("instance/to-reversed", ["esnext.array.to-reversed"]),
  388. toSorted: define("instance/to-sorted", ["esnext.array.to-sorted", "es.array.sort"]),
  389. toSpliced: define("instance/to-spliced", ["esnext.array.to-spliced"]),
  390. toString: define(null, ["es.object.to-string", "es.error.to-string", "es.date.to-string", "es.regexp.to-string"]),
  391. trim: define("instance/trim", ["es.string.trim"]),
  392. trimEnd: define("instance/trim-end", ["es.string.trim-end"]),
  393. trimLeft: define("instance/trim-left", ["es.string.trim-start"]),
  394. trimRight: define("instance/trim-right", ["es.string.trim-end"]),
  395. trimStart: define("instance/trim-start", ["es.string.trim-start"]),
  396. uniqueBy: define("instance/unique-by", ["esnext.array.unique-by", "es.map"]),
  397. unshift: define("instance/unshift", ["es.array.unshift"]),
  398. unThis: define("instance/un-this", ["esnext.function.un-this"]),
  399. values: define("instance/values", ArrayNatureIteratorsWithTag),
  400. with: define("instance/with", ["esnext.array.with"]),
  401. __defineGetter__: define(null, ["es.object.define-getter"]),
  402. __defineSetter__: define(null, ["es.object.define-setter"]),
  403. __lookupGetter__: define(null, ["es.object.lookup-getter"]),
  404. __lookupSetter__: define(null, ["es.object.lookup-setter"]),
  405. ["__proto__"]: define(null, ["es.object.proto"])
  406. };
  407. const CommonInstanceDependencies = new Set(["es.object.to-string", "es.object.define-getter", "es.object.define-setter", "es.object.lookup-getter", "es.object.lookup-setter", "es.regexp.exec"]);
  408. const {
  409. types: t$2
  410. } = _babel.default || _babel;
  411. function canSkipPolyfill(desc, path) {
  412. const {
  413. node,
  414. parent
  415. } = path;
  416. switch (desc.name) {
  417. case "es.string.split":
  418. {
  419. if (!t$2.isCallExpression(parent, {
  420. callee: node
  421. })) return false;
  422. if (parent.arguments.length < 1) return true;
  423. const splitter = parent.arguments[0];
  424. return t$2.isStringLiteral(splitter) || t$2.isTemplateLiteral(splitter);
  425. }
  426. }
  427. }
  428. const {
  429. types: t$1
  430. } = _babel.default || _babel;
  431. function callMethod(path, id) {
  432. const {
  433. object
  434. } = path.node;
  435. let context1, context2;
  436. if (t$1.isIdentifier(object)) {
  437. context1 = object;
  438. context2 = t$1.cloneNode(object);
  439. } else {
  440. context1 = path.scope.generateDeclaredUidIdentifier("context");
  441. context2 = t$1.assignmentExpression("=", t$1.cloneNode(context1), object);
  442. }
  443. path.replaceWith(t$1.memberExpression(t$1.callExpression(id, [context2]), t$1.identifier("call")));
  444. path.parentPath.unshiftContainer("arguments", context1);
  445. }
  446. function isCoreJSSource(source) {
  447. if (typeof source === "string") {
  448. source = source.replace(/\\/g, "/").replace(/(\/(index)?)?(\.js)?$/i, "").toLowerCase();
  449. }
  450. return Object.prototype.hasOwnProperty.call(corejsEntries, source) && corejsEntries[source];
  451. }
  452. function coreJSModule(name) {
  453. return `core-js/modules/${name}.js`;
  454. }
  455. function coreJSPureHelper(name, useBabelRuntime, ext) {
  456. return useBabelRuntime ? `${useBabelRuntime}/core-js/${name}${ext}` : `core-js-pure/features/${name}.js`;
  457. }
  458. const {
  459. types: t
  460. } = _babel.default || _babel;
  461. const runtimeCompat = "#__secret_key__@babel/runtime__compatibility";
  462. const esnextFallback = (name, cb) => {
  463. if (cb(name)) return true;
  464. if (!name.startsWith("es.")) return false;
  465. const fallback = `esnext.${name.slice(3)}`;
  466. if (!corejs3Polyfills[fallback]) return false;
  467. return cb(fallback);
  468. };
  469. var index = defineProvider(function ({
  470. getUtils,
  471. method,
  472. shouldInjectPolyfill,
  473. createMetaResolver,
  474. debug,
  475. babel
  476. }, {
  477. version = 3,
  478. proposals,
  479. shippedProposals,
  480. [runtimeCompat]: {
  481. useBabelRuntime,
  482. ext = ".js"
  483. } = {
  484. useBabelRuntime: ""
  485. }
  486. }) {
  487. const isWebpack = babel.caller(caller => (caller == null ? void 0 : caller.name) === "babel-loader");
  488. const resolve = createMetaResolver({
  489. global: BuiltIns,
  490. static: StaticProperties,
  491. instance: InstanceProperties
  492. });
  493. const available = new Set(getModulesListForTargetVersion(version));
  494. function getCoreJSPureBase(useProposalBase) {
  495. return useBabelRuntime ? useProposalBase ? `${useBabelRuntime}/core-js` : `${useBabelRuntime}/core-js-stable` : useProposalBase ? "core-js-pure/features" : "core-js-pure/stable";
  496. }
  497. function maybeInjectGlobalImpl(name, utils) {
  498. if (shouldInjectPolyfill(name)) {
  499. debug(name);
  500. utils.injectGlobalImport(coreJSModule(name));
  501. return true;
  502. }
  503. return false;
  504. }
  505. function maybeInjectGlobal(names, utils, fallback = true) {
  506. for (const name of names) {
  507. if (fallback) {
  508. esnextFallback(name, name => maybeInjectGlobalImpl(name, utils));
  509. } else {
  510. maybeInjectGlobalImpl(name, utils);
  511. }
  512. }
  513. }
  514. function maybeInjectPure(desc, hint, utils, object) {
  515. if (desc.pure && !(object && desc.exclude && desc.exclude.includes(object)) && esnextFallback(desc.name, shouldInjectPolyfill)) {
  516. const {
  517. name
  518. } = desc;
  519. let useProposalBase = false;
  520. if (proposals || shippedProposals && name.startsWith("esnext.")) {
  521. useProposalBase = true;
  522. } else if (name.startsWith("es.") && !available.has(name)) {
  523. useProposalBase = true;
  524. }
  525. const coreJSPureBase = getCoreJSPureBase(useProposalBase);
  526. return utils.injectDefaultImport(`${coreJSPureBase}/${desc.pure}${ext}`, hint);
  527. }
  528. }
  529. function isFeatureStable(name) {
  530. if (name.startsWith("esnext.")) {
  531. const esName = `es.${name.slice(7)}`; // If its imaginative esName is not in latest compat data, it means
  532. // the proposal is not stage 4
  533. return esName in corejs3Polyfills;
  534. }
  535. return true;
  536. }
  537. return {
  538. name: "corejs3",
  539. polyfills: corejs3Polyfills,
  540. filterPolyfills(name) {
  541. if (!available.has(name)) return false;
  542. if (proposals || method === "entry-global") return true;
  543. if (shippedProposals && corejs3ShippedProposalsList.has(name)) {
  544. return true;
  545. }
  546. return isFeatureStable(name);
  547. },
  548. entryGlobal(meta, utils, path) {
  549. if (meta.kind !== "import") return;
  550. const modules = isCoreJSSource(meta.source);
  551. if (!modules) return;
  552. if (modules.length === 1 && meta.source === coreJSModule(modules[0]) && shouldInjectPolyfill(modules[0])) {
  553. // Avoid infinite loop: do not replace imports with a new copy of
  554. // themselves.
  555. debug(null);
  556. return;
  557. }
  558. const modulesSet = new Set(modules);
  559. const filteredModules = modules.filter(module => {
  560. if (!module.startsWith("esnext.")) return true;
  561. const stable = module.replace("esnext.", "es.");
  562. if (modulesSet.has(stable) && shouldInjectPolyfill(stable)) {
  563. return false;
  564. }
  565. return true;
  566. });
  567. maybeInjectGlobal(filteredModules, utils, false);
  568. path.remove();
  569. },
  570. usageGlobal(meta, utils, path) {
  571. const resolved = resolve(meta);
  572. if (!resolved) return;
  573. if (canSkipPolyfill(resolved.desc, path)) return;
  574. let deps = resolved.desc.global;
  575. if (resolved.kind !== "global" && "object" in meta && meta.object && meta.placement === "prototype") {
  576. const low = meta.object.toLowerCase();
  577. deps = deps.filter(m => m.includes(low) || CommonInstanceDependencies.has(m));
  578. }
  579. maybeInjectGlobal(deps, utils);
  580. },
  581. usagePure(meta, utils, path) {
  582. if (meta.kind === "in") {
  583. if (meta.key === "Symbol.iterator") {
  584. path.replaceWith(t.callExpression(utils.injectDefaultImport(coreJSPureHelper("is-iterable", useBabelRuntime, ext), "isIterable"), [path.node.right] // meta.kind === "in" narrows this
  585. ));
  586. }
  587. return;
  588. }
  589. if (path.parentPath.isUnaryExpression({
  590. operator: "delete"
  591. })) return;
  592. if (meta.kind === "property") {
  593. // We can't compile destructuring and updateExpression.
  594. if (!path.isMemberExpression()) return;
  595. if (!path.isReferenced()) return;
  596. if (path.parentPath.isUpdateExpression()) return;
  597. if (t.isSuper(path.node.object)) {
  598. return;
  599. }
  600. if (meta.key === "Symbol.iterator") {
  601. if (!shouldInjectPolyfill("es.symbol.iterator")) return;
  602. const {
  603. parent,
  604. node
  605. } = path;
  606. if (t.isCallExpression(parent, {
  607. callee: node
  608. })) {
  609. if (parent.arguments.length === 0) {
  610. path.parentPath.replaceWith(t.callExpression(utils.injectDefaultImport(coreJSPureHelper("get-iterator", useBabelRuntime, ext), "getIterator"), [node.object]));
  611. path.skip();
  612. } else {
  613. callMethod(path, utils.injectDefaultImport(coreJSPureHelper("get-iterator-method", useBabelRuntime, ext), "getIteratorMethod"));
  614. }
  615. } else {
  616. path.replaceWith(t.callExpression(utils.injectDefaultImport(coreJSPureHelper("get-iterator-method", useBabelRuntime, ext), "getIteratorMethod"), [path.node.object]));
  617. }
  618. return;
  619. }
  620. }
  621. let resolved = resolve(meta);
  622. if (!resolved) return;
  623. if (canSkipPolyfill(resolved.desc, path)) return;
  624. if (useBabelRuntime && resolved.desc.pure && resolved.desc.pure.slice(-6) === "/index") {
  625. // Remove /index, since it doesn't exist in @babel/runtime-corejs3s
  626. resolved = { ...resolved,
  627. desc: { ...resolved.desc,
  628. pure: resolved.desc.pure.slice(0, -6)
  629. }
  630. };
  631. }
  632. if (resolved.kind === "global") {
  633. const id = maybeInjectPure(resolved.desc, resolved.name, utils);
  634. if (id) path.replaceWith(id);
  635. } else if (resolved.kind === "static") {
  636. const id = maybeInjectPure(resolved.desc, resolved.name, utils, // @ts-expect-error
  637. meta.object);
  638. if (id) path.replaceWith(id);
  639. } else if (resolved.kind === "instance") {
  640. const id = maybeInjectPure(resolved.desc, `${resolved.name}InstanceProperty`, utils, // @ts-expect-error
  641. meta.object);
  642. if (!id) return;
  643. const {
  644. node
  645. } = path;
  646. if (t.isCallExpression(path.parent, {
  647. callee: node
  648. })) {
  649. callMethod(path, id);
  650. } else {
  651. path.replaceWith(t.callExpression(id, [node.object]));
  652. }
  653. }
  654. },
  655. visitor: method === "usage-global" && {
  656. // import("foo")
  657. CallExpression(path) {
  658. if (path.get("callee").isImport()) {
  659. const utils = getUtils(path);
  660. if (isWebpack) {
  661. // Webpack uses Promise.all to handle dynamic import.
  662. maybeInjectGlobal(PromiseDependenciesWithIterators, utils);
  663. } else {
  664. maybeInjectGlobal(PromiseDependencies, utils);
  665. }
  666. }
  667. },
  668. // (async function () { }).finally(...)
  669. Function(path) {
  670. if (path.node.async) {
  671. maybeInjectGlobal(PromiseDependencies, getUtils(path));
  672. }
  673. },
  674. // for-of, [a, b] = c
  675. "ForOfStatement|ArrayPattern"(path) {
  676. maybeInjectGlobal(CommonIterators, getUtils(path));
  677. },
  678. // [...spread]
  679. SpreadElement(path) {
  680. if (!path.parentPath.isObjectExpression()) {
  681. maybeInjectGlobal(CommonIterators, getUtils(path));
  682. }
  683. },
  684. // yield*
  685. YieldExpression(path) {
  686. if (path.node.delegate) {
  687. maybeInjectGlobal(CommonIterators, getUtils(path));
  688. }
  689. }
  690. }
  691. };
  692. });
  693. export default index;
  694. //# sourceMappingURL=index.mjs.map