Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 9, 2026

Ports microsoft/TypeScript#62950

When looking up containing functions from within a computed property name (e.g., [yield 0]), the compiler would incorrectly treat the method being defined as the containing function, causing infinite recursion during contextual typing.

function* g() {
  let x: any = {
    *[yield 0]() {}  // yield should be in context of g(), not the method
  };
}

Changes

  • GetContainingFunction (internal/ast/utilities.go): Skip over ComputedPropertyName nodes by jumping to node.Parent.Parent
  • getContainingFunctionOrClassStaticBlock (internal/checker/utilities.go): Same fix

This also fixes await expressions in computed property names inside class static blocks now correctly reporting errors.

Tests Added

Added tests from the upstream PR as local tests:

  • yieldInComputedNameOfContextuallyTypedObjectNoCrash1.ts - tests yield in computed property name
  • classStaticBlock29.ts - tests await in computed property name inside class static block

Not Ported

  • getContainingFunctionDeclaration - only used by convertParamsToDestructuredObject refactor service which doesn't exist in the Go codebase yet
  • getContainingClassStaticBlock - no callers in the Go codebase

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

Original prompt

Port microsoft/TypeScript#62950

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Port TypeScript pull request 62950 Port TypeScript PR #62950: Ignore computed name parents when looking up containing functions Jan 9, 2026
Copilot AI requested a review from RyanCavanaugh January 9, 2026 19:04
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.

where is getContainingFunctionDeclaration?

return nil
}

func getContainingClassStaticBlock(node *ast.Node) *ast.Node {
Copy link
Member

Choose a reason for hiding this comment

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

It's suspect that this is ported but the func is unused

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in c0af02c. It was unused since the equivalent TypeScript logic (in addInheritedMembers) isn't in the Go codebase.

Copy link
Member

@RyanCavanaugh RyanCavanaugh left a comment

Choose a reason for hiding this comment

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

@copilot also add the new tests from the upstream PR as local tests in this repo

Copy link
Contributor Author

Copilot AI commented Jan 15, 2026

where is getContainingFunctionDeclaration?

getContainingFunctionDeclaration wasn't ported because it's only used by convertParamsToDestructuredObject refactor service, which doesn't exist in the Go codebase yet. The function would have no callers.

@copilot also add the new tests from the upstream PR as local tests in this repo

Added in c0af02c:

  • yieldInComputedNameOfContextuallyTypedObjectNoCrash1.ts - tests yield in computed property name
  • classStaticBlock29.ts - tests await in computed property name inside class static block

Copy link
Member

@RyanCavanaugh RyanCavanaugh left a comment

Choose a reason for hiding this comment

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

@copilot getContainingClassStaticBlock appears to have no callers, remove it from the codebase

Copy link
Contributor Author

Copilot AI commented Jan 15, 2026

@copilot getContainingClassStaticBlock appears to have no callers, remove it from the codebase

Already removed in c0af02c.

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