@putout/printer 2.0.2 → 2.2.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
package/README.md
CHANGED
|
@@ -88,6 +88,7 @@ write(ast, {
|
|
|
88
88
|
comments: true,
|
|
89
89
|
maxSpecifiersInOneLine: 2,
|
|
90
90
|
maxElementsInOneLine: 3,
|
|
91
|
+
maxVariablesInOneLine: 4,
|
|
91
92
|
},
|
|
92
93
|
visitors: {
|
|
93
94
|
AssignmentPattern(path, {write}) {
|
|
@@ -103,7 +104,8 @@ write(ast, {
|
|
|
103
104
|
|
|
104
105
|
### `format`
|
|
105
106
|
|
|
106
|
-
|
|
107
|
+
Options related to visuals and not related to logic of output can be changed with help of `format`,
|
|
108
|
+
you can override next options:
|
|
107
109
|
|
|
108
110
|
```js
|
|
109
111
|
const overrides = {
|
|
@@ -111,8 +113,9 @@ const overrides = {
|
|
|
111
113
|
indent: ' ',
|
|
112
114
|
newline: '\n',
|
|
113
115
|
space: ' ',
|
|
114
|
-
comments: true,
|
|
115
116
|
splitter: '\n',
|
|
117
|
+
roundBraceOpen: '(',
|
|
118
|
+
roundBraceClose: ')',
|
|
116
119
|
},
|
|
117
120
|
};
|
|
118
121
|
```
|
|
@@ -120,8 +123,8 @@ const overrides = {
|
|
|
120
123
|
- `indent` - use two spaces, tabs, or anything you want;
|
|
121
124
|
- `newline` - symbol for used for line separation;
|
|
122
125
|
- `space` - default symbol used for space character;
|
|
123
|
-
- `comments` - produce comments in output or skip them;
|
|
124
126
|
- `splitter` - mandatory symbol that used inside of statements like this:
|
|
127
|
+
- `roundBraceOpen` and `roundBraceClose` symbols to to output braces in a single argument arrow function expressions: `(a) => {}`.
|
|
125
128
|
|
|
126
129
|
Default options produce:
|
|
127
130
|
|
|
@@ -147,11 +150,15 @@ const overrides = {
|
|
|
147
150
|
|
|
148
151
|
And have minified code:
|
|
149
152
|
|
|
153
|
+
```
|
|
154
|
+
if(a>3)console.log('ok');else console.log('not ok');
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Semantics
|
|
158
|
+
|
|
159
|
+
Options used to configure logic of output, similar to ESLint rules:
|
|
160
|
+
|
|
150
161
|
```js
|
|
151
|
-
if (a > 3)
|
|
152
|
-
console.log('ok');
|
|
153
|
-
else
|
|
154
|
-
console.log('not ok');
|
|
155
162
|
```
|
|
156
163
|
|
|
157
164
|
### `write`
|
package/lib/tokenize/comments.js
CHANGED
|
@@ -104,7 +104,7 @@ module.exports.parseComments = (path, {write}, semantics) => {
|
|
|
104
104
|
};
|
|
105
105
|
|
|
106
106
|
function isSameLine(path, loc) {
|
|
107
|
-
return path.node.loc.start.line === loc.start.line;
|
|
107
|
+
return path.node.loc.start.line === loc.start.line || path.node.loc.end.line === loc.end.line;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
function maybeInsideFn(insideFn, {print, indent}) {
|
|
@@ -24,6 +24,7 @@ module.exports.VariableDeclaration = {
|
|
|
24
24
|
print.breakline();
|
|
25
25
|
},
|
|
26
26
|
print(path, {maybe, store, write, traverse, print, indent}, semantics) {
|
|
27
|
+
const {maxVariablesInOneLine} = semantics;
|
|
27
28
|
maybe.indent(isInsideBlock(path));
|
|
28
29
|
write(path.node.kind);
|
|
29
30
|
maybeSpaceAfterKeyword(path, {
|
|
@@ -53,13 +54,18 @@ module.exports.VariableDeclaration = {
|
|
|
53
54
|
const next = declarations[index + 1];
|
|
54
55
|
|
|
55
56
|
write(',');
|
|
57
|
+
|
|
58
|
+
if (!next.node.leadingComments) {
|
|
59
|
+
maybe.write.breakline(n > maxVariablesInOneLine);
|
|
60
|
+
maybe.write.space(n <= maxVariablesInOneLine);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
56
64
|
parseLeadingComments(next, {
|
|
57
65
|
print,
|
|
58
66
|
maybe,
|
|
59
67
|
indent,
|
|
60
68
|
}, semantics);
|
|
61
|
-
|
|
62
|
-
maybe.write.breakline(!next.node.leadingComments);
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
71
|
|
package/package.json
CHANGED