fix: keep object methods, accessors and computed keys in decorator metadata - #498
Conversation
…tadata
Object literals in decorator metadata lost any member that is not a plain
`key: value` pair. `{ attach() {} }` compiled to the invalid `{attach:() {}}`,
`get`/`set`/`async`/`*` were dropped, and computed keys disappeared, with no
error. Such objects are now kept as written, with TypeScript types stripped,
as ngtsc does. Type stripping also failed for objects because codegen drops
the redundant parentheses the unwrap relied on, and an arrow returning such an
object now keeps the parentheses around its body.
When a component's resources are inlined, its metadata object in
`setClassMetadata` is rebuilt from the plain properties only, matching ngtsc's
`transformDecoratorResources`.
Methods and accessors on a decorator's own options object, such as
`@Injectable({ useFactory() {} })` or `@ViewChild('x', { get read() {} })`,
were read as `key: value` pairs and emitted as invalid code. Like ngtsc's
`reflectObjectLiteral`, they are now ignored.
6b7827e to
3b88a9c
Compare
|
Rebased onto main (conflict in One test needed an update: All |
Object literals in decorator metadata lost any member that is not a plain
key: valuepair. This is on 0.0.39 and main:{ attach() {} }compiled to the invalid{attach:() {}}.get,set,asyncand*were lost.No error was reported. The cause is
convert_object_expressioninoutput/oxc_converter.rs, which every re-emitted field goes through:providers,viewProviders,animations, NgModule and@Injectablemetadata, andsetClassMetadata.() => ({ a() {} }), now keeps the parentheses around its body.@Injectable({ useFactory() {} })or@ViewChild('x', { get read() {} }), were read as values and emitted as invalid code. Like ngtsc'sreflectObjectLiteral, they are now ignored.When a component's resources are inlined, its metadata object in
setClassMetadatais rebuilt from the plain properties only, matching ngtsc'stransformDecoratorResources.@Inputoptions are evaluated rather than reflected, so ngc rejects@Input({ transform(v) {} })with NG1010; oxc reports the same error.Tests
input/model/output/viewChildoptions), BigInt keys, and a component that combines accessors withtemplateUrl. Expected output is taken from ngc 22.Compiling 2,678 decorated files from real-world Angular repos gives byte-identical output to main in both AOT and JIT mode, with no measurable change in compile time.