Skip to content
Myr

Skip closing tag if it is an empty element (#378)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* skip closing tag if it is an empty element * Format code * Empty elements are closed by '/>'

authored by TANIGUCHI Masaya · committed by GitHub · parent 8e9282e · Browse files · 2 files+27 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+27 added−1 removed

  • tests:+5 added−0 removed
  • other:+22 added−1 removed

2 files+27 added−1 removed

modified:src/middleware/jsx/index.test.tsx+5 added
modified:src/middleware/jsx/index.ts+22 added-1 removed
8 unmodified lines
9 }10 }11}1213const emptyTags = [14 'area',15 'base',16 'br',17 'col',18 'embed',19 'hr',20 'img',21 'input',22 'keygen',23 'link',24 'meta',25 'param',26 'source',27 'track',28 'wbr',29]3031export const jsx = (32 tag: string | Function,33 props: Record<string, any>,34 ...children: (string | HtmlEscapedString)[]
23 unmodified lines
58 result += ` ${propsKeys[i]}="${escape(v.toString())}"`59 }6061 if (tag !== '') {62 if (emptyTags.includes(tag)) {63 result += '/'64 }65 result += '>'66 }6768 const flattenChildren = children.flat(Infinity)
7 unmodified lines
76 result += escape(child.toString())77 }78 }7959 if (tag !== '') {80 if (tag !== '' && !emptyTags.includes(tag)) {81 result += `</${tag}>`82 }8384 const escapedString = new String(result) as HtmlEscapedString
45 unmodified lines