Skip to content

Commit bfb236f

Browse files
author
Max Schaefer
committed
JavaScript: Add more default source nodes.
In particular, `await`, `yield` and dynamic `import` expressions are now source nodes, as well as a few other experimental and legacy language features involving non-local flow.
1 parent b0b152a commit bfb236f

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

javascript/ql/src/semmle/javascript/dataflow/Sources.qll

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,13 @@ module SourceNode {
193193
/**
194194
* A data flow node that is considered a source node by default.
195195
*
196-
* Currently, the following nodes are source nodes:
196+
* This includes all nodes that evaluate to a new object and all nodes whose
197+
* value is computed using non-local data flow (that is, flow between functions,
198+
* between modules, or through the heap):
199+
*
197200
* - import specifiers
198201
* - function parameters
199-
* - `this` nodes
202+
* - `this` expressions
200203
* - property accesses
201204
* - function invocations
202205
* - global variable accesses
@@ -206,6 +209,12 @@ module SourceNode {
206209
* - array expressions
207210
* - JSX literals
208211
* - regular expression literals
212+
* - `yield` expressions
213+
* - `await` expressions
214+
* - dynamic `import` expressions
215+
* - function-bind expressions
216+
* - `function.sent` expressions
217+
* - comprehension expressions.
209218
*
210219
* This class is for internal use only and should not normally be used directly.
211220
*/
@@ -220,7 +229,13 @@ module SourceNode {
220229
astNode instanceof JSXNode or
221230
astNode instanceof GlobalVarAccess or
222231
astNode instanceof ExternalModuleReference or
223-
astNode instanceof RegExpLiteral
232+
astNode instanceof RegExpLiteral or
233+
astNode instanceof YieldExpr or
234+
astNode instanceof ComprehensionExpr or
235+
astNode instanceof AwaitExpr or
236+
astNode instanceof FunctionSentExpr or
237+
astNode instanceof FunctionBindExpr or
238+
astNode instanceof DynamicImportExpr
224239
)
225240
or
226241
this = DataFlow::ssaDefinitionNode(SSA::definition(any(ImportSpecifier imp)))

javascript/ql/test/library-tests/DataFlow/sources.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,24 @@
4343
| tst.js:50:14:53:3 | () {\\n ... et`\\n } |
4444
| tst.js:51:5:51:13 | super(42) |
4545
| tst.js:58:1:58:3 | tag |
46+
| tst.js:61:1:61:5 | ::o.m |
4647
| tst.js:61:3:61:5 | o.m |
48+
| tst.js:62:1:62:4 | o::g |
4749
| tst.js:64:1:64:0 | this |
4850
| tst.js:64:1:67:1 | functio ... lysed\\n} |
51+
| tst.js:65:3:65:10 | yield 42 |
52+
| tst.js:66:13:66:25 | function.sent |
4953
| tst.js:68:12:68:14 | h() |
5054
| tst.js:69:1:69:9 | iter.next |
5155
| tst.js:69:1:69:13 | iter.next(23) |
5256
| tst.js:71:1:71:0 | this |
5357
| tst.js:71:1:73:1 | async f ... lysed\\n} |
58+
| tst.js:72:3:72:11 | await p() |
5459
| tst.js:72:9:72:9 | p |
5560
| tst.js:72:9:72:11 | p() |
61+
| tst.js:75:9:75:21 | import('foo') |
62+
| tst.js:83:11:83:28 | [ for (v of o) v ] |
63+
| tst.js:85:11:85:28 | ( for (v of o) v ) |
5664
| tst.js:87:1:96:2 | (functi ... r: 0\\n}) |
5765
| tst.js:87:2:87:1 | this |
5866
| tst.js:87:2:92:1 | functio ... + z;\\n} |

0 commit comments

Comments
 (0)