@putout/printer 1.8.2 → 1.8.4
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/lib/print-tokens/cook.js +1 -18
- package/lib/tokenize/expressions/call-expression.js +4 -0
- package/lib/tokenize/expressions/object-expression.js +3 -1
- package/lib/tokenize/statements/for-in-statement.js +15 -0
- package/lib/tokenize/statements/index.js +2 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2023.03.27, v1.8.4
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- c117645 @putout/printer: add support of ForInStatement
|
|
5
|
+
|
|
6
|
+
2023.03.26, v1.8.3
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- fec7aee @putout/printer: improve support of ObjectExpression inside LogicalExpression inside SpreadElement property of ObjectExpression
|
|
10
|
+
|
|
1
11
|
2023.03.26, v1.8.2
|
|
2
12
|
|
|
3
13
|
feature:
|
package/lib/print-tokens/cook.js
CHANGED
|
@@ -3,24 +3,7 @@
|
|
|
3
3
|
module.exports.cook = (tokens) => {
|
|
4
4
|
const cookedTokens = [];
|
|
5
5
|
|
|
6
|
-
for (const [i, {
|
|
7
|
-
value,
|
|
8
|
-
}] of tokens.entries()) {
|
|
9
|
-
/*
|
|
10
|
-
if (type !== TYPES.TOKEN)
|
|
11
|
-
console.log(type);
|
|
12
|
-
|
|
13
|
-
if (type === TYPES.NEWLINE && next?.type === TYPES.LINEBREAK) {
|
|
14
|
-
console.log('[skipped]');
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (type === TYPES.LINEBREAK && next?.type === TYPES.LINEBREAK) {
|
|
19
|
-
console.log('[skipped]');
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
*/
|
|
23
|
-
|
|
6
|
+
for (const [i, {value}] of tokens.entries()) {
|
|
24
7
|
cookedTokens.push(value);
|
|
25
8
|
}
|
|
26
9
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const {isCoupleLines} = require('../is');
|
|
4
4
|
const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
|
|
5
|
+
const isLogical = (path) => path.get('argument').isLogicalExpression();
|
|
5
6
|
const isForOf = (path) => {
|
|
6
7
|
if (path.parentPath.isForOfStatement())
|
|
7
8
|
return true;
|
|
@@ -24,7 +25,7 @@ module.exports.ObjectExpression = (path, {print, maybe, indent}) => {
|
|
|
24
25
|
|
|
25
26
|
for (const property of properties) {
|
|
26
27
|
if (property.isSpreadElement()) {
|
|
27
|
-
maybe.indent(length > 1);
|
|
28
|
+
maybe.indent(length > 1 || isLogical(property));
|
|
28
29
|
print(property);
|
|
29
30
|
|
|
30
31
|
if (length > 1) {
|
|
@@ -60,6 +61,7 @@ module.exports.ObjectExpression = (path, {print, maybe, indent}) => {
|
|
|
60
61
|
|
|
61
62
|
maybe.indent(manyLines);
|
|
62
63
|
print('}');
|
|
64
|
+
maybe.print.newline(path.parentPath.isLogicalExpression());
|
|
63
65
|
maybe.print(parens, ')');
|
|
64
66
|
};
|
|
65
67
|
function isOneLine(path) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.ForInStatement = (path, {print}) => {
|
|
4
|
+
print('for ');
|
|
5
|
+
print('(');
|
|
6
|
+
print('__left');
|
|
7
|
+
print(' in ');
|
|
8
|
+
print('__right');
|
|
9
|
+
print(')');
|
|
10
|
+
|
|
11
|
+
if (path.get('body').isBlockStatement())
|
|
12
|
+
print.space();
|
|
13
|
+
|
|
14
|
+
print('__body');
|
|
15
|
+
};
|
|
@@ -13,6 +13,7 @@ const importDeclarations = require('./import-declarations');
|
|
|
13
13
|
const exportDeclarations = require('./export-declarations');
|
|
14
14
|
const {WhileStatement} = require('./while-statement');
|
|
15
15
|
const {SwitchStatement} = require('./switch-statement');
|
|
16
|
+
const {ForInStatement} = require('./for-in-statement');
|
|
16
17
|
|
|
17
18
|
module.exports = {
|
|
18
19
|
...importDeclarations,
|
|
@@ -22,6 +23,7 @@ module.exports = {
|
|
|
22
23
|
VariableDeclaration,
|
|
23
24
|
IfStatement,
|
|
24
25
|
ForStatement,
|
|
26
|
+
ForInStatement,
|
|
25
27
|
ForOfStatement,
|
|
26
28
|
ReturnStatement,
|
|
27
29
|
DebuggerStatement,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.4",
|
|
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",
|