@putout/printer 18.0.6 → 18.0.8
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 +11 -0
- package/lib/tokenize/expressions/class/class.js +3 -1
- package/lib/tokenize/expressions/function/function-declaration.js +2 -10
- package/lib/tokenize/is.js +3 -11
- package/lib/tokenize/statements/variable-declaration/variable-declaration.js +19 -6
- package/lib/tokenize/type-checker/instrument.js +8 -3
- package/lib/tokenize/type-checker/parsers.js +0 -1
- package/lib/tokenize/type-checker/type-checker.js +9 -4
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2026.03.05, v18.0.8
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 08b7207 @putout/printer: VariableDeclaration: inside ForStatement
|
|
5
|
+
- dda61cc @putout/printer: type-check-coverage: check for only
|
|
6
|
+
|
|
7
|
+
2026.03.05, v18.0.7
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- dd7f874 @putout/printer: VariableDeclaration: inside ForOfStatement: indent
|
|
11
|
+
|
|
1
12
|
2026.03.05, v18.0.6
|
|
2
13
|
|
|
3
14
|
feature:
|
|
@@ -90,13 +90,15 @@ export const ClassDeclaration = {
|
|
|
90
90
|
classVisitor(path, printer, semantics);
|
|
91
91
|
}),
|
|
92
92
|
afterIf(path) {
|
|
93
|
+
const {parentPath} = path;
|
|
94
|
+
|
|
93
95
|
if (isFunctionLike(path))
|
|
94
96
|
return true;
|
|
95
97
|
|
|
96
98
|
if (isNext(path))
|
|
97
99
|
return true;
|
|
98
100
|
|
|
99
|
-
return isInsideTSModuleBlock(
|
|
101
|
+
return isInsideTSModuleBlock(parentPath);
|
|
100
102
|
},
|
|
101
103
|
after(path, {write}) {
|
|
102
104
|
write.newline();
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
2
|
import {printParams} from '#print-params';
|
|
3
3
|
import {markAfter} from '#mark';
|
|
4
|
-
import {
|
|
5
|
-
isInsideTSModuleBlock,
|
|
6
|
-
isNext,
|
|
7
|
-
isNextParent,
|
|
8
|
-
} from '#is';
|
|
4
|
+
import {isNext, isNextParent} from '#is';
|
|
9
5
|
import {createTypeChecker} from '#type-checker';
|
|
10
6
|
|
|
11
7
|
const {
|
|
@@ -22,11 +18,7 @@ const isInsideExportDefaultWithBody = createTypeChecker([
|
|
|
22
18
|
['+', hasFnBody],
|
|
23
19
|
]);
|
|
24
20
|
|
|
25
|
-
const isInsideBlockLike = createTypeChecker([
|
|
26
|
-
['+', isInsideTSModuleBlock],
|
|
27
|
-
'-: parentPath -> !BlockStatement',
|
|
28
|
-
['+: -> !', hasFnBody],
|
|
29
|
-
]);
|
|
21
|
+
const isInsideBlockLike = createTypeChecker(['+: parentPath.parentPath -> TSModuleBlock', '-: parentPath -> !BlockStatement', ['+: -> !', hasFnBody]]);
|
|
30
22
|
|
|
31
23
|
const not = (fn) => (...a) => !fn(...a);
|
|
32
24
|
const notInsideExportDefaultWithBody = not(isInsideExportDefaultWithBody);
|
package/lib/tokenize/is.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
|
-
import {createTypeChecker} from '#type-checker';
|
|
3
2
|
|
|
4
3
|
const {
|
|
5
4
|
isStringLiteral,
|
|
@@ -16,21 +15,14 @@ const {
|
|
|
16
15
|
isProgram,
|
|
17
16
|
isBlockStatement,
|
|
18
17
|
isTSModuleBlock,
|
|
18
|
+
isSwitchCase,
|
|
19
19
|
} = types;
|
|
20
20
|
|
|
21
21
|
export const isInsideProgram = (path) => isProgram(path.parentPath);
|
|
22
22
|
export const isInsideBlock = (path) => isBlockStatement(path.parentPath);
|
|
23
|
+
export const isInsideSwitchCase = (path) => isSwitchCase(path.parentPath);
|
|
23
24
|
|
|
24
|
-
export const
|
|
25
|
-
'Program',
|
|
26
|
-
'BlockStatement',
|
|
27
|
-
'TSModuleBlock',
|
|
28
|
-
'SwitchCase',
|
|
29
|
-
]);
|
|
30
|
-
|
|
31
|
-
export const isInsideTSModuleBlock = ({parentPath}) => {
|
|
32
|
-
return isTSModuleBlock(parentPath?.parentPath);
|
|
33
|
-
};
|
|
25
|
+
export const isInsideTSModuleBlock = ({parentPath}) => isTSModuleBlock(parentPath);
|
|
34
26
|
|
|
35
27
|
export const isInsideCall = ({parentPath}) => parentPath.isCallExpression();
|
|
36
28
|
|
|
@@ -7,25 +7,37 @@ import {
|
|
|
7
7
|
isNewlineBetweenSiblings,
|
|
8
8
|
exists,
|
|
9
9
|
noTrailingComment,
|
|
10
|
-
isInsideBlockLike,
|
|
11
10
|
isInsideIf,
|
|
12
11
|
isInsideBlock,
|
|
13
12
|
isInsideExport,
|
|
13
|
+
isInsideTSModuleBlock,
|
|
14
|
+
isInsideProgram,
|
|
15
|
+
isInsideSwitchCase,
|
|
14
16
|
} from '#is';
|
|
15
17
|
import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
|
|
16
18
|
import {isConcatenation} from '../../expressions/binary-expression/concatenate.js';
|
|
17
19
|
import {parseLeadingComments} from '../../comment/comment.js';
|
|
18
20
|
import {maybeDeclare} from '../../maybe/maybe-declare.js';
|
|
19
21
|
|
|
20
|
-
const isLast = (path) => path.parentPath?.isProgram() && !isNext(path);
|
|
21
|
-
|
|
22
22
|
const {isExportDeclaration} = types;
|
|
23
23
|
|
|
24
|
+
const isInsideBody = (path) => path.node === path.parentPath.node.body;
|
|
25
|
+
|
|
26
|
+
const isInsideBlockLike = createTypeChecker([
|
|
27
|
+
isInsideProgram,
|
|
28
|
+
isInsideBlock,
|
|
29
|
+
isInsideTSModuleBlock,
|
|
30
|
+
isInsideSwitchCase,
|
|
31
|
+
isInsideBody,
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
const isLast = (path) => path.parentPath?.isProgram() && !isNext(path);
|
|
35
|
+
|
|
24
36
|
const isParentTSModuleBlock = (path) => path.parentPath.isTSModuleBlock();
|
|
25
37
|
const isParentSwitchCase = (path) => path.parentPath.isSwitchCase();
|
|
26
38
|
const isFirstInSwitch = (path) => path.parentPath.get('consequent.0') === path;
|
|
27
39
|
|
|
28
|
-
const
|
|
40
|
+
const isInsideParentLike = createTypeChecker('path.parentPath', [
|
|
29
41
|
'Program',
|
|
30
42
|
'BlockStatement',
|
|
31
43
|
'ExportNamedDeclaration',
|
|
@@ -33,14 +45,15 @@ const isIsideParentLike = createTypeChecker('path.parentPath', [
|
|
|
33
45
|
]);
|
|
34
46
|
|
|
35
47
|
const isNeedSemicolon = createTypeChecker([
|
|
36
|
-
|
|
48
|
+
isInsideParentLike,
|
|
37
49
|
isParentSwitchCase,
|
|
38
50
|
isParentTSModuleBlock,
|
|
39
51
|
isInsideIf,
|
|
52
|
+
isInsideBody,
|
|
40
53
|
]);
|
|
41
54
|
|
|
42
55
|
const isNeedNewline = createTypeChecker([
|
|
43
|
-
['-: -> !',
|
|
56
|
+
['-: -> !', isInsideParentLike],
|
|
44
57
|
['-: -> !', isNext],
|
|
45
58
|
['+', noTrailingComment],
|
|
46
59
|
['+', isNewlineBetweenSiblings],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {env} from 'node:process';
|
|
1
|
+
import {env as _env} from 'node:process';
|
|
2
2
|
|
|
3
3
|
const STACK_INDEX = 3;
|
|
4
4
|
|
|
@@ -6,7 +6,12 @@ const parseCallLocation = ({stack}) => stack.split('\n')[STACK_INDEX];
|
|
|
6
6
|
|
|
7
7
|
const Coverage = new Map();
|
|
8
8
|
|
|
9
|
-
export const instrument = (typeNames, fn) => {
|
|
9
|
+
export const instrument = (typeNames, fn, overrides = {}) => {
|
|
10
|
+
const {
|
|
11
|
+
env = _env,
|
|
12
|
+
coverage = Coverage,
|
|
13
|
+
} = overrides;
|
|
14
|
+
|
|
10
15
|
const {length} = typeNames;
|
|
11
16
|
const error = Error();
|
|
12
17
|
const location = parseCallLocation(error);
|
|
@@ -14,7 +19,7 @@ export const instrument = (typeNames, fn) => {
|
|
|
14
19
|
const covered = new Set();
|
|
15
20
|
|
|
16
21
|
if (on && !location.includes('type-checker.spec.js'))
|
|
17
|
-
|
|
22
|
+
coverage.set(location, {
|
|
18
23
|
length,
|
|
19
24
|
covered,
|
|
20
25
|
typeNames,
|
|
@@ -3,6 +3,11 @@ import {instrument} from '#type-checker/instrument';
|
|
|
3
3
|
import {parseOperation, parseTypeNames} from './parsers.js';
|
|
4
4
|
import {equal, maybeCall} from './comparators.js';
|
|
5
5
|
|
|
6
|
+
const SKIP = [
|
|
7
|
+
Infinity,
|
|
8
|
+
false,
|
|
9
|
+
];
|
|
10
|
+
|
|
6
11
|
export const createTypeChecker = (deepness, typeNames) => {
|
|
7
12
|
if (!typeNames) {
|
|
8
13
|
typeNames = deepness;
|
|
@@ -30,6 +35,9 @@ export const createTypeChecker = (deepness, typeNames) => {
|
|
|
30
35
|
if (selector)
|
|
31
36
|
currentPath = jessy(selector, path);
|
|
32
37
|
|
|
38
|
+
if (!currentPath)
|
|
39
|
+
return SKIP;
|
|
40
|
+
|
|
33
41
|
const {type} = currentPath;
|
|
34
42
|
|
|
35
43
|
if (equal(not, type, typeName))
|
|
@@ -39,9 +47,6 @@ export const createTypeChecker = (deepness, typeNames) => {
|
|
|
39
47
|
return [index, result];
|
|
40
48
|
}
|
|
41
49
|
|
|
42
|
-
return
|
|
43
|
-
Infinity,
|
|
44
|
-
false,
|
|
45
|
-
];
|
|
50
|
+
return SKIP;
|
|
46
51
|
});
|
|
47
52
|
};
|
package/package.json
CHANGED