From 802c40841793f1d4090bf0916a21eb026a4231f9 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Thu, 23 Jan 2020 22:41:53 -0700 Subject: [PATCH] fix: Check for compiler errors before converting --- .gitignore | 1 + src/lib/converter/converter.ts | 56 +++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index ed6e9f1fe..19bf949ed 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ yarn-error.log /dist/ typedoc*.tgz +tmp diff --git a/src/lib/converter/converter.ts b/src/lib/converter/converter.ts index fb280265c..090dd5044 100644 --- a/src/lib/converter/converter.ts +++ b/src/lib/converter/converter.ts @@ -361,22 +361,51 @@ export class Converter extends ChildableComponent { const program = context.program; - const exclude = createMinimatch(this.application.exclude || []); const isExcluded = (file: ts.SourceFile) => exclude.some(mm => mm.match(file.fileName)); - const includedSourceFiles = program.getSourceFiles() .filter(file => !isExcluded(file)); - const isRelevantError = ({ file }: ts.Diagnostic) => !file || includedSourceFiles.includes(file); + + const errors = this.getCompilerErrors(program, includedSourceFiles); + if (errors.length) { + return errors; + } includedSourceFiles.forEach((sourceFile) => { this.convertNode(context, sourceFile); }); + return []; + } + + /** + * Resolve the project within the given context. + * + * @param context The context object describing the current state the converter is in. + * @returns The final project reflection. + */ + private resolve(context: Context): ProjectReflection { + this.trigger(Converter.EVENT_RESOLVE_BEGIN, context); + const project = context.project; + + for (const id in project.reflections) { + if (!project.reflections.hasOwnProperty(id)) { + continue; + } + this.trigger(Converter.EVENT_RESOLVE, context, project.reflections[id]); + } + + this.trigger(Converter.EVENT_RESOLVE_END, context); + return project; + } + + private getCompilerErrors(program: ts.Program, includedSourceFiles: readonly ts.SourceFile[]): ReadonlyArray { if (this.application.ignoreCompilerErrors) { return []; } + const isRelevantError = ({ file }: ts.Diagnostic) => !file || includedSourceFiles.includes(file); + let diagnostics = program.getOptionsDiagnostics().filter(isRelevantError); if (diagnostics.length) { return diagnostics; @@ -400,27 +429,6 @@ export class Converter extends ChildableComponent