$
This commit is contained in:
75
node_modules/@babel/preset-env/lib/polyfills/babel-polyfill.js
generated
vendored
Normal file
75
node_modules/@babel/preset-env/lib/polyfills/babel-polyfill.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = _default;
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
const BABEL_POLYFILL_DEPRECATION = `
|
||||
\`@babel/polyfill\` is deprecated. Please, use required parts of \`core-js\`
|
||||
and \`regenerator-runtime/runtime\` separately`;
|
||||
const NO_DIRECT_POLYFILL_IMPORT = `
|
||||
When setting \`useBuiltIns: 'usage'\`, polyfills are automatically imported when needed.
|
||||
Please remove the direct import of \`SPECIFIER\` or use \`useBuiltIns: 'entry'\` instead.`;
|
||||
|
||||
function _default({
|
||||
template
|
||||
}, {
|
||||
regenerator,
|
||||
deprecated,
|
||||
usage
|
||||
}) {
|
||||
return {
|
||||
name: "preset-env/replace-babel-polyfill",
|
||||
visitor: {
|
||||
ImportDeclaration(path) {
|
||||
const src = (0, _utils.getImportSource)(path);
|
||||
|
||||
if (usage && (0, _utils.isPolyfillSource)(src)) {
|
||||
console.warn(NO_DIRECT_POLYFILL_IMPORT.replace("SPECIFIER", src));
|
||||
if (!deprecated) path.remove();
|
||||
} else if (src === "@babel/polyfill") {
|
||||
if (deprecated) {
|
||||
console.warn(BABEL_POLYFILL_DEPRECATION);
|
||||
} else if (regenerator) {
|
||||
path.replaceWithMultiple(template.ast`
|
||||
import "core-js";
|
||||
import "regenerator-runtime/runtime.js";
|
||||
`);
|
||||
} else {
|
||||
path.replaceWith(template.ast`
|
||||
import "core-js";
|
||||
`);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Program(path) {
|
||||
path.get("body").forEach(bodyPath => {
|
||||
const src = (0, _utils.getRequireSource)(bodyPath);
|
||||
|
||||
if (usage && (0, _utils.isPolyfillSource)(src)) {
|
||||
console.warn(NO_DIRECT_POLYFILL_IMPORT.replace("SPECIFIER", src));
|
||||
if (!deprecated) bodyPath.remove();
|
||||
} else if (src === "@babel/polyfill") {
|
||||
if (deprecated) {
|
||||
console.warn(BABEL_POLYFILL_DEPRECATION);
|
||||
} else if (regenerator) {
|
||||
bodyPath.replaceWithMultiple(template.ast`
|
||||
require("core-js");
|
||||
require("regenerator-runtime/runtime.js");
|
||||
`);
|
||||
} else {
|
||||
bodyPath.replaceWith(template.ast`
|
||||
require("core-js");
|
||||
`);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
54
node_modules/@babel/preset-env/lib/polyfills/regenerator.js
generated
vendored
Normal file
54
node_modules/@babel/preset-env/lib/polyfills/regenerator.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = _default;
|
||||
|
||||
var _utils = require("./utils");
|
||||
|
||||
function isRegeneratorSource(source) {
|
||||
return source === "regenerator-runtime/runtime" || source === "regenerator-runtime/runtime.js";
|
||||
}
|
||||
|
||||
function _default() {
|
||||
const visitor = {
|
||||
ImportDeclaration(path) {
|
||||
if (isRegeneratorSource((0, _utils.getImportSource)(path))) {
|
||||
this.regeneratorImportExcluded = true;
|
||||
path.remove();
|
||||
}
|
||||
},
|
||||
|
||||
Program(path) {
|
||||
path.get("body").forEach(bodyPath => {
|
||||
if (isRegeneratorSource((0, _utils.getRequireSource)(bodyPath))) {
|
||||
this.regeneratorImportExcluded = true;
|
||||
bodyPath.remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
return {
|
||||
name: "preset-env/remove-regenerator",
|
||||
visitor,
|
||||
|
||||
pre() {
|
||||
this.regeneratorImportExcluded = false;
|
||||
},
|
||||
|
||||
post() {
|
||||
if (this.opts.debug && this.regeneratorImportExcluded) {
|
||||
let filename = this.file.opts.filename;
|
||||
|
||||
if (process.env.BABEL_ENV === "test") {
|
||||
filename = filename.replace(/\\/g, "/");
|
||||
}
|
||||
|
||||
console.log(`\n[${filename}] Based on your targets, regenerator-runtime import excluded.`);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
40
node_modules/@babel/preset-env/lib/polyfills/utils.js
generated
vendored
Normal file
40
node_modules/@babel/preset-env/lib/polyfills/utils.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.getImportSource = getImportSource;
|
||||
exports.getRequireSource = getRequireSource;
|
||||
exports.isPolyfillSource = isPolyfillSource;
|
||||
|
||||
var _t = require("@babel/types");
|
||||
|
||||
const {
|
||||
isCallExpression,
|
||||
isExpressionStatement,
|
||||
isIdentifier,
|
||||
isStringLiteral
|
||||
} = _t;
|
||||
|
||||
function getImportSource({
|
||||
node
|
||||
}) {
|
||||
if (node.specifiers.length === 0) return node.source.value;
|
||||
}
|
||||
|
||||
function getRequireSource({
|
||||
node
|
||||
}) {
|
||||
if (!isExpressionStatement(node)) return;
|
||||
const {
|
||||
expression
|
||||
} = node;
|
||||
|
||||
if (isCallExpression(expression) && isIdentifier(expression.callee) && expression.callee.name === "require" && expression.arguments.length === 1 && isStringLiteral(expression.arguments[0])) {
|
||||
return expression.arguments[0].value;
|
||||
}
|
||||
}
|
||||
|
||||
function isPolyfillSource(source) {
|
||||
return source === "@babel/polyfill" || source === "core-js";
|
||||
}
|
Reference in New Issue
Block a user