@type {BuildVisitor }
(node, index, parent)
| 357 | |
| 358 | /** @type {BuildVisitor<Root>} */ |
| 359 | function transform(node, index, parent) { |
| 360 | if (node.type === 'raw' && parent && typeof index === 'number') { |
| 361 | if (skipHtml) { |
| 362 | parent.children.splice(index, 1) |
| 363 | } else { |
| 364 | parent.children[index] = {type: 'text', value: node.value} |
| 365 | } |
| 366 | |
| 367 | return index |
| 368 | } |
| 369 | |
| 370 | if (node.type === 'element') { |
| 371 | /** @type {string} */ |
| 372 | let key |
| 373 | |
| 374 | for (key in urlAttributes) { |
| 375 | if ( |
| 376 | Object.hasOwn(urlAttributes, key) && |
| 377 | Object.hasOwn(node.properties, key) |
| 378 | ) { |
| 379 | const value = node.properties[key] |
| 380 | const test = urlAttributes[key] |
| 381 | if (test === null || test.includes(node.tagName)) { |
| 382 | node.properties[key] = urlTransform(String(value || ''), key, node) |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | if (node.type === 'element') { |
| 389 | let remove = allowedElements |
| 390 | ? !allowedElements.includes(node.tagName) |
| 391 | : disallowedElements |
| 392 | ? disallowedElements.includes(node.tagName) |
| 393 | : false |
| 394 | |
| 395 | if (!remove && allowElement && typeof index === 'number') { |
| 396 | remove = !allowElement(node, index, parent) |
| 397 | } |
| 398 | |
| 399 | if (remove && parent && typeof index === 'number') { |
| 400 | if (unwrapDisallowed && node.children) { |
| 401 | parent.children.splice(index, 1, ...node.children) |
| 402 | } else { |
| 403 | parent.children.splice(index, 1) |
| 404 | } |
| 405 | |
| 406 | return index |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | /** |
no outgoing calls
no test coverage detected
searching dependent graphs…