Skip to content

Commit bb29c8b

Browse files
devversionAndrewKushnir
authored andcommitted
refactor(migrations): cleanup TODOs in signal input migration (#57566)
Cleans up remaining TODOs in the signal input migration, and other small clean ups. PR Close #57566
1 parent 8e1d6c7 commit bb29c8b

File tree

7 files changed

+53
-14
lines changed

7 files changed

+53
-14
lines changed

packages/core/schematics/migrations/signal-migration/src/convert-input/convert_to_signal.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@ export function convertToSignalInput(
3131
resolvedMetadata: metadata,
3232
resolvedType,
3333
preferShorthandIfPossible,
34-
isUndefinedInitialValue,
3534
originalInputDecorator,
35+
initialValue,
3636
}: ConvertInputPreparation,
3737
checker: ts.TypeChecker,
3838
importManager: ImportManager,
3939
): string {
40-
let initialValue = node.initializer;
4140
let optionsLiteral: ts.ObjectLiteralExpression | null = null;
4241

4342
// We need an options array for the input because:
@@ -63,7 +62,7 @@ export function convertToSignalInput(
6362
// The initial value is `undefined` or none is present:
6463
// - We may be able to use the `input()` shorthand
6564
// - or we use an explicit `undefined` initial value.
66-
if (isUndefinedInitialValue) {
65+
if (initialValue === undefined) {
6766
// Shorthand not possible, so explicitly add `undefined`.
6867
if (preferShorthandIfPossible === null) {
6968
initialValue = ts.factory.createIdentifier('undefined');
@@ -95,7 +94,6 @@ export function convertToSignalInput(
9594
// Always add an initial value when the input is optional, and we have one, or we need one
9695
// to be able to pass options as the second argument.
9796
if (!metadata.required && (initialValue !== undefined || optionsLiteral !== null)) {
98-
// TODO: undefined `input()` shorthand support!
9997
inputArgs.push(initialValue ?? ts.factory.createIdentifier('undefined'));
10098
}
10199

packages/core/schematics/migrations/signal-migration/src/convert-input/prepare_and_check.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import assert from 'assert';
2323
export interface ConvertInputPreparation {
2424
resolvedType: ts.TypeNode | undefined;
2525
preferShorthandIfPossible: {originalType: ts.TypeNode} | null;
26-
isUndefinedInitialValue: boolean;
2726
resolvedMetadata: ExtractedInput;
2827
originalInputDecorator: Decorator;
28+
initialValue: ts.Expression | undefined;
2929
}
3030

3131
/**
@@ -126,7 +126,7 @@ export function prepareAndCheckForConversion(
126126
resolvedMetadata: metadata,
127127
resolvedType: typeToAdd,
128128
preferShorthandIfPossible,
129-
isUndefinedInitialValue,
130129
originalInputDecorator: metadata.inputDecorator,
130+
initialValue: isUndefinedInitialValue ? undefined : initialValue,
131131
};
132132
}

packages/core/schematics/migrations/signal-migration/src/passes/7_migrate_template_references.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ export function pass7__migrateTemplateReferences(
4141
}
4242
seenFileReferences.add(fileReferenceId);
4343

44-
// TODO: Control flow, or wait for Joost's PR?
45-
4644
// Expand shorthands like `{bla}` to `{bla: bla()}`.
4745
const appendText = reference.from.isObjectShorthandExpression
4846
? `: ${reference.from.read.name}()`

packages/core/schematics/migrations/signal-migration/test/golden-test/catalyst_test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ class MyComp {
1414

1515
it('should work', () => {
1616
const inputs = {
17-
hello: 'Damn',
18-
// TODO:
17+
hello: 'test',
1918
} as Partial<MyComp>;
2019
bootstrapTemplate('<my-comp [hello]="hello">', inputs);
2120
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// tslint:disable
2+
3+
import {Input, Directive} from '@angular/core';
4+
5+
@Directive()
6+
export class MyComp {
7+
@Input() firstName: string;
8+
9+
constructor() {
10+
// TODO: Consider initializations inside the constructor.
11+
// Those are not migrated right now though, as they are writes.
12+
this.firstName = 'Initial value';
13+
}
14+
}

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,26 @@ class MyComp {
9292

9393
it('should work', () => {
9494
const inputs = {
95-
hello: 'Damn',
96-
// TODO:
95+
hello: 'test',
9796
} as Partial<UnwrapSignalInputs<MyComp>>;
9897
bootstrapTemplate('<my-comp [hello]="hello">', inputs);
9998
});
99+
@@@@@@ constructor_initializations.ts @@@@@@
100+
101+
// tslint:disable
102+
103+
import {Input, Directive} from '@angular/core';
104+
105+
@Directive()
106+
export class MyComp {
107+
@Input() firstName: string;
108+
109+
constructor() {
110+
// TODO: Consider initializations inside the constructor.
111+
// Those are not migrated right now though, as they are writes.
112+
this.firstName = 'Initial value';
113+
}
114+
}
100115
@@@@@@ cross_references.ts @@@@@@
101116

102117
// tslint:disable

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,26 @@ class MyComp {
9292

9393
it('should work', () => {
9494
const inputs = {
95-
hello: 'Damn',
96-
// TODO:
95+
hello: 'test',
9796
} as Partial<UnwrapSignalInputs<MyComp>>;
9897
bootstrapTemplate('<my-comp [hello]="hello">', inputs);
9998
});
99+
@@@@@@ constructor_initializations.ts @@@@@@
100+
101+
// tslint:disable
102+
103+
import { Directive, input } from '@angular/core';
104+
105+
@Directive()
106+
export class MyComp {
107+
readonly firstName = input<string>();
108+
109+
constructor() {
110+
// TODO: Consider initializations inside the constructor.
111+
// Those are not migrated right now though, as they are writes.
112+
this.firstName = 'Initial value';
113+
}
114+
}
100115
@@@@@@ cross_references.ts @@@@@@
101116

102117
// tslint:disable

0 commit comments

Comments
 (0)