babel-plugin-closure-elimination
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -0,1 +1,4 @@ | ||
/** | ||
* # Closure Eliminator | ||
*/ | ||
"use strict"; | ||
@@ -9,5 +12,2 @@ | ||
/** | ||
* # Closure Eliminator | ||
*/ | ||
exports["default"] = build; | ||
@@ -135,7 +135,7 @@ | ||
if (node.type === "FunctionDeclaration") { | ||
var uid = this.path.parentPath.scope.generateUidBasedOnNode(node.id); | ||
if (node.type === 'FunctionDeclaration') { | ||
var uid = this.path.parentPath.scope.generateUidIdentifierBasedOnNode(node.id); | ||
this.path.parentPath.scope.rename(node.id.name, uid.name); | ||
path.insertBefore([node]); | ||
this.path.remove(); | ||
this.path.dangerouslyRemove(); | ||
} else { | ||
@@ -158,29 +158,21 @@ var uid = path.scope.generateUidIdentifier("ref"); | ||
enter: function enter(node, parent, scope) { | ||
var _this = this; | ||
var parentScope = scope.parent.getFunctionParent(); | ||
if (parent.type === "Program" || parentScope.block.type === "Program" || parent.type === "CallExpression" && parent.callee === node) { | ||
if (parent.type === 'Program' || parentScope.block.type === 'Program' || parent.type === 'CallExpression' && parent.callee === node) { | ||
return; | ||
} | ||
if (node.type === "ArrowFunctionExpression") { | ||
var _ret = (function () { | ||
var isCompatible = true; | ||
_this.traverse({ | ||
enter: function enter(node) { | ||
if (node.type === "ThisExpression") { | ||
isCompatible = false; | ||
this.stop(); | ||
} else if (this.isFunction() && node.type !== "ArrowFunctionExpression") { | ||
this.skip(); | ||
} | ||
if (node.type === 'ArrowFunctionExpression') { | ||
var isCompatible = true; | ||
this.traverse({ | ||
enter: function enter(node) { | ||
if (node.type === 'ThisExpression') { | ||
isCompatible = false; | ||
this.stop(); | ||
} else if (this.isFunction() && node.type !== 'ArrowFunctionExpression') { | ||
this.skip(); | ||
} | ||
}); | ||
if (!isCompatible) { | ||
return { | ||
v: undefined | ||
}; | ||
} | ||
})(); | ||
if (typeof _ret === "object") return _ret.v; | ||
}); | ||
if (!isCompatible) { | ||
return; | ||
} | ||
} | ||
@@ -197,3 +189,3 @@ var hoister = new PathHoister(this, this.parentPath.scope); | ||
function normalizeFunctionBody(node) { | ||
if (node.type !== "BlockStatement") { | ||
if (node.type !== 'BlockStatement') { | ||
return t.blockStatement([t.returnStatement(node)]); | ||
@@ -200,0 +192,0 @@ } else { |
{ | ||
"name": "babel-plugin-closure-elimination", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Removes closures from your JavaScript in the name of performance.", | ||
@@ -33,4 +33,4 @@ "main": "lib/index.js", | ||
"should": "^6.0.1", | ||
"babel": "^5.0.0" | ||
"babel": "^5.5.0" | ||
} | ||
} |
@@ -120,6 +120,6 @@ /** | ||
if (node.type === 'FunctionDeclaration') { | ||
let uid = this.path.parentPath.scope.generateUidBasedOnNode(node.id); | ||
let uid = this.path.parentPath.scope.generateUidIdentifierBasedOnNode(node.id); | ||
this.path.parentPath.scope.rename(node.id.name, uid.name); | ||
path.insertBefore([node]); | ||
this.path.remove(); | ||
this.path.dangerouslyRemove(); | ||
} | ||
@@ -190,2 +190,2 @@ else { | ||
} | ||
} | ||
} |
@@ -42,3 +42,3 @@ import Plugin from '../src'; | ||
const transformedWithPlugin = transform(source, {stage: 0, plugins: [Plugin]}); | ||
// console.log(transformedWithPlugin.code); | ||
//console.log(transformedWithPlugin.code); | ||
const diff = countHoisted(transformedNaked.ast, transformedWithPlugin.ast); | ||
@@ -80,2 +80,3 @@ diff.should.equal(numberToRemove); | ||
eliminate("twice", 2); | ||
eliminate("complex", 14); | ||
eliminate("inner-1", 2); | ||
@@ -82,0 +83,0 @@ eliminate("no-hoist", 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
22050
25
607