Skip to content
This repository was archived by the owner on Dec 1, 2019. It is now read-only.

Commit ab522d0

Browse files
committed
feat: support skipLibCheck, fixes #324
1 parent 72a6f68 commit ab522d0

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

src/__test__/skipLibCheck.ts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {
2+
src, webpackConfig, tsconfig,
3+
compile, expectErrors, spec
4+
} from './utils';
5+
6+
spec(__filename, async function() {
7+
src('index.ts', `
8+
/// <reference path="./index.d.ts" />
9+
function sum(a: number, b: number) {
10+
return a + b;
11+
}
12+
13+
sum(1, 1);
14+
`);
15+
16+
src('index.d.ts', `
17+
function sum(a: number, b: number): number;
18+
`);
19+
20+
tsconfig({
21+
skipLibCheck: true
22+
});
23+
24+
let stats = await compile(webpackConfig());
25+
26+
expectErrors(stats, 0);
27+
28+
tsconfig({
29+
skipLibCheck: false
30+
});
31+
32+
stats = await compile(webpackConfig());
33+
34+
expectErrors(stats, 2, [
35+
`A 'declare' modifier is required for a top level declaration in a .d.ts file`,
36+
'Overload signatures must all be exported or non-exported'
37+
]);
38+
});

src/checker/runtime.ts

+18-5
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,24 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re
362362
console.log(colors.cyan(`\n[${ instanceName }] Checking started in a separate process...`));
363363
}
364364

365-
const allDiagnostics = service.getProgram().getOptionsDiagnostics().concat(
366-
service.getProgram().getGlobalDiagnostics(),
367-
service.getProgram().getSyntacticDiagnostics(),
368-
service.getProgram().getSemanticDiagnostics(),
369-
);
365+
const program = service.getProgram();
366+
367+
const allDiagnostics = program
368+
.getOptionsDiagnostics().concat(
369+
service.getProgram().getGlobalDiagnostics()
370+
);
371+
372+
const nativeGetter = program.getSourceFiles;
373+
if (compilerConfig.options.skipLibCheck) {
374+
program.getSourceFiles = () => nativeGetter().filter(file => {
375+
return !file.isDeclarationFile;
376+
});
377+
}
378+
379+
allDiagnostics.push(...service.getProgram().getSyntacticDiagnostics());
380+
allDiagnostics.push(...service.getProgram().getSemanticDiagnostics());
381+
382+
program.getSourceFiles = nativeGetter;
370383

371384
if (allDiagnostics.length) {
372385
console.error(colors.red(`\n[${ instanceName }] Checking finished with ${ allDiagnostics.length } errors`));

0 commit comments

Comments
 (0)