Skip to content

Commit

Permalink
Slight method name and structure cleanup around parseClassElement
Browse files Browse the repository at this point in the history
Issue #656
  • Loading branch information
marijnh committed Sep 10, 2018
1 parent 5ba305b commit c28d099
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,17 +535,20 @@ pp.parseClass = function(node, isStatement) {
classBody.body = []
this.expect(tt.braceL)
while (!this.eat(tt.braceR)) {
const member = this.parseClassMember(classBody)
if (member && member.type === "MethodDefinition" && member.kind === "constructor") {
if (hadConstructor) this.raise(member.start, "Duplicate constructor in the same class")
hadConstructor = true
const element = this.parseClassElement(classBody)
if (element) {
classBody.body.push(element)
if (element.type === "MethodDefinition" && element.kind === "constructor") {
if (hadConstructor) this.raise(element.start, "Duplicate constructor in the same class")
hadConstructor = true
}
}
}
node.body = this.finishNode(classBody, "ClassBody")
return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
}

pp.parseClassMember = function(classBody) {
pp.parseClassElement = function(classBody) {
if (this.eat(tt.semi)) return null

let method = this.startNode()
Expand Down Expand Up @@ -586,7 +589,7 @@ pp.parseClassMember = function(classBody) {
} else if (method.static && key.type === "Identifier" && key.name === "prototype") {
this.raise(key.start, "Classes may not have a static property named prototype")
}
this.parseClassMethod(classBody, method, isGenerator, isAsync)
this.parseClassMethod(method, isGenerator, isAsync)
if (method.kind === "get" && method.value.params.length !== 0)
this.raiseRecoverable(method.value.start, "getter should have no params")
if (method.kind === "set" && method.value.params.length !== 1)
Expand All @@ -596,9 +599,9 @@ pp.parseClassMember = function(classBody) {
return method
}

pp.parseClassMethod = function(classBody, method, isGenerator, isAsync) {
pp.parseClassMethod = function(method, isGenerator, isAsync) {
method.value = this.parseMethod(isGenerator, isAsync)
classBody.body.push(this.finishNode(method, "MethodDefinition"))
return this.finishNode(method, "MethodDefinition")
}

pp.parseClassId = function(node, isStatement) {
Expand Down

0 comments on commit c28d099

Please sign in to comment.