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:
parent
783d85ee4b
commit
0c8fdc381d
@ -526,7 +526,7 @@ defineType("ObjectProperty", {
|
||||
}
|
||||
},
|
||||
value: {
|
||||
validate: assertNodeType("Expression")
|
||||
validate: assertNodeType("Expression", "Pattern", "RestElement")
|
||||
},
|
||||
shorthand: {
|
||||
validate: assertValueType("boolean"),
|
||||
|
||||
@ -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")))
|
||||
|
||||
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user