Skip to content

Document TypeScript binder and symbols system #17

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 14, 2025

This PR adds comprehensive technical documentation explaining how TypeScript's binder and symbols work internally. The documentation covers the core concepts needed to understand symbol resolution and name lookup behavior.

What's Added

Technical Documentation in .github/copilot-library.md

The new documentation explains:

  • Symbols: TypeScript's internal representation of declarations with their key properties (flags, escapedName, declarations, members, exports)
  • SymbolFlags: Bitmask enum categorizing declaration types (Value, Type, Namespace, etc.) and their merging rules
  • SymbolTable: Map-based storage system for organizing symbols by escaped names
  • Binder Process: How symbols are created during AST traversal, including conflict resolution and merging logic
  • Name Resolution Algorithm: Detailed explanation of how resolveName works with context-sensitive scope chain walking

Key Example Explained

The documentation thoroughly explains the classic name shadowing example:

type x = number;           // Creates symbol: flags=TypeAlias, name="x"
function fn(x: string) {   // Creates symbol: flags=FunctionScopedVariable, name="x"
  let y: x = x;            // Two different lookups happen here
}

Shows how:

  • Type position x resolves to the global type alias (number)
  • Value position x resolves to the function parameter (string)
  • Context (Type vs Value meaning) and scope hierarchy determine resolution

Validation Test Case

Added tests/cases/compiler/symbolsDocumentationTest.ts demonstrating:

  • Symbol resolution across different scopes and contexts
  • Interface and namespace merging behavior
  • Parameter shadowing of global symbols
  • Block-scoped variable shadowing

The test baselines clearly show how the same name resolves to different symbols based on context and scope.

Additional Improvements

  • Added question to .github/copilot-questions.md about complex symbol merging scenarios
  • All code follows TypeScript project formatting and linting standards

This documentation enables developers to understand the finer points of how resolveName works and debug complex symbol resolution issues.

Fixes #16.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Document how the binder and symbols work Document TypeScript binder and symbols system Jul 14, 2025
@Copilot Copilot AI requested a review from RyanCavanaugh July 14, 2025 18:05
Copilot finished work on behalf of RyanCavanaugh July 14, 2025 18:05
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.

Document how the binder and symbols work
2 participants