File tree Expand file tree Collapse file tree 2 files changed +59
-1
lines changed Expand file tree Collapse file tree 2 files changed +59
-1
lines changed Original file line number Diff line number Diff line change @@ -3285,14 +3285,24 @@ Compressor.prototype.compress = function(node) {
3285
3285
if (expr instanceof AST_Assign && expr.right.single_use) return;
3286
3286
var lhs_ids = Object.create(null);
3287
3287
var marker = new TreeWalker(function(node) {
3288
- if (node instanceof AST_SymbolRef) lhs_ids[node.definition().id] = true;
3288
+ if (!(node instanceof AST_SymbolRef)) return;
3289
+ for (var level = 0, parent, child = node; parent = marker.parent(level++); child = parent) {
3290
+ if (is_direct_assignment(child, parent)) {
3291
+ if (parent instanceof AST_DestructuredKeyVal) parent = marker.parent(level++);
3292
+ continue;
3293
+ }
3294
+ lhs_ids[node.definition().id] = true;
3295
+ return;
3296
+ }
3297
+ lhs_ids[node.definition().id] = "a";
3289
3298
});
3290
3299
while (expr instanceof AST_Assign && expr.operator == "=") {
3291
3300
expr.left.walk(marker);
3292
3301
expr = expr.right;
3293
3302
}
3294
3303
if (expr instanceof AST_ObjectIdentity) return rhs_exact_match;
3295
3304
if (expr instanceof AST_SymbolRef) {
3305
+ if (lhs_ids[expr.definition().id] === "a") return;
3296
3306
var value = expr.evaluate(compressor);
3297
3307
if (value === expr) return rhs_exact_match;
3298
3308
return rhs_fuzzy_match(value, rhs_exact_match);
Original file line number Diff line number Diff line change @@ -4241,3 +4241,51 @@ issue_5866_12: {
4241
4241
expect_stdout: "PASS"
4242
4242
node_version: ">=6"
4243
4243
}
4244
+
4245
+ issue_5899_1: {
4246
+ options = {
4247
+ collapse_vars : true ,
4248
+ }
4249
+ input: {
4250
+ var log = console . log , a , b ;
4251
+ a = "foo" ;
4252
+ log ( a && a ) ;
4253
+ b = { p : a } = a ;
4254
+ log ( a ) ;
4255
+ }
4256
+ expect: {
4257
+ var log = console . log , a , b ;
4258
+ log ( ( a = "foo" ) && a ) ;
4259
+ b = { p : a } = a ;
4260
+ log ( a ) ;
4261
+ }
4262
+ expect_stdout: [
4263
+ "foo" ,
4264
+ "undefined" ,
4265
+ ]
4266
+ node_version: ">=6"
4267
+ }
4268
+
4269
+ issue_5899_2: {
4270
+ options = {
4271
+ collapse_vars : true ,
4272
+ }
4273
+ input: {
4274
+ var log = console . log , a , b ;
4275
+ a = "foo" ;
4276
+ log ( a && a ) ;
4277
+ b = [ a ] = a ;
4278
+ log ( a ) ;
4279
+ }
4280
+ expect: {
4281
+ var log = console . log , a , b ;
4282
+ log ( ( a = "foo" ) && a ) ;
4283
+ b = [ a ] = a ;
4284
+ log ( a ) ;
4285
+ }
4286
+ expect_stdout: [
4287
+ "foo" ,
4288
+ "f" ,
4289
+ ]
4290
+ node_version: ">=6"
4291
+ }
You can’t perform that action at this time.
0 commit comments