Sha256: d393968517516330518c12fed08650a130862876ecaaf4c5f6420411665a2aa9

Contents?: true

Size: 1.76 KB

Versions: 61

Compression:

Stored size: 1.76 KB

Contents

import { options, Fragment } from 'preact';

/** @typedef {import('preact').VNode} VNode */

let vnodeId = 0;

/**
 * @fileoverview
 * This file exports various methods that implement Babel's "automatic" JSX runtime API:
 * - jsx(type, props, key)
 * - jsxs(type, props, key)
 * - jsxDEV(type, props, key, __source, __self)
 *
 * The implementation of createVNode here is optimized for performance.
 * Benchmarks: https://esbench.com/bench/5f6b54a0b4632100a7dcd2b3
 */

/**
 * JSX.Element factory used by Babel's {runtime:"automatic"} JSX transform
 * @param {VNode['type']} type
 * @param {VNode['props']} props
 * @param {VNode['key']} [key]
 * @param {string} [__source]
 * @param {string} [__self]
 */
function createVNode(type, props, key, __source, __self) {
	// We'll want to preserve `ref` in props to get rid of the need for
	// forwardRef components in the future, but that should happen via
	// a separate PR.
	let normalizedProps = {},
		ref,
		i;
	for (i in props) {
		if (i == 'ref') {
			ref = props[i];
		} else {
			normalizedProps[i] = props[i];
		}
	}

	const vnode = {
		type,
		props: normalizedProps,
		key,
		ref,
		_children: null,
		_parent: null,
		_depth: 0,
		_dom: null,
		_nextDom: undefined,
		_component: null,
		_hydrating: null,
		constructor: undefined,
		_original: --vnodeId,
		__source,
		__self
	};

	// If a Component VNode, check for and apply defaultProps.
	// Note: `type` is often a String, and can be `undefined` in development.
	if (typeof type === 'function' && (ref = type.defaultProps)) {
		for (i in ref)
			if (typeof normalizedProps[i] === 'undefined') {
				normalizedProps[i] = ref[i];
			}
	}

	if (options.vnode) options.vnode(vnode);
	return vnode;
}

export {
	createVNode as jsx,
	createVNode as jsxs,
	createVNode as jsxDEV,
	Fragment
};

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
isomorfeus-preact-10.6.62 node_modules/preact/jsx-runtime/src/index.js
isomorfeus-preact-10.6.61 node_modules/preact/jsx-runtime/src/index.js
isomorfeus-preact-10.6.60 node_modules/preact/jsx-runtime/src/index.js
isomorfeus-preact-10.6.59 node_modules/preact/jsx-runtime/src/index.js
isomorfeus-preact-10.6.58 node_modules/preact/jsx-runtime/src/index.js
isomorfeus-preact-10.6.57 node_modules/preact/jsx-runtime/src/index.js
isomorfeus-preact-10.6.56 node_modules/preact/jsx-runtime/src/index.js
isomorfeus-preact-10.6.55 node_modules/preact/jsx-runtime/src/index.js
isomorfeus-preact-10.6.54 node_modules/preact/jsx-runtime/src/index.js
isomorfeus-preact-10.6.53 node_modules/preact/jsx-runtime/src/index.js
isomorfeus-preact-10.6.52 node_modules/preact/jsx-runtime/src/index.js
isomorfeus-preact-10.6.51 node_modules/preact/jsx-runtime/src/index.js
isomorfeus-preact-10.6.50 node_modules/preact/jsx-runtime/src/index.js
isomorfeus-preact-10.6.49 node_modules/preact/jsx-runtime/src/index.js
isomorfeus-preact-10.6.48 node_modules/preact/jsx-runtime/src/index.js
isomorfeus-preact-10.6.47 node_modules/preact/jsx-runtime/src/index.js
isomorfeus-preact-10.6.46 node_modules/preact/jsx-runtime/src/index.js
isomorfeus-preact-10.6.45 node_modules/preact/jsx-runtime/src/index.js
isomorfeus-preact-10.6.44 node_modules/preact/jsx-runtime/src/index.js
isomorfeus-preact-10.6.43 node_modules/preact/jsx-runtime/src/index.js