Skip to content

Conversation

@ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Nov 11, 2025

With this PR we use accessors on Node instead casts and field accesses whenever possible. For example, an expression like

exportClause.AsNamedExports().Elements.Nodes

simply becomes

exportClause.Elements()

This PR touches a lot of code but doesn't alter any behavior. However, a number of previously distinct code branches are merged and duplicate helpers are eliminated.

Copilot AI review requested due to automatic review settings November 11, 2025 01:00
Copilot finished reviewing on behalf of ahejlsberg November 11, 2025 01:02
Copy link
Contributor

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 refactors the codebase to use accessor methods on Node instead of direct type casts and field accesses. For example, exportClause.AsNamedExports().Elements.Nodes becomes exportClause.Elements(). The changes are extensive but mechanical, improving code readability and maintainability without altering behavior.

Key Changes:

  • Added new accessor methods in internal/ast/ast.go (StatementList(), Statement(), ElementList(), PostfixToken(), QuestionToken())
  • Replaced direct field accesses with accessor methods across the entire codebase
  • Consolidated duplicate code patterns (e.g., combining multiple case statements that use the same accessor)

Reviewed Changes

Copilot reviewed 58 out of 58 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/ast/ast.go Added new accessor methods for common node operations
internal/ast/utilities.go Refactored to use accessors, removed obsolete helper functions
internal/binder/binder.go Updated to use accessors throughout binding logic
internal/binder/nameresolver.go Simplified name resolution using accessors
internal/checker/checker.go Extensive refactoring to use accessors in type checking
internal/checker/utilities.go Removed duplicate helper functions, using accessors instead
internal/parser/parser.go Updated parsing logic to use accessors
internal/transformers/* All transformer files updated to use accessors
internal/printer/* Printer logic refactored to use accessors
internal/ls/* Language service files updated to use accessors
internal/tsoptions/* Config parsing updated to use accessors

@ahejlsberg ahejlsberg added this pull request to the merge queue Nov 11, 2025
Merged via the queue into main with commit 8fdec88 Nov 11, 2025
22 checks passed
@ahejlsberg ahejlsberg deleted the use-node-accessors branch November 11, 2025 20:06
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.

3 participants