Skip to content

Commit 9e6b128

Browse files
authored
fix catch variable reference in IE8 (#1587)
`AST_Scope.def_variable()` will overwrite `AST_Symbol.thedef`, so save a copy before calling. fixes #1586
1 parent 93cdb19 commit 9e6b128

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/scope.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,10 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
212212
self.walk(new TreeWalker(function(node, descend) {
213213
if (node instanceof AST_SymbolCatch) {
214214
var name = node.name;
215+
var refs = node.thedef.references;
215216
var scope = node.thedef.scope.parent_scope;
216217
var def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node);
217-
node.thedef.references.forEach(function(ref) {
218+
refs.forEach(function(ref) {
218219
ref.thedef = def;
219220
ref.reference(options);
220221
});

test/compress/screw-ie8.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,39 @@ reduce_vars: {
182182
}
183183
}
184184
}
185+
186+
issue_1586_1: {
187+
options = {
188+
screw_ie8: false,
189+
}
190+
mangle = {
191+
screw_ie8: false,
192+
}
193+
input: {
194+
function f() {
195+
try {
196+
} catch (err) {
197+
console.log(err.message);
198+
}
199+
}
200+
}
201+
expect_exact: "function f(){try{}catch(c){console.log(c.message)}}"
202+
}
203+
204+
issue_1586_2: {
205+
options = {
206+
screw_ie8: true,
207+
}
208+
mangle = {
209+
screw_ie8: true,
210+
}
211+
input: {
212+
function f() {
213+
try {
214+
} catch (err) {
215+
console.log(err.message);
216+
}
217+
}
218+
}
219+
expect_exact: "function f(){try{}catch(c){console.log(c.message)}}"
220+
}

0 commit comments

Comments
 (0)