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

Function checkPropertyAccessibilityAtLocation

test/fixtures/snapshot/typescript.js:74354–74449  ·  view source on GitHub ↗

* Check whether the requested property can be accessed at the requested location. * Returns true if node is a valid property access, and false otherwise. * @param location The location node where we want to check if the property is accessible. * @param isSuper True if the

(location, isSuper, writing, containingType, prop, errorNode)

Source from the content-addressed store, hash-verified

74352 * @param errorNode The node where we should report an invalid property access error, or undefined if we should not report errors.
74353 */
74354 function checkPropertyAccessibilityAtLocation(location, isSuper, writing, containingType, prop, errorNode) {
74355 var flags = ts.getDeclarationModifierFlagsFromSymbol(prop, writing);
74356 if (isSuper) {
74357 // TS 1.0 spec (April 2014): 4.8.2
74358 // - In a constructor, instance member function, instance member accessor, or
74359 // instance member variable initializer where this references a derived class instance,
74360 // a super property access is permitted and must specify a public instance member function of the base class.
74361 // - In a static member function or static member accessor
74362 // where this references the constructor function object of a derived class,
74363 // a super property access is permitted and must specify a public static member function of the base class.
74364 if (languageVersion < 2 /* ScriptTarget.ES2015 */) {
74365 if (symbolHasNonMethodDeclaration(prop)) {
74366 if (errorNode) {
74367 error(errorNode, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword);
74368 }
74369 return false;
74370 }
74371 }
74372 if (flags & 128 /* ModifierFlags.Abstract */) {
74373 // A method cannot be accessed in a super property access if the method is abstract.
74374 // This error could mask a private property access error. But, a member
74375 // cannot simultaneously be private and abstract, so this will trigger an
74376 // additional error elsewhere.
74377 if (errorNode) {
74378 error(errorNode, ts.Diagnostics.Abstract_method_0_in_class_1_cannot_be_accessed_via_super_expression, symbolToString(prop), typeToString(getDeclaringClass(prop)));
74379 }
74380 return false;
74381 }
74382 }
74383 // Referencing abstract properties within their own constructors is not allowed
74384 if ((flags & 128 /* ModifierFlags.Abstract */) && symbolHasNonMethodDeclaration(prop) &&
74385 (ts.isThisProperty(location) || ts.isThisInitializedObjectBindingExpression(location) || ts.isObjectBindingPattern(location.parent) && ts.isThisInitializedDeclaration(location.parent.parent))) {
74386 var declaringClassDeclaration = ts.getClassLikeDeclarationOfSymbol(getParentOfSymbol(prop));
74387 if (declaringClassDeclaration && isNodeUsedDuringClassInitialization(location)) {
74388 if (errorNode) {
74389 error(errorNode, ts.Diagnostics.Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor, symbolToString(prop), ts.getTextOfIdentifierOrLiteral(declaringClassDeclaration.name));
74390 }
74391 return false;
74392 }
74393 }
74394 // Public properties are otherwise accessible.
74395 if (!(flags & 24 /* ModifierFlags.NonPublicAccessibilityModifier */)) {
74396 return true;
74397 }
74398 // Property is known to be private or protected at this point
74399 // Private property is accessible if the property is within the declaring class
74400 if (flags & 8 /* ModifierFlags.Private */) {
74401 var declaringClassDeclaration = ts.getClassLikeDeclarationOfSymbol(getParentOfSymbol(prop));
74402 if (!isNodeWithinClass(location, declaringClassDeclaration)) {
74403 if (errorNode) {
74404 error(errorNode, ts.Diagnostics.Property_0_is_private_and_only_accessible_within_class_1, symbolToString(prop), typeToString(getDeclaringClass(prop)));
74405 }
74406 return false;
74407 }
74408 return true;
74409 }
74410 // Property is known to be protected at this point
74411 // All protected properties of a supertype are accessible in a super access

Callers 2

isPropertyAccessibleFunction · 0.85

Calls 15

symbolToStringFunction · 0.85
typeToStringFunction · 0.85
getDeclaringClassFunction · 0.85
getParentOfSymbolFunction · 0.85
isNodeWithinClassFunction · 0.85
forEachEnclosingClassFunction · 0.85
getDeclaredTypeOfSymbolFunction · 0.85
getSymbolOfNodeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…