Skip to content

fix(vite-plugin-angular): emit unary operators by operator and position - #2606

Merged
brandonroberts merged 2 commits into
analogjs:betafrom
AyeshaWaseemAhmad:fix/emit-unary-operators
Oct 8, 2026
Merged

brandonroberts merged 2 commits into
analogjs:betafrom
AyeshaWaseemAhmad:fix/emit-unary-operators

Conversation

@AyeshaWaseemAhmad

Copy link
Copy Markdown
Contributor

PR Checklist

Closes #2593

Affected scope

  • Primary scope: vite-plugin-angular
  • Secondary scopes: none

Recommended merge strategy for maintainer [optional]

  • Squash merge
  • Rebase merge
  • Other

What is the new behavior?

visitUnaryOperatorExpr returned -(operand) for every UnaryOperatorExpr. Unary plus was emitted as negation, and the ++ and -- operators that Angular adds to the output AST in 22.3 (count++, --count) were emitted as negation without an error, so the handler or binding never changed the value.

The visitor now looks the operator up in UNARY_OP_STR, built at module load from the UnaryOperator members present on the installed @angular/compiler, as BINARY_OP_STR is. It uses isPrefix when present to place the operator before or after the operand. An operator missing from the table throws a [fast-compile] Unsupported UnaryOperator ... error, as visitBinaryOperatorExpr does, instead of emitting wrong code. The operand stays parenthesized as before: -(x) is unchanged, and the new forms are +(x), ++(x) and (x)--.

js-emitter.spec.ts covers unary plus and minus, operand parenthesization, the unsupported-operator error, and prefix and postfix increment and decrement on Angular versions that define them.

Test plan

  • vitest run in packages/vite-plugin-angular with the installed @angular/compiler 22.2.0: 805 passed, 10 skipped. The four increment and decrement tests are skipped there because the enum members do not exist.
  • The same run with @angular/compiler 22.3.0-next.1 swapped in: 809 passed, 6 skipped, including the four increment and decrement tests. Against the previous emitter, six of the new tests fail on 22.3.0-next.1 and two on 22.2.0.
  • prettier --check and tsc --noEmit on the library and spec projects are clean. eslint reports one existing no-useless-escape error on SINGLE_QUOTE_ESCAPE_RE, which this change does not touch.
  • Not run: nx format:check, pnpm build and the full pnpm test.

Does this PR introduce a breaking change?

  • Yes
  • No

visitUnaryOperatorExpr returned -(operand) for every UnaryOperatorExpr, so
unary plus was emitted as negation and the increment/decrement operators that
Angular adds in 22.3 (count++, --count) were emitted as negation with no
error. Look the operator up in a table built from the UnaryOperator members
that exist on the installed @angular/compiler, honor isPrefix when present,
and throw for an operator the installed version does not define instead of
emitting wrong code.

Closes analogjs#2593
@netlify

netlify Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for analog-blog ready!

Name Link
🔨 Latest commit 84489a3
🔍 Latest deploy log https://app.netlify.com/projects/analog-blog/deploys/6ac7f410e5df210008e14477
😎 Deploy Preview https://deploy-preview-2606--analog-blog.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for analog-app ready!

Name Link
🔨 Latest commit 84489a3
🔍 Latest deploy log https://app.netlify.com/projects/analog-app/deploys/6ac7f410a059970008902e3a
😎 Deploy Preview https://deploy-preview-2606--analog-app.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for analog-docs ready!

Name Link
🔨 Latest commit 84489a3
🔍 Latest deploy log https://app.netlify.com/projects/analog-docs/deploys/6ac7f41005fa07000824f85c
😎 Deploy Preview https://deploy-preview-2606--analog-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot added the scope:vite-plugin-angular Changes in @analogjs/vite-plugin-angular label Oct 8, 2026
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: analogjs/analog/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: abbc3138-46a3-4d29-9ef8-55bae5223697
📥 Commits

Reviewing files that changed from the base of the PR and between 044fa17 and 84489a3.

📒 Files selected for processing (4)
  • packages/vite-plugin-angular/src/lib/compiler/angular-version.ts
  • packages/vite-plugin-angular/src/lib/compiler/component.spec.ts
  • packages/vite-plugin-angular/src/lib/compiler/js-emitter.spec.ts
  • packages/vite-plugin-angular/src/lib/compiler/js-emitter.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The unary operator emitter now maps supported Angular operators to JavaScript tokens. It emits unary plus and minus, and emits increment and decrement in prefix or postfix form according to isPrefix. Unsupported operator values produce an error that includes the compiler version. Tests cover operator formatting, parenthesized operands, unsupported values, and increment/decrement when the installed Angular version defines them. Component compiler tests also check emitted event-handler expressions and TypeScript syntax diagnostics.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 84489

No actionable merge-blocking issue is identified for the current change; it is mergeable after normal checks.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the unary-operator emission changes, compatibility behavior across Angular versions, tests, and validation results.
Title check ✅ Passed The title follows the preferred Conventional Commit format and accurately summarizes the vite-plugin-angular change.
Linked Issues check ✅ Passed Issue #2593 requires correct fastCompile emission for unary plus/minus and Angular 22.3 increment/decrement operators, including prefix and postfix placement, older compiler compatibility, and no sile…
Out of Scope Changes check ✅ Passed The changes remain within vite-plugin-angular fastCompile unary emission and its supporting capability logic and tests. The test additions directly verify the requirements in issue #2593. No unrelat…
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

@nx-cloud

nx-cloud Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 84489a3

Command Status Duration Result
nx run-many --target e2e --projects=analog-app-... ✅ Succeeded 46s View ↗
nx run-many --target test ✅ Succeeded 1m 33s View ↗
nx run-many --target build --all --parallel=1 -... ✅ Succeeded 1m 58s View ↗
nx run-many --target lint --all --exclude=conte... ✅ Succeeded 1m 28s View ↗
nx-cloud record -- pnpm prettier:check ✅ Succeeded 7s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-10-08 19:57:55 UTC

@brandonroberts brandonroberts left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Requesting changes to preserve grouping when unary-expression results are used in member access. Reproduced with Angular 22.3.0-next.1; details below.

The emitted operand was parenthesized but the unary expression itself was not,
so using its result as a member receiver changed the grouping. With Angular
22.3, (count++).toString() was emitted as (ctx.count)++.toString(), a
SyntaxError, and (++count).toString() as ++(ctx.count).toString(), which
increments the result of toString() and throws a ReferenceError. Unary minus
had the same problem: -(x).toString() negated the result of toString().

Wrap the complete expression, e.g. ((ctx.count)++).toString(). Test the
composition at the emitter level by executing the emitted code, and at the
template level by checking the emitted listener and parsing the compiled
output. Share the increment/decrement capability check from angular-version.

@brandonroberts brandonroberts left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verified the full-expression grouping fix and regression tests. Targeted emitter/component tests pass on Angular 22.2.0 and 22.3.0-next.1, including prefix/postfix mutation and member access. The earlier correctness finding is resolved.

@brandonroberts
brandonroberts merged commit 4f3fd76 into analogjs:beta Oct 8, 2026
30 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope:vite-plugin-angular Changes in @analogjs/vite-plugin-angular

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vite-plugin-angular: fastCompile does not handle increment/decrement (++/--) template operators

2 participants