diff --git a/packages/core/schematics/migrations/signal-migration/src/input_detection/template_reference_visitor.ts b/packages/core/schematics/migrations/signal-migration/src/input_detection/template_reference_visitor.ts index 7e38d1a334c..3496fce36b9 100644 --- a/packages/core/schematics/migrations/signal-migration/src/input_detection/template_reference_visitor.ts +++ b/packages/core/schematics/migrations/signal-migration/src/input_detection/template_reference_visitor.ts @@ -17,6 +17,7 @@ import { PropertyRead, PropertyWrite, RecursiveAstVisitor, + SafePropertyRead, ThisReceiver, TmplAstBoundAttribute, TmplAstBoundEvent, @@ -274,12 +275,15 @@ export class TemplateExpressionReferenceVisitor extends RecursiveAs super.visitLiteralMap(ast, context); } - // TODO: Consider safe property reads/writes. - override visitPropertyRead(ast: PropertyRead) { this._inspectPropertyAccess(ast); super.visitPropertyRead(ast, null); } + override visitSafePropertyRead(ast: SafePropertyRead) { + this._inspectPropertyAccess(ast); + super.visitPropertyRead(ast, null); + } + override visitPropertyWrite(ast: PropertyWrite) { this._inspectPropertyAccess(ast); super.visitPropertyWrite(ast, null); diff --git a/packages/core/schematics/migrations/signal-migration/test/golden-test/safe_property_reads.ts b/packages/core/schematics/migrations/signal-migration/test/golden-test/safe_property_reads.ts new file mode 100644 index 00000000000..77146666e32 --- /dev/null +++ b/packages/core/schematics/migrations/signal-migration/test/golden-test/safe_property_reads.ts @@ -0,0 +1,22 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +// tslint:disable + +import {Component, Input} from '@angular/core'; + +@Component({ + template: ` + {{bla?.myInput}} + `, +}) +class WithSafePropertyReads { + @Input() myInput = 0; + + bla: this | undefined = this; +} diff --git a/packages/core/schematics/migrations/signal-migration/test/golden.txt b/packages/core/schematics/migrations/signal-migration/test/golden.txt index 0e0fb8d1d46..b99dd3abbc9 100644 --- a/packages/core/schematics/migrations/signal-migration/test/golden.txt +++ b/packages/core/schematics/migrations/signal-migration/test/golden.txt @@ -751,6 +751,30 @@ import { input } from '@angular/core'; class Required { simpleInput = input.required(); } +@@@@@@ safe_property_reads.ts @@@@@@ + +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +// tslint:disable + +import { Component, input } from '@angular/core'; + +@Component({ + template: ` + {{bla?.myInput()}} + `, +}) +class WithSafePropertyReads { + myInput = input(0); + + bla: this | undefined = this; +} @@@@@@ scope_sharing.ts @@@@@@ // tslint:disable diff --git a/packages/core/schematics/migrations/signal-migration/test/golden_best_effort.txt b/packages/core/schematics/migrations/signal-migration/test/golden_best_effort.txt index f6a75c14f90..091bed03655 100644 --- a/packages/core/schematics/migrations/signal-migration/test/golden_best_effort.txt +++ b/packages/core/schematics/migrations/signal-migration/test/golden_best_effort.txt @@ -751,6 +751,30 @@ import { input } from '@angular/core'; class Required { simpleInput = input.required(); } +@@@@@@ safe_property_reads.ts @@@@@@ + +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +// tslint:disable + +import { Component, input } from '@angular/core'; + +@Component({ + template: ` + {{bla?.myInput()}} + `, +}) +class WithSafePropertyReads { + myInput = input(0); + + bla: this | undefined = this; +} @@@@@@ scope_sharing.ts @@@@@@ // tslint:disable