@putout/printer 1.49.0 → 1.50.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
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
2023.04.14, v1.50.0
|
|
2
|
+
|
|
3
|
+
fix:
|
|
4
|
+
- 6203f72 @putout/printer: ArrayExpression: one element CallExpression
|
|
5
|
+
|
|
6
|
+
feature:
|
|
7
|
+
- 491126f @putout/printer: ArrayExpression: two elements ReturnStatement: no newline
|
|
8
|
+
|
|
9
|
+
2023.04.14, v1.49.1
|
|
10
|
+
|
|
11
|
+
fix:
|
|
12
|
+
- 378734f @putout/printer: newline inside in ObjectPattern inside ForOfStatement
|
|
13
|
+
|
|
1
14
|
2023.04.14, v1.49.0
|
|
2
15
|
|
|
3
16
|
fix:
|
|
@@ -21,6 +21,9 @@ const isStringAndString = ([a, b]) => isStringLiteral(a) && isStringLiteral(b);
|
|
|
21
21
|
const isIdentifierAndIdentifier = ([a, b]) => isIdentifier(a) && isIdentifier(b);
|
|
22
22
|
const isArrayParent = (path) => path.parentPath.isArrayExpression();
|
|
23
23
|
|
|
24
|
+
const isOneElementCall = (path, {elements}) => path.parentPath.isCallExpression() && elements.length === 1;
|
|
25
|
+
const isTwoElementReturn = (path, {elements}) => path.parentPath.isReturnStatement() && elements.length === 2;
|
|
26
|
+
|
|
24
27
|
const isTwoLongStrings = ([a, b]) => {
|
|
25
28
|
const LONG_STRING = 20;
|
|
26
29
|
|
|
@@ -172,10 +175,13 @@ function tooLong(path) {
|
|
|
172
175
|
}
|
|
173
176
|
|
|
174
177
|
function isNewlineBetweenElements(path, {elements}) {
|
|
175
|
-
if (
|
|
178
|
+
if (isTwoElementReturn(path, {elements}))
|
|
176
179
|
return false;
|
|
177
180
|
|
|
178
|
-
if (
|
|
181
|
+
if (isOneElementCall(path, {elements}))
|
|
182
|
+
return false;
|
|
183
|
+
|
|
184
|
+
if (isIncreaseIndent(path))
|
|
179
185
|
return false;
|
|
180
186
|
|
|
181
187
|
if (isInsideLoop(path))
|
|
@@ -1,29 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {isCoupleLines} = require('../is');
|
|
4
|
-
|
|
5
3
|
const {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} = require('
|
|
4
|
+
isCoupleLines,
|
|
5
|
+
isForOf,
|
|
6
|
+
isIf,
|
|
7
|
+
} = require('../is');
|
|
8
|
+
|
|
9
|
+
const {isFunction} = require('@babel/types');
|
|
10
10
|
|
|
11
11
|
const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
|
|
12
12
|
const isLogical = (path) => path.get('argument').isLogicalExpression();
|
|
13
13
|
const isValue = (path) => path.get('properties.0.value').node;
|
|
14
|
-
const isIfOrStatement = (a) => isIfStatement(a) || isStatement(a);
|
|
15
|
-
const isIf = (path) => isIfStatement(path.find(
|
|
16
|
-
isIfOrStatement,
|
|
17
|
-
));
|
|
18
14
|
const isParentExpression = (path) => path.parentPath.isExpressionStatement();
|
|
19
15
|
|
|
20
|
-
const isForOf = (path) => {
|
|
21
|
-
if (path.parentPath.isForOfStatement())
|
|
22
|
-
return true;
|
|
23
|
-
|
|
24
|
-
return path.parentPath?.parentPath?.isForOfStatement();
|
|
25
|
-
};
|
|
26
|
-
|
|
27
16
|
module.exports.ObjectExpression = (path, {print, maybe, indent}) => {
|
|
28
17
|
indent.inc();
|
|
29
18
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {isIdentifier} = require('@babel/types');
|
|
4
|
-
const isForOf = (
|
|
4
|
+
const {isForOf} = require('../is');
|
|
5
5
|
|
|
6
6
|
module.exports.ObjectPattern = (path, {indent, print, maybe}) => {
|
|
7
7
|
indent.inc();
|
package/lib/tokenize/is.js
CHANGED
|
@@ -5,6 +5,10 @@ const {isMarkedAfter} = require('./mark');
|
|
|
5
5
|
const {
|
|
6
6
|
isStringLiteral,
|
|
7
7
|
isIdentifier,
|
|
8
|
+
isIfStatement,
|
|
9
|
+
isStatement,
|
|
10
|
+
isForOfStatement,
|
|
11
|
+
isVariableDeclaration,
|
|
8
12
|
} = require('@babel/types');
|
|
9
13
|
|
|
10
14
|
const isParentProgram = (path) => path.parentPath?.isProgram();
|
|
@@ -48,3 +52,22 @@ function isNextCoupleLines(path) {
|
|
|
48
52
|
return isCoupleLines(path.getNextSibling());
|
|
49
53
|
}
|
|
50
54
|
module.exports.isStringAndIdentifier = ([a, b]) => isStringLiteral(a) && isIdentifier(b);
|
|
55
|
+
|
|
56
|
+
const isIfOrStatement = (a) => isIfStatement(a) || isStatement(a);
|
|
57
|
+
const isForOfOrStatement = (a) => isForOfStatement(a) || isStatement(a);
|
|
58
|
+
|
|
59
|
+
module.exports.isIf = (path) => isIfStatement(path.find(
|
|
60
|
+
isIfOrStatement,
|
|
61
|
+
));
|
|
62
|
+
|
|
63
|
+
module.exports.isForOf = (path) => {
|
|
64
|
+
const current = path.find(isForOfOrStatement);
|
|
65
|
+
|
|
66
|
+
if (isForOfStatement(current))
|
|
67
|
+
return true;
|
|
68
|
+
|
|
69
|
+
if (isVariableDeclaration(current))
|
|
70
|
+
return isForOfStatement(current.parentPath);
|
|
71
|
+
|
|
72
|
+
return false;
|
|
73
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.50.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",
|