Fix PathHoister hoisting before a same-scope variable declaration.

Seems we didn't have tests running for this very simple case.

Also fixes #5520
This commit is contained in:
Samuel Reed 2017-05-01 15:22:26 -05:00 committed by Logan Smyth
parent 526a7d20ef
commit c307bbb3a9
8 changed files with 59 additions and 4 deletions

View File

@ -0,0 +1,9 @@
export default {
async function(name) {
const uppercasedName = name.upperCase();
// awaits depending on uppercasedName go here
return (<Foo name={uppercasedName} />);
}
};

View File

@ -0,0 +1,13 @@
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; }
export default {
function(name) {
return _asyncToGenerator(function* () {
const uppercasedName = name.upperCase();
// awaits depending on uppercasedName go here
return <Foo name={uppercasedName} />;
})();
}
};

View File

@ -0,0 +1,3 @@
{
"plugins": ["transform-async-to-generator", "transform-react-constant-elements", "syntax-jsx"]
}

View File

@ -0,0 +1,6 @@
function fn(Component, obj) {
var data = obj.data;
return () => <Component prop={data} />;
}

View File

@ -0,0 +1,7 @@
function fn(Component, obj) {
var data = obj.data,
_ref = <Component prop={data} />;
return () => _ref;
}

View File

@ -0,0 +1,6 @@
function fn(Component) {
var data = "prop";
return () => <Component prop={data} />;
}

View File

@ -0,0 +1,7 @@
function fn(Component) {
var data = "prop",
_ref = <Component prop={data} />;
return () => _ref;
}

View File

@ -99,11 +99,15 @@ export default class PathHoister {
const binding = this.bindings[name];
// allow parameter references
if (binding.kind === "param") continue;
// allow parameter references and expressions in params (like destructuring rest)
if (binding.kind === "param" || binding.path.parentKey === "params") continue;
// if this binding appears after our attachment point, then we move after it.
if (this.getAttachmentParentForPath(binding.path).key > path.key) {
// For each binding, get its attachment parent. This gives us an idea of where we might
// introduce conflicts.
const bindingParentPath = this.getAttachmentParentForPath(binding.path);
// If the binding's attachment appears at or after our attachment point, then we move after it.
if (bindingParentPath.key >= path.key) {
this.attachAfter = true;
path = binding.path;