aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-01-19 23:47:42 +0800
committerGitHub <noreply@github.com>2018-01-19 23:47:42 +0800
commit069df27bf18247a3e2f1d1a4abd0ee4fe28ef0ce (patch)
tree5c14f7b08aac48b1d8655ccac4faa08356d3251b /lib
parent3e7873217cad8b6f67839cb06d1e126ca231bc42 (diff)
downloadtracifyjs-069df27bf18247a3e2f1d1a4abd0ee4fe28ef0ce.tar.gz
tracifyjs-069df27bf18247a3e2f1d1a4abd0ee4fe28ef0ce.zip
enable `unsafe` for `test/ufuzz.js` (#2819)
- introduce `unsafe_undefined` - safer `.toString()` compression Miscellaneous - rename `unsafe_Function`
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js19
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 5235a05f..49185aec 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -84,10 +84,11 @@ function Compressor(options, false_by_default) {
typeofs : !false_by_default,
unsafe : false,
unsafe_comps : false,
- unsafe_Func : false,
+ unsafe_Function: false,
unsafe_math : false,
unsafe_proto : false,
unsafe_regexp : false,
+ unsafe_undefined: false,
unused : !false_by_default,
warnings : false,
}, true);
@@ -4100,11 +4101,13 @@ merge(Compressor.prototype, {
break;
} else if (exp instanceof AST_Dot) switch(exp.property) {
case "toString":
- if (self.args.length == 0) return make_node(AST_Binary, self, {
- left: make_node(AST_String, self, { value: "" }),
- operator: "+",
- right: exp.expression
- }).optimize(compressor);
+ if (self.args.length == 0 && !exp.expression.may_throw_on_access(compressor)) {
+ return make_node(AST_Binary, self, {
+ left: make_node(AST_String, self, { value: "" }),
+ operator: "+",
+ right: exp.expression
+ }).optimize(compressor);
+ }
break;
case "join":
if (exp.expression instanceof AST_Array) EXIT: {
@@ -4212,7 +4215,7 @@ merge(Compressor.prototype, {
break;
}
}
- if (compressor.option("unsafe_Func")
+ if (compressor.option("unsafe_Function")
&& is_undeclared_ref(exp)
&& exp.name == "Function") {
// new Function() => function(){}
@@ -5220,7 +5223,7 @@ merge(Compressor.prototype, {
}
OPT(AST_Undefined, function(self, compressor){
- if (compressor.option("unsafe")) {
+ if (compressor.option("unsafe_undefined")) {
var undef = find_variable(compressor, "undefined");
if (undef) {
var ref = make_node(AST_SymbolRef, self, {