@putout/printer 15.27.0 → 16.0.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/expressions/import-expression.js +2 -2
- package/lib/tokenize/expressions/object-pattern/comments.js +22 -0
- package/lib/tokenize/expressions/object-pattern/object-pattern.js +18 -0
- package/lib/tokenize/statements/import-declaration/import-attribute.js +2 -11
- package/lib/tokenize/statements/import-declaration/import-declaration.js +5 -4
- package/lib/tokenize/typescript/ts-import-type.js +2 -4
- package/package.json +5 -5
package/ChangeLog
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
2025.11.28, v16.0.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 8464bc8 @putout/printer: TSImportType: argument -> source
|
|
5
|
+
- 79e538a @putout/printer: ImportDeclaration: drop support of assertions
|
|
6
|
+
- 4a62b80 @putout/printer: @putout/operate v15.0.0
|
|
7
|
+
- 1876784 @putout/printer: @putout/compare v19.0.1
|
|
8
|
+
- 0a777ac @putout/printer: eslint-plugin-putout v29.0.0
|
|
9
|
+
- b0874ca @putout/printer: @putout/babel v5.0.0
|
|
10
|
+
|
|
11
|
+
2025.11.27, v15.28.0
|
|
12
|
+
|
|
13
|
+
feature:
|
|
14
|
+
- b47c2fc @putout/printer: ObjectPattern: properties: leadingComments
|
|
15
|
+
|
|
1
16
|
2025.11.12, v15.27.0
|
|
2
17
|
|
|
3
18
|
feature:
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
module.exports.ImportExpression = createImportExpression;
|
|
4
4
|
module.exports.createImportExpression = createImportExpression;
|
|
5
5
|
|
|
6
|
-
function createImportExpression(path, printer
|
|
6
|
+
function createImportExpression(path, printer) {
|
|
7
7
|
const {print, maybe} = printer;
|
|
8
8
|
const {options} = path.node;
|
|
9
9
|
|
|
10
10
|
print('import(');
|
|
11
|
-
print(
|
|
11
|
+
print('__source');
|
|
12
12
|
|
|
13
13
|
maybe.print(options, ',');
|
|
14
14
|
maybe.print.space(options);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const createPrintCommentLine = (fn) => (value) => fn(`//${value}`);
|
|
4
|
+
const createPrintCommentBlock = (fn) => (value) => fn(`/*${value}*/`);
|
|
5
|
+
|
|
6
|
+
module.exports.printLeadingComments = (path, {print}) => {
|
|
7
|
+
const printCommentLine = createPrintCommentLine(print);
|
|
8
|
+
const printCommentBlock = createPrintCommentBlock(print);
|
|
9
|
+
const {leadingComments} = path.node;
|
|
10
|
+
|
|
11
|
+
if (!leadingComments)
|
|
12
|
+
return;
|
|
13
|
+
|
|
14
|
+
for (const {type, value} of leadingComments) {
|
|
15
|
+
if (type === 'CommentLine')
|
|
16
|
+
printCommentLine(value);
|
|
17
|
+
else
|
|
18
|
+
printCommentBlock(value);
|
|
19
|
+
|
|
20
|
+
print.breakline();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {types} = require('@putout/babel');
|
|
4
|
+
|
|
4
5
|
const {wrongShorthand} = require('./wrong-shorthand');
|
|
5
6
|
|
|
6
7
|
const {
|
|
@@ -20,6 +21,8 @@ const {
|
|
|
20
21
|
isLongAssignPattern,
|
|
21
22
|
} = require('./calculate-long-assign-pattern');
|
|
22
23
|
|
|
24
|
+
const {printLeadingComments} = require('./comments');
|
|
25
|
+
|
|
23
26
|
const {
|
|
24
27
|
isObjectExpression,
|
|
25
28
|
isIdentifier,
|
|
@@ -152,6 +155,9 @@ module.exports.ObjectPattern = {
|
|
|
152
155
|
if (!isAssign && nextAssignObject)
|
|
153
156
|
print.breakline();
|
|
154
157
|
|
|
158
|
+
printLeadingComments(property, {
|
|
159
|
+
print,
|
|
160
|
+
});
|
|
155
161
|
printKey(property, printer);
|
|
156
162
|
|
|
157
163
|
if (!shorthand || wrongShorthand({computed, isAssign, keyPath, valuePath})) {
|
|
@@ -273,11 +279,23 @@ function hasObjectPattern(properties) {
|
|
|
273
279
|
const ONE_LINE = false;
|
|
274
280
|
const COUPLE_LINES = true;
|
|
275
281
|
|
|
282
|
+
function hasPropertyLeadingComment(properties) {
|
|
283
|
+
for (const property of properties) {
|
|
284
|
+
if (property.node.leadingComments)
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
|
|
276
291
|
function shouldAddNewline(path, semantics) {
|
|
277
292
|
const {parentPath} = path;
|
|
278
293
|
const properties = path.get('properties');
|
|
279
294
|
const n = properties.length - 1;
|
|
280
295
|
|
|
296
|
+
if (hasPropertyLeadingComment(properties))
|
|
297
|
+
return true;
|
|
298
|
+
|
|
281
299
|
const {
|
|
282
300
|
maxPropertiesInOneLine,
|
|
283
301
|
maxPropertiesLengthInOneLine,
|
|
@@ -8,16 +8,7 @@ module.exports.ImportAttribute = (path, {print}) => {
|
|
|
8
8
|
print(',');
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
module.exports.
|
|
12
|
-
if (isAssertions(path))
|
|
13
|
-
return printAttributes(path, 'assert', printer);
|
|
14
|
-
|
|
15
|
-
printAttributes(path, 'with', printer);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const isAssertions = (path) => path.node.extra?.deprecatedAssertSyntax;
|
|
19
|
-
|
|
20
|
-
function printAttributes(path, keyword, {write, traverse, indent}) {
|
|
11
|
+
module.exports.printAttributes = (path, keyword, {write, traverse, indent}) => {
|
|
21
12
|
const attributes = path.get('attributes');
|
|
22
13
|
|
|
23
14
|
if (!attributes.length)
|
|
@@ -38,4 +29,4 @@ function printAttributes(path, keyword, {write, traverse, indent}) {
|
|
|
38
29
|
|
|
39
30
|
indent.dec();
|
|
40
31
|
write('}');
|
|
41
|
-
}
|
|
32
|
+
};
|
|
@@ -6,8 +6,8 @@ const {markAfter} = require('../../mark');
|
|
|
6
6
|
const {isLast, isNext} = require('../../is');
|
|
7
7
|
|
|
8
8
|
const {
|
|
9
|
-
maybePrintAttributes,
|
|
10
9
|
ImportAttribute,
|
|
10
|
+
printAttributes,
|
|
11
11
|
} = require('./import-attribute');
|
|
12
12
|
|
|
13
13
|
const {
|
|
@@ -88,9 +88,9 @@ module.exports.ImportDeclaration = {
|
|
|
88
88
|
maybe.write(n, ',');
|
|
89
89
|
|
|
90
90
|
const last = index === n;
|
|
91
|
-
const
|
|
91
|
+
const penalty = index === n - 1;
|
|
92
92
|
|
|
93
|
-
maybe.write.newline(
|
|
93
|
+
maybe.write.newline(penalty && defaults.length);
|
|
94
94
|
maybe.write.newline(last);
|
|
95
95
|
}
|
|
96
96
|
|
|
@@ -102,7 +102,8 @@ module.exports.ImportDeclaration = {
|
|
|
102
102
|
print.space();
|
|
103
103
|
|
|
104
104
|
print('__source');
|
|
105
|
-
|
|
105
|
+
printAttributes(path, 'with', printer);
|
|
106
|
+
|
|
106
107
|
print(';');
|
|
107
108
|
|
|
108
109
|
if (isNext(path))
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const {createImportExpression} = require('../expressions/import-expression');
|
|
4
4
|
|
|
5
|
-
module.exports.TSImportType = (path, printer
|
|
6
|
-
createImportExpression(path, printer
|
|
7
|
-
source: 'argument',
|
|
8
|
-
});
|
|
5
|
+
module.exports.TSImportType = (path, printer) => {
|
|
6
|
+
createImportExpression(path, printer);
|
|
9
7
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "16.0.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",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"report": "madrun report"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@putout/babel": "^
|
|
37
|
-
"@putout/compare": "^
|
|
38
|
-
"@putout/operate": "^
|
|
36
|
+
"@putout/babel": "^5.0.0",
|
|
37
|
+
"@putout/compare": "^19.0.1",
|
|
38
|
+
"@putout/operate": "^15.0.0",
|
|
39
39
|
"@putout/operator-json": "^2.0.0",
|
|
40
40
|
"fullstore": "^3.0.0",
|
|
41
41
|
"just-snake-case": "^3.2.0",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"check-dts": "^0.9.0",
|
|
82
82
|
"escover": "^4.0.1",
|
|
83
83
|
"eslint": "^9.0.0",
|
|
84
|
-
"eslint-plugin-putout": "^
|
|
84
|
+
"eslint-plugin-putout": "^29.0.0",
|
|
85
85
|
"estree-to-babel": "^11.0.2",
|
|
86
86
|
"goldstein": "^6.0.1",
|
|
87
87
|
"just-kebab-case": "^4.2.0",
|