[njs] Parser: fixed semicolon check after continue/break statement.

Alexander Borisov alexander.borisov at nginx.com
Mon Jun 15 15:34:54 UTC 2020


details:   https://hg.nginx.org/njs/rev/3bfa26b91a55
branches:  
changeset: 1432:3bfa26b91a55
user:      Alexander Borisov <alexander.borisov at nginx.com>
date:      Mon Jun 15 18:33:57 2020 +0300
description:
Parser: fixed semicolon check after continue/break statement.

This closes #318 issue on GitHub.

diffstat:

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

diffs (44 lines):

diff -r 6023201cf1f3 -r 3bfa26b91a55 src/njs_parser.c
--- a/src/njs_parser.c	Mon Jun 15 15:26:44 2020 +0000
+++ b/src/njs_parser.c	Mon Jun 15 18:33:57 2020 +0300
@@ -5645,13 +5645,11 @@ njs_parser_break_continue(njs_parser_t *
         return njs_parser_failed(parser);
 
     default:
-        if (!parser->strict_semicolon
-            && parser->lexer->prev_type == NJS_TOKEN_LINE_END)
-        {
-            break;
-        }
-
         if (njs_lexer_token_is_label_identifier(token)) {
+            if (parser->lexer->prev_type == NJS_TOKEN_LINE_END) {
+                return njs_parser_stack_pop(parser);
+            }
+
             if (njs_label_find(parser->vm, parser->scope,
                                token->unique_id) == NULL)
             {
diff -r 6023201cf1f3 -r 3bfa26b91a55 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Mon Jun 15 15:26:44 2020 +0000
+++ b/src/test/njs_unit_test.c	Mon Jun 15 18:33:57 2020 +0300
@@ -2828,6 +2828,9 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("var i; for (i in [1,2,3]) {Object.seal({});}"),
       njs_str("undefined") },
 
+    { njs_str("while (0) {continue\n}"),
+      njs_str("undefined") },
+
     /* break. */
 
     { njs_str("break"),
@@ -2896,6 +2899,9 @@ static njs_unit_test_t  njs_test[] =
                  "for (i in a) if (a[i] > 4) break; s += a[i]; s"),
       njs_str("5") },
 
+    { njs_str("while (0) {break\n}"),
+      njs_str("undefined") },
+
     /* Labels. */
 
     { njs_str("var n = 0; a:{n++}; a:{n++}; n"),


More information about the nginx-devel mailing list