diff --git a/lib/compress.js b/lib/compress.js index 7f0cefcc..c955d2dd 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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) { diff --git a/test/compress/hoist_props.js b/test/compress/hoist_props.js index f572bd2d..0e05a8b5 100644 --- a/test/compress/hoist_props.js +++ b/test/compress/hoist_props.js @@ -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" +}