How to use the @tslab/typescript-for-tslab.transpileModule function in @tslab/typescript-for-tslab

To help you get started, we’ve selected a few @tslab/typescript-for-tslab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yunabe / tslab / src / tsapi.spec.ts View on Github external
it("jsfile", () => {
    // With .js suffix in fileName, ts.transpileModule handle the input as JS, not TS.
    let out = ts.transpileModule('let x: string = "hello"', {
      fileName: "src.js",
      reportDiagnostics: true
    });
    expect(out.diagnostics.length).toEqual(1);
    expect(out.diagnostics[0].messageText).toEqual(
      "'types' can only be used in a .ts file."
    );
    expect(out.outputText).toEqual('var x = "hello";\n');
    expect(out.sourceMapText).toBeUndefined();
  });
github yunabe / tslab / src / converter.ts View on Github external
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;
}
github yunabe / tslab / src / tsapi.spec.ts View on Github external
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([]);