Backport array & object pattern fixes to 6.x (#5770)

* Backport array & object pattern fixes to 6.x

Original PRs merged to 7.0 as #5722 and #5762

* fix lint error
This commit is contained in:
Bo Lingen 2017-06-08 15:58:37 -05:00 committed by Henry Zhu
parent 783d85ee4b
commit 0c8fdc381d
3 changed files with 26 additions and 2 deletions

View File

@ -526,7 +526,7 @@ defineType("ObjectProperty", {
}
},
value: {
validate: assertNodeType("Expression")
validate: assertNodeType("Expression", "Pattern", "RestElement")
},
shorthand: {
validate: assertValueType("boolean"),

View File

@ -29,7 +29,7 @@ defineType("ArrayPattern", {
aliases: ["Pattern", "LVal"],
fields: {
elements: {
validate: chain(assertValueType("array"), assertEach(assertNodeType("Expression")))
validate: chain(assertValueType("array"), assertEach(assertNodeType("Identifier", "Pattern", "RestElement")))
},
decorators: {
validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator")))

View File

@ -31,4 +31,28 @@ suite("validators", function () {
assert(t.isValidIdentifier("await") === false);
});
});
suite("patterns", function () {
it("allows nested pattern structures", function () {
const pattern = t.objectPattern([
t.objectProperty(
t.identifier("a"),
t.objectPattern([
t.objectProperty(
t.identifier("b"),
t.stringLiteral("foo")
),
t.objectProperty(
t.identifier("c"),
t.arrayPattern([
t.identifier("value"),
])
),
])
),
]);
assert(t.isNodesEquivalent(pattern, pattern) === true);
});
});
});