Skip to content

Commit

Permalink
feat(runtime): add jsx Fragment (#2647)
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Aug 24, 2020
1 parent d6eabb9 commit f3abee7
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/compiler/sys/typescript/typescript-config.ts
Expand Up @@ -146,6 +146,7 @@ const createDefaultTsConfig = (config: d.Config) =>
target: 'es2017',
jsx: 'react',
jsxFactory: 'h',
jsxFragmentFactory: 'Fragment'
},
include: [relative(config.rootDir, config.srcDir)],
},
Expand Down
1 change: 1 addition & 0 deletions src/compiler/transformers/test/transpile.ts
Expand Up @@ -40,6 +40,7 @@ export function transpileModule(

options.jsx = ts.JsxEmit.React;
options.jsxFactory = 'h';
options.jsxFragmentFactory = 'Fragment';

const inputFileName = 'module.tsx';
const sourceFile = ts.createSourceFile(inputFileName, input, options.target);
Expand Down
1 change: 1 addition & 0 deletions src/compiler/transformers/update-stencil-core-import.ts
Expand Up @@ -62,6 +62,7 @@ const KEEP_IMPORTS = new Set([
'getMode',
'Build',
'Host',
'Fragment',
'getAssetPath',
'writeTask',
'readTask',
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/transpile/transpile-module.ts
Expand Up @@ -59,6 +59,10 @@ export const transpileModule = (config: d.Config, input: string, transformOpts:
tsCompilerOptions.jsxFactory = 'h';
}

if (tsCompilerOptions.jsxFragmentFactory != null && !isString(tsCompilerOptions.jsxFragmentFactory)) {
tsCompilerOptions.jsxFragmentFactory = 'Fragment';
}

if (tsCompilerOptions.paths && !isString(tsCompilerOptions.baseUrl)) {
tsCompilerOptions.baseUrl = '.';
}
Expand Down
5 changes: 5 additions & 0 deletions src/declarations/stencil-public-runtime.ts
Expand Up @@ -481,6 +481,11 @@ export interface ChildNode {
*/
export declare const Host: FunctionalComponent<HostAttributes>;

/**
* Fragment
*/
export declare const Fragment: FunctionalComponent<{}>;

/**
* The "h" namespace is used to import JSX types for elements and attributes.
* It is imported in order to avoid conflicting global JSX issues.
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/fragment.ts
@@ -0,0 +1,3 @@
import { FunctionalComponent } from '../declarations/stencil-public-runtime';

export const Fragment: FunctionalComponent = (_, children: any) => children;
1 change: 1 addition & 0 deletions src/runtime/index.ts
Expand Up @@ -16,3 +16,4 @@ export { forceUpdate, postUpdateComponent, getRenderingRef } from './update-comp
export { proxyComponent } from './proxy-component';
export { renderVdom } from './vdom/vdom-render';
export { setMode, getMode } from './mode';
export { Fragment } from './fragment';

0 comments on commit f3abee7

Please sign in to comment.