|
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() { |
| 20 | + this instanceof SourceNode::Range |
| 21 | + } |
| 22 | + |
21 | 23 | /** |
22 | 24 | * Holds if this node flows into `sink` in zero or more local (that is, |
23 | 25 | * intra-procedural) steps. |
@@ -187,44 +189,63 @@ abstract class SourceNode extends DataFlow::Node { |
187 | 189 | } |
188 | 190 | } |
189 | 191 |
|
190 | | -/** |
191 | | - * A data flow node that is considered a source node by default. |
192 | | - * |
193 | | - * Currently, the following nodes are source nodes: |
194 | | - * - import specifiers |
195 | | - * - non-destructuring function parameters |
196 | | - * - property accesses |
197 | | - * - function invocations |
198 | | - * - `this` expressions |
199 | | - * - global variable accesses |
200 | | - * - function definitions |
201 | | - * - class definitions |
202 | | - * - object expressions |
203 | | - * - array expressions |
204 | | - * - JSX literals. |
205 | | - */ |
206 | | -class DefaultSourceNode extends SourceNode { |
| 192 | +module SourceNode { |
| 193 | + /** |
| 194 | + * A data flow node that should be considered a source node. |
| 195 | + * |
| 196 | + * Subclass this class to introduce new kinds of source nodes. If you want to refine |
| 197 | + * the definition of existing source nodes, subclass `DataFlow::SourceNode` instead. |
| 198 | + */ |
| 199 | + abstract cached class Range extends DataFlow::Node { |
| 200 | + } |
| 201 | + |
| 202 | + /** |
| 203 | + * A data flow node that is considered a source node by default. |
| 204 | + * |
| 205 | + * Currently, the following nodes are source nodes: |
| 206 | + * - import specifiers |
| 207 | + * - function parameters |
| 208 | + * - `this` nodes |
| 209 | + * - property accesses |
| 210 | + * - function invocations |
| 211 | + * - global variable accesses |
| 212 | + * - function definitions |
| 213 | + * - class definitions |
| 214 | + * - object expressions |
| 215 | + * - array expressions |
| 216 | + * - JSX literals |
| 217 | + * |
| 218 | + * This class is for internal use only and should not normally be used directly. |
| 219 | + */ |
| 220 | + class DefaultRange extends Range { |
| 221 | + DefaultRange() { |
| 222 | + exists (ASTNode astNode | this = DataFlow::valueNode(astNode) | |
| 223 | + astNode instanceof PropAccess or |
| 224 | + astNode instanceof Function or |
| 225 | + astNode instanceof ClassDefinition or |
| 226 | + astNode instanceof ObjectExpr or |
| 227 | + astNode instanceof ArrayExpr or |
| 228 | + astNode instanceof JSXNode or |
| 229 | + astNode instanceof GlobalVarAccess or |
| 230 | + astNode instanceof ExternalModuleReference |
| 231 | + ) |
| 232 | + or |
| 233 | + exists (SsaExplicitDefinition ssa, VarDef def | |
| 234 | + this = DataFlow::ssaDefinitionNode(ssa) and def = ssa.getDef() | |
| 235 | + def instanceof ImportSpecifier |
| 236 | + ) |
| 237 | + or |
| 238 | + DataFlow::parameterNode(this, _) |
| 239 | + or |
| 240 | + this instanceof DataFlow::Impl::InvokeNodeDef |
| 241 | + or |
| 242 | + DataFlow::thisNode(this, _) |
| 243 | + } |
| 244 | + } |
| 245 | +} |
| 246 | + |
| 247 | +deprecated class DefaultSourceNode extends SourceNode { |
207 | 248 | DefaultSourceNode() { |
208 | | - exists (ASTNode astNode | this = DataFlow::valueNode(astNode) | |
209 | | - astNode instanceof PropAccess or |
210 | | - astNode instanceof Function or |
211 | | - astNode instanceof ClassDefinition or |
212 | | - astNode instanceof ObjectExpr or |
213 | | - astNode instanceof ArrayExpr or |
214 | | - astNode instanceof JSXNode or |
215 | | - astNode instanceof GlobalVarAccess or |
216 | | - astNode instanceof ExternalModuleReference |
217 | | - ) |
218 | | - or |
219 | | - exists (SsaExplicitDefinition ssa, VarDef def | |
220 | | - this = DataFlow::ssaDefinitionNode(ssa) and def = ssa.getDef() | |
221 | | - def instanceof ImportSpecifier |
222 | | - ) |
223 | | - or |
224 | | - DataFlow::parameterNode(this, _) |
225 | | - or |
226 | | - this instanceof DataFlow::Impl::InvokeNodeDef |
227 | | - or |
228 | | - DataFlow::thisNode(this, _) |
| 249 | + this instanceof SourceNode::DefaultRange |
229 | 250 | } |
230 | 251 | } |
0 commit comments