@putout/printer 18.47.5 → 18.49.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.11.03, v18.49.0
2
+
3
+ feature:
4
+ - 80d1224d @putout/printer: ExportDeclaration: defer (https://github.com/tc39/proposal-deferred-reexports)
5
+ - d8ad8369 @putout/printer: ImportExpression: sync (https://github.com/tc39/proposal-import-sync)
6
+ - cf513b78 @putout/printer: StructDeclaration (https://github.com/tc39/proposal-structs)
7
+
8
+ 2026.10.17, v18.48.0
9
+
10
+ feature:
11
+ - b8c5a8ef @putout/printer: jsx: indent: improve
12
+
1
13
  2026.10.04, v18.47.5
2
14
 
3
15
  feature:
@@ -25,7 +25,7 @@ const isSpaceBeforeImplements = createTypeChecker([
25
25
  ['+: node.typeParameters.params.length', '<', 2],
26
26
  ]);
27
27
 
28
- const classVisitor = maybeDecorators((path, printer, semantics) => {
28
+ const createVisitor = (name) => (path, printer, semantics) => {
29
29
  const {node} = path;
30
30
  const {
31
31
  id,
@@ -41,7 +41,7 @@ const classVisitor = maybeDecorators((path, printer, semantics) => {
41
41
  } = printer;
42
42
 
43
43
  maybe.print(abstract, 'abstract ');
44
- print('class');
44
+ print(name);
45
45
  maybe.print(id || superClass, ' ');
46
46
  print('__id');
47
47
  print('__typeParameters');
@@ -93,7 +93,9 @@ const classVisitor = maybeDecorators((path, printer, semantics) => {
93
93
  indent();
94
94
 
95
95
  print('}');
96
- });
96
+ };
97
+
98
+ const classVisitor = maybeDecorators(createVisitor('class'));
97
99
 
98
100
  export const ClassExpression = classVisitor;
99
101
 
@@ -106,9 +108,7 @@ export const ClassDeclaration = {
106
108
  before: (path, {indent}) => {
107
109
  indent();
108
110
  },
109
- print: maybeDeclare((path, printer, semantics) => {
110
- classVisitor(path, printer, semantics);
111
- }),
111
+ print: maybeDeclare(classVisitor),
112
112
  afterIf,
113
113
  after(path, {write}) {
114
114
  write.newline();
@@ -119,3 +119,5 @@ export const ClassDeclaration = {
119
119
  }
120
120
  },
121
121
  };
122
+
123
+ export const StructDeclaration = createVisitor('struct');
@@ -3,9 +3,11 @@ import {maybeParens} from '#maybe-parens';
3
3
  export const ImportExpression = maybeParens({
4
4
  print: (path, printer) => {
5
5
  const {print, maybe} = printer;
6
- const {options} = path.node;
6
+ const {sync, options} = path.node;
7
7
 
8
- print('import(');
8
+ print('import');
9
+ maybe.print(sync, '.sync');
10
+ print('(');
9
11
  print('__source');
10
12
 
11
13
  maybe.print(options, ',');
@@ -1,7 +1,11 @@
1
1
  export * from './function/functions.js';
2
2
  export * from './unary-expression/unary-expressions.js';
3
3
  export * from './member-expression/member-expressions.js';
4
- export {ClassExpression, ClassDeclaration} from './class/class.js';
4
+ export {
5
+ ClassExpression,
6
+ ClassDeclaration,
7
+ StructDeclaration,
8
+ } from './class/class.js';
5
9
  export {CallExpression, OptionalCallExpression} from './call-expression/call-expression.js';
6
10
  export {NewExpression} from './new-expression/new-expression.js';
7
11
  export {ObjectExpression} from './object-expression/object-expression.js';
@@ -3,7 +3,7 @@ import {parseComments} from '#comments';
3
3
 
4
4
  export {JSXElement} from './jsx-element.js';
5
5
  export {JSXAttribute} from './jsx-attribute.js';
6
- export {JSXOpeningElement} from './jsx-opening-element.js';
6
+ export {JSXOpeningElement} from './jsx-opening-element/jsx-opening-element.js';
7
7
  export * from './jsx-fragment.js';
8
8
  export {JSXText} from './jsx-text/jsx-text.js';
9
9
 
@@ -0,0 +1,45 @@
1
+ import {types} from '@putout/babel';
2
+ import {createTypeChecker} from '#type-checker';
3
+ import {isCoupleLines} from '#is';
4
+
5
+ const {
6
+ isObjectProperty,
7
+ isCallExpression,
8
+ isJSXElement,
9
+ isJSXExpressionContainer,
10
+ isJSXFragment,
11
+ isLogicalExpression,
12
+ isFunction,
13
+ } = types;
14
+
15
+ const isIdentableParent = createTypeChecker([
16
+ isObjectProperty,
17
+ isCallExpression,
18
+ isJSXElement,
19
+ isJSXExpressionContainer,
20
+ isJSXFragment,
21
+ isLogicalExpression,
22
+ ]);
23
+
24
+ const hasJSXExpression = ({value}) => isJSXExpressionContainer(value);
25
+
26
+ const hasFnAttribute = (path) => {
27
+ for (const attribute of path.node.attributes.filter(hasJSXExpression)) {
28
+ if (isFunction(attribute.value.expression))
29
+ return true;
30
+ }
31
+
32
+ return false;
33
+ };
34
+
35
+ export const isIndentBefore = createTypeChecker([
36
+ ['+: parentPath.parentPath -> !', isIdentableParent],
37
+ ['-: parentPath.parentPath -> !CallExpression'],
38
+ ['+', hasFnAttribute],
39
+ ]);
40
+
41
+ export const isIndent = createTypeChecker([
42
+ ['-: -> !', isCoupleLines],
43
+ ['+: parentPath.parentPath -> JSXElement'],
44
+ ['+: parentPath.parentPath -> CallExpression'],
45
+ ]);
@@ -0,0 +1,26 @@
1
+ import {isCoupleLines} from '#is';
2
+ import {isIndent, isIndentBefore} from './indent.js';
3
+
4
+ export const JSXOpeningElement = (path, {print, maybe}) => {
5
+ const coupleLines = isCoupleLines(path);
6
+ const shouldIndent = isIndent(path);
7
+
8
+ maybe.indent.inc(shouldIndent);
9
+ maybe.indent(isIndentBefore(path));
10
+ print('<');
11
+ print('__name');
12
+
13
+ for (const attr of path.get('attributes')) {
14
+ maybe.print.space(!coupleLines);
15
+ print(attr);
16
+ }
17
+
18
+ if (isCoupleLines(path))
19
+ print.breakline();
20
+
21
+ if (path.node.selfClosing)
22
+ print('/');
23
+
24
+ print('>');
25
+ maybe.indent.dec(shouldIndent);
26
+ };
@@ -71,7 +71,7 @@ export const ExportNamedDeclaration = maybeDecorators({
71
71
  } = printer;
72
72
 
73
73
  const {trailingComma} = semantics;
74
- const {exportKind} = path.node;
74
+ const {phase, exportKind} = path.node;
75
75
  const specifiers = path.get('specifiers');
76
76
  const {maxOneLineSpecifiers} = options.exports;
77
77
  const source = path.get('source');
@@ -79,6 +79,9 @@ export const ExportNamedDeclaration = maybeDecorators({
79
79
  indent();
80
80
  print('export');
81
81
 
82
+ if (phase === 'defer')
83
+ print(' defer');
84
+
82
85
  if (exportKind === 'type' && specifiers.length)
83
86
  print(' type');
84
87
 
@@ -183,3 +186,4 @@ export const ExportNamedDeclaration = maybeDecorators({
183
186
  markAfter(path);
184
187
  },
185
188
  });
189
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.47.5",
3
+ "version": "18.49.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",
@@ -1,48 +0,0 @@
1
- import {isCoupleLines} from '#is';
2
-
3
- const isNotJSX = ({parentPath}) => {
4
- const grandPath = parentPath.parentPath;
5
-
6
- if (grandPath.isObjectProperty())
7
- return false;
8
-
9
- if (grandPath.isCallExpression())
10
- return false;
11
-
12
- if (grandPath.isJSXElement())
13
- return false;
14
-
15
- if (grandPath.isJSXExpressionContainer())
16
- return false;
17
-
18
- if (grandPath.isJSXFragment())
19
- return false;
20
-
21
- return !grandPath.isLogicalExpression();
22
- };
23
-
24
- export const JSXOpeningElement = (path, {print, maybe}) => {
25
- maybe.indent(isNotJSX(path));
26
- print('<');
27
- print('__name');
28
-
29
- const coupleLines = isCoupleLines(path);
30
- const noCoupleLines = !coupleLines;
31
- const shouldIndent = coupleLines && path.parentPath.parentPath.isJSXElement();
32
-
33
- maybe.indent.inc(shouldIndent);
34
-
35
- for (const attr of path.get('attributes')) {
36
- maybe.print.space(noCoupleLines);
37
- print(attr);
38
- }
39
-
40
- if (isCoupleLines(path))
41
- print.breakline();
42
-
43
- if (path.node.selfClosing)
44
- print('/');
45
-
46
- print('>');
47
- maybe.indent.dec(shouldIndent);
48
- };