1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | /**
|
4 | * While it is often possible to pass a wrapped or modified copy of `typescript` or `typescript.sys` as a function argument to override/extend some typescript-internal behavior,
|
5 | * sometimes the typescript-internal code ignores these passed objects and directly references the internal `typescript` object reference.
|
6 | * In these situations, the only way of consistently overriding some behavior is to directly replace methods on the `typescript` object.
|
7 | *
|
8 | * So beware, this method directly modifies the passed `typescript` object!
|
9 | * @param typescript TypeScript instance to patch
|
10 | * @param config
|
11 | */
|
12 | function patchTypescript(typescript, config) {
|
13 | if (config.skipGetSyntacticDiagnostics) {
|
14 | patchSkipGetSyntacticDiagnostics(typescript);
|
15 | }
|
16 | }
|
17 | exports.patchTypescript = patchTypescript;
|
18 | /**
|
19 | * Overrides the [`typescript.createEmitAndSemanticDiagnosticsBuilderProgram`](https://github.com/Microsoft/TypeScript/blob/89386ddda7dafc63cb35560e05412487f47cc267/src/compiler/builder.ts#L1176)
|
20 | * method to return a `ts.Program` instance that does not emit syntactic errors,
|
21 | * to prevent the [`typescript.createWatchCompilerHost`](https://github.com/Microsoft/TypeScript/blob/89386ddda7dafc63cb35560e05412487f47cc267/src/compiler/watch.ts#L333)
|
22 | * method from bailing during diagnostic collection in the [`emitFilesAndReportErrors`](https://github.com/Microsoft/TypeScript/blob/89386ddda7dafc63cb35560e05412487f47cc267/src/compiler/watch.ts#L141) callback.
|
23 | *
|
24 | * See the description of TypeScriptPatchConfig.skipGetSyntacticDiagnostics and
|
25 | * [this github discussion](https://github.com/Realytics/fork-ts-checker-webpack-plugin/issues/257#issuecomment-485414182)
|
26 | * for further information on this problem & solution.
|
27 | */
|
28 | function patchSkipGetSyntacticDiagnostics(typescript) {
|
29 | const { createEmitAndSemanticDiagnosticsBuilderProgram: originalCreateEmitAndSemanticDiagnosticsBuilderProgram } = typescript;
|
30 | const patchedMethods = {
|
31 | createEmitAndSemanticDiagnosticsBuilderProgram(...args) {
|
32 | const program = originalCreateEmitAndSemanticDiagnosticsBuilderProgram.apply(typescript, args);
|
33 | program.getSyntacticDiagnostics = () => [];
|
34 | return program;
|
35 | }
|
36 | };
|
37 | // directly patch the typescript object!
|
38 | Object.assign(typescript, patchedMethods);
|
39 | }
|
40 | //# sourceMappingURL=patchTypescript.js.map |
\ | No newline at end of file |