()
| 5638 | } |
| 5639 | |
| 5640 | func (p *Parser) parseObjectLiteralElement() *ast.Node { |
| 5641 | pos := p.nodePos() |
| 5642 | jsdoc := p.jsdocScannerInfo() |
| 5643 | if p.parseOptional(ast.KindDotDotDotToken) { |
| 5644 | expression := p.parseAssignmentExpressionOrHigher() |
| 5645 | result := p.finishNode(p.factory.NewSpreadAssignment(expression), pos) |
| 5646 | p.withJSDoc(result, jsdoc) |
| 5647 | return result |
| 5648 | } |
| 5649 | modifiers := p.parseModifiersEx(true /*allowDecorators*/, false /*permitConstAsModifier*/, false /*stopOnStartOfClassStaticBlock*/) |
| 5650 | if p.parseContextualModifier(ast.KindGetKeyword) { |
| 5651 | return p.parseAccessorDeclaration(pos, jsdoc, modifiers, ast.KindGetAccessor, ParseFlagsNone) |
| 5652 | } |
| 5653 | if p.parseContextualModifier(ast.KindSetKeyword) { |
| 5654 | return p.parseAccessorDeclaration(pos, jsdoc, modifiers, ast.KindSetAccessor, ParseFlagsNone) |
| 5655 | } |
| 5656 | asteriskToken := p.parseOptionalToken(ast.KindAsteriskToken) |
| 5657 | tokenIsIdentifier := p.isIdentifier() |
| 5658 | name := p.parsePropertyName() |
| 5659 | // Disallowing of optional property assignments and definite assignment assertion happens in the grammar checker. |
| 5660 | postfixToken := p.parseOptionalToken(ast.KindQuestionToken) |
| 5661 | // Decorators, Modifiers, questionToken, and exclamationToken are not supported by property assignments and are reported in the grammar checker |
| 5662 | if postfixToken == nil { |
| 5663 | postfixToken = p.parseOptionalToken(ast.KindExclamationToken) |
| 5664 | } |
| 5665 | if asteriskToken != nil || p.token == ast.KindOpenParenToken || p.token == ast.KindLessThanToken { |
| 5666 | return p.parseMethodDeclaration(pos, jsdoc, modifiers, asteriskToken, name, postfixToken, nil /*diagnosticMessage*/) |
| 5667 | } |
| 5668 | // check if it is short-hand property assignment or normal property assignment |
| 5669 | // NOTE: if token is EqualsToken it is interpreted as CoverInitializedName production |
| 5670 | // CoverInitializedName[Yield] : |
| 5671 | // IdentifierReference[?Yield] Initializer[In, ?Yield] |
| 5672 | // this is necessary because ObjectLiteral productions are also used to cover grammar for ObjectAssignmentPattern |
| 5673 | var node *ast.Node |
| 5674 | isShorthandPropertyAssignment := tokenIsIdentifier && p.token != ast.KindColonToken |
| 5675 | if isShorthandPropertyAssignment { |
| 5676 | equalsToken := p.parseOptionalToken(ast.KindEqualsToken) |
| 5677 | var initializer *ast.Expression |
| 5678 | if equalsToken != nil { |
| 5679 | initializer = doInContext(p, ast.NodeFlagsDisallowInContext, false, (*Parser).parseAssignmentExpressionOrHigher) |
| 5680 | } |
| 5681 | node = p.factory.NewShorthandPropertyAssignment(modifiers, name, postfixToken, nil /*typeNode*/, equalsToken, initializer) |
| 5682 | } else { |
| 5683 | p.parseExpected(ast.KindColonToken) |
| 5684 | initializer := doInContext(p, ast.NodeFlagsDisallowInContext, false, (*Parser).parseAssignmentExpressionOrHigher) |
| 5685 | node = p.factory.NewPropertyAssignment(modifiers, name, postfixToken, nil /*typeNode*/, initializer) |
| 5686 | } |
| 5687 | p.finishNode(node, pos) |
| 5688 | p.withJSDoc(node, jsdoc) |
| 5689 | return node |
| 5690 | } |
| 5691 | |
| 5692 | func (p *Parser) parseFunctionExpression() *ast.Expression { |
| 5693 | // GeneratorExpression: |
nothing calls this directly
no test coverage detected