@putout/printer 11.14.0 → 12.1.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 +12 -0
- package/lib/tokenize/comment/parse-trailing-comments.js +1 -3
- package/lib/tokenize/expressions/array-expression/array-expression.js +1 -3
- package/lib/tokenize/expressions/array-expression/newline.js +2 -6
- package/lib/tokenize/expressions/call-expression/call-expression.js +1 -1
- package/lib/tokenize/expressions/class/class.js +1 -3
- package/lib/tokenize/expressions/function/params.js +1 -3
- package/lib/tokenize/expressions/member-expression/member-expressions.js +8 -10
- package/lib/tokenize/expressions/new-expression/new-expression.js +1 -1
- package/lib/tokenize/expressions/object-expression/object-expression.js +1 -3
- package/lib/tokenize/expressions/unary-expression/unary-expressions.js +3 -3
- package/lib/tokenize/is.js +9 -3
- package/lib/tokenize/jsx/jsx-element.js +18 -11
- package/lib/tokenize/jsx/jsx-fragment.js +1 -3
- package/lib/tokenize/overrides/overrides.js +24 -28
- package/lib/tokenize/statements/program/program.js +1 -3
- package/lib/tokenize/statements/variable-declaration/variable-declaration.js +1 -3
- package/lib/tokenize/typescript/enum/ts-enum-declaration.js +1 -1
- package/lib/tokenize/typescript/index.js +2 -2
- package/lib/tokenize/typescript/interface/ts-interface-declaration.js +1 -3
- package/lib/tokenize/typescript/type/ts-type-alias-declaration.js +8 -2
- package/package.json +2 -2
package/ChangeLog
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
2025.01.12, v12.1.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 93a6b0b @putout/printer: JSX: indent
|
|
5
|
+
|
|
6
|
+
2025.01.11, v12.0.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 610ea6e @putout/printer: babel alpha v15
|
|
10
|
+
- 8093095 @putout/printer: CallExpression: typeParameters -> typeArguments
|
|
11
|
+
- d628037 @putout/printer: @putout/babel v3.0.0
|
|
12
|
+
|
|
1
13
|
2025.01.05, v11.14.0
|
|
2
14
|
|
|
3
15
|
feature:
|
|
@@ -57,9 +57,7 @@ const isSpreadBeforeObject = (a) => {
|
|
|
57
57
|
if (prev.getPrevSibling().isObjectExpression())
|
|
58
58
|
return false;
|
|
59
59
|
|
|
60
|
-
return prev
|
|
61
|
-
.get('argument')
|
|
62
|
-
.isCallExpression();
|
|
60
|
+
return prev.get('argument').isCallExpression();
|
|
63
61
|
};
|
|
64
62
|
|
|
65
63
|
const isNextSimple = (a) => {
|
|
@@ -245,13 +245,9 @@ function isNumbers(elements) {
|
|
|
245
245
|
return false;
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
-
|
|
249
|
-
return !parentPath.isCallExpression();
|
|
250
|
-
}
|
|
248
|
+
const isLastArg = ({parentPath}) => !parentPath.isCallExpression();
|
|
251
249
|
|
|
252
|
-
|
|
253
|
-
return path.find(isObjectProperty);
|
|
254
|
-
}
|
|
250
|
+
const isParentProperty = (path) => path.find(isObjectProperty);
|
|
255
251
|
|
|
256
252
|
module.exports.isIncreaseIndent = isIncreaseIndent;
|
|
257
253
|
function isIncreaseIndent(path) {
|
|
@@ -18,7 +18,7 @@ const CallExpression = maybeParens((path, {indent, print, maybe, traverse}) => {
|
|
|
18
18
|
const isParentCall = tooLong(args) && path.parentPath.isCallExpression();
|
|
19
19
|
|
|
20
20
|
const callee = path.get('callee');
|
|
21
|
-
const typeParameters = path.get('
|
|
21
|
+
const typeParameters = path.get('typeArguments');
|
|
22
22
|
|
|
23
23
|
traverse(callee);
|
|
24
24
|
|
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const {parseComments} = require('../../comment/comment');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
return path.get('params');
|
|
7
|
-
}
|
|
5
|
+
const parseParams = (path) => path.get('params');
|
|
8
6
|
|
|
9
7
|
module.exports.printParams = (path, printer, semantics, customization = {}) => {
|
|
10
8
|
const {extra, typeParameters} = path.node;
|
|
@@ -83,16 +83,14 @@ const isIfUp = (path) => {
|
|
|
83
83
|
if (!ifPath)
|
|
84
84
|
return is;
|
|
85
85
|
|
|
86
|
-
ifPath
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
},
|
|
95
|
-
});
|
|
86
|
+
ifPath.get('test').traverse({
|
|
87
|
+
MemberExpression(currentPath) {
|
|
88
|
+
if (path === currentPath) {
|
|
89
|
+
is = true;
|
|
90
|
+
path.stop();
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
});
|
|
96
94
|
|
|
97
95
|
return is;
|
|
98
96
|
};
|
|
@@ -142,9 +142,7 @@ const notLastArgInsideCall = (path) => {
|
|
|
142
142
|
if (isCoupleLines(path))
|
|
143
143
|
return false;
|
|
144
144
|
|
|
145
|
-
return path !== parentPath
|
|
146
|
-
.get('arguments')
|
|
147
|
-
.at(-1);
|
|
145
|
+
return path !== parentPath.get('arguments').at(-1);
|
|
148
146
|
};
|
|
149
147
|
|
|
150
148
|
const ONE_LINE = true;
|
|
@@ -20,7 +20,7 @@ module.exports.UnaryExpression = unaryExpression;
|
|
|
20
20
|
module.exports.UpdateExpression = unaryExpression;
|
|
21
21
|
|
|
22
22
|
module.exports.AwaitExpression = maybeParens((path, {print}) => {
|
|
23
|
-
printUnary(
|
|
23
|
+
printUnary('await', {
|
|
24
24
|
print,
|
|
25
25
|
});
|
|
26
26
|
});
|
|
@@ -37,7 +37,7 @@ module.exports.YieldExpression = maybeParens((path, {print, maybe}) => {
|
|
|
37
37
|
module.exports.ThrowStatement = (path, {print, indent, maybe}) => {
|
|
38
38
|
indent();
|
|
39
39
|
|
|
40
|
-
printUnary(
|
|
40
|
+
printUnary('throw', {
|
|
41
41
|
print,
|
|
42
42
|
});
|
|
43
43
|
|
|
@@ -46,7 +46,7 @@ module.exports.ThrowStatement = (path, {print, indent, maybe}) => {
|
|
|
46
46
|
maybe.print.breakline(isNext(path));
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
function printUnary(
|
|
49
|
+
function printUnary(name, {print}) {
|
|
50
50
|
print(`${name} `);
|
|
51
51
|
print('__argument');
|
|
52
52
|
}
|
package/lib/tokenize/is.js
CHANGED
|
@@ -35,11 +35,17 @@ const isPrev = (path) => {
|
|
|
35
35
|
const isNextParent = (path) => isNext(path.parentPath);
|
|
36
36
|
const isLast = (path) => isParentProgram(path) && !isNext(path);
|
|
37
37
|
|
|
38
|
-
module.exports.isNextObject = (a) => a
|
|
39
|
-
|
|
38
|
+
module.exports.isNextObject = (a) => a
|
|
39
|
+
.getNextSibling()
|
|
40
|
+
.isObjectExpression();
|
|
41
|
+
module.exports.isPrevObject = (a) => a
|
|
42
|
+
.getPrevSibling()
|
|
43
|
+
.isObjectExpression();
|
|
40
44
|
|
|
41
45
|
module.exports.isFirst = (path) => path.node === path.parentPath.node.body?.[0];
|
|
42
|
-
module.exports.isPrevBody = (path) => path
|
|
46
|
+
module.exports.isPrevBody = (path) => path
|
|
47
|
+
.getPrevSibling()
|
|
48
|
+
.isBlockStatement();
|
|
43
49
|
module.exports.isNext = isNext;
|
|
44
50
|
module.exports.isPrev = isPrev;
|
|
45
51
|
module.exports.isNextParent = isNextParent;
|
|
@@ -17,22 +17,16 @@ module.exports.JSXElement = {
|
|
|
17
17
|
write.newline();
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
|
-
print(path, {print, traverse,
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (insideFn && insideCall)
|
|
25
|
-
indent.inc();
|
|
20
|
+
print(path, {print, traverse, maybe}) {
|
|
21
|
+
const needIndent = isNeedIndent(path);
|
|
22
|
+
maybe.indent.inc(needIndent);
|
|
26
23
|
|
|
27
24
|
print('__openingElement');
|
|
28
|
-
path
|
|
29
|
-
.get('children')
|
|
30
|
-
.map(traverse);
|
|
25
|
+
path.get('children').map(traverse);
|
|
31
26
|
|
|
32
27
|
print('__closingElement');
|
|
33
28
|
|
|
34
|
-
|
|
35
|
-
indent.dec();
|
|
29
|
+
maybe.indent.dec(needIndent);
|
|
36
30
|
},
|
|
37
31
|
after(path, {write, indent, maybe}) {
|
|
38
32
|
const {leadingComments} = path.node;
|
|
@@ -62,3 +56,16 @@ function condition(path) {
|
|
|
62
56
|
|
|
63
57
|
return path.parentPath.isVariableDeclarator();
|
|
64
58
|
}
|
|
59
|
+
|
|
60
|
+
function isNeedIndent(path) {
|
|
61
|
+
const attributesCount = path.node.openingElement.attributes.length;
|
|
62
|
+
|
|
63
|
+
if (attributesCount > 3)
|
|
64
|
+
return false;
|
|
65
|
+
|
|
66
|
+
const insideFn = path.parentPath.isArrowFunctionExpression();
|
|
67
|
+
const insideJSX = path.parentPath.isJSXElement();
|
|
68
|
+
const insideCall = path.parentPath.parentPath.isCallExpression();
|
|
69
|
+
|
|
70
|
+
return insideJSX || insideFn && insideCall;
|
|
71
|
+
}
|
|
@@ -9,9 +9,7 @@ module.exports.JSXFragment = {
|
|
|
9
9
|
},
|
|
10
10
|
print(path, {print, traverse}) {
|
|
11
11
|
print('__openingFragment');
|
|
12
|
-
path
|
|
13
|
-
.get('children')
|
|
14
|
-
.map(traverse);
|
|
12
|
+
path.get('children').map(traverse);
|
|
15
13
|
print('__closingFragment');
|
|
16
14
|
},
|
|
17
15
|
after(path, {write, indent}) {
|
|
@@ -16,32 +16,28 @@ module.exports.parseOverrides = (overrides = {}) => {
|
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
}
|
|
19
|
+
const initFormat = (format) => ({
|
|
20
|
+
indent: ' ',
|
|
21
|
+
newline: '\n',
|
|
22
|
+
space: ' ',
|
|
23
|
+
splitter: '\n',
|
|
24
|
+
quote: `'`,
|
|
25
|
+
endOfFile: '\n',
|
|
26
|
+
...format,
|
|
27
|
+
});
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
};
|
|
47
|
-
}
|
|
29
|
+
const initSemantics = (semantics = {}) => ({
|
|
30
|
+
comments: true,
|
|
31
|
+
maxPropertiesInOneLine: 2,
|
|
32
|
+
maxPropertiesLengthInOneLine: 15,
|
|
33
|
+
maxSpecifiersInOneLine: 2,
|
|
34
|
+
maxElementsInOneLine: 5,
|
|
35
|
+
maxLogicalsInOneLine: 3,
|
|
36
|
+
maxVariablesInOneLine: 4,
|
|
37
|
+
maxTypesInOneLine: 3,
|
|
38
|
+
trailingComma: true,
|
|
39
|
+
encodeSingleQuote: true,
|
|
40
|
+
encodeDoubleQuote: false,
|
|
41
|
+
...semantics,
|
|
42
|
+
roundBraces: parseRoundBraces(semantics),
|
|
43
|
+
});
|
|
@@ -204,7 +204,5 @@ const isNextAssign = (path) => {
|
|
|
204
204
|
if (parentPath.isBlockStatement() && parentPath.node.body.length < 3)
|
|
205
205
|
return false;
|
|
206
206
|
|
|
207
|
-
return nextPath
|
|
208
|
-
.get('expression')
|
|
209
|
-
.isAssignmentExpression();
|
|
207
|
+
return nextPath.get('expression').isAssignmentExpression();
|
|
210
208
|
};
|
|
@@ -136,7 +136,7 @@ module.exports = {
|
|
|
136
136
|
},
|
|
137
137
|
TSInstantiationExpression(path, {print}) {
|
|
138
138
|
print('__expression');
|
|
139
|
-
print('
|
|
139
|
+
print('__typeArguments');
|
|
140
140
|
},
|
|
141
141
|
TSAnyKeyword(path, {write}) {
|
|
142
142
|
write('any');
|
|
@@ -165,7 +165,7 @@ module.exports = {
|
|
|
165
165
|
},
|
|
166
166
|
TSClassImplements(path, {print}) {
|
|
167
167
|
print('__expression');
|
|
168
|
-
print('
|
|
168
|
+
print('__typeArguments');
|
|
169
169
|
},
|
|
170
170
|
TSInterfaceHeritage(path, {print}) {
|
|
171
171
|
print('__expression');
|
|
@@ -8,8 +8,14 @@ const {
|
|
|
8
8
|
|
|
9
9
|
const {markAfter} = require('../../mark');
|
|
10
10
|
const {maybeDeclare} = require('../../maybe/maybe-declare');
|
|
11
|
-
|
|
12
|
-
const
|
|
11
|
+
|
|
12
|
+
const isNextType = (a) => a
|
|
13
|
+
.getNextSibling()
|
|
14
|
+
.isTSTypeAliasDeclaration();
|
|
15
|
+
|
|
16
|
+
const isNextExport = (a) => a
|
|
17
|
+
.getNextSibling()
|
|
18
|
+
.isExportDeclaration();
|
|
13
19
|
|
|
14
20
|
module.exports.TSTypeAliasDeclaration = {
|
|
15
21
|
beforeIf: (path) => !path.parentPath.isExportDeclaration(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.1.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Simplest possible opinionated Babel AST printer for 🐊Putout",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"report": "madrun report"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@putout/babel": "^
|
|
35
|
+
"@putout/babel": "^3.0.0",
|
|
36
36
|
"@putout/compare": "^15.0.2",
|
|
37
37
|
"@putout/operate": "^12.0.0",
|
|
38
38
|
"@putout/operator-json": "^2.0.0",
|