( key: string, value: unknown, tag?: string, )
| 61 | |
| 62 | // render an attr with dynamic (unknown) key. |
| 63 | export function ssrRenderDynamicAttr( |
| 64 | key: string, |
| 65 | value: unknown, |
| 66 | tag?: string, |
| 67 | ): string { |
| 68 | if (!isRenderableAttrValue(value)) { |
| 69 | return `` |
| 70 | } |
| 71 | const attrKey = |
| 72 | tag && (tag.indexOf('-') > 0 || isSVGTag(tag)) |
| 73 | ? key // preserve raw name on custom elements and svg |
| 74 | : propsToAttrMap[key] || key.toLowerCase() |
| 75 | if (isBooleanAttr(attrKey)) { |
| 76 | return includeBooleanAttr(value) ? ` ${attrKey}` : `` |
| 77 | } else if (isSSRSafeAttrName(attrKey)) { |
| 78 | return value === '' ? ` ${attrKey}` : ` ${attrKey}="${escapeHtml(value)}"` |
| 79 | } else { |
| 80 | console.warn( |
| 81 | `[@vue/server-renderer] Skipped rendering unsafe attribute name: ${attrKey}`, |
| 82 | ) |
| 83 | return `` |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | // Render a v-bind attr with static key. The key is pre-processed at compile |
| 88 | // time and we only need to check and escape value. |
no test coverage detected