Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69931574e1 | ||
|
|
b5af8a1914 | ||
|
|
c14d09ba84 | ||
|
|
4fc39d8dad | ||
|
|
0b7c70f726 |
@@ -118,7 +118,8 @@ a double dash to prevent input files being used as option arguments:
|
|||||||
JS that was generated from some other original
|
JS that was generated from some other original
|
||||||
code. Specify "inline" if the source map is
|
code. Specify "inline" if the source map is
|
||||||
included within the sources.
|
included within the sources.
|
||||||
`filename` Name and/or location of the output source.
|
`filename` Filename and/or location of the output source
|
||||||
|
(sets `file` attribute in source map).
|
||||||
`includeSources` Pass this flag if you want to include
|
`includeSources` Pass this flag if you want to include
|
||||||
the content of source files in the
|
the content of source files in the
|
||||||
source map as sourcesContent property.
|
source map as sourcesContent property.
|
||||||
@@ -149,7 +150,9 @@ debugging your compressed JavaScript. To get a source map, pass
|
|||||||
|
|
||||||
Additional options:
|
Additional options:
|
||||||
|
|
||||||
- `--source-map "filename='<NAME>'"` to specify the name of the source map.
|
- `--source-map "filename='<NAME>'"` to specify the name of the source map. The value of
|
||||||
|
`filename` is only used to set `file` attribute (see [the spec][sm-spec])
|
||||||
|
in source map file.
|
||||||
|
|
||||||
- `--source-map "root='<URL>'"` to pass the URL where the original files can be found.
|
- `--source-map "root='<URL>'"` to pass the URL where the original files can be found.
|
||||||
|
|
||||||
|
|||||||
@@ -380,6 +380,16 @@ merge(Compressor.prototype, {
|
|||||||
mark(tw, def, true);
|
mark(tw, def, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
scope.may_call_this = function() {
|
||||||
|
scope.may_call_this = noop;
|
||||||
|
if (!scope.contains_this()) return;
|
||||||
|
scope.functions.each(function(def) {
|
||||||
|
if (def.init instanceof AST_Defun && !(def.id in tw.defun_ids)) {
|
||||||
|
tw.defun_ids[def.id] = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function mark_defun(tw, def) {
|
function mark_defun(tw, def) {
|
||||||
@@ -556,6 +566,7 @@ merge(Compressor.prototype, {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
def(AST_Call, function(tw, descend) {
|
def(AST_Call, function(tw, descend) {
|
||||||
|
if (tw.find_parent(AST_Scope).may_call_this()) return;
|
||||||
var exp = this.expression;
|
var exp = this.expression;
|
||||||
if (!(exp instanceof AST_SymbolRef)) return;
|
if (!(exp instanceof AST_SymbolRef)) return;
|
||||||
var def = exp.definition();
|
var def = exp.definition();
|
||||||
@@ -1240,7 +1251,10 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function should_stop(node, parent) {
|
function should_stop(node, parent) {
|
||||||
if (node instanceof AST_Assign) return node.operator != "=" && lhs.equivalent_to(node.left);
|
if (parent instanceof AST_For) return node !== parent.init;
|
||||||
|
if (node instanceof AST_Assign) {
|
||||||
|
return node.operator != "=" && lhs.equivalent_to(node.left);
|
||||||
|
}
|
||||||
if (node instanceof AST_Call) {
|
if (node instanceof AST_Call) {
|
||||||
return lhs instanceof AST_PropAccess && lhs.equivalent_to(node.expression);
|
return lhs instanceof AST_PropAccess && lhs.equivalent_to(node.expression);
|
||||||
}
|
}
|
||||||
@@ -1249,7 +1263,6 @@ merge(Compressor.prototype, {
|
|||||||
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;
|
||||||
if (node instanceof AST_With) return true;
|
if (node instanceof AST_With) return true;
|
||||||
if (parent instanceof AST_For) return node !== parent.init;
|
|
||||||
if (replace_all) return false;
|
if (replace_all) return false;
|
||||||
return node instanceof AST_SymbolRef && !node.is_declared(compressor);
|
return node instanceof AST_SymbolRef && !node.is_declared(compressor);
|
||||||
}
|
}
|
||||||
@@ -6276,7 +6289,7 @@ merge(Compressor.prototype, {
|
|||||||
return self;
|
return self;
|
||||||
});
|
});
|
||||||
|
|
||||||
AST_Lambda.DEFMETHOD("contains_this", function() {
|
AST_Scope.DEFMETHOD("contains_this", function() {
|
||||||
var result;
|
var result;
|
||||||
var self = this;
|
var self = this;
|
||||||
self.walk(new TreeWalker(function(node) {
|
self.walk(new TreeWalker(function(node) {
|
||||||
|
|||||||
@@ -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.3.25",
|
"version": "3.3.27",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4931,6 +4931,27 @@ collapse_rhs_lhs_2: {
|
|||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
collapse_rhs_loop: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var s;
|
||||||
|
s = "<tpl>PASS</tpl>";
|
||||||
|
for (var m, r = /<tpl>(.*)<\/tpl>/; m = s.match(r);)
|
||||||
|
s = s.replace(m[0], m[1]);
|
||||||
|
console.log(s);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var s;
|
||||||
|
s = "<tpl>PASS</tpl>";
|
||||||
|
for (var m, r = /<tpl>(.*)<\/tpl>/; m = s.match(r);)
|
||||||
|
s = s.replace(m[0], m[1]);
|
||||||
|
console.log(s);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
collapse_rhs_side_effects: {
|
collapse_rhs_side_effects: {
|
||||||
options = {
|
options = {
|
||||||
collapse_vars: true,
|
collapse_vars: true,
|
||||||
|
|||||||
@@ -6178,3 +6178,192 @@ issue_3125: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "7"
|
expect_stdout: "7"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3140_1: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var a;
|
||||||
|
function f() {
|
||||||
|
}
|
||||||
|
f.g = function g() {
|
||||||
|
function h() {
|
||||||
|
console.log(a ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
a = true;
|
||||||
|
this();
|
||||||
|
a = false;
|
||||||
|
h.g = g;
|
||||||
|
return h;
|
||||||
|
};
|
||||||
|
return f;
|
||||||
|
})().g().g();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
var a;
|
||||||
|
function f() {
|
||||||
|
}
|
||||||
|
f.g = function g() {
|
||||||
|
function h() {
|
||||||
|
console.log(a ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
a = true;
|
||||||
|
this();
|
||||||
|
a = false;
|
||||||
|
h.g = g;
|
||||||
|
return h;
|
||||||
|
};
|
||||||
|
return f;
|
||||||
|
})().g().g();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3140_2: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var a;
|
||||||
|
function f() {
|
||||||
|
}
|
||||||
|
f.g = function g() {
|
||||||
|
var self = this;
|
||||||
|
function h() {
|
||||||
|
console.log(a ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
a = true;
|
||||||
|
self();
|
||||||
|
a = false;
|
||||||
|
h.g = g;
|
||||||
|
return h;
|
||||||
|
};
|
||||||
|
return f;
|
||||||
|
})().g().g();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
var a;
|
||||||
|
function f() {
|
||||||
|
}
|
||||||
|
f.g = function g() {
|
||||||
|
function h() {
|
||||||
|
console.log(a ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
a = true;
|
||||||
|
this();
|
||||||
|
a = false;
|
||||||
|
h.g = g;
|
||||||
|
return h;
|
||||||
|
};
|
||||||
|
return f;
|
||||||
|
})().g().g();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3140_3: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var a;
|
||||||
|
function f() {
|
||||||
|
}
|
||||||
|
f.g = function g() {
|
||||||
|
var self = this;
|
||||||
|
function h() {
|
||||||
|
console.log(a ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
a = true;
|
||||||
|
(function() {
|
||||||
|
return self;
|
||||||
|
})()();
|
||||||
|
a = false;
|
||||||
|
h.g = g;
|
||||||
|
return h;
|
||||||
|
};
|
||||||
|
return f;
|
||||||
|
})().g().g();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
var a;
|
||||||
|
function f() {
|
||||||
|
}
|
||||||
|
f.g = function g() {
|
||||||
|
var self = this;
|
||||||
|
function h() {
|
||||||
|
console.log(a ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
a = true;
|
||||||
|
(function() {
|
||||||
|
return self;
|
||||||
|
})()();
|
||||||
|
a = false;
|
||||||
|
h.g = g;
|
||||||
|
return h;
|
||||||
|
};
|
||||||
|
return f;
|
||||||
|
})().g().g();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3140_4: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function() {
|
||||||
|
var a;
|
||||||
|
function f() {
|
||||||
|
}
|
||||||
|
f.g = function g() {
|
||||||
|
var o = {
|
||||||
|
p: this
|
||||||
|
};
|
||||||
|
function h() {
|
||||||
|
console.log(a ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
a = true;
|
||||||
|
o.p();
|
||||||
|
a = false;
|
||||||
|
h.g = g;
|
||||||
|
return h;
|
||||||
|
};
|
||||||
|
return f;
|
||||||
|
})().g().g();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function() {
|
||||||
|
var a;
|
||||||
|
function f() {
|
||||||
|
}
|
||||||
|
f.g = function g() {
|
||||||
|
var o = {
|
||||||
|
p: this
|
||||||
|
};
|
||||||
|
function h() {
|
||||||
|
console.log(a ? "PASS" : "FAIL");
|
||||||
|
}
|
||||||
|
a = true;
|
||||||
|
o.p();
|
||||||
|
a = false;
|
||||||
|
h.g = g;
|
||||||
|
return h;
|
||||||
|
};
|
||||||
|
return f;
|
||||||
|
})().g().g();
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user