Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a82003d6ac | ||
|
|
da9f1622fc | ||
|
|
8a4c7077bb | ||
|
|
0a63f2f2b0 | ||
|
|
931ac66638 | ||
|
|
35338a100f | ||
|
|
d57b606e73 | ||
|
|
00ada04111 | ||
|
|
a31c477fea | ||
|
|
bde7418ce1 |
121
lib/compress.js
121
lib/compress.js
@@ -1293,6 +1293,7 @@ merge(Compressor.prototype, {
|
|||||||
return lhs instanceof AST_PropAccess && lhs.equivalent_to(node.expression);
|
return lhs instanceof AST_PropAccess && lhs.equivalent_to(node.expression);
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Debugger) return true;
|
if (node instanceof AST_Debugger) return true;
|
||||||
|
if (node instanceof AST_Defun) return funarg && lhs.name === node.name.name;
|
||||||
if (node instanceof AST_IterationStatement) return !(node instanceof AST_For);
|
if (node instanceof AST_IterationStatement) return !(node instanceof AST_For);
|
||||||
if (node instanceof AST_LoopControl) return true;
|
if (node instanceof AST_LoopControl) return true;
|
||||||
if (node instanceof AST_Try) return true;
|
if (node instanceof AST_Try) return true;
|
||||||
@@ -3399,16 +3400,28 @@ merge(Compressor.prototype, {
|
|||||||
def(AST_Lambda, function(scope) {
|
def(AST_Lambda, function(scope) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var result = true;
|
var result = true;
|
||||||
self.walk(new TreeWalker(function(node) {
|
var inner_scopes = [];
|
||||||
|
self.walk(new TreeWalker(function(node, descend) {
|
||||||
if (!result) return true;
|
if (!result) return true;
|
||||||
|
if (node instanceof AST_Catch) {
|
||||||
|
inner_scopes.push(node.argname.scope);
|
||||||
|
descend();
|
||||||
|
inner_scopes.pop();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (node instanceof AST_Scope && node !== self) {
|
||||||
|
inner_scopes.push(node);
|
||||||
|
descend();
|
||||||
|
inner_scopes.pop();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (node instanceof AST_SymbolRef) {
|
if (node instanceof AST_SymbolRef) {
|
||||||
if (self.inlined) {
|
if (self.inlined) {
|
||||||
result = false;
|
result = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
var def = node.definition();
|
var def = node.definition();
|
||||||
if (member(def, self.enclosed)
|
if (!self.variables.has(def.name) && !member(def.scope, inner_scopes)) {
|
||||||
&& !self.variables.has(def.name)) {
|
|
||||||
if (scope) {
|
if (scope) {
|
||||||
var scope_def = scope.find_variable(node);
|
var scope_def = scope.find_variable(node);
|
||||||
if (def.undeclared ? !scope_def : scope_def === def) {
|
if (def.undeclared ? !scope_def : scope_def === def) {
|
||||||
@@ -4055,10 +4068,11 @@ merge(Compressor.prototype, {
|
|||||||
var top_retain = self instanceof AST_Toplevel && compressor.top_retain || return_false;
|
var top_retain = self instanceof AST_Toplevel && compressor.top_retain || return_false;
|
||||||
var defs_by_id = Object.create(null);
|
var defs_by_id = Object.create(null);
|
||||||
self.transform(new TreeTransformer(function(node, descend) {
|
self.transform(new TreeTransformer(function(node, descend) {
|
||||||
if (node instanceof AST_Assign
|
if (node instanceof AST_Assign) {
|
||||||
&& node.operator == "="
|
if (node.operator != "=") return;
|
||||||
&& node.write_only
|
if (!node.write_only) return;
|
||||||
&& can_hoist(node.left, node.right, 1)) {
|
if (node.left.scope !== self) return;
|
||||||
|
if (!can_hoist(node.left, node.right, 1)) return;
|
||||||
descend(node, this);
|
descend(node, this);
|
||||||
var defs = new Dictionary();
|
var defs = new Dictionary();
|
||||||
var assignments = [];
|
var assignments = [];
|
||||||
@@ -4087,17 +4101,9 @@ merge(Compressor.prototype, {
|
|||||||
}));
|
}));
|
||||||
return make_sequence(node, assignments);
|
return make_sequence(node, assignments);
|
||||||
}
|
}
|
||||||
if (node instanceof AST_Unary
|
if (node instanceof AST_Scope) return node === self ? undefined : node;
|
||||||
&& !unary_side_effects[node.operator]
|
if (node instanceof AST_VarDef) {
|
||||||
&& node.expression instanceof AST_SymbolRef
|
if (!can_hoist(node.name, node.value, 0)) return;
|
||||||
&& node.expression.definition().id in defs_by_id) {
|
|
||||||
node = node.clone();
|
|
||||||
node.expression = make_node(AST_Object, node, {
|
|
||||||
properties: []
|
|
||||||
});
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
if (node instanceof AST_VarDef && can_hoist(node.name, node.value, 0)) {
|
|
||||||
descend(node, this);
|
descend(node, this);
|
||||||
var defs = new Dictionary();
|
var defs = new Dictionary();
|
||||||
var var_defs = [];
|
var var_defs = [];
|
||||||
@@ -4110,32 +4116,6 @@ merge(Compressor.prototype, {
|
|||||||
defs_by_id[node.name.definition().id] = defs;
|
defs_by_id[node.name.definition().id] = defs;
|
||||||
return MAP.splice(var_defs);
|
return MAP.splice(var_defs);
|
||||||
}
|
}
|
||||||
if (node instanceof AST_PropAccess && node.expression instanceof AST_SymbolRef) {
|
|
||||||
var defs = defs_by_id[node.expression.definition().id];
|
|
||||||
if (defs) {
|
|
||||||
var def = defs.get(node.getProperty());
|
|
||||||
var sym = make_node(AST_SymbolRef, node, {
|
|
||||||
name: def.name,
|
|
||||||
scope: node.expression.scope,
|
|
||||||
thedef: def
|
|
||||||
});
|
|
||||||
sym.reference({});
|
|
||||||
return sym;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function can_hoist(sym, right, count) {
|
|
||||||
if (sym.scope !== self) return;
|
|
||||||
var def = sym.definition();
|
|
||||||
if (def.assignments != count) return;
|
|
||||||
if (def.direct_access) return;
|
|
||||||
if (def.escaped.depth == 1) return;
|
|
||||||
if (def.references.length == count) return;
|
|
||||||
if (def.single_use) return;
|
|
||||||
if (top_retain(def)) return;
|
|
||||||
if (sym.fixed_value() !== right) return;
|
|
||||||
return right instanceof AST_Object;
|
|
||||||
}
|
|
||||||
|
|
||||||
function make_sym(sym, key) {
|
function make_sym(sym, key) {
|
||||||
var new_var = make_node(AST_SymbolVar, sym, {
|
var new_var = make_node(AST_SymbolVar, sym, {
|
||||||
@@ -4148,6 +4128,43 @@ merge(Compressor.prototype, {
|
|||||||
return new_var;
|
return new_var;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
self.transform(new TreeTransformer(function(node, descend) {
|
||||||
|
if (node instanceof AST_PropAccess) {
|
||||||
|
if (!(node.expression instanceof AST_SymbolRef)) return;
|
||||||
|
var defs = defs_by_id[node.expression.definition().id];
|
||||||
|
if (!defs) return;
|
||||||
|
var def = defs.get(node.getProperty());
|
||||||
|
var sym = make_node(AST_SymbolRef, node, {
|
||||||
|
name: def.name,
|
||||||
|
scope: node.expression.scope,
|
||||||
|
thedef: def
|
||||||
|
});
|
||||||
|
sym.reference({});
|
||||||
|
return sym;
|
||||||
|
}
|
||||||
|
if (node instanceof AST_Unary) {
|
||||||
|
if (unary_side_effects[node.operator]) return;
|
||||||
|
if (!(node.expression instanceof AST_SymbolRef)) return;
|
||||||
|
if (!(node.expression.definition().id in defs_by_id)) return;
|
||||||
|
var opt = node.clone();
|
||||||
|
opt.expression = make_node(AST_Object, node, {
|
||||||
|
properties: []
|
||||||
|
});
|
||||||
|
return opt;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
function can_hoist(sym, right, count) {
|
||||||
|
var def = sym.definition();
|
||||||
|
if (def.assignments != count) return;
|
||||||
|
if (def.direct_access) return;
|
||||||
|
if (def.escaped.depth == 1) return;
|
||||||
|
if (def.references.length == count) return;
|
||||||
|
if (def.single_use) return;
|
||||||
|
if (top_retain(def)) return;
|
||||||
|
if (sym.fixed_value() !== right) return;
|
||||||
|
return right instanceof AST_Object;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// drop_side_effect_free()
|
// drop_side_effect_free()
|
||||||
@@ -5220,25 +5237,26 @@ merge(Compressor.prototype, {
|
|||||||
return return_value(stat);
|
return return_value(stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
function var_exists(catches, name) {
|
function var_exists(defined, name) {
|
||||||
return catches[name] || identifier_atom[name] || scope.var_names()[name];
|
return defined[name] || identifier_atom[name] || scope.var_names()[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
function can_inject_args(catches, safe_to_inject) {
|
function can_inject_args(catches, used, safe_to_inject) {
|
||||||
for (var i = 0; i < fn.argnames.length; i++) {
|
for (var i = 0; i < fn.argnames.length; i++) {
|
||||||
var arg = fn.argnames[i];
|
var arg = fn.argnames[i];
|
||||||
if (arg.__unused) continue;
|
if (arg.__unused) continue;
|
||||||
if (!safe_to_inject || var_exists(catches, arg.name)) return false;
|
if (!safe_to_inject || var_exists(catches, arg.name)) return false;
|
||||||
|
used[arg.name] = true;
|
||||||
if (in_loop) in_loop.push(arg.definition());
|
if (in_loop) in_loop.push(arg.definition());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function can_inject_vars(catches, safe_to_inject) {
|
function can_inject_vars(catches, used, safe_to_inject) {
|
||||||
for (var i = 0; i < fn.body.length; i++) {
|
for (var i = 0; i < fn.body.length; i++) {
|
||||||
var stat = fn.body[i];
|
var stat = fn.body[i];
|
||||||
if (stat instanceof AST_Defun) {
|
if (stat instanceof AST_Defun) {
|
||||||
if (!safe_to_inject || var_exists(catches, stat.name.name)) return false;
|
if (!safe_to_inject || var_exists(used, stat.name.name)) return false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!(stat instanceof AST_Var)) continue;
|
if (!(stat instanceof AST_Var)) continue;
|
||||||
@@ -5267,8 +5285,9 @@ merge(Compressor.prototype, {
|
|||||||
var safe_to_inject = (!(scope instanceof AST_Toplevel) || compressor.toplevel.vars)
|
var safe_to_inject = (!(scope instanceof AST_Toplevel) || compressor.toplevel.vars)
|
||||||
&& (exp !== fn || fn.parent_scope === compressor.find_parent(AST_Scope));
|
&& (exp !== fn || fn.parent_scope === compressor.find_parent(AST_Scope));
|
||||||
var inline = compressor.option("inline");
|
var inline = compressor.option("inline");
|
||||||
if (!can_inject_vars(catches, inline >= 3 && safe_to_inject)) return false;
|
var used = Object.create(catches);
|
||||||
if (!can_inject_args(catches, inline >= 2 && safe_to_inject)) return false;
|
if (!can_inject_args(catches, used, inline >= 2 && safe_to_inject)) return false;
|
||||||
|
if (!can_inject_vars(catches, used, inline >= 3 && safe_to_inject)) return false;
|
||||||
return !in_loop || in_loop.length == 0 || !is_reachable(fn, in_loop);
|
return !in_loop || in_loop.length == 0 || !is_reachable(fn, in_loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -136,8 +136,7 @@ function OutputStream(options) {
|
|||||||
|
|
||||||
function make_string(str, quote) {
|
function make_string(str, quote) {
|
||||||
var dq = 0, sq = 0;
|
var dq = 0, sq = 0;
|
||||||
str = str.replace(/[\\\b\f\n\r\v\t\x22\x27\u2028\u2029\0\ufeff]/g,
|
str = str.replace(/[\\\b\f\n\r\v\t\x22\x27\u2028\u2029\0\ufeff]/g, function(s, i) {
|
||||||
function(s, i) {
|
|
||||||
switch (s) {
|
switch (s) {
|
||||||
case '"': ++dq; return '"';
|
case '"': ++dq; return '"';
|
||||||
case "'": ++sq; return "'";
|
case "'": ++sq; return "'";
|
||||||
@@ -599,7 +598,6 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
print(encoded);
|
print(encoded);
|
||||||
},
|
},
|
||||||
encode_string : encode_string,
|
|
||||||
next_indent : next_indent,
|
next_indent : next_indent,
|
||||||
with_indent : with_indent,
|
with_indent : with_indent,
|
||||||
with_block : with_block,
|
with_block : with_block,
|
||||||
@@ -1383,8 +1381,27 @@ function OutputStream(options) {
|
|||||||
if (regexp.raw_source) {
|
if (regexp.raw_source) {
|
||||||
str = "/" + regexp.raw_source + str.slice(str.lastIndexOf("/"));
|
str = "/" + regexp.raw_source + str.slice(str.lastIndexOf("/"));
|
||||||
}
|
}
|
||||||
str = output.to_utf8(str);
|
output.print(output.to_utf8(str).replace(/\\(?:\0(?![0-9])|[^\0])/g, function(seq) {
|
||||||
output.print(str);
|
switch (seq[1]) {
|
||||||
|
case "\n": return "\\n";
|
||||||
|
case "\r": return "\\r";
|
||||||
|
case "\t": return "\t";
|
||||||
|
case "\b": return "\b";
|
||||||
|
case "\f": return "\f";
|
||||||
|
case "\0": return "\0";
|
||||||
|
case "\x0B": return "\v";
|
||||||
|
case "\u2028": return "\\u2028";
|
||||||
|
case "\u2029": return "\\u2029";
|
||||||
|
default: return seq;
|
||||||
|
}
|
||||||
|
}).replace(/[\n\r\u2028\u2029]/g, function(c) {
|
||||||
|
switch (c) {
|
||||||
|
case "\n": return "\\n";
|
||||||
|
case "\r": return "\\r";
|
||||||
|
case "\u2028": return "\\u2028";
|
||||||
|
case "\u2029": return "\\u2029";
|
||||||
|
}
|
||||||
|
}));
|
||||||
var p = output.parent();
|
var p = output.parent();
|
||||||
if (p instanceof AST_Binary && /^in/.test(p.operator) && p.left === self)
|
if (p instanceof AST_Binary && /^in/.test(p.operator) && p.left === self)
|
||||||
output.print(" ");
|
output.print(" ");
|
||||||
|
|||||||
@@ -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.6.0",
|
"version": "3.6.1",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
@@ -23,12 +23,12 @@
|
|||||||
"LICENSE"
|
"LICENSE"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"commander": "~2.20.0",
|
"commander": "2.20.0",
|
||||||
"source-map": "~0.6.1"
|
"source-map": "~0.6.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"acorn": "~6.1.1",
|
"acorn": "~7.1.0",
|
||||||
"semver": "~6.0.0"
|
"semver": "~6.3.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node test/compress.js && node test/mocha.js"
|
"test": "node test/compress.js && node test/mocha.js"
|
||||||
|
|||||||
@@ -6197,3 +6197,43 @@ Infinity_assignment: {
|
|||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3439_1: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(typeof function(a) {
|
||||||
|
function a() {}
|
||||||
|
return a;
|
||||||
|
}(42));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(typeof function(a) {
|
||||||
|
function a() {}
|
||||||
|
return a;
|
||||||
|
}(42));
|
||||||
|
}
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3439_2: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(typeof function() {
|
||||||
|
var a = 42;
|
||||||
|
function a() {}
|
||||||
|
return a;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(typeof function() {
|
||||||
|
return 42;
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect_stdout: "number"
|
||||||
|
}
|
||||||
|
|||||||
@@ -3148,3 +3148,51 @@ issue_3402: {
|
|||||||
"function",
|
"function",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3439: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(typeof function() {
|
||||||
|
return function(a) {
|
||||||
|
function a() {}
|
||||||
|
return a;
|
||||||
|
}(42);
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(typeof function(a) {
|
||||||
|
function a() {}
|
||||||
|
return a;
|
||||||
|
}(42));
|
||||||
|
}
|
||||||
|
expect_stdout: "function"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3444: {
|
||||||
|
options = {
|
||||||
|
inline: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function(h) {
|
||||||
|
return f;
|
||||||
|
function f() {
|
||||||
|
g();
|
||||||
|
}
|
||||||
|
function g() {
|
||||||
|
h("PASS");
|
||||||
|
}
|
||||||
|
})(console.log)();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function(h) {
|
||||||
|
return function() {
|
||||||
|
void h("PASS");
|
||||||
|
};
|
||||||
|
})(console.log)();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -886,3 +886,31 @@ issue_3411: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3440: {
|
||||||
|
options = {
|
||||||
|
hoist_props: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
function f() {
|
||||||
|
console.log(o.p);
|
||||||
|
}
|
||||||
|
var o = {
|
||||||
|
p: "PASS",
|
||||||
|
};
|
||||||
|
return f;
|
||||||
|
})()();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
var o_p = "PASS";
|
||||||
|
return function() {
|
||||||
|
console.log(o_p);
|
||||||
|
};
|
||||||
|
})()();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,3 +35,140 @@ regexp_2: {
|
|||||||
}
|
}
|
||||||
expect_stdout: '["PASS","pass"]'
|
expect_stdout: '["PASS","pass"]'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3434_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
"\n": RegExp("\n"),
|
||||||
|
"\r": RegExp("\r"),
|
||||||
|
"\t": RegExp("\t"),
|
||||||
|
"\b": RegExp("\b"),
|
||||||
|
"\f": RegExp("\f"),
|
||||||
|
"\0": RegExp("\0"),
|
||||||
|
"\x0B": RegExp("\x0B"),
|
||||||
|
"\u2028": RegExp("\u2028"),
|
||||||
|
"\u2029": RegExp("\u2029"),
|
||||||
|
};
|
||||||
|
for (var c in o)
|
||||||
|
console.log(o[c].test("\\"), o[c].test(c));
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"var o = {",
|
||||||
|
' "\\n": /\\n/,',
|
||||||
|
' "\\r": /\\r/,',
|
||||||
|
' "\\t": /\t/,',
|
||||||
|
' "\\b": /\b/,',
|
||||||
|
' "\\f": /\f/,',
|
||||||
|
' "\\0": /\0/,',
|
||||||
|
' "\\v": /\v/,',
|
||||||
|
' "\\u2028": /\\u2028/,',
|
||||||
|
' "\\u2029": /\\u2029/',
|
||||||
|
"};",
|
||||||
|
"",
|
||||||
|
'for (var c in o) console.log(o[c].test("\\\\"), o[c].test(c));',
|
||||||
|
]
|
||||||
|
expect_stdout: [
|
||||||
|
"false true",
|
||||||
|
"false true",
|
||||||
|
"false true",
|
||||||
|
"false true",
|
||||||
|
"false true",
|
||||||
|
"false true",
|
||||||
|
"false true",
|
||||||
|
"false true",
|
||||||
|
"false true",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3434_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
beautify = {
|
||||||
|
beautify: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var o = {
|
||||||
|
"\n": RegExp("\\\n"),
|
||||||
|
"\r": RegExp("\\\r"),
|
||||||
|
"\t": RegExp("\\\t"),
|
||||||
|
"\b": RegExp("\\\b"),
|
||||||
|
"\f": RegExp("\\\f"),
|
||||||
|
"\0": RegExp("\\\0"),
|
||||||
|
"\x0B": RegExp("\\\x0B"),
|
||||||
|
"\u2028": RegExp("\\\u2028"),
|
||||||
|
"\u2029": RegExp("\\\u2029"),
|
||||||
|
};
|
||||||
|
for (var c in o)
|
||||||
|
console.log(o[c].test("\\"), o[c].test(c));
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"var o = {",
|
||||||
|
' "\\n": /\\n/,',
|
||||||
|
' "\\r": /\\r/,',
|
||||||
|
' "\\t": /\t/,',
|
||||||
|
' "\\b": /\b/,',
|
||||||
|
' "\\f": /\f/,',
|
||||||
|
' "\\0": /\0/,',
|
||||||
|
' "\\v": /\v/,',
|
||||||
|
' "\\u2028": /\\u2028/,',
|
||||||
|
' "\\u2029": /\\u2029/',
|
||||||
|
"};",
|
||||||
|
"",
|
||||||
|
'for (var c in o) console.log(o[c].test("\\\\"), o[c].test(c));',
|
||||||
|
]
|
||||||
|
expect_stdout: [
|
||||||
|
"false true",
|
||||||
|
"false true",
|
||||||
|
"false true",
|
||||||
|
"false true",
|
||||||
|
"false true",
|
||||||
|
"false true",
|
||||||
|
"false true",
|
||||||
|
"false true",
|
||||||
|
"false true",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3434_3: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
RegExp("\n");
|
||||||
|
RegExp("\r");
|
||||||
|
RegExp("\\n");
|
||||||
|
RegExp("\\\n");
|
||||||
|
RegExp("\\\\n");
|
||||||
|
RegExp("\\\\\n");
|
||||||
|
RegExp("\\\\\\n");
|
||||||
|
RegExp("\\\\\\\n");
|
||||||
|
RegExp("\u2028");
|
||||||
|
RegExp("\u2029");
|
||||||
|
RegExp("\n\r\u2028\u2029");
|
||||||
|
RegExp("\\\nfo\n[\n]o\\bbb");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
/\n/;
|
||||||
|
/\r/;
|
||||||
|
/\n/;
|
||||||
|
/\n/;
|
||||||
|
/\\n/;
|
||||||
|
/\\\n/;
|
||||||
|
/\\\n/;
|
||||||
|
/\\\n/;
|
||||||
|
/\u2028/;
|
||||||
|
/\u2029/;
|
||||||
|
/\n\r\u2028\u2029/;
|
||||||
|
/\nfo\n[\n]o\bbb/;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -960,12 +960,12 @@ if (require.main !== module) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function println(msg) {
|
function println(msg) {
|
||||||
if (typeof msg != "undefined") process.stdout.write(msg);
|
if (typeof msg != "undefined") process.stdout.write(typeof msg == "string" ? msg : msg.stack);
|
||||||
process.stdout.write("\n");
|
process.stdout.write("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
function errorln(msg) {
|
function errorln(msg) {
|
||||||
if (typeof msg != "undefined") process.stderr.write(msg);
|
if (typeof msg != "undefined") process.stderr.write(typeof msg == "string" ? msg : msg.stack);
|
||||||
process.stderr.write("\n");
|
process.stderr.write("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -980,7 +980,7 @@ function try_beautify(code, toplevel, result, printfn) {
|
|||||||
});
|
});
|
||||||
if (beautified.error) {
|
if (beautified.error) {
|
||||||
printfn("// !!! beautify failed !!!");
|
printfn("// !!! beautify failed !!!");
|
||||||
printfn(beautified.error.stack);
|
printfn(beautified.error);
|
||||||
} else if (sandbox.same_stdout(sandbox.run_code(beautified.code, toplevel), result)) {
|
} else if (sandbox.same_stdout(sandbox.run_code(beautified.code, toplevel), result)) {
|
||||||
printfn("// (beautified)");
|
printfn("// (beautified)");
|
||||||
printfn(beautified.code);
|
printfn(beautified.code);
|
||||||
@@ -1007,7 +1007,7 @@ function log_suspects(minify_options, component) {
|
|||||||
var result = UglifyJS.minify(original_code, m);
|
var result = UglifyJS.minify(original_code, m);
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
errorln("Error testing options." + component + "." + name);
|
errorln("Error testing options." + component + "." + name);
|
||||||
errorln(result.error.stack);
|
errorln(result.error);
|
||||||
} else {
|
} else {
|
||||||
var r = sandbox.run_code(result.code, m.toplevel);
|
var r = sandbox.run_code(result.code, m.toplevel);
|
||||||
return sandbox.same_stdout(original_result, r);
|
return sandbox.same_stdout(original_result, r);
|
||||||
@@ -1029,7 +1029,7 @@ function log_rename(options) {
|
|||||||
var result = UglifyJS.minify(original_code, m);
|
var result = UglifyJS.minify(original_code, m);
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
errorln("Error testing options.rename");
|
errorln("Error testing options.rename");
|
||||||
errorln(result.error.stack);
|
errorln(result.error);
|
||||||
} else {
|
} else {
|
||||||
var r = sandbox.run_code(result.code, m.toplevel);
|
var r = sandbox.run_code(result.code, m.toplevel);
|
||||||
if (sandbox.same_stdout(original_result, r)) {
|
if (sandbox.same_stdout(original_result, r)) {
|
||||||
@@ -1056,17 +1056,17 @@ function log(options) {
|
|||||||
errorln();
|
errorln();
|
||||||
errorln();
|
errorln();
|
||||||
errorln("original result:");
|
errorln("original result:");
|
||||||
errorln(errored ? original_result.stack : original_result);
|
errorln(original_result);
|
||||||
errorln("uglified result:");
|
errorln("uglified result:");
|
||||||
errorln(typeof uglify_result == "string" ? uglify_result : uglify_result.stack);
|
errorln(uglify_result);
|
||||||
} else {
|
} else {
|
||||||
errorln("// !!! uglify failed !!!");
|
errorln("// !!! uglify failed !!!");
|
||||||
errorln(uglify_code.stack);
|
errorln(uglify_code);
|
||||||
if (errored) {
|
if (errored) {
|
||||||
errorln();
|
errorln();
|
||||||
errorln();
|
errorln();
|
||||||
errorln("original stacktrace:");
|
errorln("original stacktrace:");
|
||||||
errorln(original_result.stack);
|
errorln(original_result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
errorln("minify(options):");
|
errorln("minify(options):");
|
||||||
@@ -1115,7 +1115,7 @@ for (var round = 1; round <= num_iterations; round++) {
|
|||||||
println();
|
println();
|
||||||
println();
|
println();
|
||||||
println("original result:");
|
println("original result:");
|
||||||
println(original_result.stack);
|
println(original_result);
|
||||||
println();
|
println();
|
||||||
}
|
}
|
||||||
if (!ok && isFinite(num_iterations)) {
|
if (!ok && isFinite(num_iterations)) {
|
||||||
|
|||||||
@@ -2993,6 +2993,7 @@
|
|||||||
"caption",
|
"caption",
|
||||||
"caption-side",
|
"caption-side",
|
||||||
"captionSide",
|
"captionSide",
|
||||||
|
"capture",
|
||||||
"captureEvents",
|
"captureEvents",
|
||||||
"captureStackTrace",
|
"captureStackTrace",
|
||||||
"captureStream",
|
"captureStream",
|
||||||
@@ -4957,6 +4958,7 @@
|
|||||||
"oncandidatewindowupdate",
|
"oncandidatewindowupdate",
|
||||||
"oncanplay",
|
"oncanplay",
|
||||||
"oncanplaythrough",
|
"oncanplaythrough",
|
||||||
|
"once",
|
||||||
"oncellchange",
|
"oncellchange",
|
||||||
"onchange",
|
"onchange",
|
||||||
"onchargingchange",
|
"onchargingchange",
|
||||||
@@ -5343,6 +5345,7 @@
|
|||||||
"parseInt",
|
"parseInt",
|
||||||
"part",
|
"part",
|
||||||
"participants",
|
"participants",
|
||||||
|
"passive",
|
||||||
"password",
|
"password",
|
||||||
"pasteHTML",
|
"pasteHTML",
|
||||||
"path",
|
"path",
|
||||||
|
|||||||
@@ -1,21 +1,19 @@
|
|||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
|
||||||
exports.FILES = [
|
exports.FILES = [
|
||||||
"../lib/utils.js",
|
require.resolve("../lib/utils.js"),
|
||||||
"../lib/ast.js",
|
require.resolve("../lib/ast.js"),
|
||||||
"../lib/parse.js",
|
require.resolve("../lib/parse.js"),
|
||||||
"../lib/transform.js",
|
require.resolve("../lib/transform.js"),
|
||||||
"../lib/scope.js",
|
require.resolve("../lib/scope.js"),
|
||||||
"../lib/output.js",
|
require.resolve("../lib/output.js"),
|
||||||
"../lib/compress.js",
|
require.resolve("../lib/compress.js"),
|
||||||
"../lib/sourcemap.js",
|
require.resolve("../lib/sourcemap.js"),
|
||||||
"../lib/mozilla-ast.js",
|
require.resolve("../lib/mozilla-ast.js"),
|
||||||
"../lib/propmangle.js",
|
require.resolve("../lib/propmangle.js"),
|
||||||
"../lib/minify.js",
|
require.resolve("../lib/minify.js"),
|
||||||
"./exports.js",
|
require.resolve("./exports.js"),
|
||||||
].map(function(file) {
|
];
|
||||||
return require.resolve(file);
|
|
||||||
});
|
|
||||||
|
|
||||||
new Function("MOZ_SourceMap", "exports", function() {
|
new Function("MOZ_SourceMap", "exports", function() {
|
||||||
var code = exports.FILES.map(function(file) {
|
var code = exports.FILES.map(function(file) {
|
||||||
|
|||||||
Reference in New Issue
Block a user