Skip to content

Commit f3abee7

Browse files
authored
feat(runtime): add jsx Fragment (#2647)
1 parent d6eabb9 commit f3abee7

File tree

7 files changed

+16
-0
lines changed

7 files changed

+16
-0
lines changed

src/compiler/sys/typescript/typescript-config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ const createDefaultTsConfig = (config: d.Config) =>
146146
target: 'es2017',
147147
jsx: 'react',
148148
jsxFactory: 'h',
149+
jsxFragmentFactory: 'Fragment'
149150
},
150151
include: [relative(config.rootDir, config.srcDir)],
151152
},

src/compiler/transformers/test/transpile.ts

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export function transpileModule(
4040

4141
options.jsx = ts.JsxEmit.React;
4242
options.jsxFactory = 'h';
43+
options.jsxFragmentFactory = 'Fragment';
4344

4445
const inputFileName = 'module.tsx';
4546
const sourceFile = ts.createSourceFile(inputFileName, input, options.target);

src/compiler/transformers/update-stencil-core-import.ts

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const KEEP_IMPORTS = new Set([
6262
'getMode',
6363
'Build',
6464
'Host',
65+
'Fragment',
6566
'getAssetPath',
6667
'writeTask',
6768
'readTask',

src/compiler/transpile/transpile-module.ts

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ export const transpileModule = (config: d.Config, input: string, transformOpts:
5959
tsCompilerOptions.jsxFactory = 'h';
6060
}
6161

62+
if (tsCompilerOptions.jsxFragmentFactory != null && !isString(tsCompilerOptions.jsxFragmentFactory)) {
63+
tsCompilerOptions.jsxFragmentFactory = 'Fragment';
64+
}
65+
6266
if (tsCompilerOptions.paths && !isString(tsCompilerOptions.baseUrl)) {
6367
tsCompilerOptions.baseUrl = '.';
6468
}

src/declarations/stencil-public-runtime.ts

+5
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,11 @@ export interface ChildNode {
481481
*/
482482
export declare const Host: FunctionalComponent<HostAttributes>;
483483

484+
/**
485+
* Fragment
486+
*/
487+
export declare const Fragment: FunctionalComponent<{}>;
488+
484489
/**
485490
* The "h" namespace is used to import JSX types for elements and attributes.
486491
* It is imported in order to avoid conflicting global JSX issues.

src/runtime/fragment.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { FunctionalComponent } from '../declarations/stencil-public-runtime';
2+
3+
export const Fragment: FunctionalComponent = (_, children: any) => children;

src/runtime/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ export { forceUpdate, postUpdateComponent, getRenderingRef } from './update-comp
1616
export { proxyComponent } from './proxy-component';
1717
export { renderVdom } from './vdom/vdom-render';
1818
export { setMode, getMode } from './mode';
19+
export { Fragment } from './fragment';

0 commit comments

Comments
 (0)