[class] Rewrite destructuring assignment in class field initializers

Bug: v8:5751, chromium:899537
Change-Id: I4c072727dffc9381a81eb8711c4114220345914d
Reviewed-on: https://chromium-review.googlesource.com/c/1304538
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57141}
diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h
index 9a0dc02..b9cd34a 100644
--- a/src/parsing/parser-base.h
+++ b/src/parsing/parser-base.h
@@ -2339,6 +2339,12 @@
 
     initializer = ParseAssignmentExpression(true);
     ValidateExpression();
+
+    // TODO(gsathya): In the future, this could be changed to be
+    // called once for all the class field initializers, instead of
+    // rewriting after each class field initializer, improving
+    // performance.
+    impl()->RewriteDestructuringAssignments();
   } else {
     initializer = factory()->NewUndefinedLiteral(kNoSourcePosition);
   }
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index df1ed56..26b4fd6 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -5036,6 +5036,8 @@
     "static 'a' = 0;",
     "static 'a';",
 
+    "static c = [c] = c",
+
     // ASI
     "static a = 0\n",
     "static a = 0\n b",
@@ -5126,6 +5128,8 @@
     "'a' = 0;",
     "'a';",
 
+    "c = [c] = c",
+
     // ASI
     "a = 0\n",
     "a = 0\n b",
@@ -5279,6 +5283,8 @@
     "static a b",
     "static a = 0 b",
 
+    "static c = [1] = [c]",
+
     // ASI requires that the next token is not part of any legal production
     "static a = 0\n *b(){}",
     "static a = 0\n ['b'](){}",
@@ -5327,6 +5333,8 @@
     "a b",
     "a = 0 b",
 
+    "c = [1] = [c]",
+
     // ASI requires that the next token is not part of any legal production
     "a = 0\n *b(){}",
     "a = 0\n ['b'](){}",
diff --git a/test/mjsunit/regress/regress-899537.js b/test/mjsunit/regress/regress-899537.js
new file mode 100644
index 0000000..3cd772c
--- /dev/null
+++ b/test/mjsunit/regress/regress-899537.js
@@ -0,0 +1,5 @@
+// Copyright 2018 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.
+
+[ class  { c = [ c ] = c } ]