@putout/printer 1.55.0 → 1.57.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/expressions/call-expression.js +1 -0
- package/lib/tokenize/expressions/class.js +4 -2
- package/lib/tokenize/expressions/functions/function-declaration.js +9 -8
- package/lib/tokenize/expressions/object-expression.js +1 -0
- package/lib/tokenize/expressions/unary-expressions.js +1 -0
- package/lib/tokenize/is.js +1 -0
- package/lib/tokenize/jsx/index.js +7 -0
- package/lib/tokenize/jsx/jsx-fragment.js +35 -0
- package/lib/tokenize/mark.js +2 -0
- package/lib/tokenize/statements/export-default-declaration.js +1 -17
- package/lib/tokenize/statements/variable-declaration.js +2 -0
- package/lib/tokenize/tokenize.js +2 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -3,16 +3,17 @@
|
|
|
3
3
|
module.exports.ClassExpression = classVisitor;
|
|
4
4
|
module.exports.ClassDeclaration = classVisitor;
|
|
5
5
|
|
|
6
|
-
module.exports.ClassDeclaration = (path, {print, indent}) => {
|
|
6
|
+
module.exports.ClassDeclaration = (path, {print, indent, maybe}) => {
|
|
7
7
|
indent();
|
|
8
8
|
|
|
9
9
|
classVisitor(path, {
|
|
10
10
|
print,
|
|
11
11
|
indent,
|
|
12
|
+
maybe,
|
|
12
13
|
});
|
|
13
14
|
};
|
|
14
15
|
|
|
15
|
-
function classVisitor(path, {print, indent}) {
|
|
16
|
+
function classVisitor(path, {print, indent, maybe}) {
|
|
16
17
|
print('class ');
|
|
17
18
|
print('__id');
|
|
18
19
|
print('__typeParameters');
|
|
@@ -25,6 +26,7 @@ function classVisitor(path, {print, indent}) {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
if (node.superClass) {
|
|
29
|
+
maybe.print.space(path.node.id);
|
|
28
30
|
print('extends ');
|
|
29
31
|
print('__superClass');
|
|
30
32
|
}
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
const
|
|
3
|
+
const {markAfter} = require('../../mark');
|
|
4
|
+
const {isNext} = require('../../is');
|
|
5
5
|
|
|
6
6
|
module.exports.FunctionDeclaration = {
|
|
7
|
-
beforeIf(path) {
|
|
8
|
-
return !isFirst(path) && !hasPrevNewline(path) && !path.parentPath.isExportDeclaration();
|
|
9
|
-
},
|
|
10
|
-
before(path, {write}) {
|
|
11
|
-
write('\n');
|
|
12
|
-
},
|
|
13
7
|
print(path, {print, maybe}) {
|
|
14
8
|
const {async} = path.node;
|
|
15
9
|
|
|
@@ -32,4 +26,11 @@ module.exports.FunctionDeclaration = {
|
|
|
32
26
|
print(') ');
|
|
33
27
|
print('__body');
|
|
34
28
|
},
|
|
29
|
+
afterSatisfy: () => [
|
|
30
|
+
isNext,
|
|
31
|
+
],
|
|
32
|
+
after(path, {write}) {
|
|
33
|
+
write.newline();
|
|
34
|
+
markAfter(path);
|
|
35
|
+
},
|
|
35
36
|
};
|
package/lib/tokenize/is.js
CHANGED
|
@@ -4,8 +4,10 @@ const {JSXElement} = require('./jsx-element');
|
|
|
4
4
|
const {JSXAttribute} = require('./jsx-attribute');
|
|
5
5
|
const {isCoupleLines} = require('../is');
|
|
6
6
|
const {JSXOpeningElement} = require('./jsx-opening-element');
|
|
7
|
+
const fragments = require('./jsx-fragment');
|
|
7
8
|
|
|
8
9
|
module.exports = {
|
|
10
|
+
...fragments,
|
|
9
11
|
JSXElement,
|
|
10
12
|
JSXAttribute,
|
|
11
13
|
JSXOpeningElement,
|
|
@@ -20,6 +22,11 @@ module.exports = {
|
|
|
20
22
|
JSXText(path, {write}) {
|
|
21
23
|
write(path.node.value);
|
|
22
24
|
},
|
|
25
|
+
JSXMemberExpression(path, {print}) {
|
|
26
|
+
print('__object');
|
|
27
|
+
print('.');
|
|
28
|
+
print('__property');
|
|
29
|
+
},
|
|
23
30
|
JSXSpreadAttribute(path, {print, maybe}) {
|
|
24
31
|
const isNewline = isCoupleLines(path.parentPath);
|
|
25
32
|
maybe.indent.inc(isNewline);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.JSXFragment = {
|
|
4
|
+
condition,
|
|
5
|
+
before(path, {write, indent}) {
|
|
6
|
+
write('(');
|
|
7
|
+
indent.inc();
|
|
8
|
+
write.breakline();
|
|
9
|
+
},
|
|
10
|
+
print(path, {print, traverse}) {
|
|
11
|
+
print('__openingFragment');
|
|
12
|
+
path.get('children').map(traverse);
|
|
13
|
+
print('__closingFragment');
|
|
14
|
+
},
|
|
15
|
+
after(path, {write, indent}) {
|
|
16
|
+
indent.dec();
|
|
17
|
+
write.breakline();
|
|
18
|
+
write(')');
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
module.exports.JSXOpeningFragment = (path, {write}) => {
|
|
23
|
+
write('<>');
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
module.exports.JSXClosingFragment = (path, {write}) => {
|
|
27
|
+
write('</>');
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function condition(path) {
|
|
31
|
+
if (path.parentPath.isReturnStatement())
|
|
32
|
+
return true;
|
|
33
|
+
|
|
34
|
+
return path.parentPath.isVariableDeclarator();
|
|
35
|
+
}
|
package/lib/tokenize/mark.js
CHANGED
|
@@ -14,11 +14,13 @@ function markBefore(path) {
|
|
|
14
14
|
function markAfter(path) {
|
|
15
15
|
path[WATER_MARK_AFTER] = true;
|
|
16
16
|
}
|
|
17
|
+
|
|
17
18
|
module.exports.isMarkedAfter = isMarkedAfter;
|
|
18
19
|
|
|
19
20
|
function isMarkedAfter(path) {
|
|
20
21
|
return path[WATER_MARK_AFTER];
|
|
21
22
|
}
|
|
23
|
+
|
|
22
24
|
module.exports.hasPrevNewline = (path) => {
|
|
23
25
|
return isMarkedAfter(path.getPrevSibling());
|
|
24
26
|
};
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
isNewlineBetweenStatements,
|
|
5
|
-
isNext,
|
|
6
|
-
} = require('../is');
|
|
7
|
-
|
|
8
|
-
const {isMarkedAfter} = require('../mark');
|
|
3
|
+
const {isNext} = require('../is');
|
|
9
4
|
|
|
10
5
|
const notClass = (path) => {
|
|
11
6
|
if (!isNext(path))
|
|
@@ -15,17 +10,6 @@ const notClass = (path) => {
|
|
|
15
10
|
};
|
|
16
11
|
|
|
17
12
|
module.exports.ExportDefaultDeclaration = {
|
|
18
|
-
beforeIf(path) {
|
|
19
|
-
const prev = path.getPrevSibling();
|
|
20
|
-
|
|
21
|
-
if (isMarkedAfter(prev))
|
|
22
|
-
return false;
|
|
23
|
-
|
|
24
|
-
return isNewlineBetweenStatements(prev);
|
|
25
|
-
},
|
|
26
|
-
before(path, {print}) {
|
|
27
|
-
print.newline();
|
|
28
|
-
},
|
|
29
13
|
print(path, {print, traverse, maybe}) {
|
|
30
14
|
const declaration = path.get('declaration');
|
|
31
15
|
print('export default ');
|
|
@@ -89,6 +89,7 @@ function isNextCoupleLines(path) {
|
|
|
89
89
|
|
|
90
90
|
return isCoupleLines(next);
|
|
91
91
|
}
|
|
92
|
+
|
|
92
93
|
const isLast = (path) => path.parentPath?.isProgram() && !isNext(path);
|
|
93
94
|
|
|
94
95
|
function shouldAddNewlineBefore(path) {
|
|
@@ -115,6 +116,7 @@ function shouldAddNewlineBefore(path) {
|
|
|
115
116
|
function isFirst(path) {
|
|
116
117
|
return path.node === path.parentPath.node.body?.[0];
|
|
117
118
|
}
|
|
119
|
+
|
|
118
120
|
const isNextAssign = (path) => {
|
|
119
121
|
const nextPath = path.getNextSibling();
|
|
120
122
|
|
package/lib/tokenize/tokenize.js
CHANGED
|
@@ -52,6 +52,7 @@ function initFormat(format) {
|
|
|
52
52
|
indent: ' ',
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
+
|
|
55
56
|
const createAddToken = (tokens) => {
|
|
56
57
|
const log = createLog();
|
|
57
58
|
|
|
@@ -237,6 +238,7 @@ function printIndent(i, indent) {
|
|
|
237
238
|
|
|
238
239
|
return result;
|
|
239
240
|
}
|
|
241
|
+
|
|
240
242
|
const createPrint = (path, {traverse, write}) => (maybeLine) => {
|
|
241
243
|
if (maybeLine === path)
|
|
242
244
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.57.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",
|