exclude mangling of special property names

- `null`
- `true`
- `false`
- numeric literals
This commit is contained in:
alexlamsl 2017-04-04 01:35:58 +08:00
parent 48b3fe9952
commit dd3bde86de
2 changed files with 61 additions and 34 deletions

View File

@ -46,6 +46,9 @@
function find_builtins() {
// NaN will be included due to Number.NaN
var a = [
"null",
"true",
"false",
"Infinity",
"-Infinity",
"undefined",
@ -159,7 +162,7 @@ function mangle_properties(ast, options) {
if (options.only_cache) {
return cache.props.has(name);
}
if (/^[0-9.]+$/.test(name)) return false;
if (/^-?[0-9]+(\.[0-9]+)?(e[+-][0-9]+)?$/.test(name)) return false;
return true;
}

View File

@ -7,6 +7,9 @@ mangle_props: {
Infinity: 3,
"-Infinity": 4,
"-0": 5,
null: 6,
0x25: 7,
1e100: 8,
};
console.log(
obj[void 0],
@ -23,7 +26,16 @@ mangle_props: {
obj["-Infinity"],
obj[-0],
obj[-""],
obj["-0"]
obj["-0"],
obj[null],
obj["null"],
obj[0x25],
obj["0x25"],
obj[37],
obj["37"],
obj[1e100],
obj["1e100"],
obj["1e+100"]
);
}
expect: {
@ -32,7 +44,10 @@ mangle_props: {
NaN: 2,
Infinity: 3,
"-Infinity": 4,
a: 5,
"-0": 5,
null: 6,
37: 7,
1e100: 8,
};
console.log(
obj[void 0],
@ -49,10 +64,19 @@ mangle_props: {
obj["-Infinity"],
obj[-0],
obj[-""],
obj["a"]
obj["-0"],
obj[null],
obj["null"],
obj[37],
obj["a"],
obj[37],
obj["37"],
obj[1e100],
obj["b"],
obj["1e+100"]
);
}
expect_stdout: "1 1 1 2 2 2 3 3 3 4 4 4 undefined undefined 5"
expect_stdout: "1 1 1 2 2 2 3 3 3 4 4 4 undefined undefined 5 6 6 7 undefined 7 7 8 undefined 8"
}
identifier: {
@ -156,35 +180,35 @@ identifier: {
D: 30,
F: 31,
G: 32,
H: 33,
I: 34,
J: 35,
K: 36,
L: 37,
M: 38,
N: 39,
O: 40,
P: 41,
Q: 42,
R: 43,
S: 44,
T: 45,
U: 46,
V: 47,
W: 48,
X: 49,
Y: 50,
Z: 51,
$: 52,
_: 53,
aa: 54,
ba: 55,
ca: 56,
da: 57,
ea: 58,
fa: 59,
ga: 60,
ha: 61
false: 33,
null: 34,
true: 35,
H: 36,
I: 37,
J: 38,
K: 39,
L: 40,
M: 41,
N: 42,
O: 43,
P: 44,
Q: 45,
R: 46,
S: 47,
T: 48,
U: 49,
V: 50,
W: 51,
X: 52,
Y: 53,
Z: 54,
$: 55,
_: 56,
aa: 57,
ba: 58,
ca: 59,
da: 60,
ea: 61,
};
}
}