Skip to content

Commit dd6e1c3

Browse files
JeanMechethePunderWoman
authored andcommitted
refactor(core): prevent input migration from introducing a breaking change (#63547)
Non-typed `transform` functions were stripped by the migration prior to this commit (while still logging an error). This behavior will now only happen with `--best-effort`. #63541 PR Close #63547
1 parent f612437 commit dd6e1c3

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

packages/core/schematics/migrations/signal-migration/src/input_detection/input_decorator.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,14 @@ function extractSourceCodeInput(
158158
isRequired = !!evaluatedInputOpts.get('required');
159159
}
160160
if (evaluatedInputOpts.has('transform') && evaluatedInputOpts.get('transform') != null) {
161-
transformResult = parseTransformOfInput(evaluatedInputOpts, node, reflector);
161+
const result = parseTransformOfInput(evaluatedInputOpts, node, reflector);
162+
if (result === 'parsingError') {
163+
if (!host.config.bestEffortMode) {
164+
return null;
165+
}
166+
} else {
167+
transformResult = result;
168+
}
162169
}
163170
}
164171
}
@@ -183,7 +190,7 @@ function parseTransformOfInput(
183190
evaluatedInputOpts: ResolvedValueMap,
184191
node: InputNode,
185192
reflector: ReflectionHost,
186-
): DecoratorInputTransform | null {
193+
): DecoratorInputTransform | 'parsingError' | null {
187194
const transformValue = evaluatedInputOpts.get('transform');
188195
if (!(transformValue instanceof DynamicValue) && !(transformValue instanceof Reference)) {
189196
return null;
@@ -220,6 +227,6 @@ function parseTransformOfInput(
220227
// TODO: implement error handling.
221228
// See failing case: e.g. inherit_definition_feature_spec.ts
222229
console.error(`${e.node.getSourceFile().fileName}: ${e.toString()}`);
223-
return null;
230+
return 'parsingError';
224231
}
225232
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// tslint:disable
2+
3+
import {Input} from '@angular/core';
4+
5+
export class TransformFunctions {
6+
@Input({transform: (v) => v * 10}) untypedTransform: number = 0;
7+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,15 @@ class TransformIncompatibleTypes {
14181418
// cast. This worked previously because Angular was unable to check transforms.
14191419
readonly disabled = input<boolean, unknown>(undefined, { transform: ((v: unknown) => (v === null ? undefined : !!v)) as any });
14201420
}
1421+
@@@@@@ transform_no_explicit_types.ts @@@@@@
1422+
1423+
// tslint:disable
1424+
1425+
import {Input} from '@angular/core';
1426+
1427+
export class TransformFunctions {
1428+
@Input({transform: (v) => v * 10}) untypedTransform: number = 0;
1429+
}
14211430
@@@@@@ with_getters.ts @@@@@@
14221431

14231432
// tslint:disable

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,15 @@ class TransformIncompatibleTypes {
13571357
// cast. This worked previously because Angular was unable to check transforms.
13581358
readonly disabled = input<boolean, unknown>(undefined, { transform: ((v: unknown) => (v === null ? undefined : !!v)) as any });
13591359
}
1360+
@@@@@@ transform_no_explicit_types.ts @@@@@@
1361+
1362+
// tslint:disable
1363+
1364+
import {input} from '@angular/core';
1365+
1366+
export class TransformFunctions {
1367+
readonly untypedTransform = input<number>(0);
1368+
}
13601369
@@@@@@ with_getters.ts @@@@@@
13611370

13621371
// tslint:disable

0 commit comments

Comments
 (0)