Skip to content

Commit 8fc89e2

Browse files
author
Esben Sparre Andreasen
committed
JS: introduce Expr::getUnderlyingValue
1 parent fbd3a09 commit 8fc89e2

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

javascript/ql/src/semmle/javascript/Expr.qll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ class ExprOrType extends @exprortype, Documentable {
4747

4848
/** Gets this expression or type, with any surrounding parentheses removed. */
4949
ExprOrType stripParens() { result = this }
50+
51+
/**
52+
* Gets the innermost expression that this expression evaluates to.
53+
*/
54+
Expr getUnderlyingValue() {
55+
result = this
56+
}
57+
5058
}
5159

5260
/** An expression. */
@@ -210,6 +218,11 @@ class ParExpr extends @parexpr, Expr {
210218
override predicate isImpure() {
211219
getExpression().isImpure()
212220
}
221+
222+
override Expr getUnderlyingValue() {
223+
result = getExpression().getUnderlyingValue()
224+
}
225+
213226
}
214227

215228
/** A `null` literal. */
@@ -617,6 +630,11 @@ class SeqExpr extends @seqexpr, Expr {
617630
override string getStringValue() {
618631
result = getLastOperand().getStringValue()
619632
}
633+
634+
override Expr getUnderlyingValue() {
635+
result = getLastOperand().getUnderlyingValue()
636+
}
637+
620638
}
621639

622640
/** A conditional expression. */
@@ -1284,6 +1302,11 @@ class Assignment extends @assignment, Expr {
12841302
override ControlFlowNode getFirstControlFlowNode() {
12851303
result = getLhs().getFirstControlFlowNode()
12861304
}
1305+
1306+
override Expr getUnderlyingValue() {
1307+
result = getRhs().getUnderlyingValue()
1308+
}
1309+
12871310
}
12881311

12891312
/** A simple assignment expression. */

javascript/ql/src/semmle/javascript/TypeScript.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,11 @@ class TypeAssertion extends Expr, @typeassertion {
13151315
override ControlFlowNode getFirstControlFlowNode() {
13161316
result = getExpression().getFirstControlFlowNode()
13171317
}
1318+
1319+
override Expr getUnderlyingValue() {
1320+
result = getExpression().getUnderlyingValue()
1321+
}
1322+
13181323
}
13191324

13201325
/**

0 commit comments

Comments
 (0)