summaryrefslogtreecommitdiff
path: root/node_modules/@babel/preset-env/lib/polyfills/babel-polyfill.js
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-10-14 15:31:11 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-10-14 15:31:11 +0800
commitaa773172311dcada759dfbaac485f4bc6e00bc21 (patch)
treeca6d9a5eff3ab8f689f9acb4f0df791d9486813d /node_modules/@babel/preset-env/lib/polyfills/babel-polyfill.js
parentc5a5384e846f242e901e859fe600d695d8990a9a (diff)
added babel
Diffstat (limited to 'node_modules/@babel/preset-env/lib/polyfills/babel-polyfill.js')
-rw-r--r--node_modules/@babel/preset-env/lib/polyfills/babel-polyfill.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/node_modules/@babel/preset-env/lib/polyfills/babel-polyfill.js b/node_modules/@babel/preset-env/lib/polyfills/babel-polyfill.js
new file mode 100644
index 00000000..bc9f0082
--- /dev/null
+++ b/node_modules/@babel/preset-env/lib/polyfills/babel-polyfill.js
@@ -0,0 +1,70 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.default = _default;
+var _utils = require("./utils.js");
+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");
+ `);
+ }
+ }
+ });
+ }
+ }
+ };
+}
+
+//# sourceMappingURL=babel-polyfill.js.map