Skip to content

Commit 9213216

Browse files
committed
refactor(migrations): do not accidentally detect read as incompatible write (angular#58054)
Fixes that the signal input and queries migration detects code like `fixture = bla.componentInstance.field` as an incompatible write because it's part of a binary expression, but we didn't check whether it's part of the left side. PR Close angular#58054
1 parent 9c3bd1b commit 9213216

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

packages/core/schematics/migrations/signal-migration/src/passes/reference_resolution/identify_ts_references.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ export function identifyPotentialTypeScriptReference<D extends ClassFieldDescrip
9696
return;
9797
}
9898

99-
const accessParent = unwrapParent(traverseAccess(node).parent);
99+
const access = unwrapParent(traverseAccess(node));
100+
const accessParent = access.parent;
100101
const isWriteReference =
101102
ts.isBinaryExpression(accessParent) &&
103+
accessParent.left === access &&
102104
writeBinaryOperators.includes(accessParent.operatorToken.kind);
103105

104106
// track accesses from source files to known fields.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// tslint:disable
2+
3+
import {Input} from '@angular/core';
4+
5+
export class TestCmp {
6+
@Input() testParenthesisInput = false;
7+
@Input() notMutated = true;
8+
9+
testParenthesis() {
10+
// prettier-ignore
11+
((this.testParenthesisInput)) = true;
12+
}
13+
14+
testNotMutated() {
15+
let fixture: boolean;
16+
fixture = this.notMutated;
17+
}
18+
}

packages/core/schematics/migrations/signal-migration/test/golden.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,3 +1355,25 @@ class WithJsdoc {
13551355

13561356
readonly withCommentInside = input</* intended */ boolean>();
13571357
}
1358+
@@@@@@ writing_to_inputs.ts @@@@@@
1359+
1360+
// tslint:disable
1361+
1362+
import {Input, input} from '@angular/core';
1363+
1364+
export class TestCmp {
1365+
// TODO: Skipped for migration because:
1366+
// Your application code writes to the input. This prevents migration.
1367+
@Input() testParenthesisInput = false;
1368+
readonly notMutated = input(true);
1369+
1370+
testParenthesis() {
1371+
// prettier-ignore
1372+
((this.testParenthesisInput)) = true;
1373+
}
1374+
1375+
testNotMutated() {
1376+
let fixture: boolean;
1377+
fixture = this.notMutated();
1378+
}
1379+
}

packages/core/schematics/migrations/signal-migration/test/golden_best_effort.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,3 +1307,23 @@ class WithJsdoc {
13071307

13081308
readonly withCommentInside = input</* intended */ boolean>();
13091309
}
1310+
@@@@@@ writing_to_inputs.ts @@@@@@
1311+
1312+
// tslint:disable
1313+
1314+
import {input} from '@angular/core';
1315+
1316+
export class TestCmp {
1317+
readonly testParenthesisInput = input(false);
1318+
readonly notMutated = input(true);
1319+
1320+
testParenthesis() {
1321+
// prettier-ignore
1322+
((this.testParenthesisInput)) = true;
1323+
}
1324+
1325+
testNotMutated() {
1326+
let fixture: boolean;
1327+
fixture = this.notMutated();
1328+
}
1329+
}

0 commit comments

Comments
 (0)