From 8772e7fb898f76196c38598fc33e45c738100010 Mon Sep 17 00:00:00 2001 From: Bo Lingen Date: Mon, 22 May 2017 19:24:19 -0500 Subject: [PATCH] Fix ObjectProperty patterns (#5762) * Fix Object Property values to allow Patterns * Add RestElement to allowed types * add tests for nested pattern structures --- packages/babel-types/src/definitions/core.js | 2 +- packages/babel-types/test/validators.js | 24 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/babel-types/src/definitions/core.js b/packages/babel-types/src/definitions/core.js index 1e206ac50e..d86cc05c20 100644 --- a/packages/babel-types/src/definitions/core.js +++ b/packages/babel-types/src/definitions/core.js @@ -526,7 +526,7 @@ defineType("ObjectProperty", { }, }, value: { - validate: assertNodeType("Expression"), + validate: assertNodeType("Expression", "Pattern", "RestElement"), }, shorthand: { validate: assertValueType("boolean"), diff --git a/packages/babel-types/test/validators.js b/packages/babel-types/test/validators.js index ccc83f665b..8ad737b00b 100644 --- a/packages/babel-types/test/validators.js +++ b/packages/babel-types/test/validators.js @@ -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); + }); + }); });