@putout/printer 18.24.0 → 18.26.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,15 @@
1
+ 2026.06.27, v18.26.0
2
+
3
+ feature:
4
+ - 510702c0 @putout/printer: type-checker: improve handling of absent arrow
5
+
6
+ 2026.06.27, v18.25.0
7
+
8
+ feature:
9
+ - 5478906e @putout/printer: ExportDefaultDeclaration: needsSemicolon: simplify
10
+ - 918525a4 @putout/printer: ExportDeclaration: isNewlineAfter: simplify
11
+ - 9e1ea558 @putout/printer: ExportDefaultDeclaration: inside BlockStatement
12
+
1
13
  2026.06.27, v18.24.0
2
14
 
3
15
  feature:
@@ -30,8 +30,8 @@ export const isNewlineAfterComma = createTypeChecker([
30
30
 
31
31
  const isSimpleBetweenObjects = createTypeChecker([
32
32
  ['+', callWithNext(isObjectExpression)],
33
- ['-: SpreadElement'],
34
- ['-: Identifier'],
33
+ ['-: -> SpreadElement'],
34
+ ['-: -> Identifier'],
35
35
  ['+: -> !CallExpression'],
36
36
  ]);
37
37
 
@@ -6,7 +6,7 @@ export const isConcatenation = createTypeChecker([
6
6
  ['-: parentPath -> ReturnStatement'],
7
7
  ['-: node.operator -> !', isPlus],
8
8
  ['-: node.loc', isSameLine],
9
- ['+: BinaryExpression'],
9
+ ['+: -> BinaryExpression'],
10
10
  ]);
11
11
 
12
12
  function isSameLine(loc) {
@@ -1,41 +1,46 @@
1
1
  import {types} from '@putout/babel';
2
- import {isNext} from '#is';
2
+ import {
3
+ isNext,
4
+ callWithParent,
5
+ callWithNext,
6
+ } from '#is';
7
+ import {createTypeChecker} from '#type-checker';
3
8
 
4
9
  const {
5
10
  isVariableDeclaration,
6
11
  isFunction,
12
+ isBlockStatement,
7
13
  } = types;
8
14
 
9
- function shouldAddSemicolon(path) {
10
- if (path.isClassDeclaration())
11
- return false;
12
-
13
- return !path.isFunctionDeclaration();
14
- }
15
+ const needsSemicolon = createTypeChecker([
16
+ '-: -> ClassDeclaration',
17
+ '+: -> !FunctionDeclaration',
18
+ ]);
19
+
20
+ const afterIf = createTypeChecker([
21
+ callWithParent(isBlockStatement),
22
+ isNext,
23
+ ]);
15
24
 
16
25
  export const ExportDefaultDeclaration = {
17
26
  print(path, {print, traverse, maybe}) {
18
27
  const declaration = path.get('declaration');
28
+ print.indent();
19
29
  print('export default ');
20
30
  traverse(declaration);
21
- maybe.print(shouldAddSemicolon(declaration), ';');
31
+ maybe.print(needsSemicolon(declaration), ';');
22
32
  },
23
- afterSatisfy: () => [
24
- isNext,
25
- ],
26
- after(path, {print, maybe}) {
33
+ afterIf,
34
+ after(path, {print}) {
27
35
  print.newline();
28
- maybe.print.newline(!isVarAfterFn(path));
36
+
37
+ if (isNewlineAfter(path))
38
+ print.newline();
29
39
  },
30
40
  };
31
41
 
32
- function isVarAfterFn(path) {
33
- const next = path.getNextSibling();
34
-
35
- if (!isVariableDeclaration(next))
36
- return false;
37
-
38
- const {declaration} = path.node;
39
-
40
- return isFunction(declaration);
41
- }
42
+ const isNewlineAfter = createTypeChecker([
43
+ ['-: parentPath -> BlockStatement'],
44
+ ['+: -> !', callWithNext(isVariableDeclaration)],
45
+ ['+: node.declaration -> !', isFunction],
46
+ ]);
@@ -3,6 +3,8 @@ import {instrument as _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 isString = (a) => typeof a === 'string';
7
+
6
8
  const SKIP = [
7
9
  Infinity,
8
10
  false,
@@ -29,6 +31,7 @@ export const createTypeChecker = (typeNames, overrides = {}) => {
29
31
  }
30
32
 
31
33
  validateResults(results);
34
+ validateTypeNames(checkers);
32
35
 
33
36
  const typeChecker = (path, options) => {
34
37
  for (const [index, {result, selector, typeName, not}] of checkers.entries()) {
@@ -54,3 +57,12 @@ function validateResults(results) {
54
57
  if (!results.has(true))
55
58
  throw Error(`☝️Looks like type checker missing successful route ('+'), it will always fail`);
56
59
  }
60
+
61
+ const hasTypeName = ({typeName}) => isString(typeName);
62
+
63
+ function validateTypeNames(checkers) {
64
+ for (const {typeName} of checkers.filter(hasTypeName)) {
65
+ if (typeName.includes(':'))
66
+ throw Error(`☝️Looks like typeName includes ':', most likely you forget the arrow: ' -> '`);
67
+ }
68
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.24.0",
3
+ "version": "18.26.0",
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",