Skip to content

Commit 6482533

Browse files
johnjenkinsJohn Jenkins
andauthored
feat(runtime): support tsconfig jsxImportSource (h import no longer necessary) (#6525)
* feat(runtime): support tsconfig `jsxImportSource` (meaning `h` import no longer necessary) * chore: --------- Co-authored-by: John Jenkins <john.jenkins@nanoporetech.com>
1 parent 42ebdfa commit 6482533

File tree

12 files changed

+236
-1
lines changed

12 files changed

+236
-1
lines changed

cspell-wordlist.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,6 @@ xlink
150150
yourpackage
151151
fdir
152152
shadowrootmode
153-
shadowrootdelegatesfocus
153+
shadowrootdelegatesfocus
154+
jsxmode
155+
jsxdev

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
"import": "./internal/stencil-core/index.js",
2929
"require": "./internal/stencil-core/index.cjs"
3030
},
31+
"./jsx-runtime": {
32+
"types": "./internal/stencil-core/jsx-runtime.d.ts",
33+
"import": "./internal/stencil-core/jsx-runtime.js",
34+
"require": "./internal/stencil-core/jsx-runtime.cjs"
35+
},
36+
"./jsx-dev-runtime": {
37+
"types": "./internal/stencil-core/jsx-dev-runtime.d.ts",
38+
"import": "./internal/stencil-core/jsx-dev-runtime.js",
39+
"require": "./internal/stencil-core/jsx-dev-runtime.cjs"
40+
},
3141
"./cli": {
3242
"import": "./cli/index.js",
3343
"require": "./cli/index.cjs"

src/declarations/stencil-public-runtime.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,45 @@ export declare function h(sel: any, text: string): VNode;
772772
export declare function h(sel: any, children: Array<VNode | undefined | null>): VNode;
773773
export declare function h(sel: any, data: VNodeData | null, text: string): VNode;
774774
export declare function h(sel: any, data: VNodeData | null, children: Array<VNode | undefined | null>): VNode;
775+
776+
/**
777+
* Automatic JSX runtime functions for TypeScript's react-jsx mode.
778+
* These functions are called automatically by TypeScript when using "jsx": "react-jsx".
779+
* @param type type of node
780+
* @param props properties of node
781+
* @param key optional key for the node
782+
* @returns a jsx vnode
783+
*/
784+
export declare function jsx(type: any, props: any, key?: string): VNode;
785+
786+
/**
787+
* Automatic JSX runtime functions for TypeScript's react-jsxmode with multiple children.
788+
* @param type type of node
789+
* @param props properties of node
790+
* @param key optional key for the node
791+
* @returns a jsx vnode
792+
*/
793+
export declare function jsxs(type: any, props: any, key?: string): VNode;
794+
795+
/**
796+
* Automatic JSX runtime functions for TypeScript's react-jsxdev mode.
797+
* These functions are called automatically by TypeScript when using "jsx": "react-jsxdev".
798+
* @param type type of node
799+
* @param props properties of node
800+
* @param key optional key for the node
801+
* @param isStaticChildren indicates if the children are static
802+
* @param source source information
803+
* @param self reference to the component instance
804+
* @returns a jsx vnode
805+
*/
806+
export declare function jsxDEV(
807+
type: any,
808+
props: any,
809+
key?: string | number,
810+
isStaticChildren?: boolean,
811+
source?: any,
812+
self?: any,
813+
): VNode;
775814
export declare function h(sel: any, data: VNodeData | null, children: VNode): VNode;
776815

777816
/**
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Export automatic JSX development runtime (CommonJS)
2+
// Note: This requires the client platform to be built
3+
const client = require('../client/index.js');
4+
module.exports = {
5+
jsxDEV: client.jsxDEV,
6+
Fragment: client.Fragment,
7+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Automatic JSX Development Runtime type definitions for Stencil
3+
*
4+
* This module provides TypeScript type definitions for the automatic JSX development runtime.
5+
* When using "jsx": "react-jsxdev" in tsconfig.json with "jsxImportSource": "@stencil/core",
6+
* TypeScript will automatically import from this module in development mode.
7+
*/
8+
9+
import type { VNode } from '../stencil-public-runtime';
10+
11+
export { Fragment } from '../stencil-public-runtime';
12+
13+
/**
14+
* JSX development runtime function for creating elements with debug info.
15+
*/
16+
export function jsxDEV(
17+
type: any,
18+
props: any,
19+
key?: string | number,
20+
isStaticChildren?: boolean,
21+
source?: any,
22+
self?: any,
23+
): VNode;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Re-export from the client platform (same pattern as index.js)
2+
export { jsxDEV, Fragment } from '../client/index.js';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Export automatic JSX runtime (CommonJS)
2+
// Note: This requires the client platform to be built
3+
const client = require('../client/index.js');
4+
module.exports = {
5+
jsx: client.jsx,
6+
jsxs: client.jsxs,
7+
Fragment: client.Fragment,
8+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Automatic JSX Runtime type definitions for Stencil
3+
*
4+
* This module provides TypeScript type definitions for the automatic JSX runtime.
5+
* When using "jsx": "react-jsx" or "jsx": "react-jsxdev" in tsconfig.json with
6+
* "jsxImportSource": "@stencil/core", TypeScript will automatically import from
7+
* these modules instead of requiring manual `h` imports.
8+
*/
9+
10+
import type { VNode } from '../stencil-public-runtime';
11+
12+
export { Fragment } from '../stencil-public-runtime';
13+
14+
/**
15+
* JSX runtime function for creating elements in production mode.
16+
*/
17+
export function jsx(type: any, props: any, key?: string): VNode;
18+
19+
/**
20+
* JSX runtime function for creating elements with static children.
21+
*/
22+
export function jsxs(type: any, props: any, key?: string): VNode;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Re-export from the client platform (same pattern as index.js)
2+
export { jsx, jsxs, Fragment } from '../client/index.js';

src/runtime/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ export { getValue, setValue } from './set-value';
1919
export { setTagTransformer, transformTag } from './tag-transform';
2020
export { forceUpdate, getRenderingRef, postUpdateComponent } from './update-component';
2121
export { h, Host } from './vdom/h';
22+
export { jsxDEV } from './vdom/jsx-dev-runtime';
23+
export { jsx, jsxs } from './vdom/jsx-runtime';
2224
export { insertVdomAnnotations } from './vdom/vdom-annotations';
2325
export { renderVdom } from './vdom/vdom-render';

0 commit comments

Comments
 (0)