Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return;
}
decls.push(decl);
});
stmt.declarationList.declarations = ts.createNodeArray(decls);
}
if (ts.isImportDeclaration(stmt)) {
keepNamesInImport(stmt, names);
}
// Do nothing for
// - TypeAliasDeclaration (No multiple specs)
// - FunctionDeclaration (ditto)
// - InterfaceDeclaration (ditto)
});
declsSF.statements = ts.createNodeArray(statements);
let printer = ts.createPrinter();
let anyVarsDecls: string[] = [];
anyVars.forEach(name => {
anyVarsDecls.push(`let ${name}: any;\n`);
});
return printer.printFile(declsSF) + anyVarsDecls.join("");
}
it("keep default import", () => {
const src = ts.createSourceFile(
"src.ts",
'import mydefault, {foo, bar as baz} from "mylib";',
ts.ScriptTarget.ES2019
);
const stmt = src.statements[0];
if (!ts.isImportDeclaration(stmt)) {
fail("stmt is not isImportDeclaration");
return;
}
const names = new Set(["mydefault"]);
converter.keepNamesInImport(stmt, names as Set);
let printer = ts.createPrinter();
expect(printer.printFile(src)).toEqual('import mydefault from "mylib";\n');
});