index.mjs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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.js
  7. var corejs3ShippedProposalsList = new Set(["esnext.array.find-last", "esnext.array.find-last-index", "esnext.typed-array.find-last", "esnext.typed-array.find-last-index"]);
  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.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.find-last", "esnext.typed-array.find-last-index", "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. observable: define("symbol/observable", ["esnext.symbol.observable"]),
  256. patternMatch: define("symbol/pattern-match", ["esnext.symbol.pattern-match"]),
  257. replace: define("symbol/replace", ["es.symbol.replace", "es.string.replace"]),
  258. search: define("symbol/search", ["es.symbol.search", "es.string.search"]),
  259. species: define("symbol/species", ["es.symbol.species", "es.array.species"]),
  260. split: define("symbol/split", ["es.symbol.split", "es.string.split"]),
  261. toPrimitive: define("symbol/to-primitive", ["es.symbol.to-primitive", "es.date.to-primitive"]),
  262. 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"]),
  263. unscopables: define("symbol/unscopables", ["es.symbol.unscopables"])
  264. },
  265. WeakMap: {
  266. from: define(null, ["esnext.weak-map.from", ...WeakMapDependencies]),
  267. of: define(null, ["esnext.weak-map.of", ...WeakMapDependencies])
  268. },
  269. WeakSet: {
  270. from: define(null, ["esnext.weak-set.from", ...WeakSetDependencies]),
  271. of: define(null, ["esnext.weak-set.of", ...WeakSetDependencies])
  272. },
  273. Int8Array: TypedArrayStaticMethods,
  274. Uint8Array: TypedArrayStaticMethods,
  275. Uint8ClampedArray: TypedArrayStaticMethods,
  276. Int16Array: TypedArrayStaticMethods,
  277. Uint16Array: TypedArrayStaticMethods,
  278. Int32Array: TypedArrayStaticMethods,
  279. Uint32Array: TypedArrayStaticMethods,
  280. Float32Array: TypedArrayStaticMethods,
  281. Float64Array: TypedArrayStaticMethods,
  282. WebAssembly: {
  283. CompileError: define(null, ErrorDependencies),
  284. LinkError: define(null, ErrorDependencies),
  285. RuntimeError: define(null, ErrorDependencies)
  286. }
  287. };
  288. const InstanceProperties = {
  289. asIndexedPairs: define("instance/asIndexedPairs", ["esnext.async-iterator.as-indexed-pairs", ...AsyncIteratorDependencies, "esnext.iterator.as-indexed-pairs", ...IteratorDependencies]),
  290. at: define("instance/at", [// TODO: We should introduce overloaded instance methods definition
  291. // Before that is implemented, the `esnext.string.at` must be the first
  292. // In pure mode, the provider resolves the descriptor as a "pure" `esnext.string.at`
  293. // and treats the compat-data of `esnext.string.at` as the compat-data of
  294. // pure import `instance/at`. The first polyfill here should have the lowest corejs
  295. // supported versions.
  296. "esnext.string.at", "es.string.at-alternative", "es.array.at"]),
  297. anchor: define(null, ["es.string.anchor"]),
  298. big: define(null, ["es.string.big"]),
  299. bind: define("instance/bind", ["es.function.bind"]),
  300. blink: define(null, ["es.string.blink"]),
  301. bold: define(null, ["es.string.bold"]),
  302. codePointAt: define("instance/code-point-at", ["es.string.code-point-at"]),
  303. codePoints: define("instance/code-points", ["esnext.string.code-points"]),
  304. concat: define("instance/concat", ["es.array.concat"], undefined, ["String"]),
  305. copyWithin: define("instance/copy-within", ["es.array.copy-within"]),
  306. description: define(null, ["es.symbol", "es.symbol.description"]),
  307. dotAll: define("instance/dot-all", ["es.regexp.dot-all"]),
  308. drop: define("instance/drop", ["esnext.async-iterator.drop", ...AsyncIteratorDependencies, "esnext.iterator.drop", ...IteratorDependencies]),
  309. emplace: define("instance/emplace", ["esnext.map.emplace", "esnext.weak-map.emplace"]),
  310. endsWith: define("instance/ends-with", ["es.string.ends-with"]),
  311. entries: define("instance/entries", ArrayNatureIteratorsWithTag),
  312. every: define("instance/every", ["es.array.every", "esnext.async-iterator.every", // TODO: add async iterator dependencies when we support sub-dependencies
  313. // esnext.async-iterator.every depends on es.promise
  314. // but we don't want to pull es.promise when esnext.async-iterator is disabled
  315. //
  316. // ...AsyncIteratorDependencies
  317. "esnext.iterator.every", ...IteratorDependencies]),
  318. exec: define(null, ["es.regexp.exec"]),
  319. fill: define("instance/fill", ["es.array.fill"]),
  320. filter: define("instance/filter", ["es.array.filter", "esnext.async-iterator.filter", "esnext.iterator.filter", ...IteratorDependencies]),
  321. filterReject: define("instance/filterReject", ["esnext.array.filter-reject"]),
  322. finally: define(null, ["es.promise.finally", ...PromiseDependencies]),
  323. find: define("instance/find", ["es.array.find", "esnext.async-iterator.find", "esnext.iterator.find", ...IteratorDependencies]),
  324. findIndex: define("instance/find-index", ["es.array.find-index"]),
  325. findLast: define("instance/find-last", ["esnext.array.find-last"]),
  326. findLastIndex: define("instance/find-last-index", ["esnext.array.find-last-index"]),
  327. fixed: define(null, ["es.string.fixed"]),
  328. flags: define("instance/flags", ["es.regexp.flags"]),
  329. flatMap: define("instance/flat-map", ["es.array.flat-map", "es.array.unscopables.flat-map", "esnext.async-iterator.flat-map", "esnext.iterator.flat-map", ...IteratorDependencies]),
  330. flat: define("instance/flat", ["es.array.flat", "es.array.unscopables.flat"]),
  331. getYear: define(null, ["es.date.get-year"]),
  332. groupBy: define("instance/group-by", ["esnext.array.group-by"]),
  333. groupByToMap: define("instance/group-by-to-map", ["esnext.array.group-by-to-map", "es.map", "es.object.to-string"]),
  334. fontcolor: define(null, ["es.string.fontcolor"]),
  335. fontsize: define(null, ["es.string.fontsize"]),
  336. forEach: define("instance/for-each", ["es.array.for-each", "esnext.async-iterator.for-each", "esnext.iterator.for-each", ...IteratorDependencies, "web.dom-collections.for-each"]),
  337. includes: define("instance/includes", ["es.array.includes", "es.string.includes"]),
  338. indexOf: define("instance/index-of", ["es.array.index-of"]),
  339. italic: define(null, ["es.string.italics"]),
  340. join: define(null, ["es.array.join"]),
  341. keys: define("instance/keys", ArrayNatureIteratorsWithTag),
  342. lastIndex: define(null, ["esnext.array.last-index"]),
  343. lastIndexOf: define("instance/last-index-of", ["es.array.last-index-of"]),
  344. lastItem: define(null, ["esnext.array.last-item"]),
  345. link: define(null, ["es.string.link"]),
  346. map: define("instance/map", ["es.array.map", "esnext.async-iterator.map", "esnext.iterator.map"]),
  347. match: define(null, ["es.string.match", "es.regexp.exec"]),
  348. matchAll: define("instance/match-all", ["es.string.match-all", "es.regexp.exec"]),
  349. name: define(null, ["es.function.name"]),
  350. padEnd: define("instance/pad-end", ["es.string.pad-end"]),
  351. padStart: define("instance/pad-start", ["es.string.pad-start"]),
  352. reduce: define("instance/reduce", ["es.array.reduce", "esnext.async-iterator.reduce", "esnext.iterator.reduce", ...IteratorDependencies]),
  353. reduceRight: define("instance/reduce-right", ["es.array.reduce-right"]),
  354. repeat: define("instance/repeat", ["es.string.repeat"]),
  355. replace: define(null, ["es.string.replace", "es.regexp.exec"]),
  356. replaceAll: define("instance/replace-all", ["es.string.replace-all", "es.string.replace", "es.regexp.exec"]),
  357. reverse: define("instance/reverse", ["es.array.reverse"]),
  358. search: define(null, ["es.string.search", "es.regexp.exec"]),
  359. setYear: define(null, ["es.date.set-year"]),
  360. slice: define("instance/slice", ["es.array.slice"]),
  361. small: define(null, ["es.string.small"]),
  362. some: define("instance/some", ["es.array.some", "esnext.async-iterator.some", "esnext.iterator.some", ...IteratorDependencies]),
  363. sort: define("instance/sort", ["es.array.sort"]),
  364. splice: define("instance/splice", ["es.array.splice"]),
  365. split: define(null, ["es.string.split", "es.regexp.exec"]),
  366. startsWith: define("instance/starts-with", ["es.string.starts-with"]),
  367. sticky: define("instance/sticky", ["es.regexp.sticky"]),
  368. strike: define(null, ["es.string.strike"]),
  369. sub: define(null, ["es.string.sub"]),
  370. substr: define(null, ["es.string.substr"]),
  371. sup: define(null, ["es.string.sup"]),
  372. take: define("instance/take", ["esnext.async-iterator.take", ...AsyncIteratorDependencies, "esnext.iterator.take", ...IteratorDependencies]),
  373. test: define("instance/test", ["es.regexp.test", "es.regexp.exec"]),
  374. toArray: define("instance/to-array", ["esnext.async-iterator.to-array", ...AsyncIteratorDependencies, "esnext.iterator.to-array", ...IteratorDependencies]),
  375. toAsync: define(null, ["esnext.iterator.to-async", ...IteratorDependencies, ...AsyncIteratorDependencies, ...AsyncIteratorProblemMethods]),
  376. toExponential: define(null, ["es.number.to-exponential"]),
  377. toFixed: define(null, ["es.number.to-fixed"]),
  378. toGMTString: define(null, ["es.date.to-gmt-string"]),
  379. toISOString: define(null, ["es.date.to-iso-string"]),
  380. toJSON: define(null, ["es.date.to-json", "web.url.to-json"]),
  381. toPrecision: define(null, ["es.number.to-precision"]),
  382. toReversed: define("instance/to-reversed", ["esnext.array.to-reversed"]),
  383. toSorted: define("instance/to-sorted", ["esnext.array.to-sorted", "es.array.sort"]),
  384. toSpliced: define("instance/to-reversed", ["esnext.array.to-spliced"]),
  385. toString: define(null, ["es.object.to-string", "es.error.to-string", "es.date.to-string", "es.regexp.to-string"]),
  386. trim: define("instance/trim", ["es.string.trim"]),
  387. trimEnd: define("instance/trim-end", ["es.string.trim-end"]),
  388. trimLeft: define("instance/trim-left", ["es.string.trim-start"]),
  389. trimRight: define("instance/trim-right", ["es.string.trim-end"]),
  390. trimStart: define("instance/trim-start", ["es.string.trim-start"]),
  391. uniqueBy: define("instance/unique-by", ["esnext.array.unique-by", "es.map"]),
  392. unThis: define("instance/un-this", ["esnext.function.un-this"]),
  393. values: define("instance/values", ArrayNatureIteratorsWithTag),
  394. with: define("instance/with", ["esnext.array.with"]),
  395. __defineGetter__: define(null, ["es.object.define-getter"]),
  396. __defineSetter__: define(null, ["es.object.define-setter"]),
  397. __lookupGetter__: define(null, ["es.object.lookup-getter"]),
  398. __lookupSetter__: define(null, ["es.object.lookup-setter"])
  399. };
  400. 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"]);
  401. const {
  402. types: t$1
  403. } = babel.default || babel;
  404. function callMethod(path, id) {
  405. const {
  406. object
  407. } = path.node;
  408. let context1, context2;
  409. if (t$1.isIdentifier(object)) {
  410. context1 = object;
  411. context2 = t$1.cloneNode(object);
  412. } else {
  413. context1 = path.scope.generateDeclaredUidIdentifier("context");
  414. context2 = t$1.assignmentExpression("=", t$1.cloneNode(context1), object);
  415. }
  416. path.replaceWith(t$1.memberExpression(t$1.callExpression(id, [context2]), t$1.identifier("call")));
  417. path.parentPath.unshiftContainer("arguments", context1);
  418. }
  419. function isCoreJSSource(source) {
  420. if (typeof source === "string") {
  421. source = source.replace(/\\/g, "/").replace(/(\/(index)?)?(\.js)?$/i, "").toLowerCase();
  422. }
  423. return hasOwnProperty.call(corejsEntries, source) && corejsEntries[source];
  424. }
  425. function coreJSModule(name) {
  426. return `core-js/modules/${name}.js`;
  427. }
  428. function coreJSPureHelper(name, useBabelRuntime, ext) {
  429. return useBabelRuntime ? `${useBabelRuntime}/core-js/${name}${ext}` : `core-js-pure/features/${name}.js`;
  430. }
  431. const {
  432. types: t
  433. } = babel.default || babel;
  434. const runtimeCompat = "#__secret_key__@babel/runtime__compatibility";
  435. const esnextFallback = (name, cb) => {
  436. if (cb(name)) return true;
  437. if (!name.startsWith("es.")) return false;
  438. const fallback = `esnext.${name.slice(3)}`;
  439. if (!corejs3Polyfills[fallback]) return false;
  440. return cb(fallback);
  441. };
  442. var index = defineProvider(function ({
  443. getUtils,
  444. method,
  445. shouldInjectPolyfill,
  446. createMetaResolver,
  447. debug,
  448. babel
  449. }, {
  450. version = 3,
  451. proposals,
  452. shippedProposals,
  453. [runtimeCompat]: {
  454. useBabelRuntime,
  455. ext = ".js"
  456. } = {}
  457. }) {
  458. const isWebpack = babel.caller(caller => (caller == null ? void 0 : caller.name) === "babel-loader");
  459. const resolve = createMetaResolver({
  460. global: BuiltIns,
  461. static: StaticProperties,
  462. instance: InstanceProperties
  463. });
  464. const available = new Set(getModulesListForTargetVersion(version));
  465. function getCoreJSPureBase(useProposalBase) {
  466. return useBabelRuntime ? useProposalBase ? `${useBabelRuntime}/core-js` : `${useBabelRuntime}/core-js-stable` : useProposalBase ? "core-js-pure/features" : "core-js-pure/stable";
  467. }
  468. function maybeInjectGlobalImpl(name, utils) {
  469. if (shouldInjectPolyfill(name)) {
  470. debug(name);
  471. utils.injectGlobalImport(coreJSModule(name));
  472. return true;
  473. }
  474. return false;
  475. }
  476. function maybeInjectGlobal(names, utils, fallback = true) {
  477. for (const name of names) {
  478. if (fallback) {
  479. esnextFallback(name, name => maybeInjectGlobalImpl(name, utils));
  480. } else {
  481. maybeInjectGlobalImpl(name, utils);
  482. }
  483. }
  484. }
  485. function maybeInjectPure(desc, hint, utils, object) {
  486. if (desc.pure && !(object && desc.exclude && desc.exclude.includes(object)) && esnextFallback(desc.name, shouldInjectPolyfill)) {
  487. const {
  488. name
  489. } = desc;
  490. let useProposalBase = false;
  491. if (proposals || shippedProposals && name.startsWith("esnext.")) {
  492. useProposalBase = true;
  493. } else if (name.startsWith("es.") && !available.has(name)) {
  494. useProposalBase = true;
  495. }
  496. const coreJSPureBase = getCoreJSPureBase(useProposalBase);
  497. return utils.injectDefaultImport( // $FlowIgnore, we already guard desc.pure
  498. `${coreJSPureBase}/${desc.pure}${ext}`, hint);
  499. }
  500. }
  501. function isFeatureStable(name) {
  502. if (name.startsWith("esnext.")) {
  503. const esName = `es.${name.slice(7)}`; // If its imaginative esName is not in latest compat data, it means
  504. // the proposal is not stage 4
  505. return esName in corejs3Polyfills;
  506. }
  507. return true;
  508. }
  509. return {
  510. name: "corejs3",
  511. polyfills: corejs3Polyfills,
  512. filterPolyfills(name) {
  513. if (!available.has(name)) return false;
  514. if (proposals || method === "entry-global") return true;
  515. if (shippedProposals && corejs3ShippedProposalsList.has(name)) {
  516. return true;
  517. }
  518. return isFeatureStable(name);
  519. },
  520. entryGlobal(meta, utils, path) {
  521. if (meta.kind !== "import") return;
  522. const modules = isCoreJSSource(meta.source);
  523. if (!modules) return;
  524. if (modules.length === 1 && meta.source === coreJSModule(modules[0]) && shouldInjectPolyfill(modules[0])) {
  525. // Avoid infinite loop: do not replace imports with a new copy of
  526. // themselves.
  527. debug(null);
  528. return;
  529. }
  530. const modulesSet = new Set(modules);
  531. const filteredModules = modules.filter(module => {
  532. if (!module.startsWith("esnext.")) return true;
  533. const stable = module.replace("esnext.", "es.");
  534. if (modulesSet.has(stable) && shouldInjectPolyfill(stable)) {
  535. return false;
  536. }
  537. return true;
  538. });
  539. maybeInjectGlobal(filteredModules, utils, false);
  540. path.remove();
  541. },
  542. usageGlobal(meta, utils) {
  543. const resolved = resolve(meta);
  544. if (!resolved) return;
  545. let deps = resolved.desc.global;
  546. if (resolved.kind !== "global" && meta.object && meta.placement === "prototype") {
  547. const low = meta.object.toLowerCase();
  548. deps = deps.filter(m => m.includes(low) || CommonInstanceDependencies.has(m));
  549. }
  550. maybeInjectGlobal(deps, utils);
  551. },
  552. usagePure(meta, utils, path) {
  553. if (meta.kind === "in") {
  554. if (meta.key === "Symbol.iterator") {
  555. path.replaceWith(t.callExpression(utils.injectDefaultImport(coreJSPureHelper("is-iterable", useBabelRuntime, ext), "isIterable"), [path.node.right]));
  556. }
  557. return;
  558. }
  559. if (path.parentPath.isUnaryExpression({
  560. operator: "delete"
  561. })) return;
  562. let isCall;
  563. if (meta.kind === "property") {
  564. // We can't compile destructuring.
  565. if (!path.isMemberExpression()) return;
  566. if (!path.isReferenced()) return;
  567. isCall = path.parentPath.isCallExpression({
  568. callee: path.node
  569. });
  570. if (meta.key === "Symbol.iterator") {
  571. if (!shouldInjectPolyfill("es.symbol.iterator")) return;
  572. if (isCall) {
  573. if (path.parent.arguments.length === 0) {
  574. path.parentPath.replaceWith(t.callExpression(utils.injectDefaultImport(coreJSPureHelper("get-iterator", useBabelRuntime, ext), "getIterator"), [path.node.object]));
  575. path.skip();
  576. } else {
  577. callMethod(path, utils.injectDefaultImport(coreJSPureHelper("get-iterator-method", useBabelRuntime, ext), "getIteratorMethod"));
  578. }
  579. } else {
  580. path.replaceWith(t.callExpression(utils.injectDefaultImport(coreJSPureHelper("get-iterator-method", useBabelRuntime, ext), "getIteratorMethod"), [path.node.object]));
  581. }
  582. return;
  583. }
  584. }
  585. let resolved = resolve(meta);
  586. if (!resolved) return;
  587. if (useBabelRuntime && resolved.desc.pure && resolved.desc.pure.slice(-6) === "/index") {
  588. // Remove /index, since it doesn't exist in @babel/runtime-corejs3s
  589. resolved = { ...resolved,
  590. desc: { ...resolved.desc,
  591. pure: resolved.desc.pure.slice(0, -6)
  592. }
  593. };
  594. }
  595. if (resolved.kind === "global") {
  596. const id = maybeInjectPure(resolved.desc, resolved.name, utils);
  597. if (id) path.replaceWith(id);
  598. } else if (resolved.kind === "static") {
  599. const id = maybeInjectPure(resolved.desc, resolved.name, utils, // $FlowIgnore
  600. meta.object);
  601. if (id) path.replaceWith(id);
  602. } else if (resolved.kind === "instance") {
  603. const id = maybeInjectPure(resolved.desc, `${resolved.name}InstanceProperty`, utils, // $FlowIgnore
  604. meta.object);
  605. if (!id) return;
  606. if (isCall) {
  607. callMethod(path, id);
  608. } else {
  609. path.replaceWith(t.callExpression(id, [path.node.object]));
  610. }
  611. }
  612. },
  613. visitor: method === "usage-global" && {
  614. // import("foo")
  615. CallExpression(path) {
  616. if (path.get("callee").isImport()) {
  617. const utils = getUtils(path);
  618. if (isWebpack) {
  619. // Webpack uses Promise.all to handle dynamic import.
  620. maybeInjectGlobal(PromiseDependenciesWithIterators, utils);
  621. } else {
  622. maybeInjectGlobal(PromiseDependencies, utils);
  623. }
  624. }
  625. },
  626. // (async function () { }).finally(...)
  627. Function(path) {
  628. if (path.node.async) {
  629. maybeInjectGlobal(PromiseDependencies, getUtils(path));
  630. }
  631. },
  632. // for-of, [a, b] = c
  633. "ForOfStatement|ArrayPattern"(path) {
  634. maybeInjectGlobal(CommonIterators, getUtils(path));
  635. },
  636. // [...spread]
  637. SpreadElement(path) {
  638. if (!path.parentPath.isObjectExpression()) {
  639. maybeInjectGlobal(CommonIterators, getUtils(path));
  640. }
  641. },
  642. // yield*
  643. YieldExpression(path) {
  644. if (path.node.delegate) {
  645. maybeInjectGlobal(CommonIterators, getUtils(path));
  646. }
  647. }
  648. }
  649. };
  650. });
  651. export default index;
  652. //# sourceMappingURL=index.mjs.map