From 200090a38d67e192ea1353e25514c691f3c64cc0 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Wed, 15 Mar 2017 23:24:38 +0800 Subject: [PATCH] add comments for #1602 --- lib/compress.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/compress.js b/lib/compress.js index dae1c4c3..b3004fb5 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -151,7 +151,17 @@ merge(Compressor.prototype, { node = node.hoist_declarations(this); was_scope = true; } + // Before https://github.com/mishoo/UglifyJS2/pull/1602 AST_Node.optimize() + // would call AST_Node.transform() if a different instance of AST_Node is + // produced after OPT(). + // This corrupts TreeWalker.stack, which cause AST look-ups to malfunction. + // Migrate and defer all children's AST_Node.transform() to below, which + // will now happen after this parent AST_Node has been properly substituted + // thus gives a consistent AST snapshot. descend(node, this); + // Existing code relies on how AST_Node.optimize() worked, and omitting the + // following replacement call would result in degraded efficiency of both + // output and performance. descend(node, this); var opt = node.optimize(this); if (was_scope && opt instanceof AST_Scope) {