Repository navigation
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
JeanMeche
left a comment
There was a problem hiding this comment.
Thanks for catching this and for the clean tests!
A couple of suggestions:
-
Avoid the hand-maintained operator list:
writeBinaryOperatorsis currently typed asts.BinaryOperator[], which is how it missed these 5 operators and ended up withExclamationEqualsToken(!=). Instead of maintaining an explicit list, we can check TypeScript's built-in assignment range:kind >= ts.SyntaxKind.FirstAssignment && kind <= ts.SyntaxKind.LastAssignment
(or type the table as
Record<ts.AssignmentOperator, true>so TypeScript enforces exhaustiveness and prevents non-assignment operators like!=from sneaking in). Note that switching toFirstAssignment..LastAssignmentwould also cleanly fix the!=bug you noted—fine to do either here or in a follow-up. -
Templates have the same gap: Angular templates also support compound assignment operators (
+=,??=, etc.), andTemplateExpressionReferenceVisitor.visitBinary(signal-migration/src/passes/reference_resolution/template_reference_visitor.ts) currently only checksast.operation === '='instead ofBinary.isAssignmentOperation(ast.operation)from@angular/compiler. Worth addressing either here or in a follow-up PR.
… in signal migrations The signal input and signal queries migrations detect writes to a field by checking the operator of the enclosing binary expression against a list of assignment operators. That list was missing `??=`, `**=`, `<<=`, `>>=` and `>>>=`, so fields written with these operators were migrated anyway, producing code that does not compile, e.g. `this.value() ??= fallback` or an assignment to a `const` temporary variable. The list also wrongly included `!=`, so fields that were only compared with `!=` were skipped. Writes are now detected using TypeScript's assignment operator range, so the field is skipped with the "written to" incompatibility for every assignment operator, like for `=` or `||=`. Templates and host bindings had the same gap, as only `=` was treated as a write. All template assignment operators (`+=`, `??=`, etc.) are now treated as writes as well.
d553982 to
daf6761
Compare
|
Thanks for the suggestions! Both addressed in this PR:
Note: #72348 also touches |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
The
@angular/core:signal-input-migration(andsignal-queries-migration) migrates fields that are written with??=(also**=,<<=,>>=,>>>=), producing code that does not compile:becomes
and
becomes
Cause:
writeBinaryOperators(signal-migration/src/utils/write_operators.ts), used byidentify_ts_references.tsto setisWrite, does not list these operators. The signal queries migration reuses the same reference resolution, so it is affected too (this.label ??= fallback→this.label() ??= fallback).Issue Number: N/A
What is the new behavior?
All TypeScript assignment operators are considered writes, so such fields are skipped with the "Your application code writes to the input" incompatibility, as with
=or||=. In best-effort mode the field is migrated and the write is left untouched, as for=.Tests: new cases in the
writing_to_inputs.tsgolden test (golden.txt,golden_best_effort.txt) and a spec in the signal queries migration.Does this PR introduce a breaking change?
Other information
The same list also contains
ExclamationEqualsToken(!=), which is a comparison, not a write:if (this.value != null)currently makes the migration skipvalueas "written to". It only causes missed migrations (no broken output), so I left it out of this fix to keep it focused; happy to remove it here or in a follow-up.