Fix multiple var declarations in transform-react-constant-elements (#5732) (#5756)

This was broken by a legacy attachment path conditional that
is no longer needed.
This commit is contained in:
Samuel Reed 2017-05-22 16:46:53 -05:00 committed by Henry Zhu
parent c6eab0c206
commit 853b9f8ece
5 changed files with 26 additions and 12 deletions

View File

@ -4,8 +4,9 @@ export default class App extends React.Component {
} }
} }
const _ref2 = <div>child</div>, var _ref2 = <div>child</div>;
AppItem = () => {
const AppItem = () => {
return _ref2; return _ref2;
}, },
_ref = <div> _ref = <div>

View File

@ -0,0 +1,5 @@
import React from 'react';
import Loader from 'loader';
const errorComesHere = () => <Loader className="full-height"/>,
thisWorksFine = () => <Loader className="p-y-5"/>;

View File

@ -0,0 +1,9 @@
import React from 'react';
import Loader from 'loader';
var _ref = <Loader className="full-height" />;
var _ref2 = <Loader className="p-y-5" />;
const errorComesHere = () => _ref,
thisWorksFine = () => _ref2;

View File

@ -4,10 +4,11 @@ const Parent = ({}) => _ref;
export default Parent; export default Parent;
let _ref2 = <div className="child"> var _ref2 = <div className="child">
ChildTextContent ChildTextContent
</div>, </div>;
Child = () => _ref2,
let Child = () => _ref2,
_ref = <div className="parent"> _ref = <div className="parent">
<Child /> <Child />
</div>; </div>;

View File

@ -172,12 +172,10 @@ export default class PathHoister {
// Beginning of the scope // Beginning of the scope
!path.parentPath || !path.parentPath ||
// Has siblings and is a statement // Has siblings and is a statement
(Array.isArray(path.container) && path.isStatement()) || (Array.isArray(path.container) && path.isStatement())
// Is part of multiple var declarations ) {
(path.isVariableDeclarator() && return path;
path.parentPath.node !== null && }
path.parentPath.node.declarations.length > 1))
{return path;}
} while ((path = path.parentPath)); } while ((path = path.parentPath));
} }