From f436baa102c7f5fb5d4b56ad3c876e303b47900a Mon Sep 17 00:00:00 2001 From: gdh1995 Date: Thu, 29 Jul 2021 12:09:05 +0800 Subject: [PATCH 1/2] fix: functions in global_defs may be compressed mistakenly --- lib/compress/inference.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/compress/inference.js b/lib/compress/inference.js index 8853a838f..22b9b2c71 100644 --- a/lib/compress/inference.js +++ b/lib/compress/inference.js @@ -119,6 +119,7 @@ import { has_annotation, HOP } from "../utils/index.js"; +import { parse } from "../parse.js"; import { make_node_from_constant, make_sequence, best_of_expression, read_property } from "./common.js"; import { INLINED, UNDEFINED, has_flag } from "./compressor-flags.js"; @@ -688,7 +689,17 @@ 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 = parse(value.print_to_string(), { + expression: 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); From 1caaba9e73679fe1f7488a8ffaf98eb3c0cb1604 Mon Sep 17 00:00:00 2001 From: gdh1995 Date: Thu, 29 Jul 2021 12:21:51 +0800 Subject: [PATCH 2/2] fix: use node.clone instead of re-parsing --- lib/compress/inference.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/compress/inference.js b/lib/compress/inference.js index 22b9b2c71..0b825bfdd 100644 --- a/lib/compress/inference.js +++ b/lib/compress/inference.js @@ -119,7 +119,6 @@ import { has_annotation, HOP } from "../utils/index.js"; -import { parse } from "../parse.js"; import { make_node_from_constant, make_sequence, best_of_expression, read_property } from "./common.js"; import { INLINED, UNDEFINED, has_flag } from "./compressor-flags.js"; @@ -694,9 +693,7 @@ export function is_lhs(node, parent) { // 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 = parse(value.print_to_string(), { - expression: true - }); + value = value.clone(true); } return make_node(value.CTOR, orig, value); }