source: imaps-frontend/node_modules/@babel/preset-env/lib/polyfills/babel-polyfill.cjs@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.2 KB
Line 
1;
2const {
3 getImportSource,
4 getRequireSource,
5 isPolyfillSource
6} = require("./utils.cjs");
7const BABEL_POLYFILL_DEPRECATION = `
8 \`@babel/polyfill\` is deprecated. Please, use required parts of \`core-js\`
9 and \`regenerator-runtime/runtime\` separately`;
10const NO_DIRECT_POLYFILL_IMPORT = `
11 When setting \`useBuiltIns: 'usage'\`, polyfills are automatically imported when needed.
12 Please remove the direct import of \`SPECIFIER\` or use \`useBuiltIns: 'entry'\` instead.`;
13module.exports = function ({
14 template
15}, {
16 regenerator,
17 deprecated,
18 usage
19}) {
20 return {
21 name: "preset-env/replace-babel-polyfill",
22 visitor: {
23 ImportDeclaration(path) {
24 const src = getImportSource(path);
25 if (usage && isPolyfillSource(src)) {
26 console.warn(NO_DIRECT_POLYFILL_IMPORT.replace("SPECIFIER", src));
27 if (!deprecated) path.remove();
28 } else if (src === "@babel/polyfill") {
29 if (deprecated) {
30 console.warn(BABEL_POLYFILL_DEPRECATION);
31 } else if (regenerator) {
32 path.replaceWithMultiple(template.ast`
33 import "core-js";
34 import "regenerator-runtime/runtime.js";
35 `);
36 } else {
37 path.replaceWith(template.ast`
38 import "core-js";
39 `);
40 }
41 }
42 },
43 Program(path) {
44 path.get("body").forEach(bodyPath => {
45 const src = getRequireSource(bodyPath);
46 if (usage && isPolyfillSource(src)) {
47 console.warn(NO_DIRECT_POLYFILL_IMPORT.replace("SPECIFIER", src));
48 if (!deprecated) bodyPath.remove();
49 } else if (src === "@babel/polyfill") {
50 if (deprecated) {
51 console.warn(BABEL_POLYFILL_DEPRECATION);
52 } else if (regenerator) {
53 bodyPath.replaceWithMultiple(template.ast`
54 require("core-js");
55 require("regenerator-runtime/runtime.js");
56 `);
57 } else {
58 bodyPath.replaceWith(template.ast`
59 require("core-js");
60 `);
61 }
62 }
63 });
64 }
65 }
66 };
67};
68
69//# sourceMappingURL=babel-polyfill.cjs.map
Note: See TracBrowser for help on using the repository browser.