Repository navigation
fix(vite-plugin-angular): emit unary operators by operator and position - #2606
Conversation
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
✅ Deploy Preview for analog-blog ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for analog-app ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for analog-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (4)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe 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 Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to 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)
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. Comment ✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
|
|
View your CI Pipeline Execution ↗ for commit 84489a3
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
brandonroberts
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
PR Checklist
Closes #2593
Affected scope
Recommended merge strategy for maintainer [optional]
What is the new behavior?
visitUnaryOperatorExprreturned-(operand)for everyUnaryOperatorExpr. 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 theUnaryOperatormembers present on the installed@angular/compiler, asBINARY_OP_STRis. It usesisPrefixwhen present to place the operator before or after the operand. An operator missing from the table throws a[fast-compile] Unsupported UnaryOperator ...error, asvisitBinaryOperatorExprdoes, 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.tscovers 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 runinpackages/vite-plugin-angularwith the installed@angular/compiler22.2.0: 805 passed, 10 skipped. The four increment and decrement tests are skipped there because the enum members do not exist.@angular/compiler22.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 --checkandtsc --noEmiton the library and spec projects are clean.eslintreports one existingno-useless-escapeerror onSINGLE_QUOTE_ESCAPE_RE, which this change does not touch.nx format:check,pnpm buildand the fullpnpm test.Does this PR introduce a breaking change?