(path, options, print)
| 219 | } |
| 220 | |
| 221 | function printAttributes(path, options, print) { |
| 222 | const { node } = path; |
| 223 | |
| 224 | const { attrs: attributes = [], startTagComments = [] } = node; |
| 225 | |
| 226 | if (attributes.length === 0 && startTagComments.length === 0) { |
| 227 | return node.isSelfClosing |
| 228 | ? /** |
| 229 | * <br /> |
| 230 | * ^ |
| 231 | */ |
| 232 | " " |
| 233 | : ""; |
| 234 | } |
| 235 | |
| 236 | const ignoreAttributeData = |
| 237 | node.prev?.kind === "comment" && |
| 238 | getPrettierIgnoreAttributeCommentData(node.prev.value); |
| 239 | |
| 240 | const hasPrettierIgnoreAttribute = |
| 241 | typeof ignoreAttributeData === "boolean" |
| 242 | ? () => ignoreAttributeData |
| 243 | : Array.isArray(ignoreAttributeData) |
| 244 | ? (attribute) => ignoreAttributeData.includes(attribute.rawName) |
| 245 | : () => false; |
| 246 | |
| 247 | const properties = ["attrs", "startTagComments"].filter((property) => |
| 248 | isNonEmptyArray(node[property]), |
| 249 | ); |
| 250 | const printedAttributes = properties.flatMap((property) => |
| 251 | path.map( |
| 252 | ({ node }) => ({ |
| 253 | loc: locStart(node), |
| 254 | printed: |
| 255 | node.kind === "attribute" && hasPrettierIgnoreAttribute(node) |
| 256 | ? replaceEndOfLine( |
| 257 | options.originalText.slice(locStart(node), locEnd(node)), |
| 258 | ) |
| 259 | : print(), |
| 260 | }), |
| 261 | property, |
| 262 | ), |
| 263 | ); |
| 264 | |
| 265 | if (properties.length > 1) { |
| 266 | printedAttributes.sort((a, b) => a.loc - b.loc); |
| 267 | } |
| 268 | |
| 269 | const forceNotToBreakAttrContent = |
| 270 | node.kind === "element" && |
| 271 | node.fullName === "script" && |
| 272 | attributes.length === 1 && |
| 273 | attributes[0].fullName === "src" && |
| 274 | node.children.length === 0 && |
| 275 | startTagComments.length === 0; |
| 276 | const shouldForceBreak = startTagComments.some( |
| 277 | (comment) => comment.type === "single", |
| 278 | ); |
no test coverage detected
searching dependent graphs…