fix: support number elements in jsx templates
This commit is contained in:
parent
5dfd2fd053
commit
1372ce16cb
3 changed files with 16 additions and 1 deletions
|
|
@ -25,7 +25,13 @@ export interface HTMLElement {
|
|||
/**
|
||||
* All valid types of elements that can be rendered to HTML.
|
||||
*/
|
||||
export type Element = HTMLElement | string | boolean | undefined | null;
|
||||
export type Element =
|
||||
| HTMLElement
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| undefined
|
||||
| null;
|
||||
|
||||
/**
|
||||
* Custom HTMLElement factory that can be parameterized by props.
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ const renderElement = (elem: Element): string => {
|
|||
if (elem == null || typeof elem === "boolean") {
|
||||
return "";
|
||||
}
|
||||
if (typeof elem === "number") {
|
||||
return elem.toString();
|
||||
}
|
||||
if (typeof elem === "string") {
|
||||
return escapeHtml(elem);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,4 +61,10 @@ testSuite("renderPage", ({ test, expect }) => {
|
|||
"<!DOCTYPE html><html>There are three lights!</html>"
|
||||
);
|
||||
});
|
||||
|
||||
test("renders spliced number nodes", () => {
|
||||
const nLights = 3;
|
||||
const html = renderPage(<html>There are {nLights} lights!</html>);
|
||||
expect(html).toEqual("<!DOCTYPE html><html>There are 3 lights!</html>");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue