implement --expression (#5607)

This commit is contained in:
Alex Lam S.L
2022-08-07 20:42:18 +01:00
committed by GitHub
parent 07953b36b0
commit f451a7ad79
10 changed files with 143 additions and 50 deletions

View File

@@ -53,6 +53,23 @@ describe("bin/uglifyjs", function() {
done();
});
});
it("Should work with --expression", function(done) {
exec([
uglifyjscmd,
"--expression",
"--compress",
"--mangle",
].join(" "), function(err, stdout) {
if (err) throw err;
assert.strictEqual(stdout, "function(n){for(;n(););return 42}(A)\n");
done();
}).stdin.end([
"function(x) {",
" while (x()) {}",
" return 42;",
"}(A)",
].join("\n"));
});
it("Should work with --source-map names=true", function(done) {
exec([
uglifyjscmd,
@@ -69,7 +86,7 @@ describe("bin/uglifyjs", function() {
" q: b",
"};",
"//# sourceMappingURL=data:application/json;charset=utf-8;base64,",
].join("\n")
].join("\n");
assert.strictEqual(stdout.slice(0, expected.length), expected);
var map = JSON.parse(to_ascii(stdout.slice(expected.length).trim()));
assert.deepEqual(map.names, [ "obj", "p", "a", "q", "b" ]);
@@ -97,7 +114,7 @@ describe("bin/uglifyjs", function() {
" q: b",
"};",
"//# sourceMappingURL=data:application/json;charset=utf-8;base64,",
].join("\n")
].join("\n");
assert.strictEqual(stdout.slice(0, expected.length), expected);
var map = JSON.parse(to_ascii(stdout.slice(expected.length).trim()));
assert.deepEqual(map.names, []);

View File

@@ -50,12 +50,10 @@ describe("Number literals", function() {
"0.000_000_004_2e+1_0-0B101_010+0x2_A-0o5_2+4_2",
].forEach(function(code) {
var result = UglifyJS.minify(code, {
compress: {
expression: true,
},
expression: true,
});
if (result.error) throw result.error;
assert.strictEqual(result.code, "42;");
assert.strictEqual(result.code, "42");
});
});
it("Should reject invalid use of underscore", function() {