Skip to content

Commit

Permalink
Vite Support!
Browse files Browse the repository at this point in the history
Now it works in dev and prod! The types are a bit wack still though, they need to support strings, and non-`Node[]` types, since it doesn't always have to be an array of elements.
  • Loading branch information
Offroaders123 committed Nov 20, 2023
1 parent 99a275d commit cc01856
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 2 additions & 4 deletions jsx/src/jsx-dev-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ export * from "./jsx-runtime.js";
import { JSX, jsx } from "./jsx-runtime.js";

export function jsxDEV<K extends keyof JSX.IntrinsicElements>(tagName: K, attributes: JSX.IntrinsicElementsTagNameMap[K] & { children?: Node[]; } | null, _key: unknown, _isStaticChildren: boolean, _source: { fileName: string; lineNumber: number; columnNumber: number; }, _self: JSX.IntrinsicElementsTagNameMap[K]): JSX.IntrinsicElementsTagNameMap[K] {
const children: Node[] = attributes?.children ?? [] as Node[];
delete attributes?.children;
console.log(tagName,attributes,_key,_isStaticChildren,_source,_self);
return jsx(tagName,attributes,...(Array.isArray(children) ? children : [children]));
// console.log(tagName,attributes,_key,_isStaticChildren,_source,_self);
return jsx(tagName,attributes);
}
8 changes: 5 additions & 3 deletions jsx/src/jsx-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ export namespace JSX {
}
}

export function jsx<K extends keyof JSX.IntrinsicElements>(tagName: K, attributes?: JSX.IntrinsicElementsTagNameMap[K] | null, ...children: Node[]): JSX.IntrinsicElementsTagNameMap[K] {
export function jsx<K extends keyof JSX.IntrinsicElements>(tagName: K, attributes?: JSX.IntrinsicElementsTagNameMap[K] & { children?: Node[]; } | null): JSX.IntrinsicElementsTagNameMap[K] {
const element = document.createElement(tagName);
console.log(children);
const children: Node[] = attributes?.children ?? [] as Node[];
delete attributes?.children;
console.log(tagName,attributes,children);

if (attributes !== null && attributes !== undefined){
Object.assign(element,attributes);
}

element.append(...children);
element.append(...(Array.isArray(children) ? children : [children]));

return element;
}

0 comments on commit cc01856

Please sign in to comment.