Repository navigation
fix(compiler): lower all @angular/core member decorators into JIT propDecorators - #537
Merged
Merged
Conversation
…pDecorators In JIT mode, OXC dropped @angular/core member decorators that are not field decorators (@Inject, @optional, @Attribute, @self, @host, and even @component on a member) instead of lowering them into `static propDecorators` like ngtsc's `downlevel_decorators_transform` does. ngtsc's `isAngularDecorator` checks only `decorator.import.from === '@angular/core'` — the import decides, not the decorator name — and every matching member decorator (properties, methods, get/set accessors, static or instance) lands in `propDecorators` as `{type, args?}` in source order. Add `is_angular_core_decorator` (directive/property_decorators.rs), the nameless counterpart of `angular_core_decorator`: any named or default import from `@angular/core` (under any alias) or `ns.X()` through a namespace import qualifies. `extract_all_jit_member_decorators` now routes every core decorator into `propDecorators`; decorators from other modules keep going to `__decorate` as before. Also quote string-literal member keys ('x-y') in the emitted propDecorators object literal — previously they were spliced unquoted, producing invalid JS that made `strip_typescript` bail. Fixes #522
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
Fixes #522.
Problem
In JIT mode (
jit: true), OXC dropped@angular/coremember decorators that are not field decorators —@Inject,@Optional,@Attribute,@Self,@Host, and even@Componenton a member — instead of lowering them intostatic propDecoratorslike ngtsc'sdownlevel_decorators_transformdoes.Root cause
extract_all_jit_member_decoratorsbucketed member decorators into "field decorator →propDecorators", "inANGULAR_DECORATOR_NAMESbut not a field decorator → silently dropped", and "otherwise →__decorate". Upstream's gate isisAngularDecorator, which checks onlydecorator.import.from === '@angular/core'— the import decides, not the name — so every core decorator on a property/method/accessor (static or instance) lands inpropDecoratorsas{type: <written callee>, args?}in source order.Change
directive/property_decorators.rs: newis_angular_core_decorator— the nameless counterpart ofangular_core_decorator. Named imports under any alias, default imports, andns.X()throughimport * as ns from '@angular/core'all qualify; foreign/local/undeclared decorators do not.component/transform.rs: every@angular/coremember decorator now goes intopropDecorators; theANGULAR_DECORATOR_NAMESallowlist is deleted. Non-core decorators still go to__decorateunchanged.'x-y') are now quoted in the emittedpropDecoratorsobject literal — previously spliced unquoted, producing invalid JS that madestrip_typescriptbail.Example (issue repro)
Now emits (matching ngtsc 22.x):
Known remaining divergences (follow-ups, out of scope)
ctorParametersstill name-checks againstPARAM_DECORATORS; upstream appliesisAngularDecoratorto ctor params too.setClassMetadata.propDecoratorsstays field-decorator-only; upstreamdecoratedClassMemberToMetadatauses the import check there as well.Testing
cargo test -p oxc_angular_compiler: all green (~2900 tests), including a renamed/updatedtest_jit_angular_param_decorators_go_to_prop_decorators, an updated aliased-import test, and a newmember_decorators_from_angular_core_all_go_to_prop_decoratorscovering@Inject(T) @Optional(),@Attribute('a'), mixed@Input() @Inject(T), namespaced@core.Host()/@core.Component(), and string-literal keys.transformAngularFileSync(..., {jit: true})): the issue repro, static/method/accessor members, and aliased/namespace imports all emitpropDecoratorsmatching ngtsc.