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

Method checkVariableLikeDeclaration

internal/checker/checker.go:5769–5926  ·  view source on GitHub ↗

Check variable, parameter, or property declaration

(node *ast.Node)

Source from the content-addressed store, hash-verified

5767
5768// Check variable, parameter, or property declaration
5769func (c *Checker) checkVariableLikeDeclaration(node *ast.Node) {
5770 c.checkDecorators(node)
5771 name := node.Name()
5772 if name == nil {
5773 return // Missing array binding elements have no name
5774 }
5775 typeNode := node.Type()
5776 initializer := node.Initializer()
5777 if !ast.IsBindingElement(node) {
5778 c.checkSourceElement(typeNode)
5779 }
5780 // For a computed property, just check the initializer and exit
5781 // Do not use hasDynamicName here, because that returns false for well known symbols.
5782 // We want to perform checkComputedPropertyName for all computed properties, including
5783 // well known symbols.
5784 if ast.IsComputedPropertyName(name) {
5785 c.checkComputedPropertyName(name)
5786 if initializer != nil {
5787 c.checkExpressionCached(initializer)
5788 }
5789 }
5790 if ast.IsBindingElement(node) {
5791 propName := node.PropertyName()
5792 if propName != nil && ast.IsIdentifier(node.Name()) && ast.IsPartOfParameterDeclaration(node) && ast.NodeIsMissing(ast.GetContainingFunction(node).Body()) {
5793 // type F = ({a: string}) => void;
5794 // ^^^^^^
5795 // variable renaming in function type notation is confusing,
5796 // so we forbid it even if noUnusedLocals is not enabled
5797 c.renamedBindingElementsInTypes = append(c.renamedBindingElementsInTypes, node)
5798 return
5799 }
5800 if ast.IsObjectBindingPattern(node.Parent) && hasDotDotDotToken(node) && c.languageVersion < LanguageFeatureMinimumTarget.ObjectSpreadRest {
5801 c.checkExternalEmitHelpers(node, ExternalEmitHelpersRest)
5802 }
5803 // check computed properties inside property names of binding elements
5804 if propName != nil && ast.IsComputedPropertyName(propName) {
5805 c.checkComputedPropertyName(propName)
5806 }
5807 // check private/protected variable access
5808 parent := node.Parent.Parent
5809 parentCheckMode := core.IfElse(hasDotDotDotToken(node), CheckModeRestBindingElement, CheckModeNormal)
5810 parentType := c.getTypeForBindingElementParent(parent, parentCheckMode)
5811 propNameName := node.PropertyNameOrName()
5812 if parentType != nil && !ast.IsBindingPattern(propNameName) {
5813 exprType := c.getLiteralTypeFromPropertyName(propNameName)
5814 if isTypeUsableAsPropertyName(exprType) {
5815 nameText := getPropertyNameFromType(exprType)
5816 property := c.getPropertyOfType(parentType, nameText)
5817 if property != nil {
5818 c.markPropertyAsReferenced(property, nil /*nodeForCheckWriteOnly*/, false /*isSelfTypeAccess*/)
5819 // A destructuring is never a write-only reference.
5820 c.checkPropertyAccessibility(node, parent.Initializer() != nil && parent.Initializer().Kind == ast.KindSuperKeyword, false /*writing*/, parentType, property)
5821 }
5822 }
5823 }
5824 }
5825 // For a binding pattern, check contained binding elements
5826 if ast.IsBindingPattern(name) {

Callers 5

checkParameterMethod · 0.95
checkCatchClauseMethod · 0.95
checkBindingElementMethod · 0.95

Calls 15

checkDecoratorsMethod · 0.95
checkSourceElementMethod · 0.95
checkExpressionCachedMethod · 0.95
getPropertyOfTypeMethod · 0.95
checkSourceElementsMethod · 0.95
errorMethod · 0.95

Tested by

no test coverage detected