MCPcopy
hub / github.com/jquery/esprima / parseObjectPropertyKey

Method parseObjectPropertyKey

src/parser.ts:790–826  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

788 }
789
790 parseObjectPropertyKey(): Node.PropertyKey {
791 const node = this.createNode();
792 const token = this.nextToken();
793
794 let key: Node.PropertyKey;
795 switch (token.type) {
796 case Token.StringLiteral:
797 case Token.NumericLiteral:
798 if (this.context.strict && token.octal) {
799 this.tolerateUnexpectedToken(token, Messages.StrictOctalLiteral);
800 }
801 const raw = this.getTokenRaw(token);
802 key = this.finalize(node, new Node.Literal(token.value as string, raw));
803 break;
804
805 case Token.Identifier:
806 case Token.BooleanLiteral:
807 case Token.NullLiteral:
808 case Token.Keyword:
809 key = this.finalize(node, new Node.Identifier(token.value));
810 break;
811
812 case Token.Punctuator:
813 if (token.value === '[') {
814 key = this.isolateCoverGrammar(this.parseAssignmentExpression);
815 this.expect(']');
816 } else {
817 key = this.throwUnexpectedToken(token);
818 }
819 break;
820
821 default:
822 key = this.throwUnexpectedToken(token);
823 }
824
825 return key;
826 }
827
828 isPropertyKey(key, value) {
829 return (key.type === Syntax.Identifier && key.name === value) ||

Callers 3

parseObjectPropertyMethod · 0.95
parsePropertyPatternMethod · 0.95
parseClassElementMethod · 0.95

Calls 8

createNodeMethod · 0.95
nextTokenMethod · 0.95
getTokenRawMethod · 0.95
finalizeMethod · 0.95
isolateCoverGrammarMethod · 0.95
expectMethod · 0.95
throwUnexpectedTokenMethod · 0.95

Tested by

no test coverage detected