@putout/printer 2.22.0 → 2.24.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 +10 -0
- package/lib/tokenize/expressions/array-expression/new-line.js +2 -5
- package/lib/tokenize/expressions/assignment-expression.js +1 -4
- package/lib/tokenize/expressions/functions/class-method.js +1 -3
- package/lib/tokenize/expressions/functions/function-declaration.js +1 -4
- package/lib/tokenize/expressions/functions/function-expression.js +1 -4
- package/lib/tokenize/expressions/member-expressions/member-expressions.js +1 -4
- package/lib/tokenize/expressions/object-expression/object-property.js +1 -4
- package/lib/tokenize/expressions/object-pattern/max-properties-in-one-line.js +0 -1
- package/lib/tokenize/expressions/object-pattern/object-pattern.js +4 -4
- package/lib/tokenize/expressions/unary-expressions.js +2 -8
- package/lib/tokenize/literals/index.js +2 -8
- package/lib/tokenize/statements/break-statement.js +1 -4
- package/lib/tokenize/statements/export-declaration/export-declaration.js +2 -8
- package/lib/tokenize/statements/export-declaration/export-default-declaration.js +1 -3
- package/lib/tokenize/statements/import-declaration/import-declaration.js +2 -8
- package/lib/tokenize/statements/switch-statement.js +1 -3
- package/lib/tokenize/statements/variable-declaration/variable-declaration.js +3 -0
- package/lib/tokenize/tokenize.js +1 -4
- package/lib/tokenize/typescript/ts-interface-declaration.js +1 -3
- package/lib/tokenize/typescript/ts-mapped-type.js +1 -4
- package/lib/tokenize/typescript/ts-module-declaration.js +1 -3
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -113,10 +113,7 @@ const isForOf = ({parentPath}) => parentPath.isForOfStatement();
|
|
|
113
113
|
const isStringAndString = ([a, b]) => isStringLiteral(a) && isStringLiteral(b);
|
|
114
114
|
|
|
115
115
|
const isShortTwoSimplesInsideCall = (path, short) => {
|
|
116
|
-
const {
|
|
117
|
-
node,
|
|
118
|
-
parentPath,
|
|
119
|
-
} = path;
|
|
116
|
+
const {node, parentPath} = path;
|
|
120
117
|
|
|
121
118
|
const {elements} = node;
|
|
122
119
|
const {length} = elements;
|
|
@@ -139,7 +136,7 @@ function isOneSimple(path) {
|
|
|
139
136
|
|
|
140
137
|
const [first] = elements;
|
|
141
138
|
|
|
142
|
-
if (first.isIdentifier() && first.node.name.length <
|
|
139
|
+
if (first.isIdentifier() && first.node.name.length < 15)
|
|
143
140
|
return true;
|
|
144
141
|
|
|
145
142
|
if (first.isStringLiteral() && first.node.value.length > 10)
|
|
@@ -6,10 +6,7 @@ const {printParams} = require('./params');
|
|
|
6
6
|
module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
|
|
7
7
|
const {node} = path;
|
|
8
8
|
|
|
9
|
-
const {
|
|
10
|
-
generator,
|
|
11
|
-
async,
|
|
12
|
-
} = node;
|
|
9
|
+
const {generator, async} = node;
|
|
13
10
|
|
|
14
11
|
maybe.write(async, 'async ');
|
|
15
12
|
write('function');
|
|
@@ -41,10 +41,7 @@ module.exports.MemberExpression = (path, {print, maybe, traverse}) => {
|
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
module.exports.OptionalMemberExpression = (path, {print, maybe}) => {
|
|
44
|
-
const {
|
|
45
|
-
computed,
|
|
46
|
-
optional,
|
|
47
|
-
} = path.node;
|
|
44
|
+
const {computed, optional} = path.node;
|
|
48
45
|
|
|
49
46
|
print('__object');
|
|
50
47
|
|
|
@@ -4,10 +4,7 @@ const {isConcatenation} = require('../binary-expression/concatanate');
|
|
|
4
4
|
const {isOneLine} = require('./object-expression');
|
|
5
5
|
|
|
6
6
|
module.exports.ObjectProperty = (path, {maybe, traverse, write}) => {
|
|
7
|
-
const {
|
|
8
|
-
shorthand,
|
|
9
|
-
computed,
|
|
10
|
-
} = path.node;
|
|
7
|
+
const {shorthand, computed} = path.node;
|
|
11
8
|
|
|
12
9
|
const key = path.get('key');
|
|
13
10
|
const value = path.get('value');
|
|
@@ -12,6 +12,7 @@ const {
|
|
|
12
12
|
isCoupleLines,
|
|
13
13
|
exists,
|
|
14
14
|
} = require('../../is');
|
|
15
|
+
|
|
15
16
|
const {checkMaxPropertiesInOneLine} = require('./max-properties-in-one-line');
|
|
16
17
|
|
|
17
18
|
const isTwoLevelsDeep = ({parentPath}) => parentPath.parentPath.parentPath.isObjectProperty();
|
|
@@ -26,9 +27,11 @@ module.exports.ObjectPattern = {
|
|
|
26
27
|
|
|
27
28
|
const properties = path.get('properties');
|
|
28
29
|
const n = properties.length - 1;
|
|
30
|
+
|
|
29
31
|
const is = shouldAddNewline(path, {
|
|
30
32
|
maxPropertiesInOneLine,
|
|
31
33
|
});
|
|
34
|
+
|
|
32
35
|
const hasObject = n && hasObjectPattern(properties);
|
|
33
36
|
|
|
34
37
|
maybe.print.newline(is);
|
|
@@ -45,10 +48,7 @@ module.exports.ObjectPattern = {
|
|
|
45
48
|
const keyPath = property.get('key');
|
|
46
49
|
const isAssign = valuePath.isAssignmentPattern();
|
|
47
50
|
|
|
48
|
-
const {
|
|
49
|
-
shorthand,
|
|
50
|
-
computed,
|
|
51
|
-
} = property.node;
|
|
51
|
+
const {shorthand, computed} = property.node;
|
|
52
52
|
|
|
53
53
|
const couple = isCoupleLines(valuePath) && !exists(property.getPrevSibling()) && !path.parentPath.isObjectProperty();
|
|
54
54
|
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
isLast,
|
|
5
|
-
isNext,
|
|
6
|
-
} = require('../is');
|
|
3
|
+
const {isLast, isNext} = require('../is');
|
|
7
4
|
|
|
8
5
|
module.exports.UnaryExpression = unaryExpression;
|
|
9
6
|
module.exports.UpdateExpression = unaryExpression;
|
|
@@ -40,10 +37,7 @@ function printUnary(path, name, {print}) {
|
|
|
40
37
|
const isWord = (a) => /^(delete|typeof|void)$/.test(a);
|
|
41
38
|
|
|
42
39
|
function unaryExpression(path, {maybe, traverse}) {
|
|
43
|
-
const {
|
|
44
|
-
prefix,
|
|
45
|
-
operator,
|
|
46
|
-
} = path.node;
|
|
40
|
+
const {prefix, operator} = path.node;
|
|
47
41
|
|
|
48
42
|
const argPath = path.get('argument');
|
|
49
43
|
|
|
@@ -20,10 +20,7 @@ module.exports = {
|
|
|
20
20
|
write(path.node.value);
|
|
21
21
|
},
|
|
22
22
|
StringLiteral(path, {write}) {
|
|
23
|
-
const {
|
|
24
|
-
raw,
|
|
25
|
-
value,
|
|
26
|
-
} = path.node;
|
|
23
|
+
const {raw, value} = path.node;
|
|
27
24
|
|
|
28
25
|
write(raw || `'${value}'`);
|
|
29
26
|
},
|
|
@@ -31,10 +28,7 @@ module.exports = {
|
|
|
31
28
|
const {node} = path;
|
|
32
29
|
const parenthesized = node.extra?.parenthesized;
|
|
33
30
|
|
|
34
|
-
const {
|
|
35
|
-
name,
|
|
36
|
-
optional,
|
|
37
|
-
} = node;
|
|
31
|
+
const {name, optional} = node;
|
|
38
32
|
|
|
39
33
|
maybe.write(parenthesized, '(');
|
|
40
34
|
write(name);
|
|
@@ -7,10 +7,7 @@ const {
|
|
|
7
7
|
isLast,
|
|
8
8
|
} = require('../../is');
|
|
9
9
|
|
|
10
|
-
const {
|
|
11
|
-
markAfter,
|
|
12
|
-
isMarkedAfter,
|
|
13
|
-
} = require('../../mark');
|
|
10
|
+
const {markAfter, isMarkedAfter} = require('../../mark');
|
|
14
11
|
|
|
15
12
|
const {isExportNamespaceSpecifier} = require('@babel/types');
|
|
16
13
|
|
|
@@ -23,10 +20,7 @@ const options = {
|
|
|
23
20
|
};
|
|
24
21
|
|
|
25
22
|
module.exports.ExportSpecifier = (path, {print}) => {
|
|
26
|
-
const {
|
|
27
|
-
local,
|
|
28
|
-
exported,
|
|
29
|
-
} = path.node;
|
|
23
|
+
const {local, exported} = path.node;
|
|
30
24
|
|
|
31
25
|
print('__local');
|
|
32
26
|
|
|
@@ -23,9 +23,7 @@ module.exports.ExportDefaultDeclaration = {
|
|
|
23
23
|
traverse(declaration);
|
|
24
24
|
maybe.print(shouldAddSemi(declaration), ';');
|
|
25
25
|
},
|
|
26
|
-
afterSatisfy: () => [
|
|
27
|
-
notClass,
|
|
28
|
-
],
|
|
26
|
+
afterSatisfy: () => [notClass],
|
|
29
27
|
after(path, {print}) {
|
|
30
28
|
print.newline();
|
|
31
29
|
print.newline();
|
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const {markAfter} = require('../../mark');
|
|
4
4
|
|
|
5
|
-
const {
|
|
6
|
-
isLast,
|
|
7
|
-
isNext,
|
|
8
|
-
} = require('../../is');
|
|
5
|
+
const {isLast, isNext} = require('../../is');
|
|
9
6
|
|
|
10
7
|
const {parseImportSpecifiers} = require('parse-import-specifiers');
|
|
11
8
|
|
|
@@ -53,10 +50,7 @@ module.exports.ImportDeclaration = {
|
|
|
53
50
|
const last = index === importsCount;
|
|
54
51
|
const notLast = !last;
|
|
55
52
|
|
|
56
|
-
const {
|
|
57
|
-
imported,
|
|
58
|
-
local,
|
|
59
|
-
} = spec.node;
|
|
53
|
+
const {imported, local} = spec.node;
|
|
60
54
|
|
|
61
55
|
indent.inc();
|
|
62
56
|
|
|
@@ -130,6 +130,9 @@ function isNextCoupleLines(path) {
|
|
|
130
130
|
const next = path.getNextSibling();
|
|
131
131
|
const prev = path.getPrevSibling();
|
|
132
132
|
|
|
133
|
+
if (!exists(prev.getPrevSibling()) && next.isVariableDeclaration())
|
|
134
|
+
return false;
|
|
135
|
+
|
|
133
136
|
if (path.node.loc?.start.line === prev.node?.loc?.start.line + 2)
|
|
134
137
|
return false;
|
|
135
138
|
|
package/lib/tokenize/tokenize.js
CHANGED
package/package.json
CHANGED