index.mjs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  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. var corejs3ShippedProposalsList = new Set(["esnext.global-this", "esnext.string.match-all"]);
  7. const polyfillsOrder = {};
  8. Object.keys(corejs3Polyfills).forEach((name, index) => {
  9. polyfillsOrder[name] = index;
  10. });
  11. const define = (pure, global, name = global[0], exclude) => {
  12. return {
  13. name,
  14. pure,
  15. global: global.sort((a, b) => polyfillsOrder[a] - polyfillsOrder[b]),
  16. exclude
  17. };
  18. };
  19. const typed = name => define(null, [name, ...TypedArrayDependencies]);
  20. const ArrayNatureIterators = ["es.array.iterator", "web.dom-collections.iterator"];
  21. const CommonIterators = ["es.string.iterator", ...ArrayNatureIterators];
  22. const ArrayNatureIteratorsWithTag = ["es.object.to-string", ...ArrayNatureIterators];
  23. const CommonIteratorsWithTag = ["es.object.to-string", ...CommonIterators];
  24. const TypedArrayDependencies = ["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"];
  25. const TypedArrayStaticMethods = {
  26. from: define(null, ["es.typed-array.from"]),
  27. of: define(null, ["es.typed-array.of"])
  28. };
  29. const PromiseDependencies = ["es.promise", "es.object.to-string"];
  30. const PromiseDependenciesWithIterators = [...PromiseDependencies, ...CommonIterators];
  31. const SymbolDependencies = ["es.symbol", "es.symbol.description", "es.object.to-string"];
  32. const MapDependencies = ["es.map", "esnext.map.delete-all", "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];
  33. 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];
  34. const WeakMapDependencies = ["es.weak-map", "esnext.weak-map.delete-all", ...CommonIteratorsWithTag];
  35. const WeakSetDependencies = ["es.weak-set", "esnext.weak-set.add-all", "esnext.weak-set.delete-all", ...CommonIteratorsWithTag];
  36. const URLSearchParamsDependencies = ["web.url", ...CommonIteratorsWithTag];
  37. const BuiltIns = {
  38. AggregateError: define("aggregate-error", ["esnext.aggregate-error", ...CommonIterators]),
  39. ArrayBuffer: define(null, ["es.array-buffer.constructor", "es.array-buffer.slice", "es.object.to-string"]),
  40. DataView: define(null, ["es.data-view", "es.array-buffer.slice", "es.object.to-string"]),
  41. Date: define(null, ["es.date.to-string"]),
  42. Float32Array: typed("es.typed-array.float32-array"),
  43. Float64Array: typed("es.typed-array.float64-array"),
  44. Int8Array: typed("es.typed-array.int8-array"),
  45. Int16Array: typed("es.typed-array.int16-array"),
  46. Int32Array: typed("es.typed-array.int32-array"),
  47. Uint8Array: typed("es.typed-array.uint8-array"),
  48. Uint8ClampedArray: typed("es.typed-array.uint8-clamped-array"),
  49. Uint16Array: typed("es.typed-array.uint16-array"),
  50. Uint32Array: typed("es.typed-array.uint32-array"),
  51. Map: define("map/index", MapDependencies),
  52. Number: define(null, ["es.number.constructor"]),
  53. Observable: define("observable/index", ["esnext.observable", "esnext.symbol.observable", "es.object.to-string", ...CommonIteratorsWithTag]),
  54. Promise: define("promise/index", PromiseDependencies),
  55. RegExp: define(null, ["es.regexp.constructor", "es.regexp.exec", "es.regexp.to-string"]),
  56. Set: define("set/index", SetDependencies),
  57. Symbol: define("symbol/index", SymbolDependencies),
  58. URL: define("url/index", ["web.url", ...URLSearchParamsDependencies]),
  59. URLSearchParams: define("url-search-params/index", URLSearchParamsDependencies),
  60. WeakMap: define("weak-map/index", WeakMapDependencies),
  61. WeakSet: define("weak-set/index", WeakSetDependencies),
  62. clearImmediate: define("clear-immediate", ["web.immediate"]),
  63. compositeKey: define("composite-key", ["esnext.composite-key"]),
  64. compositeSymbol: define("composite-symbol", ["esnext.composite-symbol"]),
  65. fetch: define(null, PromiseDependencies),
  66. globalThis: define("global-this", ["es.global-this"]),
  67. parseFloat: define("parse-float", ["es.parse-float"]),
  68. parseInt: define("parse-int", ["es.parse-int"]),
  69. queueMicrotask: define("queue-microtask", ["web.queue-microtask"]),
  70. setImmediate: define("set-immediate", ["web.immediate"]),
  71. setInterval: define("set-interval", ["web.timers"]),
  72. setTimeout: define("set-timeout", ["web.timers"])
  73. };
  74. const StaticProperties = {
  75. Array: {
  76. from: define("array/from", ["es.array.from", "es.string.iterator"]),
  77. isArray: define("array/is-array", ["es.array.is-array"]),
  78. of: define("array/of", ["es.array.of"])
  79. },
  80. ArrayBuffer: {
  81. isView: define(null, ["es.array-buffer.is-view"])
  82. },
  83. Date: {
  84. now: define("date/now", ["es.date.now"])
  85. },
  86. JSON: {
  87. stringify: define("json/stringify", [], "es.symbol")
  88. },
  89. Math: {
  90. DEG_PER_RAD: define("math/deg-per-rad", ["esnext.math.deg-per-rad"]),
  91. RAD_PER_DEG: define("math/rad-per-deg", ["esnext.math.rad-per-deg"]),
  92. acosh: define("math/acosh", ["es.math.acosh"]),
  93. asinh: define("math/asinh", ["es.math.asinh"]),
  94. atanh: define("math/atanh", ["es.math.atanh"]),
  95. cbrt: define("math/cbrt", ["es.math.cbrt"]),
  96. clamp: define("math/clamp", ["esnext.math.clamp"]),
  97. clz32: define("math/clz32", ["es.math.clz32"]),
  98. cosh: define("math/cosh", ["es.math.cosh"]),
  99. degrees: define("math/degrees", ["esnext.math.degrees"]),
  100. expm1: define("math/expm1", ["es.math.expm1"]),
  101. fround: define("math/fround", ["es.math.fround"]),
  102. fscale: define("math/fscale", ["esnext.math.fscale"]),
  103. hypot: define("math/hypot", ["es.math.hypot"]),
  104. iaddh: define("math/iaddh", ["esnext.math.iaddh"]),
  105. imul: define("math/imul", ["es.math.imul"]),
  106. imulh: define("math/imulh", ["esnext.math.imulh"]),
  107. isubh: define("math/isubh", ["esnext.math.isubh"]),
  108. log10: define("math/log10", ["es.math.log10"]),
  109. log1p: define("math/log1p", ["es.math.log1p"]),
  110. log2: define("math/log2", ["es.math.log2"]),
  111. radians: define("math/radians", ["esnext.math.radians"]),
  112. scale: define("math/scale", ["esnext.math.scale"]),
  113. seededPRNG: define("math/seeded-prng", ["esnext.math.seeded-prng"]),
  114. sign: define("math/sign", ["es.math.sign"]),
  115. signbit: define("math/signbit", ["esnext.math.signbit"]),
  116. sinh: define("math/sinh", ["es.math.sinh"]),
  117. tanh: define("math/tanh", ["es.math.tanh"]),
  118. trunc: define("math/trunc", ["es.math.trunc"]),
  119. umulh: define("math/umulh", ["esnext.math.umulh"])
  120. },
  121. Map: {
  122. from: define(null, ["esnext.map.from", ...MapDependencies]),
  123. groupBy: define(null, ["esnext.map.group-by", ...MapDependencies]),
  124. keyBy: define(null, ["esnext.map.key-by", ...MapDependencies]),
  125. of: define(null, ["esnext.map.of", ...MapDependencies])
  126. },
  127. Number: {
  128. EPSILON: define("number/epsilon", ["es.number.epsilon"]),
  129. MAX_SAFE_INTEGER: define("number/max-safe-integer", ["es.number.max-safe-integer"]),
  130. MIN_SAFE_INTEGER: define("number/min-safe-integer", ["es.number.min-safe-integer"]),
  131. fromString: define("number/from-string", ["esnext.number.from-string"]),
  132. isFinite: define("number/is-finite", ["es.number.is-finite"]),
  133. isInteger: define("number/is-integer", ["es.number.is-integer"]),
  134. isNaN: define("number/is-nan", ["es.number.is-nan"]),
  135. isSafeInteger: define("number/is-safe-integer", ["es.number.is-safe-integer"]),
  136. parseFloat: define("number/parse-float", ["es.number.parse-float"]),
  137. parseInt: define("number/parse-int", ["es.number.parse-int"])
  138. },
  139. Object: {
  140. assign: define("object/assign", ["es.object.assign"]),
  141. create: define("object/create", ["es.object.create"]),
  142. defineProperties: define("object/define-properties", ["es.object.define-properties"]),
  143. defineProperty: define("object/define-property", ["es.object.define-property"]),
  144. entries: define("object/entries", ["es.object.entries"]),
  145. freeze: define("object/freeze", ["es.object.freeze"]),
  146. fromEntries: define("object/from-entries", ["es.object.from-entries", "es.array.iterator"]),
  147. getOwnPropertyDescriptor: define("object/get-own-property-descriptor", ["es.object.get-own-property-descriptor"]),
  148. getOwnPropertyDescriptors: define("object/get-own-property-descriptors", ["es.object.get-own-property-descriptors"]),
  149. getOwnPropertyNames: define("object/get-own-property-names", ["es.object.get-own-property-names"]),
  150. getOwnPropertySymbols: define("object/get-own-property-symbols", ["es.symbol"]),
  151. getPrototypeOf: define("object/get-prototype-of", ["es.object.get-prototype-of"]),
  152. is: define("object/is", ["es.object.is"]),
  153. isExtensible: define("object/is-extensible", ["es.object.is-extensible"]),
  154. isFrozen: define("object/is-frozen", ["es.object.is-frozen"]),
  155. isSealed: define("object/is-sealed", ["es.object.is-sealed"]),
  156. keys: define("object/keys", ["es.object.keys"]),
  157. preventExtensions: define("object/prevent-extensions", ["es.object.prevent-extensions"]),
  158. seal: define("object/seal", ["es.object.seal"]),
  159. setPrototypeOf: define("object/set-prototype-of", ["es.object.set-prototype-of"]),
  160. values: define("object/values", ["es.object.values"])
  161. },
  162. Promise: {
  163. all: define(null, PromiseDependenciesWithIterators),
  164. allSettled: define(null, ["es.promise.all-settled", ...PromiseDependenciesWithIterators]),
  165. any: define(null, ["esnext.promise.any", ...PromiseDependenciesWithIterators]),
  166. race: define(null, PromiseDependenciesWithIterators),
  167. try: define(null, ["esnext.promise.try", ...PromiseDependenciesWithIterators])
  168. },
  169. Reflect: {
  170. apply: define("reflect/apply", ["es.reflect.apply"]),
  171. construct: define("reflect/construct", ["es.reflect.construct"]),
  172. defineMetadata: define("reflect/define-metadata", ["esnext.reflect.define-metadata"]),
  173. defineProperty: define("reflect/define-property", ["es.reflect.define-property"]),
  174. deleteMetadata: define("reflect/delete-metadata", ["esnext.reflect.delete-metadata"]),
  175. deleteProperty: define("reflect/delete-property", ["es.reflect.delete-property"]),
  176. get: define("reflect/get", ["es.reflect.get"]),
  177. getMetadata: define("reflect/get-metadata", ["esnext.reflect.get-metadata"]),
  178. getMetadataKeys: define("reflect/get-metadata-keys", ["esnext.reflect.get-metadata-keys"]),
  179. getOwnMetadata: define("reflect/get-own-metadata", ["esnext.reflect.get-own-metadata"]),
  180. getOwnMetadataKeys: define("reflect/get-own-metadata-keys", ["esnext.reflect.get-own-metadata-keys"]),
  181. getOwnPropertyDescriptor: define("reflect/get-own-property-descriptor", ["es.reflect.get-own-property-descriptor"]),
  182. getPrototypeOf: define("reflect/get-prototype-of", ["es.reflect.get-prototype-of"]),
  183. has: define("reflect/has", ["es.reflect.has"]),
  184. hasMetadata: define("reflect/has-metadata", ["esnext.reflect.has-metadata"]),
  185. hasOwnMetadata: define("reflect/has-own-metadata", ["esnext.reflect.has-own-metadata"]),
  186. isExtensible: define("reflect/is-extensible", ["es.reflect.is-extensible"]),
  187. metadata: define("reflect/metadata", ["esnext.reflect.metadata"]),
  188. ownKeys: define("reflect/own-keys", ["es.reflect.own-keys"]),
  189. preventExtensions: define("reflect/prevent-extensions", ["es.reflect.prevent-extensions"]),
  190. set: define("reflect/set", ["es.reflect.set"]),
  191. setPrototypeOf: define("reflect/set-prototype-of", ["es.reflect.set-prototype-of"])
  192. },
  193. Set: {
  194. from: define(null, ["esnext.set.from", ...SetDependencies]),
  195. of: define(null, ["esnext.set.of", ...SetDependencies])
  196. },
  197. String: {
  198. fromCodePoint: define("string/from-code-point", ["es.string.from-code-point"]),
  199. raw: define("string/raw", ["es.string.raw"])
  200. },
  201. Symbol: {
  202. asyncIterator: define("symbol/async-iterator", ["es.symbol.async-iterator"]),
  203. dispose: define("symbol/dispose", ["esnext.symbol.dispose"]),
  204. for: define("symbol/for", [], "es.symbol"),
  205. hasInstance: define("symbol/has-instance", ["es.symbol.has-instance", "es.function.has-instance"]),
  206. isConcatSpreadable: define("symbol/is-concat-spreadable", ["es.symbol.is-concat-spreadable", "es.array.concat"]),
  207. iterator: define("symbol/iterator", ["es.symbol.iterator", ...CommonIteratorsWithTag]),
  208. keyFor: define("symbol/key-for", [], "es.symbol"),
  209. match: define("symbol/match", ["es.symbol.match", "es.string.match"]),
  210. observable: define("symbol/observable", ["esnext.symbol.observable"]),
  211. patternMatch: define("symbol/pattern-match", ["esnext.symbol.pattern-match"]),
  212. replace: define("symbol/replace", ["es.symbol.replace", "es.string.replace"]),
  213. search: define("symbol/search", ["es.symbol.search", "es.string.search"]),
  214. species: define("symbol/species", ["es.symbol.species", "es.array.species"]),
  215. split: define("symbol/split", ["es.symbol.split", "es.string.split"]),
  216. toPrimitive: define("symbol/to-primitive", ["es.symbol.to-primitive", "es.date.to-primitive"]),
  217. 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"]),
  218. unscopables: define("symbol/unscopables", ["es.symbol.unscopables"])
  219. },
  220. WeakMap: {
  221. from: define(null, ["esnext.weak-map.from", ...WeakMapDependencies]),
  222. of: define(null, ["esnext.weak-map.of", ...WeakMapDependencies])
  223. },
  224. WeakSet: {
  225. from: define(null, ["esnext.weak-set.from", ...WeakSetDependencies]),
  226. of: define(null, ["esnext.weak-set.of", ...WeakSetDependencies])
  227. },
  228. Int8Array: TypedArrayStaticMethods,
  229. Uint8Array: TypedArrayStaticMethods,
  230. Uint8ClampedArray: TypedArrayStaticMethods,
  231. Int16Array: TypedArrayStaticMethods,
  232. Uint16Array: TypedArrayStaticMethods,
  233. Int32Array: TypedArrayStaticMethods,
  234. Uint32Array: TypedArrayStaticMethods,
  235. Float32Array: TypedArrayStaticMethods,
  236. Float64Array: TypedArrayStaticMethods
  237. };
  238. const InstanceProperties = {
  239. at: define("instance/at", ["esnext.string.at"]),
  240. anchor: define(null, ["es.string.anchor"]),
  241. big: define(null, ["es.string.big"]),
  242. bind: define("instance/bind", ["es.function.bind"]),
  243. blink: define(null, ["es.string.blink"]),
  244. bold: define(null, ["es.string.bold"]),
  245. codePointAt: define("instance/code-point-at", ["es.string.code-point-at"]),
  246. codePoints: define("instance/code-points", ["esnext.string.code-points"]),
  247. concat: define("instance/concat", ["es.array.concat"], undefined, ["String"]),
  248. copyWithin: define("instance/copy-within", ["es.array.copy-within"]),
  249. description: define(null, ["es.symbol", "es.symbol.description"]),
  250. endsWith: define("instance/ends-with", ["es.string.ends-with"]),
  251. entries: define("instance/entries", ArrayNatureIteratorsWithTag),
  252. every: define("instance/every", ["es.array.every"]),
  253. exec: define(null, ["es.regexp.exec"]),
  254. fill: define("instance/fill", ["es.array.fill"]),
  255. filter: define("instance/filter", ["es.array.filter"]),
  256. finally: define(null, ["es.promise.finally", ...PromiseDependencies]),
  257. find: define("instance/find", ["es.array.find"]),
  258. findIndex: define("instance/find-index", ["es.array.find-index"]),
  259. fixed: define(null, ["es.string.fixed"]),
  260. flags: define("instance/flags", ["es.regexp.flags"]),
  261. flatMap: define("instance/flat-map", ["es.array.flat-map", "es.array.unscopables.flat-map"]),
  262. flat: define("instance/flat", ["es.array.flat"]),
  263. fontcolor: define(null, ["es.string.fontcolor"]),
  264. fontsize: define(null, ["es.string.fontsize"]),
  265. forEach: define("instance/for-each", ["es.array.for-each", "web.dom-collections.for-each"]),
  266. includes: define("instance/includes", ["es.array.includes", "es.string.includes"]),
  267. indexOf: define("instance/index-of", ["es.array.index-of"]),
  268. italic: define(null, ["es.string.italics"]),
  269. join: define(null, ["es.array.join"]),
  270. keys: define("instance/keys", ArrayNatureIteratorsWithTag),
  271. lastIndex: define(null, ["esnext.array.last-index"]),
  272. lastIndexOf: define("instance/last-index-of", ["es.array.last-index-of"]),
  273. lastItem: define(null, ["esnext.array.last-item"]),
  274. link: define(null, ["es.string.link"]),
  275. map: define("instance/map", ["es.array.map"]),
  276. match: define(null, ["es.string.match", "es.regexp.exec"]),
  277. matchAll: define("instance/match-all", ["es.string.match-all"]),
  278. name: define(null, ["es.function.name"]),
  279. padEnd: define("instance/pad-end", ["es.string.pad-end"]),
  280. padStart: define("instance/pad-start", ["es.string.pad-start"]),
  281. reduce: define("instance/reduce", ["es.array.reduce"]),
  282. reduceRight: define("instance/reduce-right", ["es.array.reduce-right"]),
  283. repeat: define("instance/repeat", ["es.string.repeat"]),
  284. replace: define(null, ["es.string.replace", "es.regexp.exec"]),
  285. replaceAll: define("instance/replace-all", ["esnext.string.replace-all"]),
  286. reverse: define("instance/reverse", ["es.array.reverse"]),
  287. search: define(null, ["es.string.search", "es.regexp.exec"]),
  288. slice: define("instance/slice", ["es.array.slice"]),
  289. small: define(null, ["es.string.small"]),
  290. some: define("instance/some", ["es.array.some"]),
  291. sort: define("instance/sort", ["es.array.sort"]),
  292. splice: define("instance/splice", ["es.array.splice"]),
  293. split: define(null, ["es.string.split", "es.regexp.exec"]),
  294. startsWith: define("instance/starts-with", ["es.string.starts-with"]),
  295. strike: define(null, ["es.string.strike"]),
  296. sub: define(null, ["es.string.sub"]),
  297. sup: define(null, ["es.string.sup"]),
  298. toFixed: define(null, ["es.number.to-fixed"]),
  299. toISOString: define(null, ["es.date.to-iso-string"]),
  300. toJSON: define(null, ["es.date.to-json", "web.url.to-json"]),
  301. toPrecision: define(null, ["es.number.to-precision"]),
  302. toString: define(null, ["es.object.to-string", "es.regexp.to-string", "es.date.to-string"]),
  303. trim: define("instance/trim", ["es.string.trim"]),
  304. trimEnd: define("instance/trim-end", ["es.string.trim-end"]),
  305. trimLeft: define("instance/trim-left", ["es.string.trim-start"]),
  306. trimRight: define("instance/trim-right", ["es.string.trim-end"]),
  307. trimStart: define("instance/trim-start", ["es.string.trim-start"]),
  308. values: define("instance/values", ArrayNatureIteratorsWithTag),
  309. __defineGetter__: define(null, ["es.object.define-getter"]),
  310. __defineSetter__: define(null, ["es.object.define-setter"]),
  311. __lookupGetter__: define(null, ["es.object.lookup-getter"]),
  312. __lookupSetter__: define(null, ["es.object.lookup-setter"])
  313. };
  314. 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"]);
  315. const {
  316. types: t$1
  317. } = babel.default || babel;
  318. function callMethod(path, id) {
  319. const {
  320. object
  321. } = path.node;
  322. let context1, context2;
  323. if (t$1.isIdentifier(object)) {
  324. context1 = object;
  325. context2 = t$1.cloneNode(object);
  326. } else {
  327. context1 = path.scope.generateDeclaredUidIdentifier("context");
  328. context2 = t$1.assignmentExpression("=", t$1.cloneNode(context1), object);
  329. }
  330. path.replaceWith(t$1.memberExpression(t$1.callExpression(id, [context2]), t$1.identifier("call")));
  331. path.parentPath.unshiftContainer("arguments", context1);
  332. }
  333. function isCoreJSSource(source) {
  334. if (typeof source === "string") {
  335. source = source.replace(/\\/g, "/").replace(/(\/(index)?)?(\.js)?$/i, "").toLowerCase();
  336. }
  337. return hasOwnProperty.call(corejsEntries, source) && corejsEntries[source];
  338. }
  339. function coreJSModule(name) {
  340. return `core-js/modules/${name}.js`;
  341. }
  342. function coreJSPureHelper(name, useBabelRuntime, ext) {
  343. return useBabelRuntime ? `${useBabelRuntime}/core-js/${name}${ext}` : `core-js-pure/features/${name}.js`;
  344. }
  345. const {
  346. types: t
  347. } = babel.default || babel;
  348. const runtimeCompat = "#__secret_key__@babel/runtime__compatibility";
  349. const esnextFallback = (name, cb) => {
  350. if (cb(name)) return true;
  351. if (!name.startsWith("es.")) return false;
  352. const fallback = `esnext.${name.slice(3)}`;
  353. if (!corejs3Polyfills[fallback]) return false;
  354. return cb(fallback);
  355. };
  356. var index = defineProvider(function ({
  357. getUtils,
  358. method,
  359. shouldInjectPolyfill,
  360. createMetaResolver,
  361. debug,
  362. babel
  363. }, {
  364. version = 3,
  365. proposals,
  366. shippedProposals,
  367. [runtimeCompat]: {
  368. useBabelRuntime,
  369. ext = ".js"
  370. } = {}
  371. }) {
  372. const isWebpack = babel.caller(caller => caller?.name === "babel-loader");
  373. const resolve = createMetaResolver({
  374. global: BuiltIns,
  375. static: StaticProperties,
  376. instance: InstanceProperties
  377. });
  378. const available = new Set(getModulesListForTargetVersion(version));
  379. const coreJSPureBase = useBabelRuntime ? proposals ? `${useBabelRuntime}/core-js` : `${useBabelRuntime}/core-js-stable` : proposals ? "core-js-pure/features" : "core-js-pure/stable";
  380. function maybeInjectGlobalImpl(name, utils) {
  381. if (shouldInjectPolyfill(name)) {
  382. debug(name);
  383. utils.injectGlobalImport(coreJSModule(name));
  384. return true;
  385. }
  386. return false;
  387. }
  388. function maybeInjectGlobal(names, utils, fallback = true) {
  389. for (const name of names) {
  390. if (fallback) {
  391. esnextFallback(name, name => maybeInjectGlobalImpl(name, utils));
  392. } else {
  393. maybeInjectGlobalImpl(name, utils);
  394. }
  395. }
  396. }
  397. function maybeInjectPure(desc, hint, utils, object) {
  398. if (desc.pure && !(object && desc.exclude && desc.exclude.includes(object)) && esnextFallback(desc.name, shouldInjectPolyfill)) {
  399. return utils.injectDefaultImport(`${coreJSPureBase}/${desc.pure}${ext}`, hint);
  400. }
  401. }
  402. return {
  403. name: "corejs3",
  404. polyfills: corejs3Polyfills,
  405. filterPolyfills(name) {
  406. if (!available.has(name)) return false;
  407. if (proposals || method === "entry-global") return true;
  408. if (shippedProposals && corejs3ShippedProposalsList.has(name)) {
  409. return true;
  410. }
  411. return !name.startsWith("esnext.");
  412. },
  413. entryGlobal(meta, utils, path) {
  414. if (meta.kind !== "import") return;
  415. const modules = isCoreJSSource(meta.source);
  416. if (!modules) return;
  417. if (modules.length === 1 && meta.source === coreJSModule(modules[0]) && shouldInjectPolyfill(modules[0])) {
  418. // Avoid infinite loop: do not replace imports with a new copy of
  419. // themselves.
  420. debug(null);
  421. return;
  422. }
  423. maybeInjectGlobal(modules, utils, false);
  424. path.remove();
  425. },
  426. usageGlobal(meta, utils) {
  427. const resolved = resolve(meta);
  428. if (!resolved) return;
  429. let deps = resolved.desc.global;
  430. if (resolved.kind !== "global" && meta.object && meta.placement === "prototype") {
  431. const low = meta.object.toLowerCase();
  432. deps = deps.filter(m => m.includes(low) || CommonInstanceDependencies.has(m));
  433. }
  434. maybeInjectGlobal(deps, utils);
  435. },
  436. usagePure(meta, utils, path) {
  437. if (meta.kind === "in") {
  438. if (meta.key === "Symbol.iterator") {
  439. path.replaceWith(t.callExpression(utils.injectDefaultImport(coreJSPureHelper("is-iterable", useBabelRuntime, ext), "isIterable"), [path.node.right]));
  440. }
  441. return;
  442. }
  443. if (path.parentPath.isUnaryExpression({
  444. operator: "delete"
  445. })) return;
  446. let isCall;
  447. if (meta.kind === "property") {
  448. // We can't compile destructuring.
  449. if (!path.isMemberExpression()) return;
  450. if (!path.isReferenced()) return;
  451. isCall = path.parentPath.isCallExpression({
  452. callee: path.node
  453. });
  454. if (meta.key === "Symbol.iterator") {
  455. if (!shouldInjectPolyfill("es.symbol.iterator")) return;
  456. if (isCall) {
  457. if (path.parent.arguments.length === 0) {
  458. path.parentPath.replaceWith(t.callExpression(utils.injectDefaultImport(coreJSPureHelper("get-iterator", useBabelRuntime, ext), "getIterator"), [path.node.object]));
  459. path.skip();
  460. } else {
  461. callMethod(path, utils.injectDefaultImport(coreJSPureHelper("get-iterator-method", useBabelRuntime, ext), "getIteratorMethod"));
  462. }
  463. } else {
  464. path.replaceWith(t.callExpression(utils.injectDefaultImport(coreJSPureHelper("get-iterator-method", useBabelRuntime, ext), "getIteratorMethod"), [path.node.object]));
  465. }
  466. return;
  467. }
  468. }
  469. let resolved = resolve(meta);
  470. if (!resolved) return;
  471. if (useBabelRuntime && resolved.desc.pure && resolved.desc.pure.slice(-6) === "/index") {
  472. // Remove /index, since it doesn't exist in @babel/runtime-corejs3s
  473. resolved = { ...resolved,
  474. desc: { ...resolved.desc,
  475. pure: resolved.desc.pure.slice(0, -6)
  476. }
  477. };
  478. }
  479. if (resolved.kind === "global") {
  480. const id = maybeInjectPure(resolved.desc, resolved.name, utils);
  481. if (id) path.replaceWith(id);
  482. } else if (resolved.kind === "static") {
  483. const id = maybeInjectPure(resolved.desc, resolved.name, utils, // $FlowIgnore
  484. meta.object);
  485. if (id) path.replaceWith(id);
  486. } else if (resolved.kind === "instance") {
  487. const id = maybeInjectPure(resolved.desc, `${resolved.name}InstanceProperty`, utils, // $FlowIgnore
  488. meta.object);
  489. if (!id) return;
  490. if (isCall) {
  491. callMethod(path, id);
  492. } else {
  493. path.replaceWith(t.callExpression(id, [path.node.object]));
  494. }
  495. }
  496. },
  497. visitor: method === "usage-global" && {
  498. // import("foo")
  499. CallExpression(path) {
  500. if (path.get("callee").isImport()) {
  501. const utils = getUtils(path);
  502. if (isWebpack) {
  503. // Webpack uses Promise.all to handle dynamic import.
  504. maybeInjectGlobal(PromiseDependenciesWithIterators, utils);
  505. } else {
  506. maybeInjectGlobal(PromiseDependencies, utils);
  507. }
  508. }
  509. },
  510. // (async function () { }).finally(...)
  511. Function(path) {
  512. if (path.node.async) {
  513. maybeInjectGlobal(PromiseDependencies, getUtils(path));
  514. }
  515. },
  516. // for-of, [a, b] = c
  517. "ForOfStatement|ArrayPattern"(path) {
  518. maybeInjectGlobal(CommonIterators, getUtils(path));
  519. },
  520. // [...spread]
  521. SpreadElement(path) {
  522. if (!path.parentPath.isObjectExpression()) {
  523. maybeInjectGlobal(CommonIterators, getUtils(path));
  524. }
  525. },
  526. // yield*
  527. YieldExpression(path) {
  528. if (path.node.delegate) {
  529. maybeInjectGlobal(CommonIterators, getUtils(path));
  530. }
  531. }
  532. }
  533. };
  534. });
  535. export default index;
  536. //# sourceMappingURL=index.mjs.map