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>,
AppItem = () => {
var _ref2 = <div>child</div>;
const AppItem = () => {
return _ref2;
},
_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;
let _ref2 = <div className="child">
var _ref2 = <div className="child">
ChildTextContent
</div>,
Child = () => _ref2,
</div>;
let Child = () => _ref2,
_ref = <div className="parent">
<Child />
</div>;

View File

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