Skip to content
This repository has been archived by the owner on Dec 20, 2018. It is now read-only.

Commit

Permalink
'Short Arrow' Function now support Block
Browse files Browse the repository at this point in the history
  • Loading branch information
haifenghuang committed Dec 20, 2017
1 parent adfa986 commit ffb181b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/monkey/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1692,10 +1692,14 @@ func (p *Parser) parseThinArrowFunction(left ast.Expression) ast.Expression {
}

p.nextToken()
fn.Body = &ast.BlockStatement{
Statements: []ast.Statement{
p.parseExpressionStatement(),
},
if p.curTokenIs(token.LBRACE) { //if it's block, we use parseBlockStatement
fn.Body = p.parseBlockStatement().(*ast.BlockStatement)
} else { //not block, we use parseExpressionStatement
fn.Body = &ast.BlockStatement{
Statements: []ast.Statement{
p.parseExpressionStatement(),
},
}
}

return fn
Expand Down

0 comments on commit ffb181b

Please sign in to comment.