Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cwd,
options?.isJS ? "__tslab__.js" : "__tslab__.ts"
);
const declFilename = pathlib.join(cwd, "__prev__.d.ts");
const outDir = "outDir";
const dstFilename = pathlib.join(outDir, "__tslab__.js");
const dstDeclFilename = pathlib.join(outDir, "__tslab__.d.ts");
// c.f.
// https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping
// https://github.com/microsoft/TypeScript/issues/22306#issuecomment-412266626
const traspileTarget =
semver.major(process.version) >= 12
? ts.ScriptTarget.ES2019
: ts.ScriptTarget.ES2018;
const srcPrefix = "export {};" + ts.sys.newLine;
let srcContent: string = "";
let declContent: string = "";
/** Check if external .ts files are converted. */
const sideInputsConverted = new Set();
let builder: ts.BuilderProgram = null;
const sys = Object.create(ts.sys) as ts.System;
let rebuildTimer: RebuildTimer = null;
sys.getCurrentDirectory = function() {
return cwd;
};
sys.setTimeout = (callback: (...args: any[]) => void): any => {
if (rebuildTimer) {
throw new Error("Unexpected pending rebuildTimer");
it("keep named 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(["foo"]);
converter.keepNamesInImport(stmt, names as Set);
let printer = ts.createPrinter();
expect(printer.printFile(src)).toEqual('import { foo } from "mylib";\n');
});
it("wrong names", () => {
const src = ts.createSourceFile(
"src.ts",
'import mydefault, * as ns from "mylib";',
ts.ScriptTarget.ES2019
);
const stmt = src.statements[0];
if (!ts.isImportDeclaration(stmt)) {
fail("stmt is not isImportDeclaration");
return;
}
const names = new Set(["wrong"]);
try {
converter.keepNamesInImport(stmt, names as Set);
fail("keepNamesInImport must fail.");
} catch (e) {
expect(String(e)).toEqual("Error: no symbol is included in names");
}
});
});