diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 4849cb8c89e..d20eadd0bf3 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -40,6 +40,9 @@ module ts { } export function getTokenPosOfNode(node: Node, sourceFile?: SourceFile): number { + if (node.pos === node.end) { + return node.pos; + } return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos); } diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 88e3601b610..8745421c269 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -220,19 +220,13 @@ module ts { } function nodeHasTokens(n: Node): boolean { - if (n.kind === SyntaxKind.ExpressionStatement) { - return nodeHasTokens((n).expression); - } - - if (n.kind === SyntaxKind.EndOfFileToken || - n.kind === SyntaxKind.OmittedExpression || - n.kind === SyntaxKind.Missing || - n.kind === SyntaxKind.Unknown) { + if (n.kind === SyntaxKind.Unknown) { return false; } - // SyntaxList is already realized so getChildCount should be fast and non-expensive - return n.kind !== SyntaxKind.SyntaxList || n.getChildCount() !== 0; + // If we have a token or node that has a non-zero width, it must have tokens. + // Note, that getWidth() does not take trivia into account. + return n.getWidth() !== 0; } export function getTypeArgumentOrTypeParameterList(node: Node): NodeArray {