typescript-go icon indicating copy to clipboard operation
typescript-go copied to clipboard

Reparse fixes

Open ahejlsberg opened this issue 2 weeks ago • 0 comments

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.

ahejlsberg avatar Dec 13 '25 00:12 ahejlsberg