How to use the typescript.ScriptTarget function in typescript

To help you get started, we’ve selected a few typescript 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 dotansimha / graphql-code-generator / packages / utils / config-md-generator / src / index.ts View on Github external
export async function generateConfig(inputFile: string): Promise {
  const program: ts.Program = ts.createProgram([inputFile], {
    target: ts.ScriptTarget.ES5,
    downlevelIteration: true,
    allowSyntheticDefaultImports: true,
    lib: ['es6', 'esnext', 'es2015', 'dom'],
    moduleResolution: ts.ModuleResolutionKind.NodeJs,
    module: ts.ModuleKind.CommonJS,
  });

  const compilerDiagnostics: ReadonlyArray = program.getSemanticDiagnostics();
  if (compilerDiagnostics.length > 0) {
    for (const diagnostic of compilerDiagnostics) {
      const message: string = ts.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL);
      if (diagnostic.file) {
        const location: ts.LineAndCharacter = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start!);
        const formattedMessage: string = `${diagnostic.file.fileName}(${location.line + 1},${location.character + 1}):` + ` [TypeScript] ${message}`;
        // tslint:disable-next-line:no-console
        console.error(formattedMessage);
github angular / angular / packages / compiler-cli / src / ngtsc / typecheck / src / environment.ts View on Github external
reference(ref: Reference>): ts.Expression {
    const ngExpr = this.refEmitter.emit(ref, this.contextFile);

    // Use `translateExpression` to convert the `Expression` into a `ts.Expression`.
    return translateExpression(
        ngExpr, this.importManager, NOOP_DEFAULT_IMPORT_RECORDER, ts.ScriptTarget.ES2015);
  }
github aurelia / aurelia / compiler / template-factory.ts View on Github external
transform(emitImport?: boolean): ts.SourceFile {
    let file = ts.createSourceFile(this.owner.fileName, '', ts.ScriptTarget.Latest /*, false, ts.ScriptKind.TS */);
    let templateCode = new TemplateTransformer(this, emitImport).code;
    // let mainFile = new TemplateTransformer(this, emitImport).toSourceFile();
    return ts.updateSourceFileNode(file, [
      ...templateCode.imports,
      ...this.dependencies.reduce((statements: ts.Statement[], dep) => {
        return statements.concat(dep.toSourceFile().statements);
      }, []),
      templateCode.view
    ]);
  }
github rxweb / rxweb / rxweb.io / node_modules / @ngtools / webpack / src / transformers / ast_helpers.js View on Github external
function createTypescriptContext(content) {
    // Set compiler options.
    const compilerOptions = {
        noEmitOnError: false,
        allowJs: true,
        newLine: ts.NewLineKind.LineFeed,
        target: ts.ScriptTarget.ESNext,
        skipLibCheck: true,
        sourceMap: false,
        importHelpers: true,
    };
    // Create compiler host.
    const compilerHost = new compiler_host_1.WebpackCompilerHost(compilerOptions, basePath);
    // Add a dummy file to host content.
    compilerHost.writeFile(fileName, content, false);
    // Create the TypeScript program.
    const program = ts.createProgram([fileName], compilerOptions, compilerHost);
    return { compilerHost, program };
}
exports.createTypescriptContext = createTypescriptContext;
github ionic-team / stencil / src / compiler / transpile / transpile-to-es5-worker.ts View on Github external
export async function transpileToEs5Worker(_cwd: string, input: string, inlineHelpers: boolean) {
  const results: d.TranspileResults = {
    sourceFilePath: null,
    code: input,
    map: null,
    diagnostics: [],
    moduleFile: null,
    build: {}
  };

  const transpileOpts: ts.TranspileOptions = {
    compilerOptions: {
      sourceMap: false,
      allowJs: true,
      declaration: false,
      target: ts.ScriptTarget.ES5,
      module: ts.ModuleKind.ESNext,
      removeComments: false,
      isolatedModules: true,
      skipLibCheck: true,
      noEmitHelpers: !inlineHelpers,
      importHelpers: !inlineHelpers
    }
  };

  const tsResults = ts.transpileModule(input, transpileOpts);

  results.diagnostics.push(
    ...loadTypeScriptDiagnostics(tsResults.diagnostics)
  );

  if (results.diagnostics.length === 0) {
github compodoc / ngd / dist / platform / node / compiler / walker.js View on Github external
function Dependencies(files, options) {
            this.__cache = {};
            this.__nsModule = {};
            this.unknown = '???';
            this.files = files;
            var transpileOptions = {
                target: ts.ScriptTarget.ES5,
                module: ts.ModuleKind.CommonJS,
                tsconfigDirectory: options.tsconfigDirectory
            };
            this.program = ts.createProgram(this.files, transpileOptions, utilities_1.compilerHost(transpileOptions));
        }
        Dependencies.prototype.getDependencies = function () {
github node-opcua / node-opcua / packages / node-opcua-generator / source / generator.ts View on Github external
function compileTscriptCode(typescriptFilename: string): string {

    const content = fs.readFileSync(typescriptFilename, "ascii");

    const compilerOptions = {
        module: ts.ModuleKind.CommonJS,
        target: ts.ScriptTarget.ES2016,

        skipLibCheck: true,

        declaration: true,
        sourceMap: true,
        strict: true,

        noImplicitAny: true,
        noImplicitReturns: true
    };

    const res1 = ts.transpileModule(content, { compilerOptions, moduleName: "myModule2" });

    const javascriptFilename = typescriptFilename.replace(/\.ts$/, ".js");
    const sourcemapFilename = typescriptFilename.replace(/\.ts$/, ".js.map");
github jdiaz5513 / capnp-ts / packages / capnpc-ts / src / compiler.ts View on Github external
generateFileId(ctx);

  lookupNode(ctx, ctx.file)
    .getNestedNodes()
    .map(n => lookupNode(ctx, n))
    .forEach(n => generateNode(ctx, n));

  ctx.concreteLists.forEach(([fullClassName, field]) =>
    generateConcreteListInitializer(ctx, fullClassName, field)
  );

  const sourceFile = ts.createSourceFile(
    ctx.tsPath,
    "",
    ts.ScriptTarget.Latest,
    false,
    ts.ScriptKind.TS
  );
  const printer = ts.createPrinter();
  const source =
    ctx.statements
      .map(s => printer.printNode(ts.EmitHint.Unspecified, s, sourceFile))
      .join("\n") + "\n";

  return SOURCE_COMMENT + source;
}
github ui-jar / ui-jar / bin / cli.ts View on Github external
function startFileWatcher(cliArgs: CliArgs) {
    const fileSearch = new FileSearch(cliArgs.includes, cliArgs.excludes);
    const allFilesInDirectory = fileSearch.getFiles(cliArgs.directory);
    const program: ts.Program = ts.createProgram([...allFilesInDirectory],
        { target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS });
    const testFiles = fileSearch.getTestFiles(allFilesInDirectory, program);

    const fileWatcherOptions: FileWatcherOptions = {
        directory: cliArgs.directory,
        files: testFiles
    };

    const fileWatcher = new FileWatcher(fileWatcherOptions);
    fileWatcher.start();
    fileWatcher.addListener(FileWatcherEvent.REBUILD, (fileName: string) => {
        generateSingleFile({
            directory: cliArgs.directory,
            includes: cliArgs.includes,
            excludes: cliArgs.excludes
        }, fileName);
    });
github lukasgeiter / gettext-extractor / src / js / parser.ts View on Github external
protected parse(source: string, fileName: string, options: IJsParseOptions = {}): IMessage[] {
        let sourceFile = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true, options.scriptKind);
        return this.parseNode(sourceFile, sourceFile, options.lineNumberStart || 1);
    }