@putout/printer 18.0.6 → 18.0.7

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
+ 2026.03.05, v18.0.7
2
+
3
+ feature:
4
+ - dd7f874 @putout/printer: VariableDeclaration: inside ForOfStatement: indent
5
+
1
6
  2026.03.05, v18.0.6
2
7
 
3
8
  feature:
@@ -90,13 +90,15 @@ export const ClassDeclaration = {
90
90
  classVisitor(path, printer, semantics);
91
91
  }),
92
92
  afterIf(path) {
93
+ const {parentPath} = path;
94
+
93
95
  if (isFunctionLike(path))
94
96
  return true;
95
97
 
96
98
  if (isNext(path))
97
99
  return true;
98
100
 
99
- return isInsideTSModuleBlock(path);
101
+ return isInsideTSModuleBlock(parentPath);
100
102
  },
101
103
  after(path, {write}) {
102
104
  write.newline();
@@ -1,11 +1,7 @@
1
1
  import {types} from '@putout/babel';
2
2
  import {printParams} from '#print-params';
3
3
  import {markAfter} from '#mark';
4
- import {
5
- isInsideTSModuleBlock,
6
- isNext,
7
- isNextParent,
8
- } from '#is';
4
+ import {isNext, isNextParent} from '#is';
9
5
  import {createTypeChecker} from '#type-checker';
10
6
 
11
7
  const {
@@ -22,11 +18,7 @@ const isInsideExportDefaultWithBody = createTypeChecker([
22
18
  ['+', hasFnBody],
23
19
  ]);
24
20
 
25
- const isInsideBlockLike = createTypeChecker([
26
- ['+', isInsideTSModuleBlock],
27
- '-: parentPath -> !BlockStatement',
28
- ['+: -> !', hasFnBody],
29
- ]);
21
+ const isInsideBlockLike = createTypeChecker(['+: parentPath.parentPath -> TSModuleBlock', '-: parentPath -> !BlockStatement', ['+: -> !', hasFnBody]]);
30
22
 
31
23
  const not = (fn) => (...a) => !fn(...a);
32
24
  const notInsideExportDefaultWithBody = not(isInsideExportDefaultWithBody);
@@ -1,5 +1,4 @@
1
1
  import {types} from '@putout/babel';
2
- import {createTypeChecker} from '#type-checker';
3
2
 
4
3
  const {
5
4
  isStringLiteral,
@@ -16,21 +15,14 @@ const {
16
15
  isProgram,
17
16
  isBlockStatement,
18
17
  isTSModuleBlock,
18
+ isSwitchCase,
19
19
  } = types;
20
20
 
21
21
  export const isInsideProgram = (path) => isProgram(path.parentPath);
22
22
  export const isInsideBlock = (path) => isBlockStatement(path.parentPath);
23
+ export const isInsideSwitchCase = (path) => isSwitchCase(path.parentPath);
23
24
 
24
- export const isInsideBlockLike = createTypeChecker('path.parentPath', [
25
- 'Program',
26
- 'BlockStatement',
27
- 'TSModuleBlock',
28
- 'SwitchCase',
29
- ]);
30
-
31
- export const isInsideTSModuleBlock = ({parentPath}) => {
32
- return isTSModuleBlock(parentPath?.parentPath);
33
- };
25
+ export const isInsideTSModuleBlock = ({parentPath}) => isTSModuleBlock(parentPath);
34
26
 
35
27
  export const isInsideCall = ({parentPath}) => parentPath.isCallExpression();
36
28
 
@@ -7,25 +7,47 @@ import {
7
7
  isNewlineBetweenSiblings,
8
8
  exists,
9
9
  noTrailingComment,
10
- isInsideBlockLike,
11
10
  isInsideIf,
12
11
  isInsideBlock,
13
12
  isInsideExport,
13
+ isInsideTSModuleBlock,
14
+ isInsideProgram,
15
+ isInsideSwitchCase,
14
16
  } from '#is';
15
17
  import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
16
18
  import {isConcatenation} from '../../expressions/binary-expression/concatenate.js';
17
19
  import {parseLeadingComments} from '../../comment/comment.js';
18
20
  import {maybeDeclare} from '../../maybe/maybe-declare.js';
19
21
 
22
+ export const isInsideForOfBody = (path) => {
23
+ const {parentPath} = path;
24
+
25
+ if (!isForOfStatement(parentPath))
26
+ return false;
27
+
28
+ return path.parentPath.node.body === path.node;
29
+ };
30
+
31
+ const isInsideBlockLike = createTypeChecker([
32
+ isInsideProgram,
33
+ isInsideBlock,
34
+ isInsideTSModuleBlock,
35
+ isInsideSwitchCase,
36
+ isInsideForOfBody,
37
+ ]);
38
+
20
39
  const isLast = (path) => path.parentPath?.isProgram() && !isNext(path);
21
40
 
22
- const {isExportDeclaration} = types;
41
+ const {
42
+ isExportDeclaration,
43
+ isForOfStatement,
44
+ } = types;
23
45
 
24
46
  const isParentTSModuleBlock = (path) => path.parentPath.isTSModuleBlock();
25
47
  const isParentSwitchCase = (path) => path.parentPath.isSwitchCase();
26
48
  const isFirstInSwitch = (path) => path.parentPath.get('consequent.0') === path;
27
49
 
28
- const isIsideParentLike = createTypeChecker('path.parentPath', [
50
+ const isInsideParentLike = createTypeChecker('path.parentPath', [
29
51
  'Program',
30
52
  'BlockStatement',
31
53
  'ExportNamedDeclaration',
@@ -33,14 +55,15 @@ const isIsideParentLike = createTypeChecker('path.parentPath', [
33
55
  ]);
34
56
 
35
57
  const isNeedSemicolon = createTypeChecker([
36
- isIsideParentLike,
58
+ isInsideParentLike,
37
59
  isParentSwitchCase,
38
60
  isParentTSModuleBlock,
39
61
  isInsideIf,
62
+ isInsideForOfBody,
40
63
  ]);
41
64
 
42
65
  const isNeedNewline = createTypeChecker([
43
- ['-: -> !', isIsideParentLike],
66
+ ['-: -> !', isInsideParentLike],
44
67
  ['-: -> !', isNext],
45
68
  ['+', noTrailingComment],
46
69
  ['+', isNewlineBetweenSiblings],
@@ -49,4 +49,3 @@ export function parseTypeNames(typeNames) {
49
49
 
50
50
  return tuples;
51
51
  }
52
-
@@ -3,6 +3,11 @@ import {instrument} from '#type-checker/instrument';
3
3
  import {parseOperation, parseTypeNames} from './parsers.js';
4
4
  import {equal, maybeCall} from './comparators.js';
5
5
 
6
+ const SKIP = [
7
+ Infinity,
8
+ false,
9
+ ];
10
+
6
11
  export const createTypeChecker = (deepness, typeNames) => {
7
12
  if (!typeNames) {
8
13
  typeNames = deepness;
@@ -30,6 +35,9 @@ export const createTypeChecker = (deepness, typeNames) => {
30
35
  if (selector)
31
36
  currentPath = jessy(selector, path);
32
37
 
38
+ if (!currentPath)
39
+ return SKIP;
40
+
33
41
  const {type} = currentPath;
34
42
 
35
43
  if (equal(not, type, typeName))
@@ -39,9 +47,6 @@ export const createTypeChecker = (deepness, typeNames) => {
39
47
  return [index, result];
40
48
  }
41
49
 
42
- return [
43
- Infinity,
44
- false,
45
- ];
50
+ return SKIP;
46
51
  });
47
52
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.0.6",
3
+ "version": "18.0.7",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",