forked from OKEAMAH/prettier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
46 lines (41 loc) · 1.28 KB
/
utils.js
File metadata and controls
46 lines (41 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function describeNodeForDebugging(node) {
const nodeType = node.type || node.kind || "(unknown type)";
let nodeName = String(
node.name ||
(node.id && (typeof node.id === "object" ? node.id.name : node.id)) ||
(node.key && (typeof node.key === "object" ? node.key.name : node.key)) ||
(node.value &&
(typeof node.value === "object" ? "" : String(node.value))) ||
node.operator ||
"",
);
if (nodeName.length > 20) {
nodeName = nodeName.slice(0, 19) + "…";
}
return nodeType + (nodeName ? " " + nodeName : "");
}
function addCommentHelper(node, comment) {
const comments = (node.comments ??= []);
comments.push(comment);
comment.printed = false;
comment.nodeDescription = describeNodeForDebugging(node);
}
function addLeadingComment(node, comment) {
comment.leading = true;
comment.trailing = false;
addCommentHelper(node, comment);
}
function addDanglingComment(node, comment, marker) {
comment.leading = false;
comment.trailing = false;
if (marker) {
comment.marker = marker;
}
addCommentHelper(node, comment);
}
function addTrailingComment(node, comment) {
comment.leading = false;
comment.trailing = true;
addCommentHelper(node, comment);
}
export { addDanglingComment, addLeadingComment, addTrailingComment };