Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
} else {
header = t.variableDeclaration("var", [
t.variableDeclarator(
t.identifier(metadata.name),
wrapInterop(path, loadExpr, metadata.interop) || loadExpr,
),
]);
}
header.loc = metadata.loc;
headers.push(header);
headers.push(...buildNamespaceInitStatements(meta, metadata));
}
ensureStatementsHoisted(headers);
path.unshiftContainer("body", headers);
},
},
const amdArgs = [];
const importNames = [];
if (hasExports(meta)) {
amdArgs.push(t.stringLiteral("exports"));
importNames.push(t.identifier(meta.exportName));
}
for (const [source, metadata] of meta.source) {
amdArgs.push(t.stringLiteral(source));
importNames.push(t.identifier(metadata.name));
if (!isSideEffectImport(metadata)) {
const interop = wrapInterop(
path,
t.identifier(metadata.name),
metadata.interop,
);
if (interop) {
const header = t.expressionStatement(
t.assignmentExpression(
"=",
t.identifier(metadata.name),
interop,
),
);
header.loc = metadata.loc;
headers.push(header);
}
}
},
);
for (const [source, metadata] of meta.source) {
const loadExpr = t.callExpression(t.identifier("require"), [
t.stringLiteral(source),
]);
let header;
if (isSideEffectImport(metadata)) {
if (metadata.lazy) throw new Error("Assertion failure");
header = t.expressionStatement(loadExpr);
} else {
const init =
wrapInterop(path, loadExpr, metadata.interop) || loadExpr;
if (metadata.lazy) {
header = template.ast`
function ${metadata.name}() {
const data = ${init};
${metadata.name} = function(){ return data; };
return data;
}
`;
} else {
header = template.ast`
var ${metadata.name} = ${init};
`;
}
}
header.loc = metadata.loc;
noInterop,
},
);
if (hasExports(meta)) {
amdArgs.push(t.stringLiteral("exports"));
importNames.push(t.identifier(meta.exportName));
}
for (const [source, metadata] of meta.source) {
amdArgs.push(t.stringLiteral(source));
importNames.push(t.identifier(metadata.name));
if (!isSideEffectImport(metadata)) {
const interop = wrapInterop(
path,
t.identifier(metadata.name),
metadata.interop,
);
if (interop) {
const header = t.expressionStatement(
t.assignmentExpression(
"=",
t.identifier(metadata.name),
interop,
),
);
header.loc = metadata.loc;
headers.push(header);
}
}
if (!path.get("callee").isImport()) return;
let { requireId, resolveId, rejectId } = state;
if (!requireId) {
requireId = path.scope.generateUidIdentifier("require");
state.requireId = requireId;
}
if (!resolveId || !rejectId) {
resolveId = path.scope.generateUidIdentifier("resolve");
rejectId = path.scope.generateUidIdentifier("reject");
state.resolveId = resolveId;
state.rejectId = rejectId;
}
let result = t.identifier("imported");
if (!noInterop) result = wrapInterop(path, result, "namespace");
path.replaceWith(
template.expression.ast`
new Promise((${resolveId}, ${rejectId}) =>
${requireId}(
[${getImportSource(t, path.node)}],
imported => ${resolveId}(${result}),
${rejectId}
)
)`,
);
},
}
for (const [source, metadata] of meta.source) {
amdArgs.push(t.stringLiteral(source));
commonjsArgs.push(
t.callExpression(t.identifier("require"), [
t.stringLiteral(source),
]),
);
browserArgs.push(
buildBrowserArg(browserGlobals, exactGlobals, source),
);
importNames.push(t.identifier(metadata.name));
if (!isSideEffectImport(metadata)) {
const interop = wrapInterop(
path,
t.identifier(metadata.name),
metadata.interop,
);
if (interop) {
const header = t.expressionStatement(
t.assignmentExpression(
"=",
t.identifier(metadata.name),
interop,
),
);
header.loc = meta.loc;
headers.push(header);
}
}
}
for (const [source, metadata] of meta.source) {
amdArgs.push(t.stringLiteral(source));
commonjsArgs.push(
t.callExpression(t.identifier("require"), [
t.stringLiteral(source),
]),
);
browserArgs.push(
buildBrowserArg(browserGlobals, exactGlobals, source),
);
importNames.push(t.identifier(metadata.name));
if (!isSideEffectImport(metadata)) {
const interop = wrapInterop(
path,
t.identifier(metadata.name),
metadata.interop,
);
if (interop) {
const header = t.expressionStatement(
t.assignmentExpression(
"=",
t.identifier(metadata.name),
interop,
),
);
header.loc = meta.loc;
headers.push(header);
}
}