(leftType, right, lexicallyScopedIdentifier)
| 74576 | return getPropertyOfType(leftType, lexicallyScopedIdentifier.escapedName); |
| 74577 | } |
| 74578 | function checkPrivateIdentifierPropertyAccess(leftType, right, lexicallyScopedIdentifier) { |
| 74579 | // Either the identifier could not be looked up in the lexical scope OR the lexically scoped identifier did not exist on the type. |
| 74580 | // Find a private identifier with the same description on the type. |
| 74581 | var propertyOnType; |
| 74582 | var properties = getPropertiesOfType(leftType); |
| 74583 | if (properties) { |
| 74584 | ts.forEach(properties, function (symbol) { |
| 74585 | var decl = symbol.valueDeclaration; |
| 74586 | if (decl && ts.isNamedDeclaration(decl) && ts.isPrivateIdentifier(decl.name) && decl.name.escapedText === right.escapedText) { |
| 74587 | propertyOnType = symbol; |
| 74588 | return true; |
| 74589 | } |
| 74590 | }); |
| 74591 | } |
| 74592 | var diagName = diagnosticName(right); |
| 74593 | if (propertyOnType) { |
| 74594 | var typeValueDecl = ts.Debug.checkDefined(propertyOnType.valueDeclaration); |
| 74595 | var typeClass_1 = ts.Debug.checkDefined(ts.getContainingClass(typeValueDecl)); |
| 74596 | // We found a private identifier property with the same description. |
| 74597 | // Either: |
| 74598 | // - There is a lexically scoped private identifier AND it shadows the one we found on the type. |
| 74599 | // - It is an attempt to access the private identifier outside of the class. |
| 74600 | if (lexicallyScopedIdentifier === null || lexicallyScopedIdentifier === void 0 ? void 0 : lexicallyScopedIdentifier.valueDeclaration) { |
| 74601 | var lexicalValueDecl = lexicallyScopedIdentifier.valueDeclaration; |
| 74602 | var lexicalClass = ts.getContainingClass(lexicalValueDecl); |
| 74603 | ts.Debug.assert(!!lexicalClass); |
| 74604 | if (ts.findAncestor(lexicalClass, function (n) { return typeClass_1 === n; })) { |
| 74605 | var diagnostic = error(right, ts.Diagnostics.The_property_0_cannot_be_accessed_on_type_1_within_this_class_because_it_is_shadowed_by_another_private_identifier_with_the_same_spelling, diagName, typeToString(leftType)); |
| 74606 | ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(lexicalValueDecl, ts.Diagnostics.The_shadowing_declaration_of_0_is_defined_here, diagName), ts.createDiagnosticForNode(typeValueDecl, ts.Diagnostics.The_declaration_of_0_that_you_probably_intended_to_use_is_defined_here, diagName)); |
| 74607 | return true; |
| 74608 | } |
| 74609 | } |
| 74610 | error(right, ts.Diagnostics.Property_0_is_not_accessible_outside_class_1_because_it_has_a_private_identifier, diagName, diagnosticName(typeClass_1.name || anon)); |
| 74611 | return true; |
| 74612 | } |
| 74613 | return false; |
| 74614 | } |
| 74615 | function isThisPropertyAccessInConstructor(node, prop) { |
| 74616 | return (isConstructorDeclaredProperty(prop) || ts.isThisProperty(node) && isAutoTypedProperty(prop)) |
| 74617 | && ts.getThisContainer(node, /*includeArrowFunctions*/ true) === getDeclaringConstructor(prop); |
no test coverage detected