[njs] Parser: fixed parsing return statement without semicolon.

Alexander Borisov alexander.borisov at nginx.com
Tue Jul 14 11:51:01 UTC 2020


details:   https://hg.nginx.org/njs/rev/022995046310
branches:  
changeset: 1464:022995046310
user:      Alexander Borisov <alexander.borisov at nginx.com>
date:      Tue Jul 14 14:49:46 2020 +0300
description:
Parser: fixed parsing return statement without semicolon.

The issue was introduced in 86f55a7dc4a4.

This closes #330 issue on GitHub.

diffstat:

 src/njs_parser.c         |  3 +--
 src/test/njs_unit_test.c |  3 +++
 2 files changed, 4 insertions(+), 2 deletions(-)

diffs (33 lines):

diff -r 5f2034557bc3 -r 022995046310 src/njs_parser.c
--- a/src/njs_parser.c	Thu Jul 09 13:57:10 2020 +0000
+++ b/src/njs_parser.c	Tue Jul 14 14:49:46 2020 +0300
@@ -5719,6 +5719,7 @@ njs_parser_return_statement(njs_parser_t
 
     switch (token->type) {
     case NJS_TOKEN_SEMICOLON:
+        njs_lexer_consume_token(parser->lexer, 1);
         break;
 
     case NJS_TOKEN_LINE_END:
@@ -5741,8 +5742,6 @@ njs_parser_return_statement(njs_parser_t
 
     parser->node = node;
 
-    njs_lexer_consume_token(parser->lexer, 1);
-
     return njs_parser_stack_pop(parser);
 }
 
diff -r 5f2034557bc3 -r 022995046310 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Thu Jul 09 13:57:10 2020 +0000
+++ b/src/test/njs_unit_test.c	Tue Jul 14 14:49:46 2020 +0300
@@ -2553,6 +2553,9 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("var x = 0, y = 2; x\n--\ny; [x,y]"),
       njs_str("0,1") },
 
+    { njs_str("function f() {return\n}"),
+      njs_str("undefined") },
+
     /* if. */
 
     { njs_str("if (0);"),


More information about the nginx-devel mailing list