MCPcopy Create free account
hub / github.com/nodejs/node / isConstructorAccessible

Function isConstructorAccessible

test/fixtures/snapshot/typescript.js:76655–76685  ·  view source on GitHub ↗
(node, signature)

Source from the content-addressed store, hash-verified

76653 return typeHasProtectedAccessibleBase(target, firstBase);
76654 }
76655 function isConstructorAccessible(node, signature) {
76656 if (!signature || !signature.declaration) {
76657 return true;
76658 }
76659 var declaration = signature.declaration;
76660 var modifiers = ts.getSelectedEffectiveModifierFlags(declaration, 24 /* ModifierFlags.NonPublicAccessibilityModifier */);
76661 // (1) Public constructors and (2) constructor functions are always accessible.
76662 if (!modifiers || declaration.kind !== 171 /* SyntaxKind.Constructor */) {
76663 return true;
76664 }
76665 var declaringClassDeclaration = ts.getClassLikeDeclarationOfSymbol(declaration.parent.symbol);
76666 var declaringClass = getDeclaredTypeOfSymbol(declaration.parent.symbol);
76667 // A private or protected constructor can only be instantiated within its own class (or a subclass, for protected)
76668 if (!isNodeWithinClass(node, declaringClassDeclaration)) {
76669 var containingClass = ts.getContainingClass(node);
76670 if (containingClass && modifiers & 16 /* ModifierFlags.Protected */) {
76671 var containingType = getTypeOfNode(containingClass);
76672 if (typeHasProtectedAccessibleBase(declaration.parent.symbol, containingType)) {
76673 return true;
76674 }
76675 }
76676 if (modifiers & 8 /* ModifierFlags.Private */) {
76677 error(node, ts.Diagnostics.Constructor_of_class_0_is_private_and_only_accessible_within_the_class_declaration, typeToString(declaringClass));
76678 }
76679 if (modifiers & 16 /* ModifierFlags.Protected */) {
76680 error(node, ts.Diagnostics.Constructor_of_class_0_is_protected_and_only_accessible_within_the_class_declaration, typeToString(declaringClass));
76681 }
76682 return false;
76683 }
76684 return true;
76685 }
76686 function invocationErrorDetails(errorTarget, apparentType, kind) {
76687 var errorInfo;
76688 var isCall = kind === 0 /* SignatureKind.Call */;

Callers 1

resolveNewExpressionFunction · 0.85

Calls 6

getDeclaredTypeOfSymbolFunction · 0.85
isNodeWithinClassFunction · 0.85
getTypeOfNodeFunction · 0.85
typeToStringFunction · 0.85
errorFunction · 0.70

Tested by

no test coverage detected