fix hoist_props on const (#2724)

fixes #2710
This commit is contained in:
Alex Lam S.L
2018-01-05 06:23:53 +08:00
committed by GitHub
parent ffc64e2279
commit f76b5e0f43
2 changed files with 71 additions and 0 deletions

View File

@@ -3274,6 +3274,7 @@ merge(Compressor.prototype, {
&& (def = sym.definition()).escaped != 1
&& !def.single_use
&& !def.direct_access
&& !compressor.exposed(def)
&& !top_retain(def)
&& (value = sym.fixed_value()) === node.value
&& value instanceof AST_Object) {

View File

@@ -827,3 +827,73 @@ issue_2519: {
}
expect_stdout: "5.5"
}
toplevel_const: {
options = {
hoist_props: true,
reduce_vars: true,
toplevel: false,
}
input: {
const a = {
b: 1,
c: 2
};
console.log(a.b + a.c);
}
expect: {
const a = {
b: 1,
c: 2
};
console.log(a.b + a.c);
}
expect_stdout: "3"
}
toplevel_let: {
options = {
hoist_props: true,
reduce_vars: true,
toplevel: false,
}
input: {
let a = {
b: 1,
c: 2
};
console.log(a.b + a.c);
}
expect: {
let a = {
b: 1,
c: 2
};
console.log(a.b + a.c);
}
expect_stdout: "3"
node_version: ">=6"
}
toplevel_var: {
options = {
hoist_props: true,
reduce_vars: true,
toplevel: false,
}
input: {
var a = {
b: 1,
c: 2
};
console.log(a.b + a.c);
}
expect: {
var a = {
b: 1,
c: 2
};
console.log(a.b + a.c);
}
expect_stdout: "3"
}