Skip to content

Commit

Permalink
refactor(migrations): handle safe property reads in signal input migr…
Browse files Browse the repository at this point in the history
…ation (angular#57318)

As of this commit, the migration will also inspect safe property reads
and migrate them, if they reference an input that is being migrated.

PR Close angular#57318
  • Loading branch information
devversion authored and AndrewKushnir committed Aug 12, 2024
1 parent 6b7b44d commit 52673e6
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
PropertyRead,
PropertyWrite,
RecursiveAstVisitor,
SafePropertyRead,
ThisReceiver,
TmplAstBoundAttribute,
TmplAstBoundEvent,
Expand Down Expand Up @@ -274,12 +275,15 @@ export class TemplateExpressionReferenceVisitor<ExprContext> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,30 @@ import { input } from '@angular/core';
class Required {
simpleInput = input.required<string>();
}
@@@@@@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,30 @@ import { input } from '@angular/core';
class Required {
simpleInput = input.required<string>();
}
@@@@@@ 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
Expand Down

0 comments on commit 52673e6

Please sign in to comment.