| 1 | const pluginCorejs2 = require("babel-plugin-polyfill-corejs2").default;
|
|---|
| 2 | const pluginCorejs3 = require("babel-plugin-polyfill-corejs3").default;
|
|---|
| 3 | const pluginRegenerator = require("babel-plugin-polyfill-regenerator").default;
|
|---|
| 4 | const pluginsCompat = "#__secret_key__@babel/runtime__compatibility";
|
|---|
| 5 | function createCorejs2Plugin(options) {
|
|---|
| 6 | return (api, _, filename) => pluginCorejs2(api, options, filename);
|
|---|
| 7 | }
|
|---|
| 8 | function createCorejs3Plugin(options) {
|
|---|
| 9 | return (api, _, filename) => pluginCorejs3(api, options, filename);
|
|---|
| 10 | }
|
|---|
| 11 | function createRegeneratorPlugin(options, useRuntimeRegenerator, corejsPlugin) {
|
|---|
| 12 | if (!useRuntimeRegenerator) return corejsPlugin != null ? corejsPlugin : undefined;
|
|---|
| 13 | return (api, _, filename) => {
|
|---|
| 14 | return Object.assign({}, pluginRegenerator(api, options, filename), {
|
|---|
| 15 | inherits: corejsPlugin != null ? corejsPlugin : undefined
|
|---|
| 16 | });
|
|---|
| 17 | };
|
|---|
| 18 | }
|
|---|
| 19 | module.exports = function createBasePolyfillsPlugin({
|
|---|
| 20 | corejs,
|
|---|
| 21 | regenerator = true,
|
|---|
| 22 | moduleName
|
|---|
| 23 | }, runtimeVersion, absoluteImports) {
|
|---|
| 24 | let proposals = false;
|
|---|
| 25 | let rawVersion;
|
|---|
| 26 | if (typeof corejs === "object" && corejs !== null) {
|
|---|
| 27 | rawVersion = corejs.version;
|
|---|
| 28 | proposals = Boolean(corejs.proposals);
|
|---|
| 29 | } else {
|
|---|
| 30 | rawVersion = corejs;
|
|---|
| 31 | }
|
|---|
| 32 | const corejsVersion = rawVersion ? Number(rawVersion) : false;
|
|---|
| 33 | if (![false, 2, 3].includes(corejsVersion)) {
|
|---|
| 34 | throw new Error(`The \`core-js\` version must be false, 2 or 3, but got ${JSON.stringify(rawVersion)}.`);
|
|---|
| 35 | }
|
|---|
| 36 | if (proposals && (!corejsVersion || corejsVersion < 3)) {
|
|---|
| 37 | throw new Error("The 'proposals' option is only supported when using 'corejs: 3'");
|
|---|
| 38 | }
|
|---|
| 39 | if (typeof regenerator !== "boolean") {
|
|---|
| 40 | throw new Error("The 'regenerator' option must be undefined, or a boolean.");
|
|---|
| 41 | }
|
|---|
| 42 | const polyfillOpts = {
|
|---|
| 43 | method: "usage-pure",
|
|---|
| 44 | absoluteImports,
|
|---|
| 45 | proposals,
|
|---|
| 46 | [pluginsCompat]: {
|
|---|
| 47 | useBabelRuntime: true,
|
|---|
| 48 | runtimeVersion,
|
|---|
| 49 | ext: "",
|
|---|
| 50 | moduleName
|
|---|
| 51 | }
|
|---|
| 52 | };
|
|---|
| 53 | return createRegeneratorPlugin(polyfillOpts, regenerator, corejsVersion === 2 ? createCorejs2Plugin(polyfillOpts) : corejsVersion === 3 ? createCorejs3Plugin(polyfillOpts) : null);
|
|---|
| 54 | };
|
|---|
| 55 |
|
|---|
| 56 | //# sourceMappingURL=polyfills.cjs.map
|
|---|