Skip to content

Commit 200090a

Browse files
committed
add comments for #1602
1 parent 3787fc1 commit 200090a

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

lib/compress.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,17 @@ merge(Compressor.prototype, {
151151
node = node.hoist_declarations(this);
152152
was_scope = true;
153153
}
154+
// Before https://github.com/mishoo/UglifyJS2/pull/1602 AST_Node.optimize()
155+
// would call AST_Node.transform() if a different instance of AST_Node is
156+
// produced after OPT().
157+
// This corrupts TreeWalker.stack, which cause AST look-ups to malfunction.
158+
// Migrate and defer all children's AST_Node.transform() to below, which
159+
// will now happen after this parent AST_Node has been properly substituted
160+
// thus gives a consistent AST snapshot.
154161
descend(node, this);
162+
// Existing code relies on how AST_Node.optimize() worked, and omitting the
163+
// following replacement call would result in degraded efficiency of both
164+
// output and performance.
155165
descend(node, this);
156166
var opt = node.optimize(this);
157167
if (was_scope && opt instanceof AST_Scope) {

0 commit comments

Comments
 (0)