MCPcopy
hub / github.com/prettier/prettier / formatAttributeValue

Function formatAttributeValue

src/language-html/embed/utilities.js:42–65  ·  view source on GitHub ↗

* @param {string} code * @param {Function} textToDoc * @param {*} options * @param {(ast: any, options: any) => boolean} [shouldHugJsExpression] * @returns {Promise }

(
  code,
  textToDoc,
  options,
  shouldHugJsExpression,
)

Source from the content-addressed store, hash-verified

40 * @returns {Promise<Doc>}
41 */
42async function formatAttributeValue(
43 code,
44 textToDoc,
45 options,
46 shouldHugJsExpression,
47) {
48 options = {
49 // strictly prefer single quote to avoid unnecessary HTML entity escape
50 __isInHtmlAttribute: true,
51 __embeddedInHtml: true,
52 ...options,
53 };
54
55 let shouldHug = true;
56 if (shouldHugJsExpression) {
57 options.__onHtmlBindingRoot = (ast, options) => {
58 shouldHug = shouldHugJsExpression(ast, options);
59 };
60 }
61
62 const doc = await textToDoc(code, options, textToDoc);
63
64 return shouldHug ? group(doc) : printExpand(doc);
65}
66
67export { formatAttributeValue, printExpand, shouldHugJsExpression };

Callers 11

embedFunction · 0.90
printVueVForDirectiveFunction · 0.90
printEventHandlerFunction · 0.90
printVueBindingsFunction · 0.90
createAngularPrinterFunction · 0.90
printVueVOnDirectiveFunction · 0.90
printVueVBindDirectiveFunction · 0.90
printExpressionFunction · 0.90

Calls 4

groupFunction · 0.90
shouldHugJsExpressionFunction · 0.85
textToDocFunction · 0.85
printExpandFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…