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

Method parseObjectProperty

src/parser.ts:833–919  ·  view source on GitHub ↗
(hasProto)

Source from the content-addressed store, hash-verified

831 }
832
833 parseObjectProperty(hasProto): Node.Property {
834 const node = this.createNode();
835 const token = this.lookahead;
836
837 let kind: string;
838 let key: Node.PropertyKey | null = null;
839 let value: Node.PropertyValue | null = null;
840
841 let computed = false;
842 let method = false;
843 let shorthand = false;
844 let isAsync = false;
845
846 if (token.type === Token.Identifier) {
847 const id = token.value;
848 this.nextToken();
849 computed = this.match('[');
850 isAsync = !this.hasLineTerminator && (id === 'async') &&
851 !this.match(':') && !this.match('(') && !this.match('*') && !this.match(',');
852 key = isAsync ? this.parseObjectPropertyKey() : this.finalize(node, new Node.Identifier(id));
853 } else if (this.match('*')) {
854 this.nextToken();
855 } else {
856 computed = this.match('[');
857 key = this.parseObjectPropertyKey();
858 }
859
860 const lookaheadPropertyKey = this.qualifiedPropertyName(this.lookahead);
861 if (token.type === Token.Identifier && !isAsync && token.value === 'get' && lookaheadPropertyKey) {
862 kind = 'get';
863 computed = this.match('[');
864 key = this.parseObjectPropertyKey();
865 this.context.allowYield = false;
866 value = this.parseGetterMethod();
867
868 } else if (token.type === Token.Identifier && !isAsync && token.value === 'set' && lookaheadPropertyKey) {
869 kind = 'set';
870 computed = this.match('[');
871 key = this.parseObjectPropertyKey();
872 value = this.parseSetterMethod();
873
874 } else if (token.type === Token.Punctuator && token.value === '*' && lookaheadPropertyKey) {
875 kind = 'init';
876 computed = this.match('[');
877 key = this.parseObjectPropertyKey();
878 value = this.parseGeneratorMethod();
879 method = true;
880
881 } else {
882 if (!key) {
883 this.throwUnexpectedToken(this.lookahead);
884 }
885
886 kind = 'init';
887 if (this.match(':') && !isAsync) {
888 if (!computed && this.isPropertyKey(key, '__proto__')) {
889 if (hasProto.value) {
890 this.tolerateError(Messages.DuplicateProtoProperty);

Callers 1

Calls 15

createNodeMethod · 0.95
nextTokenMethod · 0.95
matchMethod · 0.95
finalizeMethod · 0.95
qualifiedPropertyNameMethod · 0.95
parseGetterMethodMethod · 0.95
parseSetterMethodMethod · 0.95
parseGeneratorMethodMethod · 0.95
throwUnexpectedTokenMethod · 0.95
isPropertyKeyMethod · 0.95
tolerateErrorMethod · 0.95

Tested by

no test coverage detected