improve unsafe on undefined (#1548)

`unsafe` turns undefined keyword into a variable of the same name if found, but that interferes with other related optimisations.

Keep track of such transformations to ensure zero information loss in the process.
This commit is contained in:
Alex Lam S.L
2017-03-05 13:09:27 +08:00
committed by GitHub
parent 1f0333e9f1
commit b33e7f88e6
3 changed files with 52 additions and 21 deletions

View File

@@ -2,6 +2,7 @@
unsafe_undefined: {
options = {
conditionals: true,
if_return: true,
unsafe: true
}
@@ -19,12 +20,7 @@ unsafe_undefined: {
expect: {
function f(n) {
return function() {
if (a)
return b;
if (c)
return d;
else
return n;
return a ? b : c ? d : n;
};
}
}
@@ -32,6 +28,7 @@ unsafe_undefined: {
keep_fnames: {
options = {
conditionals: true,
if_return: true,
unsafe: true
}
@@ -57,12 +54,7 @@ keep_fnames: {
function n(n) {
return n * n;
}
if (a)
return b;
if (c)
return d;
else
return r;
return a ? b : c ? d : r;
};
}
}