diff options
author | Fabrice Bellard <fabrice@bellard.org> | 2025-04-16 14:14:21 +0200 |
---|---|---|
committer | Fabrice Bellard <fabrice@bellard.org> | 2025-04-16 14:14:21 +0200 |
commit | 1d5e7cf3004919f4bbb0d2ce032c675493279e3b (patch) | |
tree | fe92923bc0fe0594d649b1397c43a29c97a6bcf3 /quickjs.c | |
parent | 5449fd42d62e5f3fda38736475f7c65c133b5cd2 (diff) | |
download | quickjs-1d5e7cf3004919f4bbb0d2ce032c675493279e3b.tar.gz quickjs-1d5e7cf3004919f4bbb0d2ce032c675493279e3b.zip |
fixed destructuring parsing: do it only in assignment expressions
Diffstat (limited to 'quickjs.c')
-rw-r--r-- | quickjs.c | 27 |
1 files changed, 12 insertions, 15 deletions
@@ -24653,20 +24653,12 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) break; case '{': case '[': - { - int skip_bits; - if (js_parse_skip_parens_token(s, &skip_bits, FALSE) == '=') { - if (js_parse_destructuring_element(s, 0, 0, FALSE, skip_bits & SKIP_HAS_ELLIPSIS, TRUE, FALSE) < 0) - return -1; - } else { - if (s->token.val == '{') { - if (js_parse_object_literal(s)) - return -1; - } else { - if (js_parse_array_literal(s)) - return -1; - } - } + if (s->token.val == '{') { + if (js_parse_object_literal(s)) + return -1; + } else { + if (js_parse_array_literal(s)) + return -1; } break; case TOK_NEW: @@ -25639,7 +25631,7 @@ static __exception int js_parse_cond_expr(JSParseState *s, int parse_flags) /* allowed parse_flags: PF_IN_ACCEPTED */ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags) { - int opcode, op, scope; + int opcode, op, scope, skip_bits; JSAtom name0 = JS_ATOM_NULL; JSAtom name; @@ -25816,6 +25808,11 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags) return js_parse_function_decl(s, JS_PARSE_FUNC_ARROW, JS_FUNC_NORMAL, JS_ATOM_NULL, s->token.ptr); + } else if ((s->token.val == '{' || s->token.val == '[') && + js_parse_skip_parens_token(s, &skip_bits, FALSE) == '=') { + if (js_parse_destructuring_element(s, 0, 0, FALSE, skip_bits & SKIP_HAS_ELLIPSIS, TRUE, FALSE) < 0) + return -1; + return 0; } next: if (s->token.val == TOK_IDENT) { |