Merge pull request #356 from asger-semmle/parameter-node

Approved by xiemaisi
This commit is contained in:
semmle-qlci
2018-11-07 08:31:05 +00:00
committed by GitHub
7 changed files with 57 additions and 0 deletions

View File

@@ -33,6 +33,9 @@ module DataFlow {
ce.getMethodName() = kind and (kind = "call" or kind = "apply")
}
or TThisNode(StmtContainer f) { f.(Function).getThisBinder() = f or f instanceof TopLevel }
or TUnusedParameterNode(SimpleParameter p) {
not exists (SsaExplicitDefinition ssa | p = ssa.getDef())
}
/**
* A node in the data flow graph.
@@ -671,6 +674,37 @@ module DataFlow {
override string getPropertyName() { none() }
}
/**
* A data flow node representing an unused parameter.
*
* This case exists to ensure all parameters have a corresponding data-flow node.
* In most cases, parameters are represented by SSA definitions or destructuring pattern nodes.
*/
private class UnusedParameterNode extends DataFlow::Node, TUnusedParameterNode {
SimpleParameter p;
UnusedParameterNode() {
this = TUnusedParameterNode(p)
}
override string toString() {
result = p.toString()
}
override ASTNode getAstNode() {
result = p
}
override BasicBlock getBasicBlock() {
result = p.getBasicBlock()
}
override predicate hasLocationInfo(string filepath, int startline, int startcolumn,
int endline, int endcolumn) {
p.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
}
/**
* Provides classes representing various kinds of calls.
*
@@ -866,6 +900,8 @@ module DataFlow {
)
or
nd = TDestructuringPatternNode(p)
or
nd = TUnusedParameterNode(p)
}
/**

View File

@@ -0,0 +1,7 @@
| sources.js:1:6:1:6 | x |
| sources.js:3:11:3:11 | x |
| tst.js:16:13:16:13 | a |
| tst.js:32:12:32:12 | b |
| tst.js:87:11:87:24 | { p: x, ...o } |
| tst.js:98:11:98:24 | [ x, ...rest ] |
| tst.ts:13:39:13:38 | args |

View File

@@ -0,0 +1,4 @@
import javascript
from DataFlow::ParameterNode param
select param

View File

@@ -25,6 +25,7 @@
| tst.js:28:2:29:3 | () =>\\n x |
| tst.js:32:1:32:0 | this |
| tst.js:32:1:34:1 | functio ... ables\\n} |
| tst.js:32:12:32:12 | b |
| tst.js:35:1:35:7 | g(true) |
| tst.js:37:9:42:1 | {\\n x: ... ;\\n }\\n} |
| tst.js:39:4:39:3 | this |

View File

@@ -1 +1,4 @@
| promises.js:3:17:5:4 | new Pro ... );\\n }) | promises.js:3:48:3:53 | reject |
| promises.js:10:18:17:4 | new Pro ... );\\n }) | promises.js:10:36:10:38 | rej |
| promises.js:33:19:35:6 | new Pro ... \\n }) | promises.js:33:50:33:55 | reject |
| promises.js:43:19:45:6 | Q.Promi ... \\n }) | promises.js:43:48:43:53 | reject |

View File

@@ -5,12 +5,16 @@
| namedImport.js:3:1:3:28 | class C ... nent {} | namedImport.js:3:27:3:26 | args |
| namedImport.js:5:1:5:20 | class D extends C {} | namedImport.js:5:19:5:18 | args |
| plainfn.js:1:1:3:1 | functio ... div>;\\n} | plainfn.js:1:16:1:20 | props |
| plainfn.js:5:1:7:1 | functio ... iv");\\n} | plainfn.js:5:17:5:21 | props |
| plainfn.js:9:1:12:1 | functio ... rn x;\\n} | plainfn.js:9:17:9:21 | props |
| plainfn.js:20:1:24:1 | functio ... n 42;\\n} | plainfn.js:20:28:20:32 | props |
| preact.js:1:1:7:1 | class H ... }\\n} | preact.js:1:38:1:37 | args |
| preact.js:1:1:7:1 | class H ... }\\n} | preact.js:2:12:2:16 | props |
| preact.js:9:1:11:1 | class H ... nt {\\n\\n} | preact.js:9:38:9:37 | args |
| probably-a-component.js:1:1:6:1 | class H ... }\\n} | probably-a-component.js:1:31:1:30 | args |
| probably-a-component.js:1:1:6:1 | class H ... }\\n} | probably-a-component.js:3:9:3:18 | this.props |
| props.js:2:5:3:5 | class C ... {\\n } | props.js:2:37:2:36 | args |
| props.js:26:5:28:5 | functio ... ;\\n } | props.js:26:16:26:20 | props |
| statePropertyWrites.js:36:19:45:1 | {\\n ren ... ;\\n }\\n} | statePropertyWrites.js:38:24:38:33 | this.props |
| thisAccesses.js:31:2:36:1 | functio ... iv/>;\\n} | thisAccesses.js:31:12:31:16 | props |
| thisAccesses.js:47:1:52:1 | class C ... }\\n} | thisAccesses.js:48:18:48:18 | y |