From 23e421119737f6501e8f5c37ac610eb52fbd6cf0 Mon Sep 17 00:00:00 2001 From: Dahan Gong Date: Sun, 22 Aug 2021 21:10:46 +0800 Subject: [PATCH] fix: functions in global_defs may be compressed mistakenly (#1036) * fix: functions in global_defs may be compressed mistakenly * fix: use node.clone instead of re-parsing --- lib/compress/inference.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/compress/inference.js b/lib/compress/inference.js index ce1f8fd67..4646bd733 100644 --- a/lib/compress/inference.js +++ b/lib/compress/inference.js @@ -688,7 +688,15 @@ export function is_lhs(node, parent) { (function(def_find_defs) { function to_node(value, orig) { - if (value instanceof AST_Node) return make_node(value.CTOR, orig, value); + if (value instanceof AST_Node) { + if (!(value instanceof AST_Constant)) { + // Value may be a function, an array including functions and even a complex assign / block expression, + // so it should never be shared in different places. + // Otherwise wrong information may be used in the compression phase + value = value.clone(true); + } + return make_node(value.CTOR, orig, value); + } if (Array.isArray(value)) return make_node(AST_Array, orig, { elements: value.map(function(value) { return to_node(value, orig);