File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed
javascript/ql/src/Statements Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -17,18 +17,27 @@ import semmle.javascript.RestrictedLocations
1717import semmle.javascript.dataflow.Refinements
1818import semmle.javascript.DefensiveProgramming
1919
20+ /**
21+ * Gets the unique definition of `v`.
22+ *
23+ * If `v` has no definitions or more than one, or if its single definition
24+ * is a destructuring assignment, this predicate is undefined.
25+ */
26+ VarDef getSingleDef ( Variable v ) {
27+ strictcount ( VarDef vd | vd .getAVariable ( ) = v ) = 1 and
28+ result .getTarget ( ) = v .getAReference ( )
29+ }
30+
2031/**
2132 * Holds if variable `v` looks like a symbolic constant, that is, it is assigned
2233 * exactly once, either in a `const` declaration or with a constant initializer.
2334 *
2435 * We do not consider conditionals to be useless if they check a symbolic constant.
2536 */
2637predicate isSymbolicConstant ( Variable v ) {
27- // defined exactly once
28- count ( VarDef vd | vd .getAVariable ( ) = v ) = 1 and
29- // the definition is either a `const` declaration or it assigns a constant to it
30- exists ( VarDef vd | vd .getAVariable ( ) = v and count ( vd .getAVariable ( ) ) = 1 |
31- vd .( VariableDeclarator ) .getDeclStmt ( ) instanceof ConstDeclStmt or
38+ exists ( VarDef vd | vd = getSingleDef ( v ) |
39+ vd .( VariableDeclarator ) .getDeclStmt ( ) instanceof ConstDeclStmt
40+ or
3241 isConstant ( vd .getSource ( ) )
3342 )
3443}
You can’t perform that action at this time.
0 commit comments