Skip to content

fix: listener handler_expression should generate tmp variable declarations in handler scope#8

Merged
Brooooooklyn merged 2 commits intomainfrom
02-04-fix_listener_tmp_variable_declarations
Feb 4, 2026
Merged

fix: listener handler_expression should generate tmp variable declarations in handler scope#8
Brooooooklyn merged 2 commits intomainfrom
02-04-fix_listener_tmp_variable_declarations

Conversation

@Brooooooklyn
Copy link
Copy Markdown
Member

@Brooooooklyn Brooooooklyn commented Feb 4, 2026

handler_expression was being processed without the IN_CHILD_OPERATION flag, causing temporary variables to be scoped to the parent create block instead of the listener function. This meant let tmp_N_0; declarations were missing inside listener functions that use safe navigation on function call receivers (e.g., getPopover()?.close()).


Note

Medium Risk
Touches the compiler’s IR traversal and temporary-variable generation for event listeners, which can change emitted code and temp var naming in templates with safe navigation. Scope is narrow but could affect listener output across templates.

Overview
Fixes listener compilation so CreateOp::Listener.handler_expression is treated as part of the handler (child operation) scope during expression traversal, aligning visitor/transform flags with handler_ops.

Updates the temporary_variables phase to generate temp-variable names/declarations for handler_expression together with handler_ops (with the correct op index ordering), ensuring safe-navigation on call receivers inside listeners emits let tmp_N_0; inside the listener function.

Adds integration tests + snapshots covering safe calls/property reads in listeners, including the embedded-view (@if) case to validate correct temp naming (tmp_2_0).

Written by Cursor Bugbot for commit ac7b95c. This will update automatically on new commits. Configure here.

…tions in handler scope

handler_expression was being processed without the IN_CHILD_OPERATION flag,
causing temporary variables to be scoped to the parent create block instead
of the listener function. This meant `let tmp_N_0;` declarations were missing
inside listener functions that use safe navigation on function call receivers
(e.g., `getPopover()?.close()`).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Comment thread crates/oxc_angular_compiler/src/pipeline/phases/temporary_variables.rs Outdated
…tmp declarations

handler_expression was being processed inside the per-op loop, causing it
to be visited/transformed once per handler_op. When handler_ops had multiple
entries (e.g., restoreView + nextContext), this produced spurious declarations
(let tmp_0_0; let tmp_1_0;) and wrong variable names.

Now handler_expression is processed once after the loop with op_count set to
handler_ops.len(), matching Angular TS where the return expression is the last
entry in handlerOps. For a listener with 2 handler_ops, this correctly
generates tmp_2_0 instead of tmp_1_0.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Brooooooklyn Brooooooklyn merged commit 8100484 into main Feb 4, 2026
3 checks passed
@Brooooooklyn Brooooooklyn deleted the 02-04-fix_listener_tmp_variable_declarations branch February 4, 2026 09: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.

1 participant