Skip to content

Commit 4f55fcb

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

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

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

55
import javascript
66

7+
overlay[local]
8+
private predicate adjacentTokens(@token token1, @token token2) {
9+
exists(@toplevel top, int index |
10+
tokeninfo(token1, _, top, index, _) and
11+
tokeninfo(token2, _, top, index + 1, _)
12+
)
13+
}
14+
715
/**
816
* A token occurring in a piece of JavaScript source code.
917
*
@@ -27,10 +35,7 @@ class Token extends Locatable, @token {
2735
string getValue() { tokeninfo(this, _, _, _, result) }
2836

2937
/** 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-
}
38+
Token getNextToken() { adjacentTokens(this, result) }
3439

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

0 commit comments

Comments
 (0)