@putout/printer 13.0.1 → 13.2.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 +12 -0
- package/lib/tokenize/expressions/array-expression/array-expression.js +1 -1
- package/lib/tokenize/expressions/assignment-expression/assignment-expression.js +8 -0
- package/lib/tokenize/expressions/object-expression/is-third-object-inside-array.js +21 -0
- package/lib/tokenize/expressions/object-expression/object-expression.js +6 -1
- package/lib/tokenize/maybe/index.js +6 -6
- package/lib/tokenize/tokenize.js +35 -29
- package/package.json +6 -3
package/ChangeLog
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
2025.03.08, v13.2.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 6a5607b @putout/printer: @putout/plugin-react-hooks v7.0.0
|
|
5
|
+
- b9c5048 @putout/printer: @putout/plugin-minify v10.0.0
|
|
6
|
+
- 87aed30 @putout/printer: third object in ArrayExpression
|
|
7
|
+
|
|
8
|
+
2025.02.25, v13.1.0
|
|
9
|
+
|
|
10
|
+
feature:
|
|
11
|
+
- 4387ef7 @putout/printer: AssignmentExpression: add semicolon even when not inside ExpressionStatement but when inside BlockStatement or Program
|
|
12
|
+
|
|
1
13
|
2025.02.22, v13.0.1
|
|
2
14
|
|
|
3
15
|
feature:
|
|
@@ -11,6 +11,8 @@ const {
|
|
|
11
11
|
isAssignmentExpression,
|
|
12
12
|
} = types;
|
|
13
13
|
|
|
14
|
+
const isInsideBlock = ({parentPath}) => /BlockStatement|Program/.test(parentPath.type);
|
|
15
|
+
|
|
14
16
|
module.exports.AssignmentExpression = (path, printer, semantics) => {
|
|
15
17
|
const {print} = printer;
|
|
16
18
|
const {operator} = path.node;
|
|
@@ -26,6 +28,12 @@ module.exports.AssignmentExpression = (path, printer, semantics) => {
|
|
|
26
28
|
print.space();
|
|
27
29
|
|
|
28
30
|
print('__right');
|
|
31
|
+
|
|
32
|
+
if (isInsideBlock(path)) {
|
|
33
|
+
print(';');
|
|
34
|
+
print.breakline();
|
|
35
|
+
}
|
|
36
|
+
|
|
29
37
|
maybePrintRightBrace(path, printer, semantics);
|
|
30
38
|
};
|
|
31
39
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types} = require('@putout/babel');
|
|
4
|
+
const {
|
|
5
|
+
isArrayExpression,
|
|
6
|
+
isCallExpression,
|
|
7
|
+
} = types;
|
|
8
|
+
|
|
9
|
+
module.exports.isThirdObjectInsideArray = (path) => {
|
|
10
|
+
const {parentPath} = path;
|
|
11
|
+
|
|
12
|
+
if (!isArrayExpression(parentPath))
|
|
13
|
+
return false;
|
|
14
|
+
|
|
15
|
+
const [, second, third] = parentPath.node.elements;
|
|
16
|
+
|
|
17
|
+
if (!isCallExpression(second))
|
|
18
|
+
return false;
|
|
19
|
+
|
|
20
|
+
return third === path.node;
|
|
21
|
+
};
|
|
@@ -15,6 +15,7 @@ const {
|
|
|
15
15
|
const {parseComments} = require('../../comment/comment');
|
|
16
16
|
const {isInsideTuple} = require('./is-inside-tuple');
|
|
17
17
|
const {isLooksLikeChain} = require('../member-expression/is-looks-like-chain');
|
|
18
|
+
const {isThirdObjectInsideArray} = require('./is-third-object-inside-array');
|
|
18
19
|
|
|
19
20
|
const {
|
|
20
21
|
isStringLiteral,
|
|
@@ -52,6 +53,10 @@ function isInsideNestedArrayCall({parentPath}) {
|
|
|
52
53
|
|
|
53
54
|
function isInsideNestedTuple({parentPath}) {
|
|
54
55
|
const {elements} = parentPath.parentPath.node;
|
|
56
|
+
|
|
57
|
+
if (!elements)
|
|
58
|
+
return false;
|
|
59
|
+
|
|
55
60
|
const [first] = elements;
|
|
56
61
|
|
|
57
62
|
return isStringLiteral(first);
|
|
@@ -65,7 +70,7 @@ module.exports.ObjectExpression = (path, printer, semantics) => {
|
|
|
65
70
|
indent,
|
|
66
71
|
} = printer;
|
|
67
72
|
|
|
68
|
-
const insideNestedArrayCall = isInsideTuple(path) || isInsideNestedArrayCall(path);
|
|
73
|
+
const insideNestedArrayCall = isInsideTuple(path) || isInsideNestedArrayCall(path) || isThirdObjectInsideArray(path);
|
|
69
74
|
|
|
70
75
|
maybe.indent.inc(!insideNestedArrayCall);
|
|
71
76
|
|
|
@@ -41,7 +41,7 @@ module.exports.maybeVisitor = (plugin, path, printer, options) => {
|
|
|
41
41
|
return objectPlugin(plugin, path, printer, options);
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
function objectPlugin(plugin, path, printer,
|
|
44
|
+
function objectPlugin(plugin, path, printer, semantics) {
|
|
45
45
|
const {
|
|
46
46
|
print,
|
|
47
47
|
split,
|
|
@@ -52,11 +52,11 @@ function objectPlugin(plugin, path, printer, options) {
|
|
|
52
52
|
afterIf = condition,
|
|
53
53
|
} = maybeSatisfy(plugin);
|
|
54
54
|
|
|
55
|
-
if (beforeIf?.(path, printer))
|
|
56
|
-
before(path, printer);
|
|
55
|
+
if (beforeIf?.(path, printer, semantics))
|
|
56
|
+
before(path, printer, semantics);
|
|
57
57
|
|
|
58
|
-
print(path, printer,
|
|
58
|
+
print(path, printer, semantics);
|
|
59
59
|
|
|
60
|
-
if (afterIf?.(path, printer))
|
|
61
|
-
after(path, printer);
|
|
60
|
+
if (afterIf?.(path, printer, semantics))
|
|
61
|
+
after(path, printer, semantics);
|
|
62
62
|
}
|
package/lib/tokenize/tokenize.js
CHANGED
|
@@ -56,18 +56,6 @@ module.exports.tokenize = (ast, overrides) => {
|
|
|
56
56
|
});
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
const maybeIndent = (a) => a && indent();
|
|
60
|
-
const maybeIndentInc = (a) => a && indent.inc();
|
|
61
|
-
const maybeIndentDec = (a) => a && indent.dec();
|
|
62
|
-
const maybeNewline = (a) => a && newline();
|
|
63
|
-
const maybeBreakline = (a) => a && breakline();
|
|
64
|
-
const maybeLinebreak = (a) => a && linebreak();
|
|
65
|
-
const maybeWrite = (a, b) => a && write(b);
|
|
66
|
-
const maybeSpace = (a) => a && space();
|
|
67
|
-
let i = 0;
|
|
68
|
-
const incIndent = () => ++i;
|
|
69
|
-
const decIndent = () => --i;
|
|
70
|
-
|
|
71
59
|
const indent = () => {
|
|
72
60
|
addToken({
|
|
73
61
|
type: TYPES.INDENT,
|
|
@@ -75,23 +63,36 @@ module.exports.tokenize = (ast, overrides) => {
|
|
|
75
63
|
});
|
|
76
64
|
};
|
|
77
65
|
|
|
78
|
-
|
|
79
|
-
inc: incIndent,
|
|
80
|
-
dec: decIndent,
|
|
81
|
-
});
|
|
66
|
+
const maybeIndent = (a) => a && indent();
|
|
82
67
|
|
|
83
|
-
const
|
|
68
|
+
const maybeIndentInc = (a) => a && indent.inc();
|
|
69
|
+
|
|
70
|
+
const maybeIndentDec = (a) => a && indent.dec();
|
|
71
|
+
|
|
72
|
+
const newline = () => {
|
|
84
73
|
addToken({
|
|
85
|
-
type: TYPES.
|
|
86
|
-
value: format.
|
|
74
|
+
type: TYPES.NEWLINE,
|
|
75
|
+
value: format.newline,
|
|
87
76
|
});
|
|
88
77
|
};
|
|
89
78
|
|
|
79
|
+
const maybeNewline = (a) => a && newline();
|
|
80
|
+
|
|
81
|
+
const breakline = () => {
|
|
82
|
+
newline();
|
|
83
|
+
indent();
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const maybeBreakline = (a) => a && breakline();
|
|
87
|
+
|
|
90
88
|
const linebreak = () => {
|
|
91
89
|
indent();
|
|
92
90
|
newline();
|
|
93
91
|
};
|
|
94
92
|
|
|
93
|
+
const maybeLinebreak = (a) => a && linebreak();
|
|
94
|
+
const maybeWrite = (a, b) => a && write(b);
|
|
95
|
+
|
|
95
96
|
const space = () => {
|
|
96
97
|
addToken({
|
|
97
98
|
type: TYPES.SPACE,
|
|
@@ -99,22 +100,27 @@ module.exports.tokenize = (ast, overrides) => {
|
|
|
99
100
|
});
|
|
100
101
|
};
|
|
101
102
|
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
const maybeSpace = (a) => a && space();
|
|
104
|
+
let i = 0;
|
|
105
|
+
const incIndent = () => ++i;
|
|
106
|
+
const decIndent = () => --i;
|
|
106
107
|
|
|
107
|
-
|
|
108
|
+
assign(indent, {
|
|
109
|
+
inc: incIndent,
|
|
110
|
+
dec: decIndent,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const splitter = () => {
|
|
108
114
|
addToken({
|
|
109
|
-
type: TYPES.
|
|
110
|
-
value: format.
|
|
115
|
+
type: TYPES.SPLITTER,
|
|
116
|
+
value: format.splitter,
|
|
111
117
|
});
|
|
112
118
|
};
|
|
113
119
|
|
|
114
|
-
const
|
|
120
|
+
const quote = () => {
|
|
115
121
|
addToken({
|
|
116
|
-
type: TYPES.
|
|
117
|
-
value: format.
|
|
122
|
+
type: TYPES.QUOTE,
|
|
123
|
+
value: format.quote,
|
|
118
124
|
});
|
|
119
125
|
};
|
|
120
126
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "13.0
|
|
3
|
+
"version": "13.2.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",
|
|
@@ -62,16 +62,19 @@
|
|
|
62
62
|
},
|
|
63
63
|
"#test": {
|
|
64
64
|
"default": "./test/create-test.js"
|
|
65
|
+
},
|
|
66
|
+
"#is": {
|
|
67
|
+
"default": "./lib/tokenize/is.js"
|
|
65
68
|
}
|
|
66
69
|
},
|
|
67
70
|
"devDependencies": {
|
|
68
71
|
"@putout/eslint": "^4.1.0",
|
|
69
72
|
"@putout/eslint-flat": "^2.0.0",
|
|
70
|
-
"@putout/plugin-minify": "^
|
|
73
|
+
"@putout/plugin-minify": "^10.0.0",
|
|
71
74
|
"@putout/plugin-printer": "^4.0.0",
|
|
72
75
|
"@putout/plugin-promises": "^16.0.0",
|
|
73
76
|
"@putout/plugin-react-hook-form": "^5.0.0",
|
|
74
|
-
"@putout/plugin-react-hooks": "^
|
|
77
|
+
"@putout/plugin-react-hooks": "^7.0.0",
|
|
75
78
|
"acorn": "^8.8.2",
|
|
76
79
|
"c8": "^10.1.2",
|
|
77
80
|
"check-dts": "^0.8.0",
|