forked from TypeStrong/fork-ts-checker-webpack-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ApiIncrementalChecker): improve generation of diagnostics
when the options `checkSyntacticErrors: false` and `useTypescriptIncrementalApi: true` both were active, no semantic errors were emitted as soon as the first syntactic error was encountered this patches the `typescript` import to override that behavior see discussion in TypeStrong#257
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// tslint:disable-next-line:no-implicit-dependencies | ||
import * as ts from 'typescript'; // Imported for types alone | ||
|
||
export interface TypeScriptPatchConfig { | ||
/** | ||
* Ususally, the compilerHost created with typescript.createWatchCompilerHost will bail out of diagnostics collection if there has been any syntactic error. | ||
* (see /~https://github.com/Microsoft/TypeScript/blob/89386ddda7dafc63cb35560e05412487f47cc267/src/compiler/watch.ts#L141 ) | ||
* If this plugin is running with `checkSyntacticErrors: false`, this might lead to situations where no syntactic errors are reported within webpack | ||
* (because the file causing a syntactic error might not get processed by ts-loader), but there are semantic errors that would be missed due to this behavior. | ||
* This ensures that the compilerHost always assumes that there were no syntactic errors to be found and continues to check for semantic errors. | ||
*/ | ||
skipGetSyntacticDiagnostics: boolean; | ||
} | ||
|
||
export function patchTypescript( | ||
typescript: typeof ts, | ||
config: TypeScriptPatchConfig | ||
) { | ||
const { | ||
createEmitAndSemanticDiagnosticsBuilderProgram: originalCreateEmitAndSemanticDiagnosticsBuilderProgram | ||
} = typescript; | ||
|
||
const patchSkipGetSyntacticDiagnostics: Pick< | ||
typeof ts, | ||
'createEmitAndSemanticDiagnosticsBuilderProgram' | ||
> = { | ||
createEmitAndSemanticDiagnosticsBuilderProgram(...args: any[]) { | ||
const program = originalCreateEmitAndSemanticDiagnosticsBuilderProgram.apply( | ||
typescript, | ||
args as any | ||
); | ||
program.getSyntacticDiagnostics = () => []; | ||
return program; | ||
} | ||
}; | ||
|
||
// directly patch the typescript object | ||
Object.assign( | ||
typescript, | ||
config.skipGetSyntacticDiagnostics ? patchSkipGetSyntacticDiagnostics : {} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters