Skip to content

Commit 5d03379

Browse files
committed
fix(errors): improve error reporting when files are missing
1 parent 923a7d1 commit 5d03379

File tree

7 files changed

+44
-37
lines changed

7 files changed

+44
-37
lines changed

lib/plugin.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ System.register(['typescript', './logger', './factory', './format-errors', './ut
4040
.filter(utils_1.isTypescriptDeclaration)
4141
.forEach(function (d) {
4242
System.import(d + "!" + __moduleName)
43-
.catch(function (err) { throw err; });
43+
.catch(function (err) {
44+
logger.error(err);
45+
throw err;
46+
});
4447
});
4548
return load.source;
4649
});

lib/type-checker.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,9 @@ System.register(['typescript', './logger', './utils', "./compiler-host"], functi
3737
return [];
3838
};
3939
TypeChecker.prototype.forceCheck = function () {
40-
var files = this._host.getAllFiles()
41-
.filter(function (file) { return file.fileName != compiler_host_1.__HTML_MODULE__; });
42-
var unchecked = files.filter(function (file) { return !file.checked; });
43-
var errored = files.filter(function (file) { return file.checked && utils_1.hasError(file.errors); });
44-
if ((errored.length > 0) || (unchecked.length > 0)) {
45-
return [{
46-
file: undefined,
47-
start: undefined,
48-
length: undefined,
49-
code: 9999,
50-
category: ts.DiagnosticCategory.Error,
51-
messageText: "compilation failed [" + files.length + " files, " + errored.length + " failed, " + unchecked.length + " unchecked]"
52-
}];
53-
}
54-
return [];
40+
var candidates = this.getCandidates();
41+
candidates.forEach(function (candidate) { return candidate.checkable = true; });
42+
return this.getAllDiagnostics(candidates);
5543
};
5644
TypeChecker.prototype.getCandidates = function () {
5745
var _this = this;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "plugin-typescript",
3-
"version": "4.0.1",
3+
"version": "4.0.2",
44
"description": "TypeScript loader for SystemJS",
55
"main": "lib/plugin.js",
66
"homepage": "https://github.com/frankwallis/plugin-typescript",

src/plugin.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ export function translate(load: Module): Promise<string> {
6363
.filter(isTypescriptDeclaration)
6464
.forEach(d => {
6565
System.import(d + "!" + __moduleName)
66-
.catch(err => { throw err });
66+
.catch(err => {
67+
logger.error(err);
68+
throw err;
69+
});
6770
});
6871

6972
return load.source;

src/type-checker.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,12 @@ export class TypeChecker {
4545
}
4646

4747
/*
48-
throws if there are compiler errors or unresolved files
48+
type-checks any unchecked files even if all dependencies have not been loaded
4949
*/
5050
public forceCheck(): ts.Diagnostic[] {
51-
const files = this._host.getAllFiles()
52-
.filter(file => file.fileName != __HTML_MODULE__);
53-
const unchecked = files.filter(file => !file.checked);
54-
const errored = files.filter(file => file.checked && hasError(file.errors));
55-
56-
if ((errored.length > 0) || (unchecked.length > 0)) {
57-
return [{
58-
file: undefined,
59-
start: undefined,
60-
length: undefined,
61-
code: 9999,
62-
category: ts.DiagnosticCategory.Error,
63-
messageText: `compilation failed [${files.length} files, ${errored.length} failed, ${unchecked.length} unchecked]`
64-
}];
65-
}
66-
67-
return [];
51+
const candidates = this.getCandidates();
52+
candidates.forEach(candidate => candidate.checkable = true);
53+
return this.getAllDiagnostics(candidates);
6854
}
6955

7056
private getCandidates() {

test/resolver-spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,5 +197,4 @@ describe('Resolver', () => {
197197
deps.list.should.have.length(1);
198198
deps.list[0].should.equal(expected);
199199
});
200-
201200
});

test/type-checker-spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,34 @@ describe('TypeChecker', () => {
165165
diags.should.not.have.length(0);
166166
});
167167

168+
it('forceChecks files even if dependencies have not been loaded', async () => {
169+
const options = {
170+
noImplicitAny: true
171+
};
172+
host = new CompilerHost(options);
173+
typeChecker = new TypeChecker(host);
174+
resolver = new Resolver(host, resolve, lookup);
175+
176+
const libName = (ts as any).normalizePath(require.resolve(host.getDefaultLibFileName()));
177+
resolver.registerDeclarationFile(libName);
178+
host.addFile(libName, fs.readFileSync(libName, 'utf8'));
179+
180+
// should pass normal check and fail forceCheck
181+
host.addFile("index.ts", '/// <reference path="declaration.d.ts" />\n import a from "amodule"; export = a;');
182+
await resolver.resolve("index.ts")
183+
let diags = typeChecker.check();
184+
diags.should.have.length(0);
185+
diags = typeChecker.forceCheck();
186+
diags.should.not.have.length(0);
187+
188+
// now passes forceCheck
189+
host.addFile("declaration.d.ts", "declare module 'amodule' { export var a: number; }");
190+
await resolver.resolve("declaration.d.ts");
191+
diags = typeChecker.forceCheck();
192+
formatErrors(diags, console as any);
193+
diags.should.have.length(0);
194+
});
195+
168196
it('handles backslash in references', async () => {
169197
const diags = await typecheckAll(backslashReference);
170198
formatErrors(diags, console as any);

0 commit comments

Comments
 (0)