Skip to content
This repository was archived by the owner on Sep 1, 2026. It is now read-only.

Remap JS type nodes in declaration emit to TS constructs or fallback to serialization - #3449

Merged
Wesley Wigham (weswigham) merged 1 commit into
microsoft:mainfrom
weswigham:js-decl-remapping
Apr 20, 2026
Merged

Wesley Wigham (weswigham) merged 1 commit into
microsoft:mainfrom
weswigham:js-decl-remapping

Conversation

@weswigham

Copy link
Copy Markdown
Member

Fixes part 1 (the bug part) of #2533 and handles #3402 as a side-effect.

With the reparser-focused approach, this was generally supposed to be getting handled in the reparser stage (if we supported them) - the js node remapping logic in the node builder was ported just because some bits of it were still port-able (and it's harmless to keep), so is what I'll say is "partially ported" compared to strada, since a ton of jsdoc node kinds were (and still are) outright missing, highlighting that we're in some weird middleground place right now where the AST isn't exactly like strada's, but nor is it fully handled upfront like we'd originally proposed for corsa.

Rather than deferring to that node builder logic like this, IMO, it'd be better to perform all these js-ts type node remappings at parse/reparse time, but since we're only doing a light touch of reparsing right now (object and signature types), this is where we're at, where some remapping logic lives in the parser/reparser so the checker can leverage it, and some in nodecopy for emit.

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@ahejlsberg

Copy link
Copy Markdown
Member

I'm not familiar with the "the js node remapping logic in the node builder". What does it do?

@weswigham

Copy link
Copy Markdown
Member Author

I'm not familiar with the "the js node remapping logic in the node builder". What does it do?

It's a big part of nodecopy.go (which is also concerned with sanity checking nodes copied into a new context behave the same way, which is actually the part that handles #3402) - it's logic in visitExistingNodeTreeSymbolsWorker that remaps jsdoc node kinds to TS ones and explicitly recognizes js-only type node patterns (for kinds that aren't inherently jsdoc only) and remaps them to the equivalent ts ones. Basically the AST equivalent of what the checker does when looking up types for one of these nodes (but rather than node-> type, it's node->node). There's also a bunch of partial-serialization fallback stuff that ended up getting added over time to better support ID, but that's mostly irrelevant here. There's a lot of comments in it for logic that doesn't seem to hold water anymore (either because of missing syntax kinds or intentional removals) that we used to do in strada. In theory it was all extraneous with the reparser strategy we set out initially (since anything js specific was set to be reparsed into TS constructs), but I ported what I could during the initial port just in case (after all, we could always go back and remove it later as dead code).

@weswigham
Wesley Wigham (weswigham) added this pull request to the merge queue Apr 20, 2026
Merged via the queue into microsoft:main with commit 74841e4 Apr 20, 2026
25 checks passed
@weswigham
Wesley Wigham (weswigham) deleted the js-decl-remapping branch April 20, 2026 21:15
Jake Bailey (jakebailey) pushed a commit to jakebailey/TypeScript that referenced this pull request Aug 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants