Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ast.program.body = ast.program.body.filter((i: any) => {
// export function a() {}
// export interface Bang {}
// export type Foo = string | number;
if (
i.type === AST_NODE_TYPES.ExportNamedDeclaration &&
(i.declaration.type === AST_NODE_TYPES.TSTypeAliasDeclaration ||
i.declaration.type === AST_NODE_TYPES.FunctionDeclaration ||
i.declaration.type === AST_NODE_TYPES.TSInterfaceDeclaration)
) {
return allowed.includes(i.declaration.id.name);
}
// export const manager = {};
// export const {f,g: h} = {f: 4, g:5};
if (
i.type === AST_NODE_TYPES.ExportNamedDeclaration &&
i.declaration.type === AST_NODE_TYPES.VariableDeclaration
) {
// MUTATION!
// eslint-disable-next-line no-param-reassign
i.declaration.declarations = i.declaration.declarations.filter((d: any) => {
if (d.id.type === AST_NODE_TYPES.ObjectPattern) {
// MUTATION!
// eslint-disable-next-line no-param-reassign
str += this.codeFromTSDeclareFunction(ast);
break;
case AST_NODE_TYPES.TSEnumDeclaration:
str += this.codeFromTSEnumDeclaration(ast);
break;
case AST_NODE_TYPES.TSModuleBlock:
str += this.codeFromTSModuleBlock(ast);
break;
case AST_NODE_TYPES.TSModuleDeclaration:
str += this.codeFromTSModuleDeclaration(ast);
break;
case AST_NODE_TYPES.TSInterfaceDeclaration:
str += this.codeFromTSInterfaceDeclaration(ast);
break;
case AST_NODE_TYPES.TSTypeAssertion:
str += this.codeFromTSTypeAssertion(ast);
break;
default:
console.log(util.inspect(ast, true, 3));
throw new Error('unrecornized type: ' + ast.type);
break;
}
return str;
}