@putout/printer 1.29.0 → 1.30.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 +5 -0
- package/lib/tokenize/expressions/functions.js +5 -3
- package/lib/tokenize/expressions/object-expression.js +2 -7
- package/lib/tokenize/jsx/index.js +23 -0
- package/lib/tokenize/jsx/jsx-element.js +25 -0
- package/lib/tokenize/maybe.js +3 -2
- package/lib/tokenize/statements/if-statement.js +1 -3
- package/lib/tokenize/tokenize.js +2 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {hasPrevNewline} = require('../mark');
|
|
4
|
-
const isFirst = (path) => !path
|
|
5
|
-
.getPrevSibling().node;
|
|
4
|
+
const isFirst = (path) => !path.getPrevSibling().node;
|
|
6
5
|
|
|
7
6
|
module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
|
|
8
7
|
const {node} = path;
|
|
9
8
|
|
|
10
|
-
const {
|
|
9
|
+
const {
|
|
10
|
+
generator,
|
|
11
|
+
async,
|
|
12
|
+
} = node;
|
|
11
13
|
|
|
12
14
|
maybe.print(async, 'async ');
|
|
13
15
|
print('function');
|
|
@@ -3,13 +3,8 @@
|
|
|
3
3
|
const {isCoupleLines} = require('../is');
|
|
4
4
|
const {isFunction} = require('@babel/types');
|
|
5
5
|
const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
.get('argument').isLogicalExpression();
|
|
9
|
-
|
|
10
|
-
const isValue = (path) => path
|
|
11
|
-
.get('properties.0.value').node;
|
|
12
|
-
|
|
6
|
+
const isLogical = (path) => path.get('argument').isLogicalExpression();
|
|
7
|
+
const isValue = (path) => path.get('properties.0.value').node;
|
|
13
8
|
const isIf = (path) => path.parentPath.parentPath.isIfStatement();
|
|
14
9
|
const isParentExpression = (path) => path.parentPath.isExpressionStatement();
|
|
15
10
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {JSXElement} = require('./jsx-element');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
JSXElement,
|
|
7
|
+
JSXOpeningElement(path, {print}) {
|
|
8
|
+
print('<');
|
|
9
|
+
print('__name');
|
|
10
|
+
print('>');
|
|
11
|
+
},
|
|
12
|
+
JSXIdentifier(path, {write}) {
|
|
13
|
+
write(path.node.name);
|
|
14
|
+
},
|
|
15
|
+
JSXText(path, {write}) {
|
|
16
|
+
write(path.node.value);
|
|
17
|
+
},
|
|
18
|
+
JSXClosingElement(path, {print}) {
|
|
19
|
+
print('</');
|
|
20
|
+
print('__name');
|
|
21
|
+
print('>');
|
|
22
|
+
},
|
|
23
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.JSXElement = {
|
|
4
|
+
condition,
|
|
5
|
+
before(path, {write, indent}) {
|
|
6
|
+
write('(');
|
|
7
|
+
write.breakline();
|
|
8
|
+
indent();
|
|
9
|
+
indent.inc();
|
|
10
|
+
},
|
|
11
|
+
print(path, {print, traverse}) {
|
|
12
|
+
print('__openingElement');
|
|
13
|
+
path.get('children').map(traverse);
|
|
14
|
+
print('__closingElement');
|
|
15
|
+
},
|
|
16
|
+
after(path, {write, indent}) {
|
|
17
|
+
indent.dec();
|
|
18
|
+
write.breakline();
|
|
19
|
+
write(')');
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function condition(path) {
|
|
24
|
+
return path.parentPath.isReturnStatement();
|
|
25
|
+
}
|
package/lib/tokenize/maybe.js
CHANGED
|
@@ -27,10 +27,11 @@ function objectPlugin(plugin, path, printer) {
|
|
|
27
27
|
const {
|
|
28
28
|
print,
|
|
29
29
|
split,
|
|
30
|
+
condition,
|
|
30
31
|
before = split,
|
|
31
|
-
beforeIf,
|
|
32
|
+
beforeIf = condition,
|
|
32
33
|
after = split,
|
|
33
|
-
afterIf,
|
|
34
|
+
afterIf = condition,
|
|
34
35
|
} = plugin;
|
|
35
36
|
|
|
36
37
|
if (beforeIf?.(path, printer)) {
|
|
@@ -6,9 +6,7 @@ const {
|
|
|
6
6
|
} = require('../mark');
|
|
7
7
|
|
|
8
8
|
const {isFirst} = require('../is');
|
|
9
|
-
|
|
10
|
-
const isEmptyConsequent = (path) => path
|
|
11
|
-
.get('consequent').isEmptyStatement();
|
|
9
|
+
const isEmptyConsequent = (path) => path.get('consequent').isEmptyStatement();
|
|
12
10
|
|
|
13
11
|
module.exports.IfStatement = {
|
|
14
12
|
before: (path, {print}) => {
|
package/lib/tokenize/tokenize.js
CHANGED
|
@@ -8,6 +8,7 @@ const expressions = require('./expressions');
|
|
|
8
8
|
const statements = require('./statements');
|
|
9
9
|
const literals = require('./literals');
|
|
10
10
|
const typescript = require('./typescript');
|
|
11
|
+
const jsx = require('./jsx');
|
|
11
12
|
const {TYPES} = require('../types');
|
|
12
13
|
|
|
13
14
|
const {
|
|
@@ -38,6 +39,7 @@ const traversers = {
|
|
|
38
39
|
...statements,
|
|
39
40
|
...literals,
|
|
40
41
|
...typescript,
|
|
42
|
+
...jsx,
|
|
41
43
|
};
|
|
42
44
|
|
|
43
45
|
const GET = '__';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.30.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",
|