Arrows copied from decorator metadata into the output lose parameter defaults and the async keyword. This changes runtime behavior: an async factory returns a value instead of a Promise, and a default value is no longer applied.
Repro
import {Component, Directive, Input} from '@angular/core';
@Directive({selector: '[d]'})
export class D {
@Input({transform: (v: string = 'a') => v.length}) a = 0;
@Input({transform: async (v: any) => 1}) b: any;
}
@Component({selector: 'c', template: '', providers: [{provide: 'T', useFactory: async (x: number = 1) => x}]})
export class C {}
OXC (main and #504 tip)
inputs:{a:[2,"a","a",(v) =>v.length],b:[2,"b","b",(v) =>1]}
// setClassMetadata
{a:[{type:Input,args:[{transform:(v) =>v.length}]}],b:[{type:Input,args:[{transform:(v) =>1}]}]}
i0.ɵɵProvidersFeature([{provide:"T",useFactory:(x) =>x}])
ngtsc 22.1.7
inputs: { a: [2, "a", "a", (v = 'a') => v.length], b: [2, "b", "b", async (v) => 1] }
{ a: [{ type: Input, args: [{ transform: (v = 'a') => v.length }] }], b: [{ type: Input, args: [{ transform: async (v) => 1 }] }] }
i0.ɵɵProvidersFeature([{ provide: 'T', useFactory: async (x = 1) => x }])
The .d.ts is already correct on the stack (ngAcceptInputType_a: string, ngAcceptInputType_b: any).
Where
crates/oxc_angular_compiler/src/output/oxc_converter.rs (main), convert_arrow_function_expression:
- It reads only
param.pattern (a BindingIdentifier) and ignores the parameter's default value.
- It ignores
arrow.r#async.
ArrowFunctionExpr (output/ast.rs) has no field for either. The function-expression path is worth checking for the same issue.
On main?
Yes.
Direction
Add async and default values to the output AST, or fall back to raw source (types stripped) when the arrow uses either, as is already done for destructured params.
Arrows copied from decorator metadata into the output lose parameter defaults and the
asynckeyword. This changes runtime behavior: anasyncfactory returns a value instead of a Promise, and a default value is no longer applied.Repro
OXC (main and #504 tip)
ngtsc 22.1.7
The
.d.tsis already correct on the stack (ngAcceptInputType_a: string,ngAcceptInputType_b: any).Where
crates/oxc_angular_compiler/src/output/oxc_converter.rs(main),convert_arrow_function_expression:param.pattern(aBindingIdentifier) and ignores the parameter's default value.arrow.r#async.ArrowFunctionExpr(output/ast.rs) has no field for either. The function-expression path is worth checking for the same issue.On main?
Yes.
Direction
Add
asyncand default values to the output AST, or fall back to raw source (types stripped) when the arrow uses either, as is already done for destructured params.