4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@@ -12,8 +12,8 @@ jobs:
|
||||
- '-mb braces'
|
||||
- '--ie -c'
|
||||
- '-mc'
|
||||
- '-p acorn --toplevel -mco spidermonkey'
|
||||
- '--toplevel -mc passes=3,pure_getters,unsafe'
|
||||
- '-p acorn -mco spidermonkey'
|
||||
- '-mc passes=3,pure_getters,unsafe'
|
||||
script:
|
||||
- acorn.sh
|
||||
- bootstrap.sh
|
||||
|
||||
@@ -119,6 +119,8 @@ a double dash to prevent input files being used as option arguments:
|
||||
--keep-fnames Do not mangle/drop function names. Useful for
|
||||
code relying on Function.prototype.name.
|
||||
--module Process input as ES module (implies --toplevel)
|
||||
--no-module Avoid optimizations which may alter runtime behavior
|
||||
under prior versions of JavaScript.
|
||||
--name-cache <file> File to hold mangled name mappings.
|
||||
--self Build UglifyJS as a library (implies --wrap UglifyJS)
|
||||
--source-map [options] Enable source map/specify source map options:
|
||||
@@ -530,9 +532,9 @@ if (result.error) throw result.error;
|
||||
- `mangle.properties` (default: `false`) — a subcategory of the mangle option.
|
||||
Pass an object to specify custom [mangle property options](#mangle-properties-options).
|
||||
|
||||
- `module` (default: `false`) — set to `true` if you wish to process input as
|
||||
ES module, i.e. implicit `"use strict";` and support for top-level `await`,
|
||||
alongside with `toplevel` enabled.
|
||||
- `module` (default: `true`) — process input as ES module, i.e. implicit
|
||||
`"use strict";` and support for top-level `await`, alongside with `toplevel`
|
||||
enabled.
|
||||
|
||||
- `nameCache` (default: `null`) — pass an empty object `{}` or a previously
|
||||
used `nameCache` object if you wish to cache mangled variable and
|
||||
|
||||
10
bin/uglifyjs
10
bin/uglifyjs
@@ -108,7 +108,8 @@ function process_option(name, no_value) {
|
||||
" --ie Support non-standard Internet Explorer.",
|
||||
" --keep-fargs Do not mangle/drop function arguments.",
|
||||
" --keep-fnames Do not mangle/drop function names. Useful for code relying on Function.prototype.name.",
|
||||
" --module Process input as ES module (implies --toplevel)",
|
||||
" --module Process input as ES module (implies --toplevel).",
|
||||
" --no-module Process input with improved JavaScript compatibility.",
|
||||
" --name-cache <file> File to hold mangled name mappings.",
|
||||
" --rename Force symbol expansion.",
|
||||
" --no-rename Disable symbol expansion.",
|
||||
@@ -155,7 +156,6 @@ function process_option(name, no_value) {
|
||||
case "expression":
|
||||
case "ie":
|
||||
case "ie8":
|
||||
case "module":
|
||||
case "timings":
|
||||
case "toplevel":
|
||||
case "v8":
|
||||
@@ -201,6 +201,12 @@ function process_option(name, no_value) {
|
||||
if (typeof options.mangle != "object") options.mangle = {};
|
||||
options.mangle.properties = parse_js(read_value(), options.mangle.properties);
|
||||
break;
|
||||
case "module":
|
||||
options.module = true;
|
||||
break;
|
||||
case "no-module":
|
||||
options.module = false;
|
||||
break;
|
||||
case "name-cache":
|
||||
nameCache = read_value(true);
|
||||
options.nameCache = JSON.parse(read_file(nameCache, "{}"));
|
||||
|
||||
@@ -10234,22 +10234,24 @@ Compressor.prototype.compress = function(node) {
|
||||
}
|
||||
|
||||
function varify(self, compressor) {
|
||||
return all(self.definitions, function(defn) {
|
||||
if (all(self.definitions, function(defn) {
|
||||
return !defn.name.match_symbol(function(node) {
|
||||
if (node instanceof AST_SymbolDeclaration) return !can_varify(compressor, node);
|
||||
}, true);
|
||||
}) ? to_var(self, compressor.find_parent(AST_Scope)) : self;
|
||||
})) return to_var(self, compressor.find_parent(AST_Scope));
|
||||
}
|
||||
|
||||
OPT(AST_Const, function(self, compressor) {
|
||||
if (!compressor.option("varify")) return self;
|
||||
var decl = varify(self, compressor);
|
||||
if (decl) return decl;
|
||||
if (can_letify(self, compressor, 0)) return to_let(self);
|
||||
return varify(self, compressor);
|
||||
return self;
|
||||
});
|
||||
|
||||
OPT(AST_Let, function(self, compressor) {
|
||||
if (!compressor.option("varify")) return self;
|
||||
return varify(self, compressor);
|
||||
return varify(self, compressor) || self;
|
||||
});
|
||||
|
||||
function trim_optional_chain(node, compressor) {
|
||||
|
||||
@@ -82,14 +82,14 @@ function minify(files, options) {
|
||||
keep_fargs: false,
|
||||
keep_fnames: false,
|
||||
mangle: {},
|
||||
module: false,
|
||||
module: undefined,
|
||||
nameCache: null,
|
||||
output: {},
|
||||
parse: {},
|
||||
rename: undefined,
|
||||
sourceMap: false,
|
||||
timings: false,
|
||||
toplevel: !!(options && !options["expression"] && options["module"]),
|
||||
toplevel: undefined,
|
||||
v8: false,
|
||||
validate: false,
|
||||
warnings: false,
|
||||
@@ -104,8 +104,10 @@ function minify(files, options) {
|
||||
if (options.ie) set_shorthand("ie", options, [ "compress", "mangle", "output", "rename" ]);
|
||||
if (options.keep_fargs) set_shorthand("keep_fargs", options, [ "compress", "mangle", "rename" ]);
|
||||
if (options.keep_fnames) set_shorthand("keep_fnames", options, [ "compress", "mangle", "rename" ]);
|
||||
if (options.module === undefined && !options.ie) options.module = true;
|
||||
if (options.module) set_shorthand("module", options, [ "compress", "parse" ]);
|
||||
if (options.toplevel) set_shorthand("toplevel", options, [ "compress", "mangle", "rename" ]);
|
||||
if (options.toplevel === undefined && !options.expression && options.module) options.toplevel = true;
|
||||
if (options.toplevel !== undefined) set_shorthand("toplevel", options, [ "compress", "mangle", "rename" ]);
|
||||
if (options.v8) set_shorthand("v8", options, [ "mangle", "output", "rename" ]);
|
||||
if (options.webkit) set_shorthand("webkit", options, [ "compress", "mangle", "output", "rename" ]);
|
||||
var quoted_props;
|
||||
|
||||
12
lib/scope.js
12
lib/scope.js
@@ -68,9 +68,7 @@ SymbolDef.prototype = {
|
||||
var cache = this.global && options.cache && options.cache.props;
|
||||
if (cache && cache.has(this.name)) {
|
||||
this.mangled_name = cache.get(this.name);
|
||||
} else if (this.unmangleable(options)) {
|
||||
names_in_use(this.scope, options).set(this.name, true);
|
||||
} else {
|
||||
} else if (!this.unmangleable(options)) {
|
||||
var def = this.redefined();
|
||||
if (def) {
|
||||
this.mangled_name = def.mangled_name || def.name;
|
||||
@@ -651,8 +649,12 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
||||
}, true);
|
||||
}
|
||||
var to_mangle = node.to_mangle = [];
|
||||
node.variables.each(function(def) {
|
||||
if (!defer_redef(def)) to_mangle.push(def);
|
||||
node.variables.each(function(def, name) {
|
||||
if (def.unmangleable(options)) {
|
||||
names_in_use(node, options).set(name, true);
|
||||
} else if (!defer_redef(def)) {
|
||||
to_mangle.push(def);
|
||||
}
|
||||
});
|
||||
descend();
|
||||
if (options.cache && node instanceof AST_Toplevel) {
|
||||
|
||||
@@ -167,6 +167,34 @@ rename_mangle: {
|
||||
}
|
||||
}
|
||||
|
||||
mangle_export_import: {
|
||||
mangle = {
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
export let o = A;
|
||||
import { p as A } from "foo";
|
||||
}
|
||||
expect: {
|
||||
export let o = p;
|
||||
import { p } from "foo";
|
||||
}
|
||||
}
|
||||
|
||||
mangle_import_export: {
|
||||
mangle = {
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
import { p as A } from "foo";
|
||||
export let o = A;
|
||||
}
|
||||
expect: {
|
||||
import { p } from "foo";
|
||||
export let o = p;
|
||||
}
|
||||
}
|
||||
|
||||
keep_ref: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
|
||||
@@ -206,7 +206,13 @@ describe("bin/uglifyjs", function() {
|
||||
}, 1000);
|
||||
});
|
||||
it("Should work with --keep-fargs (mangle only)", function(done) {
|
||||
var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fargs -m';
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/issue-1431/sample.js",
|
||||
"--keep-fargs",
|
||||
"--mangle",
|
||||
"--no-module",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, "function f(x){return function(){function n(a){return a*a}return x(n)}}function g(op){return op(1)+op(2)}console.log(f(g)()==5);\n");
|
||||
@@ -214,7 +220,14 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should work with --keep-fargs (mangle & compress)", function(done) {
|
||||
var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fargs -m -c';
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/issue-1431/sample.js",
|
||||
"--keep-fargs",
|
||||
"--mangle",
|
||||
"--no-module",
|
||||
"--compress",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, "function f(x){return function(){return x(function(a){return a*a})}}function g(op){return op(1)+op(2)}console.log(5==f(g)());\n");
|
||||
@@ -222,7 +235,12 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should work with keep_fargs under mangler options", function(done) {
|
||||
var command = uglifyjscmd + ' test/input/issue-1431/sample.js -m keep_fargs=true';
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/issue-1431/sample.js",
|
||||
"--mangle", "keep_fargs=true",
|
||||
"--no-module",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, "function f(x){return function(){function n(a){return a*a}return x(n)}}function g(op){return op(1)+op(2)}console.log(f(g)()==5);\n");
|
||||
@@ -230,7 +248,12 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should work with --keep-fnames (mangle only)", function(done) {
|
||||
var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fnames -m';
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/issue-1431/sample.js",
|
||||
"--keep-fnames",
|
||||
"--mangle",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, "function f(r){return function(){function n(n){return n*n}return r(n)}}function g(n){return n(1)+n(2)}console.log(f(g)()==5);\n");
|
||||
@@ -238,7 +261,14 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should work with --keep-fnames (mangle & compress)", function(done) {
|
||||
var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fnames -m -c';
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/issue-1431/sample.js",
|
||||
"--keep-fnames",
|
||||
"--mangle",
|
||||
"--no-module",
|
||||
"--compress",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, "function f(n){return function(){return n(function n(r){return r*r})}}function g(n){return n(1)+n(2)}console.log(5==f(g)());\n");
|
||||
@@ -557,7 +587,11 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should throw syntax error (delete x)", function(done) {
|
||||
var command = uglifyjscmd + " test/input/invalid/delete.js";
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/invalid/delete.js",
|
||||
"--no-module",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
assert.ok(err);
|
||||
assert.strictEqual(stdout, "");
|
||||
@@ -571,7 +605,11 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should throw syntax error (function g(arguments))", function(done) {
|
||||
var command = uglifyjscmd + " test/input/invalid/function_1.js";
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/invalid/function_1.js",
|
||||
"--no-module",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
assert.ok(err);
|
||||
assert.strictEqual(stdout, "");
|
||||
@@ -585,7 +623,11 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should throw syntax error (function eval())", function(done) {
|
||||
var command = uglifyjscmd + " test/input/invalid/function_2.js";
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/invalid/function_2.js",
|
||||
"--no-module",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
assert.ok(err);
|
||||
assert.strictEqual(stdout, "");
|
||||
@@ -599,7 +641,11 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should throw syntax error (iife arguments())", function(done) {
|
||||
var command = uglifyjscmd + " test/input/invalid/function_3.js";
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/invalid/function_3.js",
|
||||
"--no-module",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
assert.ok(err);
|
||||
assert.strictEqual(stdout, "");
|
||||
@@ -613,7 +659,11 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should throw syntax error (catch (eval))", function(done) {
|
||||
var command = uglifyjscmd + " test/input/invalid/try.js";
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/invalid/try.js",
|
||||
"--no-module",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
assert.ok(err);
|
||||
assert.strictEqual(stdout, "");
|
||||
@@ -627,7 +677,11 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should throw syntax error (var eval)", function(done) {
|
||||
var command = uglifyjscmd + " test/input/invalid/var.js";
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/invalid/var.js",
|
||||
"--no-module",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
assert.ok(err);
|
||||
assert.strictEqual(stdout, "");
|
||||
@@ -641,7 +695,11 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should throw syntax error (var { eval })", function(done) {
|
||||
var command = uglifyjscmd + " test/input/invalid/destructured_var.js";
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/invalid/destructured_var.js",
|
||||
"--no-module",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
assert.ok(err);
|
||||
assert.strictEqual(stdout, "");
|
||||
@@ -807,7 +865,8 @@ describe("bin/uglifyjs", function() {
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/issue-2310/input.js",
|
||||
"-c",
|
||||
"--compress",
|
||||
"--no-module",
|
||||
"--source-map", "url=inline",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
@@ -840,7 +899,12 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should work with --mangle reserved=[]", function(done) {
|
||||
var command = uglifyjscmd + " test/input/issue-505/input.js -m reserved=[callback]";
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/issue-505/input.js",
|
||||
"--mangle", "reserved=[callback]",
|
||||
"--no-module",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, 'function test(callback){"aaaaaaaaaaaaaaaa";callback(err,data);callback(err,data)}\n');
|
||||
@@ -848,7 +912,12 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should work with --mangle reserved=false", function(done) {
|
||||
var command = uglifyjscmd + " test/input/issue-505/input.js -m reserved=false";
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/issue-505/input.js",
|
||||
"--mangle", "reserved=false",
|
||||
"--no-module",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, 'function test(a){"aaaaaaaaaaaaaaaa";a(err,data);a(err,data)}\n');
|
||||
@@ -865,7 +934,12 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should work with mangle.properties.regex from --config-file", function(done) {
|
||||
var command = uglifyjscmd + " test/input/issue-3315/input.js --config-file test/input/issue-3315/config.json";
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/issue-3315/input.js",
|
||||
"--config-file", "test/input/issue-3315/config.json",
|
||||
"--no-module",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, 'function f(){"aaaaaaaaaa";var a={prop:1,t:2};return a.prop+a.t}\n');
|
||||
@@ -882,7 +956,12 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should work with explicit --rename", function(done) {
|
||||
var command = uglifyjscmd + " test/input/rename/input.js --rename";
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/rename/input.js",
|
||||
"--no-module",
|
||||
"--rename",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, "function f(a){return b(a);function b(c){return c+c}}\n");
|
||||
@@ -890,7 +969,14 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should work with explicit --no-rename", function(done) {
|
||||
var command = uglifyjscmd + " test/input/rename/input.js -mc passes=2 --no-rename";
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/rename/input.js",
|
||||
"--compress", "passes=2",
|
||||
"--mangle",
|
||||
"--no-module",
|
||||
"--no-rename",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, "function f(n){return function(n){return n+n}(n)}\n");
|
||||
@@ -898,7 +984,13 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should work with implicit --rename", function(done) {
|
||||
var command = uglifyjscmd + " test/input/rename/input.js -mc passes=2";
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/rename/input.js",
|
||||
"--compress", "passes=2",
|
||||
"--mangle",
|
||||
"--no-module",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, "function f(n){return n+n}\n");
|
||||
@@ -906,7 +998,12 @@ describe("bin/uglifyjs", function() {
|
||||
});
|
||||
});
|
||||
it("Should work with implicit --no-rename", function(done) {
|
||||
var command = uglifyjscmd + " test/input/rename/input.js -c passes=2";
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
"test/input/rename/input.js",
|
||||
"--compress", "passes=2",
|
||||
"--no-module",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout, stderr) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, "function f(x){return function(x){return x+x}(x)}\n");
|
||||
@@ -971,12 +1068,7 @@ describe("bin/uglifyjs", function() {
|
||||
]).join("\n");
|
||||
exec(uglifyjscmd + " -mc", function(err, stdout) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(stdout, [
|
||||
"console.log(function(){",
|
||||
"var p={p:25},n={p:121},o={p:1024};",
|
||||
"return p.p+n.p+o.p",
|
||||
"}());\n",
|
||||
].join(""));
|
||||
assert.strictEqual(stdout, "console.log({p:25}.p+{p:121}.p+{p:1024}.p);\n");
|
||||
assert.strictEqual(run_code(stdout), run_code(code));
|
||||
done();
|
||||
}).stdin.end(code);
|
||||
|
||||
@@ -117,6 +117,7 @@ describe("comments", function() {
|
||||
beautify: true,
|
||||
comments: "all",
|
||||
},
|
||||
toplevel: false,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
assert.strictEqual(result.code, [
|
||||
@@ -376,6 +377,7 @@ describe("comments", function() {
|
||||
var result = UglifyJS.minify(js, {
|
||||
compress: { collapse_vars: false, reduce_vars: false },
|
||||
output: { comments: true },
|
||||
toplevel: false,
|
||||
});
|
||||
assert.strictEqual(result.code, 'function f(){/*c1*/var/*c2*/n=/*c3*/!1;return n}');
|
||||
});
|
||||
@@ -384,6 +386,7 @@ describe("comments", function() {
|
||||
var result = UglifyJS.minify(js, {
|
||||
compress: { collapse_vars: false, reduce_vars: false },
|
||||
output: { comments: false },
|
||||
toplevel: false,
|
||||
});
|
||||
assert.strictEqual(result.code, 'function f(){var n=!1;return n}');
|
||||
});
|
||||
@@ -458,6 +461,7 @@ describe("comments", function() {
|
||||
it("Should handle shebang and preamble correctly", function() {
|
||||
var code = UglifyJS.minify("#!/usr/bin/node\nvar x = 10;", {
|
||||
output: { preamble: "/* Build */" },
|
||||
toplevel: false,
|
||||
}).code;
|
||||
assert.strictEqual(code, "#!/usr/bin/node\n/* Build */\nvar x=10;");
|
||||
});
|
||||
@@ -465,6 +469,7 @@ describe("comments", function() {
|
||||
it("Should handle preamble without shebang correctly", function() {
|
||||
var code = UglifyJS.minify("var x = 10;", {
|
||||
output: { preamble: "/* Build */" },
|
||||
toplevel: false,
|
||||
}).code;
|
||||
assert.strictEqual(code, "/* Build */\nvar x=10;");
|
||||
});
|
||||
@@ -476,7 +481,10 @@ describe("comments", function() {
|
||||
for (var i = 1; i <= 5000; ++i) js += "// " + i + "\n";
|
||||
for (; i <= 10000; ++i) js += "/* " + i + " */ /**/";
|
||||
js += "x; }";
|
||||
var result = UglifyJS.minify(js, { mangle: false });
|
||||
var result = UglifyJS.minify(js, {
|
||||
mangle: false,
|
||||
toplevel: false,
|
||||
});
|
||||
assert.strictEqual(result.code, "function lots_of_comments(x){return 7-x}");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -373,7 +373,9 @@ describe("Directives", function() {
|
||||
'function f(){}'
|
||||
],
|
||||
].forEach(function(test) {
|
||||
var result = UglifyJS.minify(test[0]);
|
||||
var result = UglifyJS.minify(test[0], {
|
||||
module: false,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
assert.strictEqual(result.code, test[1], test[0]);
|
||||
});
|
||||
|
||||
@@ -5,31 +5,44 @@ var path = require("path");
|
||||
describe("bin/uglifyjs with input file globs", function() {
|
||||
var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs';
|
||||
it("bin/uglifyjs with one input file extension glob.", function(done) {
|
||||
var command = uglifyjscmd + ' "test/input/issue-1242/foo.*" -cm';
|
||||
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
'"test/input/issue-1242/foo.*"',
|
||||
"--compress",
|
||||
"--mangle",
|
||||
"--no-module",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout) {
|
||||
if (err) throw err;
|
||||
|
||||
assert.strictEqual(stdout, 'var print=console.log.bind(console);function foo(o){print("Foo:",2*o)}\n');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("bin/uglifyjs with one input file name glob.", function(done) {
|
||||
var command = uglifyjscmd + ' "test/input/issue-1242/b*.es5" -cm';
|
||||
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
'"test/input/issue-1242/b*.es5"',
|
||||
"--compress",
|
||||
"--mangle",
|
||||
"--no-module",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout) {
|
||||
if (err) throw err;
|
||||
|
||||
assert.strictEqual(stdout, 'function bar(n){return 3*n}function baz(n){return n/2}\n');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("bin/uglifyjs with multiple input file globs.", function(done) {
|
||||
var command = uglifyjscmd + ' "test/input/issue-1242/???.es5" "test/input/issue-1242/*.js" -mc toplevel,passes=3';
|
||||
|
||||
var command = [
|
||||
uglifyjscmd,
|
||||
'"test/input/issue-1242/???.es5"',
|
||||
'"test/input/issue-1242/*.js"',
|
||||
"--compress", "toplevel,passes=3",
|
||||
"--mangle",
|
||||
"--no-module",
|
||||
].join(" ");
|
||||
exec(command, function(err, stdout) {
|
||||
if (err) throw err;
|
||||
|
||||
assert.strictEqual(stdout, 'var print=console.log.bind(console);print("qux",9,6),print("Foo:",22);\n');
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -6,8 +6,11 @@ describe("Input file as map", function() {
|
||||
var jsMap = {
|
||||
'/scripts/foo.js': 'var foo = {"x": 1, y: 2, \'z\': 3};'
|
||||
};
|
||||
var result = UglifyJS.minify(jsMap, {sourceMap: true});
|
||||
|
||||
var result = UglifyJS.minify(jsMap, {
|
||||
sourceMap: true,
|
||||
toplevel: false,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
var map = JSON.parse(result.map);
|
||||
assert.strictEqual(result.code, 'var foo={x:1,y:2,z:3};');
|
||||
assert.deepEqual(map.sources, ['/scripts/foo.js']);
|
||||
@@ -26,8 +29,11 @@ describe("Input file as map", function() {
|
||||
'var foo = {"x": 1, y: 2, \'z\': 3};',
|
||||
'var bar = 15;'
|
||||
];
|
||||
var result = UglifyJS.minify(jsSeq, {sourceMap: true});
|
||||
|
||||
var result = UglifyJS.minify(jsSeq, {
|
||||
sourceMap: true,
|
||||
toplevel: false,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
var map = JSON.parse(result.map);
|
||||
assert.strictEqual(result.code, 'var foo={x:1,y:2,z:3},bar=15;');
|
||||
assert.deepEqual(map.sources, ['0', '1']);
|
||||
@@ -37,8 +43,13 @@ describe("Input file as map", function() {
|
||||
var jsMap = {
|
||||
'/scripts/foo.js': 'var foo = {"x": 1, y: 2, \'z\': 3};'
|
||||
};
|
||||
var result = UglifyJS.minify(jsMap, {sourceMap: {includeSources: true}});
|
||||
|
||||
var result = UglifyJS.minify(jsMap, {
|
||||
sourceMap: {
|
||||
includeSources: true,
|
||||
},
|
||||
toplevel: false,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
var map = JSON.parse(result.map);
|
||||
assert.strictEqual(result.code, 'var foo={x:1,y:2,z:3};');
|
||||
assert.deepEqual(map.sourcesContent, ['var foo = {"x": 1, y: 2, \'z\': 3};']);
|
||||
|
||||
@@ -11,7 +11,9 @@ function read(path) {
|
||||
describe("minify", function() {
|
||||
it("Should test basic sanity of minify with default options", function() {
|
||||
var js = "function foo(bar) { if (bar) return 3; else return 7; var u = not_called(); }";
|
||||
var result = UglifyJS.minify(js);
|
||||
var result = UglifyJS.minify(js, {
|
||||
module: false,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
assert.strictEqual(result.code, "function foo(n){return n?3:7}");
|
||||
});
|
||||
@@ -46,10 +48,13 @@ describe("minify", function() {
|
||||
].forEach(function(file) {
|
||||
var code = read("test/input/issue-1242/" + file);
|
||||
var result = UglifyJS.minify(code, {
|
||||
compress: {
|
||||
toplevel: false,
|
||||
},
|
||||
mangle: {
|
||||
cache: cache,
|
||||
toplevel: true
|
||||
}
|
||||
toplevel: true,
|
||||
},
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
original += code;
|
||||
@@ -78,10 +83,13 @@ describe("minify", function() {
|
||||
].forEach(function(file) {
|
||||
var code = read("test/input/issue-1242/" + file);
|
||||
var result = UglifyJS.minify(code, {
|
||||
mangle: {
|
||||
toplevel: true
|
||||
compress: {
|
||||
toplevel: false,
|
||||
},
|
||||
nameCache: cache
|
||||
mangle: {
|
||||
toplevel: true,
|
||||
},
|
||||
nameCache: cache,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
original += code;
|
||||
@@ -162,8 +170,10 @@ describe("minify", function() {
|
||||
var js = 'var foo = {"x": 1, y: 2, \'z\': 3};';
|
||||
var result = UglifyJS.minify(js, {
|
||||
output: {
|
||||
keep_quoted_props: true
|
||||
}});
|
||||
keep_quoted_props: true,
|
||||
},
|
||||
toplevel: false,
|
||||
});
|
||||
assert.strictEqual(result.code, 'var foo={"x":1,y:2,"z":3};');
|
||||
});
|
||||
it("Should preserve quote styles when quote_style is 3", function() {
|
||||
@@ -171,8 +181,10 @@ describe("minify", function() {
|
||||
var result = UglifyJS.minify(js, {
|
||||
output: {
|
||||
keep_quoted_props: true,
|
||||
quote_style: 3
|
||||
}});
|
||||
quote_style: 3,
|
||||
},
|
||||
toplevel: false,
|
||||
});
|
||||
assert.strictEqual(result.code, 'var foo={"x":1,y:2,\'z\':3};');
|
||||
});
|
||||
it("Should not preserve quotes in object literals when disabled", function() {
|
||||
@@ -180,8 +192,10 @@ describe("minify", function() {
|
||||
var result = UglifyJS.minify(js, {
|
||||
output: {
|
||||
keep_quoted_props: false,
|
||||
quote_style: 3
|
||||
}});
|
||||
quote_style: 3,
|
||||
},
|
||||
toplevel: false,
|
||||
});
|
||||
assert.strictEqual(result.code, 'var foo={x:1,y:2,z:3};');
|
||||
});
|
||||
});
|
||||
@@ -223,7 +237,7 @@ describe("minify", function() {
|
||||
output: {
|
||||
comments: "all",
|
||||
beautify: false,
|
||||
}
|
||||
},
|
||||
});
|
||||
var code = result.code;
|
||||
assert.strictEqual(code, "// comment1 comment2\nbar();");
|
||||
@@ -233,7 +247,8 @@ describe("minify", function() {
|
||||
output: {
|
||||
comments: "all",
|
||||
beautify: false,
|
||||
}
|
||||
},
|
||||
toplevel: false,
|
||||
});
|
||||
var code = result.code;
|
||||
assert.strictEqual(code, "var a=function(){foo()}();");
|
||||
@@ -301,7 +316,7 @@ describe("minify", function() {
|
||||
compress: false,
|
||||
mangle: false,
|
||||
output: {
|
||||
ast: true
|
||||
ast: true,
|
||||
},
|
||||
}).ast;
|
||||
assert.strictEqual(ast.TYPE, "Toplevel");
|
||||
@@ -312,9 +327,10 @@ describe("minify", function() {
|
||||
var stat = ast.body[0].body[0];
|
||||
UglifyJS.minify(ast, {
|
||||
compress: {
|
||||
sequences: false
|
||||
sequences: false,
|
||||
toplevel: false,
|
||||
},
|
||||
mangle: false
|
||||
mangle: false,
|
||||
});
|
||||
assert.ok(stat.body);
|
||||
assert.strictEqual(stat.print_to_string(), "a=x()");
|
||||
|
||||
@@ -109,6 +109,7 @@ describe("sourcemaps", function() {
|
||||
"}",
|
||||
].join("\n"), {
|
||||
sourceMap: true,
|
||||
toplevel: false,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
assert.strictEqual(result.code, "class A{static P=42;set#q(s){}}");
|
||||
@@ -187,6 +188,7 @@ describe("sourcemaps", function() {
|
||||
sourceMap: {
|
||||
content: "inline",
|
||||
},
|
||||
toplevel: false,
|
||||
warnings: true,
|
||||
});
|
||||
assert.strictEqual(result.code, "var bar=function(bar){return bar};");
|
||||
@@ -201,6 +203,7 @@ describe("sourcemaps", function() {
|
||||
content: "inline",
|
||||
url: "inline",
|
||||
},
|
||||
toplevel: false,
|
||||
warnings: true,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
@@ -296,8 +299,9 @@ describe("sourcemaps", function() {
|
||||
it("Should append source map to output js when sourceMapInline is enabled", function() {
|
||||
var result = UglifyJS.minify('var a = function(foo) { return foo; };', {
|
||||
sourceMap: {
|
||||
url: "inline"
|
||||
}
|
||||
url: "inline",
|
||||
},
|
||||
toplevel: false,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
var code = result.code;
|
||||
@@ -305,7 +309,9 @@ describe("sourcemaps", function() {
|
||||
"//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIjAiXSwibmFtZXMiOlsiYSIsImZvbyJdLCJtYXBwaW5ncyI6IkFBQUEsSUFBSUEsRUFBSSxTQUFTQyxHQUFPLE9BQU9BLENBQUsifQ==");
|
||||
});
|
||||
it("Should not append source map to output js when sourceMapInline is not enabled", function() {
|
||||
var result = UglifyJS.minify('var a = function(foo) { return foo; };');
|
||||
var result = UglifyJS.minify("var a = function(foo) { return foo; };", {
|
||||
module: false,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
var code = result.code;
|
||||
assert.strictEqual(code, "var a=function(n){return n};");
|
||||
@@ -316,11 +322,12 @@ describe("sourcemaps", function() {
|
||||
directives: false,
|
||||
},
|
||||
output: {
|
||||
max_line_len: 20
|
||||
max_line_len: 20,
|
||||
},
|
||||
sourceMap: {
|
||||
url: "inline"
|
||||
}
|
||||
url: "inline",
|
||||
},
|
||||
toplevel: false,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
assert.strictEqual(result.code, read("test/input/issue-505/output.js"));
|
||||
@@ -334,7 +341,8 @@ describe("sourcemaps", function() {
|
||||
sourceMap: {
|
||||
includeSources: true,
|
||||
url: "inline",
|
||||
}
|
||||
},
|
||||
toplevel: false,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
var map = JSON.parse(result.map);
|
||||
@@ -348,7 +356,8 @@ describe("sourcemaps", function() {
|
||||
sourceMap: {
|
||||
content: "inline",
|
||||
includeSources: true,
|
||||
}
|
||||
},
|
||||
toplevel: false,
|
||||
});
|
||||
if (result.error) throw result.error;
|
||||
map = JSON.parse(result.map);
|
||||
|
||||
@@ -3,7 +3,7 @@ require("./run")([
|
||||
"-b braces",
|
||||
"-m",
|
||||
"-mc passes=3",
|
||||
"-mc passes=3,toplevel",
|
||||
"--no-module -mc",
|
||||
"-mc passes=3,unsafe",
|
||||
"-mc keep_fargs=false,passes=3",
|
||||
"-mc keep_fargs=false,passes=3,pure_getters,unsafe,unsafe_comps,unsafe_math,unsafe_proto",
|
||||
|
||||
@@ -5,5 +5,6 @@ require("./run")([
|
||||
var args = options.split(/ /);
|
||||
args.unshift("test/jetstream.js");
|
||||
args.push("-b", "beautify=false,webkit");
|
||||
args.push("--no-module");
|
||||
return args;
|
||||
}));
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
{
|
||||
"compress": false,
|
||||
"mangle": false,
|
||||
"module": false,
|
||||
"output": {
|
||||
"beautify": true,
|
||||
"braces": true
|
||||
@@ -9,14 +10,19 @@
|
||||
"rename": true
|
||||
},
|
||||
{
|
||||
"compress": false
|
||||
"compress": false,
|
||||
"module": false
|
||||
},
|
||||
{
|
||||
"mangle": false
|
||||
"mangle": false,
|
||||
"module": false
|
||||
},
|
||||
{
|
||||
"module": false
|
||||
},
|
||||
{},
|
||||
{
|
||||
"ie": true,
|
||||
"module": false,
|
||||
"toplevel": true
|
||||
},
|
||||
{
|
||||
@@ -28,6 +34,7 @@
|
||||
},
|
||||
"keep_fargs": true,
|
||||
"keep_fnames": true,
|
||||
"module": false,
|
||||
"toplevel": true
|
||||
},
|
||||
{
|
||||
@@ -39,6 +46,7 @@
|
||||
"unsafe_math": true,
|
||||
"unsafe_proto": true,
|
||||
"unsafe_regexp": true
|
||||
}
|
||||
},
|
||||
"module": false
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user