Skip to content

fix: parenthesize inlined values where they bind differently - #186

Closed
bardrop wants to merge 1 commit into
unplugin:mainfrom
bardrop:fix-parenthesize-inlined-values
Closed

bardrop wants to merge 1 commit into
unplugin:mainfrom
bardrop:fix-parenthesize-inlined-values

Conversation

@bardrop

@bardrop bardrop commented Nov 12, 2026

Copy link
Copy Markdown

Closes #182

Inlined values were written over the macro node as is, so some call sites parsed differently or not at all. parenthesize only handled an object at the head of an expression statement. It now also wraps the value when:

  • it is the object of a member expression and is a plain integer or starts with -/+: version().toFixed(1) -> (3).toFixed(1), offset().toString() -> (-1).toString() (was a parse error, or -(1).toString() if spaced)
  • it follows a unary operator and starts with -/+: -offset() -> -(-1) (was --1)
  • it is the right side of a binary -/+ and starts with -/+: 5-offset() -> 5-(-1) (was 5--1)
  • it is the left side of ** and is signed: (-1) ** 2
  • it is a concise arrow body and starts with {: () => defaults() -> () => ({ "mode": "prod" })

The statement-head check (with the ; guard) now also covers values that start with [, (, -, /, ... Before, list().forEach(...) on the line after let total = 0 became 0[1, 2].forEach(...), and a negative value or a regex at the start of a line was joined to the previous line in the same way.

Added a parenthesize.js fixture with every case. On main it fails with a parse error (Invalid characters after number, Cannot assign to this expression, Expected a semicolon). vitest run (46), eslint ., tsc --noEmit pass; other snapshots unchanged.

This touches the same file as #185 (the NaN/Infinity fix) but not the same lines.

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@bardrop

bardrop commented Nov 12, 2026

Copy link
Copy Markdown
Author

Closing this. It was made with an AI coding agent, and the contributing guide asks for PR text in a person's own words. Sorry for the noise. The issue and the test case above still show the bug, if it helps.

@bardrop bardrop closed this Nov 12, 2026
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.

Inlined macro values are not parenthesized, producing invalid syntax at some call sites

1 participant