Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
path,
(fileName, eventKind) => {
sideInputsConverted.delete(fileName);
callback(fileName, eventKind);
if (options?._fileWatcher) {
options._fileWatcher(fileName, eventKind);
}
},
pollingInterval
);
};
const host = ts.createWatchCompilerHost(
[declFilename, srcFilename],
{
// module is ESNext, not ES2015, to support dynamic import.
module: ts.ModuleKind.ESNext,
moduleResolution: ts.ModuleResolutionKind.NodeJs,
esModuleInterop: true,
target: traspileTarget,
declaration: true,
newLine: ts.NewLineKind.LineFeed,
// Remove 'use strict' from outputs.
noImplicitUseStrict: true,
typeRoots: getTypeRoots(),
// allowJs, checkJs and outDir are necessary to transpile .js files.
allowJs: true,
checkJs: true,
// tslab does not show error messages in d.ts (e.g. files in @types).
// This may improve the compile performance slightly.
skipLibCheck: true,
// rootDir is necessary to stabilize the paths of output files.
rootDir: cwd,
export function esModuleToCommonJSModule(
js: string,
target: ts.ScriptTarget
): string {
let out = ts.transpileModule(js, {
fileName: "custom.js",
compilerOptions: {
module: ts.ModuleKind.CommonJS,
esModuleInterop: true,
target,
newLine: ts.NewLineKind.LineFeed,
// Remove 'use strict' from outputs.
noImplicitUseStrict: true
}
}).outputText;
return out;
}
it("import to require", () => {
let out = ts.transpileModule(
[
'import {a, b} from "os";',
'import * as c from "vm";',
"let d = a() + b;",
"let e = x(y);",
"export {a, b, c, d, e}"
].join("\n"),
{
fileName: "src.js",
compilerOptions: {
noImplicitUseStrict: true,
module: ts.ModuleKind.CommonJS
}
}
);
expect(out.diagnostics).toEqual([]);
expect(out.outputText).toEqual(
[
'Object.defineProperty(exports, "__esModule", { value: true });',
'var os_1 = require("os");',
"exports.a = os_1.a;",
"exports.b = os_1.b;",
'var c = require("vm");',
"exports.c = c;",
"var d = os_1.a() + os_1.b;",
"exports.d = d;",
"var e = x(y);",
"exports.e = e;",