@putout/printer 12.19.1 → 12.20.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/is.js +2 -0
- package/lib/tokenize/statements/{break-statement.js → break-statement/break-statement.js} +8 -3
- package/lib/tokenize/statements/debugger-statement.js +1 -2
- package/lib/tokenize/statements/if-statement/if-statement.js +8 -4
- package/lib/tokenize/statements/index.js +1 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/lib/tokenize/is.js
CHANGED
|
@@ -128,6 +128,8 @@ module.exports.isForOf = (path) => {
|
|
|
128
128
|
return false;
|
|
129
129
|
};
|
|
130
130
|
|
|
131
|
+
module.exports.isInsideIf = (path) => path.parentPath?.isIfStatement();
|
|
132
|
+
|
|
131
133
|
module.exports.isNewlineBetweenSiblings = (path) => {
|
|
132
134
|
const endCurrent = path.node?.loc?.end?.line;
|
|
133
135
|
const startNext = path.getNextSibling().node?.loc?.start?.line;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
isParentBlock,
|
|
5
|
+
isNextParent,
|
|
6
|
+
isInsideIf,
|
|
7
|
+
} = require('../../is');
|
|
4
8
|
|
|
5
|
-
const
|
|
9
|
+
const isInsideCase = (path) => path.parentPath.isSwitchCase();
|
|
6
10
|
|
|
7
11
|
module.exports.BreakStatement = {
|
|
8
12
|
split(path, {print}) {
|
|
@@ -19,6 +23,7 @@ module.exports.BreakStatement = {
|
|
|
19
23
|
afterSatisfy: () => [
|
|
20
24
|
isParentBlock,
|
|
21
25
|
isNextParent,
|
|
22
|
-
|
|
26
|
+
isInsideCase,
|
|
27
|
+
isInsideIf,
|
|
23
28
|
],
|
|
24
29
|
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {isNext} = require('../is');
|
|
3
|
+
const {isNext, isInsideIf} = require('../is');
|
|
4
4
|
const isInsideBlock = (path) => path.parentPath.isBlockStatement();
|
|
5
|
-
const isInsideIf = (path) => path.parentPath.isIfStatement();
|
|
6
5
|
|
|
7
6
|
module.exports.DebuggerStatement = {
|
|
8
7
|
print(path, {print, indent}) {
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
const {types} = require('@putout/babel');
|
|
4
4
|
|
|
5
5
|
const {markAfter} = require('../../mark');
|
|
6
|
-
const {
|
|
6
|
+
const {
|
|
7
|
+
exists,
|
|
8
|
+
isNext,
|
|
9
|
+
isInsideIf,
|
|
10
|
+
} = require('../../is');
|
|
7
11
|
|
|
8
12
|
const {
|
|
9
13
|
isBlockStatement,
|
|
@@ -20,7 +24,6 @@ const isInsideNestedBody = ({parentPath}) => {
|
|
|
20
24
|
return parentPath.parentPath.type === 'BlockStatement';
|
|
21
25
|
};
|
|
22
26
|
|
|
23
|
-
const isInsideIf = (path) => path.parentPath.parentPath?.isIfStatement();
|
|
24
27
|
const isEmptyBody = (path) => !path.node.body.length;
|
|
25
28
|
|
|
26
29
|
const isLastEmptyInsideBody = (path) => {
|
|
@@ -40,7 +43,8 @@ const isLastEmptyInsideBody = (path) => {
|
|
|
40
43
|
|
|
41
44
|
module.exports.IfStatement = {
|
|
42
45
|
print: (path, {indent, print, maybe, write, traverse}) => {
|
|
43
|
-
const
|
|
46
|
+
const {parentPath} = path;
|
|
47
|
+
const partOfAlternate = parentPath.get('alternate');
|
|
44
48
|
|
|
45
49
|
if (path !== partOfAlternate)
|
|
46
50
|
indent();
|
|
@@ -60,7 +64,7 @@ module.exports.IfStatement = {
|
|
|
60
64
|
print.space();
|
|
61
65
|
print(consequent);
|
|
62
66
|
|
|
63
|
-
if (isInsideIf(path) || isInsideNestedBody(path))
|
|
67
|
+
if (isInsideIf(path.parentPath) || isInsideNestedBody(path))
|
|
64
68
|
maybe.print.newline(isEmptyBody(consequent));
|
|
65
69
|
} else {
|
|
66
70
|
const is = !isEmptyConsequent(path);
|
|
@@ -17,7 +17,7 @@ const {WhileStatement} = require('./while-statement');
|
|
|
17
17
|
const {SwitchStatement} = require('./switch-statement');
|
|
18
18
|
const {ForInStatement} = require('./for-in-statement');
|
|
19
19
|
const {ExportDefaultDeclaration} = require('./export-declaration/export-default-declaration');
|
|
20
|
-
const {BreakStatement} = require('./break-statement');
|
|
20
|
+
const {BreakStatement} = require('./break-statement/break-statement');
|
|
21
21
|
const {DoWhileStatement} = require('./do-while-statement');
|
|
22
22
|
const {Program} = require('./program/program');
|
|
23
23
|
const {ContinueStatement} = require('./continue-statement');
|
package/package.json
CHANGED