()
| 5292 | } |
| 5293 | |
| 5294 | func (p *Parser) parseMemberExpressionOrHigher() *ast.Node { |
| 5295 | // Note: to make our lives simpler, we decompose the NewExpression productions and |
| 5296 | // place ObjectCreationExpression and FunctionExpression into PrimaryExpression. |
| 5297 | // like so: |
| 5298 | // |
| 5299 | // PrimaryExpression : See 11.1 |
| 5300 | // this |
| 5301 | // Identifier |
| 5302 | // Literal |
| 5303 | // ArrayLiteral |
| 5304 | // ObjectLiteral |
| 5305 | // (Expression) |
| 5306 | // FunctionExpression |
| 5307 | // new MemberExpression Arguments? |
| 5308 | // |
| 5309 | // MemberExpression : See 11.2 |
| 5310 | // PrimaryExpression |
| 5311 | // MemberExpression[Expression] |
| 5312 | // MemberExpression.IdentifierName |
| 5313 | // |
| 5314 | // CallExpression : See 11.2 |
| 5315 | // MemberExpression |
| 5316 | // CallExpression Arguments |
| 5317 | // CallExpression[Expression] |
| 5318 | // CallExpression.IdentifierName |
| 5319 | // |
| 5320 | // Technically this is ambiguous. i.e. CallExpression defines: |
| 5321 | // |
| 5322 | // CallExpression: |
| 5323 | // CallExpression Arguments |
| 5324 | // |
| 5325 | // If you see: "new Foo()" |
| 5326 | // |
| 5327 | // Then that could be treated as a single ObjectCreationExpression, or it could be |
| 5328 | // treated as the invocation of "new Foo". We disambiguate that in code (to match |
| 5329 | // the original grammar) by making sure that if we see an ObjectCreationExpression |
| 5330 | // we always consume arguments if they are there. So we treat "new Foo()" as an |
| 5331 | // object creation only, and not at all as an invocation. Another way to think |
| 5332 | // about this is that for every "new" that we see, we will consume an argument list if |
| 5333 | // it is there as part of the *associated* object creation node. Any additional |
| 5334 | // argument lists we see, will become invocation expressions. |
| 5335 | // |
| 5336 | // Because there are no other places in the grammar now that refer to FunctionExpression |
| 5337 | // or ObjectCreationExpression, it is safe to push down into the PrimaryExpression |
| 5338 | // production. |
| 5339 | // |
| 5340 | // Because CallExpression and MemberExpression are left recursive, we need to bottom out |
| 5341 | // of the recursion immediately. So we parse out a primary expression to start with. |
| 5342 | pos := p.nodePos() |
| 5343 | expression := p.parsePrimaryExpression() |
| 5344 | return p.parseMemberExpressionRest(pos, expression, true /*allowOptionalChain*/) |
| 5345 | } |
| 5346 | |
| 5347 | func (p *Parser) parseMemberExpressionRest(pos int, expression *ast.Expression, allowOptionalChain bool) *ast.Expression { |
| 5348 | for { |
no test coverage detected