diff --git a/lib/6to5/transformation/transformers/other/react.js b/lib/6to5/transformation/transformers/other/react.js index 4059af0fc7..08ccc30356 100644 --- a/lib/6to5/transformation/transformers/other/react.js +++ b/lib/6to5/transformation/transformers/other/react.js @@ -65,7 +65,7 @@ exports.JSXOpeningElement = { var attribs = node.attributes; if (attribs.length) { - attribs = buildJSXOpeningElementAttributes(attribs); + attribs = buildJSXOpeningElementAttributes(attribs, file); } else { attribs = t.literal(null); } @@ -98,7 +98,7 @@ exports.JSXOpeningElement = { * all prior attributes to an array for later processing. */ -var buildJSXOpeningElementAttributes = function (attribs) { +var buildJSXOpeningElementAttributes = function (attribs, file) { var _props = []; var objs = []; @@ -132,7 +132,7 @@ var buildJSXOpeningElementAttributes = function (attribs) { // spread it attribs = t.callExpression( - t.memberExpression(t.identifier("React"), t.identifier("__spread")), + file.addHelper("extends"), objs ); } diff --git a/test/fixtures/transformation/react/adds-appropriate-newlines-when-using-spread-attribute/expected.js b/test/fixtures/transformation/react/adds-appropriate-newlines-when-using-spread-attribute/expected.js index 3912b9765a..07ab7b039f 100644 --- a/test/fixtures/transformation/react/adds-appropriate-newlines-when-using-spread-attribute/expected.js +++ b/test/fixtures/transformation/react/adds-appropriate-newlines-when-using-spread-attribute/expected.js @@ -1,2 +1,4 @@ -React.createElement(Component, React.__spread({}, props, { +var _extends = function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { target[key] = source[key]; } } return target; }; + +React.createElement(Component, _extends({}, props, { sound: "moo" })); diff --git a/test/fixtures/transformation/react/wraps-props-in-react-spread-for-first-spread-attributes/expected.js b/test/fixtures/transformation/react/wraps-props-in-react-spread-for-first-spread-attributes/expected.js index f6ef0b74ea..14458d027c 100644 --- a/test/fixtures/transformation/react/wraps-props-in-react-spread-for-first-spread-attributes/expected.js +++ b/test/fixtures/transformation/react/wraps-props-in-react-spread-for-first-spread-attributes/expected.js @@ -1 +1,3 @@ -React.createElement(Component, React.__spread({}, x, { y: 2, z: true })); +var _extends = function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { target[key] = source[key]; } } return target; }; + +React.createElement(Component, _extends({}, x, { y: 2, z: true })); diff --git a/test/fixtures/transformation/react/wraps-props-in-react-spread-for-last-spread-attributes/expected.js b/test/fixtures/transformation/react/wraps-props-in-react-spread-for-last-spread-attributes/expected.js index a1651713c2..63e4875f71 100644 --- a/test/fixtures/transformation/react/wraps-props-in-react-spread-for-last-spread-attributes/expected.js +++ b/test/fixtures/transformation/react/wraps-props-in-react-spread-for-last-spread-attributes/expected.js @@ -1 +1,3 @@ -React.createElement(Component, React.__spread({ y: 2, z: true }, x)); +var _extends = function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { target[key] = source[key]; } } return target; }; + +React.createElement(Component, _extends({ y: 2, z: true }, x)); diff --git a/test/fixtures/transformation/react/wraps-props-in-react-spread-for-middle-spread-attributes/expected.js b/test/fixtures/transformation/react/wraps-props-in-react-spread-for-middle-spread-attributes/expected.js index 9f3084024a..7fcdfabd30 100644 --- a/test/fixtures/transformation/react/wraps-props-in-react-spread-for-middle-spread-attributes/expected.js +++ b/test/fixtures/transformation/react/wraps-props-in-react-spread-for-middle-spread-attributes/expected.js @@ -1 +1,3 @@ -React.createElement(Component, React.__spread({ y: 2 }, x, { z: true })); +var _extends = function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { target[key] = source[key]; } } return target; }; + +React.createElement(Component, _extends({ y: 2 }, x, { z: true }));