babel-plugin-closure-elimination
Advanced tools
Comparing version 1.1.12 to 1.1.13
@@ -68,11 +68,9 @@ 'use strict'; | ||
function _getAttachmentPositio(bestParent, prevPath) { | ||
var possibleSiblings = void 0; | ||
if (bestParent.isFunction()) { | ||
possibleSiblings = bestParent.get('body.body'); | ||
} else if (bestParent.isProgram() || bestParent.isBlockStatement()) { | ||
possibleSiblings = bestParent.get('body'); | ||
var prevParents = prevPath.getAncestry(), | ||
bestParentIdx = prevParents.indexOf(bestParent); | ||
if (-1 === bestParentIdx) { | ||
throw new Error('Possible parent not really in ancestry'); | ||
} | ||
var prevParents = prevPath.getAncestry(); | ||
return possibleSiblings.find(function (x) { | ||
return prevParents.indexOf(x) !== -1; | ||
return prevParents.slice(1, bestParentIdx).reverse().find(function (path) { | ||
return (path.parentPath.isBlockStatement() || path.parentPath.isProgram()) && path.parentPath.scope !== prevPath.parentPath.scope; | ||
}); | ||
@@ -110,5 +108,7 @@ } | ||
var attachPath = _getAttachmentPositio(bestParentScope.path, path); | ||
// _logAllProgram(path, 'before');// debug | ||
moveToNewPosition(path, attachPath); | ||
// _logAllProgram(path, 'after');// debug | ||
if (attachPath) { | ||
// _logAllProgram(path, 'before');// debug | ||
moveToNewPosition(path, attachPath); | ||
// _logAllProgram(path, 'after');// debug | ||
} | ||
} | ||
@@ -115,0 +115,0 @@ } |
{ | ||
"name": "babel-plugin-closure-elimination", | ||
"version": "1.1.12", | ||
"version": "1.1.13", | ||
"description": "Removes closures from your JavaScript in the name of performance.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -30,5 +30,7 @@ import 'babel-polyfill'; | ||
const attachPath = getAttachmentPosition(bestParentScope.path, path); | ||
// _logAllProgram(path, 'before');// debug | ||
moveToNewPosition(path, attachPath); | ||
// _logAllProgram(path, 'after');// debug | ||
if (attachPath) { | ||
// _logAllProgram(path, 'before');// debug | ||
moveToNewPosition(path, attachPath); | ||
// _logAllProgram(path, 'after');// debug | ||
} | ||
} | ||
@@ -94,10 +96,14 @@ } | ||
function getAttachmentPosition(bestParent, prevPath) { | ||
let possibleSiblings; | ||
if (bestParent.isFunction()) { | ||
possibleSiblings = bestParent.get('body.body'); | ||
} else if (bestParent.isProgram() || bestParent.isBlockStatement()) { | ||
possibleSiblings = bestParent.get('body'); | ||
const prevParents = prevPath.getAncestry(), | ||
bestParentIdx = prevParents.indexOf(bestParent); | ||
if (-1 === bestParentIdx) { | ||
throw new Error('Possible parent not really in ancestry'); | ||
} | ||
const prevParents = prevPath.getAncestry(); | ||
return possibleSiblings.find(x => prevParents.indexOf(x) !== -1); | ||
return prevParents | ||
.slice(1, bestParentIdx) | ||
.reverse() | ||
.find( | ||
path => (path.parentPath.isBlockStatement() || path.parentPath.isProgram()) && | ||
path.parentPath.scope !== prevPath.parentPath.scope | ||
); | ||
} | ||
@@ -122,3 +128,3 @@ | ||
); | ||
if(node.id && node.id.name) { | ||
if (node.id && node.id.name) { | ||
scope.rename(node.id.name, uid.name); | ||
@@ -125,0 +131,0 @@ } |
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
14359
308