Skip to content

Commit b883553

Browse files
committed
Pull in local version of expando thing after change in main
1 parent 3f637af commit b883553

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

internal/ls/codeactions_fixmissingtypeannotation.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,26 +424,33 @@ func (f *isolatedDeclarationsFixer) extractAsVariable(span core.TextRange) strin
424424
}
425425

426426
// findExpandoFunction finds the function declaration that has expando properties assigned to it.
427+
// isExpandoPropertyDeclarationForFix matches TS's isExpandoPropertyDeclaration which includes
428+
// PropertyAccessExpression, ElementAccessExpression, and BinaryExpression. The shared
429+
// ast.IsExpandoPropertyDeclaration was narrowed to BinaryExpression only for checker purposes.
430+
func isExpandoPropertyDeclarationForFix(node *ast.Node) bool {
431+
return node != nil && (ast.IsPropertyAccessExpression(node) || ast.IsElementAccessExpression(node) || ast.IsBinaryExpression(node))
432+
}
433+
427434
func findExpandoFunction(ch *checker.Checker, node *ast.Node) *ast.Node {
428435
expandoDeclaration := ast.FindAncestorOrQuit(node, func(n *ast.Node) ast.FindAncestorResult {
429436
if ast.IsStatement(n) {
430437
return ast.FindAncestorQuit
431438
}
432-
if ast.IsExpandoPropertyDeclaration(n) {
439+
if isExpandoPropertyDeclarationForFix(n) {
433440
return ast.FindAncestorTrue
434441
}
435442
return ast.FindAncestorFalse
436443
})
437444

438-
if expandoDeclaration == nil || !ast.IsExpandoPropertyDeclaration(expandoDeclaration) {
445+
if expandoDeclaration == nil || !isExpandoPropertyDeclarationForFix(expandoDeclaration) {
439446
return nil
440447
}
441448

442449
assignmentTarget := expandoDeclaration
443450
// Some late bound expando members use the whole expression as the declaration.
444451
if ast.IsBinaryExpression(assignmentTarget) {
445452
assignmentTarget = assignmentTarget.AsBinaryExpression().Left
446-
if !ast.IsExpandoPropertyDeclaration(assignmentTarget) {
453+
if !isExpandoPropertyDeclarationForFix(assignmentTarget) {
447454
return nil
448455
}
449456
}

internal/printer/printer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,10 @@ func (p *Printer) emitEntityName(node *ast.EntityName) {
12011201
p.emitIdentifierReference(node.AsIdentifier())
12021202
case ast.KindQualifiedName:
12031203
p.emitQualifiedName(node.AsQualifiedName())
1204+
case ast.KindPropertyAccessExpression:
1205+
// TypeQuery nodes may have PropertyAccessExpression as exprName (e.g. typeof foo.x).
1206+
// TS's emitter handles this via generic emit(); we dispatch to expression emitter here.
1207+
p.emitExpression(node, ast.OperatorPrecedenceDisallowComma)
12041208
default:
12051209
panic(fmt.Sprintf("unexpected EntityName: %v", node.Kind))
12061210
}

0 commit comments

Comments
 (0)