Skip to content

Compute node bounds once at construction - #1865

Merged
TwitchBronBron merged 5 commits into
flatten-locationsfrom
construction-time-bounds
Oct 15, 2026
Merged

TwitchBronBron merged 5 commits into
flatten-locationsfrom
construction-time-bounds

Conversation

@TwitchBronBron

Copy link
Copy Markdown
Member

Stacked on #1845. Body, Block, AnnotationExpression and the literal expressions computed their bounds lazily, so a plugin editing the AST could change them after parsing. Bounds should describe where a node came from in the original source.

  • Every node now sets pos/end/source in its constructor from what it was given
  • Empty blocks get their bounds from the parent's constructor via Block.setBoundsBetween() (function, if/else, #if, for, for each, while, try/catch)
  • The parser builds Body after its statements are known, and sets annotation bounds once its call is attached
  • Also guards against combining offsets from two different sources for empty blocks

Verified with npm run test:nocover (new tests for each empty-block parent and for bounds surviving later AST edits).

🤖 Generated with Claude Code

TwitchBronBron and others added 2 commits October 2, 2026 16:07
Body, Block, AnnotationExpression and the literal expressions computed their bounds lazily, so plugin edits could change them after the fact. Every node now sets its bounds in its constructor from what it was given. Empty blocks get theirs from the parent's constructor via Block.setBoundsBetween(), and the parser builds Body after its statements are known.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
TwitchBronBron and others added 3 commits October 15, 2026 14:31
…tion-time-bounds

# Conflicts:
#	src/parser/AstNode.spec.ts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tion-time-bounds

# Conflicts:
#	src/parser/AstNode.spec.ts
#	src/parser/Expression.ts
#	src/parser/Statement.ts
@TwitchBronBron
TwitchBronBron marked this pull request as ready for review October 15, 2026 20:05
@TwitchBronBron
TwitchBronBron merged commit 5f2a19e into flatten-locations Oct 15, 2026
9 checks passed
@TwitchBronBron
TwitchBronBron deleted the construction-time-bounds branch October 15, 2026 20:06
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.

1 participant