Skip to content

Commit

Permalink
fix: Check for compiler errors before converting
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Mar 15, 2020
1 parent 5cbd44d commit 802c408
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ yarn-error.log
/dist/

typedoc*.tgz
tmp
56 changes: 32 additions & 24 deletions src/lib/converter/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,22 +361,51 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
*/
private compile(context: Context): ReadonlyArray<ts.Diagnostic> {
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<ts.Diagnostic> {
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;
Expand All @@ -400,27 +429,6 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
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;
}

/**
* Return the basename of the default library that should be used.
*
Expand Down

0 comments on commit 802c408

Please sign in to comment.