From a5819a14bec6c7efba67743085c6b196d1ce1c90 Mon Sep 17 00:00:00 2001 From: Asger F Date: Fri, 12 Sep 2025 09:49:52 +0200 Subject: [PATCH] JS: Fix bad join order in getNextToken() --- javascript/ql/lib/semmle/javascript/Tokens.qll | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/javascript/ql/lib/semmle/javascript/Tokens.qll b/javascript/ql/lib/semmle/javascript/Tokens.qll index c6a9b05a3d1..3d4e70d6149 100644 --- a/javascript/ql/lib/semmle/javascript/Tokens.qll +++ b/javascript/ql/lib/semmle/javascript/Tokens.qll @@ -4,6 +4,13 @@ import javascript +private predicate adjacentTokens(Token token1, Token token2) { + exists(TopLevel top, int index | + tokeninfo(token1, _, top, index, _) and + tokeninfo(token2, _, top, index + 1, _) + ) +} + /** * A token occurring in a piece of JavaScript source code. * @@ -27,10 +34,7 @@ class Token extends Locatable, @token { string getValue() { tokeninfo(this, _, _, _, result) } /** Gets the token following this token inside the same toplevel structure, if any. */ - Token getNextToken() { - this.getTopLevel() = result.getTopLevel() and - this.getIndex() + 1 = result.getIndex() - } + Token getNextToken() { adjacentTokens(this, result) } /** Gets the token preceding this token inside the same toplevel structure, if any. */ Token getPreviousToken() { result.getNextToken() = this }