@putout/printer 1.91.0 → 1.92.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.05.10, v1.92.0
2
+
3
+ feature:
4
+ - 2d623d5 @putout/printer: ExportNamespaceDeclaration: improve support
5
+
1
6
  2023.05.10, v1.91.0
2
7
 
3
8
  feature:
@@ -9,9 +9,16 @@ const {
9
9
  markAfter,
10
10
  isMarkedAfter,
11
11
  } = require('../../mark');
12
+ const {isExportNamespaceSpecifier} = require('@babel/types');
12
13
 
13
14
  const isDeclarationNewline = (path) => isMarkedAfter(path.get('declaration'));
14
15
 
16
+ const options = {
17
+ exports: {
18
+ maxOneLineSpecifiers: 2,
19
+ },
20
+ };
21
+
15
22
  module.exports.ExportSpecifier = (path, {print}) => {
16
23
  const {
17
24
  local,
@@ -27,38 +34,53 @@ module.exports.ExportSpecifier = (path, {print}) => {
27
34
  };
28
35
 
29
36
  module.exports.ExportNamespaceSpecifier = (path, {print}) => {
30
- print(' * as ');
37
+ print('* as ');
31
38
  print('__exported');
32
39
  };
33
40
 
34
41
  module.exports.ExportNamedDeclaration = {
35
- print(path, {print, traverse, write, indent}) {
42
+ print(path, {print, traverse, write, indent, maybe}) {
36
43
  const {exportKind} = path.node;
37
44
  const specifiers = path.get('specifiers');
45
+ const {maxOneLineSpecifiers} = options.exports;
46
+ const source = path.get('source');
38
47
 
39
48
  indent();
40
49
  write('export ');
41
50
 
42
51
  if (exportKind === 'type' && specifiers.length) {
43
- print('type');
52
+ print('type ');
53
+ print(specifiers[0]);
54
+ print(' from ');
55
+ traverse(source);
56
+ print(';');
57
+
58
+ return;
59
+ }
60
+
61
+ if (isExportNamespaceSpecifier(specifiers[0])) {
44
62
  print(specifiers[0]);
45
63
  print(' from ');
46
64
  print('__source');
47
65
  print(';');
66
+ print.newline();
48
67
 
49
68
  return;
50
69
  }
51
70
 
71
+ const n = specifiers.length;
72
+ const isNewline = !exists(source) || n > maxOneLineSpecifiers;
73
+
52
74
  if (specifiers.length) {
53
75
  write('{');
54
76
  indent.inc();
55
- write.newline();
77
+ maybe.write.newline(isNewline);
56
78
 
57
79
  for (const spec of specifiers) {
58
- indent();
80
+ maybe.indent(isNewline);
59
81
  traverse(spec);
60
- write(',');
61
- write.newline();
82
+ maybe.write(isNewline, ',');
83
+ maybe.write.newline(isNewline);
62
84
  }
63
85
 
64
86
  indent.dec();
@@ -88,3 +110,4 @@ module.exports.ExportNamedDeclaration = {
88
110
  markAfter(path);
89
111
  },
90
112
  };
113
+
@@ -73,4 +73,3 @@ module.exports = {
73
73
  },
74
74
  WhileStatement,
75
75
  };
76
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.91.0",
3
+ "version": "1.92.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",