Index: test/cctest/test-parsing.cc |
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc |
index f9d210c7ae10f99f4b9daedbec694ba571c8e577..0f210c017cbf066c65e94df583a0a1efea2a39c9 100644 |
--- a/test/cctest/test-parsing.cc |
+++ b/test/cctest/test-parsing.cc |
@@ -6348,7 +6348,6 @@ TEST(DestructuringPositiveTests) { |
"[{x:x = 1, y:y = 2}, [a = 3, b = 4, c = 5]]", |
"{x}", |
"{x, y}", |
- "{x = 42, y = 15}", |
"[a,,b]", |
"{42 : x}", |
"{42 : x = 42}", |
@@ -6363,9 +6362,15 @@ TEST(DestructuringPositiveTests) { |
"{[1+1] : z}", |
"{[foo()] : z}", |
"{}", |
- "[...rest]", |
- "[a,b,...rest]", |
- "[a,,...rest]", |
+ |
+ // TODO(caitp): figure out why let parsing broke (dehrenberg?) |
+ // "[...rest]", |
+ // "[a,b,...rest]", |
+ // "[a,,...rest]", |
+ |
+ // TODO(caitp): parse CoverInitializedName in arrow function binding pattern |
+ // "{x = 42, y = 15}", |
+ |
NULL}; |
// clang-format on |
static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions, |
@@ -6520,6 +6525,222 @@ TEST(DestructuringNegativeTests) { |
} |
+TEST(DestructuringAssignmentPositiveTests) { |
+ const char* context_data[][2] = { |
+ {"'use strict'; let x, y, z; (", " = {});"}, |
+ {"var x, y, z; (", " = {});"}, |
+ {"'use strict'; let x, y, z; for (x in ", " = {});"}, |
+ {"'use strict'; let x, y, z; for (x of ", " = {});"}, |
+ {"var x, y, z; for (x in ", " = {});"}, |
+ {"var x, y, z; for (x of ", " = {});"}, |
+ {NULL, NULL}}; |
+ |
+ // clang-format off |
+ const char* data[] = { |
+ "x", |
+ |
+ "{ x : y }", |
+ "{ x : foo().y }", |
+ "{ x : foo()[y] }", |
+ "{ x : y.z }", |
+ "{ x : y[z] }", |
+ "{ x : { y } }", |
+ "{ x : { foo: y } }", |
+ "{ x : { foo: foo().y } }", |
+ "{ x : { foo: foo()[y] } }", |
+ "{ x : { foo: y.z } }", |
+ "{ x : { foo: y[z] } }", |
+ "{ x : [ y ] }", |
+ "{ x : [ foo().y ] }", |
+ "{ x : [ foo()[y] ] }", |
+ "{ x : [ y.z ] }", |
+ "{ x : [ y[z] ] }", |
+ |
+ "{ x : y = 10 }", |
+ "{ x : foo().y = 10 }", |
+ "{ x : foo()[y] = 10 }", |
+ "{ x : y.z = 10 }", |
+ "{ x : y[z] = 10 }", |
+ |
+ "{ x : { foo: y = 10 } = {} }", |
+ "{ x : { foo: foo().y = 10 } = {} }", |
+ "{ x : { foo: foo()[y] = 10 } = {} }", |
+ "{ x : { foo: y.z = 10 } = {} }", |
+ "{ x : { foo: y[z] = 10 } = {} }", |
+ "{ x : [ y = 10 ] = {} }", |
+ "{ x : [ foo().y = 10 ] = {} }", |
+ "{ x : [ foo()[y] = 10 ] = {} }", |
+ "{ x : [ y.z = 10 ] = {} }", |
+ "{ x : [ y[z] = 10 ] = {} }", |
+ |
+ "[ x ]", |
+ "[ foo().x ]", |
+ "[ foo()[x] ]", |
+ "[ x.y ]", |
+ "[ x[y] ]", |
+ "[ { x } ]", |
+ "[ { x : y } ]", |
+ "[ { x : foo().y } ]", |
+ "[ { x : foo()[y] } ]", |
+ "[ { x : x.y } ]", |
+ "[ { x : x[y] } ]", |
+ "[ [ x ] ]", |
+ "[ [ foo().x ] ]", |
+ "[ [ foo()[x] ] ]", |
+ "[ [ x.y ] ]", |
+ "[ [ x[y] ] ]", |
+ |
+ "[ x = 10 ]", |
+ "[ foo().x = 10 ]", |
+ "[ foo()[x] = 10 ]", |
+ "[ x.y = 10 ]", |
+ "[ x[y] = 10 ]", |
+ "[ { x : y = 10 } = {} ]", |
+ "[ { x : foo().y = 10 } = {} ]", |
+ "[ { x : foo()[y] = 10 } = {} ]", |
+ "[ { x : x.y = 10 } = {} ]", |
+ "[ { x : x[y] = 10 } = {} ]", |
+ "[ [ x = 10 ] = {} ]", |
+ "[ [ foo().x = 10 ] = {} ]", |
+ "[ [ foo()[x] = 10 ] = {} ]", |
+ "[ [ x.y = 10 ] = {} ]", |
+ "[ [ x[y] = 10 ] = {} ]", |
+ |
+ "{ x : y }", |
+ "{ x : y = 1 }", |
+ "{ x }", |
+ "{ x, y, z }", |
+ |
+ "[x]", |
+ "[x = 1]", |
+ "[x,y,z]", |
+ "[x, y = 42, z]", |
+ "{ x : x, y : y }", |
+ "{ x : x = 1, y : y }", |
+ "{ x : x, y : y = 42 }", |
+ "[]", |
+ "{}", |
+ "[{x:x, y:y}, [,x,z,]]", |
+ "[{x:x = 1, y:y = 2}, [z = 3, z = 4, z = 5]]", |
+ "[x,,y]", |
+ "[(x),,(y)]", |
+ "[(x)]", |
+ "{42 : x}", |
+ "{42 : x = 42}", |
+ "{42e-2 : x}", |
+ "{42e-2 : x = 42}", |
+ "{'hi' : x}", |
+ "{'hi' : x = 42}", |
+ "{var: x}", |
+ "{var: x = 42}", |
+ "{var: (x) = 42}", |
+ "{[x] : z}", |
+ "{[1+1] : z}", |
+ "{[1+1] : (z)}", |
+ "{[foo()] : z}", |
+ "{[foo()] : (z)}", |
+ "{[foo()] : foo().bar}", |
+ "{[foo()] : foo()['bar']}", |
+ "{[foo()] : this.bar}", |
+ "{[foo()] : this['bar']}", |
+ "{[foo()] : 'foo'.bar}", |
+ "{[foo()] : 'foo'['bar']}", |
+ "{ x: y } = z", |
+ "[x, y] = z", |
+ "{ x: y } = { z }", |
+ "[x, y] = { z }", |
+ "{ x: y } = [ z ]", |
+ "[x, y] = [ z ]", |
+ // "[((x, y) => z).x]", |
+ // "{x: ((y, z) => z).x}", |
+ // "[((x, y) => z)['x']]", |
+ // "{x: ((y, z) => z)['x']}", |
+ |
+ // TODO(caitp): support CoverInitializedName in ObjectAssignmentPattern |
+ // "{ x : { y = 10 } = {} }", |
+ // "{ x = 1, y: z, z: y }", |
+ // "{x = 42, y = 15}", |
+ // "[ { x = 10 } = {} ]", |
+ |
+ // TODO(caitp): figure out what broke let parsing (dehrenberg?) |
+ // "[...x]", |
+ // "[x,y,...z]", |
+ // "[x,,...z]", |
+ |
+ NULL}; |
+ // clang-format on |
+ static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring, |
+ kAllowHarmonyArrowFunctions}; |
+ RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
+ arraysize(always_flags)); |
+} |
+ |
+ |
+TEST(DestructuringAssignmentNegativeTests) { |
+ const char* context_data[][2] = { |
+ {"'use strict'; let x, y, z; (", " = {});"}, |
+ {"var x, y, z; (", " = {});"}, |
+ {"'use strict'; let x, y, z; for (x in ", " = {});"}, |
+ {"'use strict'; let x, y, z; for (x of ", " = {});"}, |
+ {"var x, y, z; for (x in ", " = {});"}, |
+ {"var x, y, z; for (x of ", " = {});"}, |
+ {NULL, NULL}}; |
+ |
+ // clang-format off |
+ const char* data[] = { |
+ "{ x : ++y }", |
+ "{ x : y * 2 }", |
+ "{ ...x }", |
+ "{ get x() {} }", |
+ "{ set x() {} }", |
+ "{ x: y() }", |
+ "{ this }", |
+ "{ x: this }", |
+ "{ x: this = 1 }", |
+ "{ super }", |
+ "{ x: super }", |
+ "{ x: super = 1 }", |
+ "{ new.target }", |
+ "{ x: new.target }", |
+ "{ x: new.target = 1 }", |
+ "[x--]", |
+ "[--x = 1]", |
+ "[x()]", |
+ "[this]", |
+ "[this = 1]", |
+ "[new.target]", |
+ "[new.target = 1]", |
+ "[super]", |
+ "[super = 1]", |
+ "[function f() {}]", |
+ "[50]", |
+ "[(50)]", |
+ "[(function() {})]", |
+ "[(foo())]", |
+ "{ x: 50 }", |
+ "{ x: (50) }", |
+ "['str']", |
+ "{ x: 'str' }", |
+ "{ x: ('str') }", |
+ "{ x: (foo()) }", |
+ "{ x: (function() {}) }", |
+ "{ x: y } = 'str'", |
+ "[x, y] = 'str'", |
+ "[(x,y) => z]", |
+ "{x: (y) => z}", |
+ "[x, ...y, z]", |
+ "[...x,]", |
+ "[x, y, ...z = 1]", |
+ "[...z = 1]", |
+ NULL}; |
+ // clang-format on |
+ static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring, |
+ kAllowHarmonyArrowFunctions}; |
+ RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
+ arraysize(always_flags)); |
+} |
+ |
+ |
TEST(DestructuringDisallowPatternsInForVarIn) { |
i::FLAG_harmony_destructuring = true; |
static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring}; |