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

Function parsePropDefs

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

* @param {typeof import('./base-element').PreactBaseElement} Ctor * @param {JsonObject} props * @param {AmpElementProps} propDefs * @param {Element} element * @param {?MediaQueryProps} mediaQueryProps

(Ctor, props, propDefs, element, mediaQueryProps)

Source from the content-addressed store, hash-verified

165 * @param {?MediaQueryProps} mediaQueryProps
166 */
167function parsePropDefs(Ctor, props, propDefs, element, mediaQueryProps) {
168 // Match all children defined with "selector".
169 if (checkPropsFor(propDefs, HAS_SELECTOR)) {
170 // There are plain "children" and there're slotted children assigned
171 // as separate properties. Thus in a carousel the plain "children" are
172 // slides, and the "arrowNext" children are passed via a "arrowNext"
173 // property.
174 const elements = realChildElements(element);
175 for (let i = 0; i < elements.length; i++) {
176 const childElement = /** @type {HTMLElement} */ (elements[i]);
177 const match = matchChild(childElement, propDefs);
178 if (!match) {
179 continue;
180 }
181 const def = propDefs[match];
182 const {
183 as = false,
184 clone,
185 name = match,
186 props: slotProps = {},
187 single,
188 } = def;
189 devAssert(clone || Ctor['usesShadowDom']);
190 const parsedSlotProps = {};
191 parsePropDefs(
192 Ctor,
193 parsedSlotProps,
194 slotProps,
195 childElement,
196 mediaQueryProps
197 );
198
199 // TBD: assign keys, reuse slots, etc.
200 if (single) {
201 props[name] = createSlot(
202 childElement,
203 childElement.getAttribute('slot') || `i-amphtml-${name}`,
204 parsedSlotProps,
205 as
206 );
207 } else {
208 const list = props[name] || (props[name] = []);
209 devAssert(!as);
210 list.push(
211 clone
212 ? createShallowVNodeCopy(childElement)
213 : createSlot(
214 childElement,
215 childElement.getAttribute('slot') ||
216 `i-amphtml-${name}-${childIdGenerator()}`,
217 parsedSlotProps
218 )
219 );
220 }
221 }
222 }
223
224 for (const name in propDefs) {

Callers 1

collectPropsFunction · 0.85

Calls 13

realChildElementsFunction · 0.90
devAssertFunction · 0.90
createSlotFunction · 0.90
realChildNodesFunction · 0.90
parseBooleanAttributeFunction · 0.90
checkPropsForFunction · 0.85
matchChildFunction · 0.85
createShallowVNodeCopyFunction · 0.85
getAttributeMethod · 0.80
resolveListQueryMethod · 0.80
StringFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected