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

feat(runtime): add jsx Fragment #2647

Merged
merged 1 commit into from Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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';