babel-plugin-fuck-optimization
Advanced tools
Comparing version 1.0.0 to 2.0.0
{ | ||
"name": "babel-plugin-fuck-optimization", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Plugin for Babel which fucks all the optimizations in your code", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"test": "node test/index.test.js" | ||
"test": "node --allow-natives-syntax test/index.test.js" | ||
}, | ||
"author": "ghaiklor", | ||
"contributors": [ | ||
"bniwredyc" | ||
], | ||
"license": "MIT", | ||
@@ -11,0 +14,0 @@ "devDependencies": { |
@@ -17,14 +17,13 @@ # babel-plugin-fuck-optimization | ||
function add(a, b) { | ||
try {} catch (e) {} finally {} | ||
var deoptimization = { | ||
var __deoptimization = { | ||
__proto__: "notsofast" | ||
}; | ||
with (deoptimization) { | ||
return a + b; | ||
} | ||
return a + b; | ||
} | ||
``` | ||
It traverses all the `BlockStatement` and if its parent is `FunctionDeclaration` | ||
it pushes the new `TryStatement` with `CatchClause` within the `BlockStatement`. | ||
It traverses all the `BlockStatement` and if its parent is `FunctionDeclaration` or `ClassMethod` | ||
~~it pushes the new `TryStatement` with `CatchClause` within the `BlockStatement`~~ (optimized in V8 5.3.1) | ||
it adds an object literal declaration with modified `__proto__` property. | ||
@@ -0,1 +1,3 @@ | ||
var deoptimizationVariableName = '__deoptimization' | ||
module.exports = function (babel) { | ||
@@ -15,17 +17,5 @@ var t = babel.types; | ||
var oldBody = path.node.body.slice(0); | ||
path.node.body.length = 0; | ||
var tryCatchStatement = t.tryStatement( | ||
t.blockStatement([]), | ||
t.catchClause(t.identifier('e'), t.blockStatement([])), | ||
t.blockStatement([]) | ||
); | ||
path.node.body.push(tryCatchStatement); | ||
var deoptimizationVariableDeclaration = t.variableDeclaration('var', [ | ||
t.variableDeclarator( | ||
t.identifier('deoptimization'), | ||
t.identifier(deoptimizationVariableName), | ||
t.objectExpression([ | ||
@@ -37,10 +27,3 @@ t.objectProperty(t.Identifier('__proto__'), t.stringLiteral('notsofast')) | ||
path.node.body.push(deoptimizationVariableDeclaration); | ||
var withStatement = t.withStatement( | ||
t.identifier('deoptimization'), | ||
t.blockStatement(oldBody) | ||
); | ||
path.node.body.push(withStatement); | ||
path.node.body.unshift(deoptimizationVariableDeclaration); | ||
} | ||
@@ -47,0 +30,0 @@ } |
var babel = require('babel-core'); | ||
var plugin = require('../src/index.js'); | ||
var INPUT_SOURCE = 'function add(a, b) {return a + b;}'; | ||
var INPUT_SOURCE = 'function testFunction(a, b) {return a + b;}'; | ||
console.log('Transforming: \n' + INPUT_SOURCE + '\n'); | ||
var out = babel.transform(INPUT_SOURCE, {plugins: [plugin]}); | ||
var out = babel.transform(INPUT_SOURCE, { plugins: [plugin] }); | ||
console.log('Transformed to: \n' + out.code + '\n'); | ||
out.code.replace('testFunction', 'deoptimizedTestFunction'); | ||
function testFunction(a, b) { | ||
return a + b; | ||
} | ||
function deoptimizedTestFunction(a, b) { | ||
var __deoptimization = { | ||
__proto__: "notsofast" | ||
}; | ||
return a + b; | ||
} | ||
function printStatus(fn) { | ||
switch (%GetOptimizationStatus(fn)) { | ||
case 1: | ||
console.log("Function is optimized"); | ||
break; | ||
case 2: | ||
console.log("Function is not optimized"); | ||
break; | ||
case 3: | ||
console.log("Function is always optimized"); | ||
break; | ||
case 4: | ||
console.log("Function is never optimized"); | ||
break; | ||
case 6: | ||
console.log("Function is maybe deoptimized"); | ||
break; | ||
case 7: | ||
console.log("Function is optimized by TurboFan"); | ||
break; | ||
default: | ||
console.log("Unknown optimization status"); | ||
break; | ||
} | ||
} | ||
//Fill type-info | ||
testFunction(2, 2); | ||
// 2 calls are needed to go from uninitialized -> pre-monomorphic -> monomorphic | ||
testFunction(2, 2); | ||
%OptimizeFunctionOnNextCall(testFunction); | ||
//The next call | ||
testFunction(2, 2); | ||
//Check | ||
printStatus(testFunction); | ||
//Fill type-info | ||
deoptimizedTestFunction(2, 2); | ||
// 2 calls are needed to go from uninitialized -> pre-monomorphic -> monomorphic | ||
deoptimizedTestFunction(2, 2); | ||
%OptimizeFunctionOnNextCall(deoptimizedTestFunction); | ||
//The next call | ||
deoptimizedTestFunction(2, 2); | ||
//Check | ||
printStatus(deoptimizedTestFunction); |
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
4683
84
29