From d367c96df6ea716d8e4f3b1a8485d99da3a7abd3 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 4 Mar 2015 18:37:50 -0800 Subject: [PATCH] CR feedback. --- src/compiler/utilities.ts | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index f2687a151af..30eda5efd23 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -236,10 +236,6 @@ module ts { }; } - interface FileTextRange extends TextRange { - sourceFile: SourceFile; - } - /* @internal */ export function getSpanOfTokenAtPosition(sourceFile: SourceFile, pos: number): TextSpan { var scanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/ true, sourceFile.text); @@ -250,7 +246,7 @@ module ts { } export function getErrorSpanForNode(sourceFile: SourceFile, node: Node): TextSpan { - var errorNode: Node; + var errorNode = node; switch (node.kind) { // This list is a work in progress. Add missing node kinds to improve their error // spans. @@ -267,24 +263,12 @@ module ts { break; } - if (node.kind === SyntaxKind.FunctionExpression) { - var functionExpression = node; - if (nodeIsMissing(functionExpression.name)) { - // If it's an anonymous function expression, put the error on the first token. - return getSpanOfTokenAtPosition(sourceFile, node.pos); - } - else { - errorNode = functionExpression.name; - } + 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); } - // We now have the ideal error span, but it may be a node that is optional and absent - // (e.g. the name of a function expression), in which case errorSpan will be undefined. - // Alternatively, it might be required and missing (e.g. the name of a module), in which - // case its pos will equal its end (length 0). In either of these cases, we should fall - // back to the original node that the error was issued on. - errorNode = nodeIsMissing(errorNode) ? node : errorNode; - var pos = nodeIsMissing(errorNode) ? errorNode.pos : skipTrivia(sourceFile.text, errorNode.pos);