diff --git a/VERSION b/VERSION index 276cbf9e..2bf1c1cc 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.3.0 +2.3.1 diff --git a/docs/abs.wasm b/docs/abs.wasm index 8c223968..ab810fb0 100644 Binary files a/docs/abs.wasm and b/docs/abs.wasm differ diff --git a/evaluator/builtin_functions_test.go b/evaluator/builtin_functions_test.go index fddcfbcf..fdd2f32c 100644 --- a/evaluator/builtin_functions_test.go +++ b/evaluator/builtin_functions_test.go @@ -582,8 +582,8 @@ func TestClamp(t *testing.T) { func TestCamel(t *testing.T) { tests := []Tests{ {`"long cool woman in a black dress".camel()`, "longCoolWomanInABlackDress"}, - {`" long cool woman in a black dress ".camel()`, "longCoolWomanInABlackDress"}, - {`" long cool woman in a_black dress ".camel()`, "longCoolWomanInABlackDress"}, + {`"long cool woman in a black dress ".camel()`, "longCoolWomanInABlackDress"}, + {`"long cool woman in a_black dress ".camel()`, "longCoolWomanInABlackDress"}, } testBuiltinFunction(tests, t) diff --git a/evaluator/evaluator_test.go b/evaluator/evaluator_test.go index be7c8032..0101358d 100644 --- a/evaluator/evaluator_test.go +++ b/evaluator/evaluator_test.go @@ -520,6 +520,30 @@ func TestReturnStatements(t *testing.T) { input string expected interface{} }{ + {` +if false { + return +} +return 3 +`, 3}, + {` +if true { + return +} +return 3 +`, nil}, + {` +if false { + return; +} +return 3 +`, 3}, + {` +if true { + return; +} +return 3 +`, nil}, {"return;", nil}, {"return", nil}, {"return 1", 1}, diff --git a/examples/implicit_retur_value.abs b/examples/implicit_return_value.abs similarity index 100% rename from examples/implicit_retur_value.abs rename to examples/implicit_return_value.abs diff --git a/go.mod b/go.mod index 0500a335..7520a44c 100644 --- a/go.mod +++ b/go.mod @@ -4,12 +4,12 @@ go 1.12 require ( github.com/c-bata/go-prompt v0.2.4-0.20190826134812-0f95e1d1de2e - github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 + github.com/iancoleman/strcase v0.1.0 github.com/jteeuwen/go-bindata v3.0.7+incompatible // indirect - github.com/mattn/go-colorable v0.1.6 // indirect + github.com/mattn/go-colorable v0.1.7 // indirect github.com/mattn/go-runewidth v0.0.9 // indirect github.com/mattn/go-tty v0.0.3 // indirect - github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942 // indirect - golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 - golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd // indirect + github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03 // indirect + golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a + golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8 // indirect ) diff --git a/go.sum b/go.sum index 5355d285..b9ca6a99 100644 --- a/go.sum +++ b/go.sum @@ -2,11 +2,15 @@ github.com/c-bata/go-prompt v0.2.4-0.20190826134812-0f95e1d1de2e h1:wISxI1PW3d8y github.com/c-bata/go-prompt v0.2.4-0.20190826134812-0f95e1d1de2e/go.mod h1:Fd2OKZ3h6UdKxcSflqFDkUpTbTKwrtLbvtCp3eVuTEs= github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 h1:VHgatEHNcBFEB7inlalqfNqw65aNkM1lGX2yt3NmbS8= github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE= +github.com/iancoleman/strcase v0.1.0 h1:Lar8rut26AXkJUmVOb2bRsFGv//+tJBeJLxXvpZpF1Q= +github.com/iancoleman/strcase v0.1.0/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE= github.com/jteeuwen/go-bindata v3.0.7+incompatible/go.mod h1:JVvhzYOiGBnFSYRyV00iY8q7/0PThjIYav1p9h5dmKs= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE= github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw= +github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= @@ -22,9 +26,13 @@ github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvr github.com/pkg/term v0.0.0-20180423043932-cda20d4ac917/go.mod h1:eCbImbZ95eXtAUIbLAuAVnBnwf83mjf6QIVH8SHYwqQ= github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942 h1:A7GG7zcGjl3jqAqGPmcNjd/D9hzL95SuoOQAaFNdLU0= github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942/go.mod h1:eCbImbZ95eXtAUIbLAuAVnBnwf83mjf6QIVH8SHYwqQ= +github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03 h1:pd4YKIqCB0U7O2I4gWHgEUA2mCEOENmco0l/bM957bU= +github.com/pkg/term v0.0.0-20200520122047-c3ffed290a03/go.mod h1:Z9+Ul5bCbBKnbCvdOWbLqTHhJiYV414CURZJba6L8qA= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 h1:3zb4D3T4G8jdExgVU/95+vQXfpEPiMdCaZgmGVxjNHM= golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM= +golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180620133508-ad87a3a340fa/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -37,4 +45,6 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8 h1:AvbQYmiaaaza3cW3QXRyPo5kYgpFIzOAfeAAN7m3qQ4= +golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/parser/parser.go b/parser/parser.go index ac12e0d9..3fbcb0c4 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -346,16 +346,15 @@ func (p *Parser) parseReturnStatement() *ast.ReturnStatement { stmt := &ast.ReturnStatement{Token: p.curToken} returnToken := p.curToken - p.nextToken() - // return; - if p.curTokenIs(token.SEMICOLON) { + if p.peekTokenIs(token.SEMICOLON) { stmt.ReturnValue = &ast.NullLiteral{Token: p.curToken} - } else if p.curTokenIs(token.RBRACE) || p.curTokenIs(token.EOF) { + } else if p.peekTokenIs(token.RBRACE) || p.peekTokenIs(token.EOF) { // return stmt.ReturnValue = &ast.NullLiteral{Token: returnToken} } else { // return xyz + p.nextToken() stmt.ReturnValue = p.parseExpression(LOWEST) }