Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function(
_: any,
{ corejs, include, exclude, polyfillTargets, debug }: InternalPluginOptions,
) {
const polyfills = filterItems(
corejs3Polyfills,
include,
exclude,
polyfillTargets,
null,
);
const available = new Set(getModulesListForTargetVersion(corejs.version));
function shouldReplace(source, modules) {
if (!modules) return false;
if (
// Don't replace an import with itself to avoid an infinite loop
modules.length === 1 &&
polyfills.has(modules[0]) &&
available.has(modules[0]) &&
getModulePath(modules[0]) === source
) {
return false;
}
return true;
}
const isPolyfillImport = {
debug,
}: InternalPluginOptions,
) {
const polyfills = filterItems(
proposals
? corejs3Polyfills
: shippedProposals
? corejs3PolyfillsWithShippedProposals
: corejs3PolyfillsWithoutProposals,
include,
exclude,
polyfillTargets,
null,
);
const available = new Set(getModulesListForTargetVersion(corejs.version));
function resolveKey(path, computed) {
const { node, parent, scope } = path;
if (path.isStringLiteral()) return node.value;
const { name } = node;
const isIdentifier = path.isIdentifier();
if (isIdentifier && !(computed || parent.computed)) return name;
if (!isIdentifier || scope.getBindingIdentifier(name)) {
const { value } = path.evaluate();
if (typeof value === "string") return value;
}
}
function resolveSource(path) {
const { node, scope } = path;
let builtIn, instanceType;
const set = new Set();
function filter(method, list) {
for (const ns of list) {
for (const name of modulesList) {
if (name === ns || name.startsWith(`${ ns }.`)) {
set[method](name);
}
}
}
}
filter('add', modules);
filter('delete', blacklist);
modules = modulesList.filter(it => set.has(it));
if (targets) modules = compat({ targets, filter: modules }).list;
const tempFileName = `core-js-${ Math.random().toString(36).slice(2) }.js`;
const tempFile = join(tmpdir, tempFileName);
await webpack({
mode: 'none',
node: {
global: false,
process: false,
setImmediate: false,
},
entry: modules.map(it => require.resolve(`core-js/modules/${ it }`)),
output: {
path: tmpdir,
module.exports = async function ({ blacklist = [], modules = modulesList.slice(), targets, filename } = {}) {
const set = new Set();
function filter(method, list) {
for (const ns of list) {
for (const name of modulesList) {
if (name === ns || name.startsWith(`${ ns }.`)) {
set[method](name);
}
}
}
}
filter('add', modules);
filter('delete', blacklist);
modules = modulesList.filter(it => set.has(it));