@putout/printer 1.57.0 → 1.58.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/lib/tokenize/comments.js +9 -2
- package/lib/tokenize/expressions/class.js +7 -1
- package/lib/tokenize/expressions/functions/arrow-function-expression.js +8 -1
- package/lib/tokenize/expressions/functions/function-declaration.js +12 -0
- package/lib/tokenize/jsx/jsx-element.js +16 -1
- package/lib/tokenize/jsx/jsx-opening-element.js +25 -23
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/lib/tokenize/comments.js
CHANGED
|
@@ -10,12 +10,19 @@ module.exports.parseLeadingComments = (path, {print, maybe}) => {
|
|
|
10
10
|
if (!leadingComments || !leadingComments.length)
|
|
11
11
|
return;
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
const insideFn = path.parentPath.isFunction();
|
|
14
|
+
const isIndent = !path.isClassMethod() && !insideFn;
|
|
14
15
|
|
|
15
16
|
for (const {type, value} of leadingComments) {
|
|
16
|
-
maybe.indent(
|
|
17
|
+
maybe.indent(isIndent);
|
|
17
18
|
|
|
18
19
|
if (type === 'CommentLine') {
|
|
20
|
+
maybe.indent.inc(insideFn);
|
|
21
|
+
maybe.indent.inc(insideFn);
|
|
22
|
+
maybe.print.breakline(insideFn);
|
|
23
|
+
maybe.indent.dec(insideFn);
|
|
24
|
+
maybe.indent.dec(insideFn);
|
|
25
|
+
|
|
19
26
|
print(`//${value}`);
|
|
20
27
|
print.newline();
|
|
21
28
|
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {isNext} = require('../is');
|
|
4
|
+
|
|
3
5
|
module.exports.ClassExpression = classVisitor;
|
|
4
6
|
module.exports.ClassDeclaration = classVisitor;
|
|
5
7
|
|
|
6
|
-
module.exports.ClassDeclaration = (path, {print, indent, maybe}) => {
|
|
8
|
+
module.exports.ClassDeclaration = (path, {print, indent, maybe, write}) => {
|
|
7
9
|
indent();
|
|
8
10
|
|
|
9
11
|
classVisitor(path, {
|
|
@@ -11,6 +13,10 @@ module.exports.ClassDeclaration = (path, {print, indent, maybe}) => {
|
|
|
11
13
|
indent,
|
|
12
14
|
maybe,
|
|
13
15
|
});
|
|
16
|
+
|
|
17
|
+
if (!path.parentPath.isExportDeclaration() && isNext(path)) {
|
|
18
|
+
write.newline();
|
|
19
|
+
}
|
|
14
20
|
};
|
|
15
21
|
|
|
16
22
|
function classVisitor(path, {print, indent, maybe}) {
|
|
@@ -37,7 +37,14 @@ module.exports.ArrowFunctionExpression = {
|
|
|
37
37
|
|
|
38
38
|
print.space();
|
|
39
39
|
print('=>');
|
|
40
|
-
|
|
40
|
+
|
|
41
|
+
const body = path.get('body');
|
|
42
|
+
|
|
43
|
+
const insideCall = path.parentPath.isCallExpression();
|
|
44
|
+
const isJSX = body.isJSXElement();
|
|
45
|
+
|
|
46
|
+
maybe.print.space(!insideCall && isJSX);
|
|
47
|
+
maybe.print.space(!isJSX);
|
|
41
48
|
print('__body');
|
|
42
49
|
},
|
|
43
50
|
after(path, {write}) {
|
|
@@ -2,8 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
const {markAfter} = require('../../mark');
|
|
4
4
|
const {isNext} = require('../../is');
|
|
5
|
+
const isFirst = (path) => !path.getPrevSibling().node;
|
|
5
6
|
|
|
6
7
|
module.exports.FunctionDeclaration = {
|
|
8
|
+
beforeIf(path) {
|
|
9
|
+
if (isFirst(path))
|
|
10
|
+
return false;
|
|
11
|
+
|
|
12
|
+
const prev = path.getPrevSibling();
|
|
13
|
+
|
|
14
|
+
return prev.isClassDeclaration();
|
|
15
|
+
},
|
|
16
|
+
before(path, {write}) {
|
|
17
|
+
write.newline();
|
|
18
|
+
},
|
|
7
19
|
print(path, {print, maybe}) {
|
|
8
20
|
const {async} = path.node;
|
|
9
21
|
|
|
@@ -7,10 +7,25 @@ module.exports.JSXElement = {
|
|
|
7
7
|
indent.inc();
|
|
8
8
|
write.breakline();
|
|
9
9
|
},
|
|
10
|
-
print(path, {print, traverse}) {
|
|
10
|
+
print(path, {print, traverse, indent, maybe}) {
|
|
11
|
+
const insideFn = path.parentPath.isArrowFunctionExpression();
|
|
12
|
+
const insideCall = path.parentPath.parentPath.isCallExpression();
|
|
13
|
+
|
|
14
|
+
if (insideFn && insideCall) {
|
|
15
|
+
indent.inc();
|
|
16
|
+
indent.inc();
|
|
17
|
+
indent();
|
|
18
|
+
}
|
|
19
|
+
|
|
11
20
|
print('__openingElement');
|
|
12
21
|
path.get('children').map(traverse);
|
|
13
22
|
print('__closingElement');
|
|
23
|
+
|
|
24
|
+
if (insideFn && insideCall) {
|
|
25
|
+
indent.dec();
|
|
26
|
+
maybe.print.breakline(insideCall);
|
|
27
|
+
indent.dec();
|
|
28
|
+
}
|
|
14
29
|
},
|
|
15
30
|
after(path, {write, indent}) {
|
|
16
31
|
indent.dec();
|
|
@@ -2,27 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
const {isCoupleLines} = require('../is');
|
|
4
4
|
|
|
5
|
-
module.exports.JSXOpeningElement =
|
|
6
|
-
print(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
5
|
+
module.exports.JSXOpeningElement = {
|
|
6
|
+
print(path, {print, maybe}) {
|
|
7
|
+
print('<');
|
|
8
|
+
print('__name');
|
|
9
|
+
|
|
10
|
+
const coupleLines = isCoupleLines(path);
|
|
11
|
+
const noCoupleLines = !coupleLines;
|
|
12
|
+
const shouldIndent = coupleLines && path.parentPath.parentPath.isJSXElement();
|
|
13
|
+
|
|
14
|
+
maybe.indent.inc(shouldIndent);
|
|
15
|
+
|
|
16
|
+
for (const attr of path.get('attributes')) {
|
|
17
|
+
maybe.print.space(noCoupleLines);
|
|
18
|
+
print(attr);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (isCoupleLines(path))
|
|
22
|
+
print.breakline();
|
|
23
|
+
|
|
24
|
+
if (path.node.selfClosing)
|
|
25
|
+
print('/');
|
|
26
|
+
|
|
27
|
+
print('>');
|
|
28
|
+
maybe.indent.dec(shouldIndent);
|
|
29
|
+
},
|
|
28
30
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.58.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Easiest possible opinionated Babel AST printer made with ❤️ to use in 🐊Putout",
|