Skip to content

Commit d1ec24c

Browse files
committed
fix: @putout/plugin-minify: convert-let-to-var-inside-label -> convert-l
1 parent 3d8364b commit d1ec24c

File tree

13 files changed

+52
-31
lines changed

13 files changed

+52
-31
lines changed

packages/plugin-minify/.putout.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"split-variable-declarations": "off",
55
"assignment/split": "off",
66
"convert-template-to-string": "off",
7-
"conditions/convert-equal-to-strict-equal": "off"
7+
"conditions/convert-equal-to-strict-equal": "off",
8+
"conditions/evaluate": "off"
89
}
910
}
1011
}

packages/plugin-minify/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ npm i @putout/plugin-putout -D
1717
-[apply-ternary](#apply-ternary);
1818
-[convert-array-from-to-spread](#convert-array-from-to-spread);
1919
-[convert-const-to-let](#convert-const-to-let);
20-
-[convert-let-to-var-inside-label](#convert-let-to-var-inside-label);
20+
-[convert-let-to-var](#convert-let-to-var);
2121
-[convert-if-to-logical](#convert-if-to-logical);
2222
-[convert-return-to-sequence-expression](#convert-return-to-sequence-expression);
2323
-[convert-strict-equal-to-equal](#convert-strict-equal-to-equal);
@@ -43,7 +43,7 @@ npm i @putout/plugin-putout -D
4343
"minify/apply-ternary": "on",
4444
"minify/apply-template-literal": "on",
4545
"minify/convert-const-to-let": "on",
46-
"minify/convert-let-to-var-inside-label": "on",
46+
"minify/convert-let-to-var": "on",
4747
"minify/convert-if-to-logical": "on",
4848
"minify/convert-strict-equal-to-equal": "on",
4949
"minify/convert-array-from-to-spread": "on",
@@ -165,24 +165,30 @@ const a = 5;
165165
let a = 5;
166166
```
167167

168-
## convert-let-to-var-inside-label
168+
## convert-let-to-var
169169

170170
> `Lexical declaration cannot appear in a single-statement context`
171171
>
172172
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements#difference_between_statements_and_declarations)
173173
174-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b92716be2c378e440e0ba963bb284803/da777584a3382012787a8216e089f6bc84b98abe).
174+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/269edbd94999bc2ca919de7326a2c0fc/665350212e082c26d282e181da8506904322fd1b).
175175

176176
### ❌ Example of incorrect code
177177

178178
```
179179
javascript: let a = 3;
180+
181+
if (5)
182+
let b = 3;
180183
```
181184

182185
### ✅ Example of correct code
183186

184187
```js
185188
javascript: var a = 3;
189+
190+
if (5)
191+
var b = 3;
186192
```
187193

188194
## convert-return-to-sequence-expression

packages/plugin-minify/lib/convert-let-to-var-inside-label/fixture/convert-let-to-var-inside-label-fix.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/plugin-minify/lib/convert-let-to-var-inside-label/index.spec.js

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
javascript: var a = 3;if (a)
2+
var b = 3;

packages/plugin-minify/test/fixture/convert-let-to-var-inside-label.js renamed to packages/plugin-minify/lib/convert-let-to-var/fixture/convert-let-to-var.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
javascript: let a = 3;
2+
3+
if (a)
4+
let b = 3;

packages/plugin-minify/lib/convert-let-to-var-inside-label/index.js renamed to packages/plugin-minify/lib/convert-let-to-var/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import {types} from 'putout';
22

3-
const {isLabeledStatement} = types;
3+
const {
4+
isIfStatement,
5+
isLabeledStatement,
6+
} = types;
47

58
export const report = () => `Use 'var' instead of 'let' inside label`;
69

710
export const match = () => ({
811
'let __b = __c': (vars, path) => {
9-
return isLabeledStatement(path.parentPath);
12+
if (isLabeledStatement(path.parentPath))
13+
return true;
14+
15+
return isIfStatement(path.parentPath);
1016
},
1117
});
1218

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
3+
4+
const test = createTest(import.meta.url, {
5+
plugins: [
6+
['convert-let-to-var', plugin],
7+
],
8+
});
9+
10+
test('minify: convert-let-to-var: report', (t) => {
11+
t.report('convert-let-to-var', `Use 'var' instead of 'let' inside label`);
12+
t.end();
13+
});
14+
15+
test('minify: convert-let-to-var: transform', (t) => {
16+
t.transform('convert-let-to-var');
17+
t.end();
18+
});

packages/plugin-minify/lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as convertLetToVarInsideLabel from './convert-let-to-var-inside-label/index.js';
1+
import * as convertLetToVar from './convert-let-to-var/index.js';
22
import * as applyTernary from './apply-ternary/index.js';
33
import * as applyTemplateLiteral from './apply-template-literal/index.js';
44
import * as convertConstToLet from './convert-const-to-let/index.js';
@@ -39,5 +39,5 @@ export const rules = {
3939
'join-continued-strings': joinContinuedStrings,
4040
'convert-return-to-sequence-expression': convertReturnToSequenceExpression,
4141
'merge-assignment-expressions': mergeAssignmentExpressions,
42-
'convert-let-to-var-inside-label': convertLetToVarInsideLabel,
42+
'convert-let-to-var': convertLetToVar,
4343
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
javascript: var a = 3;if (a)
2+
var b = 3;

0 commit comments

Comments
 (0)