Repository navigation
Preserve synthesized node ranges across API serialization - #64903
Merged
Andrew Branch (andrewbranch) merged 3 commits intoNov 19, 2026
Merged
Conversation
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix printer attaching source comments to synthesized nodes
Preserve synthesized node ranges across API serialization
Oct 21, 2026
…fix-printer-source-comments # Conflicts: # packages/typescript/src/api/node/encoder.ts # packages/typescript/src/api/node/node.generated.ts # packages/typescript/test/async/api.test.ts # packages/typescript/test/encoder.test.ts # packages/typescript/test/sync/api.test.ts # tools/scripts/tsc/generate-encoder.ts Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Printing updated source files through printNode or printFile drops the leading shebang because the updated root’s synthetic ranges cause shebang emission to be skipped.
1 open issue
What changed in this PR
This PR addresses #64859 by preserving synthesized AST ranges across API serialization, preventing the printer from attaching source comments to newly created nodes.
Changes:
- Preserve node and node-list ranges instead of clamping negative positions to zero.
- Decode positions as signed 32-bit values in Go and JavaScript node-list accessors.
- Add range round-trip tests and async/sync printer regressions for comment preservation.
| File | Description |
|---|---|
tsc/internal/api/encoder/decoder.go |
Decode node and list positions as signed integers. |
tsc/internal/api/encoder/decoder_test.go |
Verify synthesized ranges survive Go decoding. |
tools/scripts/tsc/generate-encoder.ts |
Generate signed node-list range accessors. |
packages/typescript/test/sync/api.test.ts |
Add synchronous printer comment-preservation regression. |
packages/typescript/test/encoder.test.ts |
Test synthesized node and list range round-trips. |
packages/typescript/test/async/api.test.ts |
Add asynchronous printer comment-preservation regression. |
packages/typescript/src/api/node/node.generated.ts |
Read remote node-list ranges as signed integers. |
packages/typescript/src/api/node/encoder.ts |
Preserve root, child, and list ranges during encoding. |
Review effort: Balanced
Comment on lines
+307
to
+308
| node.pos, | ||
| node.end, |
There was a problem hiding this comment.
I don't think this is actionable until #65447 is in
Andrew Branch (andrewbranch)
requested a review
from Jake Bailey (jakebailey)
November 18, 2026 23:27
Jake Bailey (jakebailey)
approved these changes
Nov 18, 2026
Andrew Branch (andrewbranch)
deleted the
copilot/fix-printer-source-comments
branch
November 19, 2026 00:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The API encoder clamped synthesized ranges from
-1to0, causing the printer to attach source comments to synthesized nodes.