@putout/printer 16.4.0 → 16.6.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,13 @@
1
+ 2026.01.03, v16.6.0
2
+
3
+ feature:
4
+ - 8558f03 @putout/printer: ExportDeclaration: export default from: add support
5
+
6
+ 2025.12.27, v16.5.0
7
+
8
+ feature:
9
+ - 039ab4a @putout/printer: SwitchCase: maybe space after case
10
+
1
11
  2025.12.11, v16.4.0
2
12
 
3
13
  feature:
@@ -20,6 +20,7 @@ const {
20
20
  isExportNamespaceSpecifier,
21
21
  isVariableDeclaration,
22
22
  isExportNamedDeclaration,
23
+ isExportDefaultSpecifier,
23
24
  } = types;
24
25
 
25
26
  const isDeclarationNewline = (path) => isMarkedAfter(path.get('declaration'));
@@ -47,6 +48,10 @@ module.exports.ExportNamespaceSpecifier = (path, {print}) => {
47
48
  print('__exported');
48
49
  };
49
50
 
51
+ module.exports.ExportDefaultSpecifier = (path, {print}) => {
52
+ print('__exported');
53
+ };
54
+
50
55
  module.exports.ExportNamedDeclaration = {
51
56
  beforeIf(path) {
52
57
  const prev = path.getPrevSibling();
@@ -88,15 +93,30 @@ module.exports.ExportNamedDeclaration = {
88
93
 
89
94
  if (specifiers && !path.node.declaration) {
90
95
  print.space();
91
- print('{');
92
96
 
93
- if (specifiers.length) {
97
+ const [first, ...rest] = specifiers;
98
+
99
+ if (!specifiers.length) {
100
+ print('{}');
101
+ } else if (isExportDefaultSpecifier(first) && !rest.length) {
102
+ traverse(first);
103
+ } else {
104
+ if (isExportDefaultSpecifier(first)) {
105
+ traverse(first);
106
+ print(',');
107
+ print.space();
108
+ } else {
109
+ rest.unshift(first);
110
+ }
111
+
112
+ print('{');
113
+
94
114
  indent.inc();
95
115
  maybe.print.newline(isNewline);
96
116
 
97
117
  const lastIndex = n - 1;
98
118
 
99
- for (const [i, spec] of specifiers.entries()) {
119
+ for (const [i, spec] of rest.entries()) {
100
120
  const isType = spec.node.exportKind === 'type';
101
121
  const isLast = i < lastIndex;
102
122
 
@@ -114,9 +134,9 @@ module.exports.ExportNamedDeclaration = {
114
134
 
115
135
  indent.dec();
116
136
  indent();
137
+ print('}');
117
138
  }
118
139
 
119
- print('}');
120
140
  const source = path.get('source');
121
141
 
122
142
  if (exists(source)) {
@@ -156,3 +176,4 @@ module.exports.ExportNamedDeclaration = {
156
176
  markAfter(path);
157
177
  },
158
178
  };
179
+
@@ -14,7 +14,7 @@ const exportDeclarations = require('./export-declaration/export-declaration');
14
14
  const {ExportAllDeclaration} = require('./export-declaration/export-all-declaration');
15
15
 
16
16
  const {WhileStatement} = require('./while-statement/while-statement');
17
- const {SwitchStatement} = require('./switch-statement');
17
+ const {SwitchStatement} = require('./switch-statement/switch-statement');
18
18
  const {ForInStatement} = require('./for-in-statement');
19
19
  const {ExportDefaultDeclaration} = require('./export-declaration/export-default-declaration');
20
20
  const {BreakStatement} = require('./break-statement/break-statement');
@@ -2,12 +2,12 @@
2
2
 
3
3
  module.exports.maybeSpaceAfterKeyword = (path, {print}, semantics) => {
4
4
  const {roundBraces} = semantics;
5
- const {argument} = path.node;
5
+ const {node} = path;
6
6
 
7
- if (!argument)
7
+ if (!node)
8
8
  return;
9
9
 
10
- const {type} = argument;
10
+ const {type} = node;
11
11
 
12
12
  if (type === 'SequenceExpression' && roundBraces.sequence)
13
13
  return print.space();
@@ -18,7 +18,7 @@ module.exports.maybeSpaceAfterKeyword = (path, {print}, semantics) => {
18
18
  if (type === 'ArrayExpression' || type === 'ObjectExpression')
19
19
  return print.space();
20
20
 
21
- if (type === 'UnaryExpression' && argument.operator === '!')
21
+ if (type === 'UnaryExpression' && node.operator === '!')
22
22
  return print.space();
23
23
 
24
24
  if (type === 'ArrowFunctionExpression' && roundBraces.arrow)
@@ -29,7 +29,10 @@ module.exports.ReturnStatement = {
29
29
 
30
30
  maybe.indent(!isInsideLabel(path));
31
31
  print('return');
32
- maybeSpaceAfterKeyword(path, printer, semantics);
32
+
33
+ const arg = path.get('argument');
34
+
35
+ maybeSpaceAfterKeyword(arg, printer, semantics);
33
36
 
34
37
  if (isJSXWithComment(path)) {
35
38
  print('(');
@@ -4,9 +4,11 @@ const {
4
4
  isNext,
5
5
  exists,
6
6
  isLast,
7
- } = require('../is');
7
+ } = require('#is');
8
8
 
9
- const {parseLeadingComments} = require('../comment/comment');
9
+ const {parseLeadingComments} = require('../../comment/comment');
10
+
11
+ const {maybeSpaceAfterKeyword} = require('../return-statement/maybe-space-after-keyword.js');
10
12
 
11
13
  module.exports.SwitchStatement = {
12
14
  print(path, printer, semantics) {
@@ -36,7 +38,8 @@ module.exports.SwitchStatement = {
36
38
  parseLeadingComments(switchCase, printer, semantics);
37
39
 
38
40
  if (exists(test)) {
39
- write('case ');
41
+ write('case');
42
+ maybeSpaceAfterKeyword(test, printer, semantics);
40
43
  traverse(test);
41
44
  } else {
42
45
  write('default');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "16.4.0",
3
+ "version": "16.6.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",