A term representing property access, function calls and object instantiation. The term MemberExpression
is relatively complex to handle how the new
operator and Arguments are matched.
The grammar can be expressed as saying that you must greadily consume the new
operators on the left and match it with the most Arguments as possible. If there are not enough Arguments it results in a default instantiation (e.g. new a
), this is equivalent to implicitly adding empty ()
arguments to match all the new
operators. Once the new operators are all matched (with explicit or implicit arguments), the expression is balanced and any extra arguments correspond to a call expression.
It can be summarized as saying that arguments are bound "more tightly" to the new
operator if present.
Here are some examples describing the syntax tree from each member expression.
a
// MemberExpression: `a`
// NewMemberExpression: `a`
// BalancedMemberExpression: `a`
// PrimaryExpression: `a`
new a
// MemberExpression: `new a`
// NewMemberExpression: `new a`
// NewMemberExpression: ` a`
// BalancedMemberExpression: `a` `a`
// PrimaryExpression: `a` `a`
a()
// MemberExpression: `a()`
// CallMemberExpression: `a()`
// BalancedMemberExpression: `a `
// PrimaryExpression: `a`
// Arguments: ` ()`
new a()
// MemberExpression: `new a()`
// NewMemberExpression: `new a()`
// BalancedMemberExpression: `new a()`
// BalancedMemberExpression: ` a `
// PrimaryExpression `a`
// Arguments: ` ()`
new new a
// MemberExpression: `new new a`
// NewMemberExpression: `new new a`
// NewMemberExpression: ` new a`
// NewMemberExpression: ` a`
// BalancedMemberExpression: `a`
// PrimaryExpression: `a`
a()()
// MemberExpression: `a()()`
// CallMemberExpression: `a()()`
// CallMemberExpression: `a() `
// BalancedMemberExpression: `a `
// PrimaryExpression: `a`
// Arguments: ` ()`
// Arguments: ` ()`
new new a()()
// MemberExpression: `new new a()()`
// NewMemberExpression: `new new a()()`
// BalancedMemberExpression: `new new a()()`
// BalancedMemberExpression: ` new a() `
// BalancedMemberExpression: ` a `
// PrimaryExpression: `a`
// Arguments: ` ()`
// Arguments: ` ()`
new new a()
// MemberExpression: `new new a()`
// NewMemberExpression: `new new a()`
// NewMemberExpression: ` new a()`
// BalancedMemberExpression: `new a()`
// BalancedMemberExpression: ` a `
// PrimaryExpression: `a`
// Arguments: ` ()`
new a()()
// MemberExpression: `new a()()`
// CallMemberExpression: `new a()()`
// NewMemberExpression: `new a()`
// BalancedMemberExpression: `new a()`
// BalancedMemberExpression: ` a `
// PrimaryExpression: `a`
// Arguments: ` ()`
// Arguments: ` ()`
Syntax
MemberExpression :
{
NewMemberExpression
| CallMemberExpression
}
Represents a member expression with zero or more new
operators than Arguments. Excess new
operators can be interpreted as matched with implicit ()
Arguments term.
new Array
new Array()
Syntax
NewMemberExpression :
{
BalancedMemberExpression
|new
NewMemberExpression
}
Represents a member expression with the same number of new
operators on the left as Arguments on the right.
Syntax
BalancedMemberExpression :
{
PrimaryExpression
| BalancedMemberExpression Trivia? MemberKey
|new
BalancedMemberExpression Trivia? Arguments
}
Represents a member expression with strictly more Arguments on the right than new
operators on the left.
Syntax
CallMemberExpression :
{
BalancedMemberExpression Trivia? Arguments
| CallMemberExpression Trivia? Arguments
| AbstractPseudoCall
| CallMemberExpression Trivia? MemberKey
}
Syntax
MemberKey :
{
[
Trivia? Expression Trivia?]
|.
Trivia? [Identifier]
}
Syntax
Arguments :
{
(
Trivia?)
|(
Trivia? argumentList Trivia?)
}argumentList :
{
AssignmentExpression
| argumentList Trivia?,
Trivia? AssignmentExpression
}