Commit 132152f6 authored by Adam Klein's avatar Adam Klein Committed by Commit Bot

[parser] Fix rewinding logic for destructuring in arrow params

Only rewind destructuring assignments if we actually preparsed
the arrow function. For the case of single-expression bodies,
we don't preparse, but we were previously erroneously rewinding.

Bug: v8:6970
Change-Id: I38e15a8a5bdb05abee3bafe7bbd7736b55a6950b
Reviewed-on: https://chromium-review.googlesource.com/733950Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Commit-Queue: Adam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48883}
parent a4e3716d
......@@ -4358,6 +4358,13 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
formal_parameters.scope->ResetAfterPreparsing(ast_value_factory_,
false);
// Discard any queued destructuring assignments which appeared
// in this function's parameter list.
FunctionState* parent_state = function_state.outer();
DCHECK_NOT_NULL(parent_state);
DCHECK_GE(parent_state->destructuring_assignments_to_rewrite().length(),
rewritable_length);
parent_state->RewindDestructuringAssignments(rewritable_length);
} else {
Consume(Token::LBRACE);
body = impl()->NewStatementList(8);
......@@ -4394,14 +4401,6 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
}
impl()->CheckConflictingVarDeclarations(formal_parameters.scope, CHECK_OK);
if (is_lazy_top_level_function) {
FunctionState* parent_state = function_state.outer();
DCHECK_NOT_NULL(parent_state);
DCHECK_GE(parent_state->destructuring_assignments_to_rewrite().length(),
rewritable_length);
parent_state->RewindDestructuringAssignments(rewritable_length);
}
impl()->RewriteDestructuringAssignments();
}
......
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
assertEquals(42, (({a = {b} = {b: 42}}) => a.b)({}));
assertEquals(42, b);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment