From 673b0716379e261008b6cbf187e6b212104fb69e Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 1 Jan 2018 00:09:26 +0800 Subject: enhance `join_vars` & `sequences` (#2697) - nudge declarations without assignments - within `AST_BlockStatement` - across `AST_If` --- test/compress/sequences.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'test/compress/sequences.js') diff --git a/test/compress/sequences.js b/test/compress/sequences.js index 81b06881..3d12fb0b 100644 --- a/test/compress/sequences.js +++ b/test/compress/sequences.js @@ -796,3 +796,66 @@ cascade_assignment_in_return: { } } } + +hoist_defun: { + options = { + join_vars: true, + sequences: true, + } + input: { + x(); + function f() {} + y(); + } + expect: { + function f() {} + x(), y(); + } +} + +hoist_decl: { + options = { + join_vars: true, + sequences: true, + } + input: { + var a; + w(); + var b = x(); + y(); + for (var c; 0;) z(); + var d; + } + expect: { + var a; + w(); + var b = x(), c, d; + for (y(); 0;) z(); + } +} + +for_init_var: { + options = { + join_vars: true, + unused: false, + } + input: { + var a = "PASS"; + (function() { + var b = 42; + for (var c = 5; c > 0;) c--; + a = "FAIL"; + var a; + })(); + console.log(a); + } + expect: { + var a = "PASS"; + (function() { + for (var b = 42, c = 5, a; c > 0;) c--; + a = "FAIL"; + })(); + console.log(a); + } + expect_stdout: "PASS" +} -- cgit v1.2.3