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

Function readMicrosyntax

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

Source from the content-addressed store, hash-verified

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

Callers 2

templateMemberUsesFunction · 0.85

Calls 5

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

Tested by

no test coverage detected