Skip to content

Ensure nodes have real parents, fix parent race #970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 29, 2025

Conversation

andrewbranch
Copy link
Member

This is an alternative to #966 that doesn’t do any cloning. Any nodes that are shared between the real tree and reparsed nodes have parent pointers into the real tree.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
andrewbranch Andrew Branch
@andrewbranch andrewbranch requested review from Copilot and sandersn and removed request for Copilot May 28, 2025 23:07
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures that JSDoc import tags get real parent pointers during reparse and analysis, preventing races between the real AST and reparsed nodes.

  • Attach the newly constructed ImportDeclaration to its JSDocImportTag in the parser.
  • Update checker routines to handle KindJSDocImportTag when resolving import specifiers and module specifiers.
  • Amend the binder to avoid overwriting valid parents on reparsed nodes and add an JSImportDeclaration field in the AST type.

Reviewed Changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.

File Description
internal/parser/reparser.go Set JSImportDeclaration on JSDocImportTag nodes.
internal/checker/checker.go Handle KindJSDocImportTag in import resolution.
internal/binder/binder.go Only overwrite node.Parent for nil or reparsed flags.
internal/ast/ast.go Add JSImportDeclaration field to JSDocImportTag.

@@ -30,22 +30,22 @@ module.exports = Timer;
* @param {HookHandler} handle
*/
function Hook(handle) {
>Hook : (handle: HookHandler) => void
>handle : HookHandler
>Hook : (handle: (arg: any) => void) => void
Copy link
Member

Choose a reason for hiding this comment

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

the main different effect of this alternate-parent technique is that symbols no longer print as aliases. I'll need to figure out why when I start burning down the jsdoc diffs.

==== index.js (4 errors) ====
/**
* @typedef {{ [K in keyof B]: { fn: (a: A, b: B) => void; thing: B[K]; } }} Funcs
~
Copy link
Member

Choose a reason for hiding this comment

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

my best guess is that the something set the type expression parents to the synthetic type alias, inconsistent with other type expressions, and the binder change now makes it consistent with the others. I have a branch that sets Host on typedef children which should fix this.

Edit:actually it may be that all type aliases were working by mistake?

Copy link
Member

Choose a reason for hiding this comment

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

actually it may be that all typedefs were setting their type's parent to the synthetic node. Not in the reparser, though, so through the binder's existing code.

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

This is what we agreed on yesterday. Making parents consistently point to real nodes undoes the serendipitous binder set that makes typedefs work by mistake, but I have a fix for that.

I still need to figure out why symbols that resolve through synth-parent redirection no longer print as aliases. Since the type is right, it could be a quirk of the temp type printer.

@jakebailey
Copy link
Member

It's probably a temporary thing, though we'll see how much this affects the node builder and declaration emit PR.

@andrewbranch andrewbranch added this pull request to the merge queue May 29, 2025
@andrewbranch andrewbranch removed this pull request from the merge queue due to a manual request May 29, 2025
@andrewbranch
Copy link
Member Author

waiting for #791 to merge first, probably will have to update baselines

Verified

This commit was signed with the committer’s verified signature. The key has expired.
andrewbranch Andrew Branch

Verified

This commit was signed with the committer’s verified signature. The key has expired.
andrewbranch Andrew Branch
@andrewbranch
Copy link
Member Author

There seems to be a new logical conflict with #791 around declaration emit for JSDoc @import tags.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
andrewbranch Andrew Branch
@andrewbranch andrewbranch requested a review from jakebailey May 29, 2025 16:33
@andrewbranch andrewbranch added this pull request to the merge queue May 29, 2025
Merged via the queue into microsoft:main with commit 360255e May 29, 2025
23 checks passed
@andrewbranch andrewbranch deleted the bug/parent-race branch May 29, 2025 18:44
This was referenced May 29, 2025
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.

None yet

3 participants