fix: keep object methods, accessors and computed keys in decorator metadata - #498
Open
ashley-hunter wants to merge 1 commit into
Open
ashley-hunter wants to merge 1 commit into
ashley-hunter wants to merge 1 commit into
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.One remaining difference: ngc rejects
@Input({ transform(v) {} })with NG1010. oxc now ignores the method rather than reporting the 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.