fix: Don't hoist JSX elements referencing mutable variables (#13054)
issue-13051 Co-authored-by: Clint Goodman <clintgoodman@workfront.com>
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
var _span;
|
||||
|
||||
let foo = 'hello';
|
||||
|
||||
const mutate = () => {
|
||||
@@ -8,5 +6,5 @@ const mutate = () => {
|
||||
|
||||
export const Component = () => {
|
||||
if (Math.random() > 0.5) mutate();
|
||||
return _span || (_span = <span>{foo}</span>);
|
||||
return <span>{foo}</span>;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
var _span;
|
||||
|
||||
let foo = 'hello';
|
||||
export const Component = () => {
|
||||
foo = 'goodbye';
|
||||
return _span || (_span = <span>{foo}</span>);
|
||||
return <span>{foo}</span>;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
function render() {
|
||||
const nodes = [];
|
||||
|
||||
for(let i = 0; i < 5; i++) {
|
||||
nodes.push(<div>{i}</div>)
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
function render() {
|
||||
const nodes = [];
|
||||
|
||||
for (let i = 0; i < 5; i++) {
|
||||
nodes.push(<div>{i}</div>);
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
var _div;
|
||||
|
||||
var Foo = React.createClass({
|
||||
render: function render() {
|
||||
return _div || (_div = <div foo={notDeclared}></div>);
|
||||
return <div foo={notDeclared}></div>;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user