diff options
author | Mihai Bazon <mihai@bazon.net> | 2012-09-17 20:02:14 +0300 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2012-09-17 20:02:57 +0300 |
commit | d91613b4a8318b7fdd0d18cf6550e6670c59f71e (patch) | |
tree | 5f72c6834ec243e445902d1ef1cc6684f7e59547 /lib | |
parent | ee669ba8784a37805cd699cc0ca38e335982eb59 (diff) | |
download | tracifyjs-d91613b4a8318b7fdd0d18cf6550e6670c59f71e.tar.gz tracifyjs-d91613b4a8318b7fdd0d18cf6550e6670c59f71e.zip |
only do the typeof x == "undefined" optimization if x is a symbol reference and it's declared in scope, or x is not a symbol reference.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/compress.js b/lib/compress.js index ba6f809f..ca7bfe51 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1371,19 +1371,23 @@ function Compressor(options, false_by_default) { // XXX: intentionally falling down to the next case case "==": case "!=": - if (compressor.option("unsafe")) { - if (this.left instanceof AST_UnaryPrefix - && this.left.operator == "typeof" - && this.right instanceof AST_String - && this.right.value == "undefined") { + if (this.left instanceof AST_UnaryPrefix + && this.left.operator == "typeof" + && this.right instanceof AST_String + && this.right.value == "undefined") { + if (!(this.left.expression instanceof AST_SymbolRef) + || !this.left.expression.undeclared()) { this.left = this.left.expression; this.right = make_node(AST_Undefined, this.right).optimize(compressor); if (this.operator.length == 2) this.operator += "="; } - else if (this.left instanceof AST_String - && this.left.value == "undefined" - && this.right instanceof AST_UnaryPrefix - && this.right.operator == "typeof") { + } + else if (this.left instanceof AST_String + && this.left.value == "undefined" + && this.right instanceof AST_UnaryPrefix + && this.right.operator == "typeof") { + if (!(this.right.expression instanceof AST_SymbolRef) + || !this.right.expression.undeclared()) { this.left = this.right.expression; this.right = make_node(AST_Undefined, this.left).optimize(compressor); if (this.operator.length == 2) this.operator += "="; |