]> git.kaiwu.me - njs.git/commitdiff
Improved parsing object literals.
authorDmitry Volyntsev <xeioex@nginx.com>
Fri, 1 Feb 2019 15:26:18 +0000 (18:26 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Fri, 1 Feb 2019 15:26:18 +0000 (18:26 +0300)
njs/njs_parser.c

index 22de2110c7900cb59a81b966c5aba52999cc005f..19516b9c983bef66bdb349d670e26fe2dae0d3e6 100644 (file)
@@ -2151,6 +2151,13 @@ njs_parser_object(njs_vm_t *vm, njs_parser_t *parser, njs_parser_node_t *obj)
 
     left = NULL;
 
+    object = njs_parser_node_new(vm, parser, NJS_TOKEN_OBJECT_VALUE);
+    if (nxt_slow_path(object == NULL)) {
+        return NJS_TOKEN_ERROR;
+    }
+
+    object->u.object = obj;
+
     for ( ;; ) {
         token = njs_parser_property_token(parser);
 
@@ -2177,13 +2184,6 @@ njs_parser_object(njs_vm_t *vm, njs_parser_t *parser, njs_parser_node_t *obj)
             return token;
         }
 
-        object = njs_parser_node_new(vm, parser, NJS_TOKEN_OBJECT_VALUE);
-        if (nxt_slow_path(object == NULL)) {
-            return NJS_TOKEN_ERROR;
-        }
-
-        object->u.object = obj;
-
         propref = njs_parser_node_new(vm, parser, NJS_TOKEN_PROPERTY);
         if (nxt_slow_path(propref == NULL)) {
             return NJS_TOKEN_ERROR;