Skip to content

fix(emit): arrow functions in metadata lose default parameter values and async #512

Description

@Brooooooklyn

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions