MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / readMicrosyntax

Function readMicrosyntax

src/resolution/angular-template-synthesizer.ts:382–439  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

380 * takes (`index`, `index as i`) belong to the directive, never the component.
381 */
382export function readMicrosyntax(text: string): { expressions: Array<{ at: number; text: string }>; locals: string[] } {
383 const expressions: Array<{ at: number; text: string }> = [];
384 const locals: string[] = [];
385 let i = 0;
386 const skip = (separators: boolean) => {
387 while (i < text.length && (isBlank(text[i]) || (separators && (text[i] === ';' || text[i] === ',')))) i++;
388 };
389 const word = (): string | null => {
390 NAME_AT.lastIndex = i;
391 const m = NAME_AT.exec(text);
392 if (!m) return null;
393 i += m[0].length;
394 return m[0];
395 };
396 let first = true;
397 while (i < text.length) {
398 skip(true);
399 if (i >= text.length) break;
400 const start = i;
401 const key = word();
402 if (key === 'let' && isBlank(text[i])) {
403 // `let item`, `let i = index`: a local, and the context name it takes.
404 skip(false);
405 const local = word();
406 if (local) locals.push(local);
407 skip(false);
408 if (text[i] === '=') {
409 i++;
410 skip(false);
411 word();
412 }
413 first = false;
414 continue;
415 }
416 if (first || key === null) {
417 // The directive's own expression (`*ngIf="cond"`) has no key.
418 i = start;
419 } else {
420 skip(false);
421 if (text[i] === ':') i++;
422 skip(false);
423 }
424 const end = expressionEnd(text, i);
425 if (end > i) expressions.push({ at: i, text: text.slice(i, end) });
426 i = end;
427 skip(false);
428 if (/^as(?![\w$])/.test(text.slice(i, i + 3))) {
429 i += 2;
430 skip(false);
431 const alias = word();
432 if (alias) locals.push(alias);
433 }
434 // Nothing read (a stray character): step past it.
435 if (i === start) i++;
436 first = false;
437 }
438 return { expressions, locals };
439}

Callers 2

templateMemberUsesFunction · 0.85

Calls 5

wordFunction · 0.85
pushMethod · 0.80
skipFunction · 0.70
isBlankFunction · 0.70
expressionEndFunction · 0.70

Tested by

no test coverage detected