66 * found in the LICENSE file at https://angular.io/license
77 */
88
9- import { AST , ASTWithSource , BindingPipe , ParseSourceSpan , PropertyRead , PropertyWrite , SafePropertyRead , TmplAstBoundAttribute , TmplAstBoundEvent , TmplAstElement , TmplAstNode , TmplAstReference , TmplAstTemplate , TmplAstTextAttribute , TmplAstVariable } from '@angular/compiler' ;
9+ import { AST , ASTWithSource , BindingPipe , ParseSourceSpan , PropertyRead , PropertyWrite , R3Identifiers , SafePropertyRead , TmplAstBoundAttribute , TmplAstBoundEvent , TmplAstElement , TmplAstNode , TmplAstReference , TmplAstTemplate , TmplAstTextAttribute , TmplAstVariable } from '@angular/compiler' ;
1010import ts from 'typescript' ;
1111
1212import { AbsoluteFsPath } from '../../file_system' ;
@@ -311,7 +311,6 @@ export class SymbolBuilder {
311311 continue ;
312312 }
313313
314-
315314 const target = this . getDirectiveSymbolForAccessExpression ( outputFieldAccess , consumer ) ;
316315 if ( target === null ) {
317316 continue ;
@@ -359,12 +358,33 @@ export class SymbolBuilder {
359358 continue ;
360359 }
361360
362- const symbolInfo = this . getSymbolOfTsNode ( node . left ) ;
361+ const signalInputAssignment = unwrapSignalInputWriteTAccessor ( node . left ) ;
362+ let symbolInfo : TsNodeSymbolInfo | null = null ;
363+
364+ // Signal inputs need special treatment because they are generated with an extra keyed
365+ // access. E.g. `_t1.prop[WriteT_ACCESSOR_SYMBOL]`. Observations:
366+ // - The keyed access for the write type needs to be resolved for the "input type".
367+ // - The definition symbol of the input should be the input class member, and not the
368+ // internal write accessor. Symbol should resolve `_t1.prop`.
369+ if ( signalInputAssignment !== null ) {
370+ const fieldSymbol = this . getSymbolOfTsNode ( signalInputAssignment . fieldExpr ) ;
371+ const typeSymbol = this . getSymbolOfTsNode ( signalInputAssignment . typeExpr ) ;
372+
373+ symbolInfo = fieldSymbol === null || typeSymbol === null ? null : {
374+ tcbLocation : fieldSymbol . tcbLocation ,
375+ tsSymbol : fieldSymbol . tsSymbol ,
376+ tsType : typeSymbol . tsType ,
377+ } ;
378+ } else {
379+ symbolInfo = this . getSymbolOfTsNode ( node . left ) ;
380+ }
381+
363382 if ( symbolInfo === null || symbolInfo . tsSymbol === null ) {
364383 continue ;
365384 }
366385
367- const target = this . getDirectiveSymbolForAccessExpression ( node . left , consumer ) ;
386+ const target = this . getDirectiveSymbolForAccessExpression (
387+ signalInputAssignment ?. fieldExpr ?? node . left , consumer ) ;
368388 if ( target === null ) {
369389 continue ;
370390 }
@@ -383,11 +403,10 @@ export class SymbolBuilder {
383403 }
384404
385405 private getDirectiveSymbolForAccessExpression (
386- node : ts . ElementAccessExpression | ts . PropertyAccessExpression ,
406+ fieldAccessExpr : ts . ElementAccessExpression | ts . PropertyAccessExpression ,
387407 { isComponent, selector, isStructural} : TypeCheckableDirectiveMeta ) : DirectiveSymbol | null {
388- // In either case, `_t1["index"]` or `_t1.index`, `node.expression` is _t1.
389- // The retrieved symbol for _t1 will be the variable declaration.
390- const tsSymbol = this . getTypeChecker ( ) . getSymbolAtLocation ( node . expression ) ;
408+ // In all cases, `_t1["index"]` or `_t1.index`, `node.expression` is _t1.
409+ const tsSymbol = this . getTypeChecker ( ) . getSymbolAtLocation ( fieldAccessExpr . expression ) ;
391410 if ( tsSymbol ?. declarations === undefined || tsSymbol . declarations . length === 0 ||
392411 selector === null ) {
393412 return null ;
@@ -625,8 +644,6 @@ export class SymbolBuilder {
625644 let tsSymbol : ts . Symbol | undefined ;
626645 if ( ts . isPropertyAccessExpression ( node ) ) {
627646 tsSymbol = this . getTypeChecker ( ) . getSymbolAtLocation ( node . name ) ;
628- } else if ( ts . isElementAccessExpression ( node ) ) {
629- tsSymbol = this . getTypeChecker ( ) . getSymbolAtLocation ( node . argumentExpression ) ;
630647 } else {
631648 tsSymbol = this . getTypeChecker ( ) . getSymbolAtLocation ( node ) ;
632649 }
@@ -670,3 +687,35 @@ function anyNodeFilter(n: ts.Node): n is ts.Node {
670687function sourceSpanEqual ( a : ParseSourceSpan , b : ParseSourceSpan ) {
671688 return a . start . offset === b . start . offset && a . end . offset === b . end . offset ;
672689}
690+
691+ function unwrapSignalInputWriteTAccessor ( expr : ts . LeftHandSideExpression ) : ( null | {
692+ fieldExpr : ts . ElementAccessExpression | ts . PropertyAccessExpression ,
693+ typeExpr : ts . ElementAccessExpression
694+ } ) {
695+ // e.g. `_t2.inputA[i2.ɵINPUT_SIGNAL_BRAND_WRITE_TYPE]`
696+ // 1. Assert that we are dealing with an element access expression.
697+ // 2. Assert that we are dealing with a signal brand symbol access in the argument expression.
698+ if ( ! ts . isElementAccessExpression ( expr ) ||
699+ ! ts . isPropertyAccessExpression ( expr . argumentExpression ) ) {
700+ return null ;
701+ }
702+
703+ // Assert that the property access in the element access is a simple identifier and
704+ // refers to `ɵINPUT_SIGNAL_BRAND_WRITE_TYPE`.
705+ if ( ! ts . isIdentifier ( expr . argumentExpression . name ) ||
706+ expr . argumentExpression . name . text !== R3Identifiers . InputSignalBrandWriteType . name ) {
707+ return null ;
708+ }
709+
710+ // Assert that the `_t2.inputA` is actually either a keyed element access, or
711+ // property access expression. This is checked for type safety and to catch unexpected cases.
712+ if ( ! ts . isPropertyAccessExpression ( expr . expression ) &&
713+ ! ts . isElementAccessExpression ( expr . expression ) ) {
714+ throw new Error ( 'Unexpected expression for signal input write type.' ) ;
715+ }
716+
717+ return {
718+ fieldExpr : expr . expression ,
719+ typeExpr : expr ,
720+ } ;
721+ }
0 commit comments