Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exit(path, state) {
if (!isModule(path)) return;
// Rename the bindings auto-injected into the scope so there is no
// risk of conflict between the bindings.
path.scope.rename("exports");
path.scope.rename("module");
path.scope.rename("require");
path.scope.rename("__filename");
path.scope.rename("__dirname");
// Rewrite references to 'module' and 'exports' to throw exceptions.
// These objects are specific to CommonJS and are not available in
// real ES6 implementations.
if (!allowCommonJSExports) {
simplifyAccess(path, new Set(["module", "exports"]));
path.traverse(moduleExportsVisitor, {
scope: path.scope,
});
}
let moduleName = this.getModuleName();
if (moduleName) moduleName = t.stringLiteral(moduleName);
const { meta, headers } = rewriteModuleStatementsAndPrepareHeader(
path,
{
exportName: "exports",
loose,
strict,
strictMode,
allowTopLevelThis,
// because Babel currently parses all files as sourceType:module.
if (!isModule(path, true /* requireUnambiguous */)) return;
// Rename the bindings auto-injected into the scope so there is no
// risk of conflict between the bindings.
path.scope.rename("exports");
path.scope.rename("module");
path.scope.rename("require");
path.scope.rename("__filename");
path.scope.rename("__dirname");
// Rewrite references to 'module' and 'exports' to throw exceptions.
// These objects are specific to CommonJS and are not available in
// real ES6 implementations.
if (!allowCommonJSExports) {
simplifyAccess(path, new Set(["module", "exports"]));
path.traverse(moduleExportsVisitor, {
scope: path.scope,
});
}
let moduleName = this.getModuleName();
if (moduleName) moduleName = t.stringLiteral(moduleName);
const {
meta,
headers,
} = rewriteModuleStatementsAndPrepareHeader(path, {
exportName: "exports",
loose,
strict,
strictMode,
exportMeta = [];
exported.set(local, exportMeta);
}
exportMeta.push(...data.names);
}
// Rewrite initialization of bindings to update exports.
programPath.traverse(rewriteBindingInitVisitor, {
metadata,
requeueInParent,
scope: programPath.scope,
exported, // local name => exported name list
});
simplifyAccess(
programPath,
// NOTE(logan): The 'Array.from' calls are to make this code with in loose mode.
new Set([...Array.from(imported.keys()), ...Array.from(exported.keys())]),
);
// Rewrite reads/writes from imports and exports to have the correct behavior.
programPath.traverse(rewriteReferencesVisitor, {
seen: new WeakSet(),
metadata,
requeueInParent,
scope: programPath.scope,
imported, // local / import
exported, // local name => exported name list
buildImportReference: ([source, importName, localName], identNode) => {
const meta = metadata.source.get(source);