wallet-core/src/h.js
Florian Dold 6e5fb04d3f Squashed 'thirdparty/preact/' changes from b2d90cc..ba094e2
ba094e2 Run only local tests for pull requests ()
e9fc3c2 Fix CI build ()
70a5ca3 This adds a link to preact-i18nline. ()
5dffd85 Merge branch 'pr-fix-build-for-windows' of https://github.com/Download/preact
f14edf7 kilobits => kilobytes ()
c193547 Test for 
284e4aa 6.4.0
24eab2f Prevent accidental duplicate recycling of elements when swapping the base element of a component. Fixes .
76c5ef7 fix lint error
8008886 When swapping the base of a composed child component, update its parent's base reference. Fixes .
fd4f21f Add an equality check prior to setting `.nodeValue` on text nodes, since Firefox (and maybe others) don't do this internally by default.  Fixes  - thanks @zbinlin!
1555e2b Add CDNJS version badge in readme ()
79c8bae Disable React Developer Tools integration tests under IE ()
84f4eeb Refactor `linkState()` a bit to drop around 40 bytes. Coincidentally, that's the exact size of the hooks just added for DevTools... 👌
22bbfcb Little tweaks 👯
f8b326e Document how to use the React DevTools with Preact ()
1f4a8eb Correct "preact/devtools" type definitions ()
68f22eb Add React Developer Tools integration ()
2a7a027 Add ref and allow objects in className ()
4a59cca fix readme todomvc link ()
37ca4e0 Fixes build for Windows 
cf93387 6.3.0
ff05818 Make `VNode.children` *always* be an Array, even when there are no children.
9b095f4 Added link to preact-layout ()

git-subtree-dir: thirdparty/preact
git-subtree-split: ba094e27b602cb16aded7dcad95f71e44b7b0476
2016-11-08 15:07:07 +01:00

51 lines
1.2 KiB
JavaScript

import { VNode } from './vnode';
import options from './options';
const stack = [];
/** JSX/hyperscript reviver
* Benchmarks: https://esbench.com/bench/57ee8f8e330ab09900a1a1a0
* @see http://jasonformat.com/wtf-is-jsx
* @public
* @example
* /** @jsx h *\/
* import { render, h } from 'preact';
* render(<span>foo</span>, document.body);
*/
export function h(nodeName, attributes) {
let children = [],
lastSimple, child, simple, i;
for (i=arguments.length; i-- > 2; ) {
stack.push(arguments[i]);
}
if (attributes && attributes.children) {
if (!stack.length) stack.push(attributes.children);
delete attributes.children;
}
while (stack.length) {
if ((child = stack.pop()) instanceof Array) {
for (i=child.length; i--; ) stack.push(child[i]);
}
else if (child!=null && child!==false) {
if (typeof child=='number' || child===true) child = String(child);
simple = typeof child=='string';
if (simple && lastSimple) {
children[children.length-1] += child;
}
else {
children.push(child);
lastSimple = simple;
}
}
}
let p = new VNode(nodeName, attributes || undefined, children);
// if a "vnode hook" is defined, pass every created VNode to it
if (options.vnode) options.vnode(p);
return p;
}