Skip to content
Myr

feat(middleware/jsx): We need Fragment. (#310)

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

authored by Taku Amano · committed by GitHub · parent cfc8c6e · Browse files · 3 files+37 added−6 removed
This commit

State

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

Diff stats

3 files+37 added−6 removed

  • tests:+25 added−3 removed
  • other:+12 added−3 removed

3 files+37 added−6 removed

modified:src/middleware/jsx/index.test.tsx+25 added-3 removed
modified:src/middleware/jsx/index.ts+11 added-3 removed
30 unmodified lines
31 if (typeof tag === 'function') {32 return tag.call(null, { ...props, children: children.length <= 1 ? children[0] : children })33 }3435 let result = `<${tag}`35 let result = tag !== '' ? `<${tag}` : ''3637 const propsKeys = Object.keys(props || {})38 for (let i = 0, len = propsKeys.length; i < len; i++) {39 const v = props[propsKeys[i]]
12 unmodified lines
5253 result += ` ${propsKeys[i]}="${escape(v.toString())}"`54 }5556 if (tag !== '') {56 result += '>'57 result += '>'58 }5960 const flattenChildren = children.flat(Infinity)61 for (let i = 0, len = flattenChildren.length; i < len; i++) {62 const child = flattenChildren[i]
5 unmodified lines
68 result += escape(child.toString())69 }70 }7172 if (tag !== '') {70 result += `</${tag}>`73 result += `</${tag}>`74 }7576 const escapedString = new String(result) as EscapedString77 escapedString.isEscaped = true78
35 unmodified lines
114 prevProps = props115 return (computed ||= component(props))116 }) as FC<T>117}118119export const Fragment = (props: { key?: string; children?: any }): EscapedString => {120 return h('', {}, ...(props.children || []))121}
modified:tsconfig.json+1 added
18 unmodified lines
19 "@cloudflare/workers-types"20 ],21 "jsx": "react",22 "jsxFactory": "h",23 "jsxFragmentFactory": "Fragment",24 },25 "include": [26 "src/**/*.ts",27 "src/**/*.mts",
3 unmodified lines