babel-plugin-minify-simplify
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -5,3 +5,3 @@ "use strict"; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
@@ -169,4 +169,4 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
var EX = types.Expression; | ||
var LE = types.LogicalExpression; | ||
var EX = types.Expression, | ||
LE = types.LogicalExpression; | ||
@@ -408,3 +408,20 @@ // Convention: | ||
if (prev.isVariableDeclaration()) { | ||
if (!node.init) { | ||
var referencedOutsideLoop = false; | ||
// we don't care if vars are referenced outside the loop as they are fn scope | ||
if (prev.node.kind === "let" || prev.node.kind === "const") { | ||
var ids = Object.keys(prev.getBindingIdentifiers()); | ||
idloop: for (var i = 0; i < ids.length; i++) { | ||
var refs = prev.scope.bindings[ids[i]].referencePaths; | ||
for (var j = 0; j < refs.length; j++) { | ||
if (!isAncestor(path, refs[j])) { | ||
referencedOutsideLoop = true; | ||
break idloop; | ||
} | ||
} | ||
} | ||
} | ||
if (!node.init && !referencedOutsideLoop) { | ||
node.init = prev.node; | ||
@@ -544,4 +561,4 @@ consumed = true; | ||
enter: function enter(path) { | ||
var node = path.node; | ||
var parent = path.parent; | ||
var node = path.node, | ||
parent = path.parent; | ||
@@ -578,4 +595,4 @@ | ||
exit: function exit(path) { | ||
var node = path.node; | ||
var parent = path.parent; | ||
var node = path.node, | ||
parent = path.parent; | ||
@@ -1062,6 +1079,6 @@ | ||
var cond = consTestPairs.reduceRight(function (alt, _ref5) { | ||
var _ref6 = _slicedToArray(_ref5, 2); | ||
var _ref6 = _slicedToArray(_ref5, 2), | ||
test = _ref6[0], | ||
cons = _ref6[1]; | ||
var test = _ref6[0]; | ||
var cons = _ref6[1]; | ||
return t.conditionalExpression(test, cons, alt); | ||
@@ -1126,7 +1143,6 @@ }, defaultRet.argument || VOID_0); | ||
var _switchCase$consequen = _slicedToArray(switchCase.consequent, 2); | ||
var _switchCase$consequen = _slicedToArray(switchCase.consequent, 2), | ||
cons = _switchCase$consequen[0], | ||
breakStatement = _switchCase$consequen[1]; | ||
var cons = _switchCase$consequen[0]; | ||
var breakStatement = _switchCase$consequen[1]; | ||
if (switchCase === node.cases[node.cases.length - 1]) { | ||
@@ -1174,6 +1190,6 @@ if (breakStatement && !t.isBreakStatement(breakStatement)) { | ||
var cond = exprTestPairs.reduceRight(function (alt, _ref7) { | ||
var _ref8 = _slicedToArray(_ref7, 2); | ||
var _ref8 = _slicedToArray(_ref7, 2), | ||
test = _ref8[0], | ||
cons = _ref8[1]; | ||
var test = _ref8[0]; | ||
var cons = _ref8[1]; | ||
return t.conditionalExpression(test, cons, alt); | ||
@@ -1240,5 +1256,9 @@ }, defaultExpr || VOID_0); | ||
function needsBlock(node, parent) { | ||
return t.isFunction(parent) && node === parent.body || t.isTryStatement(parent) || t.isCatchClause(parent) || t.isSwitchStatement(parent); | ||
return t.isFunction(parent) && node === parent.body || t.isTryStatement(parent) || t.isCatchClause(parent) || t.isSwitchStatement(parent) || isSingleBlockScopeDeclaration(node) && t.isIfStatement(parent); | ||
} | ||
function isSingleBlockScopeDeclaration(block) { | ||
return t.isBlockStatement(block) && block.body.length === 1 && (t.isVariableDeclaration(block.body[0], { kind: "let" }) || t.isVariableDeclaration(block.body[0], { kind: "const" }) || t.isFunctionDeclaration(block.body[0])); | ||
} | ||
function isVoid0(expr) { | ||
@@ -1391,2 +1411,10 @@ return expr === VOID_0 || t.isUnaryExpression(expr, { operator: "void" }) && t.isNumericLiteral(expr.argument, { value: 0 }); | ||
} | ||
// path1 -> path2 | ||
// is path1 an ancestor of path2 | ||
function isAncestor(path1, path2) { | ||
return !!path2.findParent(function (parent) { | ||
return parent === path1; | ||
}); | ||
} | ||
}; |
{ | ||
"name": "babel-plugin-minify-simplify", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "", | ||
@@ -17,5 +17,5 @@ "homepage": "https://github.com/babel/babili#readme", | ||
"babel-helper-is-nodes-equiv": "^0.0.1", | ||
"babel-helper-to-multiple-sequence-expressions": "^0.0.1" | ||
"babel-helper-to-multiple-sequence-expressions": "^0.0.2" | ||
}, | ||
"devDependencies": {} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51687
1286
+ Addedbabel-helper-to-multiple-sequence-expressions@0.0.2(transitive)
- Removedbabel-helper-to-multiple-sequence-expressions@0.0.1(transitive)