Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Commit

Permalink
Fix no-wrapper optimization in conditional expression's test
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Nov 27, 2016
1 parent e40995d commit d9462c5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/helpers/is-child-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ function ancestorPath(path, useFastRoot) {
continue;
}
} else if (path.isConditionalExpression()) {
if (last.key === 'test') {
break;
}

continue;
} else if (path.isLogicalExpression()) {
if (path.get("right") === last || path.node.operator === "||") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ function render() {
</div> :
<other />
}
{<div /> ? 1 : 2}
</div>;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
var _jsxWrapper = function _jsxWrapper(func, args) {
var wrapper = args ? function wrapper() {
return func.apply(this, args);
} : func;
wrapper.__jsxDOMWrapper = true;
return wrapper;
};

var _hasOwn = Object.prototype.hasOwnProperty;

var _forOwn = function _forOwn(object, iterator) {
Expand All @@ -20,6 +28,10 @@ var _renderArbitrary = function _renderArbitrary(child) {
}
};

var _wrapper = function _wrapper() {
return elementVoid("div");
};

function getDiv() {
elementOpen("div");
text("Bottom");
Expand All @@ -31,5 +43,7 @@ function render() {

_renderArbitrary(true ? (elementOpen("div"), (elementOpen("div"), text("Top"), elementClose("div")), _renderArbitrary(getDiv()), elementClose("div")) : elementVoid("other"));

_renderArbitrary(_jsxWrapper(_wrapper) ? 1 : 2);

return elementClose("div");
}

0 comments on commit d9462c5

Please sign in to comment.