當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript compiler.isSyntaxError函數代碼示例

本文整理匯總了TypeScript中@angular/compiler.isSyntaxError函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript isSyntaxError函數的具體用法?TypeScript isSyntaxError怎麽用?TypeScript isSyntaxError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了isSyntaxError函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: consoleError

 .catch(e => {
   if (e instanceof tsc.UserError || isSyntaxError(e)) {
     consoleError(e.message);
   } else {
     consoleError(e.stack);
   }
   return Promise.resolve(1);
 });
開發者ID:DanielKucal,項目名稱:angular,代碼行數:8,代碼來源:main.ts

示例2: consoleError

 return tsc.main(project, cliOptions, codegen).then(() => 0).catch(e => {
   if (e instanceof tsc.UserError || isSyntaxError(e)) {
     consoleError(e.message);
     return Promise.resolve(1);
   } else {
     consoleError(e.stack);
     consoleError('Compilation failed');
     return Promise.resolve(1);
   }
 });
開發者ID:JohnnyQQQQ,項目名稱:angular,代碼行數:10,代碼來源:main.ts

示例3: performCompilation

export function performCompilation({rootNames, options, host, oldProgram, emitCallback,
                                    gatherDiagnostics = defaultGatherDiagnostics,
                                    customTransformers, emitFlags = api.EmitFlags.Default}: {
  rootNames: string[],
  options: api.CompilerOptions,
  host?: api.CompilerHost,
  oldProgram?: api.Program,
  emitCallback?: api.TsEmitCallback,
  gatherDiagnostics?: (program: api.Program) => Diagnostics,
  customTransformers?: api.CustomTransformers,
  emitFlags?: api.EmitFlags
}): PerformCompilationResult {
  let program: api.Program|undefined;
  let emitResult: ts.EmitResult|undefined;
  let allDiagnostics: Diagnostics = [];
  try {
    if (!host) {
      host = ng.createCompilerHost({options});
    }

    program = ng.createProgram({rootNames, host, options, oldProgram});

    const beforeDiags = Date.now();
    allDiagnostics.push(...gatherDiagnostics(program !));
    if (options.diagnostics) {
      const afterDiags = Date.now();
      allDiagnostics.push(
          createMessageDiagnostic(`Time for diagnostics: ${afterDiags - beforeDiags}ms.`));
    }

    if (!hasErrors(allDiagnostics)) {
      emitResult = program !.emit({emitCallback, customTransformers, emitFlags});
      allDiagnostics.push(...emitResult.diagnostics);
      return {diagnostics: allDiagnostics, program, emitResult};
    }
    return {diagnostics: allDiagnostics, program};
  } catch (e) {
    let errMsg: string;
    let code: number;
    if (isSyntaxError(e)) {
      // don't report the stack for syntax errors as they are well known errors.
      errMsg = e.message;
      code = api.DEFAULT_ERROR_CODE;
    } else {
      errMsg = e.stack;
      // It is not a syntax error we might have a program with unknown state, discard it.
      program = undefined;
      code = api.UNKNOWN_ERROR_CODE;
    }
    allDiagnostics.push(
        {category: ts.DiagnosticCategory.Error, messageText: errMsg, code, source: api.SOURCE});
    return {diagnostics: allDiagnostics, program};
  }
}
開發者ID:cartant,項目名稱:angular,代碼行數:54,代碼來源:perform_compile.ts


注:本文中的@angular/compiler.isSyntaxError函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。