You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					71 lines
				
				2.2 KiB
			
		
		
			
		
	
	
					71 lines
				
				2.2 KiB
			| 
								 
											3 years ago
										 
									 | 
							
								"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");
							 | 
						||
| 
								 | 
							
								              `);
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								          }
							 | 
						||
| 
								 | 
							
								        });
							 | 
						||
| 
								 | 
							
								      }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								  };
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//# sourceMappingURL=babel-polyfill.js.map
							 |