MCPcopy Create free account
hub / github.com/ampproject/amphtml / createShallowVNodeCopy

Function createShallowVNodeCopy

src/preact/parse-props.js:287–302  ·  view source on GitHub ↗

* Copies an Element into a VNode representation. * (Interpretation into VNode is not recursive, so it excludes children.) * @param {Element} element * @return {import('preact').VNode}

(element)

Source from the content-addressed store, hash-verified

285 * @return {import('preact').VNode}
286 */
287function createShallowVNodeCopy(element) {
288 /** @type {JsonObject} */
289 const props = {
290 // Setting `key` to an object is fine in Preact, but not React.
291 'key': element,
292 };
293 // We need to read element.attributes and element.attributes.length only once,
294 // since reading a live NamedNodeMap repeatedly is expensive.
295 const {attributes, localName} = element;
296 const {length} = attributes;
297 for (let i = 0; i < length; i++) {
298 const {name, value} = attributes[i];
299 props[name] = value;
300 }
301 return Preact.createElement(localName, props);
302}
303
304/**
305 * @param {HTMLElement} element

Callers 1

parsePropDefsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected