Skip to content

Commit

Permalink
fix(jsx): enable Fragment (#1412)
Browse files Browse the repository at this point in the history
* fix(jsx): enable `Fragment`

* denoify
  • Loading branch information
yusukebe authored Sep 5, 2023
1 parent 405ec8c commit 3351e9d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
12 changes: 12 additions & 0 deletions deno_dist/jsx/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { html } from '../helper/html/index.ts'
import { Hono } from '../hono.ts'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { jsx, memo, Fragment } from './index.ts'

interface SiteData {
Expand Down Expand Up @@ -364,6 +366,16 @@ describe('Fragment', () => {
expect(template.toString()).toBe('<p>1</p><p>2</p>')
})

it('Should render children - with `Fragment`', () => {
const template = (
<Fragment>
<p>1</p>
<p>2</p>
</Fragment>
)
expect(template.toString()).toBe('<p>1</p><p>2</p>')
})

it('Should render nothing for empty Fragment', () => {
const template = <></>
expect(template.toString()).toBe('')
Expand Down
4 changes: 2 additions & 2 deletions deno_dist/jsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,6 @@ export const memo = <T>(
}) as FC<T>
}

export const Fragment = (props: { key?: string; children?: Child[] }): JSXNode => {
return new JSXFragmentNode('', {}, props.children || [])
export const Fragment = (props: { key?: string; children?: Child[] }): HtmlEscapedString => {
return new JSXFragmentNode('', {}, props.children || []) as never
}
12 changes: 12 additions & 0 deletions src/jsx/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { html } from '../helper/html'
import { Hono } from '../hono'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { jsx, memo, Fragment } from './index'

interface SiteData {
Expand Down Expand Up @@ -364,6 +366,16 @@ describe('Fragment', () => {
expect(template.toString()).toBe('<p>1</p><p>2</p>')
})

it('Should render children - with `Fragment`', () => {
const template = (
<Fragment>
<p>1</p>
<p>2</p>
</Fragment>
)
expect(template.toString()).toBe('<p>1</p><p>2</p>')
})

it('Should render nothing for empty Fragment', () => {
const template = <></>
expect(template.toString()).toBe('')
Expand Down
4 changes: 2 additions & 2 deletions src/jsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,6 @@ export const memo = <T>(
}) as FC<T>
}

export const Fragment = (props: { key?: string; children?: Child[] }): JSXNode => {
return new JSXFragmentNode('', {}, props.children || [])
export const Fragment = (props: { key?: string; children?: Child[] }): HtmlEscapedString => {
return new JSXFragmentNode('', {}, props.children || []) as never
}

0 comments on commit 3351e9d

Please sign in to comment.