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:
Bo Lingen 2017-05-22 19:24:19 -05:00 committed by Henry Zhu
parent 853b9f8ece
commit 8772e7fb89
2 changed files with 25 additions and 1 deletions

View File

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

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);
});
});
});