2012-08-21 09:55:56 +00:00
|
|
|
var fs = require("fs");
|
|
|
|
|
|
2017-03-22 22:11:16 +00:00
|
|
|
var UglifyJS = exports;
|
|
|
|
|
var FILES = UglifyJS.FILES = [
|
2012-10-08 09:55:18 +00:00
|
|
|
"../lib/utils.js",
|
|
|
|
|
"../lib/ast.js",
|
|
|
|
|
"../lib/parse.js",
|
|
|
|
|
"../lib/transform.js",
|
|
|
|
|
"../lib/scope.js",
|
|
|
|
|
"../lib/output.js",
|
|
|
|
|
"../lib/compress.js",
|
|
|
|
|
"../lib/sourcemap.js",
|
Add property name mangler
We only touch properties that are present in an object literal, or which are
assigned to. Example:
x = { foo: 1 };
x.bar = 2;
x["baz"] = 3;
x[cond ? "qwe" : "asd"] = 4;
console.log(x.stuff);
The names "foo", "bar", "baz", "qwe" and "asd" will be mangled, and the
resulting mangled names will be used for the same properties throughout the
code. The "stuff" will not be, since it's just referenced but never
assigned to.
This *will* break most of the code out there, but could work on carefully
written code: do not use eval, do not define methods or properties by
walking an array of names, etc. Also, a comprehensive list of exclusions
needs to be passed, to avoid mangling properties that are standard in
JavaScript, DOM, used in external libraries etc.
2015-03-14 09:22:28 +00:00
|
|
|
"../lib/mozilla-ast.js",
|
2015-09-24 14:57:47 +00:00
|
|
|
"../lib/propmangle.js",
|
2017-04-15 15:50:50 +00:00
|
|
|
"../lib/minify.js",
|
2015-09-24 14:57:47 +00:00
|
|
|
"./exports.js",
|
2012-10-08 09:55:18 +00:00
|
|
|
].map(function(file){
|
2017-03-22 22:11:16 +00:00
|
|
|
return require.resolve(file);
|
2012-10-08 09:55:18 +00:00
|
|
|
});
|
|
|
|
|
|
2017-05-07 19:24:42 +00:00
|
|
|
new Function("MOZ_SourceMap", "exports", function() {
|
|
|
|
|
var code = FILES.map(function(file) {
|
|
|
|
|
return fs.readFileSync(file, "utf8");
|
|
|
|
|
});
|
|
|
|
|
code.push("exports.describe_ast = " + describe_ast.toString());
|
|
|
|
|
return code.join("\n\n");
|
|
|
|
|
}())(
|
2015-09-24 14:57:47 +00:00
|
|
|
require("source-map"),
|
2017-03-22 22:11:16 +00:00
|
|
|
UglifyJS
|
2015-09-24 14:57:47 +00:00
|
|
|
);
|
2012-08-21 09:55:56 +00:00
|
|
|
|
2017-05-07 19:24:42 +00:00
|
|
|
function describe_ast() {
|
|
|
|
|
var out = OutputStream({ beautify: true });
|
2012-10-09 10:21:21 +00:00
|
|
|
function doitem(ctor) {
|
|
|
|
|
out.print("AST_" + ctor.TYPE);
|
|
|
|
|
var props = ctor.SELF_PROPS.filter(function(prop){
|
|
|
|
|
return !/^\$/.test(prop);
|
|
|
|
|
});
|
|
|
|
|
if (props.length > 0) {
|
|
|
|
|
out.space();
|
|
|
|
|
out.with_parens(function(){
|
|
|
|
|
props.forEach(function(prop, i){
|
|
|
|
|
if (i) out.space();
|
|
|
|
|
out.print(prop);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (ctor.documentation) {
|
|
|
|
|
out.space();
|
|
|
|
|
out.print_string(ctor.documentation);
|
|
|
|
|
}
|
|
|
|
|
if (ctor.SUBCLASSES.length > 0) {
|
|
|
|
|
out.space();
|
|
|
|
|
out.with_block(function(){
|
|
|
|
|
ctor.SUBCLASSES.forEach(function(ctor, i){
|
|
|
|
|
out.indent();
|
|
|
|
|
doitem(ctor);
|
|
|
|
|
out.newline();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-05-07 19:24:42 +00:00
|
|
|
doitem(AST_Node);
|
2017-05-24 18:32:36 +00:00
|
|
|
return out + "\n";
|
2017-05-07 19:24:42 +00:00
|
|
|
}
|