Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (options.diagnostics) {
var afterDiags = Date.now();
allDiagnostics.push(util_1.createMessageDiagnostic("Time for diagnostics: " + (afterDiags - beforeDiags) + "ms."));
}
if (!hasErrors(allDiagnostics)) {
emitResult =
program.emit({ emitCallback: emitCallback, mergeEmitResultsCallback: mergeEmitResultsCallback, customTransformers: customTransformers, emitFlags: emitFlags });
allDiagnostics.push.apply(allDiagnostics, tslib_1.__spread(emitResult.diagnostics));
return { diagnostics: allDiagnostics, program: program, emitResult: emitResult };
}
return { diagnostics: allDiagnostics, program: program };
}
catch (e) {
var errMsg = void 0;
var code = void 0;
if (compiler_1.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: code, source: api.SOURCE });
return { diagnostics: allDiagnostics, program: program };
}
}
exports.performCompilation = performCompilation;
private _createProgramOnError(e: any) {
// Still fill the analyzedModules and the tsProgram
// so that we don't cause other errors for users who e.g. want to emit the ngProgram.
this._analyzedModules = emptyModules;
this.oldTsProgram = undefined;
this._hostAdapter.isSourceFile = () => false;
this._tsProgram = ts.createProgram(this.rootNames, this.options, this.hostAdapter);
if (isSyntaxError(e)) {
this._addStructuralDiagnostics(e);
return;
}
throw e;
}
// TODO(tbosch): allow generating files that are not in the rootDir
// See https://github.com/angular/angular/issues/19337
let genFiles = this.compiler.emitAllImpls(this.analyzedModules)
.filter(genFile => isInRootDir(genFile.genFileUrl, this.options));
if (this.oldProgramEmittedGeneratedFiles) {
const oldProgramEmittedGeneratedFiles = this.oldProgramEmittedGeneratedFiles;
genFiles = genFiles.filter(genFile => {
const oldGenFile = oldProgramEmittedGeneratedFiles.get(genFile.genFileUrl);
return !oldGenFile || !genFile.isEquivalent(oldGenFile);
});
}
return {genFiles, genDiags: []};
} catch (e) {
// TODO(tbosch): check whether we can actually have syntax errors here,
// as we already parsed the metadata and templates before to create the type check block.
if (isSyntaxError(e)) {
const genDiags: ts.Diagnostic[] = [{
file: undefined,
start: undefined,
length: undefined,
messageText: e.message,
category: ts.DiagnosticCategory.Error,
source: SOURCE,
code: DEFAULT_ERROR_CODE
}];
return {genFiles: [], genDiags};
}
throw e;
}
}
const projectDir = fs.lstatSync(project).isFile() ? path.dirname(project) : project;
// file names in tsconfig are resolved relative to this absolute path
const basePath = path.resolve(process.cwd(), projectDir);
const {parsed, ngOptions} = readConfiguration(project, basePath, checkFunc);
// CLI arguments can override the i18n options
const ngcOptions = mergeCommandLine(parsedArgs, ngOptions);
const res = performCompilation(
basePath, parsed.fileNames, parsed.options, ngcOptions, consoleError, checkFunc);
return res.errorCode;
} catch (e) {
if (isSyntaxError(e)) {
consoleError(e.message);
return 1;
}
consoleError(e.stack);
consoleError('Compilation failed');
return 2;
}
}
.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 = 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 = UNKNOWN_ERROR_CODE;
}
allDiagnostics.push(
{category: ts.DiagnosticCategory.Error, messageText: errMsg, code, source: SOURCE});
return {diagnostics: allDiagnostics, program};
})
}
return tsc.main(project, cliOptions, codegen).then(function () { return 0; }).catch(function (e) {
if (e instanceof tsc.UserError || compiler_1.isSyntaxError(e)) {
consoleError(e.message);
return Promise.resolve(1);
}
else {
consoleError(e.stack);
consoleError('Compilation failed');
return Promise.resolve(1);
}
});
}
.catch(e => {
if (e instanceof UserError || isSyntaxError(e)) {
consoleError(e.message);
return Promise.resolve(1);
} else {
consoleError(e.stack);
consoleError('Compilation failed');
return Promise.resolve(1);
}
});
}
private _addStructuralDiagnostics(error: Error) {
const diagnostics = this._structuralDiagnostics || (this._structuralDiagnostics = []);
if (isSyntaxError(error)) {
diagnostics.push(...syntaxErrorToDiagnostics(error));
} else {
diagnostics.push({
messageText: error.toString(),
category: ts.DiagnosticCategory.Error,
source: SOURCE,
code: DEFAULT_ERROR_CODE
});
}
}