How to use the @tslab/typescript-for-tslab.ModuleKind 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 / converter.ts View on Github external
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,
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([]);
    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;",