@putout/printer 9.0.2 → 9.1.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/README.md +1 -0
- package/lib/tokenize/expressions/assignment-expression/assignment-expression.js +16 -30
- package/lib/tokenize/expressions/assignment-expression/maybe-write-brace.js +40 -0
- package/lib/tokenize/expressions/sequence-expression/maybe-write-brace.js +35 -0
- package/lib/tokenize/expressions/sequence-expression/sequence-expression.js +7 -26
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2024.06.09, v9.1.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 82ddbc3 @putout/printer: semantics: roundBraces: add support of AssignmentExpression (@putoutjs/minify#15)
|
|
5
|
+
|
|
6
|
+
2024.06.07, v9.0.3
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- a254ee6 @putout/printer: SequenceExpression maybe-write-brace
|
|
10
|
+
|
|
1
11
|
2024.06.07, v9.0.2
|
|
2
12
|
|
|
3
13
|
feature:
|
package/README.md
CHANGED
|
@@ -177,6 +177,7 @@ Options used to configure logic of output, similar to ESLint rules:
|
|
|
177
177
|
- ✅ `roundBraces` to output braces or not
|
|
178
178
|
- In a single argument arrow function expressions `(a) => {}` or not `a => {}`;
|
|
179
179
|
- In sequence expressions: `for(let e of l) (a(), b())` or not `for(let e of l) a(), b()`;
|
|
180
|
+
- In assignment expressions: `(e.o=w(e.o)` or not `e.o=w(e.o)`;
|
|
180
181
|
|
|
181
182
|
## Visitors API
|
|
182
183
|
|
|
@@ -1,38 +1,24 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {isObjectPattern} = require('@putout/babel').types;
|
|
4
|
-
const {isParens} = require('../unary-expression/parens');
|
|
5
3
|
const {isCoupleLines} = require('../../is');
|
|
6
4
|
const {isMarkedAfter} = require('../../mark');
|
|
5
|
+
const {
|
|
6
|
+
maybePrintLeftBrace,
|
|
7
|
+
maybePrintRightBrace,
|
|
8
|
+
} = require('./maybe-write-brace');
|
|
7
9
|
|
|
8
|
-
module.exports.AssignmentExpression = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
before(path, {write}) {
|
|
21
|
-
write('(');
|
|
22
|
-
},
|
|
23
|
-
print(path, {print, maybe}) {
|
|
24
|
-
const {operator} = path.node;
|
|
25
|
-
maybe.print.breakline(isPrevCoupleLines(path));
|
|
26
|
-
|
|
27
|
-
print('__left');
|
|
28
|
-
print.space();
|
|
29
|
-
print(operator);
|
|
30
|
-
print.space();
|
|
31
|
-
print('__right');
|
|
32
|
-
},
|
|
33
|
-
after(path, {write}) {
|
|
34
|
-
write(')');
|
|
35
|
-
},
|
|
10
|
+
module.exports.AssignmentExpression = (path, printer, semantics) => {
|
|
11
|
+
const {print, maybe} = printer;
|
|
12
|
+
const {operator} = path.node;
|
|
13
|
+
|
|
14
|
+
maybe.print.breakline(isPrevCoupleLines(path));
|
|
15
|
+
maybePrintLeftBrace(path, printer, semantics);
|
|
16
|
+
print('__left');
|
|
17
|
+
print.space();
|
|
18
|
+
print(operator);
|
|
19
|
+
print.space();
|
|
20
|
+
print('__right');
|
|
21
|
+
maybePrintRightBrace(path, printer, semantics);
|
|
36
22
|
};
|
|
37
23
|
|
|
38
24
|
const isPrevCoupleLines = ({parentPath}) => {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {isParens} = require('../unary-expression/parens');
|
|
4
|
+
|
|
5
|
+
module.exports.maybePrintLeftBrace = (path, printer, semantics) => {
|
|
6
|
+
maybeWriteBrace(path, printer, semantics, {
|
|
7
|
+
brace: '(',
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
module.exports.maybePrintRightBrace = (path, printer, semantics) => {
|
|
12
|
+
maybeWriteBrace(path, printer, semantics, {
|
|
13
|
+
brace: ')',
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function maybeWriteBrace(path, printer, semantics, {brace}) {
|
|
18
|
+
const {parentPath} = path;
|
|
19
|
+
const {type} = parentPath;
|
|
20
|
+
const {roundBraces} = semantics;
|
|
21
|
+
const {write} = printer;
|
|
22
|
+
|
|
23
|
+
if (path.node.left.type === 'ObjectPattern') {
|
|
24
|
+
write(brace);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (type === 'LogicalExpression') {
|
|
29
|
+
write(brace);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!roundBraces)
|
|
34
|
+
return;
|
|
35
|
+
|
|
36
|
+
if (!isParens(path))
|
|
37
|
+
return;
|
|
38
|
+
|
|
39
|
+
write(brace);
|
|
40
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.maybeWriteLeftBrace = (path, printer, semantics) => {
|
|
4
|
+
maybeWriteBrace(path, printer, semantics, {
|
|
5
|
+
brace: '(',
|
|
6
|
+
});
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
module.exports.maybeWriteRightBrace = (path, printer, semantics) => {
|
|
10
|
+
maybeWriteBrace(path, printer, semantics, {
|
|
11
|
+
brace: ')',
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function maybeWriteBrace(path, printer, semantics, {brace}) {
|
|
16
|
+
const {parentPath} = path;
|
|
17
|
+
const {type} = parentPath;
|
|
18
|
+
const {roundBraces} = semantics;
|
|
19
|
+
const {write} = printer;
|
|
20
|
+
|
|
21
|
+
if (type === 'ArrowFunctionExpression') {
|
|
22
|
+
write(brace);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (type === 'LogicalExpression') {
|
|
27
|
+
write(brace);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!roundBraces)
|
|
32
|
+
return;
|
|
33
|
+
|
|
34
|
+
write(brace);
|
|
35
|
+
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {
|
|
4
|
+
maybeWriteLeftBrace,
|
|
5
|
+
maybeWriteRightBrace,
|
|
6
|
+
} = require('./maybe-write-brace');
|
|
7
|
+
|
|
3
8
|
module.exports.SequenceExpression = (path, printer, semantics) => {
|
|
4
9
|
const {maybe, traverse} = printer;
|
|
5
10
|
|
|
6
11
|
const expressions = path.get('expressions');
|
|
7
12
|
const n = expressions.length - 1;
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
brace: '(',
|
|
11
|
-
});
|
|
14
|
+
maybeWriteLeftBrace(path, printer, semantics);
|
|
12
15
|
|
|
13
16
|
for (const [index, expression] of expressions.entries()) {
|
|
14
17
|
traverse(expression);
|
|
@@ -16,27 +19,5 @@ module.exports.SequenceExpression = (path, printer, semantics) => {
|
|
|
16
19
|
maybe.write.space(index < n);
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
brace: ')',
|
|
21
|
-
});
|
|
22
|
+
maybeWriteRightBrace(path, printer, semantics);
|
|
22
23
|
};
|
|
23
|
-
|
|
24
|
-
function maybeWriteBrace(path, printer, semantics, {brace}) {
|
|
25
|
-
const {roundBraces} = semantics;
|
|
26
|
-
const {write} = printer;
|
|
27
|
-
|
|
28
|
-
if (path.parentPath.isArrowFunctionExpression()) {
|
|
29
|
-
write(brace);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (path.parentPath.isLogicalExpression()) {
|
|
34
|
-
write(brace);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (!roundBraces)
|
|
39
|
-
return;
|
|
40
|
-
|
|
41
|
-
write(brace);
|
|
42
|
-
}
|
package/package.json
CHANGED