@putout/printer 12.10.0 → 12.12.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
|
@@ -17,6 +17,7 @@ const {
|
|
|
17
17
|
isClassProperty,
|
|
18
18
|
isTSPropertySignature,
|
|
19
19
|
isSpreadElement,
|
|
20
|
+
isClassBody,
|
|
20
21
|
} = types;
|
|
21
22
|
|
|
22
23
|
const isProperty = satisfy([
|
|
@@ -70,10 +71,20 @@ function isCommentOnPreviousLine(path) {
|
|
|
70
71
|
if (isCommentOfPrevious(path))
|
|
71
72
|
return false;
|
|
72
73
|
|
|
73
|
-
return line
|
|
74
|
+
return line <= loc.start.line - 1;
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
const isFirst = (path) =>
|
|
77
|
+
const isFirst = (path) => {
|
|
78
|
+
const {parentPath} = path;
|
|
79
|
+
|
|
80
|
+
if (path === parentPath.get('properties')[0])
|
|
81
|
+
return true;
|
|
82
|
+
|
|
83
|
+
if (isClassBody(parentPath) && isClassProperty(path))
|
|
84
|
+
return path === parentPath.get('body')[0];
|
|
85
|
+
|
|
86
|
+
return false;
|
|
87
|
+
};
|
|
77
88
|
|
|
78
89
|
module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics) => {
|
|
79
90
|
if (!semantics.comments)
|
|
@@ -101,10 +112,13 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
|
|
|
101
112
|
&& !insideFn
|
|
102
113
|
&& !propIs;
|
|
103
114
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
115
|
+
const count = leadingComments.length - 1;
|
|
116
|
+
|
|
117
|
+
for (const [index, {type, value}] of leadingComments.entries()) {
|
|
107
118
|
if (type === 'CommentLine') {
|
|
119
|
+
if (!path.isClassProperty() || index)
|
|
120
|
+
maybe.indent(isIndent);
|
|
121
|
+
|
|
108
122
|
maybeInsideFn(insideFn, {
|
|
109
123
|
print,
|
|
110
124
|
indent,
|
|
@@ -117,8 +131,12 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
|
|
|
117
131
|
|
|
118
132
|
print(`//${value}`);
|
|
119
133
|
|
|
120
|
-
|
|
121
|
-
|
|
134
|
+
if (index === count) {
|
|
135
|
+
maybe.print.breakline(propIs);
|
|
136
|
+
maybe.print.newline(!propIs);
|
|
137
|
+
} else {
|
|
138
|
+
print.newline();
|
|
139
|
+
}
|
|
122
140
|
|
|
123
141
|
if (isInsideVar(path)) {
|
|
124
142
|
indent.inc();
|
|
@@ -130,6 +148,8 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
|
|
|
130
148
|
}
|
|
131
149
|
|
|
132
150
|
if (type === 'CommentBlock') {
|
|
151
|
+
maybe.indent(isIndent);
|
|
152
|
+
|
|
133
153
|
const looksLikeMethod = path.isClassMethod();
|
|
134
154
|
const looksLikeDirective = path.isDirective();
|
|
135
155
|
const looksLikeProp = path.isObjectProperty();
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const {types} = require('@putout/babel');
|
|
4
4
|
const {isLooksLikeChain} = require('../../expressions/member-expression/is-looks-like-chain');
|
|
5
5
|
const {
|
|
6
|
+
isReturnStatement,
|
|
6
7
|
isExpressionStatement,
|
|
7
8
|
isMemberExpression,
|
|
8
9
|
isCallExpression,
|
|
@@ -38,5 +39,10 @@ function isTopCall(path) {
|
|
|
38
39
|
if (!isCallExpression(path))
|
|
39
40
|
return false;
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
const {parentPath} = path;
|
|
43
|
+
|
|
44
|
+
if (isReturnStatement(parentPath))
|
|
45
|
+
return true;
|
|
46
|
+
|
|
47
|
+
return isExpressionStatement(parentPath);
|
|
42
48
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.12.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",
|
|
@@ -52,10 +52,16 @@
|
|
|
52
52
|
],
|
|
53
53
|
"imports": {
|
|
54
54
|
"#test/printer": {
|
|
55
|
-
"default": "./test/
|
|
55
|
+
"default": "./test/print-extension/print-extension.js"
|
|
56
56
|
},
|
|
57
57
|
"#test/fixture": {
|
|
58
58
|
"default": "./test/fixture.js"
|
|
59
|
+
},
|
|
60
|
+
"#printer": {
|
|
61
|
+
"default": "./lib/printer.js"
|
|
62
|
+
},
|
|
63
|
+
"#test": {
|
|
64
|
+
"default": "./test/create-test.js"
|
|
59
65
|
}
|
|
60
66
|
},
|
|
61
67
|
"devDependencies": {
|