Skip to content

Commit 33001a7

Browse files
committed
JS: Fix bad join order in getNextToken()
1 parent 38529e5 commit 33001a7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

javascript/ql/lib/semmle/javascript/Tokens.qll

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
import javascript
66

7+
private predicate adjacentTokens(Token token1, Token token2) {
8+
exists(TopLevel top, int index |
9+
tokeninfo(token1, _, top, index, _) and
10+
tokeninfo(token2, _, top, index + 1, _)
11+
)
12+
}
13+
714
/**
815
* A token occurring in a piece of JavaScript source code.
916
*
@@ -27,10 +34,7 @@ class Token extends Locatable, @token {
2734
string getValue() { tokeninfo(this, _, _, _, result) }
2835

2936
/** Gets the token following this token inside the same toplevel structure, if any. */
30-
Token getNextToken() {
31-
this.getTopLevel() = result.getTopLevel() and
32-
this.getIndex() + 1 = result.getIndex()
33-
}
37+
Token getNextToken() { adjacentTokens(this, result) }
3438

3539
/** Gets the token preceding this token inside the same toplevel structure, if any. */
3640
Token getPreviousToken() { result.getNextToken() = this }

0 commit comments

Comments
 (0)