@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
|
@@ -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('
|
|
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
|
+
|
package/package.json
CHANGED