]> git.kaiwu.me - njs.git/commitdiff
Fixed "return" usage in a true branch of an "if" statement.
authorIgor Sysoev <igor@sysoev.ru>
Wed, 7 Dec 2016 12:02:00 +0000 (15:02 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Wed, 7 Dec 2016 12:02:00 +0000 (15:02 +0300)
njs/njs_parser.c
njs/test/njs_unit_test.c

index 4b2063ccdaf0608911b0d1ece2b755c4601cdd7f..c9f06463855add02139dbfd56d289512d01a3839 100644 (file)
@@ -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;
     }
 }
index c5cf0da26be2bb6d099eebf81be7c88c8c6ef079..2de48b61d0552300c7fa15ae2b9db76a61581a05 100644 (file)
@@ -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)"),