diff options
author | Richard van Velzen <rvanvelzen@experty.com> | 2016-04-12 20:30:44 +0200 |
---|---|---|
committer | Richard van Velzen <rvanvelzen@experty.com> | 2016-04-13 15:03:31 +0200 |
commit | 4b4528ee0552edb7ba1d24dad89e29880065e1c0 (patch) | |
tree | a015dbb287a2dd0ad27c95beb54dfc6ba0949a02 | |
parent | 187a0caf9d2b283387b57b71dea6aa133b266638 (diff) | |
download | tracifyjs-4b4528ee0552edb7ba1d24dad89e29880065e1c0.tar.gz tracifyjs-4b4528ee0552edb7ba1d24dad89e29880065e1c0.zip |
Prevent endless recursion when evaluating self-referencing consts
Fix #1041
-rw-r--r-- | lib/compress.js | 12 | ||||
-rw-r--r-- | test/compress/issue-1041.js | 39 |
2 files changed, 49 insertions, 2 deletions
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 || {}; + } +} |