()
| 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 |
no test coverage detected