@putout/printer 18.0.5 → 18.0.6

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 CHANGED
@@ -1,3 +1,8 @@
1
+ 2026.03.05, v18.0.6
2
+
3
+ feature:
4
+ - 2b1dbb4 @putout/printer: check-types: instrument
5
+
1
6
  2026.03.04, v18.0.5
2
7
 
3
8
  feature:
@@ -0,0 +1,33 @@
1
+ import {env} from 'node:process';
2
+
3
+ const STACK_INDEX = 3;
4
+
5
+ const parseCallLocation = ({stack}) => stack.split('\n')[STACK_INDEX];
6
+
7
+ const Coverage = new Map();
8
+
9
+ export const instrument = (typeNames, fn) => {
10
+ const {length} = typeNames;
11
+ const error = Error();
12
+ const location = parseCallLocation(error);
13
+ const on = env.TYPE_CHECK;
14
+ const covered = new Set();
15
+
16
+ if (on && !location.includes('type-checker.spec.js'))
17
+ Coverage.set(location, {
18
+ length,
19
+ covered,
20
+ typeNames,
21
+ });
22
+
23
+ return (path, options) => {
24
+ const [index, result] = fn(path, options);
25
+
26
+ if (on && index !== Infinity)
27
+ covered.add(index);
28
+
29
+ return result;
30
+ };
31
+ };
32
+
33
+ export const getCoverage = () => Coverage;
@@ -1,6 +1,6 @@
1
- import {isArray} from '@putout/compare/lib/is.js';
2
1
  import {createTuple} from './create-tuple.js';
3
2
 
3
+ const {isArray} = Array;
4
4
  const isString = (a) => typeof a === 'string';
5
5
 
6
6
  export const parseOperation = (operation) => {
@@ -49,3 +49,4 @@ export function parseTypeNames(typeNames) {
49
49
 
50
50
  return tuples;
51
51
  }
52
+
@@ -1,4 +1,5 @@
1
1
  import {jessy} from 'jessy';
2
+ import {instrument} from '#type-checker/instrument';
2
3
  import {parseOperation, parseTypeNames} from './parsers.js';
3
4
  import {equal, maybeCall} from './comparators.js';
4
5
 
@@ -10,16 +11,19 @@ export const createTypeChecker = (deepness, typeNames) => {
10
11
 
11
12
  const tuples = parseTypeNames(typeNames);
12
13
 
13
- return (path, options) => {
14
+ return instrument(typeNames, (path, options) => {
14
15
  let i = deepness.split('.').length;
15
16
 
16
17
  while (--i)
17
18
  path = path?.parentPath;
18
19
 
19
20
  if (!path)
20
- return false;
21
+ return [
22
+ Infinity,
23
+ false,
24
+ ];
21
25
 
22
- for (const [operation, typeName] of tuples) {
26
+ for (const [index, [operation, typeName]] of tuples.entries()) {
23
27
  const [result, selector, not] = parseOperation(operation);
24
28
  let currentPath = path;
25
29
 
@@ -29,12 +33,15 @@ export const createTypeChecker = (deepness, typeNames) => {
29
33
  const {type} = currentPath;
30
34
 
31
35
  if (equal(not, type, typeName))
32
- return result;
36
+ return [index, result];
33
37
 
34
38
  if (maybeCall(typeName, not, currentPath, options))
35
- return result;
39
+ return [index, result];
36
40
  }
37
41
 
38
- return false;
39
- };
42
+ return [
43
+ Infinity,
44
+ false,
45
+ ];
46
+ });
40
47
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.0.5",
3
+ "version": "18.0.6",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",
@@ -19,16 +19,16 @@
19
19
  "scripts": {
20
20
  "wisdom": "madrun wisdom",
21
21
  "test": "madrun test",
22
+ "test:check": "madrun test:check",
22
23
  "test:dts": "madrun test:dts",
23
24
  "watch:test": "madrun watch:test",
24
25
  "lint": "madrun lint",
25
26
  "lint:redlint": "madrun lint:redlint",
26
27
  "lint:putout": "madrun lint:putout",
27
- "fresh:lint": "madrun fresh:lint",
28
- "lint:fresh": "madrun lint:fresh",
28
+ "fresh": "madrun fresh",
29
29
  "fix:lint": "madrun fix:lint",
30
- "fix:lint:putout": "madrun fix:lint:putout",
31
30
  "fix:lint:redlint": "madrun fix:lint:redlint",
31
+ "fix:lint:putout": "madrun fix:lint:putout",
32
32
  "coverage": "madrun coverage",
33
33
  "coverage:html": "madrun coverage:html",
34
34
  "report": "madrun report"
@@ -64,7 +64,8 @@
64
64
  "#print-params": "./lib/tokenize/expressions/function/params.js",
65
65
  "#import-attributes": "./lib/tokenize/statements/import-declaration/import-attribute.js",
66
66
  "#types": "./lib/types.js",
67
- "#type-checker": "./lib/tokenize/type-checker/type-checker.js"
67
+ "#type-checker": "./lib/tokenize/type-checker/type-checker.js",
68
+ "#type-checker/instrument": "./lib/tokenize/type-checker/instrument.js"
68
69
  },
69
70
  "devDependencies": {
70
71
  "@babel/parser": "^7.28.5",
@@ -76,6 +77,7 @@
76
77
  "@putout/plugin-react-hook-form": "^6.0.0",
77
78
  "@putout/plugin-react-hooks": "^9.0.0",
78
79
  "acorn": "^8.8.2",
80
+ "chalk": "^5.6.2",
79
81
  "check-dts": "^0.9.0",
80
82
  "escover": "^6.0.0",
81
83
  "eslint": "^10.0.0",