]> git.kaiwu.me - njs.git/commitdiff
Fixed labeled empty statement.
authorVadim Zhestikov <v.zhestikov@f5.com>
Mon, 24 Oct 2022 14:48:28 +0000 (07:48 -0700)
committerVadim Zhestikov <v.zhestikov@f5.com>
Mon, 24 Oct 2022 14:48:28 +0000 (07:48 -0700)
This fixes #593 issue on Github.

src/njs_parser.c
src/test/njs_unit_test.c

index 05cfaf1709cada5ee2d40a2c8ba690aa598b6ed3..2b94d3d4cf81770baf8fad11a45a03052685ba2b 100644 (file)
@@ -4701,39 +4701,41 @@ njs_parser_statement_after(njs_parser_t *parser, njs_lexer_token_t *token,
 
     new_node = parser->node;
 
-    if (new_node->hoist) {
-        child = &njs_parser_chain_top(parser);
+    if (new_node != NULL) {
+        if (new_node->hoist) {
+            child = &njs_parser_chain_top(parser);
 
-        while (*child != NULL) {
-            node = *child;
+            while (*child != NULL) {
+                node = *child;
 
-            if (node->hoist) {
-                break;
+                if (node->hoist) {
+                    break;
+                }
+
+                child = &node->left;
             }
 
-            child = &node->left;
+            last = *child;
         }
 
-        last = *child;
-    }
-
-    stmt = njs_parser_node_new(parser, NJS_TOKEN_STATEMENT);
-    if (njs_slow_path(stmt == NULL)) {
-        return NJS_ERROR;
-    }
+        stmt = njs_parser_node_new(parser, NJS_TOKEN_STATEMENT);
+        if (njs_slow_path(stmt == NULL)) {
+            return NJS_ERROR;
+        }
 
-    stmt->hoist = new_node->hoist;
-    stmt->left = last;
-    stmt->right = new_node;
+        stmt->hoist = new_node->hoist;
+        stmt->left = last;
+        stmt->right = new_node;
 
-    *child = stmt;
+        *child = stmt;
 
-    top = (child != &parser->target) ? njs_parser_chain_top(parser)
-                                     : stmt;
+        top = (child != &parser->target) ? njs_parser_chain_top(parser)
+                                         : stmt;
 
-    parser->node = top;
+        parser->node = top;
 
-    njs_parser_chain_top_set(parser, top);
+       njs_parser_chain_top_set(parser, top);
+    }
 
     return njs_parser_stack_pop(parser);
 }
index b8818b4400d2ec1acb3a79a7799729f7bb44bf22..35614708a2ebdbeeef60b0d06f87259c76560619 100644 (file)
@@ -3159,6 +3159,9 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("a:\n\n1"),
       njs_str("1") },
 
+    { njs_str("a:;"),
+      njs_str("undefined") },
+
     { njs_str("a:\n\n"),
       njs_str("SyntaxError: Unexpected end of input in 3") },