Skip to content

Commit 2aea325

Browse files
committed
JS: Improve documentation for getTokenizedAstNode
1 parent 92d6fec commit 2aea325

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/FunctionBodyFeatures.qll

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,30 @@
77
import javascript
88
private import FeaturizationConfig
99

10+
/**
11+
* Returns a tokenized representation of the AST node for use in the `enclosingFunctionBody`
12+
* feature.
13+
*/
1014
string getTokenizedAstNode(ASTNode node) {
11-
// NB: Unary and binary operator expressions e.g. -a, a + b and compound
12-
// assignments e.g. a += b can be identified by the expression type.
15+
// e.g. `x` -> "x"
1316
result = node.(Identifier).getName()
1417
or
1518
// Computed property accesses for which we can predetermine the property being accessed.
16-
// NB: May alias with operators e.g. could have '+' as a property name.
19+
// e.g. we'll featurize the `["date"]` part of `response["date"]` as `date`
1720
result = node.(IndexExpr).getPropertyName()
1821
or
1922
// We use `getRawValue` to give us distinct representations for `0xa`, `0xA`, and `10`.
23+
// e.g. `0xa` -> "0xa", `0xA` -> "0xA", `10` -> "10"
2024
result = node.(NumberLiteral).getRawValue()
2125
or
22-
// We use `getValue` rather than `getRawValue` so we assign `"a"` and `'a'` the same representation.
26+
// We use `getValue` rather than `getRawValue` so we assign `"a"` and `'a'` the same
27+
// representation.
28+
// e.g. `"a"` -> "a", `'a'` -> "a", `true` -> "true"
2329
not node instanceof NumberLiteral and
2430
result = node.(Literal).getValue()
2531
or
32+
// e.g. we'll featurize the `Hello ` and `!` parts of ``Hello ${user.name}!`` to "Hello " and "!"
33+
// respectively
2634
result = node.(TemplateElement).getRawValue()
2735
}
2836

0 commit comments

Comments
 (0)