aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoralexlamsl <alexlamsl@gmail.com>2017-02-18 19:34:54 +0800
committeralexlamsl <alexlamsl@gmail.com>2017-02-21 13:29:58 +0800
commitec64acd2c8d8573abd5b77f8f8946767444841bb (patch)
tree73f4bbbfe5298777ae1ef19ae711d2c9dacb60dd /lib
parentac0b61ed6e1bce4794100c5bb83f6e5b22996d8a (diff)
downloadtracifyjs-ec64acd2c8d8573abd5b77f8f8946767444841bb.tar.gz
tracifyjs-ec64acd2c8d8573abd5b77f8f8946767444841bb.zip
introduce `unsafe_proto`
- `Array.prototype.slice` => `[].slice` closes #1491
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index cb99a173..237af72c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -54,6 +54,7 @@ function Compressor(options, false_by_default) {
drop_debugger : !false_by_default,
unsafe : false,
unsafe_comps : false,
+ unsafe_proto : false,
conditionals : !false_by_default,
comparisons : !false_by_default,
evaluate : !false_by_default,
@@ -3148,6 +3149,28 @@ merge(Compressor.prototype, {
})
}).optimize(compressor);
}
+ if (compressor.option("unsafe_proto")
+ && self.expression instanceof AST_Dot
+ && self.expression.property == "prototype") {
+ var exp = self.expression.expression;
+ if (exp instanceof AST_SymbolRef && exp.undeclared()) switch (exp.name) {
+ case "Array":
+ self.expression = make_node(AST_Array, self.expression, {
+ elements: []
+ });
+ break;
+ case "Object":
+ self.expression = make_node(AST_Object, self.expression, {
+ properties: []
+ });
+ break;
+ case "String":
+ self.expression = make_node(AST_String, self.expression, {
+ value: ""
+ });
+ break;
+ }
+ }
return self.evaluate(compressor)[0];
});