only skip traversal of immutable JSX elements in the optimisation.react.constantElements transformer when we've actually hoisted them - closes #1344

This commit is contained in:
Sebastian McKenzie
2015-04-24 19:28:51 +01:00
parent 6e4e11a365
commit 63344eb0a4
4 changed files with 30 additions and 2 deletions

View File

@@ -33,9 +33,11 @@ export function JSXElement(node, parent, scope, file) {
var state = { isImmutable: true };
this.traverse(immutabilityVisitor, state);
this.skip();
if (state.isImmutable) this.hoist();
if (state.isImmutable) {
this.hoist();
this.skip();
}
node._hoisted = true;
}

View File

@@ -109,6 +109,14 @@ export default class PathHoister {
])
]);
var parent = this.path.parentPath;
if (parent.isJSXElement() && this.path.container === parent.node.children) {
// turning the `span` in `<div><span /></div>` to an expression so we need to wrap it with
// an expression container
uid = t.jSXExpressionContainer(uid);
}
this.path.replaceWith(uid);
}
}