@putout/printer 1.52.3 → 1.53.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/statements/variable-declaration.js +27 -28
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2023.04.17, v1.53.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- fd99eef @putout/printer: VariableDeclaration: use afterSatisfy
|
|
5
|
+
|
|
6
|
+
2023.04.17, v1.52.4
|
|
7
|
+
|
|
8
|
+
fix:
|
|
9
|
+
- cda4b9e @putout/printer: newline when VariableDeclaration inside of ExportDeclaration
|
|
10
|
+
|
|
1
11
|
2023.04.17, v1.52.3
|
|
2
12
|
|
|
3
13
|
fix:
|
|
@@ -11,6 +11,8 @@ const {
|
|
|
11
11
|
markAfter,
|
|
12
12
|
} = require('../mark');
|
|
13
13
|
|
|
14
|
+
const {isExportDeclaration} = require('@babel/types');
|
|
15
|
+
|
|
14
16
|
const isParentBlock = (path) => /Program|BlockStatement|Export/.test(path.parentPath.type);
|
|
15
17
|
|
|
16
18
|
module.exports.VariableDeclaration = {
|
|
@@ -37,7 +39,15 @@ module.exports.VariableDeclaration = {
|
|
|
37
39
|
|
|
38
40
|
store(wasNewline);
|
|
39
41
|
},
|
|
40
|
-
|
|
42
|
+
afterSatisfy: () => [
|
|
43
|
+
noNextParentBlock,
|
|
44
|
+
notLastCoupleLines,
|
|
45
|
+
isNextAssign,
|
|
46
|
+
isNextCoupleLines,
|
|
47
|
+
notLastPrevVarNotNextVar,
|
|
48
|
+
isNewlineBetweenStatements,
|
|
49
|
+
notLastParentExport,
|
|
50
|
+
],
|
|
41
51
|
after(path, {maybe, store}) {
|
|
42
52
|
const wasNewline = store();
|
|
43
53
|
maybe.print.linebreak(wasNewline);
|
|
@@ -57,36 +67,23 @@ function notLastParentExport(path) {
|
|
|
57
67
|
return path.parentPath.isExportDeclaration();
|
|
58
68
|
}
|
|
59
69
|
|
|
60
|
-
function
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return false;
|
|
66
|
-
|
|
67
|
-
if (isCoupleLines(path))
|
|
68
|
-
return true;
|
|
69
|
-
|
|
70
|
-
if (isNextAssign(path))
|
|
71
|
-
return true;
|
|
72
|
-
|
|
73
|
-
const next = path.getNextSibling();
|
|
70
|
+
function notLastCoupleLines(path) {
|
|
71
|
+
return !isLast(path) && isCoupleLines(path);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function notLastPrevVarNotNextVar(path) {
|
|
74
75
|
const prev = path.getPrevSibling();
|
|
76
|
+
const next = path.getNextSibling();
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (isNewlineBetweenStatements(path))
|
|
83
|
-
return true;
|
|
84
|
-
|
|
85
|
-
if (notLastParentExport(path))
|
|
86
|
-
return true;
|
|
78
|
+
return !isLast(path) && prev.isVariableDeclaration() && !next.isVariableDeclaration();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function isNextCoupleLines(path) {
|
|
82
|
+
const next = path.getNextSibling();
|
|
87
83
|
|
|
88
|
-
return
|
|
84
|
+
return isCoupleLines(next);
|
|
89
85
|
}
|
|
86
|
+
|
|
90
87
|
const isLast = (path) => path.parentPath?.isProgram() && !isNext(path);
|
|
91
88
|
|
|
92
89
|
function shouldAddNewlineBefore(path) {
|
|
@@ -104,8 +101,10 @@ function shouldAddNewlineBefore(path) {
|
|
|
104
101
|
if (prevPath.isStatement() && !prevPath.isExpressionStatement() && !prevPath.isBlockStatement())
|
|
105
102
|
return false;
|
|
106
103
|
|
|
107
|
-
if (isCoupleLines(path))
|
|
104
|
+
if (!isExportDeclaration(path.parentPath) && isCoupleLines(path))
|
|
108
105
|
return true;
|
|
106
|
+
|
|
107
|
+
return false;
|
|
109
108
|
}
|
|
110
109
|
|
|
111
110
|
function isFirst(path) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.53.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",
|