Skip to content

Preserve synthesized node ranges across API serialization - #64903

Merged
Andrew Branch (andrewbranch) merged 3 commits into
mainfrom
copilot/fix-printer-source-comments
Nov 19, 2026
Merged

Andrew Branch (andrewbranch) merged 3 commits into
mainfrom
copilot/fix-printer-source-comments

Conversation

Copilot AI commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Encoding: Preserve ranges for roots, children, and node lists.
  • Decoding: Read ranges as signed 32-bit values in Go and generated JavaScript node-list accessors.
  • Coverage: Add range round-trip and async/sync printer regressions verifying original comments remain intact without duplication.

@typescript-automation typescript-automation Bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Oct 21, 2026
@typescript-automation typescript-automation Bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug and removed For Milestone Bug PRs that fix a bug with a specific milestone labels Oct 21, 2026
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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this is actionable until #65447 is in

@andrewbranch
Andrew Branch (andrewbranch) added this pull request to the merge queue Nov 19, 2026
Merged via the queue into main with commit fb1d462 Nov 19, 2026
35 checks passed
@andrewbranch
Andrew Branch (andrewbranch) deleted the copilot/fix-printer-source-comments branch November 19, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API] Printer attaches source comments to synthesized nodes because the node encoder sends pos -1 as 0

5 participants