Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vanjs-jsx fixes #329

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions addons/van_jsx/src/createElement.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import van from "vanjs-core";
import { setAttribute } from "./hyper";
const createElement = (jsxTag, { children, style, ref, ...props }) => {
const createElement = (jsxTag, allProps) => {
if (typeof jsxTag === "string") {
const { children, ref, ...props } = allProps
// TODO VanNode to VanElement
const ele = van.tags[jsxTag](children);
for (const [key, value] of Object.entries(props ?? {})) {
Expand All @@ -27,7 +28,7 @@ const createElement = (jsxTag, { children, style, ref, ...props }) => {
return ele;
}
if (typeof jsxTag === "function") {
return jsxTag({ ...props, ref, style, children });
return jsxTag(allProps);
}
};
export default createElement;
3 changes: 2 additions & 1 deletion addons/van_jsx/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import { State, StateView } from "vanjs-core";
export declare function createState<T>(initialValue: T): State<T>;
export declare function createState<T>(initialValue: T | null): StateView<T>;
export declare function createState<T = undefined>(): State<T | undefined>;
export { default as createElement, default as jsx, default as jsxDEV, } from "./createElement";
export declare function Fragment({ children }: { children?: VanNode | undefined }): VanNode | [VanNode] | undefined;
export { default as createElement, default as jsx, default as jsxs, default as jsxDEV, } from "./createElement";
export * from "./type";
5 changes: 4 additions & 1 deletion addons/van_jsx/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ import van from "vanjs-core";
export function createState(v) {
return van.state(v);
}
export { default as createElement, default as jsx, default as jsxDEV, } from "./createElement";
export function Fragment({children}) {
return children;
}
export { default as createElement, default as jsx, default as jsxs, default as jsxDEV, } from "./createElement";
1 change: 1 addition & 0 deletions addons/van_jsx/src/jsx-runtime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./index";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be fixed by adjusting the configuration of package.json.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this file may cause the vscode editor's smart import to carry a special path.

For example

import {} from "van_jsx/jsx_runtime";