From 51a293601b417b329a8ee96267d13f3425cb74d6 Mon Sep 17 00:00:00 2001 From: Noah Lemen Date: Tue, 25 Jul 2017 09:30:32 -0400 Subject: [PATCH] add JSXAttribute visitor function, wraps JSXElement attributes in a JSXExpressionContainer; also adds test fixtures (#6006) --- packages/babel-plugin-transform-react-jsx/src/index.js | 6 ++++++ .../react/should-allow-elements-as-attributes/actual.js | 1 + .../react/should-allow-elements-as-attributes/expected.js | 3 +++ 3 files changed, 10 insertions(+) create mode 100644 packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-allow-elements-as-attributes/actual.js create mode 100644 packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-allow-elements-as-attributes/expected.js diff --git a/packages/babel-plugin-transform-react-jsx/src/index.js b/packages/babel-plugin-transform-react-jsx/src/index.js index 5b119cb6f6..60cb13d3a1 100644 --- a/packages/babel-plugin-transform-react-jsx/src/index.js +++ b/packages/babel-plugin-transform-react-jsx/src/index.js @@ -47,6 +47,12 @@ export default function({ types: t }) { ); }; + visitor.JSXAttribute = function(path) { + if (t.isJSXElement(path.node.value)) { + path.node.value = t.jSXExpressionContainer(path.node.value); + } + }; + return { inherits: jsx, visitor, diff --git a/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-allow-elements-as-attributes/actual.js b/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-allow-elements-as-attributes/actual.js new file mode 100644 index 0000000000..240f6d37ae --- /dev/null +++ b/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-allow-elements-as-attributes/actual.js @@ -0,0 +1 @@ +
/> diff --git a/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-allow-elements-as-attributes/expected.js b/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-allow-elements-as-attributes/expected.js new file mode 100644 index 0000000000..23783424a4 --- /dev/null +++ b/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-allow-elements-as-attributes/expected.js @@ -0,0 +1,3 @@ +React.createElement("div", { + attr: React.createElement("div", null) +}); \ No newline at end of file