|
9 | 9 | import javascript |
10 | 10 |
|
11 | 11 | /** |
12 | | - * A source node for local data flow, that is, a node for which local |
13 | | - * data flow cannot provide any information about its inputs. |
| 12 | + * A source node for local data flow, that is, a node from which local data flow is tracked. |
14 | 13 | * |
15 | | - * By default, functions, object and array expressions and JSX nodes |
16 | | - * are considered sources, as well as expressions that have non-local |
17 | | - * flow (such as calls and property accesses). Additional sources |
18 | | - * can be modelled by extending this class with additional subclasses. |
| 14 | + * Examples include function parameters, imports and property accesses; see |
| 15 | + * `DataFlow::SourceNode::DefaultRange` for details. You can introduce new kinds of |
| 16 | + * source nodes by defining new subclasses of `DataFlow::SourceNode::Range`. |
19 | 17 | */ |
20 | | -abstract class SourceNode extends DataFlow::Node { |
| 18 | +class SourceNode extends DataFlow::Node { |
| 19 | + SourceNode() { this instanceof SourceNode::Range } |
| 20 | + |
21 | 21 | /** |
22 | 22 | * Holds if this node flows into `sink` in zero or more local (that is, |
23 | 23 | * intra-procedural) steps. |
@@ -167,45 +167,62 @@ abstract class SourceNode extends DataFlow::Node { |
167 | 167 | } |
168 | 168 | } |
169 | 169 |
|
170 | | -/** |
171 | | - * A data flow node that is considered a source node by default. |
172 | | - * |
173 | | - * Currently, the following nodes are source nodes: |
174 | | - * - import specifiers |
175 | | - * - non-destructuring function parameters |
176 | | - * - property accesses |
177 | | - * - function invocations |
178 | | - * - `this` expressions |
179 | | - * - global variable accesses |
180 | | - * - function definitions |
181 | | - * - class definitions |
182 | | - * - object expressions |
183 | | - * - array expressions |
184 | | - * - JSX literals. |
185 | | - */ |
186 | | -class DefaultSourceNode extends SourceNode { |
187 | | - DefaultSourceNode() { |
188 | | - exists(ASTNode astNode | this = DataFlow::valueNode(astNode) | |
189 | | - astNode instanceof PropAccess or |
190 | | - astNode instanceof Function or |
191 | | - astNode instanceof ClassDefinition or |
192 | | - astNode instanceof ObjectExpr or |
193 | | - astNode instanceof ArrayExpr or |
194 | | - astNode instanceof JSXNode or |
195 | | - astNode instanceof GlobalVarAccess or |
196 | | - astNode instanceof ExternalModuleReference |
197 | | - ) |
198 | | - or |
199 | | - exists(SsaExplicitDefinition ssa, VarDef def | |
200 | | - this = DataFlow::ssaDefinitionNode(ssa) and def = ssa.getDef() |
201 | | - | |
202 | | - def instanceof ImportSpecifier |
203 | | - ) |
204 | | - or |
205 | | - DataFlow::parameterNode(this, _) |
206 | | - or |
207 | | - this instanceof DataFlow::Impl::InvokeNodeDef |
208 | | - or |
209 | | - DataFlow::thisNode(this, _) |
| 170 | +module SourceNode { |
| 171 | + /** |
| 172 | + * A data flow node that should be considered a source node. |
| 173 | + * |
| 174 | + * Subclass this class to introduce new kinds of source nodes. If you want to refine |
| 175 | + * the definition of existing source nodes, subclass `DataFlow::SourceNode` instead. |
| 176 | + */ |
| 177 | + cached |
| 178 | + abstract class Range extends DataFlow::Node { } |
| 179 | + |
| 180 | + /** |
| 181 | + * A data flow node that is considered a source node by default. |
| 182 | + * |
| 183 | + * Currently, the following nodes are source nodes: |
| 184 | + * - import specifiers |
| 185 | + * - function parameters |
| 186 | + * - `this` nodes |
| 187 | + * - property accesses |
| 188 | + * - function invocations |
| 189 | + * - global variable accesses |
| 190 | + * - function definitions |
| 191 | + * - class definitions |
| 192 | + * - object expressions |
| 193 | + * - array expressions |
| 194 | + * - JSX literals |
| 195 | + * |
| 196 | + * This class is for internal use only and should not normally be used directly. |
| 197 | + */ |
| 198 | + class DefaultRange extends Range { |
| 199 | + DefaultRange() { |
| 200 | + exists(ASTNode astNode | this = DataFlow::valueNode(astNode) | |
| 201 | + astNode instanceof PropAccess or |
| 202 | + astNode instanceof Function or |
| 203 | + astNode instanceof ClassDefinition or |
| 204 | + astNode instanceof ObjectExpr or |
| 205 | + astNode instanceof ArrayExpr or |
| 206 | + astNode instanceof JSXNode or |
| 207 | + astNode instanceof GlobalVarAccess or |
| 208 | + astNode instanceof ExternalModuleReference |
| 209 | + ) |
| 210 | + or |
| 211 | + exists(SsaExplicitDefinition ssa, VarDef def | |
| 212 | + this = DataFlow::ssaDefinitionNode(ssa) and def = ssa.getDef() |
| 213 | + | |
| 214 | + def instanceof ImportSpecifier |
| 215 | + ) |
| 216 | + or |
| 217 | + DataFlow::parameterNode(this, _) |
| 218 | + or |
| 219 | + this instanceof DataFlow::Impl::InvokeNodeDef |
| 220 | + or |
| 221 | + DataFlow::thisNode(this, _) |
| 222 | + } |
210 | 223 | } |
211 | 224 | } |
| 225 | + |
| 226 | +deprecated class DefaultSourceNode extends SourceNode { |
| 227 | + DefaultSourceNode() { this instanceof SourceNode::DefaultRange } |
| 228 | +} |
0 commit comments