fix corner case in inline (#5410)

fixes #5409
This commit is contained in:
Alex Lam S.L
2022-04-06 05:23:47 +01:00
committed by GitHub
parent ccd77d70db
commit 998c9792da
4 changed files with 50 additions and 20 deletions

View File

@@ -13160,6 +13160,19 @@ Compressor.prototype.compress = function(node) {
return found;
}
function insert_assign(def, assign) {
var visited = [];
def.references.forEach(function(ref) {
var fixed = ref.fixed;
if (!fixed || !push_uniq(visited, fixed)) return;
if (fixed.assigns) {
fixed.assigns.unshift(assign);
} else {
fixed.assigns = [ assign ];
}
});
}
function init_ref(compressor, name) {
var sym = make_node(AST_SymbolRef, name, name);
var assign = make_node(AST_Assign, name, {
@@ -13173,16 +13186,7 @@ Compressor.prototype.compress = function(node) {
return assign.right;
};
sym.fixed.assigns = [ assign ];
var visited = [];
def.references.forEach(function(ref) {
var fixed = ref.fixed;
if (!fixed || !push_uniq(visited, fixed)) return;
if (fixed.assigns) {
fixed.assigns.unshift(assign);
} else {
fixed.assigns = [ assign ];
}
});
insert_assign(def, assign);
}
def.assignments++;
def.references.push(sym);
@@ -13391,12 +13395,12 @@ Compressor.prototype.compress = function(node) {
if (value) body.push(make_node(AST_SimpleStatement, call, { body: value }));
return;
}
body.push(make_node(AST_Var, call, {
definitions: [ make_node(AST_VarDef, call, {
name: argname.convert_symbol(AST_SymbolVar, process),
value: value || make_node(AST_Undefined, call).transform(compressor),
}) ],
}));
var defn = make_node(AST_VarDef, call, {
name: argname.convert_symbol(AST_SymbolVar, process),
value: value || make_node(AST_Undefined, call).transform(compressor),
});
if (argname instanceof AST_SymbolFunarg) insert_assign(argname.definition(), defn);
body.push(make_node(AST_Var, call, { definitions: [ defn ] }));
});
if (values.length) body.push(make_node(AST_SimpleStatement, call, {
body: make_sequence(call, values),

View File

@@ -8370,3 +8370,31 @@ issue_5401: {
}
expect_stdout: "PASS"
}
issue_5409: {
options = {
inline: true,
merge_vars: true,
reduce_vars: true,
unused: true,
}
input: {
(function(a) {
(a = console) || FAIL(a);
(function(b) {
console.log(b && b);
while (!console);
})();
})();
}
expect: {
(function(a) {
(a = console) || FAIL(a);
a = void 0;
console.log(a && a);
while (!console);
return;
})();
}
expect_stdout: "undefined"
}

View File

@@ -1258,8 +1258,7 @@ issues_3267_1: {
}
expect: {
!function() {
var i = Object();
if (i)
if (Object())
return console.log("PASS");
throw "FAIL";
}();

View File

@@ -6689,8 +6689,7 @@ issues_3267_1: {
}
expect: {
!function(x) {
var i = Object();
if (i)
if (Object())
return console.log("PASS");
throw "FAIL";
}();