diff --git a/.prettierignore b/.prettierignore index e07c1a7c..03caa088 100644 --- a/.prettierignore +++ b/.prettierignore @@ -3,3 +3,4 @@ packages/*/test/fixtures/**/input.* packages/*/test/fixtures/**/exec.* packages/*/test/fixtures/**/output.* packages/babel-plugin-polyfill-corejs2/data/* +packages/babel-plugin-polyfill-corejs3/src/shipped-proposals.js \ No newline at end of file diff --git a/package.json b/package.json index 7073880f..3f1810a4 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,8 @@ "private": true, "license": "MIT", "scripts": { - "build": "yarn build-es-shims-data && gulp build && gulp bundle", + "build": "yarn build-es-shims-data && yarn build-corejs3-shipped-proposals && gulp build && gulp bundle", + "build-corejs3-shipped-proposals": "node ./scripts/build-corejs3-shipped-proposals.mjs", "build-es-shims-data": "./scripts/download-compat-table.sh && node ./scripts/build-es-shims-data", "clean": "rimraf packages/*/lib packages/*/esm", "clean-all": "yarn clean && rimraf packages/*/node_modules node_modules", diff --git a/packages/babel-plugin-polyfill-corejs3/package.json b/packages/babel-plugin-polyfill-corejs3/package.json index 2e4e42a7..3a86adcf 100644 --- a/packages/babel-plugin-polyfill-corejs3/package.json +++ b/packages/babel-plugin-polyfill-corejs3/package.json @@ -27,7 +27,7 @@ ], "dependencies": { "@babel/helper-define-polyfill-provider": "workspace:^0.2.2", - "core-js-compat": "^3.16.2" + "core-js-compat": "^3.18.0" }, "devDependencies": { "@babel/core": "^7.13.0", diff --git a/packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.js b/packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.js index dfa5db6e..f9463475 100644 --- a/packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.js +++ b/packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.js @@ -47,6 +47,7 @@ const ArrayNatureIteratorsWithTag = [ const CommonIteratorsWithTag = ["es.object.to-string", ...CommonIterators]; const TypedArrayDependencies = [ + "es.typed-array.at", "es.typed-array.copy-within", "es.typed-array.every", "es.typed-array.fill", @@ -73,13 +74,13 @@ const TypedArrayDependencies = [ "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.unique-by", ]; -const TypedArrayStaticMethods = { - from: define(null, ["es.typed-array.from"]), - of: define(null, ["es.typed-array.of"]), -}; - export const PromiseDependencies = ["es.promise", "es.object.to-string"]; export const PromiseDependenciesWithIterators = [ @@ -96,6 +97,7 @@ const SymbolDependencies = [ const MapDependencies = [ "es.map", "esnext.map.delete-all", + "esnext.map.emplace", "esnext.map.every", "esnext.map.filter", "esnext.map.find", @@ -135,6 +137,7 @@ const SetDependencies = [ const WeakMapDependencies = [ "es.weak-map", "esnext.weak-map.delete-all", + "esnext.weak-map.emplace", ...CommonIteratorsWithTag, ]; @@ -150,7 +153,27 @@ const URLSearchParamsDependencies = [ ...CommonIteratorsWithTag, ]; +const AsyncIteratorDependencies = [ + "esnext.async-iterator.constructor", + ...PromiseDependencies, +]; + +const IteratorDependencies = [ + "esnext.iterator.constructor", + "es.object.to-string", +]; + +const TypedArrayStaticMethods = { + from: define(null, ["es.typed-array.from"]), + fromAsync: define(null, [ + "esnext.typed-array.from-async", + ...PromiseDependenciesWithIterators, + ]), + of: define(null, ["es.typed-array.of"]), +}; + export const BuiltIns: ObjectMap = { + AsyncIterator: define("async-iterator/index", AsyncIteratorDependencies), AggregateError: define("aggregate-error", [ "es.aggregate-error", ...CommonIterators, @@ -171,6 +194,7 @@ export const BuiltIns: ObjectMap = { Int8Array: typed("es.typed-array.int8-array"), Int16Array: typed("es.typed-array.int16-array"), Int32Array: typed("es.typed-array.int32-array"), + Iterator: define("iterator/index", IteratorDependencies), Uint8Array: typed("es.typed-array.uint8-array"), Uint8ClampedArray: typed("es.typed-array.uint8-clamped-array"), Uint16Array: typed("es.typed-array.uint16-array"), @@ -184,9 +208,12 @@ export const BuiltIns: ObjectMap = { ...CommonIteratorsWithTag, ]), Promise: define("promise/index", PromiseDependencies), + Reflect: define(null, ["es.reflect.to-string-tag", "es.object.to-string"]), RegExp: define(null, [ "es.regexp.constructor", + "es.regexp.dot-all", "es.regexp.exec", + "es.regexp.sticky", "es.regexp.to-string", ]), Set: define("set/index", SetDependencies), @@ -199,6 +226,7 @@ export const BuiltIns: ObjectMap = { clearImmediate: define("clear-immediate", ["web.immediate"]), compositeKey: define("composite-key", ["esnext.composite-key"]), compositeSymbol: define("composite-symbol", ["esnext.composite-symbol"]), + escape: define("escape", ["es.escape"]), fetch: define(null, PromiseDependencies), globalThis: define("global-this", ["es.global-this"]), parseFloat: define("parse-float", ["es.parse-float"]), @@ -207,14 +235,29 @@ export const BuiltIns: ObjectMap = { setImmediate: define("set-immediate", ["web.immediate"]), setInterval: define("set-interval", ["web.timers"]), setTimeout: define("set-timeout", ["web.timers"]), + unescape: define("unescape", ["es.unescape"]), }; export const StaticProperties: ObjectMap< ObjectMap, > = { + AsyncIterator: { + from: define("async-iterator/from", [ + "esnext.async-iterator.from", + ...AsyncIteratorDependencies, + ...CommonIterators, + ]), + }, Array: { from: define("array/from", ["es.array.from", "es.string.iterator"]), + fromAsync: define("array/from-async", [ + "esnext.array.from-async", + ...PromiseDependenciesWithIterators, + ]), isArray: define("array/is-array", ["es.array.is-array"]), + isTemplateObject: define("array/is-template-object", [ + "esnext.array.is-template-object", + ]), of: define("array/of", ["es.array.of"]), }, @@ -222,12 +265,27 @@ export const StaticProperties: ObjectMap< isView: define(null, ["es.array-buffer.is-view"]), }, + BigInt: { + range: define("bigint/range", [ + "esnext.bigint.range", + "es.object.to-string", + ]), + }, + Date: { now: define("date/now", ["es.date.now"]), }, + Iterator: { + from: define("iterator/from", [ + "esnext.iterator.from", + ...IteratorDependencies, + ...CommonIterators, + ]), + }, + JSON: { - stringify: define("json/stringify", [], "es.symbol"), + stringify: define("json/stringify", ["es.json.stringify"], "es.symbol"), }, Math: { @@ -287,6 +345,10 @@ export const StaticProperties: ObjectMap< ]), parseFloat: define("number/parse-float", ["es.number.parse-float"]), parseInt: define("number/parse-int", ["es.number.parse-int"]), + range: define("number/range", [ + "esnext.number.range", + "es.object.to-string", + ]), }, Object: { @@ -319,7 +381,7 @@ export const StaticProperties: ObjectMap< getPrototypeOf: define("object/get-prototype-of", [ "es.object.get-prototype-of", ]), - hasOwn: define("object/has-own", ["esnext.object.has-own"]), + hasOwn: define("object/has-own", ["es.object.has-own"]), is: define("object/is", ["es.object.is"]), isExtensible: define("object/is-extensible", ["es.object.is-extensible"]), isFrozen: define("object/is-frozen", ["es.object.is-frozen"]), @@ -341,7 +403,11 @@ export const StaticProperties: ObjectMap< "es.promise.all-settled", ...PromiseDependenciesWithIterators, ]), - any: define(null, ["es.promise.any", ...PromiseDependenciesWithIterators]), + any: define(null, [ + "es.promise.any", + "es.aggregate-error", + ...PromiseDependenciesWithIterators, + ]), race: define(null, PromiseDependenciesWithIterators), try: define(null, [ "esnext.promise.try", @@ -415,6 +481,9 @@ export const StaticProperties: ObjectMap< }, Symbol: { + asyncDispose: define("symbol/async-dispose", [ + "esnext.symbol.async-dispose", + ]), asyncIterator: define("symbol/async-iterator", [ "es.symbol.async-iterator", ]), @@ -434,6 +503,12 @@ export const StaticProperties: ObjectMap< ]), keyFor: define("symbol/key-for", [], "es.symbol"), match: define("symbol/match", ["es.symbol.match", "es.string.match"]), + matcher: define("symbol/matcher", ["esnext.symbol.matcher"]), + matchAll: define("symbol/match-all", [ + "es.symbol.match-all", + "es.string.match-all", + ]), + metadata: define("symbol/metadata", ["esnext.symbol.metadata"]), observable: define("symbol/observable", ["esnext.symbol.observable"]), patternMatch: define("symbol/pattern-match", [ "esnext.symbol.pattern-match", @@ -483,10 +558,22 @@ export const StaticProperties: ObjectMap< }; export const InstanceProperties = { + asIndexedPairs: define("instance/asIndexedPairs", [ + "esnext.async-iterator.as-indexed-pairs", + ...AsyncIteratorDependencies, + "esnext.iterator.as-indexed-pairs", + ...IteratorDependencies, + ]), at: define("instance/at", [ + // TODO: We should introduce overloaded instance methods definition + // Before that is implemented, the `esnext.string.at` must be the first + // In pure mode, the provider resolves the descriptor as a "pure" `esnext.string.at` + // and treats the compat-data of `esnext.string.at` as the compat-data of + // pure import `instance/at`. The first polyfill here should have the lowest corejs + // supported versions. "esnext.string.at", - "esnext.array.at", - "esnext.typed-array.at", + "es.string.at-alternative", + "es.array.at", ]), anchor: define(null, ["es.string.anchor"]), big: define(null, ["es.string.big"]), @@ -498,14 +585,46 @@ export const InstanceProperties = { concat: define("instance/concat", ["es.array.concat"], undefined, ["String"]), copyWithin: define("instance/copy-within", ["es.array.copy-within"]), description: define(null, ["es.symbol", "es.symbol.description"]), + dotAll: define("instance/dot-all", ["es.regexp.dot-all"]), + drop: define("instance/drop", [ + "esnext.async-iterator.drop", + ...AsyncIteratorDependencies, + "esnext.iterator.drop", + ...IteratorDependencies, + ]), + emplace: define("instance/emplace", [ + "esnext.map.emplace", + "esnext.weak-map.emplace", + ]), endsWith: define("instance/ends-with", ["es.string.ends-with"]), entries: define("instance/entries", ArrayNatureIteratorsWithTag), - every: define("instance/every", ["es.array.every"]), + every: define("instance/every", [ + "es.array.every", + "esnext.async-iterator.every", + // TODO: add async iterator dependencies when we support sub-dependencies + // esnext.async-iterator.every depends on es.promise + // but we don't want to pull es.promise when esnext.async-iterator is disabled + // + // ...AsyncIteratorDependencies + "esnext.iterator.every", + ...IteratorDependencies, + ]), exec: define(null, ["es.regexp.exec"]), fill: define("instance/fill", ["es.array.fill"]), - filter: define("instance/filter", ["es.array.filter"]), + filter: define("instance/filter", [ + "es.array.filter", + "esnext.async-iterator.filter", + "esnext.iterator.filter", + ...IteratorDependencies, + ]), + filterReject: define("instance/filterReject", ["esnext.array.filter-reject"]), finally: define(null, ["es.promise.finally", ...PromiseDependencies]), - find: define("instance/find", ["es.array.find"]), + find: define("instance/find", [ + "es.array.find", + "esnext.async-iterator.find", + "esnext.iterator.find", + ...IteratorDependencies, + ]), findIndex: define("instance/find-index", ["es.array.find-index"]), findLast: define("instance/find-last", ["esnext.array.find-last"]), findLastIndex: define("instance/find-last-index", [ @@ -516,12 +635,20 @@ export const InstanceProperties = { flatMap: define("instance/flat-map", [ "es.array.flat-map", "es.array.unscopables.flat-map", + "esnext.async-iterator.flat-map", + "esnext.iterator.flat-map", + ...IteratorDependencies, ]), - flat: define("instance/flat", ["es.array.flat"]), + flat: define("instance/flat", ["es.array.flat", "es.array.unscopables.flat"]), + getYear: define(null, ["es.date.get-year"]), + groupBy: define("instance/group-by", ["esnext.array.group-by"]), fontcolor: define(null, ["es.string.fontcolor"]), fontsize: define(null, ["es.string.fontsize"]), forEach: define("instance/for-each", [ "es.array.for-each", + "esnext.async-iterator.for-each", + "esnext.iterator.for-each", + ...IteratorDependencies, "web.dom-collections.for-each", ]), includes: define("instance/includes", [ @@ -536,30 +663,68 @@ export const InstanceProperties = { lastIndexOf: define("instance/last-index-of", ["es.array.last-index-of"]), lastItem: define(null, ["esnext.array.last-item"]), link: define(null, ["es.string.link"]), - map: define("instance/map", ["es.array.map"]), + map: define("instance/map", [ + "es.array.map", + "esnext.async-iterator.map", + "esnext.iterator.map", + ]), match: define(null, ["es.string.match", "es.regexp.exec"]), - matchAll: define("instance/match-all", ["es.string.match-all"]), + matchAll: define("instance/match-all", [ + "es.string.match-all", + "es.regexp.exec", + ]), name: define(null, ["es.function.name"]), padEnd: define("instance/pad-end", ["es.string.pad-end"]), padStart: define("instance/pad-start", ["es.string.pad-start"]), - reduce: define("instance/reduce", ["es.array.reduce"]), + reduce: define("instance/reduce", [ + "es.array.reduce", + "esnext.async-iterator.reduce", + "esnext.iterator.reduce", + ...IteratorDependencies, + ]), reduceRight: define("instance/reduce-right", ["es.array.reduce-right"]), repeat: define("instance/repeat", ["es.string.repeat"]), replace: define(null, ["es.string.replace", "es.regexp.exec"]), - replaceAll: define("instance/replace-all", ["es.string.replace-all"]), + replaceAll: define("instance/replace-all", [ + "es.string.replace-all", + "es.string.replace", + "es.regexp.exec", + ]), reverse: define("instance/reverse", ["es.array.reverse"]), search: define(null, ["es.string.search", "es.regexp.exec"]), + setYear: define(null, ["es.date.set-year"]), slice: define("instance/slice", ["es.array.slice"]), small: define(null, ["es.string.small"]), - some: define("instance/some", ["es.array.some"]), + some: define("instance/some", [ + "es.array.some", + "esnext.async-iterator.some", + "esnext.iterator.some", + ...IteratorDependencies, + ]), sort: define("instance/sort", ["es.array.sort"]), splice: define("instance/splice", ["es.array.splice"]), split: define(null, ["es.string.split", "es.regexp.exec"]), startsWith: define("instance/starts-with", ["es.string.starts-with"]), + sticky: define("instance/sticky", ["es.regexp.sticky"]), strike: define(null, ["es.string.strike"]), sub: define(null, ["es.string.sub"]), + substr: define(null, ["es.string.substr"]), sup: define(null, ["es.string.sup"]), + take: define("instance/take", [ + "esnext.async-iterator.take", + ...AsyncIteratorDependencies, + "esnext.iterator.take", + ...IteratorDependencies, + ]), + test: define("instance/test", ["es.regexp.test", "es.regexp.exec"]), + toArray: define("instance/to-array", [ + "esnext.async-iterator.to-array", + ...AsyncIteratorDependencies, + "esnext.iterator.to-array", + ...IteratorDependencies, + ]), toFixed: define(null, ["es.number.to-fixed"]), + toGMTString: define(null, ["es.date.to-gmt-string"]), toISOString: define(null, ["es.date.to-iso-string"]), toJSON: define(null, ["es.date.to-json", "web.url.to-json"]), toPrecision: define(null, ["es.number.to-precision"]), @@ -573,6 +738,7 @@ export const InstanceProperties = { trimLeft: define("instance/trim-left", ["es.string.trim-start"]), trimRight: define("instance/trim-right", ["es.string.trim-end"]), trimStart: define("instance/trim-start", ["es.string.trim-start"]), + uniqueBy: define("instance/unique-by", ["esnext.array.unique-by", "es.map"]), values: define("instance/values", ArrayNatureIteratorsWithTag), __defineGetter__: define(null, ["es.object.define-getter"]), __defineSetter__: define(null, ["es.object.define-setter"]), diff --git a/packages/babel-plugin-polyfill-corejs3/src/shipped-proposals.js b/packages/babel-plugin-polyfill-corejs3/src/shipped-proposals.js index 9cfc3b77..58324a8d 100644 --- a/packages/babel-plugin-polyfill-corejs3/src/shipped-proposals.js +++ b/packages/babel-plugin-polyfill-corejs3/src/shipped-proposals.js @@ -1,6 +1,5 @@ // @flow +// This file is automatically generated by scripts/build-corejs3-shipped-proposals.js export default new Set([ - "esnext.global-this", - "esnext.string.match-all", ]); diff --git a/packages/babel-plugin-polyfill-corejs3/test/check-builtin-definitions.test.js b/packages/babel-plugin-polyfill-corejs3/test/check-builtin-definitions.test.js index 90c65ca9..e3ec6a49 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/check-builtin-definitions.test.js +++ b/packages/babel-plugin-polyfill-corejs3/test/check-builtin-definitions.test.js @@ -8,7 +8,7 @@ import { const supportedCorejs3Modules = new Set(); -const corejs3Modules = corejs3Entries["core-js"]; +const corejs3Modules = new Set(corejs3Entries["core-js"]); function addsupportedCorejs3Modules(descriptors) { for (const { global } of Object.values(descriptors)) { @@ -48,76 +48,29 @@ packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.js.`, } allowList.push(name); } + for (const name of supportedCorejs3Modules.values()) { + if (!corejs3Modules.has(name)) { + todoListItem++; + console.error( + `"${name}" in +packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.js +is not in "core-js-compat/entries": This is very likely a typo`, + ); + } + } expect(todoListItem).toBe(0); // The allowlist should only be added when we decide we don't support // the feature in `src/builtin-definitions.js` expect(allowList).toMatchInlineSnapshot(` Array [ - "es.symbol.match-all", - "es.array.unscopables.flat", - "es.date.get-year", - "es.date.set-year", - "es.date.to-gmt-string", - "es.escape", - "es.json.stringify", - "es.reflect.to-string-tag", - "es.regexp.dot-all", - "es.regexp.sticky", - "es.regexp.test", - "es.string.substr", - "es.unescape", "esnext.array.filter-out", - "esnext.array.filter-reject", - "esnext.array.group-by", - "esnext.array.is-template-object", - "esnext.array.unique-by", - "esnext.async-iterator.constructor", - "esnext.async-iterator.as-indexed-pairs", - "esnext.async-iterator.drop", - "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.from", - "esnext.async-iterator.map", - "esnext.async-iterator.reduce", - "esnext.async-iterator.some", - "esnext.async-iterator.take", - "esnext.async-iterator.to-array", - "esnext.bigint.range", - "esnext.iterator.constructor", - "esnext.iterator.as-indexed-pairs", - "esnext.iterator.drop", - "esnext.iterator.every", - "esnext.iterator.filter", - "esnext.iterator.find", - "esnext.iterator.flat-map", - "esnext.iterator.for-each", - "esnext.iterator.from", - "esnext.iterator.map", - "esnext.iterator.reduce", - "esnext.iterator.some", - "esnext.iterator.take", - "esnext.iterator.to-array", - "esnext.map.emplace", "esnext.map.update-or-insert", "esnext.map.upsert", - "esnext.number.range", "esnext.object.iterate-entries", "esnext.object.iterate-keys", "esnext.object.iterate-values", - "esnext.symbol.async-dispose", - "esnext.symbol.matcher", - "esnext.symbol.metadata", "esnext.symbol.replace-all", "esnext.typed-array.filter-out", - "esnext.typed-array.filter-reject", - "esnext.typed-array.find-last", - "esnext.typed-array.find-last-index", - "esnext.typed-array.group-by", - "esnext.typed-array.unique-by", - "esnext.weak-map.emplace", "esnext.weak-map.upsert", ] `); diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/all-proposals-chrome-90-corejs-3.16/input.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/all-proposals-chrome-90-corejs-3.16/input.mjs new file mode 100644 index 00000000..33a70615 --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/all-proposals-chrome-90-corejs-3.16/input.mjs @@ -0,0 +1,35 @@ +[].findLast(fn); +[].findLastIndex(fn); + +[].asIndexedPairs(); + +Iterator.from({ + next: () => ({ done: Math.random() > .9, value: Math.random() * 10 | 0 }) + }).forEach(console.log).toArray(); + +AsyncIterator.from([1, 2, 3, 4, 5, 6, 7]) + .drop(1) + .take(5) + .filter(it => it % 2) + .groupBy(it => id % 4) + .map(it => it ** 2) + .toArray() + .then(console.log); + +[1, 2, 3, 4, 5, 6, 7, 7].uniqueBy(x => x).groupBy(x => x % 2); + +Number.range(1, 2); +BigInt.range(1n, 2n); + +Array.isTemplateObject((x => x)`a${ x }z`) + +new Map([['x', 1]]).emplace('x', { update: x => x + 1, insert: () => 0}); + +/x/.dotAll; +/x/.sticky + +Symbol.asyncDispose +Symbol.matcher +Symbol.matchAll +Symbol.metadata +Symbol.replaceAll \ No newline at end of file diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/all-proposals-chrome-90-corejs-3.16/options.json b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/all-proposals-chrome-90-corejs-3.16/options.json new file mode 100644 index 00000000..1cf540c0 --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/all-proposals-chrome-90-corejs-3.16/options.json @@ -0,0 +1,15 @@ +{ + "targets": { + "chrome": 90 + }, + "plugins": [ + [ + "@@/polyfill-corejs3", + { + "method": "usage-global", + "version": "3.16", + "proposals": true + } + ] + ] +} \ No newline at end of file diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/all-proposals-chrome-90-corejs-3.16/output.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/all-proposals-chrome-90-corejs-3.16/output.mjs new file mode 100644 index 00000000..09b772b1 --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/all-proposals-chrome-90-corejs-3.16/output.mjs @@ -0,0 +1,66 @@ +import "core-js/modules/esnext.array.find-last.js"; +import "core-js/modules/esnext.array.find-last-index.js"; +import "core-js/modules/esnext.async-iterator.constructor.js"; +import "core-js/modules/esnext.async-iterator.to-array.js"; +import "core-js/modules/esnext.iterator.constructor.js"; +import "core-js/modules/esnext.iterator.to-array.js"; +import "core-js/modules/esnext.async-iterator.for-each.js"; +import "core-js/modules/esnext.iterator.for-each.js"; +import "core-js/modules/esnext.iterator.from.js"; +import "core-js/modules/esnext.async-iterator.map.js"; +import "core-js/modules/esnext.iterator.map.js"; +import "core-js/modules/esnext.array.group-by.js"; +import "core-js/modules/esnext.async-iterator.filter.js"; +import "core-js/modules/esnext.iterator.filter.js"; +import "core-js/modules/esnext.async-iterator.take.js"; +import "core-js/modules/esnext.iterator.take.js"; +import "core-js/modules/esnext.async-iterator.drop.js"; +import "core-js/modules/esnext.iterator.drop.js"; +import "core-js/modules/esnext.async-iterator.from.js"; +import "core-js/modules/esnext.array.unique-by.js"; +import "core-js/modules/esnext.number.range.js"; +import "core-js/modules/esnext.bigint.range.js"; +import "core-js/modules/esnext.array.is-template-object.js"; +import "core-js/modules/esnext.map.emplace.js"; +import "core-js/modules/esnext.weak-map.emplace.js"; +import "core-js/modules/esnext.map.delete-all.js"; +import "core-js/modules/esnext.map.every.js"; +import "core-js/modules/esnext.map.filter.js"; +import "core-js/modules/esnext.map.find.js"; +import "core-js/modules/esnext.map.find-key.js"; +import "core-js/modules/esnext.map.includes.js"; +import "core-js/modules/esnext.map.key-of.js"; +import "core-js/modules/esnext.map.map-keys.js"; +import "core-js/modules/esnext.map.map-values.js"; +import "core-js/modules/esnext.map.merge.js"; +import "core-js/modules/esnext.map.reduce.js"; +import "core-js/modules/esnext.map.some.js"; +import "core-js/modules/esnext.map.update.js"; +import "core-js/modules/esnext.symbol.async-dispose.js"; +import "core-js/modules/esnext.symbol.matcher.js"; +import "core-js/modules/esnext.symbol.metadata.js"; +[].findLast(fn); +[].findLastIndex(fn); +[].asIndexedPairs(); +Iterator.from({ + next: () => ({ + done: Math.random() > .9, + value: Math.random() * 10 | 0 + }) +}).forEach(console.log).toArray(); +AsyncIterator.from([1, 2, 3, 4, 5, 6, 7]).drop(1).take(5).filter(it => it % 2).groupBy(it => id % 4).map(it => it ** 2).toArray().then(console.log); +[1, 2, 3, 4, 5, 6, 7, 7].uniqueBy(x => x).groupBy(x => x % 2); +Number.range(1, 2); +BigInt.range(1n, 2n); +Array.isTemplateObject((x => x)`a${x}z`); +new Map([['x', 1]]).emplace('x', { + update: x => x + 1, + insert: () => 0 +}); +/x/.dotAll; +/x/.sticky; +Symbol.asyncDispose; +Symbol.matcher; +Symbol.matchAll; +Symbol.metadata; +Symbol.replaceAll; diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/array-at-proposals-corejs-3.8/options.json b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/array-at-proposals-corejs-3.8/options.json index 2df64af9..b02ac474 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/array-at-proposals-corejs-3.8/options.json +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/array-at-proposals-corejs-3.8/options.json @@ -4,7 +4,7 @@ "@@/polyfill-corejs3", { "method": "usage-global", - "version": 3.8, + "version": "3.8", "proposals": true } ] diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/array-at-proposals-corejs-3.8/output.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/array-at-proposals-corejs-3.8/output.mjs index 1132dd25..add60f53 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/array-at-proposals-corejs-3.8/output.mjs +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/array-at-proposals-corejs-3.8/output.mjs @@ -1,3 +1,2 @@ import "core-js/modules/esnext.array.at.js"; -import "core-js/modules/esnext.typed-array.at.js"; [].at(-1); diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/array-flat/output.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/array-flat/output.mjs index b7a735f4..b15f5b2f 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/array-flat/output.mjs +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/array-flat/output.mjs @@ -1,5 +1,7 @@ import "core-js/modules/es.array.flat.js"; +import "core-js/modules/es.array.unscopables.flat.js"; import "core-js/modules/es.array.flat-map.js"; import "core-js/modules/es.array.unscopables.flat-map.js"; +import "core-js/modules/es.object.to-string.js"; [].flat(); [].flatMap(); diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/esnext-es-fallback-corejs-3.6/output.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/esnext-es-fallback-corejs-3.6/output.mjs index 8cdd04d8..cd39079c 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/esnext-es-fallback-corejs-3.6/output.mjs +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/esnext-es-fallback-corejs-3.6/output.mjs @@ -1,2 +1,4 @@ +import "core-js/modules/es.regexp.exec.js"; +import "core-js/modules/es.string.replace.js"; import "core-js/modules/esnext.string.replace-all.js"; "x".replaceAll("x", ""); diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/evaluated-instance-methods/output.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/evaluated-instance-methods/output.mjs index 28a71c4b..03dc6823 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/evaluated-instance-methods/output.mjs +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/evaluated-instance-methods/output.mjs @@ -1,5 +1,6 @@ import "core-js/modules/es.array.includes.js"; import "core-js/modules/es.array.find.js"; +import "core-js/modules/es.object.to-string.js"; var arrayInstance = []; var inclidesStr = "includes"; var findStr = "find"; // Allow instance methods be assigned to variables. diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/instance-at-proposals-corejs-3.8/options.json b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/instance-at-proposals-corejs-3.8/options.json index 2df64af9..b02ac474 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/instance-at-proposals-corejs-3.8/options.json +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/instance-at-proposals-corejs-3.8/options.json @@ -4,7 +4,7 @@ "@@/polyfill-corejs3", { "method": "usage-global", - "version": 3.8, + "version": "3.8", "proposals": true } ] diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/instance-at-proposals-corejs-3.8/output.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/instance-at-proposals-corejs-3.8/output.mjs index 22e740fa..ed6ae4a5 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/instance-at-proposals-corejs-3.8/output.mjs +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/instance-at-proposals-corejs-3.8/output.mjs @@ -2,6 +2,7 @@ import "core-js/modules/es.array.iterator.js"; import "core-js/modules/es.array-buffer.slice.js"; import "core-js/modules/es.object.to-string.js"; import "core-js/modules/es.typed-array.int8-array.js"; +import "core-js/modules/esnext.typed-array.at.js"; import "core-js/modules/es.typed-array.copy-within.js"; import "core-js/modules/es.typed-array.every.js"; import "core-js/modules/es.typed-array.fill.js"; @@ -27,7 +28,6 @@ import "core-js/modules/es.typed-array.to-locale-string.js"; import "core-js/modules/es.typed-array.to-string.js"; import "core-js/modules/esnext.array.at.js"; import "core-js/modules/esnext.string.at.js"; -import "core-js/modules/esnext.typed-array.at.js"; // obscuring instance type let tmp; diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/object-hasown-version-3.11/output.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/object-hasown-version-3.11/output.mjs index f03dc36b..7ca9b48e 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/object-hasown-version-3.11/output.mjs +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/object-hasown-version-3.11/output.mjs @@ -1 +1,2 @@ +import "core-js/modules/esnext.object.has-own.js"; Object.hasOwn; diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.0-proposals/options.json b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.0-proposals/options.json index 9b03e9a8..c52dad5f 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.0-proposals/options.json +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.0-proposals/options.json @@ -4,7 +4,7 @@ "@@/polyfill-corejs3", { "method": "usage-global", - "version": 3.0, + "version": "3.0", "proposals": true } ] diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.0-proposals/output.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.0-proposals/output.mjs index acc15ae5..0b10d319 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.0-proposals/output.mjs +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.0-proposals/output.mjs @@ -1,4 +1,5 @@ import "core-js/modules/esnext.global-this.js"; +import "core-js/modules/es.regexp.exec.js"; import "core-js/modules/esnext.string.match-all.js"; globalThis; foo.matchAll(bar); diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.0/options.json b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.0/options.json index 1d379daf..2ccde88b 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.0/options.json +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.0/options.json @@ -4,7 +4,7 @@ "@@/polyfill-corejs3", { "method": "usage-global", - "version": 3.0 + "version": "3.0" } ] ] diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.0/output.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.0/output.mjs index acc15ae5..0b10d319 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.0/output.mjs +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.0/output.mjs @@ -1,4 +1,5 @@ import "core-js/modules/esnext.global-this.js"; +import "core-js/modules/es.regexp.exec.js"; import "core-js/modules/esnext.string.match-all.js"; globalThis; foo.matchAll(bar); diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.8-proposals/options.json b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.8-proposals/options.json index 2df64af9..b02ac474 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.8-proposals/options.json +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.8-proposals/options.json @@ -4,7 +4,7 @@ "@@/polyfill-corejs3", { "method": "usage-global", - "version": 3.8, + "version": "3.8", "proposals": true } ] diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.8-proposals/output.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.8-proposals/output.mjs index 48f87cf6..1f9a7ff8 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.8-proposals/output.mjs +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.8-proposals/output.mjs @@ -1,4 +1,5 @@ import "core-js/modules/es.global-this.js"; +import "core-js/modules/es.regexp.exec.js"; import "core-js/modules/es.string.match-all.js"; globalThis; foo.matchAll(bar); diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.8/options.json b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.8/options.json index c1cd418a..075e909b 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.8/options.json +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.8/options.json @@ -4,7 +4,7 @@ "@@/polyfill-corejs3", { "method": "usage-global", - "version": 3.8 + "version": "3.8" } ] ] diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.8/output.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.8/output.mjs index 48f87cf6..1f9a7ff8 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.8/output.mjs +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/proposal-to-stable-corejs-3.8/output.mjs @@ -1,4 +1,5 @@ import "core-js/modules/es.global-this.js"; +import "core-js/modules/es.regexp.exec.js"; import "core-js/modules/es.string.match-all.js"; globalThis; foo.matchAll(bar); diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/string-at-proposals-corejs-3.8/options.json b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/string-at-proposals-corejs-3.8/options.json index 2df64af9..b02ac474 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/string-at-proposals-corejs-3.8/options.json +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/string-at-proposals-corejs-3.8/options.json @@ -4,7 +4,7 @@ "@@/polyfill-corejs3", { "method": "usage-global", - "version": 3.8, + "version": "3.8", "proposals": true } ] diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/typed-array-at-proposals-corejs-3.8/options.json b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/typed-array-at-proposals-corejs-3.8/options.json index 2df64af9..b02ac474 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/typed-array-at-proposals-corejs-3.8/options.json +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/typed-array-at-proposals-corejs-3.8/options.json @@ -4,7 +4,7 @@ "@@/polyfill-corejs3", { "method": "usage-global", - "version": 3.8, + "version": "3.8", "proposals": true } ] diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/typed-array-at-proposals-corejs-3.8/output.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/typed-array-at-proposals-corejs-3.8/output.mjs index bc26c7e4..8803be2d 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/typed-array-at-proposals-corejs-3.8/output.mjs +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-global/typed-array-at-proposals-corejs-3.8/output.mjs @@ -1,10 +1,10 @@ import "core-js/modules/esnext.array.at.js"; import "core-js/modules/esnext.string.at.js"; -import "core-js/modules/esnext.typed-array.at.js"; import "core-js/modules/es.array.iterator.js"; import "core-js/modules/es.array-buffer.slice.js"; import "core-js/modules/es.object.to-string.js"; import "core-js/modules/es.typed-array.int8-array.js"; +import "core-js/modules/esnext.typed-array.at.js"; import "core-js/modules/es.typed-array.copy-within.js"; import "core-js/modules/es.typed-array.every.js"; import "core-js/modules/es.typed-array.fill.js"; diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/all-proposals-chrome-90-corejs-3.16/input.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/all-proposals-chrome-90-corejs-3.16/input.mjs new file mode 100644 index 00000000..33a70615 --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/all-proposals-chrome-90-corejs-3.16/input.mjs @@ -0,0 +1,35 @@ +[].findLast(fn); +[].findLastIndex(fn); + +[].asIndexedPairs(); + +Iterator.from({ + next: () => ({ done: Math.random() > .9, value: Math.random() * 10 | 0 }) + }).forEach(console.log).toArray(); + +AsyncIterator.from([1, 2, 3, 4, 5, 6, 7]) + .drop(1) + .take(5) + .filter(it => it % 2) + .groupBy(it => id % 4) + .map(it => it ** 2) + .toArray() + .then(console.log); + +[1, 2, 3, 4, 5, 6, 7, 7].uniqueBy(x => x).groupBy(x => x % 2); + +Number.range(1, 2); +BigInt.range(1n, 2n); + +Array.isTemplateObject((x => x)`a${ x }z`) + +new Map([['x', 1]]).emplace('x', { update: x => x + 1, insert: () => 0}); + +/x/.dotAll; +/x/.sticky + +Symbol.asyncDispose +Symbol.matcher +Symbol.matchAll +Symbol.metadata +Symbol.replaceAll \ No newline at end of file diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/all-proposals-chrome-90-corejs-3.16/options.json b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/all-proposals-chrome-90-corejs-3.16/options.json new file mode 100644 index 00000000..fd988069 --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/all-proposals-chrome-90-corejs-3.16/options.json @@ -0,0 +1,15 @@ +{ + "targets": { + "chrome": 90 + }, + "plugins": [ + [ + "@@/polyfill-corejs3", + { + "method": "usage-pure", + "version": "3.16", + "proposals": true + } + ] + ] +} \ No newline at end of file diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/all-proposals-chrome-90-corejs-3.16/output.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/all-proposals-chrome-90-corejs-3.16/output.mjs new file mode 100644 index 00000000..9a2df8f8 --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/all-proposals-chrome-90-corejs-3.16/output.mjs @@ -0,0 +1,55 @@ +var _context, _context2, _context3, _context4, _context5, _context6, _context7, _context8, _context9, _context10, _context11; + +import _findLastInstanceProperty from "core-js-pure/features/instance/find-last.js"; +import _findLastIndexInstanceProperty from "core-js-pure/features/instance/find-last-index.js"; +import _asIndexedPairsInstanceProperty from "core-js-pure/features/instance/asIndexedPairs.js"; +import _toArrayInstanceProperty from "core-js-pure/features/instance/to-array.js"; +import _Iterator$from from "core-js-pure/features/iterator/from.js"; +import _groupByInstanceProperty from "core-js-pure/features/instance/group-by.js"; +import _takeInstanceProperty from "core-js-pure/features/instance/take.js"; +import _dropInstanceProperty from "core-js-pure/features/instance/drop.js"; +import _AsyncIterator$from from "core-js-pure/features/async-iterator/from.js"; +import _uniqueByInstanceProperty from "core-js-pure/features/instance/unique-by.js"; +import _Number$range from "core-js-pure/features/number/range.js"; +import _BigInt$range from "core-js-pure/features/bigint/range.js"; +import _Array$isTemplateObject from "core-js-pure/features/array/is-template-object.js"; +import _emplaceInstanceProperty from "core-js-pure/features/instance/emplace.js"; +import _Symbol$asyncDispose from "core-js-pure/features/symbol/async-dispose.js"; +import _Symbol$matcher from "core-js-pure/features/symbol/matcher.js"; +import _Symbol$metadata from "core-js-pure/features/symbol/metadata.js"; + +_findLastInstanceProperty(_context = []).call(_context, fn); + +_findLastIndexInstanceProperty(_context2 = []).call(_context2, fn); + +_asIndexedPairsInstanceProperty(_context3 = []).call(_context3); + +_toArrayInstanceProperty(_context4 = _Iterator$from({ + next: () => ({ + done: Math.random() > .9, + value: Math.random() * 10 | 0 + }) +}).forEach(console.log)).call(_context4); + +_toArrayInstanceProperty(_context5 = _groupByInstanceProperty(_context6 = _takeInstanceProperty(_context7 = _dropInstanceProperty(_context8 = _AsyncIterator$from([1, 2, 3, 4, 5, 6, 7])).call(_context8, 1)).call(_context7, 5).filter(it => it % 2)).call(_context6, it => id % 4).map(it => it ** 2)).call(_context5).then(console.log); + +_groupByInstanceProperty(_context9 = _uniqueByInstanceProperty(_context10 = [1, 2, 3, 4, 5, 6, 7, 7]).call(_context10, x => x)).call(_context9, x => x % 2); + +_Number$range(1, 2); + +_BigInt$range(1n, 2n); + +_Array$isTemplateObject((x => x)`a${x}z`); + +_emplaceInstanceProperty(_context11 = new Map([['x', 1]])).call(_context11, 'x', { + update: x => x + 1, + insert: () => 0 +}); + +/x/.dotAll; +/x/.sticky; +_Symbol$asyncDispose; +_Symbol$matcher; +Symbol.matchAll; +_Symbol$metadata; +Symbol.replaceAll; diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/object-hasown-version-3.11/output.mjs b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/object-hasown-version-3.11/output.mjs index f03dc36b..d4573623 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/object-hasown-version-3.11/output.mjs +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/object-hasown-version-3.11/output.mjs @@ -1 +1,2 @@ -Object.hasOwn; +import _Object$hasOwn from "core-js-pure/features/object/has-own.js"; +_Object$hasOwn; diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/proposal-to-stable-corejs-3.0-proposals/options.json b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/proposal-to-stable-corejs-3.0-proposals/options.json index fdcfdcd7..e18e63ea 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/proposal-to-stable-corejs-3.0-proposals/options.json +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/proposal-to-stable-corejs-3.0-proposals/options.json @@ -4,7 +4,7 @@ "@@/polyfill-corejs3", { "method": "usage-pure", - "version": 3.0, + "version": "3.0", "proposals": true } ] diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/proposal-to-stable-corejs-3.0/options.json b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/proposal-to-stable-corejs-3.0/options.json index 57275184..5a8e188b 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/proposal-to-stable-corejs-3.0/options.json +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/proposal-to-stable-corejs-3.0/options.json @@ -4,7 +4,7 @@ "@@/polyfill-corejs3", { "method": "usage-pure", - "version": 3.0 + "version": "3.0" } ] ] diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/proposal-to-stable-corejs-3.8-proposals/options.json b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/proposal-to-stable-corejs-3.8-proposals/options.json index c133e7a8..a0f686f7 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/proposal-to-stable-corejs-3.8-proposals/options.json +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/proposal-to-stable-corejs-3.8-proposals/options.json @@ -4,7 +4,7 @@ "@@/polyfill-corejs3", { "method": "usage-pure", - "version": 3.8, + "version": "3.8", "proposals": true } ] diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/proposal-to-stable-corejs-3.8/options.json b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/proposal-to-stable-corejs-3.8/options.json index 10e0c2c3..66e8d411 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/proposal-to-stable-corejs-3.8/options.json +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/proposal-to-stable-corejs-3.8/options.json @@ -4,7 +4,7 @@ "@@/polyfill-corejs3", { "method": "usage-pure", - "version": 3.8 + "version": "3.8" } ] ] diff --git a/scripts/build-corejs3-shipped-proposals.mjs b/scripts/build-corejs3-shipped-proposals.mjs new file mode 100644 index 00000000..b1d4076c --- /dev/null +++ b/scripts/build-corejs3-shipped-proposals.mjs @@ -0,0 +1,26 @@ +import compatData from "../packages/babel-plugin-polyfill-corejs3/core-js-compat/data.js"; +import fs from "node:fs"; + +const path = new URL( + "../packages/babel-plugin-polyfill-corejs3/src/shipped-proposals.js", + import.meta.url +); + +const template = features => `// @flow +// This file is automatically generated by scripts/build-corejs3-shipped-proposals.js + +export default new Set([ +${features.map(f => ` "${f}",\n`).join("")}]); +`; + +const shippedProposals = []; + +for (const feature in compatData) { + if (!feature.startsWith("esnext.")) continue; + const esName = "es." + feature.slice(7); + if (esName in compatData) continue; + if (Object.keys(compatData[feature]).length === 0) continue; + shippedProposals.push(feature); +} + +fs.writeFileSync(path, template(shippedProposals)); diff --git a/yarn.lock b/yarn.lock index 420245e0..1e712b35 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3818,7 +3818,7 @@ __metadata: "@babel/plugin-transform-for-of": ^7.10.4 "@babel/plugin-transform-modules-commonjs": ^7.10.4 "@babel/plugin-transform-spread": ^7.13.0 - core-js-compat: ^3.16.2 + core-js-compat: ^3.18.0 core-js-pure: ^3.8.1 peerDependencies: "@babel/core": ^7.0.0-0 @@ -4163,18 +4163,18 @@ __metadata: languageName: node linkType: hard -"browserslist@npm:^4.14.5, browserslist@npm:^4.16.7": - version: 4.16.8 - resolution: "browserslist@npm:4.16.8" +"browserslist@npm:^4.14.5, browserslist@npm:^4.17.0": + version: 4.17.0 + resolution: "browserslist@npm:4.17.0" dependencies: - caniuse-lite: ^1.0.30001251 + caniuse-lite: ^1.0.30001254 colorette: ^1.3.0 - electron-to-chromium: ^1.3.811 + electron-to-chromium: ^1.3.830 escalade: ^3.1.1 node-releases: ^1.1.75 bin: browserslist: cli.js - checksum: bf638feeb7af598a807ac4a70fe64af884b799e015f52894ac2df42cefbc818a08548f8a48c29a60699c049272bf70aaa7415551c6a8ac45767b7c289d9f5bf2 + checksum: e7c4b78520f1e6f547112891d4a2298fa2d9bcba0156fd62b8229d654cd7a6c72db74254d774a55cacf604fbee0966189ac6fb1ce71e8c1a24bb5ce1c2ed9644 languageName: node linkType: hard @@ -4389,10 +4389,10 @@ __metadata: languageName: node linkType: hard -"caniuse-lite@npm:^1.0.30001251": - version: 1.0.30001251 - resolution: "caniuse-lite@npm:1.0.30001251" - checksum: 6d7d4b93bdaa4d7859b830c5afdfa40ef2cc15a88edfae446c6ded1ae77ae4de50b5b5ba63c4a56ecdde5a530f26252ef56b86abbe7aa0dda5de8f1d793a454e +"caniuse-lite@npm:^1.0.30001254": + version: 1.0.30001258 + resolution: "caniuse-lite@npm:1.0.30001258" + checksum: ef97b5eb31cf99b4a8e895da133c918d4dc606acf55dec6d9bbde4f94e9b2b18bcfc3b105c2d59c68ea0f51dd11fd83ef7b42cb28489c48f486cc49b4dcb7bfb languageName: node linkType: hard @@ -4996,13 +4996,13 @@ __metadata: languageName: node linkType: hard -"core-js-compat@npm:^3.16.2, core-js-compat@npm:^3.8.1, core-js-compat@npm:^3.9.0": - version: 3.16.2 - resolution: "core-js-compat@npm:3.16.2" +"core-js-compat@npm:^3.18.0, core-js-compat@npm:^3.8.1, core-js-compat@npm:^3.9.0": + version: 3.18.0 + resolution: "core-js-compat@npm:3.18.0" dependencies: - browserslist: ^4.16.7 + browserslist: ^4.17.0 semver: 7.0.0 - checksum: 2ab3f6a7973a9b2037c97e11ad6eff1b749902426acc167c132936d13816c436e8d84396ec074c0aa6ff00a2390bde6f7fb187210b760bdb75820cb02c8f29e0 + checksum: a0c75f8e235a1b9d5100013e1f6707159c6b460f14c998f02b4c46d6c2e4c02fbe451d432695f6b73c760a39500d5ecc85c52ff946b488f6f395c3461db0954f languageName: node linkType: hard @@ -5533,10 +5533,10 @@ __metadata: languageName: node linkType: hard -"electron-to-chromium@npm:^1.3.683, electron-to-chromium@npm:^1.3.811": - version: 1.3.816 - resolution: "electron-to-chromium@npm:1.3.816" - checksum: 40037d6f47dd12512db9241680f84e5532dadf6b27a10b9959814d9d00a1ea55a81ac30623ba424ea88259ddc5a168dd0e055a480f76fe174b63225febccd569 +"electron-to-chromium@npm:^1.3.683, electron-to-chromium@npm:^1.3.830": + version: 1.3.843 + resolution: "electron-to-chromium@npm:1.3.843" + checksum: 0233a98b245add127bc7d7aaefab88d83a1d1312d9eee47841138af6acab1a51bb39e3f12bd864ef2d5b2fa00fd42a77ae1a001e44cbfde277a275f525221e00 languageName: node linkType: hard