@putout/printer 17.1.0 → 17.3.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/array-expression/indent.js +18 -0
- package/lib/tokenize/literals/string-literal.js +4 -4
- package/lib/tokenize/statements/export-declaration/export-declaration.js +11 -1
- package/lib/tokenize/statements/import-declaration/import-attribute.js +3 -2
- package/lib/tokenize/statements/import-declaration/import-declaration.js +2 -2
- package/package.json +4 -3
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2026.02.11, v17.3.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 26a5a19 @putout/printer: ExportDeclaration: import attributes
|
|
5
|
+
|
|
6
|
+
2026.02.11, v17.2.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 7cb116c @putout/printer: ArrayExpression: ObjectExpression, after StringLiteral/TemplateLiteral: indent
|
|
10
|
+
- 7a5f660 @putout/printer: eslint v10.0.0
|
|
11
|
+
|
|
1
12
|
2026.02.01, v17.1.0
|
|
2
13
|
|
|
3
14
|
feature:
|
|
@@ -4,10 +4,25 @@ import {isIndented} from '#is';
|
|
|
4
4
|
const {
|
|
5
5
|
isStringLiteral,
|
|
6
6
|
isArrayExpression,
|
|
7
|
+
isObjectExpression,
|
|
8
|
+
isTemplateLiteral,
|
|
7
9
|
} = types;
|
|
8
10
|
|
|
9
11
|
export const isInsideArray = (path) => path.parentPath.isArrayExpression();
|
|
10
12
|
|
|
13
|
+
const isObjectAfterString = ([first, second]) => {
|
|
14
|
+
if (!first || !second)
|
|
15
|
+
return false;
|
|
16
|
+
|
|
17
|
+
if (!isObjectExpression(second))
|
|
18
|
+
return false;
|
|
19
|
+
|
|
20
|
+
if (isStringLiteral(first))
|
|
21
|
+
return true;
|
|
22
|
+
|
|
23
|
+
return isTemplateLiteral(first);
|
|
24
|
+
};
|
|
25
|
+
|
|
11
26
|
export const isArrayIndented = (path) => {
|
|
12
27
|
const elements = path.get('elements');
|
|
13
28
|
|
|
@@ -16,6 +31,9 @@ export const isArrayIndented = (path) => {
|
|
|
16
31
|
|
|
17
32
|
const [first] = elements;
|
|
18
33
|
|
|
34
|
+
if (isObjectAfterString(elements))
|
|
35
|
+
return false;
|
|
36
|
+
|
|
19
37
|
return !isTwoLongStrings(elements) || !isInsideArray(path) && isIndented(first);
|
|
20
38
|
};
|
|
21
39
|
|
|
@@ -32,18 +32,18 @@ const maybeEscape = (value, {escapeDoubleQuote, escapeSingleQuote}) => {
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
const escape = (list, {slash, quote}) => {
|
|
35
|
-
const
|
|
35
|
+
const result = [];
|
|
36
36
|
|
|
37
37
|
for (const [index, char] of list.entries()) {
|
|
38
38
|
const prev = list[index - 1];
|
|
39
39
|
|
|
40
40
|
if (char === quote && prev !== slash) {
|
|
41
|
-
|
|
41
|
+
result.push(`${slash}${char}`);
|
|
42
42
|
continue;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
result.push(char);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
return
|
|
48
|
+
return result.join('');
|
|
49
49
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
|
+
import {printAttributes} from '#import-attributes';
|
|
2
3
|
import {
|
|
3
4
|
isParentBlock,
|
|
4
5
|
isNewlineBetweenSiblings,
|
|
@@ -60,7 +61,14 @@ export const ExportNamedDeclaration = {
|
|
|
60
61
|
before(path, {print}) {
|
|
61
62
|
print.linebreak();
|
|
62
63
|
},
|
|
63
|
-
print(path,
|
|
64
|
+
print(path, printer, semantics) {
|
|
65
|
+
const {
|
|
66
|
+
print,
|
|
67
|
+
traverse,
|
|
68
|
+
indent,
|
|
69
|
+
maybe,
|
|
70
|
+
} = printer;
|
|
71
|
+
|
|
64
72
|
const {trailingComma} = semantics;
|
|
65
73
|
const {exportKind} = path.node;
|
|
66
74
|
const specifiers = path.get('specifiers');
|
|
@@ -78,6 +86,7 @@ export const ExportNamedDeclaration = {
|
|
|
78
86
|
print(specifiers[0]);
|
|
79
87
|
print(' from ');
|
|
80
88
|
print('__source');
|
|
89
|
+
printAttributes(path, printer);
|
|
81
90
|
print(';');
|
|
82
91
|
maybe.print.newline(!isLast(path));
|
|
83
92
|
|
|
@@ -138,6 +147,7 @@ export const ExportNamedDeclaration = {
|
|
|
138
147
|
if (exists(source)) {
|
|
139
148
|
print(' from ');
|
|
140
149
|
traverse(source);
|
|
150
|
+
printAttributes(path, printer);
|
|
141
151
|
}
|
|
142
152
|
|
|
143
153
|
print(';');
|
|
@@ -6,13 +6,14 @@ export const ImportAttribute = (path, {print}) => {
|
|
|
6
6
|
print(',');
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
export const printAttributes = (path,
|
|
9
|
+
export const printAttributes = (path, {write, traverse, indent}) => {
|
|
10
10
|
const attributes = path.get('attributes');
|
|
11
11
|
|
|
12
12
|
if (!attributes.length)
|
|
13
13
|
return;
|
|
14
14
|
|
|
15
|
-
write(
|
|
15
|
+
write.space();
|
|
16
|
+
write('with');
|
|
16
17
|
write.space();
|
|
17
18
|
|
|
18
19
|
write('{');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {parseImportSpecifiers} from 'parse-import-specifiers';
|
|
2
2
|
import {isLast, isNext} from '#is';
|
|
3
|
+
import {printAttributes} from '#import-attributes';
|
|
3
4
|
import {markAfter} from '../../mark.js';
|
|
4
|
-
import {printAttributes} from './import-attribute.js';
|
|
5
5
|
import {
|
|
6
6
|
printTrailingCommentBlock,
|
|
7
7
|
printTrailingCommentLine,
|
|
@@ -95,7 +95,7 @@ export const ImportDeclaration = {
|
|
|
95
95
|
print.space();
|
|
96
96
|
|
|
97
97
|
print('__source');
|
|
98
|
-
printAttributes(path,
|
|
98
|
+
printAttributes(path, printer);
|
|
99
99
|
|
|
100
100
|
print(';');
|
|
101
101
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "17.
|
|
3
|
+
"version": "17.3.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",
|
|
@@ -58,7 +58,8 @@
|
|
|
58
58
|
"#test": "./test/create-test.js",
|
|
59
59
|
"#is": "./lib/tokenize/is.js",
|
|
60
60
|
"#maybe-parens": "./lib/tokenize/maybe/maybe-parens.js",
|
|
61
|
-
"#print-params": "./lib/tokenize/expressions/function/params.js"
|
|
61
|
+
"#print-params": "./lib/tokenize/expressions/function/params.js",
|
|
62
|
+
"#import-attributes": "./lib/tokenize/statements/import-declaration/import-attribute.js"
|
|
62
63
|
},
|
|
63
64
|
"devDependencies": {
|
|
64
65
|
"@babel/parser": "^7.28.5",
|
|
@@ -72,7 +73,7 @@
|
|
|
72
73
|
"c8": "^10.1.2",
|
|
73
74
|
"check-dts": "^0.9.0",
|
|
74
75
|
"escover": "^5.0.0",
|
|
75
|
-
"eslint": "^
|
|
76
|
+
"eslint": "^10.0.0",
|
|
76
77
|
"eslint-plugin-putout": "^30.0.0",
|
|
77
78
|
"estree-to-babel": "^12.0.0",
|
|
78
79
|
"goldstein": "^7.0.0",
|