Skip to content

Commit d3da642

Browse files
committed
JS: Fix bad join order in getNextToken()
1 parent a4346ed commit d3da642

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
@@ -6,6 +6,13 @@ module;
66

77
import javascript
88

9+
private predicate adjacentTokens(Token token1, Token token2) {
10+
exists(TopLevel top, int index |
11+
tokeninfo(token1, _, top, index, _) and
12+
tokeninfo(token2, _, top, index + 1, _)
13+
)
14+
}
15+
916
/**
1017
* A token occurring in a piece of JavaScript source code.
1118
*
@@ -29,10 +36,7 @@ class Token extends Locatable, @token {
2936
string getValue() { tokeninfo(this, _, _, _, result) }
3037

3138
/** Gets the token following this token inside the same toplevel structure, if any. */
32-
Token getNextToken() {
33-
this.getTopLevel() = result.getTopLevel() and
34-
this.getIndex() + 1 = result.getIndex()
35-
}
39+
Token getNextToken() { adjacentTokens(this, result) }
3640

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

0 commit comments

Comments
 (0)