Skip to content

fix(compiler): ignore @HostBinding/@HostListener on static members - #545

Merged
Brooooooklyn merged 1 commit into
mainfrom
fix/issue-544-static-host-bindings
Oct 6, 2026
Merged

Brooooooklyn merged 1 commit into
mainfrom
fix/issue-544-static-host-bindings

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Fixes #544.

Problem

@HostBinding/@HostListener on static members were collected as real host bindings: extract_host_bindings_in/extract_host_listeners_in never checked r#static, so @HostBinding('class.b') static b emitted ɵɵclassProp("b", ctx.b) and inflated hostVars, while ngtsc's filterToMembersWithDecorator (!member.isStatic, typescript.ts:621, used by directive/src/shared.ts:626,693) ignores static members entirely.

Change

Both extractors now carry r#static through the element match and continue on static members. Private #x members were already unreachable (get_property_key_name returns None for PrivateIdentifier, and decorators can't appear on private elements anyway).

Testing

  • New test_static_host_binding_and_listener_are_ignored: instance @HostBinding('class.a') + @HostListener('click') still emit; static counterparts produce no classProp/listener and hostVars drops 4→2.
  • cargo test -p oxc_angular_compiler: 2944 passed, 0 failed; conformance 1264/1264.
  • Verified end-to-end via transformAngularFileSync: the static b/scroll entries are gone from hostBindings while a/click remain.

ngtsc's `filterToMembersWithDecorator` filters `!member.isStatic` before
collecting decorated members, so `@HostBinding('class.b') static b` and
`@HostListener('scroll') static onScroll()` never become host bindings
upstream (packages/compiler-cli src/ngtsc/reflection/src/typescript.ts,
used by directive/src/shared.ts:626,693).

OXC's `extract_host_bindings_in`/`extract_host_listeners_in` didn't check
`r#static`, so a decorated static member emitted a `ɵɵclassProp`/`ɵɵlistener`
and was counted in `hostVars`. Both extractors now skip static class
elements, matching upstream. Private (`#x`) members can't carry
decorators and were already unreachable via `get_property_key_name`.

Fixes #544
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@Brooooooklyn
Brooooooklyn merged commit 9af6868 into main Oct 6, 2026
10 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/issue-544-static-host-bindings branch October 6, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(aot): @HostBinding/@HostListener on static or private members should be excluded

1 participant