Fix constant elements hoisted out of block (#4419)

When block scoped variables caused the block to be wrapped in a closure, the variable `bindings` remained in parent function scope, which caused the JSX element to be hoisted out of the closure.
This commit is contained in:
Scott Kyle
2016-12-03 12:14:34 -08:00
parent 27e201e0e1
commit 5a9509205b
4 changed files with 43 additions and 3 deletions

View File

@@ -0,0 +1,11 @@
function render(flag) {
if (flag) {
let bar = "bar";
[].map(() => bar);
return <foo bar={bar} />;
}
return null;
}

View File

@@ -0,0 +1,17 @@
function render(flag) {
if (flag) {
var _ret = function () {
var bar = "bar";
[].map(() => bar);
return {
v: <foo bar={bar} />
};
}();
if (typeof _ret === "object") return _ret.v;
}
return null;
}

View File

@@ -0,0 +1,7 @@
{
"plugins": [
"syntax-jsx",
"transform-es2015-block-scoping",
"transform-react-constant-elements"
]
}