fix corner cases in typeofs (#5301)

This commit is contained in:
Alex Lam S.L
2022-01-17 06:03:41 +00:00
committed by GitHub
parent 43807c26fb
commit 35d7f316ef
3 changed files with 139 additions and 7 deletions

View File

@@ -8715,6 +8715,7 @@ Compressor.prototype.compress = function(node) {
});
function mark_locally_defined(condition, consequent, alternative) {
if (condition instanceof AST_Sequence) condition = condition.tail_node();
if (!(condition instanceof AST_Binary)) return;
if (!(condition.left instanceof AST_String)) {
switch (condition.operator) {
@@ -8749,6 +8750,8 @@ Compressor.prototype.compress = function(node) {
var abort = false;
var def = sym.definition();
var fn;
var refs = [];
var scanned = [];
var tw = new TreeWalker(function(node, descend) {
if (abort) return true;
if (node instanceof AST_Assign) {
@@ -8765,11 +8768,40 @@ Compressor.prototype.compress = function(node) {
if (node instanceof AST_Call) {
descend();
fn = node.expression.tail_node();
if (fn instanceof AST_Lambda) {
fn.walk(tw);
} else {
abort = true;
var save;
if (fn instanceof AST_SymbolRef) {
fn = fn.fixed_value();
save = refs.length;
}
if (!(fn instanceof AST_Lambda)) {
abort = true;
} else if (push_uniq(scanned, fn)) {
fn.walk(tw);
}
if (save >= 0) refs.length = save;
return true;
}
if (node instanceof AST_DWLoop) {
var save = refs.length;
descend();
if (abort) refs.length = save;
return true;
}
if (node instanceof AST_For) {
if (node.init) node.init.walk(tw);
var save = refs.length;
if (node.condition) node.condition.walk(tw);
node.body.walk(tw);
if (node.step) node.step.walk(tw);
if (abort) refs.length = save;
return true;
}
if (node instanceof AST_ForEnumeration) {
node.object.walk(tw);
var save = refs.length;
node.init.walk(tw);
node.body.walk(tw);
if (abort) refs.length = save;
return true;
}
if (node instanceof AST_Scope) {
@@ -8777,11 +8809,14 @@ Compressor.prototype.compress = function(node) {
return true;
}
if (node instanceof AST_SymbolRef) {
if (node.definition() === def) node.defined = true;
if (node.definition() === def) refs.push(node);
return true;
}
});
body.walk(tw);
refs.forEach(function(ref) {
ref.defined = true;
});
function negate(node) {
if (!(node instanceof AST_Binary)) return;