@putout/printer 18.50.6 → 18.52.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 +10 -0
- package/lib/tokenize/comments/comments-printer/comments-printer.js +5 -3
- package/lib/tokenize/comments/comments-printer/print-comment-block.js +38 -0
- package/lib/tokenize/literals/string-literal/string-literal.js +17 -1
- package/lib/tokenize/type-checker/instrument.d.ts +1 -0
- package/lib/tokenize/type-checker/instrument.js +3 -2
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import {printCommentBlock} from './print-comment-block.js';
|
|
2
|
+
|
|
1
3
|
const createPrintCommentLine = (fn, value) => () => fn(`//${value}`);
|
|
2
|
-
const createPrintCommentBlock = (
|
|
4
|
+
const createPrintCommentBlock = (printer, value) => () => printCommentBlock(value, printer, '\n');
|
|
3
5
|
|
|
4
6
|
const isCommentBlock = (node) => node.type === 'CommentBlock';
|
|
5
7
|
const isCommentLine = (node) => node.type === 'CommentLine';
|
|
@@ -65,7 +67,7 @@ export const printLeadingComments = (path, printer, semantics, {currentTraverse}
|
|
|
65
67
|
if (isCommentBlock(comment))
|
|
66
68
|
printLeadingCommentBlock?.(path, printer, semantics, {
|
|
67
69
|
index,
|
|
68
|
-
printComment: createPrintCommentBlock(
|
|
70
|
+
printComment: createPrintCommentBlock(printer, value),
|
|
69
71
|
});
|
|
70
72
|
}
|
|
71
73
|
};
|
|
@@ -99,7 +101,7 @@ export const printTrailingComments = (path, printer, semantics, {currentTraverse
|
|
|
99
101
|
if (isCommentBlock(comment))
|
|
100
102
|
printTrailingCommentBlock?.(path, printer, semantics, {
|
|
101
103
|
index,
|
|
102
|
-
printComment: createPrintCommentBlock(
|
|
104
|
+
printComment: createPrintCommentBlock(printer, value),
|
|
103
105
|
isLast: index === n,
|
|
104
106
|
isSameLine: isSameLine(path, loc),
|
|
105
107
|
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const isStarLine = (line) => line
|
|
2
|
+
.trim()
|
|
3
|
+
.startsWith('*');
|
|
4
|
+
|
|
5
|
+
const isBlank = (line) => !line.trim();
|
|
6
|
+
|
|
7
|
+
export const printCommentBlock = (value, {print, indent}, end = '') => {
|
|
8
|
+
const [first, ...rest] = value.split('\n');
|
|
9
|
+
|
|
10
|
+
if (!rest.length || !indent.getLevel()) {
|
|
11
|
+
print(`/*${value}*/${end}`);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const last = rest.at(-1);
|
|
16
|
+
const lines = isBlank(last) ? rest.slice(0, -1) : rest;
|
|
17
|
+
|
|
18
|
+
if (!lines.every(isStarLine)) {
|
|
19
|
+
print(`/*${value}*/${end}`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
print(`/*${first}`);
|
|
24
|
+
|
|
25
|
+
for (const line of lines) {
|
|
26
|
+
print.breakline();
|
|
27
|
+
|
|
28
|
+
print(` ${line.trimStart()}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (isBlank(last)) {
|
|
32
|
+
print.breakline();
|
|
33
|
+
|
|
34
|
+
print(' ');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
print(`*/${end}`);
|
|
38
|
+
};
|
|
@@ -1,5 +1,21 @@
|
|
|
1
|
+
const {stringify} = JSON;
|
|
2
|
+
const escapeValue = (value) => stringify(value)
|
|
3
|
+
.slice(1, -1)
|
|
4
|
+
.replaceAll(`'`, `\\'`);
|
|
5
|
+
|
|
6
|
+
const getRaw = ({value, raw, extra}) => {
|
|
7
|
+
if (raw)
|
|
8
|
+
return raw;
|
|
9
|
+
|
|
10
|
+
if (extra?.raw && extra.rawValue === value)
|
|
11
|
+
return extra.raw;
|
|
12
|
+
|
|
13
|
+
return `'${escapeValue(value)}'`;
|
|
14
|
+
};
|
|
15
|
+
|
|
1
16
|
export const StringLiteral = (path, {write}, semantics) => {
|
|
2
|
-
const {value
|
|
17
|
+
const {value} = path.node;
|
|
18
|
+
const raw = getRaw(path.node);
|
|
3
19
|
|
|
4
20
|
if (path.parentPath.isJSXAttribute()) {
|
|
5
21
|
write(`"${value}"`);
|
|
@@ -2,7 +2,7 @@ import {env as _env} from 'node:process';
|
|
|
2
2
|
|
|
3
3
|
const STACK_INDEX = 3;
|
|
4
4
|
|
|
5
|
-
const parseCallLocation = ({stack}) => stack.split('\n')[
|
|
5
|
+
const parseCallLocation = ({stack}, stackIndex) => stack.split('\n')[stackIndex];
|
|
6
6
|
|
|
7
7
|
const Coverage = new Map();
|
|
8
8
|
|
|
@@ -11,10 +11,11 @@ export const instrument = (typeNames, fn, overrides = {}) => {
|
|
|
11
11
|
env = _env,
|
|
12
12
|
coverage = Coverage,
|
|
13
13
|
instrumentName = 'TYPE_CHECK',
|
|
14
|
+
stackIndex = STACK_INDEX,
|
|
14
15
|
} = overrides;
|
|
15
16
|
|
|
16
17
|
const error = Error();
|
|
17
|
-
const location = parseCallLocation(error);
|
|
18
|
+
const location = parseCallLocation(error, stackIndex);
|
|
18
19
|
const on = env[instrumentName];
|
|
19
20
|
const covered = new Set();
|
|
20
21
|
|
package/package.json
CHANGED