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

Function createUnionOrIntersectionProperty

test/fixtures/snapshot/typescript.js:59152–59314  ·  view source on GitHub ↗
(containingType, name, skipObjectFunctionPropertyAugment)

Source from the content-addressed store, hash-verified

59150 return getReducedType(getApparentType(getReducedType(type)));
59151 }
59152 function createUnionOrIntersectionProperty(containingType, name, skipObjectFunctionPropertyAugment) {
59153 var _a, _b;
59154 var singleProp;
59155 var propSet;
59156 var indexTypes;
59157 var isUnion = containingType.flags & 1048576 /* TypeFlags.Union */;
59158 // Flags we want to propagate to the result if they exist in all source symbols
59159 var optionalFlag = isUnion ? 0 /* SymbolFlags.None */ : 16777216 /* SymbolFlags.Optional */;
59160 var syntheticFlag = 4 /* CheckFlags.SyntheticMethod */;
59161 var checkFlags = isUnion ? 0 : 8 /* CheckFlags.Readonly */;
59162 var mergedInstantiations = false;
59163 for (var _i = 0, _c = containingType.types; _i < _c.length; _i++) {
59164 var current = _c[_i];
59165 var type = getApparentType(current);
59166 if (!(isErrorType(type) || type.flags & 131072 /* TypeFlags.Never */)) {
59167 var prop = getPropertyOfType(type, name, skipObjectFunctionPropertyAugment);
59168 var modifiers = prop ? ts.getDeclarationModifierFlagsFromSymbol(prop) : 0;
59169 if (prop) {
59170 if (isUnion) {
59171 optionalFlag |= (prop.flags & 16777216 /* SymbolFlags.Optional */);
59172 }
59173 else {
59174 optionalFlag &= prop.flags;
59175 }
59176 if (!singleProp) {
59177 singleProp = prop;
59178 }
59179 else if (prop !== singleProp) {
59180 var isInstantiation = (getTargetSymbol(prop) || prop) === (getTargetSymbol(singleProp) || singleProp);
59181 // If the symbols are instances of one another with identical types - consider the symbols
59182 // equivalent and just use the first one, which thus allows us to avoid eliding private
59183 // members when intersecting a (this-)instantiations of a class with it's raw base or another instance
59184 if (isInstantiation && compareProperties(singleProp, prop, function (a, b) { return a === b ? -1 /* Ternary.True */ : 0 /* Ternary.False */; }) === -1 /* Ternary.True */) {
59185 // If we merged instantiations of a generic type, we replicate the symbol parent resetting behavior we used
59186 // to do when we recorded multiple distinct symbols so that we still get, eg, `Array<T>.length` printed
59187 // back and not `Array<string>.length` when we're looking at a `.length` access on a `string[] | number[]`
59188 mergedInstantiations = !!singleProp.parent && !!ts.length(getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(singleProp.parent));
59189 }
59190 else {
59191 if (!propSet) {
59192 propSet = new ts.Map();
59193 propSet.set(getSymbolId(singleProp), singleProp);
59194 }
59195 var id = getSymbolId(prop);
59196 if (!propSet.has(id)) {
59197 propSet.set(id, prop);
59198 }
59199 }
59200 }
59201 if (isUnion && isReadonlySymbol(prop)) {
59202 checkFlags |= 8 /* CheckFlags.Readonly */;
59203 }
59204 else if (!isUnion && !isReadonlySymbol(prop)) {
59205 checkFlags &= ~8 /* CheckFlags.Readonly */;
59206 }
59207 checkFlags |= (!(modifiers & 24 /* ModifierFlags.NonPublicAccessibilityModifier */) ? 256 /* CheckFlags.ContainsPublic */ : 0) |
59208 (modifiers & 16 /* ModifierFlags.Protected */ ? 512 /* CheckFlags.ContainsProtected */ : 0) |
59209 (modifiers & 8 /* ModifierFlags.Private */ ? 1024 /* CheckFlags.ContainsPrivate */ : 0) |

Callers 2

Calls 15

getApparentTypeFunction · 0.85
isErrorTypeFunction · 0.85
getPropertyOfTypeFunction · 0.85
getTargetSymbolFunction · 0.85
comparePropertiesFunction · 0.85
getSymbolIdFunction · 0.85
isReadonlySymbolFunction · 0.85
isPrototypePropertyFunction · 0.85
isLateBoundNameFunction · 0.85
isTupleTypeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…