Skip to content

Commit 32f6cf3

Browse files
Corrected token start position calculation & nodeHasTokens predicate.
1 parent a390afb commit 32f6cf3

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/compiler/parser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ module ts {
4040
}
4141

4242
export function getTokenPosOfNode(node: Node, sourceFile?: SourceFile): number {
43+
if (node.pos === node.end) {
44+
return node.pos;
45+
}
4346
return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos);
4447
}
4548

src/services/utilities.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,13 @@ module ts {
220220
}
221221

222222
function nodeHasTokens(n: Node): boolean {
223-
if (n.kind === SyntaxKind.ExpressionStatement) {
224-
return nodeHasTokens((<ExpressionStatement>n).expression);
225-
}
226-
227-
if (n.kind === SyntaxKind.EndOfFileToken ||
228-
n.kind === SyntaxKind.OmittedExpression ||
229-
n.kind === SyntaxKind.Missing ||
230-
n.kind === SyntaxKind.Unknown) {
223+
if (n.kind === SyntaxKind.Unknown) {
231224
return false;
232225
}
233226

234-
// SyntaxList is already realized so getChildCount should be fast and non-expensive
235-
return n.kind !== SyntaxKind.SyntaxList || n.getChildCount() !== 0;
227+
// If we have a token or node that has a non-zero width, it must have tokens.
228+
// Note, that getWidth() does not take trivia into account.
229+
return n.getWidth() !== 0;
236230
}
237231

238232
export function getTypeArgumentOrTypeParameterList(node: Node): NodeArray<Node> {

0 commit comments

Comments
 (0)