Prevent endless recursion when evaluating self-referencing consts
Fix #1041
This commit is contained in:
@@ -1030,8 +1030,16 @@ merge(Compressor.prototype, {
|
|||||||
: ev(this.alternative, compressor);
|
: ev(this.alternative, compressor);
|
||||||
});
|
});
|
||||||
def(AST_SymbolRef, function(compressor){
|
def(AST_SymbolRef, function(compressor){
|
||||||
var d = this.definition();
|
if (this._evaluating) throw def;
|
||||||
if (d && d.constant && d.init) return ev(d.init, compressor);
|
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;
|
throw def;
|
||||||
});
|
});
|
||||||
def(AST_Dot, function(compressor){
|
def(AST_Dot, function(compressor){
|
||||||
|
|||||||
39
test/compress/issue-1041.js
Normal file
39
test/compress/issue-1041.js
Normal file
@@ -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 || {};
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user