Skip to content

fix(emit): spread arguments in calls and new are dropped (f(...P) → f(P)) #511

Description

@Brooooooklyn

When decorator metadata is copied into the output, ... in call and new arguments is lost. This changes runtime behavior, not only the setClassMetadata copy. For example, providers: f(...P) is emitted as ɵɵProvidersFeature(f(P)).

Repro

import {Component} from '@angular/core';
const P: any[] = [];
function f(...a: any[]) { return a; }
class Box { constructor(...a: any[]) {} }
@Component({selector: 'c', template: '', providers: f(...P)})
export class C {}
@Component({selector: 'c2', template: '', providers: [{provide: 'T', useValue: new Box(...P)}, ...P]})
export class C2 {}

OXC (main and #504 tip)

features:[i0.ɵɵProvidersFeature(f(P))]
// setClassMetadata
args:[{selector:"c",template:"",providers:f(P)}]
// C2
i0.ɵɵProvidersFeature([{provide:"T",useValue:new Box(P)},...P])

ngtsc 22.1.7

features: [i0.ɵɵProvidersFeature(f(...P))]
args: [{ selector: 'c', template: '', providers: f(...P) }]
i0.ɵɵProvidersFeature([{ provide: 'T', useValue: new Box(...P) }, ...P])

Array spread (...P in an array) is already kept.

Where

crates/oxc_angular_compiler/src/output/oxc_converter.rs (main): convert_call_expression_with_optional and convert_new_expression turn Argument::SpreadElement into its plain argument. They should wrap it in OutputExpression::SpreadElement, as the array path does.

Also (shape only)

A member with only non-Angular decorators is left out of the setClassMetadata prop map. ngtsc lists it with an empty array:

function Foo(): PropertyDecorator { return () => {}; }
@Component({selector: 'c', template: ''})
export class C { @Foo() x: any; @Input() y: any; }
  • OXC: {y:[{type:Input}]}
  • ngtsc: { x: [], y: [{ type: Input }] }

Only the shape differs: the entry is an empty decorator list. Worth matching only if the compare suite needs it.

On main?

Yes, both.

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