Skip to content

Commit 0ba610f

Browse files
authored
Merge pull request #5013 from erik-krogh/asmWhitespace
JS: remove benign result for js/whitespace-contradicts-precedence related to " | 0" expressions
2 parents 1c84455 + d86705f commit 0ba610f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

javascript/ql/src/Expressions/WhitespaceContradictsPrecedence.ql

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ class HarmlessNestedExpr extends BinaryExpr {
6161
}
6262
}
6363

64+
/**
65+
* Holds if contradicting whitespace for `binop` is unlikely to cause confusion.
66+
*/
67+
predicate benignWhitespace(BinaryExpr binop) {
68+
// asm.js like `expr |0` binary expression.
69+
not binop.getParent() instanceof BinaryExpr and
70+
binop.getOperator() = "|" and
71+
binop.getRightOperand().getIntValue() = 0
72+
}
73+
6474
/**
6575
* Holds if `inner` is an operand of `outer`, and the relative precedence
6676
* may not be immediately clear, but is important for the semantics of
@@ -69,7 +79,8 @@ class HarmlessNestedExpr extends BinaryExpr {
6979
predicate interestingNesting(BinaryExpr inner, BinaryExpr outer) {
7080
inner = outer.getAChildExpr() and
7181
not inner instanceof AssocNestedExpr and
72-
not inner instanceof HarmlessNestedExpr
82+
not inner instanceof HarmlessNestedExpr and
83+
not benignWhitespace(outer)
7384
}
7485

7586
from BinaryExpr inner, BinaryExpr outer

javascript/ql/test/query-tests/Expressions/WhitespaceContradictsPrecedence/tst.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,6 @@ x + x >> 1
5050

5151
// OK
5252
x + x >> 1
53+
54+
// OK (asm.js-like)
55+
x = x - 1|0;

0 commit comments

Comments
 (0)