Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sourceMap,
allowDynamicRequire,
astCache
) {
const ast = astCache || tryParse(parse, code, id);
const magicString = new MagicString(code);
const required = {};
// Because objects have no guaranteed ordering, yet we need it,
// we need to keep track of the order in a array
const sources = [];
let uid = 0;
let scope = attachScopes(ast, 'scope');
const uses = { module: false, exports: false, global: false, require: false };
let lexicalDepth = 0;
let programDepth = 0;
const globals = new Set();
// TODO technically wrong since globals isn't populated yet, but ¯\_(ツ)_/¯
const HELPERS_NAME = deconflict(scope, globals, 'commonjsHelpers');
const namedExports = {};
// TODO handle transpiled modules
let shouldWrap = /__esModule/.test(code);
function isRequireStatement(node) {
}
if (!ast) {
return null;
}
const imports = new Set();
ast.body.forEach((node) => {
if (node.type === 'ImportDeclaration') {
node.specifiers.forEach((specifier) => {
imports.add(specifier.local.name);
});
}
});
// analyse scopes
let scope = attachScopes(ast, 'scope');
const magicString = new MagicString(code);
const newImports = new Map();
function handleReference(node, name, keypath) {
let mod = modulesMap.get(keypath);
if (mod && !imports.has(name) && !scope.contains(name)) {
if (typeof mod === 'string') mod = [mod, 'default'];
// prevent module from importing itself
if (mod[0] === id) return false;
const hash = `${keypath}:${mod[0]}:${mod[1]}`;
const importLocalName =