MCPcopy Create free account
hub / github.com/adobe/react-spectrum / renderChildren

Function renderChildren

packages/dev/s2-docs/src/Code.tsx:367–417  ·  view source on GitHub ↗
(
  children: (HastNode | HastTextNode)[],
  key: string,
  links?: Links
)

Source from the content-addressed store, hash-verified

365}
366
367function renderChildren(
368 children: (HastNode | HastTextNode)[],
369 key: string,
370 links?: Links
371): Token[] {
372 let childArray: Token[] = [];
373 let type = -1;
374 let stringIndex = -1;
375 for (let [i, child] of children.entries()) {
376 let indent =
377 i === 1 && stringIndex >= 0 && /^\s+$/.test(childArray[stringIndex] as string)
378 ? (childArray[stringIndex] as string)
379 : '';
380 let childNode = renderHast(child, `${key}.${i}`, links, indent);
381 let childNodes = Array.isArray(childNode) ? childNode : [childNode];
382 let childIndex = 0;
383 while (childIndex < childNodes.length) {
384 let child = childNodes[childIndex++];
385 let childType = -1;
386 if (typeof child === 'number') {
387 // A number represents a token type. Consume the next value.
388 childType = child;
389 child = childNodes[childIndex++];
390 if (childType !== type) {
391 childArray.push(childType);
392 }
393 }
394
395 // If this is a string, either append to the previous string if it is
396 // the same token type, or push a new string.
397 if (typeof child === 'string') {
398 if (childType !== type) {
399 type = childType;
400 stringIndex = childArray.length;
401 childArray.push(child);
402 } else if (stringIndex >= 0) {
403 childArray[stringIndex] += child;
404 } else {
405 stringIndex = childArray.length;
406 childArray.push(child);
407 }
408 } else {
409 type = -1;
410 stringIndex = -1;
411 childArray.push(child);
412 }
413 }
414 }
415
416 return childArray;
417}
418
419function text(node) {
420 if (node.type === 'text') {

Callers 2

Code.tsxFile · 0.70
renderHastFunction · 0.70

Calls 2

renderHastFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected