MCPcopy Create free account
hub / github.com/dop251/goja / parseClass

Method parseClass

parser/statement.go:301–454  ·  view source on GitHub ↗
(declaration bool)

Source from the content-addressed store, hash-verified

299}
300
301func (self *_parser) parseClass(declaration bool) *ast.ClassLiteral {
302 if declaration && !self.scope.allowLet && self.token == token.CLASS {
303 self.errorUnexpectedToken(token.CLASS)
304 }
305
306 node := &ast.ClassLiteral{
307 Class: self.expect(token.CLASS),
308 }
309
310 self.tokenToBindingId()
311 var name *ast.Identifier
312 if self.token == token.IDENTIFIER {
313 name = self.parseIdentifier()
314 } else if declaration {
315 // Use expect error handling
316 self.expect(token.IDENTIFIER)
317 }
318
319 node.Name = name
320
321 if self.token != token.LEFT_BRACE {
322 self.expect(token.EXTENDS)
323 node.SuperClass = self.parseLeftHandSideExpressionAllowCall()
324 }
325
326 self.expect(token.LEFT_BRACE)
327
328 for self.token != token.RIGHT_BRACE && self.token != token.EOF {
329 if self.token == token.SEMICOLON {
330 self.next()
331 continue
332 }
333 start := self.idx
334 static := false
335 if self.token == token.STATIC {
336 switch self.peek() {
337 case token.ASSIGN, token.SEMICOLON, token.RIGHT_BRACE, token.LEFT_PARENTHESIS:
338 // treat as identifier
339 default:
340 self.next()
341 if self.token == token.LEFT_BRACE {
342 b := &ast.ClassStaticBlock{
343 Static: start,
344 }
345 b.Block, b.DeclarationList = self.parseFunctionBlock(false, true, false)
346 b.Source = self.slice(b.Block.LeftBrace, b.Block.Idx1())
347 node.Body = append(node.Body, b)
348 continue
349 }
350 static = true
351 }
352 }
353
354 var kind ast.PropertyKind
355 var async bool
356 methodBodyStart := self.idx
357 if self.literal == "get" || self.literal == "set" {
358 if tok := self.peek(); tok != token.SEMICOLON && tok != token.LEFT_PARENTHESIS {

Callers 2

parseStatementMethod · 0.95

Calls 15

errorUnexpectedTokenMethod · 0.95
expectMethod · 0.95
tokenToBindingIdMethod · 0.95
parseIdentifierMethod · 0.95
nextMethod · 0.95
peekMethod · 0.95
parseFunctionBlockMethod · 0.95
sliceMethod · 0.95
errorMethod · 0.95
parseMethodDefinitionMethod · 0.95

Tested by

no test coverage detected