8000 fix(compiler-cli): handle initializer APIs wrapped in type casts (#62… · angular/angular@d25a6a0 · GitHub
[go: up one dir, main page]

Skip to content

Commit d25a6a0

Browse files
committed
fix(compiler-cli): handle initializer APIs wrapped in type casts (#62203)
Fixes that the logic recognizing initializer APIs didn't account for the expression being wrapped in an `as` expresion or in a parenthesized expression. This was already accounted for in the diagnostic so these changes align the behavior between them. Fixes #62197. PR Close #62203
1 parent 223279e commit d25a6a0

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

packages/compiler-cli/src/ngtsc/annotations/directive/src/initializer_functions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ export function tryParseInitializerApi<Functions extends InitializerApiFunction[
8282
reflector: ReflectionHost,
8383
importTracker: ImportedSymbolsTracker,
8484
): (InitializerFunctionMetadata & {api: Functions[number]}) | null {
85+
if (ts.isAsExpression(expression) || ts.isParenthesizedExpression(expression)) {
86+
return tryParseInitializerApi(functions, expression.expression, reflector, importTracker);
87+
}
88+
8589
if (!ts.isCallExpression(expression)) {
8690
return null;
8791
}

packages/compiler-cli/test/ngtsc/authoring_inputs_spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,5 +433,39 @@ runInEachFileSystem(() => {
433433
expect(diagnostics.length).toBe(0);
434434
});
435435
});
436+
437+
it('should resolve input inside an `as` expression', () => {
438+
env.write(
439+
'test.ts',
440+
`
441+
import {Directive, input, Signal} from '@angular/core';
442+
443+
@Directive()
444+
export class TestDir {
445+
data = input('test') as Signal<string>;
446+
}
447+
`,
448+
);
449+
env.driveMain();
450+
const js = env.getContents('test.js');
451+
expect(js).toContain('inputs: { data: [1, "data"] }');
452+
});
453+
454+
it('should resolve input inside a parenthesized expression', () => {
455+
env.write(
456+
'test.ts',
457+
`
458+
import {Directive, input, Signal} from '@angular/core';
459+
460+
@Directive()
461+
export class TestDir {
462+
data = ((input('test')));
463+
}
464+
`,
465+
);
466+
env.driveMain();
467+
const js = env.getContents('test.js');
468+
expect(js).toContain('inputs: { data: [1, "data"] }');
469+
});
436470
});
437471
});

0 commit comments

Comments
 (0)
0