@putout/printer 12.2.0 → 12.4.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/object-expression/is-inside-tuple.js +22 -0
- package/lib/tokenize/expressions/object-expression/object-expression.js +11 -4
- package/lib/tokenize/statements/{expression-statement.js → expression-statement/expression-statement.js} +21 -6
- package/lib/tokenize/statements/index.js +1 -1
- package/package.json +9 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2025.01.15, v12.4.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 96a5778 ObjectExpression: inside tuple
|
|
5
|
+
|
|
6
|
+
2025.01.14, v12.3.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- a8074a5 @putout/printer: ExpressionStatement: inside ReturnStatement
|
|
10
|
+
- ecf7d0e @putout/printer: move out ExpressionStatement
|
|
11
|
+
|
|
1
12
|
2025.01.13, v12.2.0
|
|
2
13
|
|
|
3
14
|
feature:
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types} = require('@putout/babel');
|
|
4
|
+
const {
|
|
5
|
+
isNumericLiteral,
|
|
6
|
+
isNullLiteral,
|
|
7
|
+
isArrayExpression,
|
|
8
|
+
} = types;
|
|
9
|
+
|
|
10
|
+
module.exports.isInsideTuple = (path) => {
|
|
11
|
+
const {parentPath} = path;
|
|
12
|
+
|
|
13
|
+
if (!isArrayExpression(parentPath))
|
|
14
|
+
return false;
|
|
15
|
+
|
|
16
|
+
const [first, second] = parentPath.node.elements;
|
|
17
|
+
|
|
18
|
+
if (second !== path.node)
|
|
19
|
+
return false;
|
|
20
|
+
|
|
21
|
+
return isNullLiteral(first) || isNumericLiteral(first);
|
|
22
|
+
};
|
|
@@ -14,8 +14,12 @@ const {
|
|
|
14
14
|
|
|
15
15
|
const {parseComments} = require('../../comment/comment');
|
|
16
16
|
const {likeChain} = require('../member-expression/member-expressions');
|
|
17
|
+
const {isInsideTuple} = require('./is-inside-tuple');
|
|
17
18
|
|
|
18
|
-
const {
|
|
19
|
+
const {
|
|
20
|
+
isStringLiteral,
|
|
21
|
+
isArrayExpression,
|
|
22
|
+
} = types;
|
|
19
23
|
|
|
20
24
|
const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
|
|
21
25
|
const isLogical = (path) => path.get('argument').isLogicalExpression();
|
|
@@ -37,16 +41,19 @@ const isMemberExpressionCallee = ({parentPath}) => {
|
|
|
37
41
|
const isInsideCall = ({parentPath}) => parentPath.isCallExpression();
|
|
38
42
|
|
|
39
43
|
function isInsideNestedArrayCall({parentPath}) {
|
|
40
|
-
if (!
|
|
44
|
+
if (!isArrayExpression(parentPath))
|
|
41
45
|
return false;
|
|
42
46
|
|
|
43
|
-
if (!parentPath.parentPath
|
|
47
|
+
if (!isArrayExpression(parentPath.parentPath))
|
|
44
48
|
return false;
|
|
45
49
|
|
|
46
50
|
return isInsideCall(parentPath.parentPath);
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
function isInsideNestedTuple({parentPath}) {
|
|
54
|
+
if (!isArrayExpression(parentPath.parentPath))
|
|
55
|
+
return false;
|
|
56
|
+
|
|
50
57
|
const {elements} = parentPath.parentPath.node;
|
|
51
58
|
const [first] = elements;
|
|
52
59
|
|
|
@@ -61,7 +68,7 @@ module.exports.ObjectExpression = (path, printer, semantics) => {
|
|
|
61
68
|
indent,
|
|
62
69
|
} = printer;
|
|
63
70
|
|
|
64
|
-
const insideNestedArrayCall = isInsideNestedArrayCall(path);
|
|
71
|
+
const insideNestedArrayCall = isInsideTuple(path) || isInsideNestedArrayCall(path);
|
|
65
72
|
|
|
66
73
|
maybe.indent.inc(!insideNestedArrayCall);
|
|
67
74
|
|
|
@@ -11,8 +11,9 @@ const {
|
|
|
11
11
|
hasTrailingComment,
|
|
12
12
|
isCoupleLines,
|
|
13
13
|
isInsideLabel,
|
|
14
|
-
} = require('
|
|
14
|
+
} = require('../../is');
|
|
15
15
|
|
|
16
|
+
const not = (fn) => (...a) => !fn(...a);
|
|
16
17
|
const isBeforeElse = (path) => {
|
|
17
18
|
if (!path.parentPath.isIfStatement())
|
|
18
19
|
return false;
|
|
@@ -23,6 +24,9 @@ const isBeforeElse = (path) => {
|
|
|
23
24
|
return Boolean(path.parentPath.node.alternate);
|
|
24
25
|
};
|
|
25
26
|
|
|
27
|
+
const isInsideReturn = ({parentPath}) => parentPath.isReturnStatement();
|
|
28
|
+
const notInsideReturn = not(isInsideReturn);
|
|
29
|
+
|
|
26
30
|
const satisfyAfter = satisfy([
|
|
27
31
|
isNotLastOrParentLast,
|
|
28
32
|
isParentBlock,
|
|
@@ -37,16 +41,25 @@ const shouldBreakline = satisfy([
|
|
|
37
41
|
]);
|
|
38
42
|
|
|
39
43
|
module.exports.ExpressionStatement = {
|
|
44
|
+
beforeIf(path) {
|
|
45
|
+
if (isInsideReturn(path))
|
|
46
|
+
return false;
|
|
47
|
+
|
|
48
|
+
return !isInsideLabel(path);
|
|
49
|
+
},
|
|
50
|
+
before(path, {indent}) {
|
|
51
|
+
indent();
|
|
52
|
+
},
|
|
40
53
|
print(path, {print, maybe, store}) {
|
|
41
|
-
|
|
54
|
+
const insideReturn = isInsideReturn(path);
|
|
42
55
|
|
|
43
56
|
print('__expression');
|
|
44
|
-
print(';');
|
|
57
|
+
maybe.print(!insideReturn, ';');
|
|
45
58
|
|
|
46
59
|
if (!isNext(path))
|
|
47
60
|
return;
|
|
48
61
|
|
|
49
|
-
if (shouldBreakline(path)) {
|
|
62
|
+
if (!insideReturn && shouldBreakline(path)) {
|
|
50
63
|
print.newline();
|
|
51
64
|
maybe.indent(isNext(path) && noTrailingComment(path));
|
|
52
65
|
store(true);
|
|
@@ -71,8 +84,10 @@ module.exports.ExpressionStatement = {
|
|
|
71
84
|
if (isTopParentLast(path))
|
|
72
85
|
return;
|
|
73
86
|
|
|
74
|
-
|
|
75
|
-
|
|
87
|
+
if (notInsideReturn(path)) {
|
|
88
|
+
print.newline();
|
|
89
|
+
maybe.markAfter(store(), path);
|
|
90
|
+
}
|
|
76
91
|
},
|
|
77
92
|
};
|
|
78
93
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {ExpressionStatement} = require('./expression-statement');
|
|
3
|
+
const {ExpressionStatement} = require('./expression-statement/expression-statement');
|
|
4
4
|
const {VariableDeclaration} = require('./variable-declaration/variable-declaration');
|
|
5
5
|
const {IfStatement} = require('./if-statement/if-statement');
|
|
6
6
|
const {ForOfStatement} = require('./for-of-statement/for-of-statement');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.4.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",
|
|
@@ -50,6 +50,14 @@
|
|
|
50
50
|
"traverse",
|
|
51
51
|
"generate"
|
|
52
52
|
],
|
|
53
|
+
"imports": {
|
|
54
|
+
"#test/printer": {
|
|
55
|
+
"default": "./test/printer.js"
|
|
56
|
+
},
|
|
57
|
+
"#test/fixture": {
|
|
58
|
+
"default": "./test/fixture.js"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
53
61
|
"devDependencies": {
|
|
54
62
|
"@putout/eslint": "^3.5.0",
|
|
55
63
|
"@putout/plugin-minify": "^9.0.0",
|