Skip to content

fix(partial): strip brackets from host binding keys - #682

Open
benjavicente wants to merge 1 commit into
voidzero-dev:mainfrom
benjavicente:fix/partial-host-binding-keys
Open

benjavicente wants to merge 1 commit into
voidzero-dev:mainfrom
benjavicente:fix/partial-host-binding-keys

Conversation

@benjavicente

Copy link
Copy Markdown

🤖 Made by agents
🙋‍♂️ Reviewed by human: I'm not that familiar with the codebase, but reviewing the structure of the fix it looks like a decent fix. Did a pass with multiple agents reviews to be sure. Tested the fix with a library.

Fixes #680

Summary: in partial mode, host.listeners / host.properties kept the (…) / […] of their host: keys. Angular's linker then listened for an event named (click), set a property named [attr.x], and failed the build on (window:resize) (Unexpected global target '(window'). This PR writes bare names, as ngtsc's parseHostBindings does.

Changes

  • partial/directive.rs and partial/component.rs strip the brackets with the existing strip_host_key when writing listeners / properties. The full compilation already did this.
  • Everything after the brackets (keydown.shift.tab, window: / document: targets, attr. / class. / style.height.px, @trigger animations) stays for the linker to parse, as with ngtsc.

Tests

  • partial_directive_test.rs: the host test now uses the bracketed keys the pipeline produces.
  • New partial-host-bindings.test.ts: links partial directives and components with Angular's linker and with Oxc's, and checks the generated host instructions. The Angular-linker cases fail without this fix.

Reproduction: https://github.com/benjavicente/oxc-angular-repro-partial-host-keys

The partial `host` kept the binding syntax of each `host:` key, emitting
`listeners: { "(click)": … }` and `properties: { "[attr.x]": … }`. ngtsc's
`parseHostBindings` keys them by the bare name (`click`, `attr.x`), and the
linker parses that name the way a full compilation parses a `host:` key
after removing its brackets. Angular's linker therefore bound a `(click)`
event and a `[attr.x]` property, and rejected `(window:resize)` with
"Unexpected global target '(window'".

Strip the brackets when writing the partial `listeners` / `properties` of
directives and components, as the full compilation already does.

Fixes voidzero-dev#680
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.

compilationMode: 'partial' keeps template syntax in host binding keys ("(click)", "[attr.x]")

1 participant