From 76f7569ff02ee94bad848dca7baa468c788e40ab Mon Sep 17 00:00:00 2001 From: bluelovers Date: Wed, 17 Nov 2021 22:08:55 +0800 Subject: [PATCH] feat: support typescript jsxFragmentFactory https://github.com/developit/vhtml/issues/31 ```json "jsxFragmentFactory": "Fragment", ``` or ```json "jsxFactory": "vhtml", "jsxFragmentFactory": "vhtml.Fragment", ``` --- ```ts import h, { Fragment } from 'vhtml'; ``` --- src/vhtml.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/vhtml.js b/src/vhtml.js index 0e03f69..7ce7a4c 100644 --- a/src/vhtml.js +++ b/src/vhtml.js @@ -11,8 +11,10 @@ let DOMAttributeNames = { let sanitized = {}; +export const Fragment = ({ children }: { children: string[] }) => h(null as any, null, ...children); + /** Hyperscript reviver that constructs a sanitized HTML string. */ -export default function h(name, attrs) { +function h(name, attrs) { let stack=[], s = ''; attrs = attrs || {}; for (let i=arguments.length; i-- > 2; ) { @@ -58,3 +60,7 @@ export default function h(name, attrs) { sanitized[s] = true; return s; } + +h.Fragment = Fragment; + +export default h