Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 9, 2025

This PR ports TypeScript PR#60052 to the Go codebase.

Overview

This change allows computed property names in declaration files to be resolved even when they're not literals, as long as they are entity name expressions (like a.b.c). Additionally, the implementation now preserves those computed names in declaration emit when possible, rather than always converting them to generic index signatures.

What Changed

1. Symbol Resolution for Computed Names

The trackComputedName function now resolves names at the enclosingDeclaration location first, with a fallback to the firstIdentifier location. This ensures correct symbol tracking when computed names are referenced across different scopes:

// Before: Always resolved at firstIdentifier location
name := b.ch.resolveName(firstIdentifier, ...)

// After: Try enclosingDeclaration first, fallback to firstIdentifier
name := b.ch.resolveName(enclosingDeclaration, ...)
if name == nil {
    fallback := b.ch.resolveName(firstIdentifier, ...)
    ...
}

2. Static vs Instance Index Signature Checking

Updated checkIndexConstraints to properly check static properties against static index signatures and instance properties against instance index signatures. Previously, only instance properties were validated against index signatures:

// Before: Only checked instance properties
if !ast.IsStatic(member) && !c.hasBindableName(member) {
    ...
}

// After: Check both static and instance properties appropriately
if ((!isStaticIndex && !ast.IsStatic(member)) ||
    (isStaticIndex && ast.IsStatic(member))) && !c.hasBindableName(member) {
    ...
}

3. Preserving Computed Names in Declaration Emit

Added indexInfoToObjectComputedNamesOrSignatureDeclaration function that preserves computed property names as explicit property signatures when all components are visible entity name expressions, rather than always collapsing them into generic index signatures:

// Before: { [x: string]: number; }
// After:  { [Symbol.foo]: number; }

This provides more precise type information in declaration files while maintaining compatibility with the TypeScript compiler's behavior.

Test Results

  • ✅ All tests pass
  • 27 diff files deleted - Go implementation now matches TypeScript behavior
  • ✅ Net reduction of 627 lines of test differences

Key tests now passing include:

  • declarationEmitSimpleComputedNames1
  • declarationEmitComputedNamesInaccessible
  • ES5SymbolProperty1
  • computedPropertyNames48
  • And many more

Impact

This change brings the Go implementation closer to TypeScript's handling of computed property names in declaration contexts, enabling better support for:

  • Symbol-based property keys
  • Enum-based property keys
  • Entity name expressions as computed property names
  • More precise declaration emit for library authors
Original prompt

From the TypeScript repo, port PR#60052

Note

Custom agent used: Strada to Corsa Port Expert
A Go and TypeScript expert who can easily figure out how to port PRs from one language to another


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] Port PR#60052 to TypeScript repo Port PR#60052: Computed names in declaration files are resolved even when non-literal, preserve computed names when expressions are entity names Oct 9, 2025
@Copilot Copilot AI requested a review from RyanCavanaugh October 9, 2025 21:47
Copilot finished work on behalf of RyanCavanaugh October 9, 2025 21:47
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.

2 participants