Selecting identifiers
Perhaps the most basic - and common - expression is the Identifier expression: it is what we use to refer to the callee x
in the function call x()
, or the property a
in the object literal { a: 1 }
, or the parameter a
in the declaration function x(a) {}
.
(id)
selects identifiers that appear on their own or in other expressions. The following query will match x
in the expression x + y
, the declaration function a(x) {}
, or the call x()
:
(id x)
Anywhere an Identifier is allowed in JavaScript, the (id)
selector is also allowed in SYNG queries.
Shorthand form
Because identifiers are very common, SYNG provides a shorthand for this selector in the form of the identifier atom:
x
The above expands into the selector we saw earlier: (id x)
. This form is convenient when we're selecting identifiers as part of other expressions:
(call x) ; or
(call (id x))
The above two queries are equivalent. While we haven't encountered the (call)
selector yet, it is enough to know that the shorthand exists for now.