@putout/printer 1.66.0 → 1.68.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/lib/tokenize/comments.js +2 -1
- package/lib/tokenize/expressions/object-expression.js +3 -1
- package/lib/tokenize/is.js +2 -0
- package/lib/tokenize/maybe/index.js +3 -1
- package/lib/tokenize/statements/export-declarations.js +17 -0
- package/lib/tokenize/statements/index.js +6 -1
- package/lib/tokenize/statements/return-statement.js +30 -17
- package/lib/tokenize/typescript/ts-type-parameter.js +0 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/lib/tokenize/comments.js
CHANGED
|
@@ -55,10 +55,11 @@ module.exports.parseTrailingComments = (path, {write, maybe}) => {
|
|
|
55
55
|
for (const {type, value, loc} of trailingComments) {
|
|
56
56
|
if (type === 'CommentLine') {
|
|
57
57
|
const sameLine = isSameLine(path, loc);
|
|
58
|
+
|
|
58
59
|
maybe.write.space(sameLine);
|
|
59
60
|
maybe.indent(!sameLine);
|
|
60
61
|
write(`//${value}`);
|
|
61
|
-
|
|
62
|
+
write.newline();
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
};
|
|
@@ -4,6 +4,8 @@ const {
|
|
|
4
4
|
isCoupleLines,
|
|
5
5
|
isForOf,
|
|
6
6
|
isIf,
|
|
7
|
+
noTrailingComment,
|
|
8
|
+
|
|
7
9
|
} = require('../is');
|
|
8
10
|
|
|
9
11
|
const {isFunction} = require('@babel/types');
|
|
@@ -46,7 +48,7 @@ module.exports.ObjectExpression = (path, {print, maybe, indent}) => {
|
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
print(property);
|
|
49
|
-
maybe.print.newline(manyLines);
|
|
51
|
+
maybe.print.newline(manyLines && noTrailingComment(property));
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
indent.dec();
|
package/lib/tokenize/is.js
CHANGED
|
@@ -23,7 +23,9 @@ module.exports.maybeThrow = (a, path, b) => {
|
|
|
23
23
|
}));
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
const maybeProgram = (ast) => isProgram(ast) ? ast : Program([
|
|
26
|
+
const maybeProgram = (ast) => isProgram(ast) ? ast : Program([
|
|
27
|
+
ExpressionStatement(ast),
|
|
28
|
+
]);
|
|
27
29
|
|
|
28
30
|
module.exports.maybeFile = (ast) => isFile(ast) ? ast : File(maybeProgram(ast));
|
|
29
31
|
|
|
@@ -14,10 +14,27 @@ module.exports.ExportSpecifier = (path, {print}) => {
|
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
+
module.exports.ExportNamespaceSpecifier = (path, {print}) => {
|
|
18
|
+
print(' * as ');
|
|
19
|
+
print('__exported');
|
|
20
|
+
};
|
|
21
|
+
|
|
17
22
|
module.exports.ExportNamedDeclaration = (path, {print, traverse, write, indent}) => {
|
|
23
|
+
const {exportKind} = path.node;
|
|
18
24
|
const specifiers = path.get('specifiers');
|
|
25
|
+
|
|
19
26
|
write('export ');
|
|
20
27
|
|
|
28
|
+
if (exportKind === 'type' && specifiers.length) {
|
|
29
|
+
print('type');
|
|
30
|
+
print(specifiers[0]);
|
|
31
|
+
print(' from ');
|
|
32
|
+
print('__source');
|
|
33
|
+
print(';');
|
|
34
|
+
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
21
38
|
if (specifiers.length) {
|
|
22
39
|
write('{');
|
|
23
40
|
indent.inc();
|
|
@@ -16,7 +16,11 @@ const {SwitchStatement} = require('./switch-statement');
|
|
|
16
16
|
const {ForInStatement} = require('./for-in-statement');
|
|
17
17
|
const {ExportDefaultDeclaration} = require('./export-default-declaration');
|
|
18
18
|
const {BreakStatement} = require('./break-statement');
|
|
19
|
-
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
ExportNamespaceSpecifier,
|
|
22
|
+
ExportSpecifier,
|
|
23
|
+
} = exportDeclarations;
|
|
20
24
|
|
|
21
25
|
module.exports = {
|
|
22
26
|
...importDeclarations,
|
|
@@ -24,6 +28,7 @@ module.exports = {
|
|
|
24
28
|
BlockStatement,
|
|
25
29
|
ExpressionStatement,
|
|
26
30
|
ExportSpecifier,
|
|
31
|
+
ExportNamespaceSpecifier,
|
|
27
32
|
ExportDefaultDeclaration,
|
|
28
33
|
VariableDeclaration,
|
|
29
34
|
IfStatement,
|
|
@@ -1,25 +1,38 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
isPrevBody,
|
|
5
|
+
noTrailingComment,
|
|
6
|
+
} = require('../is');
|
|
7
|
+
|
|
4
8
|
const {hasPrevNewline} = require('../mark');
|
|
5
9
|
const isBodyLength = ({parentPath}) => parentPath.node?.body?.length > 2;
|
|
6
10
|
|
|
7
|
-
module.exports.ReturnStatement =
|
|
8
|
-
|
|
11
|
+
module.exports.ReturnStatement = {
|
|
12
|
+
beforeIf(path) {
|
|
13
|
+
return !hasPrevNewline(path) && isBodyLength(path) || isPrevBody(path);
|
|
14
|
+
},
|
|
15
|
+
before(path, {print}) {
|
|
9
16
|
print.indent();
|
|
10
17
|
print.newline();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
},
|
|
19
|
+
print(path, {indent, traverse, print}) {
|
|
20
|
+
indent();
|
|
21
|
+
print('return');
|
|
22
|
+
|
|
23
|
+
const argPath = path.get('argument');
|
|
24
|
+
|
|
25
|
+
if (argPath.node) {
|
|
26
|
+
print(' ');
|
|
27
|
+
traverse(argPath);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
print(';');
|
|
31
|
+
},
|
|
32
|
+
afterSatisfy: () => [
|
|
33
|
+
noTrailingComment,
|
|
34
|
+
],
|
|
35
|
+
after(path, {print}) {
|
|
36
|
+
print.newline();
|
|
37
|
+
},
|
|
25
38
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.68.0",
|
|
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",
|