提交 9670407c 编写于 作者: I ide user ide_gero3

add more nodejs buildsystem

上级 d2be9844
.DS_Store
.tmp*~
*.local.*
.pinf-*
\ No newline at end of file
此差异已折叠。
此差异已折叠。
#!/usr/bin/env node
// -*- js -*-
global.sys = require(/^v0\.[012]/.test(process.version) ? "sys" : "util");
var fs = require("fs");
var uglify = require("uglify-js"), // symlink ~/.node_libraries/uglify-js.js to ../uglify-js.js
consolidator = uglify.consolidator,
jsp = uglify.parser,
pro = uglify.uglify;
var options = {
ast: false,
consolidate: false,
mangle: true,
mangle_toplevel: false,
no_mangle_functions: false,
squeeze: true,
make_seqs: true,
dead_code: true,
verbose: false,
show_copyright: true,
out_same_file: false,
max_line_length: 32 * 1024,
unsafe: false,
reserved_names: null,
defines: { },
lift_vars: false,
codegen_options: {
ascii_only: false,
beautify: false,
indent_level: 4,
indent_start: 0,
quote_keys: false,
space_colon: false,
inline_script: false
},
make: false,
output: true // stdout
};
var args = jsp.slice(process.argv, 2);
var filename;
out: while (args.length > 0) {
var v = args.shift();
switch (v) {
case "-b":
case "--beautify":
options.codegen_options.beautify = true;
break;
case "-c":
case "--consolidate-primitive-values":
options.consolidate = true;
break;
case "-i":
case "--indent":
options.codegen_options.indent_level = args.shift();
break;
case "-q":
case "--quote-keys":
options.codegen_options.quote_keys = true;
break;
case "-mt":
case "--mangle-toplevel":
options.mangle_toplevel = true;
break;
case "-nmf":
case "--no-mangle-functions":
options.no_mangle_functions = true;
break;
case "--no-mangle":
case "-nm":
options.mangle = false;
break;
case "--no-squeeze":
case "-ns":
options.squeeze = false;
break;
case "--no-seqs":
options.make_seqs = false;
break;
case "--no-dead-code":
options.dead_code = false;
break;
case "--no-copyright":
case "-nc":
options.show_copyright = false;
break;
case "-o":
case "--output":
options.output = args.shift();
break;
case "--overwrite":
options.out_same_file = true;
break;
case "-v":
case "--verbose":
options.verbose = true;
break;
case "--ast":
options.ast = true;
break;
case "--unsafe":
options.unsafe = true;
break;
case "--max-line-len":
options.max_line_length = parseInt(args.shift(), 10);
break;
case "--reserved-names":
options.reserved_names = args.shift().split(",");
break;
case "--lift-vars":
options.lift_vars = true;
break;
case "-d":
case "--define":
var defarg = args.shift();
try {
var defsym = function(sym) {
// KEYWORDS_ATOM doesn't include NaN or Infinity - should we check
// for them too ?? We don't check reserved words and the like as the
// define values are only substituted AFTER parsing
if (jsp.KEYWORDS_ATOM.hasOwnProperty(sym)) {
throw "Don't define values for inbuilt constant '"+sym+"'";
}
return sym;
},
defval = function(v) {
if (v.match(/^"(.*)"$/) || v.match(/^'(.*)'$/)) {
return [ "string", RegExp.$1 ];
}
else if (!isNaN(parseFloat(v))) {
return [ "num", parseFloat(v) ];
}
else if (v.match(/^[a-z\$_][a-z\$_0-9]*$/i)) {
return [ "name", v ];
}
else if (!v.match(/"/)) {
return [ "string", v ];
}
else if (!v.match(/'/)) {
return [ "string", v ];
}
throw "Can't understand the specified value: "+v;
};
if (defarg.match(/^([a-z_\$][a-z_\$0-9]*)(=(.*))?$/i)) {
var sym = defsym(RegExp.$1),
val = RegExp.$2 ? defval(RegExp.$2.substr(1)) : [ 'name', 'true' ];
options.defines[sym] = val;
}
else {
throw "The --define option expects SYMBOL[=value]";
}
} catch(ex) {
sys.print("ERROR: In option --define "+defarg+"\n"+ex+"\n");
process.exit(1);
}
break;
case "--define-from-module":
var defmodarg = args.shift(),
defmodule = require(defmodarg),
sym,
val;
for (sym in defmodule) {
if (defmodule.hasOwnProperty(sym)) {
options.defines[sym] = function(val) {
if (typeof val == "string")
return [ "string", val ];
if (typeof val == "number")
return [ "num", val ];
if (val === true)
return [ 'name', 'true' ];
if (val === false)
return [ 'name', 'false' ];
if (val === null)
return [ 'name', 'null' ];
if (val === undefined)
return [ 'name', 'undefined' ];
sys.print("ERROR: In option --define-from-module "+defmodarg+"\n");
sys.print("ERROR: Unknown object type for: "+sym+"="+val+"\n");
process.exit(1);
return null;
}(defmodule[sym]);
}
}
break;
case "--ascii":
options.codegen_options.ascii_only = true;
break;
case "--make":
options.make = true;
break;
case "--inline-script":
options.codegen_options.inline_script = true;
break;
default:
filename = v;
break out;
}
}
if (options.verbose) {
pro.set_logger(function(msg){
sys.debug(msg);
});
}
jsp.set_logger(function(msg){
sys.debug(msg);
});
if (options.make) {
options.out_same_file = false; // doesn't make sense in this case
var makefile = JSON.parse(fs.readFileSync(filename || "Makefile.uglify.js").toString());
output(makefile.files.map(function(file){
var code = fs.readFileSync(file.name);
if (file.module) {
code = "!function(exports, global){global = this;\n" + code + "\n;this." + file.module + " = exports;}({})";
}
else if (file.hide) {
code = "(function(){" + code + "}());";
}
return squeeze_it(code);
}).join("\n"));
}
else if (filename) {
fs.readFile(filename, "utf8", function(err, text){
if (err) throw err;
output(squeeze_it(text));
});
}
else {
var stdin = process.openStdin();
stdin.setEncoding("utf8");
var text = "";
stdin.on("data", function(chunk){
text += chunk;
});
stdin.on("end", function() {
output(squeeze_it(text));
});
}
function output(text) {
var out;
if (options.out_same_file && filename)
options.output = filename;
if (options.output === true) {
out = process.stdout;
} else {
out = fs.createWriteStream(options.output, {
flags: "w",
encoding: "utf8",
mode: 0644
});
}
out.write(text.replace(/;*$/, ";"));
if (options.output !== true) {
out.end();
}
};
// --------- main ends here.
function show_copyright(comments) {
var ret = "";
for (var i = 0; i < comments.length; ++i) {
var c = comments[i];
if (c.type == "comment1") {
ret += "//" + c.value + "\n";
} else {
ret += "/*" + c.value + "*/";
}
}
return ret;
};
function squeeze_it(code) {
var result = "";
if (options.show_copyright) {
var tok = jsp.tokenizer(code), c;
c = tok();
result += show_copyright(c.comments_before);
}
try {
var ast = time_it("parse", function(){ return jsp.parse(code); });
if (options.consolidate) ast = time_it("consolidate", function(){
return consolidator.ast_consolidate(ast);
});
if (options.lift_vars) {
ast = time_it("lift", function(){ return pro.ast_lift_variables(ast); });
}
if (options.mangle) ast = time_it("mangle", function(){
return pro.ast_mangle(ast, {
toplevel : options.mangle_toplevel,
defines : options.defines,
except : options.reserved_names,
no_functions : options.no_mangle_functions
});
});
if (options.squeeze) ast = time_it("squeeze", function(){
ast = pro.ast_squeeze(ast, {
make_seqs : options.make_seqs,
dead_code : options.dead_code,
keep_comps : !options.unsafe
});
if (options.unsafe)
ast = pro.ast_squeeze_more(ast);
return ast;
});
if (options.ast)
return sys.inspect(ast, null, null);
result += time_it("generate", function(){ return pro.gen_code(ast, options.codegen_options) });
if (!options.codegen_options.beautify && options.max_line_length) {
result = time_it("split", function(){ return pro.split_lines(result, options.max_line_length) });
}
return result;
} catch(ex) {
sys.debug(ex.stack);
sys.debug(sys.inspect(ex));
sys.debug(JSON.stringify(ex));
process.exit(1);
}
};
function time_it(name, cont) {
if (!options.verbose)
return cont();
var t1 = new Date().getTime();
try { return cont(); }
finally { sys.debug("// " + name + ": " + ((new Date().getTime() - t1) / 1000).toFixed(3) + " sec."); }
};
html { font-family: "Lucida Grande","Trebuchet MS",sans-serif; font-size: 12pt; }
body { max-width: 60em; }
.title { text-align: center; }
.todo { color: red; }
.done { color: green; }
.tag { background-color:lightblue; font-weight:normal }
.target { }
.timestamp { color: grey }
.timestamp-kwd { color: CadetBlue }
p.verse { margin-left: 3% }
pre {
border: 1pt solid #AEBDCC;
background-color: #F3F5F7;
padding: 5pt;
font-family: monospace;
font-size: 90%;
overflow:auto;
}
pre.src {
background-color: #eee; color: #112; border: 1px solid #000;
}
table { border-collapse: collapse; }
td, th { vertical-align: top; }
dt { font-weight: bold; }
div.figure { padding: 0.5em; }
div.figure p { text-align: center; }
.linenr { font-size:smaller }
.code-highlighted {background-color:#ffff00;}
.org-info-js_info-navigation { border-style:none; }
#org-info-js_console-label { font-size:10px; font-weight:bold;
white-space:nowrap; }
.org-info-js_search-highlight {background-color:#ffff00; color:#000000;
font-weight:bold; }
sup {
vertical-align: baseline;
position: relative;
top: -0.5em;
font-size: 80%;
}
sup a:link, sup a:visited {
text-decoration: none;
color: #c00;
}
sup a:before { content: "["; color: #999; }
sup a:after { content: "]"; color: #999; }
h1.title { border-bottom: 4px solid #000; padding-bottom: 5px; margin-bottom: 2em; }
#postamble {
color: #777;
font-size: 90%;
padding-top: 1em; padding-bottom: 1em; border-top: 1px solid #999;
margin-top: 2em;
padding-left: 2em;
padding-right: 2em;
text-align: right;
}
#postamble p { margin: 0; }
#footnotes { border-top: 1px solid #000; }
h1 { font-size: 200% }
h2 { font-size: 175% }
h3 { font-size: 150% }
h4 { font-size: 125% }
h1, h2, h3, h4 { font-family: "Bookman",Georgia,"Times New Roman",serif; font-weight: normal; }
@media print {
html { font-size: 11pt; }
}
此差异已折叠。
var jsp = require("./parse-js"),
pro = require("./process");
var BY_TYPE = {};
function HOP(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
};
function AST_Node(parent) {
this.parent = parent;
};
AST_Node.prototype.init = function(){};
function DEFINE_NODE_CLASS(type, props, methods) {
var base = methods && methods.BASE || AST_Node;
if (!base) base = AST_Node;
function D(parent, data) {
base.apply(this, arguments);
if (props) props.forEach(function(name, i){
this["_" + name] = data[i];
});
this.init();
};
var P = D.prototype = new AST_Node;
P.node_type = function(){ return type };
if (props) props.forEach(function(name){
var propname = "_" + name;
P["set_" + name] = function(val) {
this[propname] = val;
return this;
};
P["get_" + name] = function() {
return this[propname];
};
});
if (type != null) BY_TYPE[type] = D;
if (methods) for (var i in methods) if (HOP(methods, i)) {
P[i] = methods[i];
}
return D;
};
var AST_String_Node = DEFINE_NODE_CLASS("string", ["value"]);
var AST_Number_Node = DEFINE_NODE_CLASS("num", ["value"]);
var AST_Name_Node = DEFINE_NODE_CLASS("name", ["value"]);
var AST_Statlist_Node = DEFINE_NODE_CLASS(null, ["body"]);
var AST_Root_Node = DEFINE_NODE_CLASS("toplevel", null, { BASE: AST_Statlist_Node });
var AST_Block_Node = DEFINE_NODE_CLASS("block", null, { BASE: AST_Statlist_Node });
var AST_Splice_Node = DEFINE_NODE_CLASS("splice", null, { BASE: AST_Statlist_Node });
var AST_Var_Node = DEFINE_NODE_CLASS("var", ["definitions"]);
var AST_Const_Node = DEFINE_NODE_CLASS("const", ["definitions"]);
var AST_Try_Node = DEFINE_NODE_CLASS("try", ["body", "catch", "finally"]);
var AST_Throw_Node = DEFINE_NODE_CLASS("throw", ["exception"]);
var AST_New_Node = DEFINE_NODE_CLASS("new", ["constructor", "arguments"]);
var AST_Switch_Node = DEFINE_NODE_CLASS("switch", ["expression", "branches"]);
var AST_Switch_Branch_Node = DEFINE_NODE_CLASS(null, ["expression", "body"]);
var AST_Break_Node = DEFINE_NODE_CLASS("break", ["label"]);
var AST_Continue_Node = DEFINE_NODE_CLASS("continue", ["label"]);
var AST_Assign_Node = DEFINE_NODE_CLASS("assign", ["operator", "lvalue", "rvalue"]);
var AST_Dot_Node = DEFINE_NODE_CLASS("dot", ["expression", "name"]);
var AST_Call_Node = DEFINE_NODE_CLASS("call", ["function", "arguments"]);
var AST_Lambda_Node = DEFINE_NODE_CLASS(null, ["name", "arguments", "body"])
var AST_Function_Node = DEFINE_NODE_CLASS("function", null, AST_Lambda_Node);
var AST_Defun_Node = DEFINE_NODE_CLASS("defun", null, AST_Lambda_Node);
var AST_If_Node = DEFINE_NODE_CLASS("if", ["condition", "then", "else"]);
此差异已折叠。
此差异已折叠。
var jsp = require("./parse-js"),
pro = require("./process"),
slice = jsp.slice,
member = jsp.member,
curry = jsp.curry,
MAP = pro.MAP,
PRECEDENCE = jsp.PRECEDENCE,
OPERATORS = jsp.OPERATORS;
function ast_squeeze_more(ast) {
var w = pro.ast_walker(), walk = w.walk, scope;
function with_scope(s, cont) {
var save = scope, ret;
scope = s;
ret = cont();
scope = save;
return ret;
};
function _lambda(name, args, body) {
return [ this[0], name, args, with_scope(body.scope, curry(MAP, body, walk)) ];
};
return w.with_walkers({
"toplevel": function(body) {
return [ this[0], with_scope(this.scope, curry(MAP, body, walk)) ];
},
"function": _lambda,
"defun": _lambda,
"new": function(ctor, args) {
if (ctor[0] == "name") {
if (ctor[1] == "Array" && !scope.has("Array")) {
if (args.length != 1) {
return [ "array", args ];
} else {
return walk([ "call", [ "name", "Array" ], args ]);
}
} else if (ctor[1] == "Object" && !scope.has("Object")) {
if (!args.length) {
return [ "object", [] ];
} else {
return walk([ "call", [ "name", "Object" ], args ]);
}
} else if ((ctor[1] == "RegExp" || ctor[1] == "Function" || ctor[1] == "Error") && !scope.has(ctor[1])) {
return walk([ "call", [ "name", ctor[1] ], args]);
}
}
},
"call": function(expr, args) {
if (expr[0] == "dot" && expr[1][0] == "string" && args.length == 1
&& (args[0][1] > 0 && expr[2] == "substring" || expr[2] == "substr")) {
return [ "call", [ "dot", expr[1], "slice"], args];
}
if (expr[0] == "dot" && expr[2] == "toString" && args.length == 0) {
// foo.toString() ==> foo+""
return [ "binary", "+", expr[1], [ "string", "" ]];
}
if (expr[0] == "name") {
if (expr[1] == "Array" && args.length != 1 && !scope.has("Array")) {
return [ "array", args ];
}
if (expr[1] == "Object" && !args.length && !scope.has("Object")) {
return [ "object", [] ];
}
if (expr[1] == "String" && !scope.has("String")) {
return [ "binary", "+", args[0], [ "string", "" ]];
}
}
}
}, function() {
return walk(pro.ast_add_scope(ast));
});
};
exports.ast_squeeze_more = ast_squeeze_more;
{
"name" : "uglify-js",
"description" : "JavaScript parser and compressor/beautifier toolkit",
"author" : {
"name" : "Mihai Bazon",
"email" : "mihai.bazon@gmail.com",
"url" : "http://mihai.bazon.net/blog"
},
"version" : "1.2.6",
"main" : "./uglify-js.js",
"bin" : {
"uglifyjs" : "./bin/uglifyjs"
},
"repository": {
"type": "git",
"url": "git@github.com:mishoo/UglifyJS.git"
}
}
{
"name" : "uglify-js",
"description" : "JavaScript parser and compressor/beautifier toolkit",
"author" : {
"name" : "Mihai Bazon",
"email" : "mihai.bazon@gmail.com",
"url" : "http://mihai.bazon.net/blog"
},
"version" : "1.2.3",
"main" : "./uglify-js.js",
"bin" : {
"uglifyjs" : "./bin/uglifyjs"
},
"repository": {
"type": "git",
"url": "git@github.com:mishoo/UglifyJS.git"
}
}
#! /usr/bin/env node
global.sys = require("sys");
var fs = require("fs");
var jsp = require("../lib/parse-js");
var pro = require("../lib/process");
var filename = process.argv[2];
fs.readFile(filename, "utf8", function(err, text){
try {
var ast = time_it("parse", function(){ return jsp.parse(text); });
ast = time_it("mangle", function(){ return pro.ast_mangle(ast); });
ast = time_it("squeeze", function(){ return pro.ast_squeeze(ast); });
var gen = time_it("generate", function(){ return pro.gen_code(ast, false); });
sys.puts(gen);
} catch(ex) {
sys.debug(ex.stack);
sys.debug(sys.inspect(ex));
sys.debug(JSON.stringify(ex));
}
});
function time_it(name, cont) {
var t1 = new Date().getTime();
try { return cont(); }
finally { sys.debug("// " + name + ": " + ((new Date().getTime() - t1) / 1000).toFixed(3) + " sec."); }
};
此差异已折叠。
(function(){var a=function(){};return new a(1,2,3,4)})()
(function(){function a(){}return new a(1,2,3,4)})()
(function(){function a(){}(function(){return new a(1,2,3)})()})()
a=1,b=a,c=1,d=b,e=d,longname=2;if(longname+1){x=3;if(x)var z=7}z=1,y=1,x=1,g+=1,h=g,++i,j=i,i++,j=i+17
\ No newline at end of file
var a=a+"a"+"b"+1+c,b=a+"c"+"ds"+123+c,c=a+"c"+123+d+"ds"+c
\ No newline at end of file
function bar(){return--x}function foo(){while(bar());}function mak(){for(;;);}var x=5
a=func(),b=z;for(a++;i<10;i++)alert(i);var z=1;g=2;for(;i<10;i++)alert(i);var a=2;for(var i=1;i<10;i++)alert(i)
\ No newline at end of file
var a=1;a==1?a=2:a=17
\ No newline at end of file
function a(a){return a==1?2:17}
\ No newline at end of file
function x(a){return typeof a=="object"?a:a===42?0:a*2}function y(a){return typeof a=="object"?a:null}
function f(){var a;return(a="a")?a:a}f()
\ No newline at end of file
new(A,B),new(A||B),new(X?A:B)
\ No newline at end of file
var a=/^(?:(\w+):)?(?:\/\/(?:(?:([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#])(?::(\d))?)?(..?$|(?:[^?#\/]\/))([^?#]*)(?:\?([^#]))?(?:#(.))?/
\ No newline at end of file
var a={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"}
var a=3250441966
\ No newline at end of file
var a=function(b){b(),a()}
\ No newline at end of file
var a=0;switch(a){case 0:a++}
\ No newline at end of file
o={".5":.5},o={.5:.5},o={.5:.5}
\ No newline at end of file
result=function(){return 1}()
\ No newline at end of file
var a={};a["this"]=1,a.that=2
\ No newline at end of file
var a=2e3,b=.002,c=2e-5
\ No newline at end of file
var s,i;s="",i=0
\ No newline at end of file
function bar(a){try{foo()}catch(b){alert("Exception caught (foo not defined)")}alert(a)}bar(10)
(function(){var a=function b(a,b,c){return b}})()
var nullString="\0"
\ No newline at end of file
typeof a=="string",b+""!=c+"",d<e==f<g
\ No newline at end of file
new Array();
new Array(1);
new Array(1, 2, 3);
(function(){
var Array = function(){};
return new Array(1, 2, 3, 4);
})();
(function(){
return new Array(1, 2, 3, 4);
function Array() {};
})();
(function(){
(function(){
return new Array(1, 2, 3);
})();
function Array(){};
})();
a=1;
b=a;
c=1;
d=b;
e=d;
longname=2;
if (longname+1) {
x=3;
if (x) var z = 7;
}
z=1,y=1,x=1
g+=1;
h=g;
++i;
j=i;
i++;
j=i+17;
\ No newline at end of file
var a = a + "a" + "b" + 1 + c;
var b = a + "c" + "ds" + 123 + c;
var c = a + "c" + 123 + d + "ds" + c;
\ No newline at end of file
// test that the calculation is fold to 13
var a = 1 + 2 * 6;
// test that it isn't replaced with 0.3333 because that is more characters
var b = 1/3;
\ No newline at end of file
var x = 5;
function bar() { return --x; }
function foo() { while (bar()); }
function mak() { for(;;); }
a=func();
b=z;
for (a++; i < 10; i++) { alert(i); }
var z=1;
g=2;
for (; i < 10; i++) { alert(i); }
var a = 2;
for (var i = 1; i < 10; i++) { alert(i); }
var a = 1;
if (a == 1) {
a = 2;
} else {
a = 17;
}
function a(b) {
if (b == 1) {
return 2;
} else {
return 17;
}
return 3;
}
\ No newline at end of file
function x(a) {
if (typeof a === 'object')
return a;
if (a === 42)
return 0;
return a * 2;
}
function y(a) {
if (typeof a === 'object')
return a;
return null;
};
function f() { var a; if (a = 'a') { return a; } else { return a; } }; f();
\ No newline at end of file
new (A, B)
new (A || B)
new (X ? A : B)
\ No newline at end of file
var a = /^(?:(\w+):)?(?:\/\/(?:(?:([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#])(?::(\d))?)?(..?$|(?:[^?#\/]\/))([^?#]*)(?:\?([^#]))?(?:#(.))?/;
\ No newline at end of file
var a = {'\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\'};
\ No newline at end of file
var a = 0xC1BDCEEE;
\ No newline at end of file
var a = 0;
switch(a) {
case 0:
a++;
break;
}
\ No newline at end of file
label1 : {
label2 : {
break label2;
console.log(2);
}
console.log(1);
}
\ No newline at end of file
(a ? b : c) ? d : e
\ No newline at end of file
o = {'.5':.5}
o = {'0.5':.5}
o = {0.5:.5}
\ No newline at end of file
result=(function(){ return 1;})()
\ No newline at end of file
var a = 1 << 3;
var b = 8 >> 1;
var c = 8 >>> 1;
\ No newline at end of file
var s, i; s = ''; i = 0;
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册