(path, options, print)
| 35 | // https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/syntax/lib/generation/print.ts |
| 36 | |
| 37 | function 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), |
no test coverage detected
searching dependent graphs…