Repository navigation
fix: apply unary operators after member access - #36
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the member-access precedence fix.
No open issues 🎉
What changed in this PR
Fixes #35 by making member access bind more tightly than unary ! and -, matching JavaScript behavior in the expression parser.
Changes:
- Parses dot and bracket member accesses before constructing unary expressions.
- Adds an AST regression test for
!a.b. - Adds evaluation tests covering member access, nested unary operators, conditionals, arithmetic, and parentheses.
| File | Description |
|---|---|
| tests/parser.test.ts | Verifies that !a.b produces the correct unary-expression AST. |
| tests/api-integration.test.ts | Covers evaluation of unary operators applied to member-access results. |
| src/parser.ts | Parses member-access suffixes into the unary operand before building the unary node. |
Review effort: Balanced
|
Heads-up: the build job fails in |
help to fix the ci in this pr. |
|
Fixed the CI in this PR with two small changes:
With pnpm latest I ran install, |
|
ci is error. |
Fixes #35.
parsePrimaryparsed the operand of!/-as a bare primary, so the.prop/[i]suffix was attached to the unary expression afterwards and!d.activebecame(!d).active. Now the member accesses are parsed into the operand before the unary node is built, so!d.activeis!(d.active)and-d.valueis-(d.value), as in JavaScript.Added a parser test for the AST of
!a.band evaluation tests for the cases from the issue (!d.active,!arr[0],-d.value, plus!!arr[1],-d.value + 20and-(d).value). All 158 tests pass andbiome checkis clean.