MCPcopy Index your code
hub / github.com/lingodotdev/lingo.dev / processWithIndex

Function processWithIndex

packages/react/src/core/component.tsx:247–283  ·  view source on GitHub ↗
(nodeList: ReactNode[])

Source from the content-addressed store, hash-verified

245 let expressionIndex = 0;
246
247 function processWithIndex(nodeList: ReactNode[]): ReactNode[] {
248 return nodeList
249 .map((node) => {
250 if (typeof node === "string") {
251 const segments: ReactNode[] = [];
252 let lastIndex = 0;
253 const expressionRegex = /<expression\/>/g;
254 let match;
255
256 while ((match = expressionRegex.exec(node)) !== null) {
257 if (match.index > lastIndex) {
258 segments.push(node.slice(lastIndex, match.index));
259 }
260
261 const value = expressions[expressionIndex++];
262 segments.push(value ?? match[0]);
263
264 lastIndex = match.index + match[0].length;
265 }
266
267 if (lastIndex < node.length) {
268 segments.push(node.slice(lastIndex));
269 }
270
271 return segments;
272 } else if (isReactElement(node)) {
273 const props = node.props as { children?: ReactNode };
274 return createElement(
275 node.type,
276 { ...props },
277 ...processWithIndex(_.castArray(props.children || [])),
278 );
279 }
280 return node;
281 })
282 .flat();
283 }
284
285 return processWithIndex(nodes);
286}

Callers 1

replaceExpressionsFunction · 0.85

Calls 2

isReactElementFunction · 0.85
pushMethod · 0.65

Tested by

no test coverage detected