@putout/printer 1.7.3 → 1.7.4
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 +10 -0
- package/lib/tokenize/expressions/call-expression.js +2 -1
- package/lib/tokenize/statements/block-statement.js +2 -2
- package/lib/tokenize/statements/expression-statement.js +7 -9
- package/lib/tokenize/statements/variable-declaration.js +2 -2
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/lib/tokenize/comments.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {isFirst} = require('./is');
|
|
4
|
+
const {hasPrevNewline} = require('./mark');
|
|
5
|
+
|
|
3
6
|
module.exports.parseComments = (path, {print}) => {
|
|
4
7
|
const {leadingComments} = path.node;
|
|
5
8
|
|
|
@@ -10,6 +13,9 @@ module.exports.parseComments = (path, {print}) => {
|
|
|
10
13
|
function parseLeadingComments(path, {print}) {
|
|
11
14
|
const {leadingComments} = path.node;
|
|
12
15
|
|
|
16
|
+
if (shouldAddNewline(path))
|
|
17
|
+
print.linebreak();
|
|
18
|
+
|
|
13
19
|
for (const {type, value} of leadingComments) {
|
|
14
20
|
if (type === 'CommentLine') {
|
|
15
21
|
print(`//${value}`);
|
|
@@ -23,3 +29,7 @@ function parseLeadingComments(path, {print}) {
|
|
|
23
29
|
}
|
|
24
30
|
}
|
|
25
31
|
}
|
|
32
|
+
|
|
33
|
+
function shouldAddNewline(path) {
|
|
34
|
+
return path.isStatement() && !isFirst(path) && !hasPrevNewline(path);
|
|
35
|
+
}
|
|
@@ -20,8 +20,9 @@ module.exports.CallExpression = CallExpression;
|
|
|
20
20
|
function CallExpression(path, {indent, print, maybe}) {
|
|
21
21
|
const isParentCall = toLong(path) && path.parentPath.isCallExpression();
|
|
22
22
|
|
|
23
|
-
if (isNewLineBefore(path) && !isMarkedParentBefore(path) && !hasPrevNewline(path.parentPath))
|
|
23
|
+
if (isNewLineBefore(path) && !isMarkedParentBefore(path) && !hasPrevNewline(path.parentPath)) {
|
|
24
24
|
print.breakline();
|
|
25
|
+
}
|
|
25
26
|
|
|
26
27
|
print('__callee');
|
|
27
28
|
print('(');
|
|
@@ -26,9 +26,9 @@ module.exports.BlockStatement = (path, {indent, maybe, print}) => {
|
|
|
26
26
|
print(',');
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const
|
|
29
|
+
const shouldAddNewline = isAddNewLineAfter(path);
|
|
30
30
|
|
|
31
|
-
if (
|
|
31
|
+
if (shouldAddNewline) {
|
|
32
32
|
print.newline();
|
|
33
33
|
}
|
|
34
34
|
};
|
|
@@ -8,21 +8,19 @@ const {
|
|
|
8
8
|
|
|
9
9
|
const {isNext} = require('../is');
|
|
10
10
|
|
|
11
|
-
module.exports.ExpressionStatement = (path, {
|
|
12
|
-
if (isCoupleLinesExpression(path) && !isFirst(path) &&
|
|
11
|
+
module.exports.ExpressionStatement = (path, {indent, print}) => {
|
|
12
|
+
if (isCoupleLinesExpression(path) && !isFirst(path) && shouldAddNewline(path) && !hasPrevNewline(path)) {
|
|
13
13
|
print.breakline();
|
|
14
14
|
markBefore(path);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
const expressionPath = path.get('expression');
|
|
18
|
-
|
|
19
17
|
indent();
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
print('__expression');
|
|
19
|
+
print(';');
|
|
20
|
+
print.newline();
|
|
23
21
|
|
|
24
22
|
if (isStrictMode(path) || isCoupleLinesExpression(path) && isNext(path)) {
|
|
25
|
-
|
|
23
|
+
print.newline();
|
|
26
24
|
markAfter(path);
|
|
27
25
|
}
|
|
28
26
|
};
|
|
@@ -49,7 +47,7 @@ function isFirst(path) {
|
|
|
49
47
|
return path.node === path.parentPath.node.body[0];
|
|
50
48
|
}
|
|
51
49
|
|
|
52
|
-
function
|
|
50
|
+
function shouldAddNewline(path) {
|
|
53
51
|
const prev = path.getPrevSibling();
|
|
54
52
|
|
|
55
53
|
if (prev.isVariableDeclaration())
|
|
@@ -36,7 +36,7 @@ module.exports.VariableDeclaration = (path, {maybe, print}) => {
|
|
|
36
36
|
maybe.print(isParentBlock, ';');
|
|
37
37
|
maybe.print.newline(isParentBlock);
|
|
38
38
|
|
|
39
|
-
const is =
|
|
39
|
+
const is = shouldAddNewlineAfter(path);
|
|
40
40
|
|
|
41
41
|
if (is) {
|
|
42
42
|
print.linebreak();
|
|
@@ -44,7 +44,7 @@ module.exports.VariableDeclaration = (path, {maybe, print}) => {
|
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
function
|
|
47
|
+
function shouldAddNewlineAfter(path) {
|
|
48
48
|
if (isLast(path))
|
|
49
49
|
return true;
|
|
50
50
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.4",
|
|
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",
|