goldstein 4.10.0 → 4.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ 2023.10.19, v4.11.0
2
+
3
+ feature:
4
+ - 005959d goldstein: convert: if let
5
+
1
6
  2023.10.19, v4.10.0
2
7
 
3
8
  feature:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "goldstein",
3
- "version": "4.10.0",
3
+ "version": "4.11.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "JavaScript with no limits",
@@ -0,0 +1,18 @@
1
+ import {types} from 'putout';
2
+ const {
3
+ VariableDeclaration,
4
+ VariableDeclarator,
5
+ } = types;
6
+
7
+ export const report = () => `Use 'add-array'`;
8
+ export const replace = () => ({
9
+ '{let __a = __b; if (__c) __d}': ({__a, __b}, path) => {
10
+ const ifPath = path.get('body.1');
11
+ ifPath.node.test = VariableDeclaration('let', [
12
+ VariableDeclarator(__a, __b),
13
+ ]);
14
+
15
+ return ifPath;
16
+ },
17
+ });
18
+
@@ -4,6 +4,7 @@ import {print} from '../printer/index.js';
4
4
  import * as removeImportTry from './remove-import-try/index.js';
5
5
  import * as applyTry from './apply-try/index.js';
6
6
  import * as addArray from './add-array/index.js';
7
+ import * as applyIfLet from './apply-if-let/index.js';
7
8
  import {
8
9
  fixEmpty,
9
10
  parse,
@@ -15,6 +16,7 @@ export const convert = (source) => {
15
16
  transform(ast, source, {
16
17
  plugins: [
17
18
  ['add-array', addArray],
19
+ ['apply-if-let', applyIfLet],
18
20
  ['apply-try', applyTry],
19
21
  ['remove-import-try', removeImportTry],
20
22
  ],
@@ -1,12 +1,13 @@
1
1
  import {visitors as v} from '@putout/printer';
2
2
 
3
3
  export const IfStatement = (path, printer, semantics) => {
4
- const {print} = printer;
4
+ const {print, indent} = printer;
5
5
  const {node} = path;
6
6
 
7
7
  if (!node.goldsteinIf)
8
8
  return v.IfStatement(path, printer, semantics);
9
9
 
10
+ indent();
10
11
  print('if ');
11
12
  print('__test');
12
13
  print(' ');