Skip to content

Commit

Permalink
fix: functions in global_defs may be compressed mistakenly (#1036)
Browse files Browse the repository at this point in the history
* fix: functions in global_defs may be compressed mistakenly

* fix: use node.clone instead of re-parsing
  • Loading branch information
gdh1995 committed Aug 22, 2021
1 parent c7cd53d commit 23e4211
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/compress/inference.js
Expand Up @@ -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);
Expand Down

0 comments on commit 23e4211

Please sign in to comment.