How to use the @tslab/typescript-for-tslab.createSourceFile 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.spec.ts View on Github external
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");
    }
github yunabe / tslab / src / converter.spec.ts View on Github external
it("keep default remove namespace", () => {
    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(["mydefault"]);
    converter.keepNamesInImport(stmt, names as Set);
    let printer = ts.createPrinter();
    expect(printer.printFile(src)).toEqual('import mydefault from "mylib";\n');
  });
github yunabe / tslab / src / converter.spec.ts View on Github external
it("keep default and 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(["mydefault", "baz"]);
    converter.keepNamesInImport(stmt, names as Set);
    let printer = ts.createPrinter();
    expect(printer.printFile(src)).toEqual(
      'import mydefault, { bar as baz } from "mylib";\n'
    );
  });