Fix ObjectProperty patterns (#5762)
* Fix Object Property values to allow Patterns * Add RestElement to allowed types * add tests for nested pattern structures
This commit is contained in:
parent
853b9f8ece
commit
8772e7fb89
@ -526,7 +526,7 @@ defineType("ObjectProperty", {
|
||||
},
|
||||
},
|
||||
value: {
|
||||
validate: assertNodeType("Expression"),
|
||||
validate: assertNodeType("Expression", "Pattern", "RestElement"),
|
||||
},
|
||||
shorthand: {
|
||||
validate: assertValueType("boolean"),
|
||||
|
||||
@ -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