@putout/printer 1.70.1 → 1.70.3
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 +10 -0
- package/lib/tokenize/expressions/object-expression.js +3 -0
- package/lib/tokenize/is.js +1 -1
- package/lib/tokenize/statements/export-declarations.js +48 -28
- package/lib/tokenize/statements/expression-statement.js +2 -2
- package/lib/tokenize/statements/variable-declaration.js +4 -7
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -5,6 +5,8 @@ const {
|
|
|
5
5
|
isForOf,
|
|
6
6
|
isIf,
|
|
7
7
|
noTrailingComment,
|
|
8
|
+
isNewlineBetweenSiblings,
|
|
9
|
+
|
|
8
10
|
} = require('../is');
|
|
9
11
|
|
|
10
12
|
const {isFunction} = require('@babel/types');
|
|
@@ -50,6 +52,7 @@ module.exports.ObjectExpression = (path, {print, maybe, indent}) => {
|
|
|
50
52
|
|
|
51
53
|
print(property);
|
|
52
54
|
maybe.print.newline(manyLines && noTrailingComment(property));
|
|
55
|
+
maybe.print.linebreak(isNewlineBetweenSiblings(property));
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
indent.dec();
|
package/lib/tokenize/is.js
CHANGED
|
@@ -68,7 +68,7 @@ module.exports.isForOf = (path) => {
|
|
|
68
68
|
return false;
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
-
module.exports.
|
|
71
|
+
module.exports.isNewlineBetweenSiblings = (path) => {
|
|
72
72
|
const endCurrent = path.node?.loc?.end?.line;
|
|
73
73
|
const startNext = path.getNextSibling().node?.loc?.start?.line;
|
|
74
74
|
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {isNewlineBetweenSiblings} = require('../is');
|
|
4
|
+
const {
|
|
5
|
+
markAfter,
|
|
6
|
+
isMarkedAfter,
|
|
7
|
+
} = require('../mark');
|
|
8
|
+
|
|
9
|
+
const isDeclarationNewline = (path) => isMarkedAfter(path.get('declaration'));
|
|
10
|
+
|
|
3
11
|
module.exports.ExportSpecifier = (path, {print}) => {
|
|
4
12
|
const {
|
|
5
13
|
local,
|
|
@@ -19,37 +27,49 @@ module.exports.ExportNamespaceSpecifier = (path, {print}) => {
|
|
|
19
27
|
print('__exported');
|
|
20
28
|
};
|
|
21
29
|
|
|
22
|
-
module.exports.ExportNamedDeclaration =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
write('export ');
|
|
27
|
-
|
|
28
|
-
if (exportKind === 'type' && specifiers.length) {
|
|
29
|
-
print('type');
|
|
30
|
-
print(specifiers[0]);
|
|
31
|
-
print(' from ');
|
|
32
|
-
print('__source');
|
|
33
|
-
print(';');
|
|
30
|
+
module.exports.ExportNamedDeclaration = {
|
|
31
|
+
print(path, {print, traverse, write, indent}) {
|
|
32
|
+
const {exportKind} = path.node;
|
|
33
|
+
const specifiers = path.get('specifiers');
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (specifiers.length) {
|
|
39
|
-
write('{');
|
|
40
|
-
indent.inc();
|
|
41
|
-
write.newline();
|
|
35
|
+
write('export ');
|
|
42
36
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
if (exportKind === 'type' && specifiers.length) {
|
|
38
|
+
print('type');
|
|
39
|
+
print(specifiers[0]);
|
|
40
|
+
print(' from ');
|
|
41
|
+
print('__source');
|
|
42
|
+
print(';');
|
|
43
|
+
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (specifiers.length) {
|
|
48
|
+
write('{');
|
|
49
|
+
indent.inc();
|
|
47
50
|
write.newline();
|
|
51
|
+
|
|
52
|
+
for (const spec of specifiers) {
|
|
53
|
+
indent();
|
|
54
|
+
traverse(spec);
|
|
55
|
+
write(',');
|
|
56
|
+
write.newline();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
indent.dec();
|
|
60
|
+
write('}');
|
|
48
61
|
}
|
|
49
62
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
63
|
+
print('__declaration');
|
|
64
|
+
},
|
|
65
|
+
afterIf(path) {
|
|
66
|
+
if (isDeclarationNewline(path))
|
|
67
|
+
return false;
|
|
68
|
+
|
|
69
|
+
return isNewlineBetweenSiblings(path);
|
|
70
|
+
},
|
|
71
|
+
after(path, {print}) {
|
|
72
|
+
print.newline();
|
|
73
|
+
markAfter(path);
|
|
74
|
+
},
|
|
55
75
|
};
|
|
@@ -5,12 +5,12 @@ const {
|
|
|
5
5
|
isLast,
|
|
6
6
|
isParentBlock,
|
|
7
7
|
isParentLast,
|
|
8
|
-
|
|
8
|
+
isNewlineBetweenSiblings,
|
|
9
9
|
satisfy,
|
|
10
10
|
} = require('../is');
|
|
11
11
|
|
|
12
12
|
const shouldBreakline = satisfy([
|
|
13
|
-
|
|
13
|
+
isNewlineBetweenSiblings,
|
|
14
14
|
isNotLastBody,
|
|
15
15
|
isStrictMode,
|
|
16
16
|
]);
|
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
const {
|
|
4
4
|
isNext,
|
|
5
5
|
isCoupleLines,
|
|
6
|
-
|
|
6
|
+
isNewlineBetweenSiblings,
|
|
7
7
|
} = require('../is');
|
|
8
8
|
|
|
9
|
-
const {
|
|
10
|
-
hasPrevNewline,
|
|
11
|
-
markAfter,
|
|
12
|
-
} = require('../mark');
|
|
9
|
+
const {hasPrevNewline} = require('../mark');
|
|
13
10
|
|
|
14
11
|
const {isExportDeclaration} = require('@babel/types');
|
|
15
12
|
|
|
@@ -45,14 +42,14 @@ module.exports.VariableDeclaration = {
|
|
|
45
42
|
isNextAssign,
|
|
46
43
|
isNextCoupleLines,
|
|
47
44
|
notLastPrevVarNotNextVar,
|
|
48
|
-
|
|
45
|
+
isNewlineBetweenSiblings,
|
|
49
46
|
notLastParentExport,
|
|
50
47
|
],
|
|
51
48
|
after(path, {maybe, store}) {
|
|
52
49
|
const wasNewline = store();
|
|
53
50
|
maybe.print.linebreak(wasNewline);
|
|
54
51
|
maybe.print.newline(!wasNewline);
|
|
55
|
-
markAfter(path);
|
|
52
|
+
maybe.markAfter(wasNewline, path);
|
|
56
53
|
},
|
|
57
54
|
};
|
|
58
55
|
|
package/package.json
CHANGED