MCPcopy
hub / github.com/analogjs/analog / detectSignals

Function detectSignals

packages/vite-plugin-angular/src/lib/compiler/metadata.ts:456–681  ·  view source on GitHub ↗
(classNode: any, sourceCode: string)

Source from the content-addressed store, hash-verified

454 * viewChild(), contentChild(), viewChildren(), contentChildren().
455 */
456export function detectSignals(classNode: any, sourceCode: string) {
457 const inputs: any = {},
458 outputs: any = {},
459 viewQueries: any[] = [],
460 contentQueries: any[] = [];
461
462 const members: any[] = classNode.body?.body || [];
463
464 for (const m of members) {
465 if (
466 m.type !== 'PropertyDefinition' ||
467 !m.key?.name ||
468 !m.value ||
469 m.value.type !== 'CallExpression'
470 )
471 continue;
472
473 const name: string = m.key.name;
474 const signalCall = getCallApi(m.value);
475 if (!signalCall) continue;
476
477 const { api, required } = signalCall;
478 if (!SIGNAL_APIS.has(api)) continue;
479
480 // Skip signal synthesis when an explicit Angular decorator already
481 // covers the same field. Mirrors Angular's transform behavior
482 // (input_function.ts:42-48 et al.) and the JIT fix in
483 // jit-metadata.ts. Without this, the downstream merge in compile.ts
484 // overwrites decorator-derived metadata or, worse, concats duplicate
485 // query entries that fire twice.
486 const explicit = new Set<string>();
487 for (const dec of m.decorators || []) {
488 const decName: string | undefined = dec.expression?.callee?.name;
489 if (decName && FIELD_DECORATORS.has(decName)) explicit.add(decName);
490 }
491 const hasInput = explicit.has('Input');
492 const hasOutput = explicit.has('Output');
493 const hasQuery =
494 explicit.has('ViewChild') ||
495 explicit.has('ViewChildren') ||
496 explicit.has('ContentChild') ||
497 explicit.has('ContentChildren');
498 if (api === 'input' && hasInput) continue;
499 if (api === 'model' && (hasInput || hasOutput)) continue;
500 if ((api === 'output' || api === 'outputFromObservable') && hasOutput) {
501 continue;
502 }
503 if (
504 (api === 'viewChild' ||
505 api === 'viewChildren' ||
506 api === 'contentChild' ||
507 api === 'contentChildren') &&
508 hasQuery
509 ) {
510 continue;
511 }
512
513 const args: any[] = m.value.arguments || [];

Callers 1

compileFunction · 0.85

Calls 4

propKeyNameFunction · 0.85
stringValueFunction · 0.85
unwrapForwardRefOxcFunction · 0.85
getCallApiFunction · 0.70

Tested by

no test coverage detected