Merge branch 'master' into harmony-v3.0.1
This commit is contained in:
19
README.md
19
README.md
@@ -95,8 +95,9 @@ The available options are:
|
|||||||
`wrap_iife` Wrap IIFEs in parenthesis. Note: you may
|
`wrap_iife` Wrap IIFEs in parenthesis. Note: you may
|
||||||
want to disable `negate_iife` under
|
want to disable `negate_iife` under
|
||||||
compressor options.
|
compressor options.
|
||||||
-o, --output <file> Output file (default STDOUT). Specify "spidermonkey"
|
-o, --output <file> Output file path (default STDOUT). Specify `ast` or
|
||||||
to dump SpiderMonkey AST format (as JSON) to STDOUT.
|
`spidermonkey` to write UglifyJS or SpiderMonkey AST
|
||||||
|
as JSON to STDOUT respectively.
|
||||||
--comments [filter] Preserve copyright comments in the output. By
|
--comments [filter] Preserve copyright comments in the output. By
|
||||||
default this works like Google Closure, keeping
|
default this works like Google Closure, keeping
|
||||||
JSDoc-style comments that contain "@license" or
|
JSDoc-style comments that contain "@license" or
|
||||||
@@ -489,21 +490,21 @@ can pass additional arguments that control the code output:
|
|||||||
Passing `-b` will set this to true, but you might need to pass `-b` even
|
Passing `-b` will set this to true, but you might need to pass `-b` even
|
||||||
when you want to generate minified code, in order to specify additional
|
when you want to generate minified code, in order to specify additional
|
||||||
arguments, so you can use `-b beautify=false` to override it.
|
arguments, so you can use `-b beautify=false` to override it.
|
||||||
- `indent-level` (default 4)
|
- `indent_level` (default 4)
|
||||||
- `indent-start` (default 0) -- prefix all lines by that many spaces
|
- `indent_start` (default 0) -- prefix all lines by that many spaces
|
||||||
- `quote-keys` (default `false`) -- pass `true` to quote all keys in literal
|
- `quote_keys` (default `false`) -- pass `true` to quote all keys in literal
|
||||||
objects
|
objects
|
||||||
- `space-colon` (default `true`) -- insert a space after the colon signs
|
- `space_colon` (default `true`) -- insert a space after the colon signs
|
||||||
- `ascii-only` (default `false`) -- escape Unicode characters in strings and
|
- `ascii_only` (default `false`) -- escape Unicode characters in strings and
|
||||||
regexps (affects directives with non-ascii characters becoming invalid)
|
regexps (affects directives with non-ascii characters becoming invalid)
|
||||||
- `inline-script` (default `false`) -- escape the slash in occurrences of
|
- `inline_script` (default `false`) -- escape the slash in occurrences of
|
||||||
`</script` in strings
|
`</script` in strings
|
||||||
- `width` (default 80) -- only takes effect when beautification is on, this
|
- `width` (default 80) -- only takes effect when beautification is on, this
|
||||||
specifies an (orientative) line width that the beautifier will try to
|
specifies an (orientative) line width that the beautifier will try to
|
||||||
obey. It refers to the width of the line text (excluding indentation).
|
obey. It refers to the width of the line text (excluding indentation).
|
||||||
It doesn't work very well currently, but it does make the code generated
|
It doesn't work very well currently, but it does make the code generated
|
||||||
by UglifyJS more readable.
|
by UglifyJS more readable.
|
||||||
- `max-line-len` (default 32000) -- maximum line length (for uglified code)
|
- `max_line_len` (default 32000) -- maximum line length (for uglified code)
|
||||||
- `bracketize` (default `false`) -- always insert brackets in `if`, `for`,
|
- `bracketize` (default `false`) -- always insert brackets in `if`, `for`,
|
||||||
`do`, `while` or `with` statements, even if their body is a single
|
`do`, `while` or `with` statements, even if their body is a single
|
||||||
statement.
|
statement.
|
||||||
|
|||||||
69
bin/uglifyjs
69
bin/uglifyjs
@@ -15,6 +15,7 @@ var path = require("path");
|
|||||||
var program = require("commander");
|
var program = require("commander");
|
||||||
var UglifyJS = require("../tools/node");
|
var UglifyJS = require("../tools/node");
|
||||||
|
|
||||||
|
var skip_keys = [ "cname", "enclosed", "parent_scope", "scope", "thedef", "uses_eval", "uses_with" ];
|
||||||
var files = {};
|
var files = {};
|
||||||
var options = {
|
var options = {
|
||||||
compress: false,
|
compress: false,
|
||||||
@@ -89,7 +90,7 @@ if (program.mangleProps) {
|
|||||||
if (typeof program.mangleProps != "object") program.mangleProps = {};
|
if (typeof program.mangleProps != "object") program.mangleProps = {};
|
||||||
if (!Array.isArray(program.mangleProps.reserved)) program.mangleProps.reserved = [];
|
if (!Array.isArray(program.mangleProps.reserved)) program.mangleProps.reserved = [];
|
||||||
require("../tools/domprops").forEach(function(name) {
|
require("../tools/domprops").forEach(function(name) {
|
||||||
UglifyJS.push_uniq(program.mangleProps.reserved, name);
|
UglifyJS._push_uniq(program.mangleProps.reserved, name);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (typeof options.mangle != "object") options.mangle = {};
|
if (typeof options.mangle != "object") options.mangle = {};
|
||||||
@@ -107,6 +108,12 @@ if (program.nameCache) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (program.output == "ast") {
|
||||||
|
options.output = {
|
||||||
|
ast: true,
|
||||||
|
code: false
|
||||||
|
};
|
||||||
|
}
|
||||||
if (program.parse) {
|
if (program.parse) {
|
||||||
if (program.parse.acorn || program.parse.spidermonkey) {
|
if (program.parse.acorn || program.parse.spidermonkey) {
|
||||||
if (program.sourceMap) fatal("ERROR: inline source map only works with built-in parser");
|
if (program.sourceMap) fatal("ERROR: inline source map only works with built-in parser");
|
||||||
@@ -165,7 +172,7 @@ function run() {
|
|||||||
UglifyJS.AST_Node.warn_function = function(msg) {
|
UglifyJS.AST_Node.warn_function = function(msg) {
|
||||||
console.error("WARN:", msg);
|
console.error("WARN:", msg);
|
||||||
};
|
};
|
||||||
if (program.stats) program.stats = Date.now();
|
if (program.stats) program.stats = Date.now();
|
||||||
try {
|
try {
|
||||||
if (program.parse) {
|
if (program.parse) {
|
||||||
if (program.parse.acorn) {
|
if (program.parse.acorn) {
|
||||||
@@ -185,9 +192,13 @@ function run() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var result = UglifyJS.minify(files, options);
|
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
if (ex instanceof UglifyJS.JS_Parse_Error) {
|
fatal("ERROR: " + ex.message);
|
||||||
|
}
|
||||||
|
var result = UglifyJS.minify(files, options);
|
||||||
|
if (result.error) {
|
||||||
|
var ex = result.error;
|
||||||
|
if (ex.name == "SyntaxError") {
|
||||||
console.error("Parse error at " + ex.filename + ":" + ex.line + "," + ex.col);
|
console.error("Parse error at " + ex.filename + ":" + ex.line + "," + ex.col);
|
||||||
var col = ex.col;
|
var col = ex.col;
|
||||||
var lines = files[ex.filename].split(/\r?\n/);
|
var lines = files[ex.filename].split(/\r?\n/);
|
||||||
@@ -210,9 +221,31 @@ function run() {
|
|||||||
console.error(ex.defs);
|
console.error(ex.defs);
|
||||||
}
|
}
|
||||||
fatal("ERROR: " + ex.message);
|
fatal("ERROR: " + ex.message);
|
||||||
}
|
} else if (program.output == "ast") {
|
||||||
if (program.output == "spidermonkey") {
|
console.log(JSON.stringify(result.ast, function(key, value) {
|
||||||
console.log(JSON.stringify(UglifyJS.parse(result.code).to_mozilla_ast(), null, 2));
|
if (skip_key(key)) return;
|
||||||
|
if (value instanceof UglifyJS.AST_Token) return;
|
||||||
|
if (value instanceof UglifyJS.Dictionary) return;
|
||||||
|
if (value instanceof UglifyJS.AST_Node) {
|
||||||
|
var result = {
|
||||||
|
_class: "AST_" + value.TYPE
|
||||||
|
};
|
||||||
|
value.CTOR.PROPS.forEach(function(prop) {
|
||||||
|
result[prop] = value[prop];
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}, 2));
|
||||||
|
} else if (program.output == "spidermonkey") {
|
||||||
|
console.log(JSON.stringify(UglifyJS.minify(result.code, {
|
||||||
|
compress: false,
|
||||||
|
mangle: false,
|
||||||
|
output: {
|
||||||
|
ast: true,
|
||||||
|
code: false
|
||||||
|
}
|
||||||
|
}).ast.to_mozilla_ast(), null, 2));
|
||||||
} else if (program.output) {
|
} else if (program.output) {
|
||||||
fs.writeFileSync(program.output, result.code);
|
fs.writeFileSync(program.output, result.code);
|
||||||
if (result.map) {
|
if (result.map) {
|
||||||
@@ -230,8 +263,8 @@ function run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fatal(message) {
|
function fatal(message) {
|
||||||
console.error(message);
|
console.error(message);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A file glob function that only supports "*" and "?" wildcards in the basename.
|
// A file glob function that only supports "*" and "?" wildcards in the basename.
|
||||||
@@ -278,9 +311,17 @@ function parse_js(flag, constants) {
|
|||||||
return function(value, options) {
|
return function(value, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
try {
|
try {
|
||||||
UglifyJS.parse(value, {
|
UglifyJS.minify(value, {
|
||||||
expression: true
|
parse: {
|
||||||
}).walk(new UglifyJS.TreeWalker(function(node) {
|
expression: true
|
||||||
|
},
|
||||||
|
compress: false,
|
||||||
|
mangle: false,
|
||||||
|
output: {
|
||||||
|
ast: true,
|
||||||
|
code: false
|
||||||
|
}
|
||||||
|
}).ast.walk(new UglifyJS.TreeWalker(function(node) {
|
||||||
if (node instanceof UglifyJS.AST_Assign) {
|
if (node instanceof UglifyJS.AST_Assign) {
|
||||||
var name = node.left.print_to_string();
|
var name = node.left.print_to_string();
|
||||||
var value = node.right;
|
var value = node.right;
|
||||||
@@ -337,3 +378,7 @@ function to_cache(key) {
|
|||||||
}
|
}
|
||||||
return cache[key];
|
return cache[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function skip_key(key) {
|
||||||
|
return skip_keys.indexOf(key) >= 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -857,7 +857,7 @@ var AST_UnaryPostfix = DEFNODE("UnaryPostfix", null, {
|
|||||||
$documentation: "Unary postfix expression, i.e. `i++`"
|
$documentation: "Unary postfix expression, i.e. `i++`"
|
||||||
}, AST_Unary);
|
}, AST_Unary);
|
||||||
|
|
||||||
var AST_Binary = DEFNODE("Binary", "left operator right", {
|
var AST_Binary = DEFNODE("Binary", "operator left right", {
|
||||||
$documentation: "Binary expression, i.e. `a + b`",
|
$documentation: "Binary expression, i.e. `a + b`",
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
left: "[AST_Node] left-hand side expression",
|
left: "[AST_Node] left-hand side expression",
|
||||||
|
|||||||
@@ -108,38 +108,46 @@ function minify(files, options) {
|
|||||||
toplevel = mangle_properties(toplevel, options.mangle.properties);
|
toplevel = mangle_properties(toplevel, options.mangle.properties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options.sourceMap) {
|
var result = {};
|
||||||
if (typeof options.sourceMap.content == "string") {
|
if (options.output.ast) {
|
||||||
options.sourceMap.content = JSON.parse(options.sourceMap.content);
|
result.ast = toplevel;
|
||||||
}
|
}
|
||||||
options.output.source_map = SourceMap({
|
if (!HOP(options.output, "code") || options.output.code) {
|
||||||
file: options.sourceMap.filename,
|
if (options.sourceMap) {
|
||||||
orig: options.sourceMap.content,
|
if (typeof options.sourceMap.content == "string") {
|
||||||
root: options.sourceMap.root
|
options.sourceMap.content = JSON.parse(options.sourceMap.content);
|
||||||
});
|
}
|
||||||
if (options.sourceMap.includeSources) {
|
options.output.source_map = SourceMap({
|
||||||
for (var name in files) {
|
file: options.sourceMap.filename,
|
||||||
options.output.source_map.get().setSourceContent(name, files[name]);
|
orig: options.sourceMap.content,
|
||||||
|
root: options.sourceMap.root
|
||||||
|
});
|
||||||
|
if (options.sourceMap.includeSources) {
|
||||||
|
for (var name in files) {
|
||||||
|
options.output.source_map.get().setSourceContent(name, files[name]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
delete options.output.ast;
|
||||||
var stream = OutputStream(options.output);
|
delete options.output.code;
|
||||||
toplevel.print(stream);
|
var stream = OutputStream(options.output);
|
||||||
var result = {
|
toplevel.print(stream);
|
||||||
code: stream.get()
|
result.code = stream.get();
|
||||||
};
|
if (options.sourceMap) {
|
||||||
if (options.sourceMap) {
|
result.map = options.output.source_map.toString();
|
||||||
result.map = options.output.source_map.toString();
|
if (options.sourceMap.url == "inline") {
|
||||||
if (options.sourceMap.url == "inline") {
|
result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map);
|
||||||
result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map);
|
} else if (options.sourceMap.url) {
|
||||||
} else if (options.sourceMap.url) {
|
result.code += "\n//# sourceMappingURL=" + options.sourceMap.url;
|
||||||
result.code += "\n//# sourceMappingURL=" + options.sourceMap.url;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (warnings.length) {
|
if (warnings.length) {
|
||||||
result.warnings = warnings;
|
result.warnings = warnings;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
} catch (ex) {
|
||||||
|
return { error: ex };
|
||||||
} finally {
|
} finally {
|
||||||
AST_Node.warn_function = warn_function;
|
AST_Node.warn_function = warn_function;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"homepage": "http://lisperator.net/uglifyjs",
|
"homepage": "http://lisperator.net/uglifyjs",
|
||||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"version": "3.0.0",
|
"version": "3.0.1",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
|
|||||||
13
test/exports.js
Normal file
13
test/exports.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
exports["Compressor"] = Compressor;
|
||||||
|
exports["JS_Parse_Error"] = JS_Parse_Error;
|
||||||
|
exports["OutputStream"] = OutputStream;
|
||||||
|
exports["SourceMap"] = SourceMap;
|
||||||
|
exports["TreeWalker"] = TreeWalker;
|
||||||
|
exports["base54"] = base54;
|
||||||
|
exports["defaults"] = defaults;
|
||||||
|
exports["mangle_properties"] = mangle_properties;
|
||||||
|
exports["minify"] = minify;
|
||||||
|
exports["parse"] = parse;
|
||||||
|
exports["string_template"] = string_template;
|
||||||
|
exports["tokenizer"] = tokenizer;
|
||||||
|
exports["is_identifier"] = is_identifier;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
var UglifyJS = require('../../');
|
var UglifyJS = require("../node");
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
|
|
||||||
describe("Accessor tokens", function() {
|
describe("Accessor tokens", function() {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
var UglifyJS = require('../../');
|
var UglifyJS = require("../node");
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
|
|
||||||
describe("arguments", function() {
|
describe("arguments", function() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var uglify = require("../../");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("Arrow functions", function() {
|
describe("Arrow functions", function() {
|
||||||
it("Should not accept spread tokens on non-last parameters or without arguments parentheses", function() {
|
it("Should not accept spread tokens on non-last parameters or without arguments parentheses", function() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var uglify = require("../../");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("Class", function() {
|
describe("Class", function() {
|
||||||
it("Should not accept spread on non-last parameters in methods", function() {
|
it("Should not accept spread on non-last parameters in methods", function() {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ describe("bin/uglifyjs", function () {
|
|||||||
eval(stdout);
|
eval(stdout);
|
||||||
|
|
||||||
assert.strictEqual(typeof WrappedUglifyJS, 'object');
|
assert.strictEqual(typeof WrappedUglifyJS, 'object');
|
||||||
assert.strictEqual(true, WrappedUglifyJS.parse('foo;') instanceof WrappedUglifyJS.AST_Node);
|
assert.strictEqual(WrappedUglifyJS.minify("foo([true,,2+3]);").code, "foo([!0,,5]);");
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -509,4 +509,15 @@ describe("bin/uglifyjs", function () {
|
|||||||
return JSON.stringify(map).replace(/"/g, '\\"');
|
return JSON.stringify(map).replace(/"/g, '\\"');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
it("Should dump AST as JSON", function(done) {
|
||||||
|
var command = uglifyjscmd + " test/input/global_defs/simple.js -mco ast";
|
||||||
|
exec(command, function (err, stdout) {
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
|
var ast = JSON.parse(stdout);
|
||||||
|
assert.strictEqual(ast._class, "AST_Toplevel");
|
||||||
|
assert.ok(Array.isArray(ast.body));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
var UglifyJS = require('../../');
|
var UglifyJS = require("../node");
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
|
|
||||||
describe("comment filters", function() {
|
describe("comment filters", function() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var uglify = require("../../");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("Comment", function() {
|
describe("Comment", function() {
|
||||||
it("Should recognize eol of single line comments", function() {
|
it("Should recognize eol of single line comments", function() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var uglify = require("../../");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("Destructuring", function() {
|
describe("Destructuring", function() {
|
||||||
it("Should generate similar trees for destructuring in left hand side expressions, definitions, functions and arrow functions", function() {
|
it("Should generate similar trees for destructuring in left hand side expressions, definitions, functions and arrow functions", function() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var uglify = require("../../");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("Directives", function() {
|
describe("Directives", function() {
|
||||||
it ("Should allow tokenizer to store directives state", function() {
|
it ("Should allow tokenizer to store directives state", function() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var uglify = require("../../");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("EOF", function() {
|
describe("EOF", function() {
|
||||||
it("Should test code for at least throwing syntax error when incomplete", function() {
|
it("Should test code for at least throwing syntax error when incomplete", function() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var uglify = require("../../");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("Export", function() {
|
describe("Export", function() {
|
||||||
it ("Should parse export directives", function() {
|
it ("Should parse export directives", function() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var uglify = require("../../");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("Expression", function() {
|
describe("Expression", function() {
|
||||||
it("Should not allow the first exponentiation operator to be prefixed with an unary operator", function() {
|
it("Should not allow the first exponentiation operator to be prefixed with an unary operator", function() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var uglify = require("../../");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("Function", function() {
|
describe("Function", function() {
|
||||||
it ("Should parse binding patterns correctly", function() {
|
it ("Should parse binding patterns correctly", function() {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
var UglifyJS = require('../../');
|
var UglifyJS = require("../node");
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
|
|
||||||
describe("Getters and setters", function() {
|
describe("Getters and setters", function() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var uglify = require("../../");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("Left-hand side expressions", function () {
|
describe("Left-hand side expressions", function () {
|
||||||
it("Should parse destructuring with const/let/var correctly", function () {
|
it("Should parse destructuring with const/let/var correctly", function () {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
var Uglify = require('../../');
|
var Uglify = require("../node");
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
|
|
||||||
describe("line-endings", function() {
|
describe("line-endings", function() {
|
||||||
|
|||||||
@@ -114,17 +114,18 @@ describe("minify", function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
it("Should fail with multiple input and inline source map", function() {
|
it("Should fail with multiple input and inline source map", function() {
|
||||||
assert.throws(function() {
|
var result = Uglify.minify([
|
||||||
Uglify.minify([
|
read("./test/input/issue-520/input.js"),
|
||||||
read("./test/input/issue-520/input.js"),
|
read("./test/input/issue-520/output.js")
|
||||||
read("./test/input/issue-520/output.js")
|
], {
|
||||||
], {
|
sourceMap: {
|
||||||
sourceMap: {
|
content: "inline",
|
||||||
content: "inline",
|
url: "inline"
|
||||||
url: "inline"
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
var err = result.error;
|
||||||
|
assert.ok(err instanceof Error);
|
||||||
|
assert.strictEqual(err.stack.split(/\n/)[0], "Error: inline source map only works with singular input");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -170,26 +171,14 @@ describe("minify", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("JS_Parse_Error", function() {
|
describe("JS_Parse_Error", function() {
|
||||||
it("should throw syntax error", function() {
|
it("should return syntax error", function() {
|
||||||
assert.throws(function() {
|
var result = Uglify.minify("function f(a{}");
|
||||||
Uglify.minify("function f(a{}");
|
var err = result.error;
|
||||||
}, function(err) {
|
assert.ok(err instanceof Error);
|
||||||
assert.ok(err instanceof Error);
|
assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: Unexpected token punc «{», expected punc «,»");
|
||||||
assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: Unexpected token punc «{», expected punc «,»");
|
assert.strictEqual(err.filename, "0");
|
||||||
assert.strictEqual(err.filename, "0");
|
assert.strictEqual(err.line, 1);
|
||||||
assert.strictEqual(err.line, 1);
|
assert.strictEqual(err.col, 12);
|
||||||
assert.strictEqual(err.col, 12);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Compressor", function() {
|
|
||||||
it("should be backward compatible with ast.transform(compressor)", function() {
|
|
||||||
var ast = Uglify.parse("function f(a){for(var i=0;i<a;i++)console.log(i)}");
|
|
||||||
ast.figure_out_scope();
|
|
||||||
ast = ast.transform(Uglify.Compressor());
|
|
||||||
assert.strictEqual(ast.print_to_string(), "function f(a){for(var i=0;i<a;i++)console.log(i)}");
|
|
||||||
});
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var uglify = require("../../");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("New", function() {
|
describe("New", function() {
|
||||||
it("Should add trailing parentheses for new expressions with zero arguments in beautify mode", function() {
|
it("Should add trailing parentheses for new expressions with zero arguments in beautify mode", function() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var uglify = require("../../");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("Number literals", function () {
|
describe("Number literals", function () {
|
||||||
it("Should not allow legacy octal literals in strict mode", function() {
|
it("Should not allow legacy octal literals in strict mode", function() {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
var Uglify = require("../../");
|
var Uglify = require("../node");
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
|
|
||||||
describe("Object", function() {
|
describe("Object", function() {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
var UglifyJS = require("../../");
|
var UglifyJS = require("../node");
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
|
|
||||||
describe("operator", function() {
|
describe("operator", function() {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var exec = require("child_process").exec;
|
var exec = require("child_process").exec;
|
||||||
var uglify = require("../../");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("spidermonkey export/import sanity test", function() {
|
describe("spidermonkey export/import sanity test", function() {
|
||||||
it("should produce a functional build when using --self with spidermonkey", function(done) {
|
it("should produce a functional build when using --self with spidermonkey", function(done) {
|
||||||
@@ -15,18 +15,7 @@ describe("spidermonkey export/import sanity test", function() {
|
|||||||
|
|
||||||
eval(stdout);
|
eval(stdout);
|
||||||
assert.strictEqual(typeof SpiderUglify, "object");
|
assert.strictEqual(typeof SpiderUglify, "object");
|
||||||
|
assert.strictEqual(SpiderUglify.minify("foo([true,,2+3]);").code, "foo([!0,,5]);");
|
||||||
var ast = SpiderUglify.parse("foo([true,,2+3]);");
|
|
||||||
assert.strictEqual(true, ast instanceof SpiderUglify.AST_Node);
|
|
||||||
|
|
||||||
ast.figure_out_scope();
|
|
||||||
ast = SpiderUglify.Compressor({}).compress(ast);
|
|
||||||
assert.strictEqual(true, ast instanceof SpiderUglify.AST_Node);
|
|
||||||
|
|
||||||
var stream = SpiderUglify.OutputStream({});
|
|
||||||
ast.print(stream);
|
|
||||||
var code = stream.toString();
|
|
||||||
assert.strictEqual(code, "foo([!0,,5]);");
|
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
var UglifyJS = require('../../');
|
var UglifyJS = require("../node");
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
|
|
||||||
describe("String literals", function() {
|
describe("String literals", function() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var uglify = require("../../");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("Template string", function() {
|
describe("Template string", function() {
|
||||||
it("Should not accept invalid sequences", function() {
|
it("Should not accept invalid sequences", function() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var uglify = require("../../");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("Try", function() {
|
describe("Try", function() {
|
||||||
it("Should not allow catch with an empty parameter", function() {
|
it("Should not allow catch with an empty parameter", function() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var uglify = require("../../");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("Unicode", function() {
|
describe("Unicode", function() {
|
||||||
it("Should not accept invalid code ranges in unicode escape", function() {
|
it("Should not accept invalid code ranges in unicode escape", function() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var uglify = require("../../");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("With", function() {
|
describe("With", function() {
|
||||||
it("Should throw syntaxError when using with statement in strict mode", function() {
|
it("Should throw syntaxError when using with statement in strict mode", function() {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
var UglifyJS = require("../../");
|
var UglifyJS = require("../node");
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
|
|
||||||
describe("Yield", function() {
|
describe("Yield", function() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Testing UglifyJS <-> SpiderMonkey AST conversion
|
// Testing UglifyJS <-> SpiderMonkey AST conversion
|
||||||
// through generative testing.
|
// through generative testing.
|
||||||
|
|
||||||
var UglifyJS = require(".."),
|
var UglifyJS = require("./node"),
|
||||||
escodegen = require("escodegen"),
|
escodegen = require("escodegen"),
|
||||||
esfuzz = require("esfuzz"),
|
esfuzz = require("esfuzz"),
|
||||||
estraverse = require("estraverse"),
|
estraverse = require("estraverse"),
|
||||||
|
|||||||
6
test/node.js
Normal file
6
test/node.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
var fs = require("fs");
|
||||||
|
|
||||||
|
new Function("MOZ_SourceMap", "exports", require("../tools/node").FILES.map(function(file) {
|
||||||
|
if (/exports\.js$/.test(file)) file = require.resolve("./exports");
|
||||||
|
return fs.readFileSync(file, "utf8");
|
||||||
|
}).join("\n\n"))(require("source-map"), exports);
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#! /usr/bin/env node
|
#! /usr/bin/env node
|
||||||
|
|
||||||
var U = require("../tools/node");
|
var U = require("./node");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
var UglifyJS = require("..");
|
var UglifyJS = require("./node");
|
||||||
var ok = require("assert");
|
var ok = require("assert");
|
||||||
|
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
stream._handle.setBlocking(true);
|
stream._handle.setBlocking(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
var UglifyJS = require("..");
|
var UglifyJS = require("./node");
|
||||||
var randomBytes = require("crypto").randomBytes;
|
var randomBytes = require("crypto").randomBytes;
|
||||||
var sandbox = require("./sandbox");
|
var sandbox = require("./sandbox");
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,4 @@
|
|||||||
exports["Compressor"] = Compressor;
|
|
||||||
exports["Dictionary"] = Dictionary;
|
exports["Dictionary"] = Dictionary;
|
||||||
exports["JS_Parse_Error"] = JS_Parse_Error;
|
|
||||||
exports["OutputStream"] = OutputStream;
|
|
||||||
exports["SourceMap"] = SourceMap;
|
|
||||||
exports["TreeWalker"] = TreeWalker;
|
exports["TreeWalker"] = TreeWalker;
|
||||||
exports["base54"] = base54;
|
|
||||||
exports["defaults"] = defaults;
|
|
||||||
exports["mangle_properties"] = mangle_properties;
|
|
||||||
exports["minify"] = minify;
|
exports["minify"] = minify;
|
||||||
exports["parse"] = parse;
|
exports["_push_uniq"] = push_uniq;
|
||||||
exports["push_uniq"] = push_uniq;
|
|
||||||
exports["string_template"] = string_template;
|
|
||||||
exports["tokenizer"] = tokenizer;
|
|
||||||
exports["is_identifier"] = is_identifier;
|
|
||||||
|
|||||||
@@ -18,15 +18,19 @@ var FILES = UglifyJS.FILES = [
|
|||||||
return require.resolve(file);
|
return require.resolve(file);
|
||||||
});
|
});
|
||||||
|
|
||||||
new Function("MOZ_SourceMap", "exports", FILES.map(function(file){
|
new Function("MOZ_SourceMap", "exports", function() {
|
||||||
return fs.readFileSync(file, "utf8");
|
var code = FILES.map(function(file) {
|
||||||
}).join("\n\n"))(
|
return fs.readFileSync(file, "utf8");
|
||||||
|
});
|
||||||
|
code.push("exports.describe_ast = " + describe_ast.toString());
|
||||||
|
return code.join("\n\n");
|
||||||
|
}())(
|
||||||
require("source-map"),
|
require("source-map"),
|
||||||
UglifyJS
|
UglifyJS
|
||||||
);
|
);
|
||||||
|
|
||||||
UglifyJS.describe_ast = function() {
|
function describe_ast() {
|
||||||
var out = UglifyJS.OutputStream({ beautify: true });
|
var out = OutputStream({ beautify: true });
|
||||||
function doitem(ctor) {
|
function doitem(ctor) {
|
||||||
out.print("AST_" + ctor.TYPE);
|
out.print("AST_" + ctor.TYPE);
|
||||||
var props = ctor.SELF_PROPS.filter(function(prop){
|
var props = ctor.SELF_PROPS.filter(function(prop){
|
||||||
@@ -56,6 +60,6 @@ UglifyJS.describe_ast = function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
doitem(UglifyJS.AST_Node);
|
doitem(AST_Node);
|
||||||
return out + "";
|
return out + "";
|
||||||
};
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user