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

Function getFlowTypeOfAccessExpression

test/fixtures/snapshot/typescript.js:74751–74798  ·  view source on GitHub ↗
(node, prop, propType, errorNode, checkMode)

Source from the content-addressed store, hash-verified

74749 return false;
74750 }
74751 function getFlowTypeOfAccessExpression(node, prop, propType, errorNode, checkMode) {
74752 // Only compute control flow type if this is a property access expression that isn't an
74753 // assignment target, and the referenced property was declared as a variable, property,
74754 // accessor, or optional method.
74755 var assignmentKind = ts.getAssignmentTargetKind(node);
74756 if (assignmentKind === 1 /* AssignmentKind.Definite */) {
74757 return removeMissingType(propType, !!(prop && prop.flags & 16777216 /* SymbolFlags.Optional */));
74758 }
74759 if (prop &&
74760 !(prop.flags & (3 /* SymbolFlags.Variable */ | 4 /* SymbolFlags.Property */ | 98304 /* SymbolFlags.Accessor */))
74761 && !(prop.flags & 8192 /* SymbolFlags.Method */ && propType.flags & 1048576 /* TypeFlags.Union */)
74762 && !isDuplicatedCommonJSExport(prop.declarations)) {
74763 return propType;
74764 }
74765 if (propType === autoType) {
74766 return getFlowTypeOfProperty(node, prop);
74767 }
74768 propType = getNarrowableTypeForReference(propType, node, checkMode);
74769 // If strict null checks and strict property initialization checks are enabled, if we have
74770 // a this.xxx property access, if the property is an instance property without an initializer,
74771 // and if we are in a constructor of the same class as the property declaration, assume that
74772 // the property is uninitialized at the top of the control flow.
74773 var assumeUninitialized = false;
74774 if (strictNullChecks && strictPropertyInitialization && ts.isAccessExpression(node) && node.expression.kind === 108 /* SyntaxKind.ThisKeyword */) {
74775 var declaration = prop && prop.valueDeclaration;
74776 if (declaration && isPropertyWithoutInitializer(declaration)) {
74777 if (!ts.isStatic(declaration)) {
74778 var flowContainer = getControlFlowContainer(node);
74779 if (flowContainer.kind === 171 /* SyntaxKind.Constructor */ && flowContainer.parent === declaration.parent && !(declaration.flags & 16777216 /* NodeFlags.Ambient */)) {
74780 assumeUninitialized = true;
74781 }
74782 }
74783 }
74784 }
74785 else if (strictNullChecks && prop && prop.valueDeclaration &&
74786 ts.isPropertyAccessExpression(prop.valueDeclaration) &&
74787 ts.getAssignmentDeclarationPropertyAccessKind(prop.valueDeclaration) &&
74788 getControlFlowContainer(node) === getControlFlowContainer(prop.valueDeclaration)) {
74789 assumeUninitialized = true;
74790 }
74791 var flowType = getFlowTypeOfReference(node, propType, assumeUninitialized ? getOptionalType(propType) : propType);
74792 if (assumeUninitialized && !(getFalsyFlags(propType) & 32768 /* TypeFlags.Undefined */) && getFalsyFlags(flowType) & 32768 /* TypeFlags.Undefined */) {
74793 error(errorNode, ts.Diagnostics.Property_0_is_used_before_being_assigned, symbolToString(prop)); // TODO: GH#18217
74794 // Return the declared type to reduce follow-on errors
74795 return propType;
74796 }
74797 return assignmentKind ? getBaseTypeOfLiteralType(flowType) : flowType;
74798 }
74799 function checkPropertyNotUsedBeforeDeclaration(prop, node, right) {
74800 var valueDeclaration = prop.valueDeclaration;
74801 if (!valueDeclaration || ts.getSourceFileOfNode(node).isDeclarationFile) {

Calls 12

removeMissingTypeFunction · 0.85
getFlowTypeOfPropertyFunction · 0.85
getControlFlowContainerFunction · 0.85
getFlowTypeOfReferenceFunction · 0.85
getOptionalTypeFunction · 0.85
getFalsyFlagsFunction · 0.85
symbolToStringFunction · 0.85
getBaseTypeOfLiteralTypeFunction · 0.85
errorFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…