fix invalid transform on const (#1919)
- preserve (re)assignment to `const` for runtime error - suppress `cascade` on `const`, as runtime behaviour is ill-defined
This commit is contained in:
@@ -440,6 +440,14 @@ merge(Compressor.prototype, {
|
||||
return fixed();
|
||||
});
|
||||
|
||||
function is_reference_const(ref) {
|
||||
if (!(ref instanceof AST_SymbolRef)) return false;
|
||||
var orig = ref.definition().orig;
|
||||
for (var i = orig.length; --i >= 0;) {
|
||||
if (orig[i] instanceof AST_SymbolConst) return true;
|
||||
}
|
||||
}
|
||||
|
||||
function find_variable(compressor, name) {
|
||||
var scope, i = 0;
|
||||
while (scope = compressor.parent(i++)) {
|
||||
@@ -1909,6 +1917,7 @@ merge(Compressor.prototype, {
|
||||
&& node instanceof AST_Assign
|
||||
&& node.operator == "="
|
||||
&& node.left instanceof AST_SymbolRef
|
||||
&& !is_reference_const(node.left)
|
||||
&& scope === self) {
|
||||
node.right.walk(tw);
|
||||
return true;
|
||||
@@ -3066,7 +3075,8 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
if (left
|
||||
&& !(left instanceof AST_SymbolRef
|
||||
&& left.definition().orig[0] instanceof AST_SymbolLambda)) {
|
||||
&& (left.definition().orig[0] instanceof AST_SymbolLambda
|
||||
|| is_reference_const(left)))) {
|
||||
var parent, field;
|
||||
var cdr = self.cdr;
|
||||
while (true) {
|
||||
|
||||
Reference in New Issue
Block a user