MCPcopy Index your code
hub / github.com/BloombergGraphics/whatiscode / parseClassBody

Function parseClassBody

scripts/libs/esprima.js:4155–4211  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4153
4154
4155 function parseClassBody() {
4156 var classBody, token, isStatic, hasConstructor = false, body, method, computed, key;
4157
4158 classBody = new Node();
4159
4160 expect('{');
4161 body = [];
4162 while (!match('}')) {
4163 if (match(';')) {
4164 lex();
4165 } else {
4166 method = new Node();
4167 token = lookahead;
4168 isStatic = false;
4169 computed = match('[');
4170 key = parseObjectPropertyKey();
4171 if (key.name === 'static' && lookaheadPropertyName()) {
4172 token = lookahead;
4173 isStatic = true;
4174 computed = match('[');
4175 key = parseObjectPropertyKey();
4176 }
4177 method = tryParseMethodDefinition(token, key, computed, method);
4178 if (method) {
4179 method['static'] = isStatic;
4180 if (method.kind === 'init') {
4181 method.kind = 'method';
4182 }
4183 if (!isStatic) {
4184 if (!method.computed && (method.key.name || method.key.value.toString()) === 'constructor') {
4185 if (method.kind !== 'method' || !method.method || method.value.generator) {
4186 throwUnexpectedToken(token, Messages.ConstructorSpecialMethod);
4187 }
4188 if (hasConstructor) {
4189 throwUnexpectedToken(token, Messages.DuplicateConstructor);
4190 } else {
4191 hasConstructor = true;
4192 }
4193 method.kind = 'constructor';
4194 }
4195 } else {
4196 if (!method.computed && (method.key.name || method.key.value.toString()) === 'prototype') {
4197 throwUnexpectedToken(token, Messages.StaticPrototype);
4198 }
4199 }
4200 method.type = Syntax.MethodDefinition;
4201 delete method.method;
4202 delete method.shorthand;
4203 body.push(method);
4204 } else {
4205 throwUnexpectedToken(lookahead);
4206 }
4207 }
4208 }
4209 lex();
4210 return classBody.finishClassBody(body);
4211 }
4212

Callers 2

parseClassDeclarationFunction · 0.85
parseClassExpressionFunction · 0.85

Calls 7

expectFunction · 0.85
matchFunction · 0.85
lexFunction · 0.85
parseObjectPropertyKeyFunction · 0.85
lookaheadPropertyNameFunction · 0.85
tryParseMethodDefinitionFunction · 0.85
throwUnexpectedTokenFunction · 0.85

Tested by

no test coverage detected