Skip to content

fix: apply unary operators after member access - #36

Merged
hustcc merged 4 commits into
antvis:mainfrom
trackoor:fix-unary-member-access
Nov 19, 2026
Merged

hustcc merged 4 commits into
antvis:mainfrom
trackoor:fix-unary-member-access

Conversation

@trackoor

@trackoor trackoor commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Fixes #35.

parsePrimary parsed the operand of ! / - as a bare primary, so the .prop / [i] suffix was attached to the unary expression afterwards and !d.active became (!d).active. Now the member accesses are parsed into the operand before the unary node is built, so !d.active is !(d.active) and -d.value is -(d.value), as in JavaScript.

Added a parser test for the AST of !a.b and evaluation tests for the cases from the issue (!d.active, !arr[0], -d.value, plus !!arr[1], -d.value + 20 and -(d).value). All 158 tests pass and biome check is clean.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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

@trackoor

trackoor commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Heads-up: the build job fails in pnpm install before any tests run (the newer pnpm on the runner refuses the build scripts of @biomejs/biome and esbuild: ERR_PNPM_IGNORED_BUILDS), so it is unrelated to this change. Locally vitest run passes (158 tests) and biome check is clean.

@hustcc

hustcc commented Nov 12, 2026

Copy link
Copy Markdown
Member

Heads-up: the build job fails in pnpm install before any tests run (the newer pnpm on the runner refuses the build scripts of @biomejs/biome and esbuild: ERR_PNPM_IGNORED_BUILDS), so it is unrelated to this change. Locally vitest run passes (158 tests) and biome check is clean.

help to fix the ci in this pr.

@trackoor

Copy link
Copy Markdown
Contributor Author

Fixed the CI in this PR with two small changes:

  • pnpm-workspace.yaml allows the @biomejs/biome and esbuild build scripts, which fixes the ERR_PNPM_IGNORED_BUILDS failure in pnpm install.
  • typescript ^5.9.3 is now a dev dependency. Without it pnpm installs TypeScript 7 as the peer of @rollup/plugin-typescript, and rollup -c crashes while loading the config.

With pnpm latest I ran install, biome check, the tests, the build and the benchmark locally, and all of them pass.

@hustcc

hustcc commented Nov 19, 2026

Copy link
Copy Markdown
Member

ci is error.

@hustcc
hustcc merged commit 80122ea into antvis:main Nov 19, 2026
1 check passed
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.

!d.active returns undefined, and -d.value throws: unary operators bind before member access

3 participants