if (node instanceof AST_Unary && unary_arithmetic[node.operator]) modified(node.expression);
});
function modified(node) {
- if (node instanceof AST_Dot) {
- modified(node.expression);
- } else if (node instanceof AST_Sub) {
+ if (node instanceof AST_PropAccess) {
modified(node.expression);
- node.property.walk(scan_modified);
} else if (node instanceof AST_SymbolRef) {
node.definition().references.forEach(function(ref) {
delete ref._eval;
}
var op = this.operator;
var node;
- if (HOP(lhs, "_eval") || !(lhs instanceof AST_SymbolRef) || !lhs.fixed || !lhs.definition().fixed) {
- node = op == "=" ? this.right : make_node(AST_Binary, this, {
+ if (!HOP(lhs, "_eval") && lhs instanceof AST_SymbolRef && lhs.fixed && lhs.definition().fixed) {
+ node = lhs;
+ } else if (op == "=") {
+ lhs.walk(scan_modified);
+ node = this.right;
+ } else {
+ node = make_node(AST_Binary, this, {
operator: op.slice(0, -1),
left: lhs,
right: this.right,
});
- } else {
- node = lhs;
}
var value = node._eval(compressor, ignore_side_effects, cached, depth);
if (value === node) return this;
"true",
]
}
+
+issue_3997: {
+ options = {
+ evaluate: true,
+ reduce_vars: true,
+ toplevel: true,
+ }
+ input: {
+ var a = function f(b) {
+ return b[b += this] = b;
+ }(0);
+ console.log(typeof a);
+ }
+ expect: {
+ var a = function f(b) {
+ return b[b += this] = b;
+ }(0);
+ console.log(typeof a);
+ }
+ expect_stdout: "string"
+}