inline-loops.macro
Advanced tools
Comparing version 2.0.3 to 2.0.4
## CHANGELOG | ||
# 2.0.4 | ||
- [#37](https://github.com/planttheidea/inline-loops.macro/pull/37/files) - Smarter IIFE wrapper determination logic | ||
# 2.0.3 | ||
@@ -4,0 +8,0 @@ |
@@ -118,3 +118,3 @@ "use strict"; | ||
var t = _ref.types; | ||
if (shouldWrapInClosure(path, local)) { | ||
if (shouldWrapInClosure(path)) { | ||
if (!t.isIdentifier(replacement, { | ||
@@ -154,4 +154,3 @@ name: 'undefined' | ||
} | ||
function shouldWrapInClosure(path, local) { | ||
var _functionParent$get; | ||
function shouldWrapInClosure(path) { | ||
var parentPath = path.parentPath; | ||
@@ -161,27 +160,23 @@ if (!parentPath) { | ||
} | ||
var functionParent = path.getFunctionParent(); | ||
if (!functionParent) { | ||
return isPossiblyDynamic(parentPath); | ||
} | ||
var grandparentPath = parentPath.parentPath; | ||
if (parentPath.isPattern() || local.contents.length > 1) { | ||
if (parentPath.isAssignmentPattern()) { | ||
return true; | ||
} | ||
var contents = functionParent === null || functionParent === void 0 || (_functionParent$get = functionParent.get('body')) === null || _functionParent$get === void 0 ? void 0 : _functionParent$get.get('body'); | ||
if (Array.isArray(contents) && contents.length > 1) { | ||
return contents.flat().some(function (content) { | ||
return content.isVariableDeclaration(); | ||
}); | ||
if (parentPath.isArrayExpression() || parentPath.isAwaitExpression() || parentPath.isBinaryExpression() || parentPath.isJSXElement() || parentPath.isJSXExpressionContainer() || parentPath.isObjectExpression() || parentPath.isObjectProperty() || parentPath.isUnaryExpression()) { | ||
return shouldWrapInClosure(parentPath); | ||
} | ||
if (!grandparentPath || !parentPath.isExpression()) { | ||
return false; | ||
} | ||
var maybeNestedConditional = isPossiblyDynamic(grandparentPath); | ||
if (parentPath.isLogicalExpression()) { | ||
return !maybeNestedConditional && parentPath.get('right').node === path.node; | ||
return !path.isCallExpression() || parentPath.get('right').node === path.node || shouldWrapInClosure(parentPath); | ||
} | ||
if (parentPath.isConditionalExpression()) { | ||
return !maybeNestedConditional && parentPath.get('test').node !== path.node; | ||
return !path.isCallExpression() || parentPath.get('test').node !== path.node || shouldWrapInClosure(parentPath); | ||
} | ||
return maybeNestedConditional; | ||
var functionParent = path.getFunctionParent(); | ||
if (!functionParent || parentPath.node === functionParent.node || parentPath.parent === functionParent.node) { | ||
return false; | ||
} | ||
if ((parentPath.isReturnStatement() || parentPath.isExpressionStatement()) && parentPath.parentPath.isBlockStatement() && parentPath.parentPath.parent === functionParent.node) { | ||
var body = functionParent.get('body.body'); | ||
return !Array.isArray(body) || body.length > 1; | ||
} | ||
return true; | ||
} |
@@ -61,3 +61,3 @@ { | ||
"typings": "./index.d.ts", | ||
"version": "2.0.3" | ||
"version": "2.0.4" | ||
} |
70583
1290