@putout/printer 1.10.0 → 1.11.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 +6 -0
- package/README.md +1 -1
- package/lib/tokenize/expressions/new-expression.js +1 -3
- package/lib/tokenize/expressions/object-pattern.js +1 -2
- package/lib/tokenize/statements/block-statement.js +35 -26
- package/lib/tokenize/statements/import-declarations.js +2 -3
- package/lib/tokenize/statements/index.js +1 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {entries} = Object;
|
|
4
|
-
|
|
5
3
|
module.exports.NewExpression = (path, {indent, print, maybe}) => {
|
|
6
4
|
indent();
|
|
7
5
|
print('new ');
|
|
@@ -12,7 +10,7 @@ module.exports.NewExpression = (path, {indent, print, maybe}) => {
|
|
|
12
10
|
|
|
13
11
|
const n = args.length - 1;
|
|
14
12
|
|
|
15
|
-
for (const [i, arg] of entries(
|
|
13
|
+
for (const [i, arg] of args.entries()) {
|
|
16
14
|
print(arg);
|
|
17
15
|
maybe.print(i < n, ', ');
|
|
18
16
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {entries} = Object;
|
|
4
3
|
const isForOf = (path) => path.parentPath?.parentPath?.parentPath?.isForOfStatement();
|
|
5
4
|
|
|
6
5
|
module.exports.ObjectPattern = (path, {indent, print, maybe}) => {
|
|
@@ -13,7 +12,7 @@ module.exports.ObjectPattern = (path, {indent, print, maybe}) => {
|
|
|
13
12
|
const is = !isForOf(path) && !path.parentPath.isFunction() && n && checkLength(properties);
|
|
14
13
|
maybe.print(is, '\n');
|
|
15
14
|
|
|
16
|
-
for (const [i, property] of entries(
|
|
15
|
+
for (const [i, property] of properties.entries()) {
|
|
17
16
|
if (property.isRestElement()) {
|
|
18
17
|
print(property);
|
|
19
18
|
continue;
|
|
@@ -3,37 +3,43 @@
|
|
|
3
3
|
const {
|
|
4
4
|
isNext,
|
|
5
5
|
isParentProgram,
|
|
6
|
+
isLast,
|
|
7
|
+
|
|
6
8
|
} = require('../is');
|
|
7
9
|
|
|
8
10
|
const isFirstStatement = (path) => path.get('body.0')?.isStatement();
|
|
9
11
|
|
|
10
|
-
module.exports.BlockStatement =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
module.exports.BlockStatement = {
|
|
13
|
+
print(path, {indent, maybe, print}) {
|
|
14
|
+
const body = path.get('body');
|
|
15
|
+
|
|
16
|
+
if (path.parentPath.isBlockStatement())
|
|
17
|
+
indent();
|
|
18
|
+
|
|
19
|
+
indent.inc();
|
|
20
|
+
print('{');
|
|
21
|
+
|
|
22
|
+
if (body.length > 1 || isFirstStatement(path))
|
|
23
|
+
print.newline();
|
|
24
|
+
|
|
25
|
+
for (const element of body) {
|
|
26
|
+
print(element);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
indent.dec();
|
|
30
|
+
maybe.indent(body.length);
|
|
31
|
+
print('}');
|
|
32
|
+
|
|
33
|
+
if (path.parentPath.isObjectMethod()) {
|
|
34
|
+
print(',');
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
afterIf(path) {
|
|
38
|
+
return shouldAddNewlineAfter(path);
|
|
39
|
+
},
|
|
40
|
+
after(path, {print}) {
|
|
20
41
|
print.newline();
|
|
21
|
-
|
|
22
|
-
for (const element of body) {
|
|
23
|
-
print(element);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
indent.dec();
|
|
27
|
-
maybe.indent(body.length);
|
|
28
|
-
print('}');
|
|
29
|
-
|
|
30
|
-
if (path.parentPath.isObjectMethod()) {
|
|
31
|
-
print(',');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (shouldAddNewlineAfter(path)) {
|
|
35
|
-
print.newline();
|
|
36
|
-
}
|
|
42
|
+
},
|
|
37
43
|
};
|
|
38
44
|
|
|
39
45
|
function shouldAddNewlineAfter(path) {
|
|
@@ -48,6 +54,9 @@ function shouldAddNewlineAfter(path) {
|
|
|
48
54
|
if (isTry(path) || /FunctionExpression/.test(path.parentPath.type))
|
|
49
55
|
return false;
|
|
50
56
|
|
|
57
|
+
if (isLast(path))
|
|
58
|
+
return false;
|
|
59
|
+
|
|
51
60
|
return true;
|
|
52
61
|
}
|
|
53
62
|
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {markAfter} = require('../mark');
|
|
4
|
-
const {entries} = Object;
|
|
5
4
|
|
|
6
5
|
module.exports.ImportDeclaration = (path, {print, maybe}) => {
|
|
7
6
|
const specifiers = path.get('specifiers');
|
|
8
7
|
print('import ');
|
|
9
8
|
|
|
10
|
-
for (const [index, spec] of entries(
|
|
9
|
+
for (const [index, spec] of specifiers.entries()) {
|
|
11
10
|
if (spec.isImportDefaultSpecifier()) {
|
|
12
11
|
print(spec.get('local'));
|
|
13
12
|
continue;
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
if (spec.isImportSpecifier()) {
|
|
17
|
-
maybe.print(
|
|
16
|
+
maybe.print(index, ', ');
|
|
18
17
|
print('{');
|
|
19
18
|
print(spec.get('imported'));
|
|
20
19
|
print('}');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.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",
|