Workaround for angular/angular-cli#9036.
In getErrorSpanForNode()
in node_modules/typescript/lib/typescript.js...
Add-
if (!sourceFile) {
return ts.createTextSpan(0, 0);
}
Just before-
if (errorNode === undefined) {
// If we don't have a better node, then just set the error on the first token of
// construct.
return getSpanOfTokenAtPosition(sourceFile, node.pos);
}
Final function-
function getErrorSpanForNode(sourceFile, node) {
var errorNode = node;
switch (node.kind) {
case 268 /* SourceFile */:
var pos_1 = ts.skipTrivia(sourceFile.text, 0, /*stopAfterLineBreak*/ false);
if (pos_1 === sourceFile.text.length) {
// file is empty - return span for the beginning of the file
return ts.createTextSpan(0, 0);
}
return getSpanOfTokenAtPosition(sourceFile, pos_1);
// This list is a work in progress. Add missing node kinds to improve their error
// spans.
case 226 /* VariableDeclaration */:
case 176 /* BindingElement */:
case 229 /* ClassDeclaration */:
case 199 /* ClassExpression */:
case 230 /* InterfaceDeclaration */:
case 233 /* ModuleDeclaration */:
case 232 /* EnumDeclaration */:
case 267 /* EnumMember */:
case 228 /* FunctionDeclaration */:
case 186 /* FunctionExpression */:
case 151 /* MethodDeclaration */:
case 153 /* GetAccessor */:
case 154 /* SetAccessor */:
case 231 /* TypeAliasDeclaration */:
errorNode = node.name;
break;
case 187 /* ArrowFunction */:
return getErrorSpanForArrowFunction(sourceFile, node);
}
// new
if (!sourceFile) {
return ts.createTextSpan(0, 0);
}
if (errorNode === undefined) {
// If we don't have a better node, then just set the error on the first token of
// construct.
return getSpanOfTokenAtPosition(sourceFile, node.pos);
}
var pos = nodeIsMissing(errorNode)
? errorNode.pos
: ts.skipTrivia(sourceFile.text, errorNode.pos);
return ts.createTextSpanFromBounds(pos, errorNode.end);
}
🔥 🔥 🔥