Compare commits
78 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34075fc4c4 | ||
|
|
e5436ca566 | ||
|
|
cfde686eab | ||
|
|
a206964c0a | ||
|
|
c56d89f804 | ||
|
|
c215706350 | ||
|
|
d3b93ec682 | ||
|
|
6fe20dbe33 | ||
|
|
7ccdf3337b | ||
|
|
dafed54764 | ||
|
|
a84beafd1b | ||
|
|
f01cc1e413 | ||
|
|
338dd144b8 | ||
|
|
c719552317 | ||
|
|
855964a87a | ||
|
|
a438e2fca9 | ||
|
|
00833e893a | ||
|
|
f1a77e4fc0 | ||
|
|
b55a2fd531 | ||
|
|
e8a2c0b5bf | ||
|
|
21cd7e3f57 | ||
|
|
5172ba5f2a | ||
|
|
a57b069409 | ||
|
|
4454656c3b | ||
|
|
fa43768ce0 | ||
|
|
a74e600fa0 | ||
|
|
4b21526310 | ||
|
|
a7a7b1daed | ||
|
|
7436977aa5 | ||
|
|
e3c565b46f | ||
|
|
54b0b49b68 | ||
|
|
65648d84a5 | ||
|
|
fd788590f6 | ||
|
|
143f9054da | ||
|
|
f2286c33f1 | ||
|
|
b9615f7a62 | ||
|
|
c520e99eda | ||
|
|
615ae37ca3 | ||
|
|
7aa7f21872 | ||
|
|
4430a436eb | ||
|
|
9707ccdc9f | ||
|
|
cb8f3a2a31 | ||
|
|
8b3259e0c2 | ||
|
|
b66f47b8dd | ||
|
|
8d2e6f333e | ||
|
|
b3ef5e514d | ||
|
|
627f5fb41e | ||
|
|
d90777b724 | ||
|
|
e49297e5eb | ||
|
|
ebd82b3fb6 | ||
|
|
d074aa6e27 | ||
|
|
b052f62710 | ||
|
|
d4ac84b255 | ||
|
|
e250396d7e | ||
|
|
c6fa39b482 | ||
|
|
9aae4f2424 | ||
|
|
008c236137 | ||
|
|
b1c0664066 | ||
|
|
ea999b0e92 | ||
|
|
ce7e220de4 | ||
|
|
2bdaca10ae | ||
|
|
aa0029204e | ||
|
|
f352bcec3a | ||
|
|
08514030f4 | ||
|
|
694ca5d045 | ||
|
|
57fb58b263 | ||
|
|
18c1c9b38a | ||
|
|
5c1ae3662d | ||
|
|
cfebeb2f63 | ||
|
|
fc78423f1d | ||
|
|
2a5277b391 | ||
|
|
d47547dc71 | ||
|
|
304db15a20 | ||
|
|
7cf72b8d66 | ||
|
|
cea685f8d9 | ||
|
|
8d4b5344f4 | ||
|
|
34a0ab6f2c | ||
|
|
bcebacbb9e |
@@ -19,6 +19,7 @@ env:
|
|||||||
- NODEJS_VER=node/4
|
- NODEJS_VER=node/4
|
||||||
- NODEJS_VER=node/6
|
- NODEJS_VER=node/6
|
||||||
- NODEJS_VER=node/8
|
- NODEJS_VER=node/8
|
||||||
|
- NODEJS_VER=node/10
|
||||||
- NODEJS_VER=node/latest
|
- NODEJS_VER=node/latest
|
||||||
before_install:
|
before_install:
|
||||||
- git clone --branch v1.4.2 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
- git clone --branch v1.4.2 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
||||||
|
|||||||
11
README.md
11
README.md
@@ -605,6 +605,8 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
- `arguments` (default: `true`) -- replace `arguments[index]` with function
|
- `arguments` (default: `true`) -- replace `arguments[index]` with function
|
||||||
parameter name whenever possible.
|
parameter name whenever possible.
|
||||||
|
|
||||||
|
- `assignments` (default: `true`) -- apply optimizations to assignment expressions.
|
||||||
|
|
||||||
- `booleans` (default: `true`) -- various optimizations for boolean context,
|
- `booleans` (default: `true`) -- various optimizations for boolean context,
|
||||||
for example `!!a ? b : c → a ? b : c`
|
for example `!!a ? b : c → a ? b : c`
|
||||||
|
|
||||||
@@ -634,6 +636,9 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
- `expression` (default: `false`) -- Pass `true` to preserve completion values
|
- `expression` (default: `false`) -- Pass `true` to preserve completion values
|
||||||
from terminal statements without `return`, e.g. in bookmarklets.
|
from terminal statements without `return`, e.g. in bookmarklets.
|
||||||
|
|
||||||
|
- `functions` (default: `true`) -- convert declarations from `var`to `function`
|
||||||
|
whenever possible.
|
||||||
|
|
||||||
- `global_defs` (default: `{}`) -- see [conditional compilation](#conditional-compilation)
|
- `global_defs` (default: `{}`) -- see [conditional compilation](#conditional-compilation)
|
||||||
|
|
||||||
- `hoist_funs` (default: `false`) -- hoist function declarations
|
- `hoist_funs` (default: `false`) -- hoist function declarations
|
||||||
@@ -664,7 +669,7 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
|||||||
|
|
||||||
- `keep_fnames` (default: `false`) -- Pass `true` to prevent the
|
- `keep_fnames` (default: `false`) -- Pass `true` to prevent the
|
||||||
compressor from discarding function names. Useful for code relying on
|
compressor from discarding function names. Useful for code relying on
|
||||||
`Function.prototype.name`. See also: the `keep_fnames` [mangle option](#mangle).
|
`Function.prototype.name`. See also: the `keep_fnames` [mangle option](#mangle-options).
|
||||||
|
|
||||||
- `keep_infinity` (default: `false`) -- Pass `true` to prevent `Infinity` from
|
- `keep_infinity` (default: `false`) -- Pass `true` to prevent `Infinity` from
|
||||||
being compressed into `1/0`, which may cause performance issues on Chrome.
|
being compressed into `1/0`, which may cause performance issues on Chrome.
|
||||||
@@ -857,8 +862,8 @@ can pass additional arguments that control the code output:
|
|||||||
adjust for this text. Can be used to insert a comment containing
|
adjust for this text. Can be used to insert a comment containing
|
||||||
licensing information, for example.
|
licensing information, for example.
|
||||||
|
|
||||||
- `preserve_line` (default `false`) -- pass `true` to preserve lines, but it
|
- `preserve_line` (default `false`) -- pass `true` to retain line numbering on
|
||||||
only works if `beautify` is set to `false`.
|
a best effort basis.
|
||||||
|
|
||||||
- `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
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ environment:
|
|||||||
- NODEJS_VER: node/4
|
- NODEJS_VER: node/4
|
||||||
- NODEJS_VER: node/6
|
- NODEJS_VER: node/6
|
||||||
- NODEJS_VER: node/8
|
- NODEJS_VER: node/8
|
||||||
|
- NODEJS_VER: node/10
|
||||||
- NODEJS_VER: node/latest
|
- NODEJS_VER: node/latest
|
||||||
install:
|
install:
|
||||||
- git clone --branch v1.4.2 --depth 1 https://github.com/jasongin/nvs.git %LOCALAPPDATA%\nvs
|
- git clone --branch v1.4.2 --depth 1 https://github.com/jasongin/nvs.git %LOCALAPPDATA%\nvs
|
||||||
|
|||||||
19
bin/uglifyjs
19
bin/uglifyjs
@@ -56,6 +56,11 @@ program.option("--wrap <name>", "Embed everything as a function with “exports
|
|||||||
program.arguments("[files...]").parseArgv(process.argv);
|
program.arguments("[files...]").parseArgv(process.argv);
|
||||||
if (program.configFile) {
|
if (program.configFile) {
|
||||||
options = JSON.parse(read_file(program.configFile));
|
options = JSON.parse(read_file(program.configFile));
|
||||||
|
if (options.mangle && options.mangle.properties && options.mangle.properties.regex) {
|
||||||
|
options.mangle.properties.regex = UglifyJS.parse(options.mangle.properties.regex, {
|
||||||
|
expression: true
|
||||||
|
}).getValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!program.output && program.sourceMap && program.sourceMap.url != "inline") {
|
if (!program.output && program.sourceMap && program.sourceMap.url != "inline") {
|
||||||
fatal("ERROR: cannot write source map to STDOUT");
|
fatal("ERROR: cannot write source map to STDOUT");
|
||||||
@@ -100,7 +105,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 = {};
|
||||||
@@ -337,17 +342,9 @@ function parse_js(flag) {
|
|||||||
return function(value, options) {
|
return function(value, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
try {
|
try {
|
||||||
UglifyJS.minify(value, {
|
UglifyJS.parse(value, {
|
||||||
parse: {
|
|
||||||
expression: true
|
expression: true
|
||||||
},
|
}).walk(new UglifyJS.TreeWalker(function(node) {
|
||||||
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;
|
||||||
|
|||||||
@@ -118,10 +118,8 @@ var AST_Node = DEFNODE("Node", "start end", {
|
|||||||
}
|
}
|
||||||
}, null);
|
}, null);
|
||||||
|
|
||||||
AST_Node.warn_function = null;
|
|
||||||
AST_Node.warn = function(txt, props) {
|
AST_Node.warn = function(txt, props) {
|
||||||
if (AST_Node.warn_function)
|
if (AST_Node.warn_function) AST_Node.warn_function(string_template(txt, props));
|
||||||
AST_Node.warn_function(string_template(txt, props));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* -----[ statements ]----- */
|
/* -----[ statements ]----- */
|
||||||
@@ -207,8 +205,7 @@ var AST_LabeledStatement = DEFNODE("LabeledStatement", "label", {
|
|||||||
var label = node.label;
|
var label = node.label;
|
||||||
var def = this.label;
|
var def = this.label;
|
||||||
node.walk(new TreeWalker(function(node) {
|
node.walk(new TreeWalker(function(node) {
|
||||||
if (node instanceof AST_LoopControl
|
if (node instanceof AST_LoopControl && node.label && node.label.thedef === def) {
|
||||||
&& node.label && node.label.thedef === def) {
|
|
||||||
node.label.thedef = label;
|
node.label.thedef = label;
|
||||||
label.references.push(node);
|
label.references.push(node);
|
||||||
}
|
}
|
||||||
@@ -776,7 +773,7 @@ var AST_Label = DEFNODE("Label", "references", {
|
|||||||
}
|
}
|
||||||
}, AST_Symbol);
|
}, AST_Symbol);
|
||||||
|
|
||||||
var AST_SymbolRef = DEFNODE("SymbolRef", null, {
|
var AST_SymbolRef = DEFNODE("SymbolRef", "fixed", {
|
||||||
$documentation: "Reference to some symbol (not definition/declaration)",
|
$documentation: "Reference to some symbol (not definition/declaration)",
|
||||||
}, AST_Symbol);
|
}, AST_Symbol);
|
||||||
|
|
||||||
|
|||||||
1172
lib/compress.js
1172
lib/compress.js
File diff suppressed because it is too large
Load Diff
119
lib/output.js
119
lib/output.js
@@ -123,7 +123,7 @@ function OutputStream(options) {
|
|||||||
});
|
});
|
||||||
} : function(str) {
|
} : function(str) {
|
||||||
var s = "";
|
var s = "";
|
||||||
for (var i = 0, len = str.length; i < len; i++) {
|
for (var i = 0; i < str.length; i++) {
|
||||||
if (is_surrogate_pair_head(str[i]) && !is_surrogate_pair_tail(str[i + 1])
|
if (is_surrogate_pair_head(str[i]) && !is_surrogate_pair_tail(str[i + 1])
|
||||||
|| is_surrogate_pair_tail(str[i]) && !is_surrogate_pair_head(str[i - 1])) {
|
|| is_surrogate_pair_tail(str[i]) && !is_surrogate_pair_head(str[i - 1])) {
|
||||||
s += "\\u" + str.charCodeAt(i).toString(16);
|
s += "\\u" + str.charCodeAt(i).toString(16);
|
||||||
@@ -198,16 +198,24 @@ function OutputStream(options) {
|
|||||||
/* -----[ beautification/minification ]----- */
|
/* -----[ beautification/minification ]----- */
|
||||||
|
|
||||||
var has_parens = false;
|
var has_parens = false;
|
||||||
|
var line_end = 0;
|
||||||
|
var line_fixed = true;
|
||||||
var might_need_space = false;
|
var might_need_space = false;
|
||||||
var might_need_semicolon = false;
|
var might_need_semicolon = false;
|
||||||
var might_add_newline = 0;
|
|
||||||
var need_newline_indented = false;
|
var need_newline_indented = false;
|
||||||
var need_space = false;
|
var need_space = false;
|
||||||
var newline_insert = -1;
|
var newline_insert = -1;
|
||||||
var last = "";
|
var last = "";
|
||||||
var mapping_token, mapping_name, mappings = options.source_map && [];
|
var mapping_token, mapping_name, mappings = options.source_map && [];
|
||||||
|
|
||||||
var do_add_mapping = mappings ? function() {
|
var adjust_mappings = mappings ? function(line, col) {
|
||||||
|
mappings.forEach(function(mapping) {
|
||||||
|
mapping.line += line;
|
||||||
|
mapping.col += col;
|
||||||
|
});
|
||||||
|
} : noop;
|
||||||
|
|
||||||
|
var flush_mappings = mappings ? function() {
|
||||||
mappings.forEach(function(mapping) {
|
mappings.forEach(function(mapping) {
|
||||||
try {
|
try {
|
||||||
options.source_map.add(
|
options.source_map.add(
|
||||||
@@ -230,31 +238,30 @@ function OutputStream(options) {
|
|||||||
mappings = [];
|
mappings = [];
|
||||||
} : noop;
|
} : noop;
|
||||||
|
|
||||||
var ensure_line_len = options.max_line_len ? function() {
|
function insert_newlines(count) {
|
||||||
if (current_col > options.max_line_len) {
|
var index = OUTPUT.lastIndexOf("\n");
|
||||||
if (might_add_newline) {
|
if (line_end < index) line_end = index;
|
||||||
var left = OUTPUT.slice(0, might_add_newline);
|
var left = OUTPUT.slice(0, line_end);
|
||||||
var right = OUTPUT.slice(might_add_newline);
|
var right = OUTPUT.slice(line_end);
|
||||||
if (mappings) {
|
adjust_mappings(count, right.length - current_col);
|
||||||
var delta = right.length - current_col;
|
current_line += count;
|
||||||
mappings.forEach(function(mapping) {
|
current_pos += count;
|
||||||
mapping.line++;
|
|
||||||
mapping.col += delta;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
OUTPUT = left + "\n" + right;
|
|
||||||
current_line++;
|
|
||||||
current_pos++;
|
|
||||||
current_col = right.length;
|
current_col = right.length;
|
||||||
|
OUTPUT = left;
|
||||||
|
while (count--) OUTPUT += "\n";
|
||||||
|
OUTPUT += right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var fix_line = options.max_line_len ? function() {
|
||||||
|
if (line_fixed) {
|
||||||
if (current_col > options.max_line_len) {
|
if (current_col > options.max_line_len) {
|
||||||
AST_Node.warn("Output exceeds {max_line_len} characters", options);
|
AST_Node.warn("Output exceeds {max_line_len} characters", options);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (might_add_newline) {
|
if (current_col > options.max_line_len) insert_newlines(1);
|
||||||
might_add_newline = 0;
|
line_fixed = true;
|
||||||
do_add_mapping();
|
flush_mappings();
|
||||||
}
|
|
||||||
} : noop;
|
} : noop;
|
||||||
|
|
||||||
var requireSemicolonChars = makePredicate("( [ + * / - , .");
|
var requireSemicolonChars = makePredicate("( [ + * / - , .");
|
||||||
@@ -286,7 +293,7 @@ function OutputStream(options) {
|
|||||||
current_col++;
|
current_col++;
|
||||||
current_pos++;
|
current_pos++;
|
||||||
} else {
|
} else {
|
||||||
ensure_line_len();
|
fix_line();
|
||||||
OUTPUT += "\n";
|
OUTPUT += "\n";
|
||||||
current_pos++;
|
current_pos++;
|
||||||
current_line++;
|
current_line++;
|
||||||
@@ -304,18 +311,6 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.beautify && options.preserve_line && stack[stack.length - 1]) {
|
|
||||||
var target_line = stack[stack.length - 1].start.line;
|
|
||||||
while (current_line < target_line) {
|
|
||||||
ensure_line_len();
|
|
||||||
OUTPUT += "\n";
|
|
||||||
current_pos++;
|
|
||||||
current_line++;
|
|
||||||
current_col = 0;
|
|
||||||
might_need_space = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (might_need_space) {
|
if (might_need_space) {
|
||||||
if ((is_identifier_char(prev)
|
if ((is_identifier_char(prev)
|
||||||
&& (is_identifier_char(ch) || ch == "\\"))
|
&& (is_identifier_char(ch) || ch == "\\"))
|
||||||
@@ -337,7 +332,7 @@ function OutputStream(options) {
|
|||||||
col: current_col
|
col: current_col
|
||||||
});
|
});
|
||||||
mapping_token = false;
|
mapping_token = false;
|
||||||
if (!might_add_newline) do_add_mapping();
|
if (line_fixed) flush_mappings();
|
||||||
}
|
}
|
||||||
|
|
||||||
OUTPUT += str;
|
OUTPUT += str;
|
||||||
@@ -347,7 +342,7 @@ function OutputStream(options) {
|
|||||||
current_line += n;
|
current_line += n;
|
||||||
current_col += a[0].length;
|
current_col += a[0].length;
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
ensure_line_len();
|
fix_line();
|
||||||
current_col = a[n].length;
|
current_col = a[n].length;
|
||||||
}
|
}
|
||||||
last = str;
|
last = str;
|
||||||
@@ -374,9 +369,10 @@ function OutputStream(options) {
|
|||||||
return ret;
|
return ret;
|
||||||
} : function(col, cont) { return cont() };
|
} : function(col, cont) { return cont() };
|
||||||
|
|
||||||
var may_add_newline = options.max_line_len ? function() {
|
var may_add_newline = options.max_line_len || options.preserve_line ? function() {
|
||||||
ensure_line_len();
|
fix_line();
|
||||||
might_add_newline = OUTPUT.length;
|
line_end = OUTPUT.length;
|
||||||
|
line_fixed = false;
|
||||||
} : noop;
|
} : noop;
|
||||||
|
|
||||||
var newline = options.beautify ? function() {
|
var newline = options.beautify ? function() {
|
||||||
@@ -455,9 +451,7 @@ function OutputStream(options) {
|
|||||||
} : noop;
|
} : noop;
|
||||||
|
|
||||||
function get() {
|
function get() {
|
||||||
if (might_add_newline) {
|
if (!line_fixed) fix_line();
|
||||||
ensure_line_len();
|
|
||||||
}
|
|
||||||
return OUTPUT;
|
return OUTPUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -622,7 +616,14 @@ function OutputStream(options) {
|
|||||||
col : function() { return current_col },
|
col : function() { return current_col },
|
||||||
pos : function() { return current_pos },
|
pos : function() { return current_pos },
|
||||||
push_node : function(node) { stack.push(node) },
|
push_node : function(node) { stack.push(node) },
|
||||||
pop_node : function() { return stack.pop() },
|
pop_node : options.preserve_line ? function() {
|
||||||
|
var node = stack.pop();
|
||||||
|
if (node.start && node.start.line > current_line) {
|
||||||
|
insert_newlines(node.start.line - current_line);
|
||||||
|
}
|
||||||
|
} : function() {
|
||||||
|
stack.pop();
|
||||||
|
},
|
||||||
parent : function(n) {
|
parent : function(n) {
|
||||||
return stack[stack.length - 2 - (n || 0)];
|
return stack[stack.length - 2 - (n || 0)];
|
||||||
}
|
}
|
||||||
@@ -693,23 +694,15 @@ function OutputStream(options) {
|
|||||||
// a function expression needs parens around it when it's provably
|
// a function expression needs parens around it when it's provably
|
||||||
// the first token to appear in a statement.
|
// the first token to appear in a statement.
|
||||||
PARENS(AST_Function, function(output) {
|
PARENS(AST_Function, function(output) {
|
||||||
if (!output.has_parens() && first_in_statement(output)) {
|
if (!output.has_parens() && first_in_statement(output)) return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (output.option('webkit')) {
|
if (output.option('webkit')) {
|
||||||
var p = output.parent();
|
var p = output.parent();
|
||||||
if (p instanceof AST_PropAccess && p.expression === this) {
|
if (p instanceof AST_PropAccess && p.expression === this) return true;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (output.option('wrap_iife')) {
|
if (output.option('wrap_iife')) {
|
||||||
var p = output.parent();
|
var p = output.parent();
|
||||||
return p instanceof AST_Call && p.expression === this;
|
if (p instanceof AST_Call && p.expression === this) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// same goes for an object literal, because otherwise it would be
|
// same goes for an object literal, because otherwise it would be
|
||||||
@@ -783,17 +776,17 @@ function OutputStream(options) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
PARENS(AST_Call, function(output) {
|
PARENS(AST_Call, function(output) {
|
||||||
var p = output.parent(), p1;
|
var p = output.parent();
|
||||||
if (p instanceof AST_New && p.expression === this)
|
if (p instanceof AST_New && p.expression === this) return true;
|
||||||
return true;
|
|
||||||
|
|
||||||
// workaround for Safari bug.
|
|
||||||
// https://bugs.webkit.org/show_bug.cgi?id=123506
|
// https://bugs.webkit.org/show_bug.cgi?id=123506
|
||||||
|
if (output.option('webkit')) {
|
||||||
|
var g = output.parent(1);
|
||||||
return this.expression instanceof AST_Function
|
return this.expression instanceof AST_Function
|
||||||
&& p instanceof AST_PropAccess
|
&& p instanceof AST_PropAccess
|
||||||
&& p.expression === this
|
&& p.expression === this
|
||||||
&& (p1 = output.parent(1)) instanceof AST_Assign
|
&& g instanceof AST_Assign
|
||||||
&& p1.left === p;
|
&& g.left === p;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
PARENS(AST_New, function(output) {
|
PARENS(AST_New, function(output) {
|
||||||
@@ -1160,7 +1153,7 @@ function OutputStream(options) {
|
|||||||
def.print(output);
|
def.print(output);
|
||||||
});
|
});
|
||||||
var p = output.parent();
|
var p = output.parent();
|
||||||
if (p.init !== self || !(p instanceof AST_For || p instanceof AST_ForIn)) output.semicolon();
|
if (p && p.init !== self || !(p instanceof AST_For || p instanceof AST_ForIn)) output.semicolon();
|
||||||
});
|
});
|
||||||
|
|
||||||
function parenthesize_for_noin(node, output, noin) {
|
function parenthesize_for_noin(node, output, noin) {
|
||||||
|
|||||||
39
lib/parse.js
39
lib/parse.js
@@ -164,10 +164,6 @@ function is_unicode_connector_punctuation(ch) {
|
|||||||
return UNICODE.connector_punctuation.test(ch);
|
return UNICODE.connector_punctuation.test(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_identifier(name) {
|
|
||||||
return !RESERVED_WORDS[name] && /^[a-z_$][a-z0-9_$]*$/i.test(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
function is_identifier_start(code) {
|
function is_identifier_start(code) {
|
||||||
return code == 36 || code == 95 || is_letter(code);
|
return code == 36 || code == 95 || is_letter(code);
|
||||||
}
|
}
|
||||||
@@ -272,10 +268,8 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
|
|
||||||
function find_eol() {
|
function find_eol() {
|
||||||
var text = S.text;
|
var text = S.text;
|
||||||
for (var i = S.pos, n = S.text.length; i < n; ++i) {
|
for (var i = S.pos; i < S.text.length; ++i) {
|
||||||
var ch = text[i];
|
if (NEWLINE_CHARS[text[i]]) return i;
|
||||||
if (NEWLINE_CHARS[ch])
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -758,17 +752,21 @@ function parse($TEXT, options) {
|
|||||||
croak(msg, token.line, token.col);
|
croak(msg, token.line, token.col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function token_to_string(type, value) {
|
||||||
|
return type + (value === undefined ? "" : " «" + value + "»");
|
||||||
|
}
|
||||||
|
|
||||||
function unexpected(token) {
|
function unexpected(token) {
|
||||||
if (token == null)
|
if (token == null)
|
||||||
token = S.token;
|
token = S.token;
|
||||||
token_error(token, "Unexpected token: " + token.type + " (" + token.value + ")");
|
token_error(token, "Unexpected token: " + token_to_string(token.type, token.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
function expect_token(type, val) {
|
function expect_token(type, val) {
|
||||||
if (is(type, val)) {
|
if (is(type, val)) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
token_error(S.token, "Unexpected token " + S.token.type + " «" + S.token.value + "»" + ", expected " + type + " «" + val + "»");
|
token_error(S.token, "Unexpected token: " + token_to_string(S.token.type, S.token.value) + ", expected: " + token_to_string(type, val));
|
||||||
}
|
}
|
||||||
|
|
||||||
function expect(punc) {
|
function expect(punc) {
|
||||||
@@ -788,7 +786,7 @@ function parse($TEXT, options) {
|
|||||||
|
|
||||||
function semicolon(optional) {
|
function semicolon(optional) {
|
||||||
if (is("punc", ";")) next();
|
if (is("punc", ";")) next();
|
||||||
else if (!optional && !can_insert_semicolon()) unexpected();
|
else if (!optional && !can_insert_semicolon()) expect_token("punc", ";");
|
||||||
}
|
}
|
||||||
|
|
||||||
function parenthesised() {
|
function parenthesised() {
|
||||||
@@ -1069,7 +1067,7 @@ function parse($TEXT, options) {
|
|||||||
var in_statement = ctor === AST_Defun;
|
var in_statement = ctor === AST_Defun;
|
||||||
var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null;
|
var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null;
|
||||||
if (in_statement && !name)
|
if (in_statement && !name)
|
||||||
unexpected();
|
expect_token("name");
|
||||||
if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration))
|
if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration))
|
||||||
unexpected(prev());
|
unexpected(prev());
|
||||||
expect("(");
|
expect("(");
|
||||||
@@ -1119,7 +1117,7 @@ function parse($TEXT, options) {
|
|||||||
expect("{");
|
expect("{");
|
||||||
var a = [];
|
var a = [];
|
||||||
while (!is("punc", "}")) {
|
while (!is("punc", "}")) {
|
||||||
if (is("eof")) unexpected();
|
if (is("eof")) expect_token("punc", "}");
|
||||||
a.push(statement(strict_defun));
|
a.push(statement(strict_defun));
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
@@ -1130,7 +1128,7 @@ function parse($TEXT, options) {
|
|||||||
expect("{");
|
expect("{");
|
||||||
var a = [], cur = null, branch = null, tmp;
|
var a = [], cur = null, branch = null, tmp;
|
||||||
while (!is("punc", "}")) {
|
while (!is("punc", "}")) {
|
||||||
if (is("eof")) unexpected();
|
if (is("eof")) expect_token("punc", "}");
|
||||||
if (is("keyword", "case")) {
|
if (is("keyword", "case")) {
|
||||||
if (branch) branch.end = prev();
|
if (branch) branch.end = prev();
|
||||||
cur = [];
|
cur = [];
|
||||||
@@ -1141,8 +1139,7 @@ function parse($TEXT, options) {
|
|||||||
});
|
});
|
||||||
a.push(branch);
|
a.push(branch);
|
||||||
expect(":");
|
expect(":");
|
||||||
}
|
} else if (is("keyword", "default")) {
|
||||||
else if (is("keyword", "default")) {
|
|
||||||
if (branch) branch.end = prev();
|
if (branch) branch.end = prev();
|
||||||
cur = [];
|
cur = [];
|
||||||
branch = new AST_Default({
|
branch = new AST_Default({
|
||||||
@@ -1150,8 +1147,7 @@ function parse($TEXT, options) {
|
|||||||
body : cur
|
body : cur
|
||||||
});
|
});
|
||||||
a.push(branch);
|
a.push(branch);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (!cur) unexpected();
|
if (!cur) unexpected();
|
||||||
cur.push(statement());
|
cur.push(statement());
|
||||||
}
|
}
|
||||||
@@ -1420,10 +1416,10 @@ function parse($TEXT, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function as_name() {
|
function as_name() {
|
||||||
var tmp = S.token;
|
if (!is("name")) expect_token("name");
|
||||||
if (tmp.type != "name") unexpected();
|
var name = S.token.value;
|
||||||
next();
|
next();
|
||||||
return tmp.value;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _make_symbol(type) {
|
function _make_symbol(type) {
|
||||||
@@ -1625,6 +1621,7 @@ function parse($TEXT, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options.expression) {
|
if (options.expression) {
|
||||||
|
handle_regexp();
|
||||||
return expression(true);
|
return expression(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,25 +53,30 @@ function find_builtins(reserved) {
|
|||||||
"-Infinity",
|
"-Infinity",
|
||||||
"undefined",
|
"undefined",
|
||||||
].forEach(add);
|
].forEach(add);
|
||||||
[ Object, Array, Function, Number,
|
[
|
||||||
String, Boolean, Error, Math,
|
Array,
|
||||||
Date, RegExp
|
Boolean,
|
||||||
|
Date,
|
||||||
|
Error,
|
||||||
|
Function,
|
||||||
|
Math,
|
||||||
|
Number,
|
||||||
|
Object,
|
||||||
|
RegExp,
|
||||||
|
String,
|
||||||
].forEach(function(ctor) {
|
].forEach(function(ctor) {
|
||||||
Object.getOwnPropertyNames(ctor).map(add);
|
Object.getOwnPropertyNames(ctor).map(add);
|
||||||
if (ctor.prototype) {
|
if (ctor.prototype) {
|
||||||
Object.getOwnPropertyNames(ctor.prototype).map(add);
|
Object.getOwnPropertyNames(ctor.prototype).map(add);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function add(name) {
|
function add(name) {
|
||||||
push_uniq(reserved, name);
|
push_uniq(reserved, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function reserve_quoted_keys(ast, reserved) {
|
function reserve_quoted_keys(ast, reserved) {
|
||||||
function add(name) {
|
|
||||||
push_uniq(reserved, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
ast.walk(new TreeWalker(function(node) {
|
ast.walk(new TreeWalker(function(node) {
|
||||||
if (node instanceof AST_ObjectKeyVal && node.quote) {
|
if (node instanceof AST_ObjectKeyVal && node.quote) {
|
||||||
add(node.key);
|
add(node.key);
|
||||||
@@ -79,6 +84,10 @@ function reserve_quoted_keys(ast, reserved) {
|
|||||||
addStrings(node.property, add);
|
addStrings(node.property, add);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
function add(name) {
|
||||||
|
push_uniq(reserved, name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addStrings(node, add) {
|
function addStrings(node, add) {
|
||||||
@@ -127,10 +136,8 @@ function mangle_properties(ast, options) {
|
|||||||
// note debug may be enabled as an empty string, which is falsey. Also treat passing 'true'
|
// note debug may be enabled as an empty string, which is falsey. Also treat passing 'true'
|
||||||
// the same as passing an empty string.
|
// the same as passing an empty string.
|
||||||
var debug = options.debug !== false;
|
var debug = options.debug !== false;
|
||||||
var debug_name_suffix;
|
var debug_suffix;
|
||||||
if (debug) {
|
if (debug) debug_suffix = options.debug === true ? "" : options.debug;
|
||||||
debug_name_suffix = (options.debug === true ? "" : options.debug);
|
|
||||||
}
|
|
||||||
|
|
||||||
var names_to_mangle = [];
|
var names_to_mangle = [];
|
||||||
var unmangleable = [];
|
var unmangleable = [];
|
||||||
@@ -139,18 +146,14 @@ function mangle_properties(ast, options) {
|
|||||||
ast.walk(new TreeWalker(function(node) {
|
ast.walk(new TreeWalker(function(node) {
|
||||||
if (node instanceof AST_ObjectKeyVal) {
|
if (node instanceof AST_ObjectKeyVal) {
|
||||||
add(node.key);
|
add(node.key);
|
||||||
}
|
} else if (node instanceof AST_ObjectProperty) {
|
||||||
else if (node instanceof AST_ObjectProperty) {
|
|
||||||
// setter or getter, since KeyVal is handled above
|
// setter or getter, since KeyVal is handled above
|
||||||
add(node.key.name);
|
add(node.key.name);
|
||||||
}
|
} else if (node instanceof AST_Dot) {
|
||||||
else if (node instanceof AST_Dot) {
|
|
||||||
add(node.property);
|
add(node.property);
|
||||||
}
|
} else if (node instanceof AST_Sub) {
|
||||||
else if (node instanceof AST_Sub) {
|
|
||||||
addStrings(node.property, add);
|
addStrings(node.property, add);
|
||||||
}
|
} else if (node instanceof AST_Call
|
||||||
else if (node instanceof AST_Call
|
|
||||||
&& node.expression.print_to_string() == "Object.defineProperty") {
|
&& node.expression.print_to_string() == "Object.defineProperty") {
|
||||||
addStrings(node.args[1], add);
|
addStrings(node.args[1], add);
|
||||||
}
|
}
|
||||||
@@ -160,18 +163,14 @@ function mangle_properties(ast, options) {
|
|||||||
return ast.transform(new TreeTransformer(function(node) {
|
return ast.transform(new TreeTransformer(function(node) {
|
||||||
if (node instanceof AST_ObjectKeyVal) {
|
if (node instanceof AST_ObjectKeyVal) {
|
||||||
node.key = mangle(node.key);
|
node.key = mangle(node.key);
|
||||||
}
|
} else if (node instanceof AST_ObjectProperty) {
|
||||||
else if (node instanceof AST_ObjectProperty) {
|
|
||||||
// setter or getter
|
// setter or getter
|
||||||
node.key.name = mangle(node.key.name);
|
node.key.name = mangle(node.key.name);
|
||||||
}
|
} else if (node instanceof AST_Dot) {
|
||||||
else if (node instanceof AST_Dot) {
|
|
||||||
node.property = mangle(node.property);
|
node.property = mangle(node.property);
|
||||||
}
|
} else if (!options.keep_quoted && node instanceof AST_Sub) {
|
||||||
else if (!options.keep_quoted && node instanceof AST_Sub) {
|
|
||||||
node.property = mangleStrings(node.property);
|
node.property = mangleStrings(node.property);
|
||||||
}
|
} else if (node instanceof AST_Call
|
||||||
else if (node instanceof AST_Call
|
|
||||||
&& node.expression.print_to_string() == "Object.defineProperty") {
|
&& node.expression.print_to_string() == "Object.defineProperty") {
|
||||||
node.args[1] = mangleStrings(node.args[1]);
|
node.args[1] = mangleStrings(node.args[1]);
|
||||||
}
|
}
|
||||||
@@ -182,9 +181,7 @@ function mangle_properties(ast, options) {
|
|||||||
function can_mangle(name) {
|
function can_mangle(name) {
|
||||||
if (unmangleable.indexOf(name) >= 0) return false;
|
if (unmangleable.indexOf(name) >= 0) return false;
|
||||||
if (reserved.indexOf(name) >= 0) return false;
|
if (reserved.indexOf(name) >= 0) return false;
|
||||||
if (options.only_cache) {
|
if (options.only_cache) return cache.has(name);
|
||||||
return cache.has(name);
|
|
||||||
}
|
|
||||||
if (/^-?[0-9]+(\.[0-9]+)?(e[+-][0-9]+)?$/.test(name)) return false;
|
if (/^-?[0-9]+(\.[0-9]+)?(e[+-][0-9]+)?$/.test(name)) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -192,42 +189,29 @@ function mangle_properties(ast, options) {
|
|||||||
function should_mangle(name) {
|
function should_mangle(name) {
|
||||||
if (regex && !regex.test(name)) return false;
|
if (regex && !regex.test(name)) return false;
|
||||||
if (reserved.indexOf(name) >= 0) return false;
|
if (reserved.indexOf(name) >= 0) return false;
|
||||||
return cache.has(name)
|
return cache.has(name) || names_to_mangle.indexOf(name) >= 0;
|
||||||
|| names_to_mangle.indexOf(name) >= 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function add(name) {
|
function add(name) {
|
||||||
if (can_mangle(name))
|
if (can_mangle(name)) push_uniq(names_to_mangle, name);
|
||||||
push_uniq(names_to_mangle, name);
|
if (!should_mangle(name)) push_uniq(unmangleable, name);
|
||||||
|
|
||||||
if (!should_mangle(name)) {
|
|
||||||
push_uniq(unmangleable, name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function mangle(name) {
|
function mangle(name) {
|
||||||
if (!should_mangle(name)) {
|
if (!should_mangle(name)) {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
var mangled = cache.get(name);
|
var mangled = cache.get(name);
|
||||||
if (!mangled) {
|
if (!mangled) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
// debug mode: use a prefix and suffix to preserve readability, e.g. o.foo -> o._$foo$NNN_.
|
// debug mode: use a prefix and suffix to preserve readability, e.g. o.foo -> o._$foo$NNN_.
|
||||||
var debug_mangled = "_$" + name + "$" + debug_name_suffix + "_";
|
var debug_mangled = "_$" + name + "$" + debug_suffix + "_";
|
||||||
|
if (can_mangle(debug_mangled)) mangled = debug_mangled;
|
||||||
if (can_mangle(debug_mangled)) {
|
|
||||||
mangled = debug_mangled;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// either debug mode is off, or it is on and we could not use the mangled name
|
// either debug mode is off, or it is on and we could not use the mangled name
|
||||||
if (!mangled) {
|
if (!mangled) do {
|
||||||
do {
|
|
||||||
mangled = base54(++cname);
|
mangled = base54(++cname);
|
||||||
} while (!can_mangle(mangled));
|
} while (!can_mangle(mangled));
|
||||||
}
|
|
||||||
|
|
||||||
cache.set(name, mangled);
|
cache.set(name, mangled);
|
||||||
}
|
}
|
||||||
return mangled;
|
return mangled;
|
||||||
@@ -238,11 +222,9 @@ function mangle_properties(ast, options) {
|
|||||||
if (node instanceof AST_Sequence) {
|
if (node instanceof AST_Sequence) {
|
||||||
var last = node.expressions.length - 1;
|
var last = node.expressions.length - 1;
|
||||||
node.expressions[last] = mangleStrings(node.expressions[last]);
|
node.expressions[last] = mangleStrings(node.expressions[last]);
|
||||||
}
|
} else if (node instanceof AST_String) {
|
||||||
else if (node instanceof AST_String) {
|
|
||||||
node.value = mangle(node.value);
|
node.value = mangle(node.value);
|
||||||
}
|
} else if (node instanceof AST_Conditional) {
|
||||||
else if (node instanceof AST_Conditional) {
|
|
||||||
node.consequent = mangleStrings(node.consequent);
|
node.consequent = mangleStrings(node.consequent);
|
||||||
node.alternative = mangleStrings(node.alternative);
|
node.alternative = mangleStrings(node.alternative);
|
||||||
}
|
}
|
||||||
|
|||||||
110
lib/scope.js
110
lib/scope.js
@@ -61,8 +61,6 @@ SymbolDef.next_id = 1;
|
|||||||
|
|
||||||
SymbolDef.prototype = {
|
SymbolDef.prototype = {
|
||||||
unmangleable: function(options) {
|
unmangleable: function(options) {
|
||||||
if (!options) options = {};
|
|
||||||
|
|
||||||
return this.global && !options.toplevel
|
return this.global && !options.toplevel
|
||||||
|| this.undeclared
|
|| this.undeclared
|
||||||
|| !options.eval && this.scope.pinned()
|
|| !options.eval && this.scope.pinned()
|
||||||
@@ -118,11 +116,10 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|||||||
descend();
|
descend();
|
||||||
scope = save_scope;
|
scope = save_scope;
|
||||||
defun = save_defun;
|
defun = save_defun;
|
||||||
return true; // don't descend again in TreeWalker
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_With) {
|
if (node instanceof AST_With) {
|
||||||
for (var s = scope; s; s = s.parent_scope)
|
for (var s = scope; s; s = s.parent_scope) s.uses_with = true;
|
||||||
s.uses_with = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Symbol) {
|
if (node instanceof AST_Symbol) {
|
||||||
@@ -132,18 +129,14 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|||||||
node.thedef = node;
|
node.thedef = node;
|
||||||
node.references = [];
|
node.references = [];
|
||||||
}
|
}
|
||||||
if (node instanceof AST_SymbolDefun || options.ie8 && node instanceof AST_SymbolLambda) {
|
if (node instanceof AST_SymbolDefun) {
|
||||||
// Careful here, the scope where this should be defined is
|
// This should be defined in the parent scope, as we encounter the
|
||||||
// the parent scope. The reason is that we enter a new
|
// AST_Defun node before getting to its AST_Symbol.
|
||||||
// scope when we encounter the AST_Defun node (which is
|
(node.scope = defun.parent_scope.resolve()).def_function(node, defun);
|
||||||
// instanceof AST_Scope) but we get to the symbol a bit
|
} else if (node instanceof AST_SymbolLambda) {
|
||||||
// later.
|
var def = defun.def_function(node, node.name == "arguments" ? undefined : defun);
|
||||||
(node.scope = defun.parent_scope).def_function(node, defun);
|
if (options.ie8) def.defun = defun.parent_scope.resolve();
|
||||||
}
|
} else if (node instanceof AST_SymbolVar) {
|
||||||
else if (node instanceof AST_SymbolLambda) {
|
|
||||||
defun.def_function(node, node.name == "arguments" ? undefined : defun);
|
|
||||||
}
|
|
||||||
else if (node instanceof AST_SymbolVar) {
|
|
||||||
defun.def_variable(node, node.TYPE == "SymbolVar" ? null : undefined);
|
defun.def_variable(node, node.TYPE == "SymbolVar" ? null : undefined);
|
||||||
if (defun !== scope) {
|
if (defun !== scope) {
|
||||||
node.mark_enclosed(options);
|
node.mark_enclosed(options);
|
||||||
@@ -153,8 +146,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|||||||
}
|
}
|
||||||
node.reference(options);
|
node.reference(options);
|
||||||
}
|
}
|
||||||
}
|
} else if (node instanceof AST_SymbolCatch) {
|
||||||
else if (node instanceof AST_SymbolCatch) {
|
|
||||||
scope.def_variable(node).defun = defun;
|
scope.def_variable(node).defun = defun;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -162,9 +154,9 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|||||||
|
|
||||||
// pass 2: find back references and eval
|
// pass 2: find back references and eval
|
||||||
self.globals = new Dictionary();
|
self.globals = new Dictionary();
|
||||||
var tw = new TreeWalker(function(node, descend) {
|
var tw = new TreeWalker(function(node) {
|
||||||
if (node instanceof AST_LoopControl && node.label) {
|
if (node instanceof AST_LoopControl) {
|
||||||
node.label.thedef.references.push(node);
|
if (node.label) node.label.thedef.references.push(node);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_SymbolRef) {
|
if (node instanceof AST_SymbolRef) {
|
||||||
@@ -185,35 +177,39 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// ensure mangling works if catch reuses a scope variable
|
// ensure mangling works if catch reuses a scope variable
|
||||||
var def;
|
if (node instanceof AST_SymbolCatch) {
|
||||||
if (node instanceof AST_SymbolCatch && (def = node.definition().redefined())) {
|
var def = node.definition().redefined();
|
||||||
var s = node.scope;
|
if (def) for (var s = node.scope; s; s = s.parent_scope) {
|
||||||
while (s) {
|
|
||||||
push_uniq(s.enclosed, def);
|
push_uniq(s.enclosed, def);
|
||||||
if (s === def.scope) break;
|
if (s === def.scope) break;
|
||||||
s = s.parent_scope;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
self.walk(tw);
|
self.walk(tw);
|
||||||
|
|
||||||
// pass 3: fix up any scoping issue with IE8
|
// pass 3: fix up any scoping issue with IE8
|
||||||
if (options.ie8) {
|
if (options.ie8) self.walk(new TreeWalker(function(node) {
|
||||||
self.walk(new TreeWalker(function(node, descend) {
|
|
||||||
if (node instanceof AST_SymbolCatch) {
|
if (node instanceof AST_SymbolCatch) {
|
||||||
var name = node.name;
|
redefine(node, node.thedef.defun);
|
||||||
var refs = node.thedef.references;
|
return true;
|
||||||
var scope = node.thedef.defun;
|
}
|
||||||
var def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node);
|
if (node instanceof AST_SymbolLambda) {
|
||||||
refs.forEach(function(ref) {
|
var def = node.thedef;
|
||||||
ref.thedef = def;
|
redefine(node, node.scope.parent_scope);
|
||||||
ref.reference(options);
|
node.thedef.init = def.init;
|
||||||
});
|
|
||||||
node.thedef = def;
|
|
||||||
node.reference(options);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
function redefine(node, scope) {
|
||||||
|
var name = node.name;
|
||||||
|
var old_def = node.thedef;
|
||||||
|
var new_def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node);
|
||||||
|
old_def.orig.concat(old_def.references).forEach(function(node) {
|
||||||
|
node.thedef = new_def;
|
||||||
|
node.reference(options);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -252,8 +248,7 @@ AST_Lambda.DEFMETHOD("init_scope_vars", function() {
|
|||||||
|
|
||||||
AST_Symbol.DEFMETHOD("mark_enclosed", function(options) {
|
AST_Symbol.DEFMETHOD("mark_enclosed", function(options) {
|
||||||
var def = this.definition();
|
var def = this.definition();
|
||||||
var s = this.scope;
|
for (var s = this.scope; s; s = s.parent_scope) {
|
||||||
while (s) {
|
|
||||||
push_uniq(s.enclosed, def);
|
push_uniq(s.enclosed, def);
|
||||||
if (options.keep_fnames) {
|
if (options.keep_fnames) {
|
||||||
s.functions.each(function(d) {
|
s.functions.each(function(d) {
|
||||||
@@ -261,7 +256,6 @@ AST_Symbol.DEFMETHOD("mark_enclosed", function(options) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (s === def.scope) break;
|
if (s === def.scope) break;
|
||||||
s = s.parent_scope;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -298,13 +292,23 @@ AST_Scope.DEFMETHOD("def_variable", function(symbol, init) {
|
|||||||
return symbol.thedef = def;
|
return symbol.thedef = def;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
AST_Lambda.DEFMETHOD("resolve", return_this);
|
||||||
|
AST_Scope.DEFMETHOD("resolve", function() {
|
||||||
|
return this.parent_scope.resolve();
|
||||||
|
});
|
||||||
|
AST_Toplevel.DEFMETHOD("resolve", return_this);
|
||||||
|
|
||||||
function names_in_use(scope, options) {
|
function names_in_use(scope, options) {
|
||||||
var names = scope.names_in_use;
|
var names = scope.names_in_use;
|
||||||
if (!names) {
|
if (!names) {
|
||||||
scope.names_in_use = names = Object.create(scope.mangled_names || null);
|
scope.names_in_use = names = Object.create(scope.mangled_names || null);
|
||||||
scope.cname_holes = [];
|
scope.cname_holes = [];
|
||||||
|
var cache = options.cache && options.cache.props;
|
||||||
scope.enclosed.forEach(function(def) {
|
scope.enclosed.forEach(function(def) {
|
||||||
if (def.unmangleable(options)) names[def.name] = true;
|
if (def.unmangleable(options)) names[def.name] = true;
|
||||||
|
if (def.global && cache && cache.has(def.name)) {
|
||||||
|
names[cache.get(def.name)] = true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
@@ -314,14 +318,6 @@ function next_mangled_name(scope, options, def) {
|
|||||||
var in_use = names_in_use(scope, options);
|
var in_use = names_in_use(scope, options);
|
||||||
var holes = scope.cname_holes;
|
var holes = scope.cname_holes;
|
||||||
var names = Object.create(null);
|
var names = Object.create(null);
|
||||||
// #179, #326
|
|
||||||
// in Safari strict mode, something like (function x(x){...}) is a syntax error;
|
|
||||||
// a function expression's argument cannot shadow the function expression's name
|
|
||||||
if (scope instanceof AST_Function && scope.name && def.orig[0] instanceof AST_SymbolFunarg) {
|
|
||||||
var tricky_def = scope.name.definition();
|
|
||||||
// the function's mangled_name is null when keep_fnames is true
|
|
||||||
names[tricky_def.mangled_name || tricky_def.name] = true;
|
|
||||||
}
|
|
||||||
var scopes = [ scope ];
|
var scopes = [ scope ];
|
||||||
def.references.forEach(function(sym) {
|
def.references.forEach(function(sym) {
|
||||||
var scope = sym.scope;
|
var scope = sym.scope;
|
||||||
@@ -335,7 +331,7 @@ function next_mangled_name(scope, options, def) {
|
|||||||
} while (scope = scope.parent_scope);
|
} while (scope = scope.parent_scope);
|
||||||
});
|
});
|
||||||
var name;
|
var name;
|
||||||
for (var i = 0, len = holes.length; i < len; i++) {
|
for (var i = 0; i < holes.length; i++) {
|
||||||
name = base54(holes[i]);
|
name = base54(holes[i]);
|
||||||
if (names[name]) continue;
|
if (names[name]) continue;
|
||||||
holes.splice(i, 1);
|
holes.splice(i, 1);
|
||||||
@@ -344,7 +340,7 @@ function next_mangled_name(scope, options, def) {
|
|||||||
}
|
}
|
||||||
while (true) {
|
while (true) {
|
||||||
name = base54(++scope.cname);
|
name = base54(++scope.cname);
|
||||||
if (in_use[name] || !is_identifier(name) || options.reserved.has[name]) continue;
|
if (in_use[name] || RESERVED_WORDS[name] || options.reserved.has[name]) continue;
|
||||||
if (!names[name]) break;
|
if (!names[name]) break;
|
||||||
holes.push(scope.cname);
|
holes.push(scope.cname);
|
||||||
}
|
}
|
||||||
@@ -410,7 +406,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
|||||||
var save_nesting = lname;
|
var save_nesting = lname;
|
||||||
descend();
|
descend();
|
||||||
lname = save_nesting;
|
lname = save_nesting;
|
||||||
return true; // don't descend again in TreeWalker
|
return true;
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Scope) {
|
if (node instanceof AST_Scope) {
|
||||||
descend();
|
descend();
|
||||||
@@ -422,7 +418,9 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
|
|||||||
}
|
}
|
||||||
if (node instanceof AST_Label) {
|
if (node instanceof AST_Label) {
|
||||||
var name;
|
var name;
|
||||||
do name = base54(++lname); while (!is_identifier(name));
|
do {
|
||||||
|
name = base54(++lname);
|
||||||
|
} while (RESERVED_WORDS[name]);
|
||||||
node.mangled_name = name;
|
node.mangled_name = name;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -493,7 +491,7 @@ AST_Toplevel.DEFMETHOD("expand_names", function(options) {
|
|||||||
var name;
|
var name;
|
||||||
do {
|
do {
|
||||||
name = base54(cname++);
|
name = base54(cname++);
|
||||||
} while (avoid[name] || !is_identifier(name));
|
} while (avoid[name] || RESERVED_WORDS[name]);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -555,7 +553,7 @@ var base54 = (function() {
|
|||||||
var freq = Object.create(null);
|
var freq = Object.create(null);
|
||||||
function init(chars) {
|
function init(chars) {
|
||||||
var array = [];
|
var array = [];
|
||||||
for (var i = 0, len = chars.length; i < len; i++) {
|
for (var i = 0; i < chars.length; i++) {
|
||||||
var ch = chars[i];
|
var ch = chars[i];
|
||||||
array.push(ch);
|
array.push(ch);
|
||||||
freq[ch] = -1e-2 * i;
|
freq[ch] = -1e-2 * i;
|
||||||
|
|||||||
@@ -162,8 +162,7 @@ var MAP = (function() {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
function push_uniq(array, el) {
|
function push_uniq(array, el) {
|
||||||
if (array.indexOf(el) < 0)
|
if (array.indexOf(el) < 0) return array.push(el);
|
||||||
array.push(el);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function string_template(text, props) {
|
function string_template(text, props) {
|
||||||
@@ -173,9 +172,8 @@ function string_template(text, props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function remove(array, el) {
|
function remove(array, el) {
|
||||||
for (var i = array.length; --i >= 0;) {
|
var index = array.indexOf(el);
|
||||||
if (array[i] === el) array.splice(i, 1);
|
if (index >= 0) array.splice(index, 1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function makePredicate(words) {
|
function makePredicate(words) {
|
||||||
|
|||||||
@@ -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.4.4",
|
"version": "3.5.9",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
@@ -23,12 +23,12 @@
|
|||||||
"LICENSE"
|
"LICENSE"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"commander": "~2.16.0",
|
"commander": "~2.20.0",
|
||||||
"source-map": "~0.6.1"
|
"source-map": "~0.6.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"acorn": "~5.7.1",
|
"acorn": "~6.1.1",
|
||||||
"semver": "~5.5.0"
|
"semver": "~6.0.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node test/run-tests.js"
|
"test": "node test/run-tests.js"
|
||||||
|
|||||||
@@ -237,3 +237,342 @@ duplicate_argname: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "bar 42 foo 42 bar"
|
expect_stdout: "bar 42 foo 42 bar"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3273: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
console.log(a, a);
|
||||||
|
a++;
|
||||||
|
console.log(a, a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0 0",
|
||||||
|
"1 1",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3273_reduce_vars: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
console.log(a, a);
|
||||||
|
a++;
|
||||||
|
console.log(a, a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0 0",
|
||||||
|
"1 1",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3273_local_strict: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
"use strict";
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
"use strict";
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0 0",
|
||||||
|
"1 0",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3273_local_strict_reduce_vars: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
"use strict";
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
"use strict";
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0 0",
|
||||||
|
"1 0",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3273_global_strict: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
function f(a) {
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
function f(a) {
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0 0",
|
||||||
|
"1 0",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3273_global_strict_reduce_vars: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
function f(a) {
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
function f(a) {
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
arguments[0]++;
|
||||||
|
console.log(arguments[0], a);
|
||||||
|
}
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0 0",
|
||||||
|
"1 0",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3282_1: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
keep_fargs: false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(t) {
|
||||||
|
return function() {
|
||||||
|
t();
|
||||||
|
};
|
||||||
|
})(function() {
|
||||||
|
'use strict';
|
||||||
|
function e() {
|
||||||
|
return arguments[0];
|
||||||
|
}
|
||||||
|
e();
|
||||||
|
e();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
return function() {
|
||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
function e() {
|
||||||
|
return arguments[0];
|
||||||
|
}
|
||||||
|
e();
|
||||||
|
e();
|
||||||
|
})();
|
||||||
|
};
|
||||||
|
})()();
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3282_1_passes: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
keep_fargs: false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(t) {
|
||||||
|
return function() {
|
||||||
|
t();
|
||||||
|
};
|
||||||
|
})(function() {
|
||||||
|
'use strict';
|
||||||
|
function e() {
|
||||||
|
return arguments[0];
|
||||||
|
}
|
||||||
|
e();
|
||||||
|
e();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
return function() {
|
||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
function e(argument_0) {
|
||||||
|
return argument_0;
|
||||||
|
}
|
||||||
|
e();
|
||||||
|
e();
|
||||||
|
})();
|
||||||
|
};
|
||||||
|
})()();
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3282_2: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
keep_fargs: false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(f) {
|
||||||
|
f();
|
||||||
|
})(function() {
|
||||||
|
return (function(t) {
|
||||||
|
return function() {
|
||||||
|
t();
|
||||||
|
};
|
||||||
|
})(function() {
|
||||||
|
'use strict';
|
||||||
|
function e() {
|
||||||
|
return arguments[0];
|
||||||
|
}
|
||||||
|
e();
|
||||||
|
e();
|
||||||
|
})();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
(function() {
|
||||||
|
return function(t) {
|
||||||
|
return function() {
|
||||||
|
t();
|
||||||
|
};
|
||||||
|
}(function() {
|
||||||
|
"use strict";
|
||||||
|
function e() {
|
||||||
|
return arguments[0];
|
||||||
|
}
|
||||||
|
e();
|
||||||
|
e();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3282_2_passes: {
|
||||||
|
options = {
|
||||||
|
arguments: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
keep_fargs: false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(f) {
|
||||||
|
f();
|
||||||
|
})(function() {
|
||||||
|
return (function(t) {
|
||||||
|
return function() {
|
||||||
|
t();
|
||||||
|
};
|
||||||
|
})(function() {
|
||||||
|
'use strict';
|
||||||
|
function e() {
|
||||||
|
return arguments[0];
|
||||||
|
}
|
||||||
|
e();
|
||||||
|
e();
|
||||||
|
})();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
(function() {
|
||||||
|
return function(t) {
|
||||||
|
return function() {
|
||||||
|
t();
|
||||||
|
};
|
||||||
|
}(function() {
|
||||||
|
"use strict";
|
||||||
|
function e(argument_0) {
|
||||||
|
return argument_0;
|
||||||
|
}
|
||||||
|
e();
|
||||||
|
e();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|||||||
@@ -239,3 +239,113 @@ index_length: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "1 2"
|
expect_stdout: "1 2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor_bad: {
|
||||||
|
options = {
|
||||||
|
unsafe: true
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
try {
|
||||||
|
Array(NaN);
|
||||||
|
console.log("FAIL1");
|
||||||
|
} catch (ex) {
|
||||||
|
try {
|
||||||
|
new Array(NaN);
|
||||||
|
console.log("FAIL2");
|
||||||
|
} catch (ex) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Array(3.14);
|
||||||
|
console.log("FAIL1");
|
||||||
|
} catch (ex) {
|
||||||
|
try {
|
||||||
|
new Array(3.14);
|
||||||
|
console.log("FAIL2");
|
||||||
|
} catch (ex) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
try {
|
||||||
|
Array(NaN);
|
||||||
|
console.log("FAIL1");
|
||||||
|
} catch (ex) {
|
||||||
|
try {
|
||||||
|
Array(NaN);
|
||||||
|
console.log("FAIL2");
|
||||||
|
} catch (ex) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Array(3.14);
|
||||||
|
console.log("FAIL1");
|
||||||
|
} catch (ex) {
|
||||||
|
try {
|
||||||
|
Array(3.14);
|
||||||
|
console.log("FAIL2");
|
||||||
|
} catch (ex) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
|
expect_warnings: [
|
||||||
|
"WARN: Invalid array length: 3.14 [test/compress/arrays.js:13,12]",
|
||||||
|
"WARN: Invalid array length: 3.14 [test/compress/arrays.js:17,16]",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor_good: {
|
||||||
|
options = {
|
||||||
|
unsafe: true
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(Array());
|
||||||
|
console.log(Array(0));
|
||||||
|
console.log(Array(1));
|
||||||
|
console.log(Array(6));
|
||||||
|
console.log(Array(7));
|
||||||
|
console.log(Array(1, 2));
|
||||||
|
console.log(Array(false));
|
||||||
|
console.log(Array("foo"));
|
||||||
|
console.log(Array(Array));
|
||||||
|
console.log(new Array());
|
||||||
|
console.log(new Array(0));
|
||||||
|
console.log(new Array(1));
|
||||||
|
console.log(new Array(6));
|
||||||
|
console.log(new Array(7));
|
||||||
|
console.log(new Array(1, 2));
|
||||||
|
console.log(new Array(false));
|
||||||
|
console.log(new Array("foo"));
|
||||||
|
console.log(new Array(Array));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log([]);
|
||||||
|
console.log([]);
|
||||||
|
console.log([,]);
|
||||||
|
console.log([,,,,,,]);
|
||||||
|
console.log(Array(7));
|
||||||
|
console.log([ 1, 2 ]);
|
||||||
|
console.log([ false ]);
|
||||||
|
console.log([ "foo" ]);
|
||||||
|
console.log(Array(Array));
|
||||||
|
console.log([]);
|
||||||
|
console.log([]);
|
||||||
|
console.log([,]);
|
||||||
|
console.log([,,,,,,]);
|
||||||
|
console.log(Array(7));
|
||||||
|
console.log([ 1, 2 ]);
|
||||||
|
console.log([ false ]);
|
||||||
|
console.log([ "foo" ]);
|
||||||
|
console.log(Array(Array));
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
expect_warnings: []
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
asm_mixed: {
|
asm_mixed: {
|
||||||
options = {
|
options = {
|
||||||
|
assignments: true,
|
||||||
booleans: true,
|
booleans: true,
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
op_equals_left_local_var: {
|
op_equals_left_local_var: {
|
||||||
options = {
|
options = {
|
||||||
|
assignments: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -60,6 +61,7 @@ op_equals_left_local_var: {
|
|||||||
|
|
||||||
op_equals_right_local_var: {
|
op_equals_right_local_var: {
|
||||||
options = {
|
options = {
|
||||||
|
assignments: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -123,6 +125,7 @@ op_equals_right_local_var: {
|
|||||||
}
|
}
|
||||||
op_equals_left_global_var: {
|
op_equals_left_global_var: {
|
||||||
options = {
|
options = {
|
||||||
|
assignments: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -179,6 +182,7 @@ op_equals_left_global_var: {
|
|||||||
|
|
||||||
op_equals_right_global_var: {
|
op_equals_right_global_var: {
|
||||||
options = {
|
options = {
|
||||||
|
assignments: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
@@ -236,3 +240,74 @@ op_equals_right_global_var: {
|
|||||||
x = g() & x;
|
x = g() & x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
increment_decrement_1: {
|
||||||
|
options = {
|
||||||
|
assignments: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a) {
|
||||||
|
a += 1;
|
||||||
|
a -= 1;
|
||||||
|
return a;
|
||||||
|
}(42));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a){
|
||||||
|
++a;
|
||||||
|
--a;
|
||||||
|
return a;
|
||||||
|
}(42));
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
}
|
||||||
|
|
||||||
|
increment_decrement_2: {
|
||||||
|
options = {
|
||||||
|
assignments: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a) {
|
||||||
|
a = a + 1;
|
||||||
|
a = a - 1;
|
||||||
|
a += 1;
|
||||||
|
a -= 1;
|
||||||
|
return a;
|
||||||
|
}(42));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a){
|
||||||
|
++a;
|
||||||
|
--a;
|
||||||
|
++a;
|
||||||
|
--a;
|
||||||
|
return a;
|
||||||
|
}(42));
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3375: {
|
||||||
|
options = {
|
||||||
|
assignments: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(typeof function(b) {
|
||||||
|
var a = b += 1;
|
||||||
|
--b;
|
||||||
|
return a;
|
||||||
|
}("object"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(typeof function(b) {
|
||||||
|
var a = b += 1;
|
||||||
|
--b;
|
||||||
|
return a;
|
||||||
|
}("object"));
|
||||||
|
}
|
||||||
|
expect_stdout: "string"
|
||||||
|
}
|
||||||
|
|||||||
@@ -944,10 +944,10 @@ collapse_vars_misc1: {
|
|||||||
function f5(x) { var z = foo(); return (5 - window.x) / z }
|
function f5(x) { var z = foo(); return (5 - window.x) / z }
|
||||||
function f6() { return window.a * window.z && zap() }
|
function f6() { return window.a * window.z && zap() }
|
||||||
function f7() { var b = window.a * window.z; return b + b }
|
function f7() { var b = window.a * window.z; return b + b }
|
||||||
function f8() { var b = window.a * window.z; return b + (b + 5) }
|
function f8() { var b = window.a * window.z; return b + (5 + b) }
|
||||||
function f9() { var b = window.a * window.z; return bar() || b }
|
function f9() { var b = window.a * window.z; return bar() || b }
|
||||||
function f10(x) { var a = 5; return a += 3; }
|
function f10(x) { var a = 5; return a += 3; }
|
||||||
function f11(x) { var a = 5, b = 3; return a += --b; }
|
function f11(x) { var a = 5; return a += 2; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3895,11 +3895,11 @@ issue_2436_10: {
|
|||||||
o = { b: 3 };
|
o = { b: 3 };
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
console.log((c = o, [
|
console.log([
|
||||||
c.a,
|
(c = o).a,
|
||||||
f(c.b),
|
f(c.b),
|
||||||
c.b,
|
c.b,
|
||||||
]).join(" "));
|
].join(" "));
|
||||||
var c;
|
var c;
|
||||||
}
|
}
|
||||||
expect_stdout: "1 2 2"
|
expect_stdout: "1 2 2"
|
||||||
@@ -5730,3 +5730,451 @@ issue_3096: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "ab"
|
expect_stdout: "ab"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3215_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
evaluate: true,
|
||||||
|
ie8: false,
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function a() {
|
||||||
|
var a = 42;
|
||||||
|
return typeof a;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("number");
|
||||||
|
}
|
||||||
|
expect_stdout: "number"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3215_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
evaluate: true,
|
||||||
|
ie8: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function a() {
|
||||||
|
var a = 42;
|
||||||
|
return typeof a;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function a() {
|
||||||
|
var a = 42;
|
||||||
|
return typeof a;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "number"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3215_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
evaluate: true,
|
||||||
|
ie8: false,
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
var a = 42;
|
||||||
|
(function a() {});
|
||||||
|
return typeof a;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("number");
|
||||||
|
}
|
||||||
|
expect_stdout: "number"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3215_4: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
evaluate: true,
|
||||||
|
ie8: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
var a = 42;
|
||||||
|
(function a() {});
|
||||||
|
return typeof a;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
var a = 42;
|
||||||
|
(function a() {});
|
||||||
|
return typeof a;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "number"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3238_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
var b, c;
|
||||||
|
if (a) {
|
||||||
|
b = Object.create(null);
|
||||||
|
c = Object.create(null);
|
||||||
|
}
|
||||||
|
return b === c;
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
var b, c;
|
||||||
|
if (a) {
|
||||||
|
b = Object.create(null);
|
||||||
|
c = Object.create(null);
|
||||||
|
}
|
||||||
|
return b === c;
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1));
|
||||||
|
}
|
||||||
|
expect_stdout: "true false"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3238_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
var b, c;
|
||||||
|
if (a) {
|
||||||
|
b = Error();
|
||||||
|
c = Error();
|
||||||
|
}
|
||||||
|
return b === c;
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
var b, c;
|
||||||
|
if (a) {
|
||||||
|
b = Error();
|
||||||
|
c = Error();
|
||||||
|
}
|
||||||
|
return b === c;
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1));
|
||||||
|
}
|
||||||
|
expect_stdout: "true false"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3238_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
var b, c;
|
||||||
|
if (a) {
|
||||||
|
b = new Date();
|
||||||
|
c = new Date();
|
||||||
|
}
|
||||||
|
return b === c;
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
var b, c;
|
||||||
|
if (a) {
|
||||||
|
b = new Date();
|
||||||
|
c = new Date();
|
||||||
|
}
|
||||||
|
return b === c;
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1));
|
||||||
|
}
|
||||||
|
expect_stdout: "true false"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3238_4: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
var b, c;
|
||||||
|
if (a) {
|
||||||
|
b = a && {};
|
||||||
|
c = a && {};
|
||||||
|
}
|
||||||
|
return b === c;
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
var b, c;
|
||||||
|
if (a) {
|
||||||
|
b = a && {};
|
||||||
|
c = a && {};
|
||||||
|
}
|
||||||
|
return b === c;
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1));
|
||||||
|
}
|
||||||
|
expect_stdout: "true false"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3238_5: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
var b, c;
|
||||||
|
if (a) {
|
||||||
|
b = a ? [] : 42;
|
||||||
|
c = a ? [] : 42;
|
||||||
|
}
|
||||||
|
return b === c;
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
var b, c;
|
||||||
|
if (a) {
|
||||||
|
b = a ? [] : 42;
|
||||||
|
c = a ? [] : 42;
|
||||||
|
}
|
||||||
|
return b === c;
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1));
|
||||||
|
}
|
||||||
|
expect_stdout: "true false"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3238_6: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
var b, c;
|
||||||
|
if (a) {
|
||||||
|
b = a && 0 || [];
|
||||||
|
c = a && 0 || [];
|
||||||
|
}
|
||||||
|
return b === c;
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
var b, c;
|
||||||
|
if (a) {
|
||||||
|
b = a && 0 || [];
|
||||||
|
c = a && 0 || [];
|
||||||
|
}
|
||||||
|
return b === c;
|
||||||
|
}
|
||||||
|
console.log(f(0), f(1));
|
||||||
|
}
|
||||||
|
expect_stdout: "true false"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3247: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(o) {
|
||||||
|
console.log(o.p);
|
||||||
|
}
|
||||||
|
var a;
|
||||||
|
a = Object({ p: "PASS" });
|
||||||
|
a.q = true;
|
||||||
|
f(a, true);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(o) {
|
||||||
|
console.log(o.p);
|
||||||
|
}
|
||||||
|
var a;
|
||||||
|
(a = Object({ p: "PASS" })).q = true;
|
||||||
|
f(a, true);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3305: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
conditionals: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function calc(a) {
|
||||||
|
var x, w;
|
||||||
|
if (a) {
|
||||||
|
x = a;
|
||||||
|
w = 1;
|
||||||
|
} else {
|
||||||
|
x = 1;
|
||||||
|
w = 0;
|
||||||
|
}
|
||||||
|
return add(x, w);
|
||||||
|
}
|
||||||
|
function add(x, w) {
|
||||||
|
return x + w;
|
||||||
|
}
|
||||||
|
console.log(calc(41));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function calc(a) {
|
||||||
|
var x, w;
|
||||||
|
return w = a ? (x = a, 1) : (x = 1, 0), add(x, w);
|
||||||
|
}
|
||||||
|
function add(x, w) {
|
||||||
|
return x + w;
|
||||||
|
}
|
||||||
|
console.log(calc(41));
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3314: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function test(a, b) {
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
var a = "FAIL", b;
|
||||||
|
b = a = "PASS";
|
||||||
|
test(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function test(a, b) {
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
var a = "FAIL", b;
|
||||||
|
b = a = "PASS";
|
||||||
|
test(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3327: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
conditionals: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a, b, l = ["PASS", 42];
|
||||||
|
if (l.length === 1) {
|
||||||
|
a = l[0].a;
|
||||||
|
b = l[0].b;
|
||||||
|
} else {
|
||||||
|
a = l[0];
|
||||||
|
b = l[1];
|
||||||
|
}
|
||||||
|
function echo(a, b) {
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
echo(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a, b, l = ["PASS", 42];
|
||||||
|
function echo(a, b) {
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
b = 1 === l.length ? (a = l[0].a, l[0].b) : (a = l[0], l[1]),
|
||||||
|
echo(a,b);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS 42"
|
||||||
|
}
|
||||||
|
|
||||||
|
assign_left: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a, b) {
|
||||||
|
(b = a, b.p).q = "PASS";
|
||||||
|
return a.p.q;
|
||||||
|
}({p: {}}));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a, b) {
|
||||||
|
(b = a).p.q = "PASS";
|
||||||
|
return a.p.q;
|
||||||
|
}({p: {}}));
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
sub_property: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a, b) {
|
||||||
|
return a[(b = a, b.length - 1)];
|
||||||
|
}([ "FAIL", "PASS" ]));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a, b) {
|
||||||
|
return a[(b = a).length - 1];
|
||||||
|
}([ "FAIL", "PASS" ]));
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
assign_undeclared: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var A = (console.log(42), function() {});
|
||||||
|
B = new A();
|
||||||
|
console.log(typeof B);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
B = new (console.log(42), function() {})();
|
||||||
|
console.log(typeof B);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"42",
|
||||||
|
"object",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
@@ -323,3 +323,60 @@ is_number_unsafe: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "true"
|
expect_stdout: "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_boolean_var: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a, b) {
|
||||||
|
for (var i = 0, c = !b; i < a.length; i++)
|
||||||
|
if (!a[i] === c)
|
||||||
|
return i;
|
||||||
|
}([ false, true ], 42));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a, b) {
|
||||||
|
for (var i = 0, c = !b; i < a.length; i++)
|
||||||
|
if (!a[i] == c)
|
||||||
|
return i;
|
||||||
|
}([ false, true ], 42));
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
is_defined: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function a() {
|
||||||
|
return void 0 === a;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function a() {
|
||||||
|
return a, false;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "false"
|
||||||
|
expect_warnings: [
|
||||||
|
"WARN: Expression always defined [test/compress/comparisons.js:2,19]",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_indexOf: {
|
||||||
|
options = {
|
||||||
|
booleans: true,
|
||||||
|
comparisons: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
if (Object.keys({ foo: 42 }).indexOf("foo") >= 0) console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
if (~Object.keys({ foo: 42 }).indexOf("foo")) console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
@@ -1292,3 +1292,182 @@ to_and_or: {
|
|||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cond_seq_assign_1: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
var t;
|
||||||
|
if (a) {
|
||||||
|
t = "foo";
|
||||||
|
t = "bar";
|
||||||
|
} else {
|
||||||
|
console.log(t);
|
||||||
|
t = 42;
|
||||||
|
}
|
||||||
|
console.log(t);
|
||||||
|
}
|
||||||
|
f(f);
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
var t;
|
||||||
|
t = a ? (t = "foo", "bar") : (console.log(t), 42),
|
||||||
|
console.log(t);
|
||||||
|
}
|
||||||
|
f(f),
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"bar",
|
||||||
|
"undefined",
|
||||||
|
"42",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
cond_seq_assign_2: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
var t;
|
||||||
|
if (a) {
|
||||||
|
t = "foo";
|
||||||
|
a = "bar";
|
||||||
|
} else {
|
||||||
|
console.log(t);
|
||||||
|
t = 42;
|
||||||
|
}
|
||||||
|
console.log(t);
|
||||||
|
}
|
||||||
|
f(f);
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
var t;
|
||||||
|
a ? (t = "foo", a = "bar") : (console.log(t), t = 42),
|
||||||
|
console.log(t);
|
||||||
|
}
|
||||||
|
f(f),
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"foo",
|
||||||
|
"undefined",
|
||||||
|
"42",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
cond_seq_assign_3: {
|
||||||
|
options = {
|
||||||
|
assignments: true,
|
||||||
|
conditionals: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = 0;
|
||||||
|
if (this)
|
||||||
|
c = 1 + c, c = c + 1;
|
||||||
|
else
|
||||||
|
c = 1 + c, c = c + 1;
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = 0;
|
||||||
|
this, c = 1 + c, c += 1;
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "2"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3271: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
var i = 0, b = [];
|
||||||
|
if (a) {
|
||||||
|
b[i++] = 4,
|
||||||
|
b[i++] = 1;
|
||||||
|
} else {
|
||||||
|
b[i++] = 3,
|
||||||
|
b[i++] = 2,
|
||||||
|
b[i++] = 1;
|
||||||
|
}
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
console.log(f(0).pop(), f(1).pop());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a) {
|
||||||
|
var i = 0, b = [];
|
||||||
|
a ? b[i++] = 4 : (b[i++] = 3, b[i++] = 2),
|
||||||
|
b[i++] = 1;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
console.log(f(0).pop(), f(1).pop());
|
||||||
|
}
|
||||||
|
expect_stdout: "1 1"
|
||||||
|
}
|
||||||
|
|
||||||
|
iife_condition: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
if (function() {
|
||||||
|
return console;
|
||||||
|
}())
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function() {
|
||||||
|
return console;
|
||||||
|
}() || console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
angularjs_chain: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
passes: 2,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function nonComputedMember(left, right, context, create) {
|
||||||
|
var lhs = left();
|
||||||
|
if (create && create !== 1) {
|
||||||
|
if (lhs && lhs[right] == null) {
|
||||||
|
lhs[right] = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var value = lhs != null ? lhs[right] : undefined;
|
||||||
|
if (context) {
|
||||||
|
return { context: lhs, name: right, value: value };
|
||||||
|
} else {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function nonComputedMember(left, right, context, create) {
|
||||||
|
var lhs = left();
|
||||||
|
create && 1 !== create && lhs && null == lhs[right] && (lhs[right] = {});
|
||||||
|
var value = null != lhs ? lhs[right] : void 0;
|
||||||
|
return context ? {
|
||||||
|
context: lhs,
|
||||||
|
name: right,
|
||||||
|
value: value
|
||||||
|
} : value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -942,3 +942,21 @@ issue_2929: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe_string_replace: {
|
||||||
|
options = {
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"foo".replace("f", function() {
|
||||||
|
console.log("PASS");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"foo".replace("f", function() {
|
||||||
|
console.log("PASS");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1982,3 +1982,47 @@ issue_3192: {
|
|||||||
"foo bar",
|
"foo bar",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3233: {
|
||||||
|
options = {
|
||||||
|
pure_getters: "strict",
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = function b() {
|
||||||
|
b.c = "PASS";
|
||||||
|
};
|
||||||
|
a();
|
||||||
|
console.log(a.c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = function b() {
|
||||||
|
b.c = "PASS";
|
||||||
|
};
|
||||||
|
a();
|
||||||
|
console.log(a.c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3375: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var b = 1;
|
||||||
|
var a = c = [], c = --b + ("function" == typeof f && f());
|
||||||
|
var a = c && c[a];
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var b = 1;
|
||||||
|
var a = [], c = --b + ("function" == typeof f && f());
|
||||||
|
a = c && c[a];
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: "0 0"
|
||||||
|
}
|
||||||
|
|||||||
@@ -820,8 +820,8 @@ unsafe_charAt_noop: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(
|
console.log(
|
||||||
s.charAt(0),
|
s[0],
|
||||||
"string".charAt(x),
|
"string"[0 | x],
|
||||||
(typeof x)[0]
|
(typeof x)[0]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1124,14 +1124,14 @@ issue_2207_1: {
|
|||||||
console.log(Math.max(3, 6, 2, 7, 3, 4));
|
console.log(Math.max(3, 6, 2, 7, 3, 4));
|
||||||
console.log(Math.cos(1.2345));
|
console.log(Math.cos(1.2345));
|
||||||
console.log(Math.cos(1.2345) - Math.sin(4.321));
|
console.log(Math.cos(1.2345) - Math.sin(4.321));
|
||||||
console.log(Math.pow(Math.PI, Math.E - Math.LN10));
|
console.log(Math.pow(Math.PI, Math.E - Math.LN10).toFixed(15));
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log("A");
|
console.log("A");
|
||||||
console.log(7);
|
console.log(7);
|
||||||
console.log(Math.cos(1.2345));
|
console.log(Math.cos(1.2345));
|
||||||
console.log(1.2543732512566947);
|
console.log(1.2543732512566947);
|
||||||
console.log(1.6093984514472044);
|
console.log("1.609398451447204");
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
@@ -1199,7 +1199,7 @@ issue_2231_1: {
|
|||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Error evaluating Object.keys(void 0) [test/compress/evaluate.js:1195,20]",
|
"WARN: Error evaluating Object.keys(void 0) [test/compress/evaluate.js:1,20]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1216,7 +1216,7 @@ issue_2231_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Error evaluating Object.getOwnPropertyNames(null) [test/compress/evaluate.js:1212,20]",
|
"WARN: Error evaluating Object.getOwnPropertyNames(null) [test/compress/evaluate.js:1,20]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1245,12 +1245,12 @@ self_comparison_1: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var o = { n: NaN };
|
var o = { n: NaN };
|
||||||
console.log(o.n == o.n, o.n === o.n, o.n != o.n, o.n !== o.n, typeof o.n);
|
console.log(typeof o.n, o.n == o.n, o.n === o.n, o.n != o.n, o.n !== o.n);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(false, false, true, true, "number");
|
console.log("number", false, false, true, true);
|
||||||
}
|
}
|
||||||
expect_stdout: "false false true true 'number'"
|
expect_stdout: "number false false true true"
|
||||||
}
|
}
|
||||||
|
|
||||||
self_comparison_2: {
|
self_comparison_2: {
|
||||||
@@ -1265,12 +1265,12 @@ self_comparison_2: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var o = { n: NaN };
|
var o = { n: NaN };
|
||||||
console.log(o.n == o.n, o.n === o.n, o.n != o.n, o.n !== o.n, typeof o.n);
|
console.log(typeof o.n, o.n == o.n, o.n === o.n, o.n != o.n, o.n !== o.n);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(false, false, true, true, "number");
|
console.log("number", false, false, true, true);
|
||||||
}
|
}
|
||||||
expect_stdout: "false false true true 'number'"
|
expect_stdout: "number false false true true"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2535_1: {
|
issue_2535_1: {
|
||||||
@@ -1354,14 +1354,14 @@ issue_2535_3: {
|
|||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1340,20]",
|
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1,20]",
|
||||||
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1341,20]",
|
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:2,20]",
|
||||||
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:1342,20]",
|
"WARN: Dropping side-effect-free && [test/compress/evaluate.js:3,20]",
|
||||||
"WARN: Condition left of && always false [test/compress/evaluate.js:1342,20]",
|
"WARN: Condition left of && always false [test/compress/evaluate.js:3,20]",
|
||||||
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1343,20]",
|
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:4,20]",
|
||||||
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1344,20]",
|
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:5,20]",
|
||||||
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:1345,20]",
|
"WARN: Dropping side-effect-free || [test/compress/evaluate.js:6,20]",
|
||||||
"WARN: Condition left of || always true [test/compress/evaluate.js:1345,20]",
|
"WARN: Condition left of || always true [test/compress/evaluate.js:6,20]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1540,7 +1540,7 @@ issue_2926_2: {
|
|||||||
expect_stdout: "function"
|
expect_stdout: "function"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_2968: {
|
issue_2968_1: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
@@ -1571,6 +1571,39 @@ issue_2968: {
|
|||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2968_2: {
|
||||||
|
options = {
|
||||||
|
assignments: true,
|
||||||
|
collapse_vars: true,
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = "FAIL";
|
||||||
|
(function() {
|
||||||
|
(function(a, b) {
|
||||||
|
a <<= 0;
|
||||||
|
a && (a[(c = "PASS", 0 >>> (b += 1))] = 0);
|
||||||
|
})(42, -42);
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = "FAIL";
|
||||||
|
(function() {
|
||||||
|
a = 42,
|
||||||
|
((a <<= 0) && (a[(c = "PASS", 0)] = 0));
|
||||||
|
var a;
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
truthy_conditionals: {
|
truthy_conditionals: {
|
||||||
options = {
|
options = {
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
@@ -1610,3 +1643,90 @@ truthy_loops: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if_increment: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a) {
|
||||||
|
if (console)
|
||||||
|
return ++a;
|
||||||
|
}(0));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a) {
|
||||||
|
if (console)
|
||||||
|
return 1;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
try_increment: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(a) {
|
||||||
|
try {
|
||||||
|
return ++a;
|
||||||
|
} catch (e) {}
|
||||||
|
}(0));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(a) {
|
||||||
|
try {
|
||||||
|
return 1;
|
||||||
|
} catch (e) {}
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_escaped: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 3,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(a) {
|
||||||
|
console.log(function(index) {
|
||||||
|
return a[index];
|
||||||
|
}(function(term) {
|
||||||
|
return a.indexOf(term);
|
||||||
|
}("PASS")));
|
||||||
|
})([ "PASS" ]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_string_replace: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"foo".replace("f", function() {
|
||||||
|
console.log("PASS");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"foo".replace("f", function() {
|
||||||
|
console.log("PASS");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -236,32 +236,6 @@ issue_203: {
|
|||||||
expect_stdout: "42"
|
expect_stdout: "42"
|
||||||
}
|
}
|
||||||
|
|
||||||
no_webkit: {
|
|
||||||
beautify = {
|
|
||||||
webkit: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function() {
|
|
||||||
1 + 1;
|
|
||||||
}.a = 1);
|
|
||||||
}
|
|
||||||
expect_exact: "console.log(function(){1+1}.a=1);"
|
|
||||||
expect_stdout: "1"
|
|
||||||
}
|
|
||||||
|
|
||||||
webkit: {
|
|
||||||
beautify = {
|
|
||||||
webkit: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function() {
|
|
||||||
1 + 1;
|
|
||||||
}.a = 1);
|
|
||||||
}
|
|
||||||
expect_exact: "console.log((function(){1+1}).a=1);"
|
|
||||||
expect_stdout: "1"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2084: {
|
issue_2084: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
@@ -384,6 +358,7 @@ inner_ref: {
|
|||||||
|
|
||||||
issue_2107: {
|
issue_2107: {
|
||||||
options = {
|
options = {
|
||||||
|
assignments: true,
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
passes: 3,
|
passes: 3,
|
||||||
@@ -413,6 +388,7 @@ issue_2107: {
|
|||||||
|
|
||||||
issue_2114_1: {
|
issue_2114_1: {
|
||||||
options = {
|
options = {
|
||||||
|
assignments: true,
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
@@ -445,6 +421,7 @@ issue_2114_1: {
|
|||||||
|
|
||||||
issue_2114_2: {
|
issue_2114_2: {
|
||||||
options = {
|
options = {
|
||||||
|
assignments: true,
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
if_return: true,
|
if_return: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
@@ -1249,6 +1226,7 @@ issue_2630_1: {
|
|||||||
|
|
||||||
issue_2630_2: {
|
issue_2630_2: {
|
||||||
options = {
|
options = {
|
||||||
|
assignments: true,
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
passes: 2,
|
passes: 2,
|
||||||
@@ -1346,6 +1324,7 @@ issue_2630_4: {
|
|||||||
|
|
||||||
issue_2630_5: {
|
issue_2630_5: {
|
||||||
options = {
|
options = {
|
||||||
|
assignments: true,
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
inline: true,
|
inline: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
@@ -1424,6 +1403,8 @@ recursive_inline_2: {
|
|||||||
issue_2657: {
|
issue_2657: {
|
||||||
options = {
|
options = {
|
||||||
inline: true,
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
sequences: true,
|
sequences: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -2341,3 +2322,746 @@ issue_3125: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3274: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
join_vars: true,
|
||||||
|
loops: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var g = function(a) {
|
||||||
|
var c = a.p, b = c;
|
||||||
|
return b != c;
|
||||||
|
};
|
||||||
|
while (g(1))
|
||||||
|
console.log("FAIL");
|
||||||
|
console.log("PASS");
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
for (var c; void 0, (c = 1..p) != c;)
|
||||||
|
console.log("FAIL");
|
||||||
|
console.log("PASS");
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3297_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
function function1() {
|
||||||
|
var r = {
|
||||||
|
function2: function2
|
||||||
|
};
|
||||||
|
function function2() {
|
||||||
|
alert(1234);
|
||||||
|
function function3() {
|
||||||
|
function2();
|
||||||
|
};
|
||||||
|
function3();
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function function1() {
|
||||||
|
return {
|
||||||
|
function2: function n() {
|
||||||
|
alert(1234);
|
||||||
|
function t() {
|
||||||
|
n();
|
||||||
|
}
|
||||||
|
t();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3297_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
conditionals: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
function function1(session) {
|
||||||
|
var public = {
|
||||||
|
processBulk: processBulk
|
||||||
|
};
|
||||||
|
return public;
|
||||||
|
function processBulk(bulk) {
|
||||||
|
var subparam1 = session();
|
||||||
|
function processOne(param1) {
|
||||||
|
var param2 = {
|
||||||
|
subparam1: subparam1
|
||||||
|
};
|
||||||
|
doProcessOne({
|
||||||
|
param1: param1,
|
||||||
|
param2: param2,
|
||||||
|
}, function () {
|
||||||
|
processBulk(bulk);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
if (bulk && bulk.length > 0)
|
||||||
|
processOne(bulk.shift());
|
||||||
|
}
|
||||||
|
function doProcessOne(config, callback) {
|
||||||
|
console.log(JSON.stringify(config));
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function1(function session() {
|
||||||
|
return 42;
|
||||||
|
}).processBulk([1, 2, 3]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function function1(o) {
|
||||||
|
return {
|
||||||
|
processBulk: function t(u) {
|
||||||
|
var r = o();
|
||||||
|
function n(n) {
|
||||||
|
var o = {
|
||||||
|
subparam1: r
|
||||||
|
};
|
||||||
|
c({
|
||||||
|
param1: n,
|
||||||
|
param2: o
|
||||||
|
}, function() {
|
||||||
|
t(u);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
u && u.length > 0 && n(u.shift());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
function c(n, o) {
|
||||||
|
console.log(JSON.stringify(n));
|
||||||
|
o();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function1(function() {
|
||||||
|
return 42;
|
||||||
|
}).processBulk([ 1, 2, 3 ]);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
'{"param1":1,"param2":{"subparam1":42}}',
|
||||||
|
'{"param1":2,"param2":{"subparam1":42}}',
|
||||||
|
'{"param1":3,"param2":{"subparam1":42}}',
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3297_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
comparisons: true,
|
||||||
|
conditionals: true,
|
||||||
|
inline: true,
|
||||||
|
join_vars: true,
|
||||||
|
passes: 3,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
function function1(session) {
|
||||||
|
var public = {
|
||||||
|
processBulk: processBulk
|
||||||
|
};
|
||||||
|
return public;
|
||||||
|
function processBulk(bulk) {
|
||||||
|
var subparam1 = session();
|
||||||
|
function processOne(param1) {
|
||||||
|
var param2 = {
|
||||||
|
subparam1: subparam1
|
||||||
|
};
|
||||||
|
doProcessOne({
|
||||||
|
param1: param1,
|
||||||
|
param2: param2,
|
||||||
|
}, function () {
|
||||||
|
processBulk(bulk);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
if (bulk && bulk.length > 0)
|
||||||
|
processOne(bulk.shift());
|
||||||
|
}
|
||||||
|
function doProcessOne(config, callback) {
|
||||||
|
console.log(JSON.stringify(config));
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function1(function session() {
|
||||||
|
return 42;
|
||||||
|
}).processBulk([1, 2, 3]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function function1(u) {
|
||||||
|
return {
|
||||||
|
processBulk: function n(r) {
|
||||||
|
var o, t = u();
|
||||||
|
r && 0 < r.length && (o = {
|
||||||
|
param1: r.shift(),
|
||||||
|
param2: {
|
||||||
|
subparam1: t
|
||||||
|
}
|
||||||
|
},
|
||||||
|
console.log(JSON.stringify(o)),
|
||||||
|
n(r));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function1(function() {
|
||||||
|
return 42;
|
||||||
|
}).processBulk([ 1, 2, 3 ]);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
'{"param1":1,"param2":{"subparam1":42}}',
|
||||||
|
'{"param1":2,"param2":{"subparam1":42}}',
|
||||||
|
'{"param1":3,"param2":{"subparam1":42}}',
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
cross_references_1: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var Math = {
|
||||||
|
square: function(n) {
|
||||||
|
return n * n;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
console.log((function(factory) {
|
||||||
|
return factory();
|
||||||
|
})(function() {
|
||||||
|
return function(Math) {
|
||||||
|
return function(n) {
|
||||||
|
return Math.square(n);
|
||||||
|
};
|
||||||
|
}(Math);
|
||||||
|
})(3));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var Math = {
|
||||||
|
square: function(n) {
|
||||||
|
return n * n;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
console.log(function(Math) {
|
||||||
|
return function(n) {
|
||||||
|
return Math.square(n);
|
||||||
|
};
|
||||||
|
}(Math)(3));
|
||||||
|
}
|
||||||
|
expect_stdout: "9"
|
||||||
|
}
|
||||||
|
|
||||||
|
cross_references_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
evaluate: true,
|
||||||
|
hoist_props: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 4,
|
||||||
|
pure_getters: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var Math = {
|
||||||
|
square: function(n) {
|
||||||
|
return n * n;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
console.log((function(factory) {
|
||||||
|
return factory();
|
||||||
|
})(function() {
|
||||||
|
return function(Math) {
|
||||||
|
return function(n) {
|
||||||
|
return Math.square(n);
|
||||||
|
};
|
||||||
|
}(Math);
|
||||||
|
})(3));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(9);
|
||||||
|
}
|
||||||
|
expect_stdout: "9"
|
||||||
|
}
|
||||||
|
|
||||||
|
cross_references_3: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var Math = {
|
||||||
|
square: function(n) {
|
||||||
|
return n * n;
|
||||||
|
},
|
||||||
|
cube: function(n) {
|
||||||
|
return n * n * n;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
console.log(function(factory) {
|
||||||
|
return factory();
|
||||||
|
}(function() {
|
||||||
|
return function(Math) {
|
||||||
|
return function(n) {
|
||||||
|
Math = {
|
||||||
|
square: function(x) {
|
||||||
|
return "(SQUARE" + x + ")";
|
||||||
|
},
|
||||||
|
cube: function(x) {
|
||||||
|
return "(CUBE" + x + ")";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return Math.square(n) + Math.cube(n);
|
||||||
|
};
|
||||||
|
}(Math);
|
||||||
|
})(2));
|
||||||
|
console.log(Math.square(3), Math.cube(3));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var Math = {
|
||||||
|
square: function(n) {
|
||||||
|
return n * n;
|
||||||
|
},
|
||||||
|
cube: function(n) {
|
||||||
|
return n * n * n;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
console.log(function(Math) {
|
||||||
|
return function(n) {
|
||||||
|
Math = {
|
||||||
|
square: function(x) {
|
||||||
|
return "(SQUARE" + x + ")";
|
||||||
|
},
|
||||||
|
cube: function(x) {
|
||||||
|
return "(CUBE" + x + ")";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return Math.square(n) + Math.cube(n);
|
||||||
|
};
|
||||||
|
}(Math)(2));
|
||||||
|
console.log(Math.square(3), Math.cube(3));
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"(SQUARE2)(CUBE2)",
|
||||||
|
"9 27",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
loop_inline: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(o) {
|
||||||
|
function g(p) {
|
||||||
|
return o[p];
|
||||||
|
}
|
||||||
|
function h(q) {
|
||||||
|
while (g(q));
|
||||||
|
}
|
||||||
|
return h;
|
||||||
|
}([ 1, "foo", 0 ])(2));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function(o) {
|
||||||
|
return function(q) {
|
||||||
|
while (p = q, o[p]);
|
||||||
|
var p;
|
||||||
|
};
|
||||||
|
}([ 1, "foo", 0 ])(2));
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
functions: {
|
||||||
|
options = {
|
||||||
|
functions: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
!function() {
|
||||||
|
var a = function a() {
|
||||||
|
return a && "a";
|
||||||
|
};
|
||||||
|
var b = function x() {
|
||||||
|
return !!x;
|
||||||
|
};
|
||||||
|
var c = function(c) {
|
||||||
|
return c;
|
||||||
|
};
|
||||||
|
if (c(b(a()))) {
|
||||||
|
var d = function() {};
|
||||||
|
var e = function y() {
|
||||||
|
return typeof y;
|
||||||
|
};
|
||||||
|
var f = function(f) {
|
||||||
|
return f;
|
||||||
|
};
|
||||||
|
console.log(a(d()), b(e()), c(f(42)), typeof d, e(), typeof f);
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function() {
|
||||||
|
function a() {
|
||||||
|
return a && "a";
|
||||||
|
}
|
||||||
|
function b() {
|
||||||
|
return !!b;
|
||||||
|
}
|
||||||
|
var c = function(c) {
|
||||||
|
return c;
|
||||||
|
};
|
||||||
|
if (c(b(a()))) {
|
||||||
|
function d() {}
|
||||||
|
function e() {
|
||||||
|
return typeof e;
|
||||||
|
}
|
||||||
|
var f = function(f) {
|
||||||
|
return f;
|
||||||
|
};
|
||||||
|
console.log(a(d()), b(e()), c(f(42)), typeof d, e(), typeof f);
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
expect_stdout: "a true 42 function function function"
|
||||||
|
}
|
||||||
|
|
||||||
|
functions_use_strict: {
|
||||||
|
options = {
|
||||||
|
functions: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
!function() {
|
||||||
|
var a = function a() {
|
||||||
|
return a && "a";
|
||||||
|
};
|
||||||
|
var b = function x() {
|
||||||
|
return !!x;
|
||||||
|
};
|
||||||
|
var c = function(c) {
|
||||||
|
return c;
|
||||||
|
};
|
||||||
|
if (c(b(a()))) {
|
||||||
|
var d = function() {};
|
||||||
|
var e = function y() {
|
||||||
|
return typeof y;
|
||||||
|
};
|
||||||
|
var f = function(f) {
|
||||||
|
return f;
|
||||||
|
};
|
||||||
|
console.log(a(d()), b(e()), c(f(42)), typeof d, e(), typeof f);
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
!function() {
|
||||||
|
function a() {
|
||||||
|
return a && "a";
|
||||||
|
}
|
||||||
|
function b() {
|
||||||
|
return !!b;
|
||||||
|
}
|
||||||
|
var c = function(c) {
|
||||||
|
return c;
|
||||||
|
};
|
||||||
|
if (c(b(a()))) {
|
||||||
|
var d = function() {};
|
||||||
|
var e = function y() {
|
||||||
|
return typeof y;
|
||||||
|
};
|
||||||
|
var f = function(f) {
|
||||||
|
return f;
|
||||||
|
};
|
||||||
|
console.log(a(d()), b(e()), c(f(42)), typeof d, e(), typeof f);
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
expect_stdout: "a true 42 function function function"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2437: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
conditionals: true,
|
||||||
|
functions: true,
|
||||||
|
inline: true,
|
||||||
|
join_vars: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function foo() {
|
||||||
|
return bar();
|
||||||
|
}
|
||||||
|
function bar() {
|
||||||
|
if (xhrDesc) {
|
||||||
|
var req = new XMLHttpRequest();
|
||||||
|
var result = !!req.onreadystatechange;
|
||||||
|
Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', xhrDesc || {});
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
var req = new XMLHttpRequest();
|
||||||
|
var detectFunc = function(){};
|
||||||
|
req.onreadystatechange = detectFunc;
|
||||||
|
var result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc;
|
||||||
|
req.onreadystatechange = null;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(foo());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function() {
|
||||||
|
if (xhrDesc) {
|
||||||
|
var result = !!(req = new XMLHttpRequest()).onreadystatechange;
|
||||||
|
return Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {}),
|
||||||
|
result;
|
||||||
|
}
|
||||||
|
function detectFunc() {}
|
||||||
|
var req;
|
||||||
|
(req = new XMLHttpRequest()).onreadystatechange = detectFunc;
|
||||||
|
result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc;
|
||||||
|
return req.onreadystatechange = null, result;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2485: {
|
||||||
|
options = {
|
||||||
|
functions: true,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var foo = function(bar) {
|
||||||
|
var n = function(a, b) {
|
||||||
|
return a + b;
|
||||||
|
};
|
||||||
|
var sumAll = function(arg) {
|
||||||
|
return arg.reduce(n, 0);
|
||||||
|
};
|
||||||
|
var runSumAll = function(arg) {
|
||||||
|
return sumAll(arg);
|
||||||
|
};
|
||||||
|
bar.baz = function(arg) {
|
||||||
|
var n = runSumAll(arg);
|
||||||
|
return (n.get = 1), n;
|
||||||
|
};
|
||||||
|
return bar;
|
||||||
|
};
|
||||||
|
var bar = foo({});
|
||||||
|
console.log(bar.baz([1, 2, 3]));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var foo = function(bar) {
|
||||||
|
function n(a, b) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
function runSumAll(arg) {
|
||||||
|
return function(arg) {
|
||||||
|
return arg.reduce(n, 0);
|
||||||
|
}(arg);
|
||||||
|
}
|
||||||
|
bar.baz = function(arg) {
|
||||||
|
var n = runSumAll(arg);
|
||||||
|
return (n.get = 1), n;
|
||||||
|
};
|
||||||
|
return bar;
|
||||||
|
};
|
||||||
|
var bar = foo({});
|
||||||
|
console.log(bar.baz([1, 2, 3]));
|
||||||
|
}
|
||||||
|
expect_stdout: "6"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3364: {
|
||||||
|
options = {
|
||||||
|
functions: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
var s = 2, a = 100, b = 10, c = 0;
|
||||||
|
function f(p, e, r) {
|
||||||
|
try {
|
||||||
|
for (var i = 1; i-- > 0;)
|
||||||
|
var a = function(x) {
|
||||||
|
function g(y) {
|
||||||
|
y && y[a++];
|
||||||
|
}
|
||||||
|
var x = g(--s >= 0 && f(c++));
|
||||||
|
for (var j = 1; --j > 0;);
|
||||||
|
}();
|
||||||
|
} catch (e) {
|
||||||
|
try {
|
||||||
|
return;
|
||||||
|
} catch (z) {
|
||||||
|
for (var k = 1; --k > 0;) {
|
||||||
|
for (var l = 1; l > 0; --l) {
|
||||||
|
var n = function() {};
|
||||||
|
for (var k in n)
|
||||||
|
var o = (n, k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var r = f();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var s = 2, c = 0;
|
||||||
|
(function n(r, o, a) {
|
||||||
|
try {
|
||||||
|
for (var f = 1; f-- >0;)
|
||||||
|
var t = function(r) {
|
||||||
|
(function(r) {
|
||||||
|
r && r[t++];
|
||||||
|
})(--s >= 0 && n(c++));
|
||||||
|
for (var o = 1; --o > 0;);
|
||||||
|
}();
|
||||||
|
} catch (o) {
|
||||||
|
try {
|
||||||
|
return;
|
||||||
|
} catch (r) {
|
||||||
|
for (var v = 1; --v > 0;)
|
||||||
|
for (var i = 1; i > 0;--i) {
|
||||||
|
function u() {}
|
||||||
|
for (var v in u);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "2"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3366: {
|
||||||
|
options = {
|
||||||
|
functions: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
function g() {
|
||||||
|
return function() {};
|
||||||
|
}
|
||||||
|
var a = g();
|
||||||
|
(function() {
|
||||||
|
this && a && console.log("PASS");
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
void function() {
|
||||||
|
this && a && console.log("PASS");
|
||||||
|
}();
|
||||||
|
function a() {}
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3371: {
|
||||||
|
options = {
|
||||||
|
functions: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var a = function f() {
|
||||||
|
(function() {
|
||||||
|
console.log(typeof f);
|
||||||
|
})();
|
||||||
|
};
|
||||||
|
while (a());
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
function a() {
|
||||||
|
console.log(typeof a);
|
||||||
|
}
|
||||||
|
while (a());
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
|
|
||||||
|
class_iife: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
sequences: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var A = function() {
|
||||||
|
function B() {}
|
||||||
|
B.prototype.m = function() {
|
||||||
|
console.log("PASS");
|
||||||
|
};
|
||||||
|
return B;
|
||||||
|
}();
|
||||||
|
new A().m();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var A = (B.prototype.m = function() {
|
||||||
|
console.log("PASS");
|
||||||
|
}, B);
|
||||||
|
function B() {}
|
||||||
|
new A().m();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -141,9 +141,8 @@ mixed: {
|
|||||||
console.log(CONFIG);
|
console.log(CONFIG);
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:127,22]",
|
"WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:4,22]",
|
||||||
"WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:128,22]",
|
"WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:7,8]",
|
||||||
"WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:130,8]",
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,3 +196,23 @@ issue_2167: {
|
|||||||
doWork();
|
doWork();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3217: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
global_defs: {
|
||||||
|
"@o": "{fn:function(){var a=42;console.log(a)}}",
|
||||||
|
},
|
||||||
|
inline: true,
|
||||||
|
properties: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
o.fn();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(42);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -678,6 +678,7 @@ issue_3206_1: {
|
|||||||
input: {
|
input: {
|
||||||
console.log(function() {
|
console.log(function() {
|
||||||
var foo = function bar() {};
|
var foo = function bar() {};
|
||||||
|
var baz = function moo() {};
|
||||||
return "function" == typeof bar;
|
return "function" == typeof bar;
|
||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
@@ -700,6 +701,7 @@ issue_3206_2: {
|
|||||||
input: {
|
input: {
|
||||||
console.log(function() {
|
console.log(function() {
|
||||||
var foo = function bar() {};
|
var foo = function bar() {};
|
||||||
|
var baz = function moo() {};
|
||||||
return "function" == typeof bar;
|
return "function" == typeof bar;
|
||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
@@ -711,3 +713,259 @@ issue_3206_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "false"
|
expect_stdout: "false"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3215_1: {
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function foo() {
|
||||||
|
var bar = function bar(name) {
|
||||||
|
return "PASS";
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
"moo";
|
||||||
|
} catch (e) {
|
||||||
|
bar = function bar(name) {
|
||||||
|
return "FAIL";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return bar;
|
||||||
|
}()());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function n() {
|
||||||
|
var o = function n(o) {
|
||||||
|
return "PASS";
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
"moo";
|
||||||
|
} catch (n) {
|
||||||
|
o = function n(o) {
|
||||||
|
return "FAIL";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
}()());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3215_2: {
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function foo() {
|
||||||
|
var bar = function bar(name) {
|
||||||
|
return "PASS";
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
"moo";
|
||||||
|
} catch (e) {
|
||||||
|
bar = function bar(name) {
|
||||||
|
return "FAIL";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return bar;
|
||||||
|
}()());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function foo() {
|
||||||
|
var o = function o(n) {
|
||||||
|
return "PASS";
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
"moo";
|
||||||
|
} catch (n) {
|
||||||
|
o = function o(n) {
|
||||||
|
return "FAIL";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
}()());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3215_3: {
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function foo() {
|
||||||
|
var bar = function bar(name) {
|
||||||
|
return "FAIL";
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
moo;
|
||||||
|
} catch (e) {
|
||||||
|
bar = function bar(name) {
|
||||||
|
return "PASS";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return bar;
|
||||||
|
}()());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function n() {
|
||||||
|
var o = function n(o) {
|
||||||
|
return "FAIL";
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
moo;
|
||||||
|
} catch (n) {
|
||||||
|
o = function n(o) {
|
||||||
|
return "PASS";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
}()());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3215_4: {
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function foo() {
|
||||||
|
var bar = function bar(name) {
|
||||||
|
return "FAIL";
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
moo;
|
||||||
|
} catch (e) {
|
||||||
|
bar = function bar(name) {
|
||||||
|
return "PASS";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return bar;
|
||||||
|
}()());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function foo() {
|
||||||
|
var o = function o(n) {
|
||||||
|
return "FAIL";
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
moo;
|
||||||
|
} catch (n) {
|
||||||
|
o = function o(n) {
|
||||||
|
return "PASS";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
}()());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3355_1: {
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function f() {
|
||||||
|
var f;
|
||||||
|
})();
|
||||||
|
(function g() {
|
||||||
|
})();
|
||||||
|
console.log(typeof f === typeof g);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function o() {
|
||||||
|
var o;
|
||||||
|
})();
|
||||||
|
(function o() {
|
||||||
|
})();
|
||||||
|
console.log(typeof f === typeof g);
|
||||||
|
}
|
||||||
|
expect_stdout: "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3355_2: {
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function f() {
|
||||||
|
var f;
|
||||||
|
})();
|
||||||
|
(function g() {
|
||||||
|
})();
|
||||||
|
console.log(typeof f === typeof g);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function f() {
|
||||||
|
var f;
|
||||||
|
})();
|
||||||
|
(function g() {
|
||||||
|
})();
|
||||||
|
console.log(typeof f === typeof g);
|
||||||
|
}
|
||||||
|
expect_stdout: "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3355_3: {
|
||||||
|
mangle = {
|
||||||
|
ie8: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
!function(a) {
|
||||||
|
"aaaaaaaaaa";
|
||||||
|
a();
|
||||||
|
var b = function c() {
|
||||||
|
var c = 42;
|
||||||
|
console.log("FAIL");
|
||||||
|
};
|
||||||
|
}(function() {
|
||||||
|
console.log("PASS");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function(a) {
|
||||||
|
"aaaaaaaaaa";
|
||||||
|
a();
|
||||||
|
var o = function a() {
|
||||||
|
var a = 42;
|
||||||
|
console.log("FAIL");
|
||||||
|
};
|
||||||
|
}(function() {
|
||||||
|
console.log("PASS");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3355_4: {
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
!function(a) {
|
||||||
|
"aaaaaaaaaa";
|
||||||
|
a();
|
||||||
|
var b = function c() {
|
||||||
|
var c = 42;
|
||||||
|
console.log("FAIL");
|
||||||
|
};
|
||||||
|
}(function() {
|
||||||
|
console.log("PASS");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function(a) {
|
||||||
|
"aaaaaaaaaa";
|
||||||
|
a();
|
||||||
|
var o = function n() {
|
||||||
|
var n = 42;
|
||||||
|
console.log("FAIL");
|
||||||
|
};
|
||||||
|
}(function() {
|
||||||
|
console.log("PASS");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -396,3 +396,151 @@ if_if_return_return: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if_body_return_1: {
|
||||||
|
options = {
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = "PASS";
|
||||||
|
function f(a, b) {
|
||||||
|
if (a) {
|
||||||
|
if (b) throw new Error(c);
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
console.log(f(0, 0));
|
||||||
|
console.log(f(0, 1));
|
||||||
|
console.log(f(1, 0));
|
||||||
|
try {
|
||||||
|
f(1, 1);
|
||||||
|
console.log("FAIL");
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = "PASS";
|
||||||
|
function f(a, b) {
|
||||||
|
if (a) {
|
||||||
|
if (b) throw new Error(c);
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
console.log(f(0, 0));
|
||||||
|
console.log(f(0, 1));
|
||||||
|
console.log(f(1, 0));
|
||||||
|
try {
|
||||||
|
f(1, 1);
|
||||||
|
console.log("FAIL");
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"42",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
if_body_return_2: {
|
||||||
|
options = {
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = "PASS";
|
||||||
|
function f(a, b) {
|
||||||
|
if (0 + a) {
|
||||||
|
if (b) throw new Error(c);
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
console.log(f(0, 0));
|
||||||
|
console.log(f(0, 1));
|
||||||
|
console.log(f(1, 0));
|
||||||
|
try {
|
||||||
|
f(1, 1);
|
||||||
|
console.log("FAIL");
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = "PASS";
|
||||||
|
function f(a, b) {
|
||||||
|
if (0 + a) {
|
||||||
|
if (b) throw new Error(c);
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
console.log(f(0, 0));
|
||||||
|
console.log(f(0, 1));
|
||||||
|
console.log(f(1, 0));
|
||||||
|
try {
|
||||||
|
f(1, 1);
|
||||||
|
console.log("FAIL");
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"42",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
if_body_return_3: {
|
||||||
|
options = {
|
||||||
|
if_return: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = "PASS";
|
||||||
|
function f(a, b) {
|
||||||
|
if (1 == a) {
|
||||||
|
if (b) throw new Error(c);
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
console.log(f(0, 0));
|
||||||
|
console.log(f(0, 1));
|
||||||
|
console.log(f(1, 0));
|
||||||
|
try {
|
||||||
|
f(1, 1);
|
||||||
|
console.log("FAIL");
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = "PASS";
|
||||||
|
function f(a, b) {
|
||||||
|
if (1 != a) return true;
|
||||||
|
if (b) throw new Error(c);
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
console.log(f(0, 0));
|
||||||
|
console.log(f(0, 1));
|
||||||
|
console.log(f(1, 0));
|
||||||
|
try {
|
||||||
|
f(1, 1);
|
||||||
|
console.log("FAIL");
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
"42",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
@@ -36,10 +36,10 @@ non_hoisted_function_after_return: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:20,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:4,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:23,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:7,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:26,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:10,12]",
|
||||||
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:27,21]"
|
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:11,21]"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,18 +85,18 @@ non_hoisted_function_after_return_2a: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:68,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:4,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:68,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:4,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:71,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:7,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:71,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:7,16]",
|
||||||
"WARN: Dropping unused variable a [test/compress/issue-1034.js:68,20]",
|
"WARN: Dropping unused variable a [test/compress/issue-1034.js:4,20]",
|
||||||
"WARN: Dropping unused function nope [test/compress/issue-1034.js:75,21]",
|
"WARN: Dropping unused function nope [test/compress/issue-1034.js:11,21]",
|
||||||
"WARN: pass 0: last_count: Infinity, count: 37",
|
"WARN: pass 0: last_count: Infinity, count: 37",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:73,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:9,12]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:73,12]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:9,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:76,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:12,12]",
|
||||||
"WARN: Dropping unused variable b [test/compress/issue-1034.js:71,20]",
|
"WARN: Dropping unused variable b [test/compress/issue-1034.js:7,20]",
|
||||||
"WARN: Dropping unused variable c [test/compress/issue-1034.js:73,16]",
|
"WARN: Dropping unused variable c [test/compress/issue-1034.js:9,16]",
|
||||||
"WARN: pass 1: last_count: 37, count: 18",
|
"WARN: pass 1: last_count: 37, count: 18",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -139,12 +139,11 @@ non_hoisted_function_after_return_2b: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
// duplicate warnings no longer emitted
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:6,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:126,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:6,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:126,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:8,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:128,12]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:8,12]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:128,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:12,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:132,12]",
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,10 +190,10 @@ non_hoisted_function_after_return_strict: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "8 7"
|
expect_stdout: "8 7"
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:171,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:5,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:174,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:8,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:177,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:11,12]",
|
||||||
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:178,21]",
|
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:12,21]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,18 +244,18 @@ non_hoisted_function_after_return_2a_strict: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "5 6"
|
expect_stdout: "5 6"
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:224,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:5,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:224,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:5,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:227,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:8,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:227,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:8,16]",
|
||||||
"WARN: Dropping unused variable a [test/compress/issue-1034.js:224,20]",
|
"WARN: Dropping unused variable a [test/compress/issue-1034.js:5,20]",
|
||||||
"WARN: Dropping unused function nope [test/compress/issue-1034.js:231,21]",
|
"WARN: Dropping unused function nope [test/compress/issue-1034.js:12,21]",
|
||||||
"WARN: pass 0: last_count: Infinity, count: 48",
|
"WARN: pass 0: last_count: Infinity, count: 48",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:229,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:10,12]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:229,12]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:10,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:232,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:13,12]",
|
||||||
"WARN: Dropping unused variable b [test/compress/issue-1034.js:227,20]",
|
"WARN: Dropping unused variable b [test/compress/issue-1034.js:8,20]",
|
||||||
"WARN: Dropping unused variable c [test/compress/issue-1034.js:229,16]",
|
"WARN: Dropping unused variable c [test/compress/issue-1034.js:10,16]",
|
||||||
"WARN: pass 1: last_count: 48, count: 29",
|
"WARN: pass 1: last_count: 48, count: 29",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -304,11 +303,10 @@ non_hoisted_function_after_return_2b_strict: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "5 6"
|
expect_stdout: "5 6"
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
// duplicate warnings no longer emitted
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:7,16]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:287,16]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:7,16]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:287,16]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:9,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:289,12]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:9,12]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:289,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:13,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:293,12]",
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,13 +48,13 @@ pure_function_calls: {
|
|||||||
a.b(), f.g();
|
a.b(), f.g();
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:16,8]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:3,8]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:16,8]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:3,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:29,37]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:16,37]",
|
||||||
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:29,16]",
|
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:16,16]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:27,8]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:14,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:37,8]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:24,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:38,31]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:25,31]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,17 +110,17 @@ pure_function_calls_toplevel: {
|
|||||||
a.b(), f.g();
|
a.b(), f.g();
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:77,8]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:3,8]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:77,8]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:3,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:90,37]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:16,37]",
|
||||||
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:90,16]",
|
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:16,16]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:88,8]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:14,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:105,8]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:31,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:106,31]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:32,31]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:82,33]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:8,33]",
|
||||||
"WARN: Dropping unused variable iife1 [test/compress/issue-1261.js:82,12]",
|
"WARN: Dropping unused variable iife1 [test/compress/issue-1261.js:8,12]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:98,45]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:24,45]",
|
||||||
"WARN: Dropping unused variable MyClass [test/compress/issue-1261.js:98,12]",
|
"WARN: Dropping unused variable MyClass [test/compress/issue-1261.js:24,12]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,29 +155,29 @@ should_warn: {
|
|||||||
baz();
|
baz();
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:135,61]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:1,61]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:135,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:1,23]",
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:135,23]",
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:1,23]",
|
||||||
"WARN: Boolean || always true [test/compress/issue-1261.js:136,23]",
|
"WARN: Boolean || always true [test/compress/issue-1261.js:2,23]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:136,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:2,23]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:136,23]",
|
"WARN: Condition always true [test/compress/issue-1261.js:2,23]",
|
||||||
"WARN: Condition left of || always true [test/compress/issue-1261.js:137,8]",
|
"WARN: Condition left of || always true [test/compress/issue-1261.js:3,8]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:137,8]",
|
"WARN: Condition always true [test/compress/issue-1261.js:3,8]",
|
||||||
"WARN: Boolean && always false [test/compress/issue-1261.js:138,23]",
|
"WARN: Boolean && always false [test/compress/issue-1261.js:4,23]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:138,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:4,23]",
|
||||||
"WARN: Condition always false [test/compress/issue-1261.js:138,23]",
|
"WARN: Condition always false [test/compress/issue-1261.js:4,23]",
|
||||||
"WARN: Condition left of && always false [test/compress/issue-1261.js:139,8]",
|
"WARN: Condition left of && always false [test/compress/issue-1261.js:5,8]",
|
||||||
"WARN: Condition always false [test/compress/issue-1261.js:139,8]",
|
"WARN: Condition always false [test/compress/issue-1261.js:5,8]",
|
||||||
"WARN: + in boolean context always true [test/compress/issue-1261.js:140,23]",
|
"WARN: + in boolean context always true [test/compress/issue-1261.js:6,23]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:140,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:6,23]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:140,23]",
|
"WARN: Condition always true [test/compress/issue-1261.js:6,23]",
|
||||||
"WARN: + in boolean context always true [test/compress/issue-1261.js:141,8]",
|
"WARN: + in boolean context always true [test/compress/issue-1261.js:7,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:141,31]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:7,31]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:141,8]",
|
"WARN: Condition always true [test/compress/issue-1261.js:7,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:142,23]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:8,23]",
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:143,8]",
|
"WARN: Condition always true [test/compress/issue-1261.js:9,8]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:143,24]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:9,24]",
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:144,31]",
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:10,31]",
|
||||||
"WARN: Condition always false [test/compress/issue-1261.js:144,8]",
|
"WARN: Condition always false [test/compress/issue-1261.js:10,8]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
issue_1639_1: {
|
issue_1639_1: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
booleans: true,
|
||||||
@@ -12,7 +11,6 @@ issue_1639_1: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = 100, b = 10;
|
var a = 100, b = 10;
|
||||||
|
|
||||||
var L1 = 5;
|
var L1 = 5;
|
||||||
while (--L1 > 0) {
|
while (--L1 > 0) {
|
||||||
if ((--b), false) {
|
if ((--b), false) {
|
||||||
@@ -21,7 +19,6 @@ issue_1639_1: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(a, b);
|
console.log(a, b);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
@@ -29,7 +26,7 @@ issue_1639_1: {
|
|||||||
if (--b, 0) var ignore = 0;
|
if (--b, 0) var ignore = 0;
|
||||||
console.log(a, b);
|
console.log(a, b);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: "100 6"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1639_2: {
|
issue_1639_2: {
|
||||||
@@ -44,25 +41,23 @@ issue_1639_2: {
|
|||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var a = 100, b = 10;
|
var a = 100, b = 10;
|
||||||
|
|
||||||
function f19() {
|
function f19() {
|
||||||
if (++a, false)
|
if (++a, false)
|
||||||
if (a)
|
if (a)
|
||||||
if (++a);
|
if (++a);
|
||||||
}
|
}
|
||||||
f19();
|
f19();
|
||||||
|
|
||||||
console.log(a, b);
|
console.log(a, b);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var a = 100, b = 10;
|
var a = 100, b = 10;
|
||||||
function f19() {
|
function f19() {
|
||||||
++a, 0;
|
++a, 1;
|
||||||
}
|
}
|
||||||
f19(),
|
f19(),
|
||||||
console.log(a, b);
|
console.log(a, b);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: "101 10"
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1639_3: {
|
issue_1639_3: {
|
||||||
@@ -84,5 +79,5 @@ issue_1639_3: {
|
|||||||
a++,
|
a++,
|
||||||
console.log(a, b);
|
console.log(a, b);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: "101 10"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,11 +64,11 @@ mixed: {
|
|||||||
x = 0;
|
x = 0;
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: global_defs ENV redefined [test/compress/issue-208.js:45,12]",
|
"WARN: global_defs ENV redefined [test/compress/issue-208.js:1,12]",
|
||||||
"WARN: global_defs FOO redefined [test/compress/issue-208.js:46,12]",
|
"WARN: global_defs FOO redefined [test/compress/issue-208.js:2,12]",
|
||||||
"WARN: global_defs FOO redefined [test/compress/issue-208.js:48,10]",
|
"WARN: global_defs FOO redefined [test/compress/issue-208.js:4,10]",
|
||||||
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:49,8]",
|
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:5,8]",
|
||||||
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:50,8]",
|
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:6,8]",
|
||||||
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:51,8]",
|
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:7,8]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,6 +93,6 @@ regexp: {
|
|||||||
RegExp("should", "fail");
|
RegExp("should", "fail");
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
'WARN: Error converting RegExp("should","fail") [test/compress/issue-269.js:86,2]',
|
'WARN: Error converting RegExp("should","fail") [test/compress/issue-269.js:5,2]',
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ warn: {
|
|||||||
}().length);
|
}().length);
|
||||||
}
|
}
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Function.protoype.caller not supported [test/compress/issue-2719.js:17,19]",
|
"WARN: Function.prototype.caller not supported [test/compress/issue-2719.js:5,19]",
|
||||||
"WARN: Function.protoype.arguments not supported [test/compress/issue-2719.js:17,19]",
|
"WARN: Function.prototype.arguments not supported [test/compress/issue-2719.js:5,19]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -646,3 +646,30 @@ issue_2904: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "1"
|
expect_stdout: "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3371: {
|
||||||
|
options = {
|
||||||
|
functions: true,
|
||||||
|
join_vars: true,
|
||||||
|
loops: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var a = function() {
|
||||||
|
console.log("PASS");
|
||||||
|
};
|
||||||
|
while (a());
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
function a() {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
for (; a(); );
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
181
test/compress/preserve_line.js
Normal file
181
test/compress/preserve_line.js
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
return_1: {
|
||||||
|
beautify = {
|
||||||
|
beautify: false,
|
||||||
|
preserve_line: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function f() {
|
||||||
|
return (
|
||||||
|
f.toString() != 42
|
||||||
|
);
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"console.log(function f(){",
|
||||||
|
"",
|
||||||
|
"return 42!=f.toString()}());",
|
||||||
|
]
|
||||||
|
expect_stdout: "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
return_2: {
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
preserve_line: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function f() {
|
||||||
|
return (
|
||||||
|
f.toString() != 42
|
||||||
|
);
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"console.log(function f() {",
|
||||||
|
"",
|
||||||
|
" return 42 != f.toString();",
|
||||||
|
"}());",
|
||||||
|
]
|
||||||
|
expect_stdout: "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
return_3: {
|
||||||
|
options = {}
|
||||||
|
beautify = {
|
||||||
|
beautify: false,
|
||||||
|
preserve_line: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function f() {
|
||||||
|
return (
|
||||||
|
f.toString() != 42
|
||||||
|
);
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"console.log(function f(){",
|
||||||
|
"",
|
||||||
|
"return 42!=f.toString()}());",
|
||||||
|
]
|
||||||
|
expect_stdout: "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
return_4: {
|
||||||
|
options = {}
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
preserve_line: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function f() {
|
||||||
|
return (
|
||||||
|
f.toString() != 42
|
||||||
|
);
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"console.log(function f() {",
|
||||||
|
"",
|
||||||
|
" return 42 != f.toString();",
|
||||||
|
"}());",
|
||||||
|
]
|
||||||
|
expect_stdout: "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
return_5: {
|
||||||
|
beautify = {
|
||||||
|
beautify: false,
|
||||||
|
preserve_line: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
_is_selected = function(tags, slug) {
|
||||||
|
var ref;
|
||||||
|
return (ref = _.find(tags, {
|
||||||
|
slug: slug
|
||||||
|
})) != null ? ref.selected : void 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"_is_selected=function(tags,slug){",
|
||||||
|
"var ref",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
";return null!=(ref=_.find(tags,{slug:slug}))?ref.selected:void 0};",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
return_6: {
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
preserve_line: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
_is_selected = function(tags, slug) {
|
||||||
|
var ref;
|
||||||
|
return (ref = _.find(tags, {
|
||||||
|
slug: slug
|
||||||
|
})) != null ? ref.selected : void 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"_is_selected = function(tags, slug) {",
|
||||||
|
" var ref;",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
" return null != (ref = _.find(tags, {",
|
||||||
|
" slug: slug",
|
||||||
|
" })) ? ref.selected : void 0;",
|
||||||
|
"};",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
return_7: {
|
||||||
|
options = {}
|
||||||
|
mangle = {}
|
||||||
|
beautify = {
|
||||||
|
beautify: false,
|
||||||
|
preserve_line: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
_is_selected = function(tags, slug) {
|
||||||
|
var ref;
|
||||||
|
return (ref = _.find(tags, {
|
||||||
|
slug: slug
|
||||||
|
})) != null ? ref.selected : void 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"_is_selected=function(e,l){",
|
||||||
|
"var n",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
";return null!=(n=_.find(e,{slug:l}))?n.selected:void 0};",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
return_8: {
|
||||||
|
options = {}
|
||||||
|
mangle = {}
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
preserve_line: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
_is_selected = function(tags, slug) {
|
||||||
|
var ref;
|
||||||
|
return (ref = _.find(tags, {
|
||||||
|
slug: slug
|
||||||
|
})) != null ? ref.selected : void 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"_is_selected = function(e, l) {",
|
||||||
|
" var n;",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
" return null != (n = _.find(e, {",
|
||||||
|
" slug: l",
|
||||||
|
" })) ? n.selected : void 0;",
|
||||||
|
"};",
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1832,3 +1832,33 @@ issue_3188_3: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
join_expr: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
join_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var c = "FAIL";
|
||||||
|
(function() {
|
||||||
|
var a = 0;
|
||||||
|
switch ((a = {}) && (a.b = 0)) {
|
||||||
|
case 0:
|
||||||
|
c = "PASS";
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var c = "FAIL";
|
||||||
|
(function() {
|
||||||
|
var a = 0;
|
||||||
|
switch (a = { b: 0 }, a.b) {
|
||||||
|
case 0:
|
||||||
|
c = "PASS";
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
console.log(c);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -642,3 +642,41 @@ issue_3065_4: {
|
|||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3325_1: {
|
||||||
|
options = {
|
||||||
|
pure_funcs: "cb",
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function cb() {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function cb() {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3325_2: {
|
||||||
|
options = {
|
||||||
|
pure_funcs: "xxxcbxxx",
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function cb() {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function cb() {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -281,8 +281,8 @@ unsafe_evaluate_escaped: {
|
|||||||
console.log(function(){ var o={p:3},a=[o]; console.log(a[0].p++); return o.p; }());
|
console.log(function(){ var o={p:3},a=[o]; console.log(a[0].p++); return o.p; }());
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(function(){ var o={p:1}; console.log(o, o.p); return o.p; }());
|
console.log(function(){ var o={p:1}; console.log(o, 1); return o.p; }());
|
||||||
console.log(function(){ var o={p:2}; console.log(o.p, o); return o.p; }());
|
console.log(function(){ var o={p:2}; console.log(2, o); return o.p; }());
|
||||||
console.log(function(){ var o={p:3},a=[o]; console.log(a[0].p++); return o.p; }());
|
console.log(function(){ var o={p:3},a=[o]; console.log(a[0].p++); return o.p; }());
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
@@ -2740,18 +2740,18 @@ issue_1814_2: {
|
|||||||
!function() {
|
!function() {
|
||||||
var b = a + 1;
|
var b = a + 1;
|
||||||
!function(a) {
|
!function(a) {
|
||||||
console.log(a++, b);
|
console.log(b, a++);
|
||||||
}(0);
|
}(0);
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
!function() {
|
!function() {
|
||||||
!function(a) {
|
!function(a) {
|
||||||
console.log(a++, "321");
|
console.log("321", a++);
|
||||||
}(0);
|
}(0);
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
expect_stdout: "0 '321'"
|
expect_stdout: "321 0"
|
||||||
}
|
}
|
||||||
|
|
||||||
try_abort: {
|
try_abort: {
|
||||||
@@ -5231,11 +5231,11 @@ defun_catch_4: {
|
|||||||
try {
|
try {
|
||||||
throw 42;
|
throw 42;
|
||||||
} catch (a) {
|
} catch (a) {
|
||||||
function a() {}
|
|
||||||
console.log(a);
|
console.log(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: "42"
|
||||||
|
node_version: "<=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
defun_catch_5: {
|
defun_catch_5: {
|
||||||
@@ -5257,10 +5257,10 @@ defun_catch_5: {
|
|||||||
throw 42;
|
throw 42;
|
||||||
} catch (a) {
|
} catch (a) {
|
||||||
console.log(a);
|
console.log(a);
|
||||||
function a() {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: "42"
|
||||||
|
node_version: "<=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
defun_catch_6: {
|
defun_catch_6: {
|
||||||
@@ -5354,6 +5354,7 @@ issue_2774: {
|
|||||||
|
|
||||||
issue_2799_1: {
|
issue_2799_1: {
|
||||||
options = {
|
options = {
|
||||||
|
passes: 2,
|
||||||
reduce_funcs: true,
|
reduce_funcs: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
unused: true,
|
unused: true,
|
||||||
@@ -6429,3 +6430,328 @@ issue_3140_5: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "1"
|
expect_stdout: "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3240_1: {
|
||||||
|
options = {
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
f(1);
|
||||||
|
function f(a) {
|
||||||
|
console.log(a);
|
||||||
|
var g = function() {
|
||||||
|
f(a - 1);
|
||||||
|
};
|
||||||
|
if (a) g();
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
(function f(a) {
|
||||||
|
console.log(a);
|
||||||
|
var g = function() {
|
||||||
|
f(a - 1);
|
||||||
|
};
|
||||||
|
if (a) g();
|
||||||
|
})(1);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"1",
|
||||||
|
"0",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3240_2: {
|
||||||
|
options = {
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
f(1);
|
||||||
|
function f(a) {
|
||||||
|
console.log(a);
|
||||||
|
var g = function() {
|
||||||
|
f(a - 1);
|
||||||
|
};
|
||||||
|
if (a) g();
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
(function f(a) {
|
||||||
|
console.log(a);
|
||||||
|
if (a) (function() {
|
||||||
|
f(a - 1);
|
||||||
|
})();
|
||||||
|
})(1);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"1",
|
||||||
|
"0",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3240_3: {
|
||||||
|
options = {
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
f();
|
||||||
|
function f(b) {
|
||||||
|
if (!f.a) f.a = 0;
|
||||||
|
console.log(f.a.toString());
|
||||||
|
var g = function() {
|
||||||
|
(b ? function() {} : function() {
|
||||||
|
f.a++;
|
||||||
|
f(1);
|
||||||
|
})();
|
||||||
|
};
|
||||||
|
g();
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
(function f(b) {
|
||||||
|
if (!f.a) f.a = 0;
|
||||||
|
console.log(f.a.toString());
|
||||||
|
var g = function() {
|
||||||
|
(b ? function() {} : function() {
|
||||||
|
f.a++;
|
||||||
|
f(1);
|
||||||
|
})();
|
||||||
|
};
|
||||||
|
g();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0",
|
||||||
|
"1",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3240_4: {
|
||||||
|
options = {
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
f();
|
||||||
|
function f(b) {
|
||||||
|
if (!f.a) f.a = 0;
|
||||||
|
console.log(f.a.toString());
|
||||||
|
var g = function() {
|
||||||
|
(b ? function() {} : function() {
|
||||||
|
f.a++;
|
||||||
|
f(1);
|
||||||
|
})();
|
||||||
|
};
|
||||||
|
g();
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
(function f(b) {
|
||||||
|
if (!f.a) f.a = 0;
|
||||||
|
console.log(f.a.toString());
|
||||||
|
(function() {
|
||||||
|
(b ? function() {} : function() {
|
||||||
|
f.a++;
|
||||||
|
f(1);
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"0",
|
||||||
|
"1",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issues_3267_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(x) {
|
||||||
|
x();
|
||||||
|
})(function() {
|
||||||
|
(function(i) {
|
||||||
|
if (i)
|
||||||
|
return console.log("PASS");
|
||||||
|
throw "FAIL";
|
||||||
|
})(Object());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function(i) {
|
||||||
|
if (i)
|
||||||
|
return console.log("PASS");
|
||||||
|
throw "FAIL";
|
||||||
|
}(Object());
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issues_3267_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
keep_fargs: false,
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(x) {
|
||||||
|
x();
|
||||||
|
})(function() {
|
||||||
|
(function(i) {
|
||||||
|
if (i)
|
||||||
|
return console.log("PASS");
|
||||||
|
throw "FAIL";
|
||||||
|
})(Object());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
!function() {
|
||||||
|
if (Object())
|
||||||
|
return console.log("PASS");
|
||||||
|
throw "FAIL";
|
||||||
|
}();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issues_3267_3: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
conditionals: true,
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
inline: true,
|
||||||
|
keep_fargs: false,
|
||||||
|
passes: 2,
|
||||||
|
reduce_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
unsafe: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(x) {
|
||||||
|
x();
|
||||||
|
})(function() {
|
||||||
|
(function(i) {
|
||||||
|
if (i)
|
||||||
|
return console.log("PASS");
|
||||||
|
throw "FAIL";
|
||||||
|
})(Object());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3297: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
function f() {
|
||||||
|
var a;
|
||||||
|
var b = function a() {
|
||||||
|
console.log(a === b) && f();
|
||||||
|
};
|
||||||
|
b();
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
(function f() {
|
||||||
|
var b = function a() {
|
||||||
|
console.log(a === b) && f();
|
||||||
|
};
|
||||||
|
b();
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_side_effect_free: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 123;
|
||||||
|
"" + (a && (a.b = 0) || a);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 123;
|
||||||
|
a.b = 0;
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "123"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3377: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function f() {
|
||||||
|
return f[0], (f = 42);
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(function f() {
|
||||||
|
return f[0], (f = 42);
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
}
|
||||||
|
|||||||
@@ -534,3 +534,80 @@ function_catch_catch_ie8: {
|
|||||||
"undefined",
|
"undefined",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function_do_catch_ie8: {
|
||||||
|
rename = true
|
||||||
|
options = {
|
||||||
|
ie8: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 1, b = 1, c = 0;
|
||||||
|
function d(e) {
|
||||||
|
var f, g, h, i;
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
var j = function q(){}();
|
||||||
|
} catch (r) {
|
||||||
|
--a && w("ddddddddeeeeeeegggggggggiiiiilllllllnnnnntuuuuuuuuyyyyyyy");
|
||||||
|
var k, l, m, n, o;
|
||||||
|
--m;
|
||||||
|
--n;
|
||||||
|
--o;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
i[1];
|
||||||
|
} catch (s) {
|
||||||
|
var p;
|
||||||
|
switch (function t() {
|
||||||
|
c++;
|
||||||
|
}()) {
|
||||||
|
case j + --p:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (u) {}
|
||||||
|
} while (--i);
|
||||||
|
b--;
|
||||||
|
}
|
||||||
|
d();
|
||||||
|
console.log(b, c);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var t = 1, u = 1, y = 0;
|
||||||
|
function c(c) {
|
||||||
|
var d;
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
var e = void 0;
|
||||||
|
} catch (i) {
|
||||||
|
--t && w("ddddddddeeeeeeegggggggggiiiiilllllllnnnnntuuuuuuuuyyyyyyy");
|
||||||
|
0;
|
||||||
|
0;
|
||||||
|
0;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
d[1];
|
||||||
|
} catch (l) {
|
||||||
|
var g;
|
||||||
|
switch(function x() {
|
||||||
|
y++;
|
||||||
|
}()) {
|
||||||
|
case e + --g:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (n) {}
|
||||||
|
} while (--d);
|
||||||
|
u--;
|
||||||
|
}
|
||||||
|
c();
|
||||||
|
console.log(u, y);
|
||||||
|
}
|
||||||
|
expect_stdout: "0 1"
|
||||||
|
}
|
||||||
|
|||||||
@@ -702,7 +702,7 @@ side_effects_cascade_3: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f(a, b) {
|
function f(a, b) {
|
||||||
!(b += a) && ((b = a) || (b -= a, b ^= a)),
|
(b += a) || (b = a) || (b -= a, b ^= a),
|
||||||
a--;
|
a--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -924,14 +924,14 @@ call: {
|
|||||||
b.c = function() {
|
b.c = function() {
|
||||||
console.log(this === b ? "bar" : "baz");
|
console.log(this === b ? "bar" : "baz");
|
||||||
},
|
},
|
||||||
a, b(),
|
b(),
|
||||||
(a, b.c)(),
|
(a, b.c)(),
|
||||||
a, function() {
|
function() {
|
||||||
console.log(this === a);
|
console.log(this === a);
|
||||||
}(),
|
}(),
|
||||||
a, new b(),
|
new b(),
|
||||||
a, new b.c(),
|
new b.c(),
|
||||||
a, new function() {
|
new function() {
|
||||||
console.log(this === a);
|
console.log(this === a);
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
@@ -944,3 +944,59 @@ call: {
|
|||||||
"false",
|
"false",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
missing_link: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
evaluate: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 100;
|
||||||
|
a;
|
||||||
|
a++ + (0 ? 2 : 1);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 100;
|
||||||
|
a,
|
||||||
|
a++,
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
angularjs_chain: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function nonComputedMember(left, right, context, create) {
|
||||||
|
var lhs = left();
|
||||||
|
if (create && create !== 1) {
|
||||||
|
if (lhs && lhs[right] == null) {
|
||||||
|
lhs[right] = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var value = lhs != null ? lhs[right] : undefined;
|
||||||
|
if (context) {
|
||||||
|
return { context: lhs, name: right, value: value };
|
||||||
|
} else {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function nonComputedMember(left, right, context, create) {
|
||||||
|
var lhs = left();
|
||||||
|
create && 1 !== create && lhs && null == lhs[right] && (lhs[right] = {});
|
||||||
|
var value = null != lhs ? lhs[right] : void 0;
|
||||||
|
return context ? {
|
||||||
|
context: lhs,
|
||||||
|
name: right,
|
||||||
|
value: value
|
||||||
|
} : value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
109
test/compress/webkit.js
Normal file
109
test/compress/webkit.js
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
lambda_call_dot_assign: {
|
||||||
|
beautify = {
|
||||||
|
webkit: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
return {};
|
||||||
|
}().a = 1);
|
||||||
|
}
|
||||||
|
expect_exact: "console.log(function(){return{}}().a=1);"
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
lambda_call_dot_assign_webkit: {
|
||||||
|
beautify = {
|
||||||
|
webkit: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
return {};
|
||||||
|
}().a = 1);
|
||||||
|
}
|
||||||
|
expect_exact: "console.log((function(){return{}}()).a=1);"
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
lambda_dot_assign: {
|
||||||
|
beautify = {
|
||||||
|
webkit: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
1 + 1;
|
||||||
|
}.a = 1);
|
||||||
|
}
|
||||||
|
expect_exact: "console.log(function(){1+1}.a=1);"
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
lambda_dot_assign_webkit: {
|
||||||
|
beautify = {
|
||||||
|
webkit: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function() {
|
||||||
|
1 + 1;
|
||||||
|
}.a = 1);
|
||||||
|
}
|
||||||
|
expect_exact: "console.log((function(){1+1}).a=1);"
|
||||||
|
expect_stdout: "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
lambda_name_mangle: {
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
console.log(typeof function foo(bar) {});
|
||||||
|
}
|
||||||
|
expect_exact: "console.log(typeof function o(n){});"
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
|
|
||||||
|
lambda_name_mangle_ie8: {
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(typeof function foo(bar) {});
|
||||||
|
}
|
||||||
|
expect_exact: "console.log(typeof function n(o){});"
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
|
|
||||||
|
function_name_mangle: {
|
||||||
|
options = {
|
||||||
|
keep_fnames: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
function foo(bar) {}
|
||||||
|
console.log(typeof foo);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_exact: "(function(){console.log(typeof function o(n){})})();"
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
|
|
||||||
|
function_name_mangle_ie8: {
|
||||||
|
options = {
|
||||||
|
keep_fnames: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
ie8: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
function foo(bar) {}
|
||||||
|
console.log(typeof foo);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_exact: "(function(){console.log(typeof function n(o){})})();"
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
exports["Compressor"] = Compressor;
|
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["defaults"] = defaults;
|
||||||
|
exports["JS_Parse_Error"] = JS_Parse_Error;
|
||||||
exports["mangle_properties"] = mangle_properties;
|
exports["mangle_properties"] = mangle_properties;
|
||||||
exports["minify"] = minify;
|
exports["minify"] = minify;
|
||||||
|
exports["OutputStream"] = OutputStream;
|
||||||
exports["parse"] = parse;
|
exports["parse"] = parse;
|
||||||
|
exports["push_uniq"] = push_uniq;
|
||||||
exports["reserve_quoted_keys"] = reserve_quoted_keys;
|
exports["reserve_quoted_keys"] = reserve_quoted_keys;
|
||||||
exports["string_template"] = string_template;
|
exports["string_template"] = string_template;
|
||||||
exports["tokenizer"] = tokenizer;
|
exports["tokenizer"] = tokenizer;
|
||||||
exports["is_identifier"] = is_identifier;
|
exports["TreeTransformer"] = TreeTransformer;
|
||||||
|
exports["TreeWalker"] = TreeWalker;
|
||||||
|
|||||||
@@ -23,10 +23,9 @@ module.exports = function(url, callback) {
|
|||||||
var options = parse(url);
|
var options = parse(url);
|
||||||
options.rejectUnauthorized = false;
|
options.rejectUnauthorized = false;
|
||||||
require(options.protocol.slice(0, -1)).get(options, function(res) {
|
require(options.protocol.slice(0, -1)).get(options, function(res) {
|
||||||
if (res.statusCode !== 200) return callback(res);
|
if (res.statusCode !== 200) return callback(res.statusCode);
|
||||||
res.pipe(fs.createWriteStream(local(url)).on("close", function() {
|
res.pipe(fs.createWriteStream(local(url)));
|
||||||
callback(null, read(url));
|
callback(null, res);
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
}).on("open", function() {
|
}).on("open", function() {
|
||||||
callback(null, result);
|
callback(null, result);
|
||||||
|
|||||||
8
test/input/issue-3315/config.json
Normal file
8
test/input/issue-3315/config.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"compress": false,
|
||||||
|
"mangle": {
|
||||||
|
"properties": {
|
||||||
|
"regex": "/^_/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
test/input/issue-3315/input.js
Normal file
8
test/input/issue-3315/input.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
function f() {
|
||||||
|
"aaaaaaaaaa";
|
||||||
|
var o = {
|
||||||
|
prop: 1,
|
||||||
|
_int: 2,
|
||||||
|
};
|
||||||
|
return o.prop + o._int;
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var site = "https://browserbench.org/JetStream";
|
var site = "https://browserbench.org/JetStream1.1";
|
||||||
if (typeof phantom == "undefined") {
|
if (typeof phantom == "undefined") {
|
||||||
require("../tools/exit");
|
require("../tools/exit");
|
||||||
var args = process.argv.slice(2);
|
var args = process.argv.slice(2);
|
||||||
@@ -25,7 +25,11 @@ if (typeof phantom == "undefined") {
|
|||||||
request.resume();
|
request.resume();
|
||||||
var url = site + request.url;
|
var url = site + request.url;
|
||||||
fetch(url, function(err, res) {
|
fetch(url, function(err, res) {
|
||||||
if (err) throw err;
|
if (err) {
|
||||||
|
if (typeof err != "number") throw err;
|
||||||
|
response.writeHead(err);
|
||||||
|
response.end();
|
||||||
|
} else {
|
||||||
response.writeHead(200, {
|
response.writeHead(200, {
|
||||||
"Content-Type": {
|
"Content-Type": {
|
||||||
css: "text/css",
|
css: "text/css",
|
||||||
@@ -50,6 +54,7 @@ if (typeof phantom == "undefined") {
|
|||||||
} else {
|
} else {
|
||||||
res.pipe(response);
|
res.pipe(response);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}).listen();
|
}).listen();
|
||||||
server.on("listening", function() {
|
server.on("listening", function() {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var exec = require("child_process").exec;
|
var exec = require("child_process").exec;
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
var run_code = require("../sandbox").run_code;
|
||||||
|
|
||||||
function read(path) {
|
function read(path) {
|
||||||
return fs.readFileSync(path, "utf8");
|
return fs.readFileSync(path, "utf8");
|
||||||
@@ -257,7 +258,7 @@ describe("bin/uglifyjs", function() {
|
|||||||
assert.strictEqual(lines[0], "Parse error at test/input/invalid/simple.js:1,12");
|
assert.strictEqual(lines[0], "Parse error at test/input/invalid/simple.js:1,12");
|
||||||
assert.strictEqual(lines[1], "function f(a{}");
|
assert.strictEqual(lines[1], "function f(a{}");
|
||||||
assert.strictEqual(lines[2], " ^");
|
assert.strictEqual(lines[2], " ^");
|
||||||
assert.strictEqual(lines[3], "ERROR: Unexpected token punc «{», expected punc «,»");
|
assert.strictEqual(lines[3], "ERROR: Unexpected token: punc «{», expected: punc «,»");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -281,7 +282,7 @@ describe("bin/uglifyjs", function() {
|
|||||||
assert.strictEqual(lines[0], "Parse error at test/input/invalid/eof.js:2,0");
|
assert.strictEqual(lines[0], "Parse error at test/input/invalid/eof.js:2,0");
|
||||||
assert.strictEqual(lines[1], "foo, bar(");
|
assert.strictEqual(lines[1], "foo, bar(");
|
||||||
assert.strictEqual(lines[2], " ^");
|
assert.strictEqual(lines[2], " ^");
|
||||||
assert.strictEqual(lines[3], "ERROR: Unexpected token: eof (undefined)");
|
assert.strictEqual(lines[3], "ERROR: Unexpected token: eof");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -293,7 +294,7 @@ describe("bin/uglifyjs", function() {
|
|||||||
assert.strictEqual(lines[0], "Parse error at test/input/invalid/loop-no-body.js:2,0");
|
assert.strictEqual(lines[0], "Parse error at test/input/invalid/loop-no-body.js:2,0");
|
||||||
assert.strictEqual(lines[1], "for (var i = 0; i < 1; i++) ");
|
assert.strictEqual(lines[1], "for (var i = 0; i < 1; i++) ");
|
||||||
assert.strictEqual(lines[2], " ^");
|
assert.strictEqual(lines[2], " ^");
|
||||||
assert.strictEqual(lines[3], "ERROR: Unexpected token: eof (undefined)");
|
assert.strictEqual(lines[3], "ERROR: Unexpected token: eof");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -362,7 +363,7 @@ describe("bin/uglifyjs", function() {
|
|||||||
"Parse error at test/input/invalid/dot_1.js:1,2",
|
"Parse error at test/input/invalid/dot_1.js:1,2",
|
||||||
"a.=",
|
"a.=",
|
||||||
" ^",
|
" ^",
|
||||||
"ERROR: Unexpected token: operator (=)"
|
"ERROR: Unexpected token: operator «=», expected: name"
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -376,7 +377,7 @@ describe("bin/uglifyjs", function() {
|
|||||||
"Parse error at test/input/invalid/dot_2.js:1,0",
|
"Parse error at test/input/invalid/dot_2.js:1,0",
|
||||||
"%.a;",
|
"%.a;",
|
||||||
"^",
|
"^",
|
||||||
"ERROR: Unexpected token: operator (%)"
|
"ERROR: Unexpected token: operator «%»"
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -390,7 +391,7 @@ describe("bin/uglifyjs", function() {
|
|||||||
"Parse error at test/input/invalid/dot_3.js:1,2",
|
"Parse error at test/input/invalid/dot_3.js:1,2",
|
||||||
"a./();",
|
"a./();",
|
||||||
" ^",
|
" ^",
|
||||||
"ERROR: Unexpected token: operator (/)"
|
"ERROR: Unexpected token: operator «/», expected: name"
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -404,7 +405,7 @@ describe("bin/uglifyjs", function() {
|
|||||||
"Parse error at test/input/invalid/object.js:1,13",
|
"Parse error at test/input/invalid/object.js:1,13",
|
||||||
"console.log({%: 1});",
|
"console.log({%: 1});",
|
||||||
" ^",
|
" ^",
|
||||||
"ERROR: Unexpected token: operator (%)"
|
"ERROR: Unexpected token: operator «%»"
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -502,7 +503,7 @@ describe("bin/uglifyjs", function() {
|
|||||||
"Parse error at test/input/invalid/else.js:1,7",
|
"Parse error at test/input/invalid/else.js:1,7",
|
||||||
"if (0) else 1;",
|
"if (0) else 1;",
|
||||||
" ^",
|
" ^",
|
||||||
"ERROR: Unexpected token: keyword (else)"
|
"ERROR: Unexpected token: keyword «else»"
|
||||||
].join("\n"));
|
].join("\n"));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -633,6 +634,14 @@ describe("bin/uglifyjs", function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
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";
|
||||||
|
exec(command, function(err, stdout) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(stdout, 'function f(){"aaaaaaaaaa";var a={prop:1,a:2};return a.prop+a.a}\n');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
it("Should fail with --define a-b", function(done) {
|
it("Should fail with --define a-b", function(done) {
|
||||||
var command = uglifyjscmd + " test/input/issue-505/input.js --define a-b";
|
var command = uglifyjscmd + " test/input/issue-505/input.js --define a-b";
|
||||||
exec(command, function(err, stdout, stderr) {
|
exec(command, function(err, stdout, stderr) {
|
||||||
@@ -651,7 +660,7 @@ describe("bin/uglifyjs", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("Should work with explicit --no-rename", function(done) {
|
it("Should work with explicit --no-rename", function(done) {
|
||||||
var command = uglifyjscmd + " test/input/rename/input.js -mc --no-rename";
|
var command = uglifyjscmd + " test/input/rename/input.js -mc passes=2 --no-rename";
|
||||||
exec(command, function(err, stdout, stderr) {
|
exec(command, function(err, stdout, stderr) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(stdout, "function f(n){return function(n){return n}(n)}\n");
|
assert.strictEqual(stdout, "function f(n){return function(n){return n}(n)}\n");
|
||||||
@@ -659,7 +668,7 @@ describe("bin/uglifyjs", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("Should work with implicit --rename", function(done) {
|
it("Should work with implicit --rename", function(done) {
|
||||||
var command = uglifyjscmd + " test/input/rename/input.js -mc";
|
var command = uglifyjscmd + " test/input/rename/input.js -mc passes=2";
|
||||||
exec(command, function(err, stdout, stderr) {
|
exec(command, function(err, stdout, stderr) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(stdout, "function f(n){return n}\n");
|
assert.strictEqual(stdout, "function f(n){return n}\n");
|
||||||
@@ -667,7 +676,7 @@ describe("bin/uglifyjs", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("Should work with implicit --no-rename", function(done) {
|
it("Should work with implicit --no-rename", function(done) {
|
||||||
var command = uglifyjscmd + " test/input/rename/input.js -c";
|
var command = uglifyjscmd + " test/input/rename/input.js -c passes=2";
|
||||||
exec(command, function(err, stdout, stderr) {
|
exec(command, function(err, stdout, stderr) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(stdout, "function f(x){return function(x){return x}(x)}\n");
|
assert.strictEqual(stdout, "function f(x){return function(x){return x}(x)}\n");
|
||||||
@@ -706,4 +715,32 @@ describe("bin/uglifyjs", function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it("Should compress swarm of unused variables with reasonable performance", function(done) {
|
||||||
|
var code = [
|
||||||
|
"console.log(function() {",
|
||||||
|
];
|
||||||
|
for (var i = 0; i < 10000; i++) {
|
||||||
|
code.push("var obj" + i + " = {p: " + i + "};");
|
||||||
|
}
|
||||||
|
code.push("var map = {");
|
||||||
|
for (var i = 0; i < 10000; i++) {
|
||||||
|
code.push("obj" + i + ": obj" + i + ",");
|
||||||
|
}
|
||||||
|
code = code.concat([
|
||||||
|
"};",
|
||||||
|
"return obj25.p + obj121.p + obj1024.p;",
|
||||||
|
"}());",
|
||||||
|
]).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(run_code(stdout), run_code(code));
|
||||||
|
done();
|
||||||
|
}).stdin.end(code);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ describe("comments", function() {
|
|||||||
|
|
||||||
var fail = function(e) {
|
var fail = function(e) {
|
||||||
return e instanceof UglifyJS.JS_Parse_Error
|
return e instanceof UglifyJS.JS_Parse_Error
|
||||||
&& e.message === "Unexpected token: operator (>)"
|
&& e.message === "Unexpected token: operator «>»"
|
||||||
&& e.line === 2
|
&& e.line === 2
|
||||||
&& e.col === 0;
|
&& e.col === 0;
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ describe("comments", function() {
|
|||||||
|
|
||||||
var fail = function(e) {
|
var fail = function(e) {
|
||||||
return e instanceof UglifyJS.JS_Parse_Error
|
return e instanceof UglifyJS.JS_Parse_Error
|
||||||
&& e.message === "Unexpected token: operator (>)"
|
&& e.message === "Unexpected token: operator «>»"
|
||||||
&& e.line === 5
|
&& e.line === 5
|
||||||
&& e.col === 0;
|
&& e.col === 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ describe("Directives", function() {
|
|||||||
UglifyJS.parse(tokenizer);
|
UglifyJS.parse(tokenizer);
|
||||||
}, function(e) {
|
}, function(e) {
|
||||||
return e instanceof UglifyJS.JS_Parse_Error
|
return e instanceof UglifyJS.JS_Parse_Error
|
||||||
&& e.message === "Unexpected token: punc (])"
|
&& /^Unexpected token: punc «]»/.test(e.message)
|
||||||
}, test[0]);
|
}, test[0]);
|
||||||
test[1].forEach(function(directive) {
|
test[1].forEach(function(directive) {
|
||||||
assert.strictEqual(tokenizer.has_directive(directive), true, directive + " in " + test[0]);
|
assert.strictEqual(tokenizer.has_directive(directive), true, directive + " in " + test[0]);
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ describe("Getters and setters", function() {
|
|||||||
var fail = function(data) {
|
var fail = function(data) {
|
||||||
return function(e) {
|
return function(e) {
|
||||||
return e instanceof UglifyJS.JS_Parse_Error
|
return e instanceof UglifyJS.JS_Parse_Error
|
||||||
&& e.message === "Unexpected token: operator (" + data.operator + ")";
|
&& e.message === "Unexpected token: operator «" + data.operator + "»";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
var errorMessage = function(data) {
|
var errorMessage = function(data) {
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ describe("minify", function() {
|
|||||||
assert.strictEqual(run_code(compressed), run_code(original));
|
assert.strictEqual(run_code(compressed), run_code(original));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should avoid mangled names in cache", function() {
|
it("Should avoid cached names when mangling top-level variables", function() {
|
||||||
var cache = {};
|
var cache = {};
|
||||||
var original = "";
|
var original = "";
|
||||||
var compressed = "";
|
var compressed = "";
|
||||||
@@ -116,10 +116,34 @@ describe("minify", function() {
|
|||||||
assert.strictEqual(run_code(compressed), run_code(original));
|
assert.strictEqual(run_code(compressed), run_code(original));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Should avoid cached names when mangling inner-scoped variables", function() {
|
||||||
|
var cache = {};
|
||||||
|
var original = "";
|
||||||
|
var compressed = "";
|
||||||
|
[
|
||||||
|
'var extend = function(a, b) { console.log("extend"); a(); b(); }; function A() { console.log("A"); };',
|
||||||
|
'var B = function(A) { function B() { console.log("B") }; extend(B, A); return B; }(A);',
|
||||||
|
].forEach(function(code) {
|
||||||
|
var result = UglifyJS.minify(code, {
|
||||||
|
compress: false,
|
||||||
|
nameCache: cache,
|
||||||
|
toplevel: true,
|
||||||
|
});
|
||||||
|
if (result.error) throw result.error;
|
||||||
|
original += code;
|
||||||
|
compressed += result.code;
|
||||||
|
});
|
||||||
|
assert.strictEqual(compressed, [
|
||||||
|
'var o=function(o,n){console.log("extend");o();n()};function n(){console.log("A")}',
|
||||||
|
'var e=function(n){function e(){console.log("B")}o(e,n);return e}(n);',
|
||||||
|
].join(""));
|
||||||
|
assert.strictEqual(run_code(compressed), run_code(original));
|
||||||
|
});
|
||||||
|
|
||||||
it("Should not parse invalid use of reserved words", function() {
|
it("Should not parse invalid use of reserved words", function() {
|
||||||
assert.strictEqual(UglifyJS.minify("function enum(){}").error, undefined);
|
assert.strictEqual(UglifyJS.minify("function enum(){}").error, undefined);
|
||||||
assert.strictEqual(UglifyJS.minify("function static(){}").error, undefined);
|
assert.strictEqual(UglifyJS.minify("function static(){}").error, undefined);
|
||||||
assert.strictEqual(UglifyJS.minify("function this(){}").error.message, "Unexpected token: name (this)");
|
assert.strictEqual(UglifyJS.minify("function this(){}").error.message, "Unexpected token: name «this»");
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("keep_quoted_props", function() {
|
describe("keep_quoted_props", function() {
|
||||||
@@ -214,7 +238,7 @@ describe("minify", function() {
|
|||||||
var result = UglifyJS.minify("function f(a{}");
|
var result = UglifyJS.minify("function f(a{}");
|
||||||
var err = result.error;
|
var err = result.error;
|
||||||
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);
|
||||||
@@ -241,7 +265,7 @@ describe("minify", function() {
|
|||||||
});
|
});
|
||||||
var err = result.error;
|
var err = result.error;
|
||||||
assert.ok(err instanceof Error);
|
assert.ok(err instanceof Error);
|
||||||
assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: Unexpected token: keyword (debugger)");
|
assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: Unexpected token: keyword «debugger»");
|
||||||
});
|
});
|
||||||
it("Should skip inherited properties", function() {
|
it("Should skip inherited properties", function() {
|
||||||
var foo = Object.create({ skip: this });
|
var foo = Object.create({ skip: this });
|
||||||
|
|||||||
@@ -23,68 +23,200 @@ require("./mocha.js");
|
|||||||
|
|
||||||
/* -----[ utils ]----- */
|
/* -----[ utils ]----- */
|
||||||
|
|
||||||
function tmpl() {
|
function evaluate(code) {
|
||||||
return U.string_template.apply(this, arguments);
|
if (code instanceof U.AST_Node) code = make_code(code, { beautify: true });
|
||||||
|
return new Function("return(" + code + ")")();
|
||||||
}
|
}
|
||||||
|
|
||||||
function log() {
|
function log() {
|
||||||
var txt = tmpl.apply(this, arguments);
|
console.log("%s", tmpl.apply(null, arguments));
|
||||||
console.log("%s", txt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function log_directory(dir) {
|
function make_code(ast, options) {
|
||||||
log("*** Entering [{dir}]", { dir: dir });
|
var stream = U.OutputStream(options);
|
||||||
|
ast.print(stream);
|
||||||
|
return stream.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
function log_start_file(file) {
|
function parse_test(file) {
|
||||||
log("--- {file}", { file: file });
|
var script = fs.readFileSync(file, "utf8");
|
||||||
}
|
// TODO try/catch can be removed after fixing https://github.com/mishoo/UglifyJS2/issues/348
|
||||||
|
try {
|
||||||
function log_test(name) {
|
var ast = U.parse(script, {
|
||||||
log(" Running test [{name}]", { name: name });
|
filename: file
|
||||||
}
|
|
||||||
|
|
||||||
function find_test_files(dir) {
|
|
||||||
return fs.readdirSync(dir).filter(function(name) {
|
|
||||||
return /\.js$/i.test(name);
|
|
||||||
});
|
});
|
||||||
}
|
} catch (e) {
|
||||||
|
console.log("Caught error while parsing tests in " + file + "\n");
|
||||||
function test_directory(dir) {
|
console.log(e);
|
||||||
return path.resolve(tests_dir, dir);
|
throw e;
|
||||||
}
|
|
||||||
|
|
||||||
function as_toplevel(input, mangle_options) {
|
|
||||||
if (!(input instanceof U.AST_BlockStatement))
|
|
||||||
throw new Error("Unsupported input syntax");
|
|
||||||
for (var i = 0; i < input.body.length; i++) {
|
|
||||||
var stat = input.body[i];
|
|
||||||
if (stat instanceof U.AST_SimpleStatement && stat.body instanceof U.AST_String)
|
|
||||||
input.body[i] = new U.AST_Directive(stat.body);
|
|
||||||
else break;
|
|
||||||
}
|
}
|
||||||
var toplevel = new U.AST_Toplevel(input);
|
var tests = {};
|
||||||
toplevel.figure_out_scope(mangle_options);
|
var tw = new U.TreeWalker(function(node, descend) {
|
||||||
return toplevel;
|
if (node instanceof U.AST_LabeledStatement
|
||||||
|
&& tw.parent() instanceof U.AST_Toplevel) {
|
||||||
|
var name = node.label.name;
|
||||||
|
if (name in tests) {
|
||||||
|
throw new Error('Duplicated test name "' + name + '" in ' + file);
|
||||||
|
}
|
||||||
|
tests[name] = get_one_test(name, node.body);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!(node instanceof U.AST_Toplevel)) croak(node);
|
||||||
|
});
|
||||||
|
ast.walk(tw);
|
||||||
|
return tests;
|
||||||
|
|
||||||
|
function croak(node) {
|
||||||
|
throw new Error(tmpl("Can't understand test file {file} [{line},{col}]\n{code}", {
|
||||||
|
file: file,
|
||||||
|
line: node.start.line,
|
||||||
|
col: node.start.col,
|
||||||
|
code: make_code(node, { beautify: false })
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
function read_string(stat) {
|
||||||
|
if (stat.TYPE == "SimpleStatement") {
|
||||||
|
var body = stat.body;
|
||||||
|
switch(body.TYPE) {
|
||||||
|
case "String":
|
||||||
|
return body.value;
|
||||||
|
case "Array":
|
||||||
|
return body.elements.map(function(element) {
|
||||||
|
if (element.TYPE !== "String")
|
||||||
|
throw new Error("Should be array of strings");
|
||||||
|
return element.value;
|
||||||
|
}).join("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error("Should be string or array of strings");
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_one_test(name, block) {
|
||||||
|
var test = { name: name, options: {} };
|
||||||
|
var tw = new U.TreeWalker(function(node, descend) {
|
||||||
|
if (node instanceof U.AST_Assign) {
|
||||||
|
if (!(node.left instanceof U.AST_SymbolRef)) {
|
||||||
|
croak(node);
|
||||||
|
}
|
||||||
|
var name = node.left.name;
|
||||||
|
test[name] = evaluate(node.right);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (node instanceof U.AST_LabeledStatement) {
|
||||||
|
var label = node.label;
|
||||||
|
assert.ok([
|
||||||
|
"input",
|
||||||
|
"expect",
|
||||||
|
"expect_exact",
|
||||||
|
"expect_warnings",
|
||||||
|
"expect_stdout",
|
||||||
|
"node_version",
|
||||||
|
].indexOf(label.name) >= 0, tmpl("Unsupported label {name} [{line},{col}]", {
|
||||||
|
name: label.name,
|
||||||
|
line: label.start.line,
|
||||||
|
col: label.start.col
|
||||||
|
}));
|
||||||
|
var stat = node.body;
|
||||||
|
if (label.name == "expect_exact" || label.name == "node_version") {
|
||||||
|
test[label.name] = read_string(stat);
|
||||||
|
} else if (label.name == "expect_stdout") {
|
||||||
|
var body = stat.body;
|
||||||
|
if (body instanceof U.AST_Boolean) {
|
||||||
|
test[label.name] = body.value;
|
||||||
|
} else if (body instanceof U.AST_Call) {
|
||||||
|
var ctor = global[body.expression.name];
|
||||||
|
assert.ok(ctor === Error || ctor.prototype instanceof Error, tmpl("Unsupported expect_stdout format [{line},{col}]", {
|
||||||
|
line: label.start.line,
|
||||||
|
col: label.start.col
|
||||||
|
}));
|
||||||
|
test[label.name] = ctor.apply(null, body.args.map(function(node) {
|
||||||
|
assert.ok(node instanceof U.AST_Constant, tmpl("Unsupported expect_stdout format [{line},{col}]", {
|
||||||
|
line: label.start.line,
|
||||||
|
col: label.start.col
|
||||||
|
}));
|
||||||
|
return node.value;
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
test[label.name] = read_string(stat) + "\n";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
test[label.name] = stat;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
block.walk(tw);
|
||||||
|
return test;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to reminify original input with standard options
|
||||||
|
// to see if it matches expect_stdout.
|
||||||
|
function reminify(orig_options, input_code, input_formatted, expect_stdout) {
|
||||||
|
for (var i = 0; i < minify_options.length; i++) {
|
||||||
|
var options = JSON.parse(minify_options[i]);
|
||||||
|
if (options.compress) [
|
||||||
|
"keep_fargs",
|
||||||
|
"keep_fnames",
|
||||||
|
].forEach(function(name) {
|
||||||
|
if (name in orig_options) {
|
||||||
|
options.compress[name] = orig_options[name];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var options_formatted = JSON.stringify(options, null, 4);
|
||||||
|
var result = U.minify(input_code, options);
|
||||||
|
if (result.error) {
|
||||||
|
log("!!! failed input reminify\n---INPUT---\n{input}\n---OPTIONS---\n{options}\n--ERROR---\n{error}\n\n", {
|
||||||
|
input: input_formatted,
|
||||||
|
options: options_formatted,
|
||||||
|
error: result.error,
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
var stdout = run_code(result.code);
|
||||||
|
if (typeof expect_stdout != "string" && typeof stdout != "string" && expect_stdout.name == stdout.name) {
|
||||||
|
stdout = expect_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", {
|
||||||
|
input: input_formatted,
|
||||||
|
options: options_formatted,
|
||||||
|
output: result.code,
|
||||||
|
expected_type: typeof expect_stdout == "string" ? "STDOUT" : "ERROR",
|
||||||
|
expected: expect_stdout,
|
||||||
|
actual_type: typeof stdout == "string" ? "STDOUT" : "ERROR",
|
||||||
|
actual: stdout,
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function run_code(code) {
|
||||||
|
var result = sandbox.run_code(code, true);
|
||||||
|
return typeof result == "string" ? result.replace(/\u001b\[\d+m/g, "") : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function run_compress_tests() {
|
function run_compress_tests() {
|
||||||
var dir = test_directory("compress");
|
var dir = path.resolve(tests_dir, "compress");
|
||||||
log_directory("compress");
|
fs.readdirSync(dir).filter(function(name) {
|
||||||
var files = find_test_files(dir);
|
return /\.js$/i.test(name);
|
||||||
function test_file(file) {
|
}).forEach(function(file) {
|
||||||
log_start_file(file);
|
log("--- {file}", { file: file });
|
||||||
function test_case(test) {
|
function test_case(test) {
|
||||||
log_test(test.name);
|
log(" Running test [{name}]", { name: test.name });
|
||||||
var output_options = test.beautify || {};
|
var output_options = test.beautify || {};
|
||||||
var expect;
|
var expect;
|
||||||
if (test.expect) {
|
if (test.expect) {
|
||||||
expect = make_code(as_toplevel(test.expect, test.mangle), output_options);
|
expect = make_code(to_toplevel(test.expect, test.mangle), output_options);
|
||||||
} else {
|
} else {
|
||||||
expect = test.expect_exact;
|
expect = test.expect_exact;
|
||||||
}
|
}
|
||||||
var input = as_toplevel(test.input, test.mangle);
|
var input = to_toplevel(test.input, test.mangle);
|
||||||
var input_code = make_code(input, output_options);
|
var input_code = make_code(input);
|
||||||
var input_formatted = make_code(test.input, {
|
var input_formatted = make_code(test.input, {
|
||||||
beautify: true,
|
beautify: true,
|
||||||
quote_style: 3,
|
quote_style: 3,
|
||||||
@@ -209,185 +341,27 @@ function run_compress_tests() {
|
|||||||
failed_files[file] = 1;
|
failed_files[file] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
files.forEach(function(file) {
|
|
||||||
test_file(file);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse_test(file) {
|
function tmpl() {
|
||||||
var script = fs.readFileSync(file, "utf8");
|
return U.string_template.apply(null, arguments);
|
||||||
// TODO try/catch can be removed after fixing https://github.com/mishoo/UglifyJS2/issues/348
|
}
|
||||||
try {
|
|
||||||
var ast = U.parse(script, {
|
|
||||||
filename: file
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
console.log("Caught error while parsing tests in " + file + "\n");
|
|
||||||
console.log(e);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
var tests = {};
|
|
||||||
var tw = new U.TreeWalker(function(node, descend) {
|
|
||||||
if (node instanceof U.AST_LabeledStatement
|
|
||||||
&& tw.parent() instanceof U.AST_Toplevel) {
|
|
||||||
var name = node.label.name;
|
|
||||||
if (name in tests) {
|
|
||||||
throw new Error('Duplicated test name "' + name + '" in ' + file);
|
|
||||||
}
|
|
||||||
tests[name] = get_one_test(name, node.body);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!(node instanceof U.AST_Toplevel)) croak(node);
|
|
||||||
});
|
|
||||||
ast.walk(tw);
|
|
||||||
return tests;
|
|
||||||
|
|
||||||
function croak(node) {
|
function to_toplevel(input, mangle_options) {
|
||||||
throw new Error(tmpl("Can't understand test file {file} [{line},{col}]\n{code}", {
|
if (!(input instanceof U.AST_BlockStatement)) throw new Error("Unsupported input syntax");
|
||||||
file: file,
|
var directive = true;
|
||||||
line: node.start.line,
|
var offset = input.start.line;
|
||||||
col: node.start.col,
|
var tokens = [];
|
||||||
code: make_code(node, { beautify: false })
|
var toplevel = new U.AST_Toplevel(input.transform(new U.TreeTransformer(function(node) {
|
||||||
}));
|
if (U.push_uniq(tokens, node.start)) node.start.line -= offset;
|
||||||
}
|
if (!directive || node === input) return;
|
||||||
|
if (node instanceof U.AST_SimpleStatement && node.body instanceof U.AST_String) {
|
||||||
function read_string(stat) {
|
return new U.AST_Directive(node.body);
|
||||||
if (stat.TYPE == "SimpleStatement") {
|
|
||||||
var body = stat.body;
|
|
||||||
switch(body.TYPE) {
|
|
||||||
case "String":
|
|
||||||
return body.value;
|
|
||||||
case "Array":
|
|
||||||
return body.elements.map(function(element) {
|
|
||||||
if (element.TYPE !== "String")
|
|
||||||
throw new Error("Should be array of strings");
|
|
||||||
return element.value;
|
|
||||||
}).join("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new Error("Should be string or array of strings");
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_one_test(name, block) {
|
|
||||||
var test = { name: name, options: {} };
|
|
||||||
var tw = new U.TreeWalker(function(node, descend) {
|
|
||||||
if (node instanceof U.AST_Assign) {
|
|
||||||
if (!(node.left instanceof U.AST_SymbolRef)) {
|
|
||||||
croak(node);
|
|
||||||
}
|
|
||||||
var name = node.left.name;
|
|
||||||
test[name] = evaluate(node.right);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (node instanceof U.AST_LabeledStatement) {
|
|
||||||
var label = node.label;
|
|
||||||
assert.ok(
|
|
||||||
[
|
|
||||||
"input",
|
|
||||||
"expect",
|
|
||||||
"expect_exact",
|
|
||||||
"expect_warnings",
|
|
||||||
"expect_stdout",
|
|
||||||
"node_version",
|
|
||||||
].indexOf(label.name) >= 0,
|
|
||||||
tmpl("Unsupported label {name} [{line},{col}]", {
|
|
||||||
name: label.name,
|
|
||||||
line: label.start.line,
|
|
||||||
col: label.start.col
|
|
||||||
})
|
|
||||||
);
|
|
||||||
var stat = node.body;
|
|
||||||
if (label.name == "expect_exact" || label.name == "node_version") {
|
|
||||||
test[label.name] = read_string(stat);
|
|
||||||
} else if (label.name == "expect_stdout") {
|
|
||||||
var body = stat.body;
|
|
||||||
if (body instanceof U.AST_Boolean) {
|
|
||||||
test[label.name] = body.value;
|
|
||||||
} else if (body instanceof U.AST_Call) {
|
|
||||||
var ctor = global[body.expression.name];
|
|
||||||
assert.ok(ctor === Error || ctor.prototype instanceof Error, tmpl("Unsupported expect_stdout format [{line},{col}]", {
|
|
||||||
line: label.start.line,
|
|
||||||
col: label.start.col
|
|
||||||
}));
|
|
||||||
test[label.name] = ctor.apply(null, body.args.map(function(node) {
|
|
||||||
assert.ok(node instanceof U.AST_Constant, tmpl("Unsupported expect_stdout format [{line},{col}]", {
|
|
||||||
line: label.start.line,
|
|
||||||
col: label.start.col
|
|
||||||
}));
|
|
||||||
return node.value;
|
|
||||||
}));
|
|
||||||
} else {
|
} else {
|
||||||
test[label.name] = read_string(stat) + "\n";
|
directive = false;
|
||||||
}
|
}
|
||||||
} else {
|
})));
|
||||||
test[label.name] = stat;
|
toplevel.figure_out_scope(mangle_options);
|
||||||
}
|
return toplevel;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
block.walk(tw);
|
|
||||||
return test;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function make_code(ast, options) {
|
|
||||||
var stream = U.OutputStream(options);
|
|
||||||
ast.print(stream);
|
|
||||||
return stream.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
function evaluate(code) {
|
|
||||||
if (code instanceof U.AST_Node)
|
|
||||||
code = make_code(code, { beautify: true });
|
|
||||||
return new Function("return(" + code + ")")();
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_code(code) {
|
|
||||||
var result = sandbox.run_code(code, true);
|
|
||||||
return typeof result == "string" ? result.replace(/\u001b\[\d+m/g, "") : result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to reminify original input with standard options
|
|
||||||
// to see if it matches expect_stdout.
|
|
||||||
function reminify(orig_options, input_code, input_formatted, expect_stdout) {
|
|
||||||
for (var i = 0; i < minify_options.length; i++) {
|
|
||||||
var options = JSON.parse(minify_options[i]);
|
|
||||||
if (options.compress) [
|
|
||||||
"keep_fargs",
|
|
||||||
"keep_fnames",
|
|
||||||
].forEach(function(name) {
|
|
||||||
if (name in orig_options) {
|
|
||||||
options.compress[name] = orig_options[name];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
var options_formatted = JSON.stringify(options, null, 4);
|
|
||||||
var result = U.minify(input_code, options);
|
|
||||||
if (result.error) {
|
|
||||||
log("!!! failed input reminify\n---INPUT---\n{input}\n---OPTIONS---\n{options}\n--ERROR---\n{error}\n\n", {
|
|
||||||
input: input_formatted,
|
|
||||||
options: options_formatted,
|
|
||||||
error: result.error,
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
var stdout = run_code(result.code);
|
|
||||||
if (typeof expect_stdout != "string" && typeof stdout != "string" && expect_stdout.name == stdout.name) {
|
|
||||||
stdout = expect_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", {
|
|
||||||
input: input_formatted,
|
|
||||||
options: options_formatted,
|
|
||||||
output: result.code,
|
|
||||||
expected_type: typeof expect_stdout == "string" ? "STDOUT" : "ERROR",
|
|
||||||
expected: expect_stdout,
|
|
||||||
actual_type: typeof stdout == "string" ? "STDOUT" : "ERROR",
|
|
||||||
actual: stdout,
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,6 @@
|
|||||||
var semver = require("semver");
|
var semver = require("semver");
|
||||||
var vm = require("vm");
|
var vm = require("vm");
|
||||||
|
|
||||||
function createContext() {
|
|
||||||
return vm.createContext(Object.defineProperty({}, "console", {
|
|
||||||
value: {
|
|
||||||
log: function(msg) {
|
|
||||||
if (arguments.length == 1 && typeof msg == "string") {
|
|
||||||
return console.log("%s", msg);
|
|
||||||
}
|
|
||||||
return console.log.apply(console, [].map.call(arguments, function(arg) {
|
|
||||||
return safe_log(arg, 3);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
function safe_log(arg, level) {
|
function safe_log(arg, level) {
|
||||||
if (arg) switch (typeof arg) {
|
if (arg) switch (typeof arg) {
|
||||||
case "function":
|
case "function":
|
||||||
@@ -25,21 +10,21 @@ function safe_log(arg, level) {
|
|||||||
arg.constructor.toString();
|
arg.constructor.toString();
|
||||||
if (level--) for (var key in arg) {
|
if (level--) for (var key in arg) {
|
||||||
var desc = Object.getOwnPropertyDescriptor(arg, key);
|
var desc = Object.getOwnPropertyDescriptor(arg, key);
|
||||||
if (!desc || !desc.get) {
|
if (!desc || !desc.get) arg[key] = safe_log(arg[key], level);
|
||||||
arg[key] = safe_log(arg[key], level);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return arg;
|
return arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
function strip_func_ids(text) {
|
function log(msg) {
|
||||||
return ("" + text).replace(/F[0-9]{6}N/g, "<F<>N>");
|
if (arguments.length == 1 && typeof msg == "string") return console.log("%s", msg);
|
||||||
|
return console.log.apply(console, [].map.call(arguments, function(arg) {
|
||||||
|
return safe_log(arg, 3);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
var context;
|
var func_toString = new vm.Script([
|
||||||
var FUNC_TOSTRING = [
|
"[ Array, Boolean, Error, Function, Number, Object, RegExp, String ].forEach(function(f) {",
|
||||||
"[ Array, Boolean, Error, Function, Number, Object, RegExp, String].forEach(function(f) {",
|
|
||||||
" f.toString = Function.prototype.toString;",
|
" f.toString = Function.prototype.toString;",
|
||||||
"});",
|
"});",
|
||||||
"Function.prototype.toString = function() {",
|
"Function.prototype.toString = function() {",
|
||||||
@@ -59,7 +44,15 @@ var FUNC_TOSTRING = [
|
|||||||
' return "function(){}";',
|
' return "function(){}";',
|
||||||
" };",
|
" };",
|
||||||
"}();",
|
"}();",
|
||||||
]).join("\n");
|
]).join("\n"));
|
||||||
|
|
||||||
|
function createContext() {
|
||||||
|
var ctx = vm.createContext(Object.defineProperty({}, "console", { value: { log: log } }));
|
||||||
|
func_toString.runInContext(ctx);
|
||||||
|
return ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
var context;
|
||||||
exports.run_code = function(code, reuse) {
|
exports.run_code = function(code, reuse) {
|
||||||
var stdout = "";
|
var stdout = "";
|
||||||
var original_write = process.stdout.write;
|
var original_write = process.stdout.write;
|
||||||
@@ -69,7 +62,6 @@ exports.run_code = function(code, reuse) {
|
|||||||
try {
|
try {
|
||||||
if (!reuse || !context) context = createContext();
|
if (!reuse || !context) context = createContext();
|
||||||
vm.runInContext([
|
vm.runInContext([
|
||||||
FUNC_TOSTRING,
|
|
||||||
"!function() {",
|
"!function() {",
|
||||||
code,
|
code,
|
||||||
"}();",
|
"}();",
|
||||||
@@ -81,11 +73,18 @@ exports.run_code = function(code, reuse) {
|
|||||||
process.stdout.write = original_write;
|
process.stdout.write = original_write;
|
||||||
if (!reuse || code.indexOf(".prototype") >= 0) {
|
if (!reuse || code.indexOf(".prototype") >= 0) {
|
||||||
context = null;
|
context = null;
|
||||||
} else for (var key in context) {
|
} else {
|
||||||
delete context[key];
|
vm.runInContext(Object.keys(context).map(function(name) {
|
||||||
|
return "delete " + name;
|
||||||
|
}).join("\n"), context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function strip_func_ids(text) {
|
||||||
|
return ("" + text).replace(/F[0-9]{6}N/g, "<F<>N>");
|
||||||
|
}
|
||||||
|
|
||||||
exports.same_stdout = semver.satisfies(process.version, "0.12") ? function(expected, actual) {
|
exports.same_stdout = semver.satisfies(process.version, "0.12") ? function(expected, actual) {
|
||||||
if (typeof expected != typeof actual) return false;
|
if (typeof expected != typeof actual) return false;
|
||||||
if (typeof expected != "string") {
|
if (typeof expected != "string") {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ if (process.argv[2] == "run") {
|
|||||||
var branch = process.argv[3] || "v" + require("../package.json").version;
|
var branch = process.argv[3] || "v" + require("../package.json").version;
|
||||||
var repository = encodeURIComponent(process.argv[4] || "mishoo/UglifyJS2");
|
var repository = encodeURIComponent(process.argv[4] || "mishoo/UglifyJS2");
|
||||||
var concurrency = process.argv[5] || 1;
|
var concurrency = process.argv[5] || 1;
|
||||||
|
var platform = process.argv[6] || "node/latest";
|
||||||
(function request() {
|
(function request() {
|
||||||
setTimeout(request, (period + wait) / concurrency);
|
setTimeout(request, (period + wait) / concurrency);
|
||||||
var options = url.parse("https://api.travis-ci.org/repo/" + repository + "/requests");
|
var options = url.parse("https://api.travis-ci.org/repo/" + repository + "/requests");
|
||||||
@@ -32,20 +33,18 @@ if (process.argv[2] == "run") {
|
|||||||
res.on("data", console.log);
|
res.on("data", console.log);
|
||||||
}).on("error", console.error).end(JSON.stringify({
|
}).on("error", console.error).end(JSON.stringify({
|
||||||
request: {
|
request: {
|
||||||
message: "ufuzz testing (when idle)",
|
message: "ufuzz testing",
|
||||||
branch: branch,
|
branch: branch,
|
||||||
config: {
|
config: {
|
||||||
merge_mode: "replace",
|
cache: false,
|
||||||
language: "node_js",
|
env: "NODEJS_VER=" + platform,
|
||||||
node_js: "9",
|
|
||||||
sudo: false,
|
|
||||||
script: "node test/travis-ufuzz run"
|
script: "node test/travis-ufuzz run"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
})();
|
})();
|
||||||
} else {
|
} else {
|
||||||
console.log("Usage: test/travis-ufuzz.js <token> [branch] [repository] [concurrency]");
|
console.log("Usage: test/travis-ufuzz.js <token> [branch] [repository] [concurrency] [platform]");
|
||||||
}
|
}
|
||||||
|
|
||||||
function spawn(endTime) {
|
function spawn(endTime) {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
},
|
},
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
|
"ie8": true,
|
||||||
"toplevel": true
|
"toplevel": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
1240
tools/domprops.json
1240
tools/domprops.json
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
exports["Dictionary"] = Dictionary;
|
exports["Dictionary"] = Dictionary;
|
||||||
exports["TreeWalker"] = TreeWalker;
|
|
||||||
exports["TreeTransformer"] = TreeTransformer;
|
|
||||||
exports["minify"] = minify;
|
exports["minify"] = minify;
|
||||||
exports["parse"] = parse;
|
exports["parse"] = parse;
|
||||||
exports["_push_uniq"] = push_uniq;
|
exports["push_uniq"] = push_uniq;
|
||||||
|
exports["TreeTransformer"] = TreeTransformer;
|
||||||
|
exports["TreeWalker"] = TreeWalker;
|
||||||
|
|||||||
585
tools/props.html
585
tools/props.html
@@ -1,61 +1,540 @@
|
|||||||
|
<!doctype html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<body>
|
||||||
</head>
|
<script>
|
||||||
<body>
|
!function() {
|
||||||
<script>(function(){
|
var names = [];
|
||||||
var props = {};
|
var scanned = [];
|
||||||
|
var to_scan = [];
|
||||||
|
|
||||||
function addObject(obj) {
|
function scan(obj) {
|
||||||
if (obj == null) return;
|
if (obj && typeof obj == "object" && !~scanned.indexOf(obj)) {
|
||||||
|
scanned.push(obj);
|
||||||
|
to_scan.push(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scan(self);
|
||||||
|
[
|
||||||
|
"a",
|
||||||
|
"abbr",
|
||||||
|
"acronym",
|
||||||
|
"address",
|
||||||
|
"applet",
|
||||||
|
"area",
|
||||||
|
"article",
|
||||||
|
"aside",
|
||||||
|
"audio",
|
||||||
|
"b",
|
||||||
|
"base",
|
||||||
|
"basefont",
|
||||||
|
"bdi",
|
||||||
|
"bdo",
|
||||||
|
"bgsound",
|
||||||
|
"big",
|
||||||
|
"blink",
|
||||||
|
"blockquote",
|
||||||
|
"body",
|
||||||
|
"br",
|
||||||
|
"button",
|
||||||
|
"canvas",
|
||||||
|
"caption",
|
||||||
|
"center",
|
||||||
|
"checked",
|
||||||
|
"cite",
|
||||||
|
"code",
|
||||||
|
"col",
|
||||||
|
"colgroup",
|
||||||
|
"command",
|
||||||
|
"comment",
|
||||||
|
"compact",
|
||||||
|
"content",
|
||||||
|
"data",
|
||||||
|
"datalist",
|
||||||
|
"dd",
|
||||||
|
"declare",
|
||||||
|
"defer",
|
||||||
|
"del",
|
||||||
|
"details",
|
||||||
|
"dfn",
|
||||||
|
"dialog",
|
||||||
|
"dir",
|
||||||
|
"disabled",
|
||||||
|
"div",
|
||||||
|
"dl",
|
||||||
|
"dt",
|
||||||
|
"element",
|
||||||
|
"em",
|
||||||
|
"embed",
|
||||||
|
"fieldset",
|
||||||
|
"figcaption",
|
||||||
|
"figure",
|
||||||
|
"font",
|
||||||
|
"footer",
|
||||||
|
"form",
|
||||||
|
"frame",
|
||||||
|
"frameset",
|
||||||
|
"h1",
|
||||||
|
"h2",
|
||||||
|
"h3",
|
||||||
|
"h4",
|
||||||
|
"h5",
|
||||||
|
"h6",
|
||||||
|
"head",
|
||||||
|
"header",
|
||||||
|
"hgroup",
|
||||||
|
"hr",
|
||||||
|
"html",
|
||||||
|
"i",
|
||||||
|
"iframe",
|
||||||
|
"image",
|
||||||
|
"img",
|
||||||
|
"input",
|
||||||
|
"ins",
|
||||||
|
"isindex",
|
||||||
|
"ismap",
|
||||||
|
"kbd",
|
||||||
|
"keygen",
|
||||||
|
"label",
|
||||||
|
"legend",
|
||||||
|
"li",
|
||||||
|
"link",
|
||||||
|
"listing",
|
||||||
|
"main",
|
||||||
|
"map",
|
||||||
|
"mark",
|
||||||
|
"marquee",
|
||||||
|
"math",
|
||||||
|
"menu",
|
||||||
|
"menuitem",
|
||||||
|
"meta",
|
||||||
|
"meter",
|
||||||
|
"multicol",
|
||||||
|
"multiple",
|
||||||
|
"nav",
|
||||||
|
"nobr",
|
||||||
|
"noembed",
|
||||||
|
"noframes",
|
||||||
|
"nohref",
|
||||||
|
"noresize",
|
||||||
|
"noscript",
|
||||||
|
"noshade",
|
||||||
|
"nowrap",
|
||||||
|
"object",
|
||||||
|
"ol",
|
||||||
|
"optgroup",
|
||||||
|
"option",
|
||||||
|
"output",
|
||||||
|
"p",
|
||||||
|
"param",
|
||||||
|
"picture",
|
||||||
|
"plaintext",
|
||||||
|
"pre",
|
||||||
|
"progress",
|
||||||
|
"q",
|
||||||
|
"rb",
|
||||||
|
"readonly",
|
||||||
|
"rp",
|
||||||
|
"rt",
|
||||||
|
"rtc",
|
||||||
|
"ruby",
|
||||||
|
"s",
|
||||||
|
"samp",
|
||||||
|
"script",
|
||||||
|
"section",
|
||||||
|
"select",
|
||||||
|
"selected",
|
||||||
|
"shadow",
|
||||||
|
"small",
|
||||||
|
"source",
|
||||||
|
"spacer",
|
||||||
|
"span",
|
||||||
|
"strike",
|
||||||
|
"strong",
|
||||||
|
"style",
|
||||||
|
"sub",
|
||||||
|
"summary",
|
||||||
|
"sup",
|
||||||
|
"svg",
|
||||||
|
"table",
|
||||||
|
"tbody",
|
||||||
|
"td",
|
||||||
|
"template",
|
||||||
|
"textarea",
|
||||||
|
"tfoot",
|
||||||
|
"th",
|
||||||
|
"thead",
|
||||||
|
"time",
|
||||||
|
"title",
|
||||||
|
"tr",
|
||||||
|
"track",
|
||||||
|
"tt",
|
||||||
|
"u",
|
||||||
|
"ul",
|
||||||
|
"var",
|
||||||
|
"video",
|
||||||
|
"wbr",
|
||||||
|
"xmp",
|
||||||
|
"XXX",
|
||||||
|
].forEach(function(tag) {
|
||||||
|
scan(document.createElement(tag));
|
||||||
|
});
|
||||||
|
[
|
||||||
|
"abort",
|
||||||
|
"absolutedeviceorientation",
|
||||||
|
"activate",
|
||||||
|
"active",
|
||||||
|
"addsourcebuffer",
|
||||||
|
"addstream",
|
||||||
|
"addtrack",
|
||||||
|
"afterprint",
|
||||||
|
"afterscriptexecute",
|
||||||
|
"afterupdate",
|
||||||
|
"animationcancel",
|
||||||
|
"animationend",
|
||||||
|
"animationiteration",
|
||||||
|
"animationstart",
|
||||||
|
"appinstalled",
|
||||||
|
"audioend",
|
||||||
|
"audioprocess",
|
||||||
|
"audiostart",
|
||||||
|
"autocomplete",
|
||||||
|
"autocompleteerror",
|
||||||
|
"auxclick",
|
||||||
|
"beforeactivate",
|
||||||
|
"beforecopy",
|
||||||
|
"beforecut",
|
||||||
|
"beforedeactivate",
|
||||||
|
"beforeeditfocus",
|
||||||
|
"beforeinstallprompt",
|
||||||
|
"beforepaste",
|
||||||
|
"beforeprint",
|
||||||
|
"beforescriptexecute",
|
||||||
|
"beforeunload",
|
||||||
|
"beforeupdate",
|
||||||
|
"blocked",
|
||||||
|
"blur",
|
||||||
|
"bounce",
|
||||||
|
"boundary",
|
||||||
|
"cached",
|
||||||
|
"cancel",
|
||||||
|
"candidatewindowhide",
|
||||||
|
"candidatewindowshow",
|
||||||
|
"candidatewindowupdate",
|
||||||
|
"canplay",
|
||||||
|
"canplaythrough",
|
||||||
|
"cellchange",
|
||||||
|
"change",
|
||||||
|
"chargingchange",
|
||||||
|
"chargingtimechange",
|
||||||
|
"checking",
|
||||||
|
"click",
|
||||||
|
"close",
|
||||||
|
"compassneedscalibration",
|
||||||
|
"complete",
|
||||||
|
"connect",
|
||||||
|
"connecting",
|
||||||
|
"connectionstatechange",
|
||||||
|
"contextmenu",
|
||||||
|
"controllerchange",
|
||||||
|
"controlselect",
|
||||||
|
"copy",
|
||||||
|
"cuechange",
|
||||||
|
"cut",
|
||||||
|
"dataavailable",
|
||||||
|
"datachannel",
|
||||||
|
"datasetchanged",
|
||||||
|
"datasetcomplete",
|
||||||
|
"dblclick",
|
||||||
|
"deactivate",
|
||||||
|
"devicechange",
|
||||||
|
"devicelight",
|
||||||
|
"devicemotion",
|
||||||
|
"deviceorientation",
|
||||||
|
"deviceorientationabsolute",
|
||||||
|
"deviceproximity",
|
||||||
|
"dischargingtimechange",
|
||||||
|
"disconnect",
|
||||||
|
"display",
|
||||||
|
"downloading",
|
||||||
|
"drag",
|
||||||
|
"dragend",
|
||||||
|
"dragenter",
|
||||||
|
"dragexit",
|
||||||
|
"dragleave",
|
||||||
|
"dragover",
|
||||||
|
"dragstart",
|
||||||
|
"drop",
|
||||||
|
"durationchange",
|
||||||
|
"emptied",
|
||||||
|
"encrypted",
|
||||||
|
"end",
|
||||||
|
"ended",
|
||||||
|
"enter",
|
||||||
|
"enterpictureinpicture",
|
||||||
|
"error",
|
||||||
|
"errorupdate",
|
||||||
|
"exit",
|
||||||
|
"filterchange",
|
||||||
|
"finish",
|
||||||
|
"focus",
|
||||||
|
"focusin",
|
||||||
|
"focusout",
|
||||||
|
"freeze",
|
||||||
|
"fullscreenchange",
|
||||||
|
"fullscreenerror",
|
||||||
|
"gesturechange",
|
||||||
|
"gestureend",
|
||||||
|
"gesturestart",
|
||||||
|
"gotpointercapture",
|
||||||
|
"hashchange",
|
||||||
|
"help",
|
||||||
|
"icecandidate",
|
||||||
|
"iceconnectionstatechange",
|
||||||
|
"icegatheringstatechange",
|
||||||
|
"inactive",
|
||||||
|
"input",
|
||||||
|
"invalid",
|
||||||
|
"keydown",
|
||||||
|
"keypress",
|
||||||
|
"keyup",
|
||||||
|
"languagechange",
|
||||||
|
"layoutcomplete",
|
||||||
|
"leavepictureinpicture",
|
||||||
|
"levelchange",
|
||||||
|
"load",
|
||||||
|
"loadeddata",
|
||||||
|
"loadedmetadata",
|
||||||
|
"loadend",
|
||||||
|
"loading",
|
||||||
|
"loadingdone",
|
||||||
|
"loadingerror",
|
||||||
|
"loadstart",
|
||||||
|
"losecapture",
|
||||||
|
"lostpointercapture",
|
||||||
|
"mark",
|
||||||
|
"message",
|
||||||
|
"messageerror",
|
||||||
|
"mousedown",
|
||||||
|
"mouseenter",
|
||||||
|
"mouseleave",
|
||||||
|
"mousemove",
|
||||||
|
"mouseout",
|
||||||
|
"mouseover",
|
||||||
|
"mouseup",
|
||||||
|
"mousewheel",
|
||||||
|
"move",
|
||||||
|
"moveend",
|
||||||
|
"movestart",
|
||||||
|
"mozfullscreenchange",
|
||||||
|
"mozfullscreenerror",
|
||||||
|
"mozorientationchange",
|
||||||
|
"mozpointerlockchange",
|
||||||
|
"mozpointerlockerror",
|
||||||
|
"mscontentzoom",
|
||||||
|
"msfullscreenchange",
|
||||||
|
"msfullscreenerror",
|
||||||
|
"msgesturechange",
|
||||||
|
"msgesturedoubletap",
|
||||||
|
"msgestureend",
|
||||||
|
"msgesturehold",
|
||||||
|
"msgesturestart",
|
||||||
|
"msgesturetap",
|
||||||
|
"msgotpointercapture",
|
||||||
|
"msinertiastart",
|
||||||
|
"mslostpointercapture",
|
||||||
|
"msmanipulationstatechanged",
|
||||||
|
"msneedkey",
|
||||||
|
"msorientationchange",
|
||||||
|
"mspointercancel",
|
||||||
|
"mspointerdown",
|
||||||
|
"mspointerenter",
|
||||||
|
"mspointerhover",
|
||||||
|
"mspointerleave",
|
||||||
|
"mspointermove",
|
||||||
|
"mspointerout",
|
||||||
|
"mspointerover",
|
||||||
|
"mspointerup",
|
||||||
|
"mssitemodejumplistitemremoved",
|
||||||
|
"msthumbnailclick",
|
||||||
|
"negotiationneeded",
|
||||||
|
"nomatch",
|
||||||
|
"noupdate",
|
||||||
|
"obsolete",
|
||||||
|
"offline",
|
||||||
|
"online",
|
||||||
|
"open",
|
||||||
|
"orientationchange",
|
||||||
|
"pagechange",
|
||||||
|
"pagehide",
|
||||||
|
"pageshow",
|
||||||
|
"paste",
|
||||||
|
"pause",
|
||||||
|
"play",
|
||||||
|
"playing",
|
||||||
|
"pluginstreamstart",
|
||||||
|
"pointercancel",
|
||||||
|
"pointerdown",
|
||||||
|
"pointerenter",
|
||||||
|
"pointerleave",
|
||||||
|
"pointerlockchange",
|
||||||
|
"pointerlockerror",
|
||||||
|
"pointermove",
|
||||||
|
"pointerout",
|
||||||
|
"pointerover",
|
||||||
|
"pointerup",
|
||||||
|
"popstate",
|
||||||
|
"progress",
|
||||||
|
"propertychange",
|
||||||
|
"ratechange",
|
||||||
|
"reading",
|
||||||
|
"readystatechange",
|
||||||
|
"rejectionhandled",
|
||||||
|
"removesourcebuffer",
|
||||||
|
"removestream",
|
||||||
|
"removetrack",
|
||||||
|
"reset",
|
||||||
|
"resize",
|
||||||
|
"resizeend",
|
||||||
|
"resizestart",
|
||||||
|
"resourcetimingbufferfull",
|
||||||
|
"result",
|
||||||
|
"resume",
|
||||||
|
"rowenter",
|
||||||
|
"rowexit",
|
||||||
|
"rowsdelete",
|
||||||
|
"rowsinserted",
|
||||||
|
"scroll",
|
||||||
|
"search",
|
||||||
|
"seeked",
|
||||||
|
"seeking",
|
||||||
|
"select",
|
||||||
|
"selectionchange",
|
||||||
|
"selectstart",
|
||||||
|
"show",
|
||||||
|
"signalingstatechange",
|
||||||
|
"soundend",
|
||||||
|
"soundstart",
|
||||||
|
"sourceclose",
|
||||||
|
"sourceclosed",
|
||||||
|
"sourceended",
|
||||||
|
"sourceopen",
|
||||||
|
"speechend",
|
||||||
|
"speechstart",
|
||||||
|
"stalled",
|
||||||
|
"start",
|
||||||
|
"statechange",
|
||||||
|
"stop",
|
||||||
|
"storage",
|
||||||
|
"storagecommit",
|
||||||
|
"submit",
|
||||||
|
"success",
|
||||||
|
"suspend",
|
||||||
|
"textinput",
|
||||||
|
"timeout",
|
||||||
|
"timeupdate",
|
||||||
|
"toggle",
|
||||||
|
"touchcancel",
|
||||||
|
"touchend",
|
||||||
|
"touchmove",
|
||||||
|
"touchstart",
|
||||||
|
"track",
|
||||||
|
"transitioncancel",
|
||||||
|
"transitionend",
|
||||||
|
"transitionrun",
|
||||||
|
"transitionstart",
|
||||||
|
"unhandledrejection",
|
||||||
|
"unload",
|
||||||
|
"updateready",
|
||||||
|
"upgradeneeded",
|
||||||
|
"userproximity",
|
||||||
|
"versionchange",
|
||||||
|
"visibilitychange",
|
||||||
|
"voiceschanged",
|
||||||
|
"volumechange",
|
||||||
|
"vrdisplayactivate",
|
||||||
|
"vrdisplayconnect",
|
||||||
|
"vrdisplaydeactivate",
|
||||||
|
"vrdisplaydisconnect",
|
||||||
|
"vrdisplaypresentchange",
|
||||||
|
"waiting",
|
||||||
|
"waitingforkey",
|
||||||
|
"warning",
|
||||||
|
"webkitanimationend",
|
||||||
|
"webkitanimationiteration",
|
||||||
|
"webkitanimationstart",
|
||||||
|
"webkitcurrentplaybacktargetiswirelesschanged",
|
||||||
|
"webkitfullscreenchange",
|
||||||
|
"webkitfullscreenerror",
|
||||||
|
"webkitkeyadded",
|
||||||
|
"webkitkeyerror",
|
||||||
|
"webkitkeymessage",
|
||||||
|
"webkitneedkey",
|
||||||
|
"webkitorientationchange",
|
||||||
|
"webkitplaybacktargetavailabilitychanged",
|
||||||
|
"webkitpointerlockchange",
|
||||||
|
"webkitpointerlockerror",
|
||||||
|
"webkitresourcetimingbufferfull",
|
||||||
|
"webkittransitionend",
|
||||||
|
"wheel",
|
||||||
|
"zoom",
|
||||||
|
].forEach(function(type) {
|
||||||
|
[
|
||||||
|
"beforeunloadevent",
|
||||||
|
"compositionevent",
|
||||||
|
"customevent",
|
||||||
|
"devicemotionevent",
|
||||||
|
"deviceorientationevent",
|
||||||
|
"dragevent",
|
||||||
|
"event",
|
||||||
|
"events",
|
||||||
|
"focusevent",
|
||||||
|
"hashchangeevent",
|
||||||
|
"htmlevents",
|
||||||
|
"keyboardevent",
|
||||||
|
"messageevent",
|
||||||
|
"mouseevent",
|
||||||
|
"mouseevents",
|
||||||
|
"storageevent",
|
||||||
|
"svgevents",
|
||||||
|
"textevent",
|
||||||
|
"touchevent",
|
||||||
|
"uievent",
|
||||||
|
"uievents",
|
||||||
|
].forEach(function(interface) {
|
||||||
try {
|
try {
|
||||||
Object.getOwnPropertyNames(obj).forEach(add);
|
var event = document.createEvent(interface);
|
||||||
} catch(ex) {}
|
event.initEvent(type, true, true);
|
||||||
if (obj.prototype) {
|
scan(event);
|
||||||
Object.getOwnPropertyNames(obj.prototype).forEach(add);
|
} catch (e) {}
|
||||||
}
|
});
|
||||||
if (typeof obj == "function") {
|
|
||||||
try {
|
|
||||||
Object.getOwnPropertyNames(new obj).forEach(add);
|
|
||||||
} catch(ex) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function add(name) {
|
|
||||||
props[name] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.getOwnPropertyNames(window).forEach(function(thing){
|
|
||||||
addObject(window[thing]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var obj;
|
||||||
|
while (obj = to_scan.shift()) {
|
||||||
|
var proto = obj;
|
||||||
|
do {
|
||||||
|
Object.getOwnPropertyNames(proto).forEach(function(name) {
|
||||||
|
var visited = ~names.indexOf(name);
|
||||||
|
if (!visited) names.push(name);
|
||||||
try {
|
try {
|
||||||
addObject(new Event("click"));
|
scan(obj[name]);
|
||||||
addObject(new Event("contextmenu"));
|
if (visited) return;
|
||||||
addObject(new Event("mouseup"));
|
if (/^create/.test(name)) {
|
||||||
addObject(new Event("mousedown"));
|
scan(obj[name]());
|
||||||
addObject(new Event("keydown"));
|
|
||||||
addObject(new Event("keypress"));
|
|
||||||
addObject(new Event("keyup"));
|
|
||||||
} catch(ex) {}
|
|
||||||
|
|
||||||
var ta = document.createElement("textarea");
|
|
||||||
ta.style.width = "100%";
|
|
||||||
ta.style.height = "20em";
|
|
||||||
ta.style.boxSizing = "border-box";
|
|
||||||
<!-- ta.value = Object.keys(props).sort(cmp).map(function(name){ -->
|
|
||||||
<!-- return JSON.stringify(name); -->
|
|
||||||
<!-- }).join(",\n"); -->
|
|
||||||
ta.value = JSON.stringify({
|
|
||||||
vars: [],
|
|
||||||
props: Object.keys(props).sort(cmp)
|
|
||||||
}, null, 2);
|
|
||||||
document.body.appendChild(ta);
|
|
||||||
|
|
||||||
function cmp(a, b) {
|
|
||||||
a = a.toLowerCase();
|
|
||||||
b = b.toLowerCase();
|
|
||||||
return a < b ? -1 : a > b ? 1 : 0;
|
|
||||||
}
|
}
|
||||||
})();</script>
|
if (/^[A-Z]/.test(name)) {
|
||||||
</body>
|
scan(new obj[name]());
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
});
|
||||||
|
} while (proto = Object.getPrototypeOf(proto));
|
||||||
|
}
|
||||||
|
names.sort();
|
||||||
|
document.write('<pre>[\n "');
|
||||||
|
document.write(names.join('",\n "'));
|
||||||
|
document.write('"\n]</pre>');
|
||||||
|
}();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user