Preserve ThisBinding in conditionals & collapse_vars

Fixes #973
This commit is contained in:
alexlamsl
2016-02-16 18:15:59 +08:00
committed by Richard van Velzen
parent 63b01fe8f9
commit 31a9b05c96
3 changed files with 78 additions and 19 deletions

View File

@@ -5,19 +5,19 @@ remove_redundant_sequence_items: {
(0, 1, _decorators.logThis)();
}
expect: {
(0, logThis)();
logThis();
(0, _decorators.logThis)();
}
}
dont_remove_lexical_binding_sequence: {
dont_remove_this_binding_sequence: {
options = { side_effects: true };
input: {
(0, logThis)();
(0, _decorators.logThis)();
}
expect: {
(0, logThis)();
logThis();
(0, _decorators.logThis)();
}
}

View File

@@ -0,0 +1,52 @@
this_binding_conditionals: {
options = {
conditionals: true,
evaluate : true
};
input: {
(1 && a)();
(0 || a)();
(0 || 1 && a)();
(1 ? a : 0)();
(1 && a.b)();
(0 || a.b)();
(0 || 1 && a.b)();
(1 ? a.b : 0)();
(1 && a[b])();
(0 || a[b])();
(0 || 1 && a[b])();
(1 ? a[b] : 0)();
}
expect: {
a();
a();
a();
a();
(0, a.b)();
(0, a.b)();
(0, a.b)();
(0, a.b)();
(0, a[b])();
(0, a[b])();
(0, a[b])();
(0, a[b])();
}
}
this_binding_collapse_vars: {
options = {
collapse_vars: true,
};
input: {
var c = a; c();
var d = a.b; d();
}
expect: {
a();
(0, a.b)();
}
}