Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the
babel-plugin-polyfill-*
packages in preset-env
- Loading branch information
1 parent
fbef603
commit 526ed65
Showing
184 changed files
with
3,001 additions
and
3,593 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// @flow | ||
|
||
import { getImportSource, getRequireSource, isPolyfillSource } from "./utils"; | ||
|
||
import type { NodePath } from "@babel/traverse"; | ||
|
||
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.`; | ||
|
||
export default function ({ template }, { regenerator, deprecated, usage }) { | ||
return { | ||
name: "preset-env/replace-babel-polyfill", | ||
visitor: { | ||
ImportDeclaration(path: NodePath) { | ||
const src = getImportSource(path); | ||
if (usage && 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: NodePath) { | ||
path.get("body").forEach(bodyPath => { | ||
const src = getRequireSource(bodyPath); | ||
if (usage && 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"); | ||
`); | ||
} | ||
} | ||
}); | ||
}, | ||
}, | ||
}; | ||
} |
190 changes: 0 additions & 190 deletions
190
packages/babel-preset-env/src/polyfills/corejs2/built-in-definitions.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.