* @param {string} code * @param {Function} textToDoc * @param {*} options * @param {(ast: any, options: any) => boolean} [shouldHugJsExpression] * @returns {Promise }
( code, textToDoc, options, shouldHugJsExpression, )
| 40 | * @returns {Promise<Doc>} |
| 41 | */ |
| 42 | async 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 | |
| 67 | export { formatAttributeValue, printExpand, shouldHugJsExpression }; |
no test coverage detected
searching dependent graphs…