diff --git a/lib/compress.js b/lib/compress.js index d8a0bd7c..15a2f656 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -625,8 +625,10 @@ merge(Compressor.prototype, { function mark_escaped(d, node, value, level) { var parent = tw.parent(level); - if (value instanceof AST_Constant) return; - if (level > 0 && value instanceof AST_Function) return; + if (value) { + if (value.is_constant()) return; + if (level > 0 && value.is_constant_expression()) return; + } if (parent instanceof AST_Assign && parent.operator == "=" && node === parent.right || parent instanceof AST_Call && node !== parent.expression || parent instanceof AST_Return && node === parent.value && node.scope !== d.scope diff --git a/test/compress/hoist_props.js b/test/compress/hoist_props.js index 40d36ace..176cd9a8 100644 --- a/test/compress/hoist_props.js +++ b/test/compress/hoist_props.js @@ -500,3 +500,51 @@ issue_2473_4: { } expect_stdout: "1 2" } + +issue_2508_1: { + options = { + collapse_vars: true, + hoist_props: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + var o = { + a: [ 1 ], + f: function(x) { + console.log(x); + } + }; + o.f(o.a); + } + expect: { + (function(x) { + console.log(x); + })([ 1 ]); + } +} + +issue_2508_2: { + options = { + collapse_vars: true, + hoist_props: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + var o = { + a: { b: 2 }, + f: function(x) { + console.log(x); + } + }; + o.f(o.a); + } + expect: { + (function(x) { + console.log(x); + })({ b: 2 }); + } +}