Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
noInterop,
lazy,
esNamespaceOnly:
typeof state.filename === "string" &&
/\.mjs$/.test(state.filename)
? mjsStrictNamespace
: strictNamespace,
},
);
// 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,
noInterop,
});
for (const [source, metadata] of meta.source) {
const loadExpr = t.callExpression(t.identifier("require"), [
t.stringLiteral(source),
]);
let header;
if (isSideEffectImport(metadata)) {
header = t.expressionStatement(loadExpr);
exit(path) {
if (!isModule(path)) return;
let moduleName = this.getModuleName();
if (moduleName) moduleName = t.stringLiteral(moduleName);
const {
meta,
headers,
} = rewriteModuleStatementsAndPrepareHeader(path, {
loose,
strict,
strictMode,
allowTopLevelThis,
noInterop,
});
const amdArgs = [];
const importNames = [];
if (hasExports(meta)) {
amdArgs.push(t.stringLiteral("exports"));
importNames.push(t.identifier(meta.exportName));
}
exit(path) {
if (!isModule(path)) return;
const browserGlobals = globals || {};
let moduleName = this.getModuleName();
if (moduleName) moduleName = t.stringLiteral(moduleName);
const {
meta,
headers,
} = rewriteModuleStatementsAndPrepareHeader(path, {
loose,
strict,
strictMode,
allowTopLevelThis,
noInterop,
});
const amdArgs = [];
const commonjsArgs = [];
const browserArgs = [];
const importNames = [];
if (hasExports(meta)) {
amdArgs.push(t.stringLiteral("exports"));
commonjsArgs.push(t.identifier("exports"));
browserArgs.push(
exit(path) {
if (!isModule(path)) return;
const browserGlobals = globals || {};
let moduleName = this.getModuleName();
if (moduleName) moduleName = t.stringLiteral(moduleName);
const { meta, headers } = rewriteModuleStatementsAndPrepareHeader(
path,
{
loose,
strict,
strictMode,
allowTopLevelThis,
noInterop,
},
);
const amdArgs = [];
const commonjsArgs = [];
const browserArgs = [];
const importNames = [];
if (hasExports(meta)) {
);
}
return;
}
const amdArgs = [];
const importNames = [];
if (requireId) {
amdArgs.push(t.stringLiteral("require"));
importNames.push(requireId);
}
let moduleName = this.getModuleName();
if (moduleName) moduleName = t.stringLiteral(moduleName);
const { meta, headers } = rewriteModuleStatementsAndPrepareHeader(
path,
{
loose,
strict,
strictMode,
allowTopLevelThis,
noInterop,
},
);
if (hasExports(meta)) {
amdArgs.push(t.stringLiteral("exports"));
importNames.push(t.identifier(meta.exportName));
}