(textToDoc, print, path, options)
| 6 | import { hasLanguageComment } from "./utilities.js"; |
| 7 | |
| 8 | async function printEmbedGraphQL(textToDoc, print, path, options) { |
| 9 | const { node } = path; |
| 10 | |
| 11 | const numQuasis = node.quasis.length; |
| 12 | |
| 13 | const expressionDocs = printTemplateExpressions(path, options, print); |
| 14 | const parts = []; |
| 15 | |
| 16 | for (let i = 0; i < numQuasis; i++) { |
| 17 | const templateElement = node.quasis[i]; |
| 18 | const isFirst = i === 0; |
| 19 | const isLast = i === numQuasis - 1; |
| 20 | const text = templateElement.value.cooked; |
| 21 | |
| 22 | const lines = text.split("\n"); |
| 23 | const numLines = lines.length; |
| 24 | |
| 25 | // Bail out if an interpolation occurs within a comment. |
| 26 | if (!isLast && /#[^\n\r]*$/.test(lines[numLines - 1])) { |
| 27 | return null; |
| 28 | } |
| 29 | |
| 30 | const startsWithBlankLine = |
| 31 | numLines > 2 && lines[0].trim() === "" && lines[1].trim() === ""; |
| 32 | const endsWithBlankLine = |
| 33 | numLines > 2 && |
| 34 | lines[numLines - 1].trim() === "" && |
| 35 | lines[numLines - 2].trim() === ""; |
| 36 | |
| 37 | const commentsAndWhitespaceOnly = lines.every((line) => |
| 38 | /^\s*(?:#[^\n\r]*)?$/.test(line), |
| 39 | ); |
| 40 | |
| 41 | let doc; |
| 42 | |
| 43 | if (commentsAndWhitespaceOnly) { |
| 44 | doc = printGraphqlComments(lines); |
| 45 | } else { |
| 46 | doc = await textToDoc(text, { parser: "graphql" }); |
| 47 | } |
| 48 | |
| 49 | if (doc) { |
| 50 | doc = escapeTemplateCharacters(doc, false); |
| 51 | if (!isFirst && startsWithBlankLine) { |
| 52 | parts.push(""); |
| 53 | } |
| 54 | parts.push(doc); |
| 55 | if (!isLast && endsWithBlankLine) { |
| 56 | parts.push(""); |
| 57 | } |
| 58 | } else if (!isFirst && !isLast && startsWithBlankLine) { |
| 59 | parts.push(""); |
| 60 | } |
| 61 | |
| 62 | if (!isLast) { |
| 63 | parts.push(expressionDocs[i]); |
| 64 | } |
| 65 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…