From: Richard van Velzen Date: Tue, 12 Apr 2016 18:30:44 +0000 (+0200) Subject: Prevent endless recursion when evaluating self-referencing consts X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=4b4528ee0552edb7ba1d24dad89e29880065e1c0;p=UglifyJS.git Prevent endless recursion when evaluating self-referencing consts Fix #1041 --- diff --git a/lib/compress.js b/lib/compress.js index 153e70fb..3e33c1b4 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1030,8 +1030,16 @@ merge(Compressor.prototype, { : ev(this.alternative, compressor); }); def(AST_SymbolRef, function(compressor){ - var d = this.definition(); - if (d && d.constant && d.init) return ev(d.init, compressor); + if (this._evaluating) throw def; + this._evaluating = true; + try { + var d = this.definition(); + if (d && d.constant && d.init) { + return ev(d.init, compressor); + } + } finally { + this._evaluating = false; + } throw def; }); def(AST_Dot, function(compressor){ diff --git a/test/compress/issue-1041.js b/test/compress/issue-1041.js new file mode 100644 index 00000000..9dd176fd --- /dev/null +++ b/test/compress/issue-1041.js @@ -0,0 +1,39 @@ +const_declaration: { + options = { + evaluate: true + }; + + input: { + const goog = goog || {}; + } + expect: { + const goog = goog || {}; + } +} + +const_pragma: { + options = { + evaluate: true + }; + + input: { + /** @const */ var goog = goog || {}; + } + expect: { + var goog = goog || {}; + } +} + +// for completeness' sake +not_const: { + options = { + evaluate: true + }; + + input: { + var goog = goog || {}; + } + expect: { + var goog = goog || {}; + } +}