@putout/printer 17.10.0 → 17.11.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 +15 -0
- package/lib/tokenize/comment/parse-leading-comments.js +1 -1
- package/lib/tokenize/expressions/assignment-expression/print-separator.js +5 -3
- package/lib/tokenize/expressions/class/class.js +1 -1
- package/lib/tokenize/expressions/function/function-declaration.js +1 -1
- package/lib/tokenize/expressions/function/kind.js +5 -2
- package/lib/tokenize/expressions/new-expression/new-expression.js +1 -1
- package/lib/tokenize/expressions/object-expression/object-property.js +5 -2
- package/lib/tokenize/printer/printer.js +1 -1
- package/lib/tokenize/statements/block-statement/block-statement.js +1 -1
- package/lib/tokenize/statements/export-declaration/export-declaration.js +1 -1
- package/lib/tokenize/statements/for-of-statement/for-of-statement.js +1 -1
- package/lib/tokenize/statements/for-statement.js +9 -7
- package/lib/tokenize/statements/if-statement/if-statement-comments.js +5 -2
- package/lib/tokenize/statements/if-statement/if-statement.js +1 -1
- package/lib/tokenize/statements/import-declaration/import-declaration.js +1 -1
- package/lib/tokenize/statements/return-statement/return-statement.js +1 -1
- package/lib/tokenize/statements/variable-declaration/variable-declaration.js +1 -1
- package/lib/tokenize/statements/while-statement/while-statement-comments.js +18 -0
- package/lib/tokenize/statements/while-statement/while-statement.js +14 -6
- package/lib/tokenize/statements/with-statement/with-statement.js +8 -6
- package/lib/tokenize/typescript/enum/ts-enum-declaration.js +1 -1
- package/lib/tokenize/typescript/interface/ts-interface-declaration.js +1 -1
- package/lib/tokenize/typescript/ts-union-type/ts-union-type.js +5 -3
- package/lib/tokenize/typescript/type/ts-type-alias-declaration.js +1 -1
- package/package.json +4 -3
package/ChangeLog
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
2026.03.03, v17.11.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 08981fd @putout/printer: WhileStatement: trailng comments: improve support
|
|
5
|
+
- abfacc7 @putout/printer: superc8 v12.2.4
|
|
6
|
+
- 0ff4fb3 @putout/printer: @putout/eslint v6.0.0
|
|
7
|
+
- aa35981 @putout/printer: #mark: add
|
|
8
|
+
- 52f16d2 @putout/printer: IfStatement: comments with next sibling
|
|
9
|
+
|
|
10
|
+
2026.03.03, v17.10.1
|
|
11
|
+
|
|
12
|
+
feature:
|
|
13
|
+
- 250f066 @putout/printer: #mark: add
|
|
14
|
+
- 6f44535 @putout/printer: IfStatement: comments with next sibling
|
|
15
|
+
|
|
1
16
|
2026.03.03, v17.10.0
|
|
2
17
|
|
|
3
18
|
feature:
|
|
@@ -6,10 +6,12 @@ const {
|
|
|
6
6
|
} = types;
|
|
7
7
|
|
|
8
8
|
export const printSeparator = (path, {print}) => {
|
|
9
|
-
if (isMultiline(path))
|
|
9
|
+
if (isMultiline(path)) {
|
|
10
10
|
print.breakline();
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
print.space();
|
|
13
15
|
};
|
|
14
16
|
|
|
15
17
|
function isMultiline(path) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
2
|
import {isNext} from '#is';
|
|
3
|
-
import {markAfter} from '
|
|
3
|
+
import {markAfter} from '#mark';
|
|
4
4
|
import {maybeDeclare} from '../../maybe/maybe-declare.js';
|
|
5
5
|
import {parseComments} from '../../comment/comment.js';
|
|
6
6
|
import {maybeDecorators} from '../../maybe/maybe-decorators.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
2
|
import {isNext, isNextParent} from '#is';
|
|
3
3
|
import {printParams} from '#print-params';
|
|
4
|
-
import {markAfter} from '
|
|
4
|
+
import {markAfter} from '#mark';
|
|
5
5
|
|
|
6
6
|
const not = (fn) => (...a) => !fn(...a);
|
|
7
7
|
const notInsideExportDefaultWithBody = not(isInsideExportDefaultWithBody);
|
|
@@ -24,8 +24,11 @@ export const ObjectProperty = (path, printer, semantics) => {
|
|
|
24
24
|
traverse(value);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
if (manyLines)
|
|
27
|
+
if (manyLines) {
|
|
28
28
|
maybe.write(!isLast || trailingComma, ',');
|
|
29
|
-
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!isLast && properties.length)
|
|
30
33
|
write(', ');
|
|
31
34
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {fullstore} from 'fullstore';
|
|
2
2
|
import {TYPES} from '#types';
|
|
3
|
+
import {maybeMarkAfter} from '#mark';
|
|
3
4
|
import {createDebug, createLog} from './debug.js';
|
|
4
|
-
import {maybeMarkAfter} from '../mark.js';
|
|
5
5
|
import * as baseVisitors from '../visitors.js';
|
|
6
6
|
import {maybeVisitor, maybeThrow} from '../maybe/index.js';
|
|
7
7
|
import {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
|
+
import {markAfter} from '#mark';
|
|
2
3
|
import {
|
|
3
4
|
isNext,
|
|
4
5
|
isParentProgram,
|
|
@@ -6,7 +7,6 @@ import {
|
|
|
6
7
|
exists,
|
|
7
8
|
satisfy,
|
|
8
9
|
} from '#is';
|
|
9
|
-
import {markAfter} from '../../mark.js';
|
|
10
10
|
import {parseComments} from '../../comment/comment.js';
|
|
11
11
|
import {insideIfWithNoBody} from './inside-if-with-no-body.js';
|
|
12
12
|
import {getDirectives} from './get-directives.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {isInsideLabel, exists} from '#is';
|
|
2
|
-
import {markAfter} from '
|
|
2
|
+
import {markAfter} from '#mark';
|
|
3
3
|
|
|
4
4
|
export const ForStatement = {
|
|
5
5
|
print(path, {print, maybe}) {
|
|
@@ -26,13 +26,15 @@ export const ForStatement = {
|
|
|
26
26
|
if (body.body) {
|
|
27
27
|
print.space();
|
|
28
28
|
print('__body');
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
maybe.print.newline(is);
|
|
32
|
-
maybe.indent.inc(is);
|
|
33
|
-
print('__body');
|
|
34
|
-
maybe.indent.dec(is);
|
|
29
|
+
|
|
30
|
+
return;
|
|
35
31
|
}
|
|
32
|
+
|
|
33
|
+
const is = !path.get('body').isEmptyStatement();
|
|
34
|
+
maybe.print.newline(is);
|
|
35
|
+
maybe.indent.inc(is);
|
|
36
|
+
print('__body');
|
|
37
|
+
maybe.indent.dec(is);
|
|
36
38
|
},
|
|
37
39
|
afterIf(path) {
|
|
38
40
|
return exists(path.getNextSibling());
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
|
+
import {isNext} from '#is';
|
|
2
3
|
|
|
3
4
|
const {isBlockStatement} = types;
|
|
4
5
|
|
|
5
6
|
export const printTrailingCommentBlock = (path, printer, semantics, {printComment}) => {
|
|
6
|
-
const {
|
|
7
|
-
|
|
7
|
+
const {maybe} = printer;
|
|
8
|
+
const hasNext = isNext(path);
|
|
9
|
+
|
|
10
|
+
maybe.print.breakline(!hasNext);
|
|
8
11
|
printComment();
|
|
9
12
|
};
|
|
10
13
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {parseImportSpecifiers} from 'parse-import-specifiers';
|
|
2
2
|
import {isLast, isNext} from '#is';
|
|
3
3
|
import {printAttributes} from '#import-attributes';
|
|
4
|
-
import {markAfter} from '
|
|
4
|
+
import {markAfter} from '#mark';
|
|
5
5
|
import {
|
|
6
6
|
printTrailingCommentBlock,
|
|
7
7
|
printTrailingCommentLine,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
|
+
import {hasPrevNewline} from '#mark';
|
|
2
3
|
import {
|
|
3
4
|
isInsideLabel,
|
|
4
5
|
isPrevBody,
|
|
@@ -6,7 +7,6 @@ import {
|
|
|
6
7
|
isLast,
|
|
7
8
|
isPrevTry,
|
|
8
9
|
} from '#is';
|
|
9
|
-
import {hasPrevNewline} from '../../mark.js';
|
|
10
10
|
import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
|
|
11
11
|
|
|
12
12
|
const {isJSXElement} = types;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
|
+
import {hasPrevNewline} from '#mark';
|
|
2
3
|
import {
|
|
3
4
|
isNext,
|
|
4
5
|
isCoupleLines,
|
|
@@ -6,7 +7,6 @@ import {
|
|
|
6
7
|
exists,
|
|
7
8
|
noTrailingComment,
|
|
8
9
|
} from '#is';
|
|
9
|
-
import {hasPrevNewline} from '../../mark.js';
|
|
10
10
|
import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
|
|
11
11
|
import {isConcatenation} from '../../expressions/binary-expression/concatenate.js';
|
|
12
12
|
import {parseLeadingComments} from '../../comment/comment.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {isNext} from '#is';
|
|
2
|
+
|
|
3
|
+
export const printTrailingCommentBlock = (path, printer, semantics, {printComment}) => {
|
|
4
|
+
const {maybe} = printer;
|
|
5
|
+
const hasNext = isNext(path);
|
|
6
|
+
|
|
7
|
+
maybe.print.breakline(!hasNext);
|
|
8
|
+
printComment();
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const printTrailingCommentLine = (path, printer, semantics, {printComment}) => {
|
|
12
|
+
const {print} = printer;
|
|
13
|
+
|
|
14
|
+
print.indent();
|
|
15
|
+
|
|
16
|
+
printComment();
|
|
17
|
+
print.newline();
|
|
18
|
+
};
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import {isNext} from '#is';
|
|
2
|
-
import {markAfter} from '
|
|
2
|
+
import {markAfter} from '#mark';
|
|
3
|
+
import {
|
|
4
|
+
printTrailingCommentBlock,
|
|
5
|
+
printTrailingCommentLine,
|
|
6
|
+
} from './while-statement-comments.js';
|
|
3
7
|
|
|
4
8
|
export const WhileStatement = {
|
|
9
|
+
printTrailingCommentBlock,
|
|
10
|
+
printTrailingCommentLine,
|
|
5
11
|
print(path, {print, indent}) {
|
|
6
12
|
indent();
|
|
7
13
|
print('while');
|
|
@@ -13,12 +19,14 @@ export const WhileStatement = {
|
|
|
13
19
|
if (path.node.body.body) {
|
|
14
20
|
print.space();
|
|
15
21
|
print('__body');
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
print.newline();
|
|
19
|
-
print('__body');
|
|
20
|
-
indent.dec();
|
|
22
|
+
|
|
23
|
+
return;
|
|
21
24
|
}
|
|
25
|
+
|
|
26
|
+
indent.inc();
|
|
27
|
+
print.newline();
|
|
28
|
+
print('__body');
|
|
29
|
+
indent.dec();
|
|
22
30
|
},
|
|
23
31
|
afterIf(path) {
|
|
24
32
|
return isNext(path);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {isNext} from '#is';
|
|
2
|
-
import {markAfter} from '
|
|
2
|
+
import {markAfter} from '#mark';
|
|
3
3
|
|
|
4
4
|
export const WithStatement = {
|
|
5
5
|
print(path, {print, indent}) {
|
|
@@ -13,12 +13,14 @@ export const WithStatement = {
|
|
|
13
13
|
if (path.node.body.body) {
|
|
14
14
|
print.space();
|
|
15
15
|
print('__body');
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
print.newline();
|
|
19
|
-
print('__body');
|
|
20
|
-
indent.dec();
|
|
16
|
+
|
|
17
|
+
return;
|
|
21
18
|
}
|
|
19
|
+
|
|
20
|
+
indent.inc();
|
|
21
|
+
print.newline();
|
|
22
|
+
print('__body');
|
|
23
|
+
indent.dec();
|
|
22
24
|
},
|
|
23
25
|
afterIf(path) {
|
|
24
26
|
return isNext(path);
|
|
@@ -10,10 +10,12 @@ export const TSUnionType = maybeParens({
|
|
|
10
10
|
const types = path.get('types');
|
|
11
11
|
const {length} = types;
|
|
12
12
|
|
|
13
|
-
if (!insideTypeDeclaration(path) || length <= maxTypesInOneLine)
|
|
13
|
+
if (!insideTypeDeclaration(path) || length <= maxTypesInOneLine) {
|
|
14
14
|
printInOneLine(types, printer);
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
printInCoupleLines(types, printer);
|
|
17
19
|
},
|
|
18
20
|
});
|
|
19
21
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "17.
|
|
3
|
+
"version": "17.11.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Simplest possible opinionated Babel AST printer for 🐊Putout",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"#printer": "./lib/printer.js",
|
|
58
58
|
"#test": "./test/create-test.js",
|
|
59
59
|
"#is": "./lib/tokenize/is.js",
|
|
60
|
+
"#mark": "./lib/tokenize/mark.js",
|
|
60
61
|
"#maybe-parens": "./lib/tokenize/maybe/maybe-parens.js",
|
|
61
62
|
"#print-params": "./lib/tokenize/expressions/function/params.js",
|
|
62
63
|
"#import-attributes": "./lib/tokenize/statements/import-declaration/import-attribute.js",
|
|
@@ -64,7 +65,7 @@
|
|
|
64
65
|
},
|
|
65
66
|
"devDependencies": {
|
|
66
67
|
"@babel/parser": "^7.28.5",
|
|
67
|
-
"@putout/eslint": "^
|
|
68
|
+
"@putout/eslint": "^6.0.0",
|
|
68
69
|
"@putout/eslint-flat": "^4.0.0",
|
|
69
70
|
"@putout/plugin-minify": "^11.2.1",
|
|
70
71
|
"@putout/plugin-printer": "^7.0.0",
|
|
@@ -72,7 +73,6 @@
|
|
|
72
73
|
"@putout/plugin-react-hook-form": "^6.0.0",
|
|
73
74
|
"@putout/plugin-react-hooks": "^9.0.0",
|
|
74
75
|
"acorn": "^8.8.2",
|
|
75
|
-
"c8": "^10.1.2",
|
|
76
76
|
"check-dts": "^0.9.0",
|
|
77
77
|
"escover": "^6.0.0",
|
|
78
78
|
"eslint": "^10.0.0",
|
|
@@ -86,6 +86,7 @@
|
|
|
86
86
|
"putout": "^42.0.1",
|
|
87
87
|
"redlint": "^6.0.0",
|
|
88
88
|
"samadhi": "^4.0.2",
|
|
89
|
+
"superc8": "^12.2.4",
|
|
89
90
|
"supertape": "^12.0.9",
|
|
90
91
|
"try-catch": "^4.0.6",
|
|
91
92
|
"typescript": "^5.3.3"
|