Port TypeScript PR #62950: Ignore computed name parents when looking up containing functions#2461
Port TypeScript PR #62950: Ignore computed name parents when looking up containing functions#2461
Conversation
…up containing functions Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
jakebailey
left a comment
There was a problem hiding this comment.
where is getContainingFunctionDeclaration?
internal/checker/utilities.go
Outdated
| return nil | ||
| } | ||
|
|
||
| func getContainingClassStaticBlock(node *ast.Node) *ast.Node { |
There was a problem hiding this comment.
It's suspect that this is ported but the func is unused
There was a problem hiding this comment.
Removed in c0af02c. It was unused since the equivalent TypeScript logic (in addInheritedMembers) isn't in the Go codebase.
RyanCavanaugh
left a comment
There was a problem hiding this comment.
@copilot also add the new tests from the upstream PR as local tests in this repo
…am PR Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Added in c0af02c:
|
RyanCavanaugh
left a comment
There was a problem hiding this comment.
@copilot getContainingClassStaticBlock appears to have no callers, remove it from the codebase
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.Changes
GetContainingFunction(internal/ast/utilities.go): Skip overComputedPropertyNamenodes by jumping tonode.Parent.ParentgetContainingFunctionOrClassStaticBlock(internal/checker/utilities.go): Same fixThis also fixes
awaitexpressions 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 nameclassStaticBlock29.ts- tests await in computed property name inside class static blockNot Ported
getContainingFunctionDeclaration- only used byconvertParamsToDestructuredObjectrefactor service which doesn't exist in the Go codebase yetgetContainingClassStaticBlock- no callers in the Go codebaseOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.