aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-10-06 02:20:41 +0100
committerGitHub <noreply@github.com>2020-10-06 09:20:41 +0800
commitbc6e105174eb67547c2bd988899e4c4f2d8f6ada (patch)
tree723a511070cf6cd526c9ec0e8bc51f36b430a616 /lib
parentb91a2459c0f270b770c5d105df75f78c16af4749 (diff)
downloadtracifyjs-bc6e105174eb67547c2bd988899e4c4f2d8f6ada.tar.gz
tracifyjs-bc6e105174eb67547c2bd988899e4c4f2d8f6ada.zip
fix corner case in `ie8` (#4187)
fixes #4186
Diffstat (limited to 'lib')
-rw-r--r--lib/ast.js3
-rw-r--r--lib/compress.js23
2 files changed, 18 insertions, 8 deletions
diff --git a/lib/ast.js b/lib/ast.js
index 08b4b65c..ac779cb9 100644
--- a/lib/ast.js
+++ b/lib/ast.js
@@ -282,9 +282,6 @@ var AST_BlockScope = DEFNODE("BlockScope", "cname enclosed functions make_def pa
var AST_BlockStatement = DEFNODE("BlockStatement", null, {
$documentation: "A block statement",
- initialize: function() {
- this.variables = new Dictionary();
- },
}, AST_BlockScope);
var AST_EmptyStatement = DEFNODE("EmptyStatement", null, {
diff --git a/lib/compress.js b/lib/compress.js
index 8c28d450..29cc82a9 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1018,6 +1018,13 @@ merge(Compressor.prototype, {
return sym instanceof AST_SymbolLambda && def.scope.name === sym;
});
+ function find_scope(compressor) {
+ var level = 0, node;
+ while (node = compressor.parent(level++)) {
+ if (node.variables) return node;
+ }
+ }
+
function is_lhs_read_only(lhs, compressor) {
if (lhs instanceof AST_This) return true;
if (lhs instanceof AST_SymbolRef) {
@@ -6885,7 +6892,7 @@ merge(Compressor.prototype, {
&& !fn.pinned()
&& !(fn.name && fn instanceof AST_Function)
&& (exp === fn || !recursive_ref(compressor, def = exp.definition())
- && fn.is_constant_expression(compressor.find_parent(AST_BlockScope)))
+ && fn.is_constant_expression(find_scope(compressor)))
&& (value = can_flatten_body(stat))
&& !fn.contains_this()) {
var replacing = exp === fn || compressor.option("unused") && def.references.length - def.replaced == 1;
@@ -8303,9 +8310,16 @@ merge(Compressor.prototype, {
return lhs instanceof AST_SymbolRef || lhs.TYPE === self.TYPE;
}
+ function find_variable(compressor, name) {
+ var level = 0, node;
+ while (node = compressor.parent(level++)) {
+ if (node.variables) return node.find_variable(name);
+ }
+ }
+
OPT(AST_Undefined, function(self, compressor) {
if (compressor.option("unsafe_undefined")) {
- var undef = compressor.find_parent(AST_BlockScope).find_variable("undefined");
+ var undef = find_scope(compressor).find_variable("undefined");
if (undef) {
var ref = make_node(AST_SymbolRef, self, {
name : "undefined",
@@ -8331,7 +8345,7 @@ merge(Compressor.prototype, {
if (lhs && is_atomic(lhs, self)) return self;
if (compressor.option("keep_infinity")
&& !(lhs && !is_atomic(lhs, self))
- && !compressor.find_parent(AST_BlockScope).find_variable("Infinity"))
+ && !find_scope(compressor).find_variable("Infinity"))
return self;
return make_node(AST_Binary, self, {
operator: "/",
@@ -8346,8 +8360,7 @@ merge(Compressor.prototype, {
OPT(AST_NaN, function(self, compressor) {
var lhs = is_lhs(compressor.self(), compressor.parent());
- if (lhs && !is_atomic(lhs, self)
- || compressor.find_parent(AST_BlockScope).find_variable("NaN")) {
+ if (lhs && !is_atomic(lhs, self) || find_scope(compressor).find_variable("NaN")) {
return make_node(AST_Binary, self, {
operator: "/",
left: make_node(AST_Number, self, {