Skip to content

Commit ab36b9b

Browse files
committed
fix corner case in ie8 (#3198)
fixes #3197
1 parent 2833091 commit ab36b9b

File tree

2 files changed

+137
-12
lines changed

2 files changed

+137
-12
lines changed

lib/scope.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,17 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
132132
node.thedef = node;
133133
node.references = [];
134134
}
135-
if (node instanceof AST_SymbolLambda) {
136-
defun.def_function(node, node.name == "arguments" ? undefined : defun);
137-
}
138-
else if (node instanceof AST_SymbolDefun) {
135+
if (node instanceof AST_SymbolDefun || options.ie8 && node instanceof AST_SymbolLambda) {
139136
// Careful here, the scope where this should be defined is
140137
// the parent scope. The reason is that we enter a new
141138
// scope when we encounter the AST_Defun node (which is
142139
// instanceof AST_Scope) but we get to the symbol a bit
143140
// later.
144141
(node.scope = defun.parent_scope).def_function(node, defun);
145142
}
143+
else if (node instanceof AST_SymbolLambda) {
144+
defun.def_function(node, node.name == "arguments" ? undefined : defun);
145+
}
146146
else if (node instanceof AST_SymbolVar) {
147147
defun.def_variable(node, node.TYPE == "SymbolVar" ? null : undefined);
148148
if (defun !== scope) {
@@ -349,9 +349,6 @@ function next_mangled_name(scope, options, def) {
349349
holes.push(scope.cname);
350350
}
351351
scope.names_in_use[name] = true;
352-
if (options.ie8 && def.orig[0] instanceof AST_SymbolLambda) {
353-
names_in_use(scope.parent_scope, options)[name] = true;
354-
}
355352
return name;
356353
}
357354

test/compress/ie8.js

+133-5
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ issue_24_2: {
420420
})();
421421
}
422422
expect: {
423-
(function(n) {
424-
console.log(typeof function o(){} === typeof n ? "FAIL" : "PASS");
423+
(function(o) {
424+
console.log(typeof function n(){} === typeof o ? "FAIL" : "PASS");
425425
})();
426426
}
427427
expect_stdout: "PASS"
@@ -457,9 +457,29 @@ issue_2976_2: {
457457
}());
458458
}
459459
expect: {
460-
console.log(function n() {
461-
var o;
462-
return o === n ? "FAIL" : "PASS";
460+
console.log(function f() {
461+
var n;
462+
return n === f ? "FAIL" : "PASS";
463+
}());
464+
}
465+
expect_stdout: "PASS"
466+
}
467+
468+
issue_2976_3: {
469+
mangle = {
470+
ie8: true,
471+
toplevel: true,
472+
}
473+
input: {
474+
console.log(function f() {
475+
var a;
476+
return a === f ? "FAIL" : "PASS";
477+
}());
478+
}
479+
expect: {
480+
console.log(function o() {
481+
var n;
482+
return n === o ? "FAIL" : "PASS";
463483
}());
464484
}
465485
expect_stdout: "PASS"
@@ -538,3 +558,111 @@ issue_3035_ie8: {
538558
}
539559
expect_stdout: "PASS"
540560
}
561+
562+
issue_3197_1: {
563+
options = {
564+
ie8: false,
565+
inline: true,
566+
reduce_vars: true,
567+
side_effects: true,
568+
unused: true,
569+
}
570+
mangle = {
571+
ie8: false,
572+
}
573+
input: {
574+
var window = {};
575+
!function() {
576+
function Foo() {
577+
console.log(this instanceof Foo);
578+
}
579+
window.Foo = Foo;
580+
}();
581+
new window.Foo();
582+
}
583+
expect: {
584+
var window = {};
585+
window.Foo = function o() {
586+
console.log(this instanceof o);
587+
};
588+
new window.Foo();
589+
}
590+
expect_stdout: "true"
591+
}
592+
593+
issue_3197_1_ie8: {
594+
options = {
595+
ie8: true,
596+
inline: true,
597+
reduce_vars: true,
598+
side_effects: true,
599+
unused: true,
600+
}
601+
mangle = {
602+
ie8: true,
603+
}
604+
input: {
605+
var window = {};
606+
!function() {
607+
function Foo() {
608+
console.log(this instanceof Foo);
609+
}
610+
window.Foo = Foo;
611+
}();
612+
new window.Foo();
613+
}
614+
expect: {
615+
var window = {};
616+
window.Foo = function Foo() {
617+
console.log(this instanceof Foo);
618+
};
619+
new window.Foo();
620+
}
621+
expect_stdout: "true"
622+
}
623+
624+
issue_3197_2: {
625+
mangle = {
626+
ie8: false,
627+
}
628+
input: {
629+
(function(a) {
630+
var f = function f() {
631+
console.log(this instanceof f);
632+
};
633+
new f(a);
634+
})();
635+
}
636+
expect: {
637+
(function(n) {
638+
var o = function n() {
639+
console.log(this instanceof n);
640+
};
641+
new o(n);
642+
})();
643+
}
644+
expect_stdout: "true"
645+
}
646+
647+
issue_3197_2_ie8: {
648+
mangle = {
649+
ie8: true,
650+
}
651+
input: {
652+
(function(a) {
653+
var f = function f() {
654+
console.log(this instanceof f);
655+
};
656+
new f(a);
657+
})();
658+
}
659+
expect: {
660+
(function(n) {
661+
var o = function o() {
662+
console.log(this instanceof o);
663+
};
664+
new o(n);
665+
})();
666+
}
667+
expect_stdout: "true"
668+
}

0 commit comments

Comments
 (0)