Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3bc7cc82bb | ||
|
|
45fbdbc2dc | ||
|
|
54cb678055 | ||
|
|
e88c439eac | ||
|
|
9fc8cd4076 | ||
|
|
5476cb8f05 | ||
|
|
6a30e1d6be |
55
.travis.yml
55
.travis.yml
@@ -1,35 +1,46 @@
|
|||||||
addons:
|
|
||||||
apt:
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
packages:
|
|
||||||
- libstdc++-4.9-dev
|
|
||||||
cache:
|
cache:
|
||||||
directories: tmp
|
directories: tmp
|
||||||
language: generic
|
language: generic
|
||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
sudo: false
|
|
||||||
env:
|
env:
|
||||||
global:
|
- NODE=0.10 TYPE=compress
|
||||||
- UGLIFYJS_TEST_ALL=1
|
- NODE=0.10 TYPE=mocha
|
||||||
matrix:
|
- NODE=0.10 TYPE=release/benchmark
|
||||||
- NODEJS_VER=node/0.10
|
- NODE=0.10 TYPE=release/jetstream
|
||||||
- NODEJS_VER=node/0.12
|
- NODE=0.12 TYPE=compress
|
||||||
- NODEJS_VER=node/4
|
- NODE=0.12 TYPE=mocha
|
||||||
- NODEJS_VER=node/6
|
- NODE=0.12 TYPE=release/benchmark
|
||||||
- NODEJS_VER=node/8
|
- NODE=0.12 TYPE=release/jetstream
|
||||||
- NODEJS_VER=node/10
|
- NODE=4 TYPE=compress
|
||||||
- NODEJS_VER=node/latest
|
- NODE=4 TYPE=mocha
|
||||||
|
- NODE=4 TYPE=release/benchmark
|
||||||
|
- NODE=4 TYPE=release/jetstream
|
||||||
|
- NODE=6 TYPE=compress
|
||||||
|
- NODE=6 TYPE=mocha
|
||||||
|
- NODE=6 TYPE=release/benchmark
|
||||||
|
- NODE=6 TYPE=release/jetstream
|
||||||
|
- NODE=8 TYPE=compress
|
||||||
|
- NODE=8 TYPE=mocha
|
||||||
|
- NODE=8 TYPE=release/benchmark
|
||||||
|
- NODE=8 TYPE=release/jetstream
|
||||||
|
- NODE=10 TYPE=compress
|
||||||
|
- NODE=10 TYPE=mocha
|
||||||
|
- NODE=10 TYPE=release/benchmark
|
||||||
|
- NODE=10 TYPE=release/jetstream
|
||||||
|
- NODE=latest TYPE=compress
|
||||||
|
- NODE=latest TYPE=mocha
|
||||||
|
- NODE=latest TYPE=release/benchmark
|
||||||
|
- NODE=latest TYPE=release/jetstream
|
||||||
before_install:
|
before_install:
|
||||||
- git clone --branch v1.4.2 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
- git clone --branch v1.5.2 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
||||||
- . ~/.nvs/nvs.sh
|
- . ~/.nvs/nvs.sh
|
||||||
- nvs --version
|
- nvs --version
|
||||||
install:
|
install:
|
||||||
- nvs add $NODEJS_VER
|
- nvs add node/$NODE
|
||||||
- nvs use $NODEJS_VER
|
- nvs use node/$NODE
|
||||||
- node --version
|
- node --version
|
||||||
- npm --version --no-update-notifier
|
- npm --version --no-update-notifier
|
||||||
- npm install --no-optional --no-save --no-update-notifier
|
- npm install --no-audit --no-optional --no-save --no-update-notifier
|
||||||
script:
|
script:
|
||||||
- npm test --no-update-notifier
|
- node test/$TYPE
|
||||||
|
|||||||
88
appveyor.yml
88
appveyor.yml
@@ -1,26 +1,74 @@
|
|||||||
environment:
|
|
||||||
UGLIFYJS_TEST_ALL: 1
|
|
||||||
matrix:
|
|
||||||
- NODEJS_VER: node/0.10
|
|
||||||
- NODEJS_VER: node/0.12
|
|
||||||
- NODEJS_VER: node/4
|
|
||||||
- NODEJS_VER: node/6
|
|
||||||
- NODEJS_VER: node/8
|
|
||||||
- NODEJS_VER: node/10
|
|
||||||
- NODEJS_VER: node/latest
|
|
||||||
install:
|
|
||||||
- git clone --branch v1.4.2 --depth 1 https://github.com/jasongin/nvs.git %LOCALAPPDATA%\nvs
|
|
||||||
- set PATH=%LOCALAPPDATA%\nvs;%PATH%
|
|
||||||
- nvs --version
|
|
||||||
- nvs add %NODEJS_VER%
|
|
||||||
- nvs use %NODEJS_VER%
|
|
||||||
- node --version
|
|
||||||
- npm --version --no-update-notifier
|
|
||||||
- npm install --no-optional --no-save --no-update-notifier
|
|
||||||
build: off
|
build: off
|
||||||
cache:
|
cache:
|
||||||
- tmp
|
- tmp
|
||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
|
environment:
|
||||||
|
matrix:
|
||||||
|
- NODE: 0.10
|
||||||
|
TYPE: compress
|
||||||
|
- NODE: 0.10
|
||||||
|
TYPE: mocha
|
||||||
|
- NODE: 0.10
|
||||||
|
TYPE: release/benchmark
|
||||||
|
- NODE: 0.10
|
||||||
|
TYPE: release/jetstream
|
||||||
|
- NODE: 0.12
|
||||||
|
TYPE: compress
|
||||||
|
- NODE: 0.12
|
||||||
|
TYPE: mocha
|
||||||
|
- NODE: 0.12
|
||||||
|
TYPE: release/benchmark
|
||||||
|
- NODE: 0.12
|
||||||
|
TYPE: release/jetstream
|
||||||
|
- NODE: 4
|
||||||
|
TYPE: compress
|
||||||
|
- NODE: 4
|
||||||
|
TYPE: mocha
|
||||||
|
- NODE: 4
|
||||||
|
TYPE: release/benchmark
|
||||||
|
- NODE: 4
|
||||||
|
TYPE: release/jetstream
|
||||||
|
- NODE: 6
|
||||||
|
TYPE: compress
|
||||||
|
- NODE: 6
|
||||||
|
TYPE: mocha
|
||||||
|
- NODE: 6
|
||||||
|
TYPE: release/benchmark
|
||||||
|
- NODE: 6
|
||||||
|
TYPE: release/jetstream
|
||||||
|
- NODE: 8
|
||||||
|
TYPE: compress
|
||||||
|
- NODE: 8
|
||||||
|
TYPE: mocha
|
||||||
|
- NODE: 8
|
||||||
|
TYPE: release/benchmark
|
||||||
|
- NODE: 8
|
||||||
|
TYPE: release/jetstream
|
||||||
|
- NODE: 10
|
||||||
|
TYPE: compress
|
||||||
|
- NODE: 10
|
||||||
|
TYPE: mocha
|
||||||
|
- NODE: 10
|
||||||
|
TYPE: release/benchmark
|
||||||
|
- NODE: 10
|
||||||
|
TYPE: release/jetstream
|
||||||
|
- NODE: latest
|
||||||
|
TYPE: compress
|
||||||
|
- NODE: latest
|
||||||
|
TYPE: mocha
|
||||||
|
- NODE: latest
|
||||||
|
TYPE: release/benchmark
|
||||||
|
- NODE: latest
|
||||||
|
TYPE: release/jetstream
|
||||||
|
install:
|
||||||
|
- git clone --branch v1.5.2 --depth 1 https://github.com/jasongin/nvs.git %LOCALAPPDATA%\nvs
|
||||||
|
- set PATH=%LOCALAPPDATA%\nvs;%PATH%
|
||||||
|
- nvs --version
|
||||||
|
- nvs add node/%NODE%
|
||||||
|
- nvs use node/%NODE%
|
||||||
|
- node --version
|
||||||
|
- npm --version --no-update-notifier
|
||||||
|
- npm install --no-audit --no-optional --no-save --no-update-notifier
|
||||||
test_script:
|
test_script:
|
||||||
- npm test --no-update-notifier
|
- node test/%TYPE%
|
||||||
|
|||||||
@@ -3682,6 +3682,7 @@ merge(Compressor.prototype, {
|
|||||||
} else if (compressor.option("functions")
|
} else if (compressor.option("functions")
|
||||||
&& def.value === def.name.fixed_value()
|
&& def.value === def.name.fixed_value()
|
||||||
&& def.value instanceof AST_Function
|
&& def.value instanceof AST_Function
|
||||||
|
&& !(def.value.name && def.value.name.definition().assignments)
|
||||||
&& can_rename(def.value, def.name.name)
|
&& can_rename(def.value, def.name.name)
|
||||||
&& (!compressor.has_directive("use strict") || parent instanceof AST_Scope)) {
|
&& (!compressor.has_directive("use strict") || parent instanceof AST_Scope)) {
|
||||||
AST_Node.warn("Declaring {name} as function [{file}:{line},{col}]", template(def.name));
|
AST_Node.warn("Declaring {name} as function [{file}:{line},{col}]", template(def.name));
|
||||||
@@ -5394,7 +5395,8 @@ merge(Compressor.prototype, {
|
|||||||
|
|
||||||
OPT(AST_UnaryPrefix, function(self, compressor) {
|
OPT(AST_UnaryPrefix, function(self, compressor) {
|
||||||
var e = self.expression;
|
var e = self.expression;
|
||||||
if (self.operator == "delete"
|
if (compressor.option("evaluate")
|
||||||
|
&& self.operator == "delete"
|
||||||
&& !(e instanceof AST_SymbolRef
|
&& !(e instanceof AST_SymbolRef
|
||||||
|| e instanceof AST_PropAccess
|
|| e instanceof AST_PropAccess
|
||||||
|| is_identifier_atom(e))) {
|
|| is_identifier_atom(e))) {
|
||||||
@@ -6102,7 +6104,6 @@ merge(Compressor.prototype, {
|
|||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
value = fixed.optimize(compressor);
|
value = fixed.optimize(compressor);
|
||||||
if (value === fixed) value = fixed.clone(true);
|
|
||||||
}
|
}
|
||||||
def.replaced++;
|
def.replaced++;
|
||||||
return value;
|
return value;
|
||||||
@@ -6254,6 +6255,7 @@ merge(Compressor.prototype, {
|
|||||||
if (compressor.option("dead_code")
|
if (compressor.option("dead_code")
|
||||||
&& self.left instanceof AST_SymbolRef
|
&& self.left instanceof AST_SymbolRef
|
||||||
&& (def = self.left.definition()).scope === compressor.find_parent(AST_Lambda)) {
|
&& (def = self.left.definition()).scope === compressor.find_parent(AST_Lambda)) {
|
||||||
|
if (self.left.is_immutable()) return strip_assignment();
|
||||||
var level = 0, node, parent = self;
|
var level = 0, node, parent = self;
|
||||||
do {
|
do {
|
||||||
node = parent;
|
node = parent;
|
||||||
@@ -6261,16 +6263,12 @@ merge(Compressor.prototype, {
|
|||||||
if (parent instanceof AST_Exit) {
|
if (parent instanceof AST_Exit) {
|
||||||
if (in_try(level, parent)) break;
|
if (in_try(level, parent)) break;
|
||||||
if (is_reachable(def.scope, [ def ])) break;
|
if (is_reachable(def.scope, [ def ])) break;
|
||||||
if (self.operator == "=") return self.right.optimize(compressor);
|
|
||||||
def.fixed = false;
|
def.fixed = false;
|
||||||
return make_node(AST_Binary, self, {
|
return strip_assignment();
|
||||||
operator: self.operator.slice(0, -1),
|
|
||||||
left: self.left,
|
|
||||||
right: self.right
|
|
||||||
}).optimize(compressor);
|
|
||||||
}
|
}
|
||||||
} while (parent instanceof AST_Binary && parent.right === node
|
} while (parent instanceof AST_Binary && parent.right === node
|
||||||
|| parent instanceof AST_Sequence && parent.tail_node() === node);
|
|| parent instanceof AST_Sequence && parent.tail_node() === node
|
||||||
|
|| parent instanceof AST_UnaryPrefix);
|
||||||
}
|
}
|
||||||
self = self.lift_sequences(compressor);
|
self = self.lift_sequences(compressor);
|
||||||
if (!compressor.option("assignments")) return self;
|
if (!compressor.option("assignments")) return self;
|
||||||
@@ -6318,6 +6316,14 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function strip_assignment() {
|
||||||
|
return (self.operator != "=" ? make_node(AST_Binary, self, {
|
||||||
|
operator: self.operator.slice(0, -1),
|
||||||
|
left: self.left,
|
||||||
|
right: self.right
|
||||||
|
}) : maintain_this_binding(compressor, compressor.parent(), self, self.right)).optimize(compressor);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
OPT(AST_Conditional, function(self, compressor) {
|
OPT(AST_Conditional, function(self, compressor) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
||||||
"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.5.11",
|
"version": "3.5.12",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
"semver": "~6.0.0"
|
"semver": "~6.0.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node test/run-tests.js"
|
"test": "node test/compress.js && node test/mocha.js"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"cli",
|
"cli",
|
||||||
|
|||||||
378
test/run-tests.js → test/compress.js
Executable file → Normal file
378
test/run-tests.js → test/compress.js
Executable file → Normal file
@@ -1,25 +1,32 @@
|
|||||||
#! /usr/bin/env node
|
#! /usr/bin/env node
|
||||||
|
|
||||||
var U = require("./node");
|
|
||||||
var path = require("path");
|
|
||||||
var fs = require("fs");
|
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
|
var fs = require("fs");
|
||||||
|
var path = require("path");
|
||||||
var sandbox = require("./sandbox");
|
var sandbox = require("./sandbox");
|
||||||
var semver = require("semver");
|
var semver = require("semver");
|
||||||
|
var U = require("./node");
|
||||||
|
|
||||||
var tests_dir = path.dirname(module.filename);
|
|
||||||
var failures = 0;
|
var failures = 0;
|
||||||
var failed_files = {};
|
var failed_files = Object.create(null);
|
||||||
var minify_options = require("./ufuzz.json").map(JSON.stringify);
|
var minify_options = require("./ufuzz.json").map(JSON.stringify);
|
||||||
|
var dir = path.resolve(path.dirname(module.filename), "compress");
|
||||||
run_compress_tests();
|
fs.readdirSync(dir).filter(function(name) {
|
||||||
|
return /\.js$/i.test(name);
|
||||||
|
}).forEach(function(file) {
|
||||||
|
log("--- {file}", { file: file });
|
||||||
|
var tests = parse_test(path.resolve(dir, file));
|
||||||
|
for (var i in tests) if (!test_case(tests[i])) {
|
||||||
|
failures++;
|
||||||
|
failed_files[file] = 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
if (failures) {
|
if (failures) {
|
||||||
console.error("\n!!! Failed " + failures + " test cases.");
|
console.error();
|
||||||
|
console.error("!!! Failed " + failures + " test case(s).");
|
||||||
console.error("!!! " + Object.keys(failed_files).join(", "));
|
console.error("!!! " + Object.keys(failed_files).join(", "));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log();
|
|
||||||
require("./mocha.js");
|
|
||||||
|
|
||||||
/* -----[ utils ]----- */
|
/* -----[ utils ]----- */
|
||||||
|
|
||||||
@@ -46,11 +53,11 @@ function parse_test(file) {
|
|||||||
filename: file
|
filename: file
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("Caught error while parsing tests in " + file + "\n");
|
console.error("Caught error while parsing tests in " + file);
|
||||||
console.log(e);
|
console.error(e);
|
||||||
throw e;
|
process.exit(1);
|
||||||
}
|
}
|
||||||
var tests = {};
|
var tests = Object.create(null);
|
||||||
var tw = new U.TreeWalker(function(node, descend) {
|
var tw = new U.TreeWalker(function(node, descend) {
|
||||||
if (node instanceof U.AST_LabeledStatement
|
if (node instanceof U.AST_LabeledStatement
|
||||||
&& tw.parent() instanceof U.AST_Toplevel) {
|
&& tw.parent() instanceof U.AST_Toplevel) {
|
||||||
@@ -167,7 +174,17 @@ function reminify(orig_options, input_code, input_formatted, expect_stdout) {
|
|||||||
var options_formatted = JSON.stringify(options, null, 4);
|
var options_formatted = JSON.stringify(options, null, 4);
|
||||||
var result = U.minify(input_code, options);
|
var result = U.minify(input_code, options);
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
log("!!! failed input reminify\n---INPUT---\n{input}\n---OPTIONS---\n{options}\n--ERROR---\n{error}\n\n", {
|
log([
|
||||||
|
"!!! failed input reminify",
|
||||||
|
"---INPUT---",
|
||||||
|
"{input}",
|
||||||
|
"---OPTIONS---",
|
||||||
|
"{options}",
|
||||||
|
"--ERROR---",
|
||||||
|
"{error}",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
].join("\n"), {
|
||||||
input: input_formatted,
|
input: input_formatted,
|
||||||
options: options_formatted,
|
options: options_formatted,
|
||||||
error: result.error,
|
error: result.error,
|
||||||
@@ -179,7 +196,21 @@ function reminify(orig_options, input_code, input_formatted, expect_stdout) {
|
|||||||
stdout = expect_stdout;
|
stdout = expect_stdout;
|
||||||
}
|
}
|
||||||
if (!sandbox.same_stdout(expect_stdout, stdout)) {
|
if (!sandbox.same_stdout(expect_stdout, stdout)) {
|
||||||
log("!!! failed running reminified input\n---INPUT---\n{input}\n---OPTIONS---\n{options}\n---OUTPUT---\n{output}\n---EXPECTED {expected_type}---\n{expected}\n---ACTUAL {actual_type}---\n{actual}\n\n", {
|
log([
|
||||||
|
"!!! failed running reminified input",
|
||||||
|
"---INPUT---",
|
||||||
|
"{input}",
|
||||||
|
"---OPTIONS---",
|
||||||
|
"{options}",
|
||||||
|
"---OUTPUT---",
|
||||||
|
"{output}",
|
||||||
|
"---EXPECTED {expected_type}---",
|
||||||
|
"{expected}",
|
||||||
|
"---ACTUAL {actual_type}---",
|
||||||
|
"{actual}",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
].join("\n"), {
|
||||||
input: input_formatted,
|
input: input_formatted,
|
||||||
options: options_formatted,
|
options: options_formatted,
|
||||||
output: result.code,
|
output: result.code,
|
||||||
@@ -200,143 +231,186 @@ function run_code(code) {
|
|||||||
return typeof result == "string" ? result.replace(/\u001b\[\d+m/g, "") : result;
|
return typeof result == "string" ? result.replace(/\u001b\[\d+m/g, "") : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function run_compress_tests() {
|
function test_case(test) {
|
||||||
var dir = path.resolve(tests_dir, "compress");
|
log(" Running test [{name}]", { name: test.name });
|
||||||
fs.readdirSync(dir).filter(function(name) {
|
var output_options = test.beautify || {};
|
||||||
return /\.js$/i.test(name);
|
var expect;
|
||||||
}).forEach(function(file) {
|
if (test.expect) {
|
||||||
log("--- {file}", { file: file });
|
expect = make_code(to_toplevel(test.expect, test.mangle), output_options);
|
||||||
function test_case(test) {
|
} else {
|
||||||
log(" Running test [{name}]", { name: test.name });
|
expect = test.expect_exact;
|
||||||
var output_options = test.beautify || {};
|
}
|
||||||
var expect;
|
var input = to_toplevel(test.input, test.mangle);
|
||||||
if (test.expect) {
|
var input_code = make_code(input);
|
||||||
expect = make_code(to_toplevel(test.expect, test.mangle), output_options);
|
var input_formatted = make_code(test.input, {
|
||||||
} else {
|
beautify: true,
|
||||||
expect = test.expect_exact;
|
comments: "all",
|
||||||
}
|
keep_quoted_props: true,
|
||||||
var input = to_toplevel(test.input, test.mangle);
|
quote_style: 3,
|
||||||
var input_code = make_code(input);
|
|
||||||
var input_formatted = make_code(test.input, {
|
|
||||||
beautify: true,
|
|
||||||
comments: "all",
|
|
||||||
keep_quoted_props: true,
|
|
||||||
quote_style: 3,
|
|
||||||
});
|
|
||||||
try {
|
|
||||||
U.parse(input_code);
|
|
||||||
} catch (ex) {
|
|
||||||
log("!!! Cannot parse input\n---INPUT---\n{input}\n--PARSE ERROR--\n{error}\n\n", {
|
|
||||||
input: input_formatted,
|
|
||||||
error: ex,
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
var warnings_emitted = [];
|
|
||||||
if (test.expect_warnings) {
|
|
||||||
var expected_warnings = make_code(test.expect_warnings, {
|
|
||||||
beautify: false,
|
|
||||||
quote_style: 2, // force double quote to match JSON
|
|
||||||
});
|
|
||||||
U.AST_Node.log_function(function(text) {
|
|
||||||
warnings_emitted.push(text);
|
|
||||||
}, /"INFO: /.test(expected_warnings));
|
|
||||||
}
|
|
||||||
if (test.mangle && test.mangle.properties && test.mangle.properties.keep_quoted) {
|
|
||||||
var quoted_props = test.mangle.properties.reserved;
|
|
||||||
if (!Array.isArray(quoted_props)) quoted_props = [];
|
|
||||||
test.mangle.properties.reserved = quoted_props;
|
|
||||||
U.reserve_quoted_keys(input, quoted_props);
|
|
||||||
}
|
|
||||||
if (test.rename) {
|
|
||||||
input.figure_out_scope(test.mangle);
|
|
||||||
input.expand_names(test.mangle);
|
|
||||||
}
|
|
||||||
var cmp = new U.Compressor(test.options, true);
|
|
||||||
var output = cmp.compress(input);
|
|
||||||
output.figure_out_scope(test.mangle);
|
|
||||||
if (test.mangle) {
|
|
||||||
output.compute_char_frequency(test.mangle);
|
|
||||||
output.mangle_names(test.mangle);
|
|
||||||
if (test.mangle.properties) {
|
|
||||||
output = U.mangle_properties(output, test.mangle.properties);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
output = make_code(output, output_options);
|
|
||||||
if (expect != output) {
|
|
||||||
log("!!! failed\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n---EXPECTED---\n{expected}\n\n", {
|
|
||||||
input: input_formatted,
|
|
||||||
output: output,
|
|
||||||
expected: expect
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// expect == output
|
|
||||||
try {
|
|
||||||
U.parse(output);
|
|
||||||
} catch (ex) {
|
|
||||||
log("!!! Test matched expected result but cannot parse output\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n--REPARSE ERROR--\n{error}\n\n", {
|
|
||||||
input: input_formatted,
|
|
||||||
output: output,
|
|
||||||
error: ex,
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (test.expect_warnings) {
|
|
||||||
warnings_emitted = warnings_emitted.map(function(input) {
|
|
||||||
return input.split(process.cwd() + path.sep).join("").split(path.sep).join("/");
|
|
||||||
});
|
|
||||||
var actual_warnings = JSON.stringify(warnings_emitted);
|
|
||||||
if (expected_warnings != actual_warnings) {
|
|
||||||
log("!!! failed\n---INPUT---\n{input}\n---EXPECTED WARNINGS---\n{expected_warnings}\n---ACTUAL WARNINGS---\n{actual_warnings}\n\n", {
|
|
||||||
input: input_formatted,
|
|
||||||
expected_warnings: expected_warnings,
|
|
||||||
actual_warnings: actual_warnings,
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (test.expect_stdout
|
|
||||||
&& (!test.node_version || semver.satisfies(process.version, test.node_version))) {
|
|
||||||
var stdout = run_code(input_code);
|
|
||||||
if (test.expect_stdout === true) {
|
|
||||||
test.expect_stdout = stdout;
|
|
||||||
}
|
|
||||||
if (!sandbox.same_stdout(test.expect_stdout, stdout)) {
|
|
||||||
log("!!! Invalid input or expected stdout\n---INPUT---\n{input}\n---EXPECTED {expected_type}---\n{expected}\n---ACTUAL {actual_type}---\n{actual}\n\n", {
|
|
||||||
input: input_formatted,
|
|
||||||
expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR",
|
|
||||||
expected: test.expect_stdout,
|
|
||||||
actual_type: typeof stdout == "string" ? "STDOUT" : "ERROR",
|
|
||||||
actual: stdout,
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
stdout = run_code(output);
|
|
||||||
if (!sandbox.same_stdout(test.expect_stdout, stdout)) {
|
|
||||||
log("!!! failed\n---INPUT---\n{input}\n---EXPECTED {expected_type}---\n{expected}\n---ACTUAL {actual_type}---\n{actual}\n\n", {
|
|
||||||
input: input_formatted,
|
|
||||||
expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR",
|
|
||||||
expected: test.expect_stdout,
|
|
||||||
actual_type: typeof stdout == "string" ? "STDOUT" : "ERROR",
|
|
||||||
actual: stdout,
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!reminify(test.options, input_code, input_formatted, test.expect_stdout)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
var tests = parse_test(path.resolve(dir, file));
|
|
||||||
for (var i in tests) if (tests.hasOwnProperty(i)) {
|
|
||||||
if (!test_case(tests[i])) {
|
|
||||||
failures++;
|
|
||||||
failed_files[file] = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
try {
|
||||||
|
U.parse(input_code);
|
||||||
|
} catch (ex) {
|
||||||
|
log([
|
||||||
|
"!!! Cannot parse input",
|
||||||
|
"---INPUT---",
|
||||||
|
"{input}",
|
||||||
|
"--PARSE ERROR--",
|
||||||
|
"{error}",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
].join("\n"), {
|
||||||
|
input: input_formatted,
|
||||||
|
error: ex,
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var warnings_emitted = [];
|
||||||
|
if (test.expect_warnings) {
|
||||||
|
var expected_warnings = make_code(test.expect_warnings, {
|
||||||
|
beautify: false,
|
||||||
|
quote_style: 2, // force double quote to match JSON
|
||||||
|
});
|
||||||
|
U.AST_Node.log_function(function(text) {
|
||||||
|
warnings_emitted.push(text);
|
||||||
|
}, /"INFO: /.test(expected_warnings));
|
||||||
|
}
|
||||||
|
if (test.mangle && test.mangle.properties && test.mangle.properties.keep_quoted) {
|
||||||
|
var quoted_props = test.mangle.properties.reserved;
|
||||||
|
if (!Array.isArray(quoted_props)) quoted_props = [];
|
||||||
|
test.mangle.properties.reserved = quoted_props;
|
||||||
|
U.reserve_quoted_keys(input, quoted_props);
|
||||||
|
}
|
||||||
|
if (test.rename) {
|
||||||
|
input.figure_out_scope(test.mangle);
|
||||||
|
input.expand_names(test.mangle);
|
||||||
|
}
|
||||||
|
var cmp = new U.Compressor(test.options, true);
|
||||||
|
var output = cmp.compress(input);
|
||||||
|
output.figure_out_scope(test.mangle);
|
||||||
|
if (test.mangle) {
|
||||||
|
output.compute_char_frequency(test.mangle);
|
||||||
|
output.mangle_names(test.mangle);
|
||||||
|
if (test.mangle.properties) {
|
||||||
|
output = U.mangle_properties(output, test.mangle.properties);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output = make_code(output, output_options);
|
||||||
|
if (expect != output) {
|
||||||
|
log([
|
||||||
|
"!!! failed",
|
||||||
|
"---INPUT---",
|
||||||
|
"{input}",
|
||||||
|
"---OUTPUT---",
|
||||||
|
"{output}",
|
||||||
|
"---EXPECTED---",
|
||||||
|
"{expected}",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
].join("\n"), {
|
||||||
|
input: input_formatted,
|
||||||
|
output: output,
|
||||||
|
expected: expect
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// expect == output
|
||||||
|
try {
|
||||||
|
U.parse(output);
|
||||||
|
} catch (ex) {
|
||||||
|
log([
|
||||||
|
"!!! Test matched expected result but cannot parse output",
|
||||||
|
"---INPUT---",
|
||||||
|
"{input}",
|
||||||
|
"---OUTPUT---",
|
||||||
|
"{output}",
|
||||||
|
"--REPARSE ERROR--",
|
||||||
|
"{error}",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
].join("\n"), {
|
||||||
|
input: input_formatted,
|
||||||
|
output: output,
|
||||||
|
error: ex,
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (test.expect_warnings) {
|
||||||
|
warnings_emitted = warnings_emitted.map(function(input) {
|
||||||
|
return input.split(process.cwd() + path.sep).join("").split(path.sep).join("/");
|
||||||
|
});
|
||||||
|
var actual_warnings = JSON.stringify(warnings_emitted);
|
||||||
|
if (expected_warnings != actual_warnings) {
|
||||||
|
log([
|
||||||
|
"!!! failed",
|
||||||
|
"---INPUT---",
|
||||||
|
"{input}",
|
||||||
|
"---EXPECTED WARNINGS---",
|
||||||
|
"{expected_warnings}",
|
||||||
|
"---ACTUAL WARNINGS---",
|
||||||
|
"{actual_warnings}",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
].join("\n"), {
|
||||||
|
input: input_formatted,
|
||||||
|
expected_warnings: expected_warnings,
|
||||||
|
actual_warnings: actual_warnings,
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (test.expect_stdout
|
||||||
|
&& (!test.node_version || semver.satisfies(process.version, test.node_version))) {
|
||||||
|
var stdout = run_code(input_code);
|
||||||
|
if (test.expect_stdout === true) {
|
||||||
|
test.expect_stdout = stdout;
|
||||||
|
}
|
||||||
|
if (!sandbox.same_stdout(test.expect_stdout, stdout)) {
|
||||||
|
log([
|
||||||
|
"!!! Invalid input or expected stdout",
|
||||||
|
"---INPUT---",
|
||||||
|
"{input}",
|
||||||
|
"---EXPECTED {expected_type}---",
|
||||||
|
"{expected}",
|
||||||
|
"---ACTUAL {actual_type}---",
|
||||||
|
"{actual}",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
].join("\n"), {
|
||||||
|
input: input_formatted,
|
||||||
|
expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR",
|
||||||
|
expected: test.expect_stdout,
|
||||||
|
actual_type: typeof stdout == "string" ? "STDOUT" : "ERROR",
|
||||||
|
actual: stdout,
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
stdout = run_code(output);
|
||||||
|
if (!sandbox.same_stdout(test.expect_stdout, stdout)) {
|
||||||
|
log([
|
||||||
|
"!!! failed",
|
||||||
|
"---INPUT---",
|
||||||
|
"{input}",
|
||||||
|
"---EXPECTED {expected_type}---",
|
||||||
|
"{expected}",
|
||||||
|
"---ACTUAL {actual_type}---",
|
||||||
|
"{actual}",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
].join("\n"), {
|
||||||
|
input: input_formatted,
|
||||||
|
expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR",
|
||||||
|
expected: test.expect_stdout,
|
||||||
|
actual_type: typeof stdout == "string" ? "STDOUT" : "ERROR",
|
||||||
|
actual: stdout,
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!reminify(test.options, input_code, input_formatted, test.expect_stdout)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function tmpl() {
|
function tmpl() {
|
||||||
@@ -3497,10 +3497,10 @@ issue_2437_1: {
|
|||||||
return Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {}),
|
return Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {}),
|
||||||
result;
|
result;
|
||||||
}
|
}
|
||||||
var req, detectFunc = function(){};
|
var req = new XMLHttpRequest(), detectFunc = function(){};
|
||||||
(req = new XMLHttpRequest()).onreadystatechange = detectFunc;
|
return req.onreadystatechange = detectFunc,
|
||||||
result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc;
|
result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc,
|
||||||
return req.onreadystatechange = null, result;
|
req.onreadystatechange = null, result;
|
||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3545,8 +3545,8 @@ issue_2437_2: {
|
|||||||
if (xhrDesc)
|
if (xhrDesc)
|
||||||
return (req = new XMLHttpRequest()).onreadystatechange,
|
return (req = new XMLHttpRequest()).onreadystatechange,
|
||||||
Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {});
|
Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {});
|
||||||
var req;
|
var req = new XMLHttpRequest();
|
||||||
(req = new XMLHttpRequest).onreadystatechange = function(){},
|
req.onreadystatechange = function(){},
|
||||||
req[SYMBOL_FAKE_ONREADYSTATECHANGE_1],
|
req[SYMBOL_FAKE_ONREADYSTATECHANGE_1],
|
||||||
req.onreadystatechange = null;
|
req.onreadystatechange = null;
|
||||||
}();
|
}();
|
||||||
|
|||||||
@@ -960,3 +960,56 @@ unsafe_string_replace: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3402: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
functions: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
typeofs: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var f = function f() {
|
||||||
|
f = 42;
|
||||||
|
console.log(typeof f);
|
||||||
|
};
|
||||||
|
"function" == typeof f && f();
|
||||||
|
"function" == typeof f && f();
|
||||||
|
console.log(typeof f);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
console.log(typeof f);
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
f();
|
||||||
|
console.log(typeof f);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"function",
|
||||||
|
"function",
|
||||||
|
"function",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3406: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function f(a) {
|
||||||
|
return delete (f = a);
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function f(a) {
|
||||||
|
return delete (0, a);
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "true"
|
||||||
|
}
|
||||||
|
|||||||
@@ -797,6 +797,7 @@ assign_chain: {
|
|||||||
issue_1583: {
|
issue_1583: {
|
||||||
options = {
|
options = {
|
||||||
keep_fargs: true,
|
keep_fargs: true,
|
||||||
|
passes: 2,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -1004,7 +1005,7 @@ issue_1715_4: {
|
|||||||
delete_assign_1: {
|
delete_assign_1: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
side_effects: true,
|
evaluate: true,
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -1023,7 +1024,7 @@ delete_assign_1: {
|
|||||||
console.log((1 / 0, !0));
|
console.log((1 / 0, !0));
|
||||||
console.log((1 / 0, !0));
|
console.log((1 / 0, !0));
|
||||||
console.log((NaN, !0));
|
console.log((NaN, !0));
|
||||||
console.log((0 / 0, !0));
|
console.log((NaN, !0));
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
@@ -1031,8 +1032,8 @@ delete_assign_1: {
|
|||||||
delete_assign_2: {
|
delete_assign_2: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
keep_infinity: true,
|
keep_infinity: true,
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
toplevel: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
}
|
}
|
||||||
@@ -1051,7 +1052,7 @@ delete_assign_2: {
|
|||||||
console.log((Infinity, !0));
|
console.log((Infinity, !0));
|
||||||
console.log((1 / 0, !0));
|
console.log((1 / 0, !0));
|
||||||
console.log((NaN, !0));
|
console.log((NaN, !0));
|
||||||
console.log((0 / 0, !0));
|
console.log((NaN, !0));
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
@@ -1144,6 +1145,7 @@ var_catch_toplevel: {
|
|||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
negate_iife: true,
|
negate_iife: true,
|
||||||
|
passes: 2,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
|
|||||||
@@ -2860,10 +2860,10 @@ issue_2437: {
|
|||||||
result;
|
result;
|
||||||
}
|
}
|
||||||
function detectFunc() {}
|
function detectFunc() {}
|
||||||
var req;
|
var req = new XMLHttpRequest();
|
||||||
(req = new XMLHttpRequest()).onreadystatechange = detectFunc;
|
return req.onreadystatechange = detectFunc,
|
||||||
result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc;
|
result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc,
|
||||||
return req.onreadystatechange = null, result;
|
req.onreadystatechange = null, result;
|
||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3065,3 +3065,86 @@ class_iife: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3400: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(f) {
|
||||||
|
console.log(f()()[0].p);
|
||||||
|
})(function() {
|
||||||
|
function g() {
|
||||||
|
function h(u) {
|
||||||
|
var o = {
|
||||||
|
p: u
|
||||||
|
};
|
||||||
|
return console.log(o[g]), o;
|
||||||
|
}
|
||||||
|
function e() {
|
||||||
|
return [ 42 ].map(function(v) {
|
||||||
|
return h(v);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return e();
|
||||||
|
}
|
||||||
|
return g;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
void console.log(function g() {
|
||||||
|
function e() {
|
||||||
|
return [42].map(function(v) {
|
||||||
|
return o = {
|
||||||
|
p: v
|
||||||
|
}, console.log(o[g]) , o;
|
||||||
|
var o;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return e();
|
||||||
|
}()[0].p);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"undefined",
|
||||||
|
"42",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3402: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
functions: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
typeofs: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var f = function f() {
|
||||||
|
f = 42;
|
||||||
|
console.log(typeof f);
|
||||||
|
};
|
||||||
|
"function" == typeof f && f();
|
||||||
|
"function" == typeof f && f();
|
||||||
|
console.log(typeof f);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var f = function f() {
|
||||||
|
f = 42;
|
||||||
|
console.log(typeof f);
|
||||||
|
};
|
||||||
|
f();
|
||||||
|
f();
|
||||||
|
console.log(typeof f);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"function",
|
||||||
|
"function",
|
||||||
|
"function",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
@@ -490,6 +490,7 @@ issue_1758: {
|
|||||||
delete_seq_1: {
|
delete_seq_1: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -514,6 +515,7 @@ delete_seq_1: {
|
|||||||
delete_seq_2: {
|
delete_seq_2: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -538,6 +540,7 @@ delete_seq_2: {
|
|||||||
delete_seq_3: {
|
delete_seq_3: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
keep_infinity: true,
|
keep_infinity: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
@@ -563,6 +566,7 @@ delete_seq_3: {
|
|||||||
delete_seq_4: {
|
delete_seq_4: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
@@ -590,6 +594,7 @@ delete_seq_4: {
|
|||||||
delete_seq_5: {
|
delete_seq_5: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
keep_infinity: true,
|
keep_infinity: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
@@ -618,6 +623,7 @@ delete_seq_5: {
|
|||||||
delete_seq_6: {
|
delete_seq_6: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
|
evaluate: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
|
|||||||
@@ -62,8 +62,17 @@ if (typeof phantom == "undefined") {
|
|||||||
if (debug) {
|
if (debug) {
|
||||||
console.log("http://localhost:" + port + "/");
|
console.log("http://localhost:" + port + "/");
|
||||||
} else {
|
} else {
|
||||||
child_process.exec("npm install phantomjs-prebuilt@2.1.14 --no-save", function(error) {
|
child_process.spawn(process.platform == "win32" ? "npm.cmd" : "npm", [
|
||||||
if (error) throw error;
|
"install",
|
||||||
|
"phantomjs-prebuilt@2.1.14",
|
||||||
|
"--no-audit",
|
||||||
|
"--no-optional",
|
||||||
|
"--no-save",
|
||||||
|
"--no-update-notifier",
|
||||||
|
], {
|
||||||
|
stdio: [ "ignore", 1, 2 ]
|
||||||
|
}).on("exit", function(code) {
|
||||||
|
if (code) throw new Error("npm install failed!");
|
||||||
var program = require("phantomjs-prebuilt").exec(process.argv[1], port);
|
var program = require("phantomjs-prebuilt").exec(process.argv[1], port);
|
||||||
program.stdout.pipe(process.stdout);
|
program.stdout.pipe(process.stdout);
|
||||||
program.stderr.pipe(process.stderr);
|
program.stderr.pipe(process.stderr);
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
var assert = require("assert");
|
|
||||||
var semver = require("semver");
|
|
||||||
var spawn = require("child_process").spawn;
|
|
||||||
|
|
||||||
if (!process.env.UGLIFYJS_TEST_ALL) return;
|
|
||||||
|
|
||||||
function run(command, args, done) {
|
|
||||||
spawn(command, args, {
|
|
||||||
stdio: [ "ignore", 1, 2 ]
|
|
||||||
}).on("exit", function(code) {
|
|
||||||
assert.strictEqual(code, 0);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("test/benchmark.js", function() {
|
|
||||||
this.timeout(10 * 60 * 1000);
|
|
||||||
[
|
|
||||||
"-b",
|
|
||||||
"-b braces",
|
|
||||||
"-m",
|
|
||||||
"-mc passes=3",
|
|
||||||
"-mc passes=3,toplevel",
|
|
||||||
"-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",
|
|
||||||
].forEach(function(options) {
|
|
||||||
it("Should pass with options " + options, function(done) {
|
|
||||||
var args = options.split(/ /);
|
|
||||||
args.unshift("test/benchmark.js");
|
|
||||||
run(process.argv[0], args, done);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (semver.satisfies(process.version, "0.12")) return;
|
|
||||||
describe("test/jetstream.js", function() {
|
|
||||||
this.timeout(20 * 60 * 1000);
|
|
||||||
[
|
|
||||||
"-mc",
|
|
||||||
"-mc keep_fargs=false,passes=3,pure_getters,unsafe,unsafe_comps,unsafe_math,unsafe_proto",
|
|
||||||
].forEach(function(options) {
|
|
||||||
it("Should pass with options " + options, function(done) {
|
|
||||||
var args = options.split(/ /);
|
|
||||||
args.unshift("test/jetstream.js");
|
|
||||||
args.push("-b", "beautify=false,webkit");
|
|
||||||
run(process.argv[0], args, done);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
14
test/release/benchmark.js
Normal file
14
test/release/benchmark.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
require("./run")([
|
||||||
|
"-b",
|
||||||
|
"-b braces",
|
||||||
|
"-m",
|
||||||
|
"-mc passes=3",
|
||||||
|
"-mc passes=3,toplevel",
|
||||||
|
"-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",
|
||||||
|
].map(function(options) {
|
||||||
|
var args = options.split(/ /);
|
||||||
|
args.unshift("test/benchmark.js");
|
||||||
|
return args;
|
||||||
|
}));
|
||||||
9
test/release/jetstream.js
Normal file
9
test/release/jetstream.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
require("./run")([
|
||||||
|
"-mc",
|
||||||
|
"-mc keep_fargs=false,passes=3,pure_getters,unsafe,unsafe_comps,unsafe_math,unsafe_proto",
|
||||||
|
].map(function(options) {
|
||||||
|
var args = options.split(/ /);
|
||||||
|
args.unshift("test/jetstream.js");
|
||||||
|
args.push("-b", "beautify=false,webkit");
|
||||||
|
return args;
|
||||||
|
}));
|
||||||
16
test/release/run.js
Normal file
16
test/release/run.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
var child_process = require("child_process");
|
||||||
|
|
||||||
|
module.exports = function(tasks) {
|
||||||
|
(function next() {
|
||||||
|
if (!tasks.length) return;
|
||||||
|
var args = tasks.shift();
|
||||||
|
console.log();
|
||||||
|
console.log("\u001B[36m$> " + args.join(" ") + "\u001B[39m");
|
||||||
|
child_process.spawn(process.argv[0], args, {
|
||||||
|
stdio: [ "ignore", 1, 2 ]
|
||||||
|
}).on("exit", function(code) {
|
||||||
|
if (code) process.exit(code);
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user