@putout/printer 1.150.1 → 2.0.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 +5 -0
- package/README.md +1 -1
- package/lib/tokenize/comments.js +3 -2
- package/lib/tokenize/expressions/array-expression/array-expression.js +1 -0
- package/lib/tokenize/overrides.js +1 -1
- package/lib/tokenize/statements/expression-statement.js +5 -1
- package/lib/tokenize/statements/variable-declaration/maybe-space-after-keyword.js +5 -1
- package/lib/tokenize/statements/variable-declaration/variable-declaration.js +18 -4
- package/lib/tokenize/tokenize.js +2 -2
- package/lib/tokenize/typescript/ts-type-literal.js +1 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -80,12 +80,12 @@ write(ast, {
|
|
|
80
80
|
indent: ' ',
|
|
81
81
|
newline: '\n',
|
|
82
82
|
space: ' ',
|
|
83
|
-
comments: true,
|
|
84
83
|
splitter: '\n',
|
|
85
84
|
roundBraceOpen: '(',
|
|
86
85
|
roundBraceClose: ')',
|
|
87
86
|
},
|
|
88
87
|
semantics: {
|
|
88
|
+
comments: true,
|
|
89
89
|
maxSpecifiersInOneLine: 2,
|
|
90
90
|
maxElementsInOneLine: 3,
|
|
91
91
|
},
|
package/lib/tokenize/comments.js
CHANGED
|
@@ -6,8 +6,9 @@ const {
|
|
|
6
6
|
} = require('./is');
|
|
7
7
|
|
|
8
8
|
const {markBefore} = require('./mark');
|
|
9
|
+
const {isVariableDeclarator} = require('@babel/types');
|
|
9
10
|
|
|
10
|
-
module.exports.parseLeadingComments = (path, {print, maybe, indent}, format) => {
|
|
11
|
+
module.exports.parseLeadingComments = (path, {print, maybe, indent}, format = {}) => {
|
|
11
12
|
if (!format.comments)
|
|
12
13
|
return;
|
|
13
14
|
|
|
@@ -20,7 +21,7 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, format) =>
|
|
|
20
21
|
return;
|
|
21
22
|
|
|
22
23
|
const insideFn = path.parentPath.isFunction();
|
|
23
|
-
const isProperty = path.isObjectProperty();
|
|
24
|
+
const isProperty = path.isObjectProperty() || isVariableDeclarator(path);
|
|
24
25
|
const isIndent = !path.isClassMethod() && !insideFn && !isProperty;
|
|
25
26
|
|
|
26
27
|
for (const {type, value} of leadingComments) {
|
|
@@ -19,7 +19,6 @@ function initFormat(format) {
|
|
|
19
19
|
indent: ' ',
|
|
20
20
|
newline: '\n',
|
|
21
21
|
space: ' ',
|
|
22
|
-
comments: true,
|
|
23
22
|
splitter: '\n',
|
|
24
23
|
roundBraceOpen: '(',
|
|
25
24
|
roundBraceClose: ')',
|
|
@@ -29,6 +28,7 @@ function initFormat(format) {
|
|
|
29
28
|
|
|
30
29
|
function initSemantics(semantics = {}) {
|
|
31
30
|
return {
|
|
31
|
+
comments: true,
|
|
32
32
|
maxSpecifiersInOneLine: 2,
|
|
33
33
|
maxElementsInOneLine: 5,
|
|
34
34
|
...semantics,
|
|
@@ -29,7 +29,11 @@ const satisfyAfter = satisfy([
|
|
|
29
29
|
isNextUp,
|
|
30
30
|
]);
|
|
31
31
|
|
|
32
|
-
const shouldBreakline = satisfy([
|
|
32
|
+
const shouldBreakline = satisfy([
|
|
33
|
+
isNewlineBetweenSiblings,
|
|
34
|
+
isNotLastBody,
|
|
35
|
+
isStrictMode,
|
|
36
|
+
]);
|
|
33
37
|
|
|
34
38
|
module.exports.ExpressionStatement = {
|
|
35
39
|
print(path, {indent, print, maybe, store}) {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports.maybeSpaceAfterKeyword = (path, {write}) => {
|
|
4
|
-
const {
|
|
4
|
+
const {declarations} = path.node;
|
|
5
|
+
const {id} = declarations[0];
|
|
6
|
+
|
|
7
|
+
if (declarations.length > 1)
|
|
8
|
+
return;
|
|
5
9
|
|
|
6
10
|
if (id.type === 'ArrayPattern' || id.type === 'ObjectPattern')
|
|
7
11
|
return write.space();
|
|
@@ -13,6 +13,7 @@ const {isExportDeclaration} = require('@babel/types');
|
|
|
13
13
|
const {maybeSpaceAfterKeyword} = require('./maybe-space-after-keyword');
|
|
14
14
|
|
|
15
15
|
const {isConcatenation} = require('../../expressions/binary-expression/concatanate');
|
|
16
|
+
const {parseLeadingComments} = require('../../comments');
|
|
16
17
|
|
|
17
18
|
const isParentBlock = (path) => /Program|BlockStatement|Export/.test(path.parentPath.type);
|
|
18
19
|
const isInsideBlock = (path) => /^(Program|BlockStatement)$/.test(path.parentPath.type);
|
|
@@ -22,9 +23,9 @@ module.exports.VariableDeclaration = {
|
|
|
22
23
|
before(path, {print}) {
|
|
23
24
|
print.breakline();
|
|
24
25
|
},
|
|
25
|
-
print(path, {maybe, store, write, traverse}) {
|
|
26
|
+
print(path, {maybe, store, write, traverse, print, indent}, semantics) {
|
|
26
27
|
maybe.indent(isInsideBlock(path));
|
|
27
|
-
write(
|
|
28
|
+
write(path.node.kind);
|
|
28
29
|
maybeSpaceAfterKeyword(path, {
|
|
29
30
|
write,
|
|
30
31
|
});
|
|
@@ -32,6 +33,9 @@ module.exports.VariableDeclaration = {
|
|
|
32
33
|
const declarations = path.get('declarations');
|
|
33
34
|
const n = declarations.length - 1;
|
|
34
35
|
|
|
36
|
+
maybe.indent.inc(n);
|
|
37
|
+
maybe.print.breakline(n);
|
|
38
|
+
|
|
35
39
|
for (const [index, declaration] of declarations.entries()) {
|
|
36
40
|
const id = declaration.get('id');
|
|
37
41
|
const init = declaration.get('init');
|
|
@@ -46,10 +50,20 @@ module.exports.VariableDeclaration = {
|
|
|
46
50
|
traverse(init);
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
if (notLast) {
|
|
54
|
+
const next = declarations[index + 1];
|
|
55
|
+
|
|
56
|
+
write(',');
|
|
57
|
+
parseLeadingComments(next, {
|
|
58
|
+
print,
|
|
59
|
+
maybe,
|
|
60
|
+
indent,
|
|
61
|
+
}, semantics);
|
|
62
|
+
maybe.write.breakline(!next.node.leadingComments);
|
|
63
|
+
}
|
|
51
64
|
}
|
|
52
65
|
|
|
66
|
+
maybe.indent.dec(n);
|
|
53
67
|
maybe.write(isParentBlock(path), ';');
|
|
54
68
|
|
|
55
69
|
let wasNewline = false;
|
package/lib/tokenize/tokenize.js
CHANGED
|
@@ -233,10 +233,10 @@ module.exports.tokenize = (ast, overrides) => {
|
|
|
233
233
|
maybeThrow(!currentTraverse, path, `Node type '{{ type }}' is not supported yet: '{{ path }}'`);
|
|
234
234
|
|
|
235
235
|
const currentIndent = i;
|
|
236
|
-
parseLeadingComments(path, printer,
|
|
236
|
+
parseLeadingComments(path, printer, semantics);
|
|
237
237
|
// this is main thing
|
|
238
238
|
maybePlugin(currentTraverse, path, printer, semantics);
|
|
239
|
-
parseTrailingComments(path, printer,
|
|
239
|
+
parseTrailingComments(path, printer, semantics);
|
|
240
240
|
maybeThrow(i !== currentIndent, path, `☝️Looks like indent level changed after token visitor: '{{ type }}', for code: '{{ path }}'`);
|
|
241
241
|
|
|
242
242
|
debug(path.type);
|
package/package.json
CHANGED