Skip to content

Conversation

@ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Dec 13, 2025

This PR modifies our reparse strategy for @type and @satisfies assertions. Previously, we'd generate an ast.AsExpression or ast.SatisfiesExpression containing clones of the target expression and type, and mark all of them as ast.NodeFlagsReparsed. This had the unfortunate effect of "hiding" the target expression because it would now only occur in the AST as a reparsed node. With this PR, we still generate an ast.AsExpression or ast.SatisfiesExpression, but we no longer mark it as reparsed. We re-parent the target expression into the assertion node, but still clone the target type and mark it as ast.NodeFlagsReparsed. So, the AST reflects a normal ast.AsExpression or ast.SatisfiesExpression with an Expression child that is the original expression and Type child that is marked ast.NodeFlagsReparsed. This flag on the Type node makes it simple to detect the transformation, should that be necessary.

With this PR we have the nice property that reparsed nodes can consistently be ignored in AST walks.

The PR also contains:

  • A panic that occurs if ast.GetOrCreateToken is called with a parent marked ast.NodeFlagsReparsed. Tokens should never be created from reparsed nodes.
  • The node visitor in addRegionOutliningSpans is modified to skip over reparsed nodes.
  • Fixed error spans on @satisfies assertions to be consistent with errors spans on @type assertions.

Fixes #2245.
Fixes #2289.
Fixes #2346.

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

This seems like what we discussed; I am not sure how to reconcile #2371 with it, though.

@ahejlsberg ahejlsberg added this pull request to the merge queue Dec 13, 2025
@ahejlsberg
Copy link
Member Author

I am not sure how to reconcile #2371 with it, though.

Actually, #2371 becomes simpler because we no longer need logic to track "special" reparsed nodes. The shouldVisitNode function just becomes a simple check that the node isn't reparsed.

Merged via the queue into main with commit 92c21db Dec 13, 2025
28 checks passed
@ahejlsberg ahejlsberg deleted the reparse-fixes branch December 13, 2025 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants