From dcad2a34317ce922acf9613afb265edabdf8d7b1 Mon Sep 17 00:00:00 2001 From: Max Schaefer Date: Fri, 30 Nov 2018 09:32:31 +0000 Subject: [PATCH] JavaScript: Simplify an `if` condition. By pulling this out of the condition we can avoid computing its negation for the `else` branch, which could previously lead to quite an enormous pipeline. --- .../ql/src/semmle/javascript/frameworks/Express.qll | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/javascript/ql/src/semmle/javascript/frameworks/Express.qll b/javascript/ql/src/semmle/javascript/frameworks/Express.qll index eb9467049bca..09ac3cdce2ef 100644 --- a/javascript/ql/src/semmle/javascript/frameworks/Express.qll +++ b/javascript/ql/src/semmle/javascript/frameworks/Express.qll @@ -127,10 +127,12 @@ module Express { Expr getRouteHandlerExpr(int index) { // The first argument is a URI pattern if it is a string. If it could possibly be // a function, we consider it to be a route handler, otherwise a URI pattern. - if getArgument(0).analyze().getAType() = TTFunction() then - result = getArgument(index) - else - (index >= 0 and result = getArgument(index + 1)) + exists (AnalyzedNode firstArg | firstArg = getArgument(0).analyze() | + if firstArg.getAType() = TTFunction() then + result = getArgument(index) + else + (index >= 0 and result = getArgument(index + 1)) + ) } /** Gets an argument that represents a route handler being registered. */