MCPcopy Index your code
hub / github.com/nodejs/node / checkVariableLikeDeclaration

Function checkVariableLikeDeclaration

test/fixtures/snapshot/typescript.js:82495–82630  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

82493 }
82494 // Check variable, parameter, or property declaration
82495 function checkVariableLikeDeclaration(node) {
82496 var _a;
82497 checkDecorators(node);
82498 if (!ts.isBindingElement(node)) {
82499 checkSourceElement(node.type);
82500 }
82501 // JSDoc `function(string, string): string` syntax results in parameters with no name
82502 if (!node.name) {
82503 return;
82504 }
82505 // For a computed property, just check the initializer and exit
82506 // Do not use hasDynamicName here, because that returns false for well known symbols.
82507 // We want to perform checkComputedPropertyName for all computed properties, including
82508 // well known symbols.
82509 if (node.name.kind === 162 /* SyntaxKind.ComputedPropertyName */) {
82510 checkComputedPropertyName(node.name);
82511 if (node.initializer) {
82512 checkExpressionCached(node.initializer);
82513 }
82514 }
82515 if (ts.isBindingElement(node)) {
82516 if (ts.isObjectBindingPattern(node.parent) && node.dotDotDotToken && languageVersion < 5 /* ScriptTarget.ES2018 */) {
82517 checkExternalEmitHelpers(node, 4 /* ExternalEmitHelpers.Rest */);
82518 }
82519 // check computed properties inside property names of binding elements
82520 if (node.propertyName && node.propertyName.kind === 162 /* SyntaxKind.ComputedPropertyName */) {
82521 checkComputedPropertyName(node.propertyName);
82522 }
82523 // check private/protected variable access
82524 var parent = node.parent.parent;
82525 var parentCheckMode = node.dotDotDotToken ? 64 /* CheckMode.RestBindingElement */ : 0 /* CheckMode.Normal */;
82526 var parentType = getTypeForBindingElementParent(parent, parentCheckMode);
82527 var name = node.propertyName || node.name;
82528 if (parentType && !ts.isBindingPattern(name)) {
82529 var exprType = getLiteralTypeFromPropertyName(name);
82530 if (isTypeUsableAsPropertyName(exprType)) {
82531 var nameText = getPropertyNameFromType(exprType);
82532 var property = getPropertyOfType(parentType, nameText);
82533 if (property) {
82534 markPropertyAsReferenced(property, /*nodeForCheckWriteOnly*/ undefined, /*isSelfTypeAccess*/ false); // A destructuring is never a write-only reference.
82535 checkPropertyAccessibility(node, !!parent.initializer && parent.initializer.kind === 106 /* SyntaxKind.SuperKeyword */, /*writing*/ false, parentType, property);
82536 }
82537 }
82538 }
82539 }
82540 // For a binding pattern, check contained binding elements
82541 if (ts.isBindingPattern(node.name)) {
82542 if (node.name.kind === 202 /* SyntaxKind.ArrayBindingPattern */ && languageVersion < 2 /* ScriptTarget.ES2015 */ && compilerOptions.downlevelIteration) {
82543 checkExternalEmitHelpers(node, 512 /* ExternalEmitHelpers.Read */);
82544 }
82545 ts.forEach(node.name.elements, checkSourceElement);
82546 }
82547 // For a parameter declaration with an initializer, error and exit if the containing function doesn't have a body
82548 if (node.initializer && ts.isParameterDeclaration(node) && ts.nodeIsMissing(ts.getContainingFunction(node).body)) {
82549 error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation);
82550 return;
82551 }
82552 // For a binding pattern, validate the initializer and exit

Callers 4

checkParameterFunction · 0.85
checkPropertyDeclarationFunction · 0.85
checkVariableDeclarationFunction · 0.85
checkBindingElementFunction · 0.85

Calls 15

checkDecoratorsFunction · 0.85
checkSourceElementFunction · 0.85
checkExpressionCachedFunction · 0.85
checkExternalEmitHelpersFunction · 0.85
getPropertyNameFromTypeFunction · 0.85
getPropertyOfTypeFunction · 0.85
markPropertyAsReferencedFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…