Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (node: ts.SourceFile) => {
for (let i = node.statements.length - 1; i >= 0; i--) {
const stmt = node.statements[i];
if (ts.isExportDeclaration(stmt)) {
continue;
}
if (!ts.isExpressionStatement(stmt)) {
break;
}
const lastName = createLastExprVar();
let statements = node.statements.slice(0, i);
statements.push(
ts.createVariableStatement(
[ts.createModifier(ts.SyntaxKind.ExportKeyword)],
ts.createVariableDeclarationList(
[
ts.createVariableDeclaration(
lastName,
undefined,
stmt.expression
return (node: ts.SourceFile) => {
const statements = [];
for (const stmt of node.statements) {
if (ts.isExportDeclaration(stmt)) {
continue;
}
statements.push(stmt);
}
node.statements = ts.createNodeArray(statements);
return node;
};
}