From 87da5ec497b5ad45a82426bd5bedcccce5c8fdec Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Wed, 7 Dec 2016 15:02:00 +0300 Subject: [PATCH] Fixed "return" usage in a true branch of an "if" statement. --- njs/njs_parser.c | 4 ++++ njs/test/njs_unit_test.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/njs/njs_parser.c b/njs/njs_parser.c index 4b2063cc..c9f06463 100644 --- a/njs/njs_parser.c +++ b/njs/njs_parser.c @@ -629,6 +629,10 @@ njs_parser_return_statement(njs_vm_t *vm, njs_parser_t *parser) node->right = parser->node; parser->node = node; + if (token == NJS_TOKEN_SEMICOLON) { + return njs_parser_token(parser); + } + return token; } } diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index c5cf0da2..2de48b61 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -1514,6 +1514,21 @@ static njs_unit_test_t njs_test[] = { nxt_string("var a = [3], b; if (1==1||2==2) { b = '1'+'2'+a[0] }; b }"), nxt_string("123") }, + { nxt_string("(function(){ if(true) return 1 else return 0; })()"), + nxt_string("1") }, + + { nxt_string("(function(){ if(true) return 1; else return 0; })()"), + nxt_string("1") }, + + { nxt_string("(function(){ if(true) return 1;; else return 0; })()"), + nxt_string("SyntaxError: Unexpected token \"else\" in 1") }, + + { nxt_string("(function(){ if(true) return 1\n else return 0; })()"), + nxt_string("1") }, + + { nxt_string("(function(){ if(true) return 1\n;\n else return 0; })()"), + nxt_string("1") }, + /* do while. */ { nxt_string("do { break } if (false)"), -- 2.47.3