MCPcopy Create free account
hub / github.com/microsoft/typescript-go / checkDestructuringAssignment

Method checkDestructuringAssignment

internal/checker/checker.go:12514–12545  ·  view source on GitHub ↗
(node *ast.Node, sourceType *Type, checkMode CheckMode, rightIsThis bool)

Source from the content-addressed store, hash-verified

12512}
12513
12514func (c *Checker) checkDestructuringAssignment(node *ast.Node, sourceType *Type, checkMode CheckMode, rightIsThis bool) *Type {
12515 var target *ast.Node
12516 if ast.IsShorthandPropertyAssignment(node) {
12517 initializer := node.AsShorthandPropertyAssignment().ObjectAssignmentInitializer
12518 if initializer != nil {
12519 // In strict null checking mode, if a default value of a non-undefined type is specified, remove
12520 // undefined from the final type.
12521 if c.strictNullChecks && !c.hasTypeFacts(c.checkExpression(initializer), TypeFactsIsUndefined) {
12522 sourceType = c.getTypeWithFacts(sourceType, TypeFactsNEUndefined)
12523 }
12524 c.checkBinaryLikeExpression(node.Name(), node.AsShorthandPropertyAssignment().EqualsToken, initializer, checkMode, nil)
12525 }
12526 target = node.Name()
12527 } else {
12528 target = node
12529 }
12530 if ast.IsBinaryExpression(target) && target.AsBinaryExpression().OperatorToken.Kind == ast.KindEqualsToken {
12531 c.checkBinaryExpression(target, checkMode)
12532 target = target.AsBinaryExpression().Left
12533 // A default value is specified, so remove undefined from the final type.
12534 if c.strictNullChecks {
12535 sourceType = c.getTypeWithFacts(sourceType, TypeFactsNEUndefined)
12536 }
12537 }
12538 if ast.IsObjectLiteralExpression(target) {
12539 return c.checkObjectLiteralAssignment(target, sourceType, rightIsThis)
12540 }
12541 if ast.IsArrayLiteralExpression(target) {
12542 return c.checkArrayLiteralAssignment(target, sourceType, checkMode)
12543 }
12544 return c.checkReferenceAssignment(target, sourceType, checkMode)
12545}
12546
12547func (c *Checker) checkObjectLiteralAssignment(node *ast.Node, sourceType *Type, rightIsThis bool) *Type {
12548 properties := node.PropertyList()

Calls 15

hasTypeFactsMethod · 0.95
checkExpressionMethod · 0.95
getTypeWithFactsMethod · 0.95
AsBinaryExpressionMethod · 0.95
checkBinaryExpressionMethod · 0.95
IsBinaryExpressionFunction · 0.92

Tested by

no test coverage detected