MCPcopy
hub / github.com/prettier/prettier / print

Function print

src/language-handlebars/printer-glimmer.js:37–420  ·  view source on GitHub ↗
(path, options, print)

Source from the content-addressed store, hash-verified

35// https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/syntax/lib/generation/print.ts
36
37function print(path, options, print) {
38 const { node } = path;
39
40 switch (node.type) {
41 case "Block":
42 case "Program":
43 case "Template":
44 return group(path.map(print, "body"));
45
46 case "ElementNode": {
47 const isWhitespaceSensitive =
48 options.htmlWhitespaceSensitivity !== "ignore";
49
50 const startingTag = [
51 !isWhitespaceSensitive && path.previous?.type === "ElementNode"
52 ? softline
53 : "",
54 group([printStartingTag(path, print)]),
55 ];
56
57 if (isVoidElement(node)) {
58 return [startingTag];
59 }
60
61 const endingTag = ["</", node.tag, ">"];
62 const isStyle = node.tag === "style";
63
64 if (
65 node.children.length === 0 ||
66 ((!isWhitespaceSensitive || isStyle) &&
67 node.children.every((node) => isWhitespaceNode(node)))
68 ) {
69 return [startingTag, endingTag];
70 }
71
72 const parts = path.map(print, "children");
73
74 if (isStyle || !isWhitespaceSensitive) {
75 return [startingTag, indent([softline, ...parts]), softline, endingTag];
76 }
77
78 return [startingTag, indent(group(parts)), endingTag];
79 }
80
81 case "BlockStatement":
82 if (isElseIfBlock(path)) {
83 return [
84 printElseIfBlock(path, print),
85 printProgram(path, options, print),
86 printInverse(path, options, print),
87 ];
88 }
89
90 return [
91 printOpenBlock(path, print),
92 group([
93 printProgram(path, options, print),
94 printInverse(path, options, print),

Callers 11

printStartingTagFunction · 0.70
printCloseBlockFunction · 0.70
printProgramFunction · 0.70
printInverseFunction · 0.70
printPathFunction · 0.70
printParamsFunction · 0.70
genericPrintFunction · 0.50
printAttributesFunction · 0.50
printAngularIcuCaseFunction · 0.50
printChildFunction · 0.50

Calls 15

groupFunction · 0.90
isVoidElementFunction · 0.90
isWhitespaceNodeFunction · 0.90
indentFunction · 0.90
locStartFunction · 0.90
locEndFunction · 0.90
getPreferredQuoteFunction · 0.90
joinFunction · 0.90
replaceEndOfLineFunction · 0.90
dedentFunction · 0.90
fillFunction · 0.90
printStartingTagFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…