checkpoint
This commit is contained in:
@@ -64,6 +64,7 @@ function Compressor(options, false_by_default) {
|
|||||||
evaluate : !false_by_default,
|
evaluate : !false_by_default,
|
||||||
booleans : !false_by_default,
|
booleans : !false_by_default,
|
||||||
dwloops : !false_by_default,
|
dwloops : !false_by_default,
|
||||||
|
hoist : !false_by_default,
|
||||||
|
|
||||||
warnings : true
|
warnings : true
|
||||||
});
|
});
|
||||||
@@ -140,7 +141,7 @@ function Compressor(options, false_by_default) {
|
|||||||
statements = eliminate_dead_code(statements, compressor);
|
statements = eliminate_dead_code(statements, compressor);
|
||||||
}
|
}
|
||||||
if (compressor.option("sequences")) {
|
if (compressor.option("sequences")) {
|
||||||
statements = sequencesize(statements);
|
statements = sequencesize(statements, compressor);
|
||||||
}
|
}
|
||||||
return statements;
|
return statements;
|
||||||
};
|
};
|
||||||
@@ -157,7 +158,7 @@ function Compressor(options, false_by_default) {
|
|||||||
}
|
}
|
||||||
return a;
|
return a;
|
||||||
}, []);
|
}, []);
|
||||||
}
|
};
|
||||||
|
|
||||||
function eliminate_dead_code(statements, compressor) {
|
function eliminate_dead_code(statements, compressor) {
|
||||||
var has_quit = false;
|
var has_quit = false;
|
||||||
@@ -194,7 +195,7 @@ function Compressor(options, false_by_default) {
|
|||||||
}
|
}
|
||||||
return a;
|
return a;
|
||||||
}, []);
|
}, []);
|
||||||
}
|
};
|
||||||
|
|
||||||
// XXX: this is destructive -- it modifies tree nodes.
|
// XXX: this is destructive -- it modifies tree nodes.
|
||||||
function sequencesize(statements) {
|
function sequencesize(statements) {
|
||||||
@@ -227,7 +228,7 @@ function Compressor(options, false_by_default) {
|
|||||||
return a;
|
return a;
|
||||||
}, []);
|
}, []);
|
||||||
return statements;
|
return statements;
|
||||||
}
|
};
|
||||||
|
|
||||||
/* -----[ boolean/negation helpers ]----- */
|
/* -----[ boolean/negation helpers ]----- */
|
||||||
|
|
||||||
@@ -479,6 +480,18 @@ function Compressor(options, false_by_default) {
|
|||||||
return self;
|
return self;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
SQUEEZE(AST_Scope, function(self, compressor){
|
||||||
|
self = self.clone();
|
||||||
|
self.hoist_declarations(compressor);
|
||||||
|
self.body = tighten_body(self.body, compressor);
|
||||||
|
return self;
|
||||||
|
});
|
||||||
|
|
||||||
|
AST_Scope.DEFMETHOD("hoist_declarations", function(compressor){
|
||||||
|
if (compressor.option("hoist")) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
SQUEEZE(AST_EmptyStatement, function(self, compressor){
|
SQUEEZE(AST_EmptyStatement, function(self, compressor){
|
||||||
return self;
|
return self;
|
||||||
});
|
});
|
||||||
@@ -559,6 +572,7 @@ function Compressor(options, false_by_default) {
|
|||||||
// “has no side effects”; also it doesn't work for cases like
|
// “has no side effects”; also it doesn't work for cases like
|
||||||
// `x && true`, though it probably should.
|
// `x && true`, though it probably should.
|
||||||
var cond = self.condition.evaluate(compressor);
|
var cond = self.condition.evaluate(compressor);
|
||||||
|
self.condition = cond[0];
|
||||||
if (cond.length == 2) {
|
if (cond.length == 2) {
|
||||||
if (cond[1]) {
|
if (cond[1]) {
|
||||||
AST_Node.warn("Condition always true [{line},{col}]", self.condition.start);
|
AST_Node.warn("Condition always true [{line},{col}]", self.condition.start);
|
||||||
@@ -568,6 +582,13 @@ function Compressor(options, false_by_default) {
|
|||||||
return self.alternative || make_node(AST_EmptyStatement, self);
|
return self.alternative || make_node(AST_EmptyStatement, self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (self.condition instanceof AST_UnaryPrefix
|
||||||
|
&& self.condition.operator == "!") {
|
||||||
|
self.condition = self.condition.expression;
|
||||||
|
var tmp = self.body;
|
||||||
|
self.body = self.alternative || make_node(AST_EmptyStatement, self);
|
||||||
|
self.alternative = tmp;
|
||||||
|
}
|
||||||
if (self.body instanceof AST_SimpleStatement
|
if (self.body instanceof AST_SimpleStatement
|
||||||
&& self.alternative instanceof AST_SimpleStatement) {
|
&& self.alternative instanceof AST_SimpleStatement) {
|
||||||
return make_node(AST_SimpleStatement, self, {
|
return make_node(AST_SimpleStatement, self, {
|
||||||
@@ -578,7 +599,9 @@ function Compressor(options, false_by_default) {
|
|||||||
}).optimize(compressor)
|
}).optimize(compressor)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if ((!self.alternative || self.alternative instanceof AST_EmptyStatement) && self.body instanceof AST_SimpleStatement) {
|
if ((!self.alternative
|
||||||
|
|| self.alternative instanceof AST_EmptyStatement)
|
||||||
|
&& self.body instanceof AST_SimpleStatement) {
|
||||||
return make_node(AST_SimpleStatement, self, {
|
return make_node(AST_SimpleStatement, self, {
|
||||||
body: make_node(AST_Binary, self, {
|
body: make_node(AST_Binary, self, {
|
||||||
operator : "&&",
|
operator : "&&",
|
||||||
@@ -589,7 +612,7 @@ function Compressor(options, false_by_default) {
|
|||||||
}
|
}
|
||||||
if (self.body instanceof AST_EmptyStatement
|
if (self.body instanceof AST_EmptyStatement
|
||||||
&& self.alternative
|
&& self.alternative
|
||||||
&& !(self.alternative instanceof AST_EmptyStatement)) {
|
&& self.alternative instanceof AST_SimpleStatement) {
|
||||||
return make_node(AST_SimpleStatement, self, {
|
return make_node(AST_SimpleStatement, self, {
|
||||||
body: make_node(AST_Binary, self, {
|
body: make_node(AST_Binary, self, {
|
||||||
operator : "||",
|
operator : "||",
|
||||||
@@ -656,6 +679,7 @@ function Compressor(options, false_by_default) {
|
|||||||
|
|
||||||
SQUEEZE(AST_Lambda, function(self, compressor){
|
SQUEEZE(AST_Lambda, function(self, compressor){
|
||||||
self = self.clone();
|
self = self.clone();
|
||||||
|
self.hoist_declarations(compressor);
|
||||||
if (self.name) self.name = self.name.squeeze(compressor);
|
if (self.name) self.name = self.name.squeeze(compressor);
|
||||||
self.argnames = do_list(self.argnames, compressor);
|
self.argnames = do_list(self.argnames, compressor);
|
||||||
self.body = self.body.squeeze(compressor);
|
self.body = self.body.squeeze(compressor);
|
||||||
|
|||||||
12
lib/scope.js
12
lib/scope.js
@@ -165,6 +165,7 @@ AST_Toplevel.DEFMETHOD("scope_warnings", function(options){
|
|||||||
unreferenced : true,
|
unreferenced : true,
|
||||||
assign_to_global : true,
|
assign_to_global : true,
|
||||||
func_arguments : true,
|
func_arguments : true,
|
||||||
|
nested_defuns : true,
|
||||||
eval : true
|
eval : true
|
||||||
});
|
});
|
||||||
var tw = new TreeWalker(function(node){
|
var tw = new TreeWalker(function(node){
|
||||||
@@ -225,6 +226,17 @@ AST_Toplevel.DEFMETHOD("scope_warnings", function(options){
|
|||||||
col: node.start.col
|
col: node.start.col
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (options.nested_defuns
|
||||||
|
&& node instanceof AST_Defun
|
||||||
|
&& !(tw.parent() instanceof AST_Scope
|
||||||
|
|| (tw.parent() instanceof AST_BlockStatement
|
||||||
|
&& tw.parent(1) instanceof AST_Scope))) {
|
||||||
|
AST_Node.warn("Function {name} declared in nested statement [{line},{col}]", {
|
||||||
|
name: node.name.name,
|
||||||
|
line: node.start.line,
|
||||||
|
col: node.start.col
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.walk(tw);
|
this.walk(tw);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -145,9 +145,8 @@ var MAP = (function(){
|
|||||||
// feeling it works well in general for many scripts (well, better
|
// feeling it works well in general for many scripts (well, better
|
||||||
// than alphabetical order). It would be nice if we could adapt it to
|
// than alphabetical order). It would be nice if we could adapt it to
|
||||||
// the currently running script.
|
// the currently running script.
|
||||||
// var BASE54_DIGITS = "etnrisouaflchpdvmgybwESxTNCkLAOM_DPHBjFIqRUzWXV$JKQGYZ0516372984";
|
var BASE54_DIGITS = "etnrisouaflchpdvmgybwESxTNCkLAOM_DPHBjFIqRUzWXV$JKQGYZ0516372984";
|
||||||
|
//var BASE54_DIGITS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_0123456789";
|
||||||
var BASE54_DIGITS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_0123456789";
|
|
||||||
|
|
||||||
function base54(num) {
|
function base54(num) {
|
||||||
var ret = "", base = 54;
|
var ret = "", base = 54;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ time_it("scope", function(){
|
|||||||
ast.figure_out_scope();
|
ast.figure_out_scope();
|
||||||
});
|
});
|
||||||
|
|
||||||
// ast.scope_warnings();
|
ast.scope_warnings();
|
||||||
|
|
||||||
time_it("mangle", function(){
|
time_it("mangle", function(){
|
||||||
ast.mangle_names();
|
ast.mangle_names();
|
||||||
|
|||||||
Reference in New Issue
Block a user