var optimize = require('optimize');
optimize('console.log(1+1);'); //"console.log(2);"
zoltan-mihalyi / optimize Goto Github PK
View Code? Open in Web Editor NEWJavaScript code optimizer
JavaScript code optimizer
The name "a" is in a scope which is different from the scope of the block.
(function a(){
//a is accessible but can hide with local vars.
});
The same applies to this:
for (let a in x){
//a is accessible but can hide with local vars.
}
replace with the result of the expression
var a=1;
var a=2;
expected result:
var a=1;
a=2;
for (let j = 0; j < sub.length; j++) {
const lengthBefore = sub.length;
let result:T = (sub[j] as SemanticNode).walk(before);
j -= lengthBefore - sub.length;
if (result) {
return result;
}
}
var x=1;
var f=(function(x){return function(){return x}})(x)
x=2;
f(); //1
new RegExp("abc")
to /abc/
var i;
is removed in the code below:
var i;
for (i in obj) {
}
In IdentifierNode
This should be safe:
new Date(0).getTime()
let assignment, global vars...
In some cases (in angular optimization) we are removing directives.
Maybe it is a parser bug.
we could reduce not operator in the same way as we do in conditional reduction
a+=1
[].constructor.prototype.push.call([].constructor.prototype,1);
functions with a single return statement
a[0] is replaced by a["0"] .
Maybe a[0] was faster? Maybe just for arrays?
i = "radio";
Expr.pseudos[ i ] = createInputPseudo( i );
target=es5:
More native function can be substituted
target=es6:
More native functions and other optimizations
tested with angular.js
a = fn();
return a;
to
return fn();
use tracking
function fn() {
function declaration(){
}
return () => {
return [typeof arguments, typeof declaration];
}
declaration = function(){};
}
In the code above, the typeof expressions are predictable.
Use "effectiveValue" which is the all possible values of the variable. This should be used in try block tracking
var a=1; a=1;
to var a=1;
if else is not empty, create a negated version
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.