From ffb181b618ff865952edabc5fb908a63daaef9ad Mon Sep 17 00:00:00 2001 From: haifenghuang Date: Wed, 20 Dec 2017 11:28:07 +0800 Subject: [PATCH] 'Short Arrow' Function now support Block --- src/monkey/parser/parser.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/monkey/parser/parser.go b/src/monkey/parser/parser.go index 9a380ca..1a32be2 100644 --- a/src/monkey/parser/parser.go +++ b/src/monkey/parser/parser.go @@ -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