@putout/printer 1.21.0 → 1.23.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 +11 -0
- package/lib/tokenize/expressions/array-expression.js +12 -4
- package/lib/tokenize/expressions/array-pattern.js +0 -1
- package/lib/tokenize/expressions/class.js +1 -0
- package/lib/tokenize/expressions/functions.js +0 -1
- package/lib/tokenize/expressions/new-expression.js +0 -1
- package/lib/tokenize/expressions/object-expression.js +12 -2
- package/lib/tokenize/statements/expression-statement.js +0 -1
- package/lib/tokenize/statements/for-of-statement.js +0 -1
- package/lib/tokenize/statements/if-statement.js +0 -3
- package/lib/tokenize/statements/switch-statement.js +0 -1
- package/lib/tokenize/statements/try-statements.js +0 -1
- package/lib/tokenize/statements/variable-declaration.js +0 -1
- package/lib/tokenize/tokenize.js +0 -1
- package/lib/tokenize/typescript/index.js +1 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2023.04.05, v1.23.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 316c0f6 @putout/printer: add support of ExpressionStatement parent of ObjectExpression
|
|
5
|
+
|
|
6
|
+
2023.04.04, v1.22.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- c8fc7b7 @putout/printer: improve support of tuples
|
|
10
|
+
- 599bd93 @putout/printer: set @putout/printer as putout printer
|
|
11
|
+
|
|
1
12
|
2023.04.04, v1.21.0
|
|
2
13
|
|
|
3
14
|
feature:
|
|
@@ -8,6 +8,7 @@ const isForOf = ({parentPath}) => parentPath.isForOfStatement();
|
|
|
8
8
|
const SECOND = 1;
|
|
9
9
|
|
|
10
10
|
const isStringAndArray = ([a, b]) => a?.isStringLiteral() && b?.isArrayExpression();
|
|
11
|
+
const isStringAndIdentifier = ([a, b]) => a?.isStringLiteral() && b?.isIdentifier();
|
|
11
12
|
const isArrayParent = (path) => path.parentPath.isArrayExpression();
|
|
12
13
|
const isTwoLongStrings = ([a, b]) => {
|
|
13
14
|
const LONG_STRING = 20;
|
|
@@ -27,9 +28,8 @@ module.exports.ArrayExpression = (path, {print, maybe, indent}) => {
|
|
|
27
28
|
|
|
28
29
|
print('[');
|
|
29
30
|
|
|
30
|
-
if (!isTwoLongStrings(elements)
|
|
31
|
-
indent.inc();
|
|
32
|
-
}
|
|
31
|
+
if (!isTwoLongStrings(elements))
|
|
32
|
+
maybe.indent.inc(!shouldIncreaseIndent);
|
|
33
33
|
|
|
34
34
|
const isNewLine = isNewlineBetweenElements(path, {elements});
|
|
35
35
|
const n = elements.length - 1;
|
|
@@ -133,13 +133,21 @@ function isNewlineBetweenElements(path, {elements}) {
|
|
|
133
133
|
if (isStringAndArray(elements))
|
|
134
134
|
return false;
|
|
135
135
|
|
|
136
|
+
if (isStringAndIdentifier(elements))
|
|
137
|
+
return false;
|
|
138
|
+
|
|
136
139
|
if (tooLong(path) || isCoupleLines(path) || !isNumbers(elements) && !isForOf(path) && isLastArg(path) && !isParentProperty(path))
|
|
137
140
|
return true;
|
|
138
141
|
|
|
139
142
|
return false;
|
|
140
143
|
}
|
|
141
144
|
|
|
142
|
-
function isTwoStringsDifferentLength(
|
|
145
|
+
function isTwoStringsDifferentLength(strings) {
|
|
146
|
+
const [a, b] = strings;
|
|
147
|
+
|
|
148
|
+
if (strings.length > 2)
|
|
149
|
+
return false;
|
|
150
|
+
|
|
143
151
|
if (!a?.isStringLiteral() || !b?.isStringLiteral())
|
|
144
152
|
return false;
|
|
145
153
|
|
|
@@ -5,6 +5,7 @@ const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
|
|
|
5
5
|
const isLogical = (path) => path.get('argument').isLogicalExpression();
|
|
6
6
|
const isValue = (path) => path.get('properties.0.value').node;
|
|
7
7
|
const isIf = (path) => path.parentPath.parentPath.isIfStatement();
|
|
8
|
+
const isParentExpression = (path) => path.parentPath.isExpressionStatement();
|
|
8
9
|
|
|
9
10
|
const isForOf = (path) => {
|
|
10
11
|
if (path.parentPath.isForOfStatement())
|
|
@@ -18,7 +19,7 @@ module.exports.ObjectExpression = (path, {print, maybe, indent}) => {
|
|
|
18
19
|
|
|
19
20
|
const properties = path.get('properties');
|
|
20
21
|
const {length} = properties;
|
|
21
|
-
const parens =
|
|
22
|
+
const parens = isParens(path);
|
|
22
23
|
const manyLines = !isOneLine(path);
|
|
23
24
|
|
|
24
25
|
maybe.print(parens, '(');
|
|
@@ -62,7 +63,6 @@ function shouldAddNewline(path) {
|
|
|
62
63
|
|
|
63
64
|
return path.parentPath.parentPath.isSpreadElement();
|
|
64
65
|
}
|
|
65
|
-
|
|
66
66
|
module.exports.ObjectProperty = (path, {print, maybe}) => {
|
|
67
67
|
const {
|
|
68
68
|
shorthand,
|
|
@@ -103,3 +103,13 @@ function isOneLine(path) {
|
|
|
103
103
|
|
|
104
104
|
return !isValue(path);
|
|
105
105
|
}
|
|
106
|
+
|
|
107
|
+
function isParens(path) {
|
|
108
|
+
if (isBodyOfArrow(path))
|
|
109
|
+
return true;
|
|
110
|
+
|
|
111
|
+
if (isParentExpression(path))
|
|
112
|
+
return true;
|
|
113
|
+
|
|
114
|
+
return false;
|
|
115
|
+
}
|
package/lib/tokenize/tokenize.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.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",
|