Skip to content

Commit 14f6c7a

Browse files
committed
JS: Refactor closure support a bit
1 parent d131776 commit 14f6c7a

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

javascript/ql/lib/semmle/javascript/internal/NameResolution.qll

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,22 @@ module NameResolution {
280280
result = enum.getMemberByName(name).getIdentifier()
281281
)
282282
or
283+
storeToVariable(result, name, mod.(Closure::ClosureModule).getExportsVariable())
284+
}
285+
286+
/**
287+
* Holds if `value` is stored in `target.prop`. Only needs to recognise assignments
288+
* that are also recognised by JSDoc tooling such as the Closure compiler.
289+
*/
290+
private predicate storeToVariable(Expr value, string prop, LocalVariable target) {
283291
exists(AssignExpr assign |
284-
assign
285-
.getLhs()
286-
.(PropAccess)
287-
.accesses(mod.(Closure::ClosureModule).getExportsVariable().getAnAccess(), name) and
288-
result = assign.getRhs()
292+
// exports.name = value
293+
assign.getLhs().(PropAccess).accesses(target.getAnAccess(), prop) and
294+
value = assign.getRhs()
289295
)
296+
or
297+
// exports = { name: value }
298+
value = target.getAnAssignedExpr().(ObjectExpr).getPropertyByName(prop).getInit()
290299
}
291300

292301
/** Steps that only apply for this configuration. */

0 commit comments

Comments
 (0)