Skip to content

Commit 461ad21

Browse files
committed
feature: @putout/plugin-minify: merge-variables: include let
1 parent 0d38ed5 commit 461ad21

File tree

11 files changed

+16
-27
lines changed

11 files changed

+16
-27
lines changed

packages/plugin-minify/lib/merge-variables/fixture/await-fix.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
async function onChange(a) {
2-
var b = a.target, e = document.getElementById(target);
3-
let c = b.value;
2+
var b = a.target, c = b.value, e = document.getElementById(target);
43

54
type == 'email' && (c = c.split('@')[1]);
65

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let a = 'hello', b = '("' + a + '")';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let a='hello';let b='("'+a+'")';

packages/plugin-minify/lib/merge-variables/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ export const traverse = ({push, uplist}) => ({
1818
if (path.parentPath.node.declarations.length !== 1)
1919
return;
2020

21-
if (path.parentPath.node.kind === 'let')
22-
return;
23-
2421
const initPath = path.get('init');
2522

2623
if (initPath.isAwaitExpression())

packages/plugin-minify/lib/merge-variables/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ test('plugin-minify: merge-variables: no report: for-of', (t) => {
7878
t.end();
7979
});
8080

81+
test('plugin-minify: merge-variables: transform: let-couple', (t) => {
82+
t.transform('let-couple');
83+
t.end();
84+
});
85+
8186
test('plugin-minify: merge-variables: transform: remove-unreferenced-variables', (t) => {
8287
t.transform('remove-unreferenced-variables', {
8388
'remove-unreferenced-variables': removeUnreferencedVariables,

packages/plugin-minify/test/fixture/extract-body-fix.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
if (x)
22
return;
33

4-
let x = () => m;
5-
let y = () => m();
4+
let x = () => m, y = () => m();
65

76
function z() {
87
return hello;

packages/plugin-minify/test/fixture/mangle-names-fix.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
function A() {
2-
let a = 5;
3-
let b = 7;
4-
let c = 8;
5-
6-
let d = 'hello';
2+
let a = 5, b = 7, c = 8, d = 'hello';
73

84
function e() {
95
return A;

packages/plugin-minify/test/fixture/merge-destructuring-properties-fix.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
const {defineProperty: a, keys: b} = Object;
2-
let c = null;
3-
let d = 1073741823;
1+
const {defineProperty: a} = Object;
2+
let c = null, d = 1073741823, {keys: b} = Object;
43

54
function A(...e) {
65
if (n)
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
var a, b;
22

3-
if (a > 3) {
4-
const b = 5;
5-
let d = 3;
6-
}
3+
if (a > 3)
4+
const b = 5, d = 3;
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
async function a(A) {
2-
let b = A.target;
3-
4-
let c = b.value;
2+
let b = A.target, c = b.value, e = document.getElementById(b.dataset.resultElement);
53

64
type == 'email' && (c = c.split('@')[1]);
75

86
let d = await checkDomain(c);
97

10-
let e = document.getElementById(b.dataset.resultElement);
11-
128
e.innerHTML = `Result: ${d.data}`;
139
}

0 commit comments

Comments
 (0)