code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
function getBaseTypeNodeOfClass(type) { return ts.getClassExtendsHeritageClauseElement(type.symbol.valueDeclaration); }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
getBaseTypeNodeOfClass
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getConstructorsForTypeArguments(type, typeArgumentNodes) { var typeArgCount = typeArgumentNodes ? typeArgumentNodes.length : 0; return ts.filter(getSignaturesOfType(type, 1 /* Construct */), function (sig) { return (sig.typeParameters ? sig.typeParameters.length : 0) === typeArgCount; }); }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
getConstructorsForTypeArguments
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getInstantiatedConstructorsForTypeArguments(type, typeArgumentNodes) { var signatures = getConstructorsForTypeArguments(type, typeArgumentNodes); if (typeArgumentNodes) { var typeArguments = ts.map(typeArgumentNodes, getTypeFromTypeNode); signatures = ts.map(signatures, function (sig) { return getSignatureInstantiation(sig, typeArguments); }); } return signatures; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
getInstantiatedConstructorsForTypeArguments
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function hasClassBaseType(type) { return !!ts.forEach(getBaseTypes(type), function (t) { return !!(t.symbol.flags & 32 /* Class */); }); }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
hasClassBaseType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getBaseTypes(type) { var isClass = type.symbol.flags & 32 /* Class */; var isInterface = type.symbol.flags & 64 /* Interface */; if (!type.resolvedBaseTypes) { if (!isClass && !isInterface) { ts.Debug.fail("type must be class or interface"); } if (isClass) { resolveBaseTypesOfClass(type); } if (isInterface) { resolveBaseTypesOfInterface(type); } } return type.resolvedBaseTypes; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
getBaseTypes
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function resolveBaseTypesOfClass(type) { type.resolvedBaseTypes = type.resolvedBaseTypes || emptyArray; var baseConstructorType = getBaseConstructorTypeOfClass(type); if (!(baseConstructorType.flags & 80896 /* ObjectType */)) { return; } var baseTypeNode = getBaseTypeNodeOfClass(type); var baseType; var originalBaseType = baseConstructorType && baseConstructorType.symbol ? getDeclaredTypeOfSymbol(baseConstructorType.symbol) : undefined; if (baseConstructorType.symbol && baseConstructorType.symbol.flags & 32 /* Class */ && areAllOuterTypeParametersApplied(originalBaseType)) { // When base constructor type is a class with no captured type arguments we know that the constructors all have the same type parameters as the // class and all return the instance type of the class. There is no need for further checks and we can apply the // type arguments in the same manner as a type reference to get the same error reporting experience. baseType = getTypeFromClassOrInterfaceReference(baseTypeNode, baseConstructorType.symbol); } else { // The class derives from a "class-like" constructor function, check that we have at least one construct signature // with a matching number of type parameters and use the return type of the first instantiated signature. Elsewhere // we check that all instantiated signatures return the same type. var constructors = getInstantiatedConstructorsForTypeArguments(baseConstructorType, baseTypeNode.typeArguments); if (!constructors.length) { error(baseTypeNode.expression, ts.Diagnostics.No_base_constructor_has_the_specified_number_of_type_arguments); return; } baseType = getReturnTypeOfSignature(constructors[0]); } if (baseType === unknownType) { return; } if (!(getTargetType(baseType).flags & (1024 /* Class */ | 2048 /* Interface */))) { error(baseTypeNode.expression, ts.Diagnostics.Base_constructor_return_type_0_is_not_a_class_or_interface_type, typeToString(baseType)); return; } if (type === baseType || hasBaseType(baseType, type)) { error(type.symbol.valueDeclaration, ts.Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, /*enclosingDeclaration*/ undefined, 1 /* WriteArrayAsGenericType */)); return; } if (type.resolvedBaseTypes === emptyArray) { type.resolvedBaseTypes = [baseType]; } else { type.resolvedBaseTypes.push(baseType); } }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
resolveBaseTypesOfClass
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function areAllOuterTypeParametersApplied(type) { // An unapplied type parameter has its symbol still the same as the matching argument symbol. // Since parameters are applied outer-to-inner, only the last outer parameter needs to be checked. var outerTypeParameters = type.outerTypeParameters; if (outerTypeParameters) { var last = outerTypeParameters.length - 1; var typeArguments = type.typeArguments; return outerTypeParameters[last].symbol !== typeArguments[last].symbol; } return true; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
areAllOuterTypeParametersApplied
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function resolveBaseTypesOfInterface(type) { type.resolvedBaseTypes = type.resolvedBaseTypes || emptyArray; for (var _i = 0, _a = type.symbol.declarations; _i < _a.length; _i++) { var declaration = _a[_i]; if (declaration.kind === 215 /* InterfaceDeclaration */ && ts.getInterfaceBaseTypeNodes(declaration)) { for (var _b = 0, _c = ts.getInterfaceBaseTypeNodes(declaration); _b < _c.length; _b++) { var node = _c[_b]; var baseType = getTypeFromTypeNode(node); if (baseType !== unknownType) { if (getTargetType(baseType).flags & (1024 /* Class */ | 2048 /* Interface */)) { if (type !== baseType && !hasBaseType(baseType, type)) { if (type.resolvedBaseTypes === emptyArray) { type.resolvedBaseTypes = [baseType]; } else { type.resolvedBaseTypes.push(baseType); } } else { error(declaration, ts.Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, /*enclosingDeclaration*/ undefined, 1 /* WriteArrayAsGenericType */)); } } else { error(node, ts.Diagnostics.An_interface_may_only_extend_a_class_or_another_interface); } } } } } }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
resolveBaseTypesOfInterface
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isIndependentInterface(symbol) { for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { var declaration = _a[_i]; if (declaration.kind === 215 /* InterfaceDeclaration */) { if (declaration.flags & 262144 /* ContainsThis */) { return false; } var baseTypeNodes = ts.getInterfaceBaseTypeNodes(declaration); if (baseTypeNodes) { for (var _b = 0, baseTypeNodes_1 = baseTypeNodes; _b < baseTypeNodes_1.length; _b++) { var node = baseTypeNodes_1[_b]; if (ts.isSupportedExpressionWithTypeArguments(node)) { var baseSymbol = resolveEntityName(node.expression, 793056 /* Type */, /*ignoreErrors*/ true); if (!baseSymbol || !(baseSymbol.flags & 64 /* Interface */) || getDeclaredTypeOfClassOrInterface(baseSymbol).thisType) { return false; } } } } } } return true; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
isIndependentInterface
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getDeclaredTypeOfClassOrInterface(symbol) { var links = getSymbolLinks(symbol); if (!links.declaredType) { var kind = symbol.flags & 32 /* Class */ ? 1024 /* Class */ : 2048 /* Interface */; var type = links.declaredType = createObjectType(kind, symbol); var outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol); var localTypeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); // A class or interface is generic if it has type parameters or a "this" type. We always give classes a "this" type // because it is not feasible to analyze all members to determine if the "this" type escapes the class (in particular, // property types inferred from initializers and method return types inferred from return statements are very hard // to exhaustively analyze). We give interfaces a "this" type if we can't definitely determine that they are free of // "this" references. if (outerTypeParameters || localTypeParameters || kind === 1024 /* Class */ || !isIndependentInterface(symbol)) { type.flags |= 4096 /* Reference */; type.typeParameters = ts.concatenate(outerTypeParameters, localTypeParameters); type.outerTypeParameters = outerTypeParameters; type.localTypeParameters = localTypeParameters; type.instantiations = {}; type.instantiations[getTypeListId(type.typeParameters)] = type; type.target = type; type.typeArguments = type.typeParameters; type.thisType = createType(512 /* TypeParameter */ | 33554432 /* ThisType */); type.thisType.symbol = symbol; type.thisType.constraint = type; } } return links.declaredType; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
getDeclaredTypeOfClassOrInterface
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getDeclaredTypeOfTypeAlias(symbol) { var links = getSymbolLinks(symbol); if (!links.declaredType) { // Note that we use the links object as the target here because the symbol object is used as the unique // identity for resolution of the 'type' property in SymbolLinks. if (!pushTypeResolution(symbol, 2 /* DeclaredType */)) { return unknownType; } var declaration = ts.getDeclarationOfKind(symbol, 216 /* TypeAliasDeclaration */); var type = getTypeFromTypeNode(declaration.type); if (popTypeResolution()) { links.typeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); if (links.typeParameters) { // Initialize the instantiation cache for generic type aliases. The declared type corresponds to // an instantiation of the type alias with the type parameters supplied as type arguments. links.instantiations = {}; links.instantiations[getTypeListId(links.typeParameters)] = type; } } else { type = unknownType; error(declaration.name, ts.Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol)); } links.declaredType = type; } return links.declaredType; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
getDeclaredTypeOfTypeAlias
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getDeclaredTypeOfEnum(symbol) { var links = getSymbolLinks(symbol); if (!links.declaredType) { var type = createType(128 /* Enum */); type.symbol = symbol; links.declaredType = type; } return links.declaredType; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
getDeclaredTypeOfEnum
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getDeclaredTypeOfTypeParameter(symbol) { var links = getSymbolLinks(symbol); if (!links.declaredType) { var type = createType(512 /* TypeParameter */); type.symbol = symbol; if (!ts.getDeclarationOfKind(symbol, 137 /* TypeParameter */).constraint) { type.constraint = noConstraintType; } links.declaredType = type; } return links.declaredType; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
getDeclaredTypeOfTypeParameter
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getDeclaredTypeOfAlias(symbol) { var links = getSymbolLinks(symbol); if (!links.declaredType) { links.declaredType = getDeclaredTypeOfSymbol(resolveAlias(symbol)); } return links.declaredType; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
getDeclaredTypeOfAlias
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getDeclaredTypeOfSymbol(symbol) { ts.Debug.assert((symbol.flags & 16777216 /* Instantiated */) === 0); if (symbol.flags & (32 /* Class */ | 64 /* Interface */)) { return getDeclaredTypeOfClassOrInterface(symbol); } if (symbol.flags & 524288 /* TypeAlias */) { return getDeclaredTypeOfTypeAlias(symbol); } if (symbol.flags & 384 /* Enum */) { return getDeclaredTypeOfEnum(symbol); } if (symbol.flags & 262144 /* TypeParameter */) { return getDeclaredTypeOfTypeParameter(symbol); } if (symbol.flags & 8388608 /* Alias */) { return getDeclaredTypeOfAlias(symbol); } return unknownType; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
getDeclaredTypeOfSymbol
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isIndependentType(node) { switch (node.kind) { case 117 /* AnyKeyword */: case 130 /* StringKeyword */: case 128 /* NumberKeyword */: case 120 /* BooleanKeyword */: case 131 /* SymbolKeyword */: case 103 /* VoidKeyword */: case 9 /* StringLiteral */: return true; case 156 /* ArrayType */: return isIndependentType(node.elementType); case 151 /* TypeReference */: return isIndependentTypeReference(node); } return false; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
isIndependentType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isIndependentMember(symbol) { if (symbol.declarations && symbol.declarations.length === 1) { var declaration = symbol.declarations[0]; if (declaration) { switch (declaration.kind) { case 141 /* PropertyDeclaration */: case 140 /* PropertySignature */: return isIndependentVariableLikeDeclaration(declaration); case 143 /* MethodDeclaration */: case 142 /* MethodSignature */: case 144 /* Constructor */: return isIndependentFunctionLikeDeclaration(declaration); } } } return false; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
isIndependentMember
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function createSymbolTable(symbols) { var result = {}; for (var _i = 0, symbols_1 = symbols; _i < symbols_1.length; _i++) { var symbol = symbols_1[_i]; result[symbol.name] = symbol; } return result; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
createSymbolTable
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function createInstantiatedSymbolTable(symbols, mapper, mappingThisOnly) { var result = {}; for (var _i = 0, symbols_2 = symbols; _i < symbols_2.length; _i++) { var symbol = symbols_2[_i]; result[symbol.name] = mappingThisOnly && isIndependentMember(symbol) ? symbol : instantiateSymbol(symbol, mapper); } return result; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
createInstantiatedSymbolTable
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function addInheritedMembers(symbols, baseSymbols) { for (var _i = 0, baseSymbols_1 = baseSymbols; _i < baseSymbols_1.length; _i++) { var s = baseSymbols_1[_i]; if (!ts.hasProperty(symbols, s.name)) { symbols[s.name] = s; } } }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
addInheritedMembers
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function addInheritedSignatures(signatures, baseSignatures) { if (baseSignatures) { for (var _i = 0, baseSignatures_1 = baseSignatures; _i < baseSignatures_1.length; _i++) { var signature = baseSignatures_1[_i]; signatures.push(signature); } } }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
addInheritedSignatures
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function resolveDeclaredMembers(type) { if (!type.declaredProperties) { var symbol = type.symbol; type.declaredProperties = getNamedMembers(symbol.members); type.declaredCallSignatures = getSignaturesOfSymbol(symbol.members["__call"]); type.declaredConstructSignatures = getSignaturesOfSymbol(symbol.members["__new"]); type.declaredStringIndexType = getIndexTypeOfSymbol(symbol, 0 /* String */); type.declaredNumberIndexType = getIndexTypeOfSymbol(symbol, 1 /* Number */); } return type; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
resolveDeclaredMembers
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getTypeWithThisArgument(type, thisArgument) { if (type.flags & 4096 /* Reference */) { return createTypeReference(type.target, ts.concatenate(type.typeArguments, [thisArgument || type.target.thisType])); } return type; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
getTypeWithThisArgument
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function resolveObjectTypeMembers(type, source, typeParameters, typeArguments) { var mapper = identityMapper; var members = source.symbol.members; var callSignatures = source.declaredCallSignatures; var constructSignatures = source.declaredConstructSignatures; var stringIndexType = source.declaredStringIndexType; var numberIndexType = source.declaredNumberIndexType; if (!ts.rangeEquals(typeParameters, typeArguments, 0, typeParameters.length)) { mapper = createTypeMapper(typeParameters, typeArguments); members = createInstantiatedSymbolTable(source.declaredProperties, mapper, /*mappingThisOnly*/ typeParameters.length === 1); callSignatures = instantiateList(source.declaredCallSignatures, mapper, instantiateSignature); constructSignatures = instantiateList(source.declaredConstructSignatures, mapper, instantiateSignature); stringIndexType = instantiateType(source.declaredStringIndexType, mapper); numberIndexType = instantiateType(source.declaredNumberIndexType, mapper); } var baseTypes = getBaseTypes(source); if (baseTypes.length) { if (members === source.symbol.members) { members = createSymbolTable(source.declaredProperties); } var thisArgument = ts.lastOrUndefined(typeArguments); for (var _i = 0, baseTypes_1 = baseTypes; _i < baseTypes_1.length; _i++) { var baseType = baseTypes_1[_i]; var instantiatedBaseType = thisArgument ? getTypeWithThisArgument(instantiateType(baseType, mapper), thisArgument) : baseType; addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType)); callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, 0 /* Call */)); constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, 1 /* Construct */)); stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, 0 /* String */); numberIndexType = numberIndexType || getIndexTypeOfType(instantiatedBaseType, 1 /* Number */); } } setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
resolveObjectTypeMembers
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function resolveClassOrInterfaceMembers(type) { resolveObjectTypeMembers(type, resolveDeclaredMembers(type), emptyArray, emptyArray); }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
resolveClassOrInterfaceMembers
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function resolveTypeReferenceMembers(type) { var source = resolveDeclaredMembers(type.target); var typeParameters = ts.concatenate(source.typeParameters, [source.thisType]); var typeArguments = type.typeArguments && type.typeArguments.length === typeParameters.length ? type.typeArguments : ts.concatenate(type.typeArguments, [type]); resolveObjectTypeMembers(type, source, typeParameters, typeArguments); }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
resolveTypeReferenceMembers
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function createSignature(declaration, typeParameters, parameters, resolvedReturnType, typePredicate, minArgumentCount, hasRestParameter, hasStringLiterals) { var sig = new Signature(checker); sig.declaration = declaration; sig.typeParameters = typeParameters; sig.parameters = parameters; sig.resolvedReturnType = resolvedReturnType; sig.typePredicate = typePredicate; sig.minArgumentCount = minArgumentCount; sig.hasRestParameter = hasRestParameter; sig.hasStringLiterals = hasStringLiterals; return sig; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
createSignature
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function cloneSignature(sig) { return createSignature(sig.declaration, sig.typeParameters, sig.parameters, sig.resolvedReturnType, sig.typePredicate, sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals); }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
cloneSignature
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getDefaultConstructSignatures(classType) { if (!hasClassBaseType(classType)) { return [createSignature(undefined, classType.localTypeParameters, emptyArray, classType, undefined, 0, false, false)]; } var baseConstructorType = getBaseConstructorTypeOfClass(classType); var baseSignatures = getSignaturesOfType(baseConstructorType, 1 /* Construct */); var baseTypeNode = getBaseTypeNodeOfClass(classType); var typeArguments = ts.map(baseTypeNode.typeArguments, getTypeFromTypeNode); var typeArgCount = typeArguments ? typeArguments.length : 0; var result = []; for (var _i = 0, baseSignatures_2 = baseSignatures; _i < baseSignatures_2.length; _i++) { var baseSig = baseSignatures_2[_i]; var typeParamCount = baseSig.typeParameters ? baseSig.typeParameters.length : 0; if (typeParamCount === typeArgCount) { var sig = typeParamCount ? getSignatureInstantiation(baseSig, typeArguments) : cloneSignature(baseSig); sig.typeParameters = classType.localTypeParameters; sig.resolvedReturnType = classType; result.push(sig); } } return result; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
getDefaultConstructSignatures
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function createTupleTypeMemberSymbols(memberTypes) { var members = {}; for (var i = 0; i < memberTypes.length; i++) { var symbol = createSymbol(4 /* Property */ | 67108864 /* Transient */, "" + i); symbol.type = memberTypes[i]; members[i] = symbol; } return members; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
createTupleTypeMemberSymbols
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function resolveTupleTypeMembers(type) { var arrayElementType = getUnionType(type.elementTypes, /*noSubtypeReduction*/ true); // Make the tuple type itself the 'this' type by including an extra type argument var arrayType = resolveStructuredTypeMembers(createTypeFromGenericGlobalType(globalArrayType, [arrayElementType, type])); var members = createTupleTypeMemberSymbols(type.elementTypes); addInheritedMembers(members, arrayType.properties); setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType); }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
resolveTupleTypeMembers
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function findMatchingSignature(signatureList, signature, partialMatch, ignoreReturnTypes) { for (var _i = 0, signatureList_1 = signatureList; _i < signatureList_1.length; _i++) { var s = signatureList_1[_i]; if (compareSignatures(s, signature, partialMatch, ignoreReturnTypes, compareTypes)) { return s; } } }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
findMatchingSignature
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function findMatchingSignatures(signatureLists, signature, listIndex) { if (signature.typeParameters) { // We require an exact match for generic signatures, so we only return signatures from the first // signature list and only if they have exact matches in the other signature lists. if (listIndex > 0) { return undefined; } for (var i = 1; i < signatureLists.length; i++) { if (!findMatchingSignature(signatureLists[i], signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ false)) { return undefined; } } return [signature]; } var result = undefined; for (var i = 0; i < signatureLists.length; i++) { // Allow matching non-generic signatures to have excess parameters and different return types var match = i === listIndex ? signature : findMatchingSignature(signatureLists[i], signature, /*partialMatch*/ true, /*ignoreReturnTypes*/ true); if (!match) { return undefined; } if (!ts.contains(result, match)) { (result || (result = [])).push(match); } } return result; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
findMatchingSignatures
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getUnionIndexType(types, kind) { var indexTypes = []; for (var _i = 0, types_1 = types; _i < types_1.length; _i++) { var type = types_1[_i]; var indexType = getIndexTypeOfType(type, kind); if (!indexType) { return undefined; } indexTypes.push(indexType); } return getUnionType(indexTypes); }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
getUnionIndexType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function resolveUnionTypeMembers(type) { // The members and properties collections are empty for union types. To get all properties of a union // type use getPropertiesOfType (only the language service uses this). var callSignatures = getUnionSignatures(type.types, 0 /* Call */); var constructSignatures = getUnionSignatures(type.types, 1 /* Construct */); var stringIndexType = getUnionIndexType(type.types, 0 /* String */); var numberIndexType = getUnionIndexType(type.types, 1 /* Number */); setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexType, numberIndexType); }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
resolveUnionTypeMembers
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function intersectTypes(type1, type2) { return !type1 ? type2 : !type2 ? type1 : getIntersectionType([type1, type2]); }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
intersectTypes
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function resolveIntersectionTypeMembers(type) { // The members and properties collections are empty for intersection types. To get all properties of an // intersection type use getPropertiesOfType (only the language service uses this). var callSignatures = emptyArray; var constructSignatures = emptyArray; var stringIndexType = undefined; var numberIndexType = undefined; for (var _i = 0, _a = type.types; _i < _a.length; _i++) { var t = _a[_i]; callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(t, 0 /* Call */)); constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(t, 1 /* Construct */)); stringIndexType = intersectTypes(stringIndexType, getIndexTypeOfType(t, 0 /* String */)); numberIndexType = intersectTypes(numberIndexType, getIndexTypeOfType(t, 1 /* Number */)); } setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexType, numberIndexType); }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
resolveIntersectionTypeMembers
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function resolveAnonymousTypeMembers(type) { var symbol = type.symbol; var members; var callSignatures; var constructSignatures; var stringIndexType; var numberIndexType; if (type.target) { members = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, /*mappingThisOnly*/ false); callSignatures = instantiateList(getSignaturesOfType(type.target, 0 /* Call */), type.mapper, instantiateSignature); constructSignatures = instantiateList(getSignaturesOfType(type.target, 1 /* Construct */), type.mapper, instantiateSignature); stringIndexType = instantiateType(getIndexTypeOfType(type.target, 0 /* String */), type.mapper); numberIndexType = instantiateType(getIndexTypeOfType(type.target, 1 /* Number */), type.mapper); } else if (symbol.flags & 2048 /* TypeLiteral */) { members = symbol.members; callSignatures = getSignaturesOfSymbol(members["__call"]); constructSignatures = getSignaturesOfSymbol(members["__new"]); stringIndexType = getIndexTypeOfSymbol(symbol, 0 /* String */); numberIndexType = getIndexTypeOfSymbol(symbol, 1 /* Number */); } else { // Combinations of function, class, enum and module members = emptySymbols; callSignatures = emptyArray; constructSignatures = emptyArray; if (symbol.flags & 1952 /* HasExports */) { members = getExportsOfSymbol(symbol); } if (symbol.flags & (16 /* Function */ | 8192 /* Method */)) { callSignatures = getSignaturesOfSymbol(symbol); } if (symbol.flags & 32 /* Class */) { var classType = getDeclaredTypeOfClassOrInterface(symbol); constructSignatures = getSignaturesOfSymbol(symbol.members["__constructor"]); if (!constructSignatures.length) { constructSignatures = getDefaultConstructSignatures(classType); } var baseConstructorType = getBaseConstructorTypeOfClass(classType); if (baseConstructorType.flags & 80896 /* ObjectType */) { members = createSymbolTable(getNamedMembers(members)); addInheritedMembers(members, getPropertiesOfObjectType(baseConstructorType)); } } stringIndexType = undefined; numberIndexType = (symbol.flags & 384 /* Enum */) ? stringType : undefined; } setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
resolveAnonymousTypeMembers
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function resolveStructuredTypeMembers(type) { if (!type.members) { if (type.flags & 4096 /* Reference */) { resolveTypeReferenceMembers(type); } else if (type.flags & (1024 /* Class */ | 2048 /* Interface */)) { resolveClassOrInterfaceMembers(type); } else if (type.flags & 65536 /* Anonymous */) { resolveAnonymousTypeMembers(type); } else if (type.flags & 8192 /* Tuple */) { resolveTupleTypeMembers(type); } else if (type.flags & 16384 /* Union */) { resolveUnionTypeMembers(type); } else if (type.flags & 32768 /* Intersection */) { resolveIntersectionTypeMembers(type); } } return type; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
resolveStructuredTypeMembers
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getPropertiesOfObjectType(type) { if (type.flags & 80896 /* ObjectType */) { return resolveStructuredTypeMembers(type).properties; } return emptyArray; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
getPropertiesOfObjectType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getPropertiesOfUnionOrIntersectionType(type) { for (var _i = 0, _a = type.types; _i < _a.length; _i++) { var current = _a[_i]; for (var _b = 0, _c = getPropertiesOfType(current); _b < _c.length; _b++) { var prop = _c[_b]; getPropertyOfUnionOrIntersectionType(type, prop.name); } // The properties of a union type are those that are present in all constituent types, so // we only need to check the properties of the first type if (type.flags & 16384 /* Union */) { break; } } return type.resolvedProperties ? symbolsToArray(type.resolvedProperties) : emptyArray; }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
getPropertiesOfUnionOrIntersectionType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getPropertiesOfType(type) { type = getApparentType(type); return type.flags & 49152 /* UnionOrIntersection */ ? getPropertiesOfUnionOrIntersectionType(type) : getPropertiesOfObjectType(type); }
Push an entry on the type resolution stack. If an entry with the given target and the given property name is already on the stack, and no entries in between already have a type, then a circularity has occurred. In this case, the result values of the existing entry and all entries pushed after it are changed to false, and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. In order to see if the same query has already been done before, the target object and the propertyName both must match the one passed in. @param target The symbol, type, or signature whose type is being queried @param propertyName The property name that should be used to query the target for its type
getPropertiesOfType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getApparentTypeOfTypeParameter(type) { if (!type.resolvedApparentType) { var constraintType = getConstraintOfTypeParameter(type); while (constraintType && constraintType.flags & 512 /* TypeParameter */) { constraintType = getConstraintOfTypeParameter(constraintType); } type.resolvedApparentType = getTypeWithThisArgument(constraintType || emptyObjectType, type); } return type.resolvedApparentType; }
The apparent type of a type parameter is the base constraint instantiated with the type parameter as the type argument for the 'this' type.
getApparentTypeOfTypeParameter
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getGlobalESSymbolConstructorSymbol() { return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol")); }
Returns a type that is inside a namespace at the global scope, e.g. getExportedTypeFromNamespace('JSX', 'Element') returns the JSX.Element type
getGlobalESSymbolConstructorSymbol
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function createTypeFromGenericGlobalType(genericGlobalType, typeArguments) { return genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, typeArguments) : emptyObjectType; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
createTypeFromGenericGlobalType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function createIterableType(elementType) { return createTypeFromGenericGlobalType(globalIterableType, [elementType]); }
Instantiates a global type that is generic with some element type, and returns that instantiation.
createIterableType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function createIterableIteratorType(elementType) { return createTypeFromGenericGlobalType(globalIterableIteratorType, [elementType]); }
Instantiates a global type that is generic with some element type, and returns that instantiation.
createIterableIteratorType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function createArrayType(elementType) { return createTypeFromGenericGlobalType(globalArrayType, [elementType]); }
Instantiates a global type that is generic with some element type, and returns that instantiation.
createArrayType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getTypeFromArrayTypeNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { links.resolvedType = createArrayType(getTypeFromTypeNode(node.elementType)); } return links.resolvedType; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
getTypeFromArrayTypeNode
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function createTupleType(elementTypes) { var id = getTypeListId(elementTypes); return tupleTypes[id] || (tupleTypes[id] = createNewTupleType(elementTypes)); }
Instantiates a global type that is generic with some element type, and returns that instantiation.
createTupleType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function createNewTupleType(elementTypes) { var type = createObjectType(8192 /* Tuple */ | getPropagatingFlagsOfTypes(elementTypes)); type.elementTypes = elementTypes; return type; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
createNewTupleType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getTypeFromTupleTypeNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { links.resolvedType = createTupleType(ts.map(node.elementTypes, getTypeFromTypeNode)); } return links.resolvedType; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
getTypeFromTupleTypeNode
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function addTypeToSet(typeSet, type, typeSetKind) { if (type.flags & typeSetKind) { addTypesToSet(typeSet, type.types, typeSetKind); } else if (!ts.contains(typeSet, type)) { typeSet.push(type); } }
Instantiates a global type that is generic with some element type, and returns that instantiation.
addTypeToSet
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function addTypesToSet(typeSet, types, typeSetKind) { for (var _i = 0, types_4 = types; _i < types_4.length; _i++) { var type = types_4[_i]; addTypeToSet(typeSet, type, typeSetKind); } }
Instantiates a global type that is generic with some element type, and returns that instantiation.
addTypesToSet
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isSubtypeOfAny(candidate, types) { for (var i = 0, len = types.length; i < len; i++) { if (candidate !== types[i] && isTypeSubtypeOf(candidate, types[i])) { return true; } } return false; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
isSubtypeOfAny
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function removeSubtypes(types) { var i = types.length; while (i > 0) { i--; if (isSubtypeOfAny(types[i], types)) { types.splice(i, 1); } } }
Instantiates a global type that is generic with some element type, and returns that instantiation.
removeSubtypes
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function containsTypeAny(types) { for (var _i = 0, types_5 = types; _i < types_5.length; _i++) { var type = types_5[_i]; if (isTypeAny(type)) { return true; } } return false; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
containsTypeAny
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function removeAllButLast(types, typeToRemove) { var i = types.length; while (i > 0 && types.length > 1) { i--; if (types[i] === typeToRemove) { types.splice(i, 1); } } }
Instantiates a global type that is generic with some element type, and returns that instantiation.
removeAllButLast
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getTypeFromUnionTypeNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { links.resolvedType = getUnionType(ts.map(node.types, getTypeFromTypeNode), /*noSubtypeReduction*/ true); } return links.resolvedType; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
getTypeFromUnionTypeNode
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getTypeFromIntersectionTypeNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { links.resolvedType = getIntersectionType(ts.map(node.types, getTypeFromTypeNode)); } return links.resolvedType; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
getTypeFromIntersectionTypeNode
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { // Deferred resolution of members is handled by resolveObjectTypeMembers links.resolvedType = createObjectType(65536 /* Anonymous */, node.symbol); } return links.resolvedType; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getStringLiteralType(node) { var text = node.text; if (ts.hasProperty(stringLiteralTypes, text)) { return stringLiteralTypes[text]; } var type = stringLiteralTypes[text] = createType(256 /* StringLiteral */); type.text = text; return type; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
getStringLiteralType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getTypeFromStringLiteral(node) { var links = getNodeLinks(node); if (!links.resolvedType) { links.resolvedType = getStringLiteralType(node); } return links.resolvedType; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
getTypeFromStringLiteral
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getThisType(node) { var container = ts.getThisContainer(node, /*includeArrowFunctions*/ false); var parent = container && container.parent; if (parent && (ts.isClassLike(parent) || parent.kind === 215 /* InterfaceDeclaration */)) { if (!(container.flags & 64 /* Static */) && (container.kind !== 144 /* Constructor */ || ts.isNodeDescendentOf(node, container.body))) { return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(parent)).thisType; } } error(node, ts.Diagnostics.A_this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface); return unknownType; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
getThisType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getTypeFromThisTypeNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { links.resolvedType = getThisType(node); } return links.resolvedType; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
getTypeFromThisTypeNode
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getTypeFromTypeNode(node) { switch (node.kind) { case 117 /* AnyKeyword */: return anyType; case 130 /* StringKeyword */: return stringType; case 128 /* NumberKeyword */: return numberType; case 120 /* BooleanKeyword */: return booleanType; case 131 /* SymbolKeyword */: return esSymbolType; case 103 /* VoidKeyword */: return voidType; case 97 /* ThisKeyword */: return getTypeFromThisTypeNode(node); case 9 /* StringLiteral */: return getTypeFromStringLiteral(node); case 151 /* TypeReference */: return getTypeFromTypeReference(node); case 150 /* TypePredicate */: return booleanType; case 188 /* ExpressionWithTypeArguments */: return getTypeFromTypeReference(node); case 154 /* TypeQuery */: return getTypeFromTypeQueryNode(node); case 156 /* ArrayType */: return getTypeFromArrayTypeNode(node); case 157 /* TupleType */: return getTypeFromTupleTypeNode(node); case 158 /* UnionType */: return getTypeFromUnionTypeNode(node); case 159 /* IntersectionType */: return getTypeFromIntersectionTypeNode(node); case 160 /* ParenthesizedType */: return getTypeFromTypeNode(node.type); case 152 /* FunctionType */: case 153 /* ConstructorType */: case 155 /* TypeLiteral */: return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); // This function assumes that an identifier or qualified name is a type expression // Callers should first ensure this by calling isTypeNode case 69 /* Identifier */: case 135 /* QualifiedName */: var symbol = getSymbolAtLocation(node); return symbol && getDeclaredTypeOfSymbol(symbol); default: return unknownType; } }
Instantiates a global type that is generic with some element type, and returns that instantiation.
getTypeFromTypeNode
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function instantiateList(items, mapper, instantiator) { if (items && items.length) { var result = []; for (var _i = 0, items_1 = items; _i < items_1.length; _i++) { var v = items_1[_i]; result.push(instantiator(v, mapper)); } return result; } return items; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
instantiateList
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function createUnaryTypeMapper(source, target) { return function (t) { return t === source ? target : t; }; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
createUnaryTypeMapper
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function createBinaryTypeMapper(source1, target1, source2, target2) { return function (t) { return t === source1 ? target1 : t === source2 ? target2 : t; }; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
createBinaryTypeMapper
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function createTypeMapper(sources, targets) { switch (sources.length) { case 1: return createUnaryTypeMapper(sources[0], targets[0]); case 2: return createBinaryTypeMapper(sources[0], targets[0], sources[1], targets[1]); } return function (t) { for (var i = 0; i < sources.length; i++) { if (t === sources[i]) { return targets[i]; } } return t; }; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
createTypeMapper
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function createUnaryTypeEraser(source) { return function (t) { return t === source ? anyType : t; }; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
createUnaryTypeEraser
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function createBinaryTypeEraser(source1, source2) { return function (t) { return t === source1 || t === source2 ? anyType : t; }; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
createBinaryTypeEraser
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function createTypeEraser(sources) { switch (sources.length) { case 1: return createUnaryTypeEraser(sources[0]); case 2: return createBinaryTypeEraser(sources[0], sources[1]); } return function (t) { for (var _i = 0, sources_1 = sources; _i < sources_1.length; _i++) { var source = sources_1[_i]; if (t === source) { return anyType; } } return t; }; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
createTypeEraser
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function createInferenceMapper(context) { var mapper = function (t) { for (var i = 0; i < context.typeParameters.length; i++) { if (t === context.typeParameters[i]) { context.inferences[i].isFixed = true; return getInferredType(context, i); } } return t; }; mapper.context = context; return mapper; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
createInferenceMapper
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
mapper = function (t) { for (var i = 0; i < context.typeParameters.length; i++) { if (t === context.typeParameters[i]) { context.inferences[i].isFixed = true; return getInferredType(context, i); } } return t; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
mapper
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function identityMapper(type) { return type; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
identityMapper
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function combineTypeMappers(mapper1, mapper2) { return function (t) { return instantiateType(mapper1(t), mapper2); }; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
combineTypeMappers
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function instantiateTypeParameter(typeParameter, mapper) { var result = createType(512 /* TypeParameter */); result.symbol = typeParameter.symbol; if (typeParameter.constraint) { result.constraint = instantiateType(typeParameter.constraint, mapper); } else { result.target = typeParameter; result.mapper = mapper; } return result; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
instantiateTypeParameter
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function instantiateSignature(signature, mapper, eraseTypeParameters) { var freshTypeParameters; var freshTypePredicate; if (signature.typeParameters && !eraseTypeParameters) { freshTypeParameters = instantiateList(signature.typeParameters, mapper, instantiateTypeParameter); mapper = combineTypeMappers(createTypeMapper(signature.typeParameters, freshTypeParameters), mapper); } if (signature.typePredicate) { freshTypePredicate = { parameterName: signature.typePredicate.parameterName, parameterIndex: signature.typePredicate.parameterIndex, type: instantiateType(signature.typePredicate.type, mapper) }; } var result = createSignature(signature.declaration, freshTypeParameters, instantiateList(signature.parameters, mapper, instantiateSymbol), instantiateType(signature.resolvedReturnType, mapper), freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); result.target = signature; result.mapper = mapper; return result; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
instantiateSignature
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function instantiateSymbol(symbol, mapper) { if (symbol.flags & 16777216 /* Instantiated */) { var links = getSymbolLinks(symbol); // If symbol being instantiated is itself a instantiation, fetch the original target and combine the // type mappers. This ensures that original type identities are properly preserved and that aliases // always reference a non-aliases. symbol = links.target; mapper = combineTypeMappers(links.mapper, mapper); } // Keep the flags from the symbol we're instantiating. Mark that is instantiated, and // also transient so that we can just store data on it directly. var result = createSymbol(16777216 /* Instantiated */ | 67108864 /* Transient */ | symbol.flags, symbol.name); result.declarations = symbol.declarations; result.parent = symbol.parent; result.target = symbol; result.mapper = mapper; if (symbol.valueDeclaration) { result.valueDeclaration = symbol.valueDeclaration; } return result; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
instantiateSymbol
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function instantiateAnonymousType(type, mapper) { if (mapper.instantiations) { var cachedType = mapper.instantiations[type.id]; if (cachedType) { return cachedType; } } else { mapper.instantiations = []; } // Mark the anonymous type as instantiated such that our infinite instantiation detection logic can recognize it var result = createObjectType(65536 /* Anonymous */ | 131072 /* Instantiated */, type.symbol); result.target = type; result.mapper = mapper; mapper.instantiations[type.id] = result; return result; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
instantiateAnonymousType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function instantiateType(type, mapper) { if (type && mapper !== identityMapper) { if (type.flags & 512 /* TypeParameter */) { return mapper(type); } if (type.flags & 65536 /* Anonymous */) { return type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */) ? instantiateAnonymousType(type, mapper) : type; } if (type.flags & 4096 /* Reference */) { return createTypeReference(type.target, instantiateList(type.typeArguments, mapper, instantiateType)); } if (type.flags & 8192 /* Tuple */) { return createTupleType(instantiateList(type.elementTypes, mapper, instantiateType)); } if (type.flags & 16384 /* Union */) { return getUnionType(instantiateList(type.types, mapper, instantiateType), /*noSubtypeReduction*/ true); } if (type.flags & 32768 /* Intersection */) { return getIntersectionType(instantiateList(type.types, mapper, instantiateType)); } } return type; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
instantiateType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isContextSensitive(node) { ts.Debug.assert(node.kind !== 143 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); switch (node.kind) { case 173 /* FunctionExpression */: case 174 /* ArrowFunction */: return isContextSensitiveFunctionLikeDeclaration(node); case 165 /* ObjectLiteralExpression */: return ts.forEach(node.properties, isContextSensitive); case 164 /* ArrayLiteralExpression */: return ts.forEach(node.elements, isContextSensitive); case 182 /* ConditionalExpression */: return isContextSensitive(node.whenTrue) || isContextSensitive(node.whenFalse); case 181 /* BinaryExpression */: return node.operatorToken.kind === 52 /* BarBarToken */ && (isContextSensitive(node.left) || isContextSensitive(node.right)); case 245 /* PropertyAssignment */: return isContextSensitive(node.initializer); case 143 /* MethodDeclaration */: case 142 /* MethodSignature */: return isContextSensitiveFunctionLikeDeclaration(node); case 172 /* ParenthesizedExpression */: return isContextSensitive(node.expression); } return false; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
isContextSensitive
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isContextSensitiveFunctionLikeDeclaration(node) { return !node.typeParameters && node.parameters.length && !ts.forEach(node.parameters, function (p) { return p.type; }); }
Instantiates a global type that is generic with some element type, and returns that instantiation.
isContextSensitiveFunctionLikeDeclaration
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getTypeWithoutSignatures(type) { if (type.flags & 80896 /* ObjectType */) { var resolved = resolveStructuredTypeMembers(type); if (resolved.constructSignatures.length) { var result = createObjectType(65536 /* Anonymous */, type.symbol); result.members = resolved.members; result.properties = resolved.properties; result.callSignatures = emptyArray; result.constructSignatures = emptyArray; type = result; } } return type; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
getTypeWithoutSignatures
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isTypeIdenticalTo(source, target) { return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined); }
Instantiates a global type that is generic with some element type, and returns that instantiation.
isTypeIdenticalTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function compareTypes(source, target) { return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined) ? -1 /* True */ : 0 /* False */; }
Instantiates a global type that is generic with some element type, and returns that instantiation.
compareTypes
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isTypeSubtypeOf(source, target) { return checkTypeSubtypeOf(source, target, /*errorNode*/ undefined); }
Instantiates a global type that is generic with some element type, and returns that instantiation.
isTypeSubtypeOf
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isTypeAssignableTo(source, target) { return checkTypeAssignableTo(source, target, /*errorNode*/ undefined); }
Instantiates a global type that is generic with some element type, and returns that instantiation.
isTypeAssignableTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkTypeSubtypeOf(source, target, errorNode, headMessage, containingMessageChain) { return checkTypeRelatedTo(source, target, subtypeRelation, errorNode, headMessage, containingMessageChain); }
Instantiates a global type that is generic with some element type, and returns that instantiation.
checkTypeSubtypeOf
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkTypeAssignableTo(source, target, errorNode, headMessage, containingMessageChain) { return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage, containingMessageChain); }
Instantiates a global type that is generic with some element type, and returns that instantiation.
checkTypeAssignableTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isSignatureAssignableTo(source, target) { var sourceType = getOrCreateTypeFromSignature(source); var targetType = getOrCreateTypeFromSignature(target); return checkTypeRelatedTo(sourceType, targetType, assignableRelation, /*errorNode*/ undefined); }
Instantiates a global type that is generic with some element type, and returns that instantiation.
isSignatureAssignableTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkTypeRelatedTo(source, target, relation, errorNode, headMessage, containingMessageChain) { var errorInfo; var sourceStack; var targetStack; var maybeStack; var expandingFlags; var depth = 0; var overflow = false; var elaborateErrors = false; ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking"); var result = isRelatedTo(source, target, errorNode !== undefined, headMessage); if (overflow) { error(errorNode, ts.Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target)); } else if (errorInfo) { // If we already computed this relation, but in a context where we didn't want to report errors (e.g. overload resolution), // then we'll only have a top-level error (e.g. 'Class X does not implement interface Y') without any details. If this happened, // request a recompuation to get a complete error message. This will be skipped if we've already done this computation in a context // where errors were being reported. if (errorInfo.next === undefined) { errorInfo = undefined; elaborateErrors = true; isRelatedTo(source, target, errorNode !== undefined, headMessage); } if (containingMessageChain) { errorInfo = ts.concatenateDiagnosticMessageChains(containingMessageChain, errorInfo); } diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(errorNode, errorInfo)); } return result !== 0 /* False */; function reportError(message, arg0, arg1, arg2) { errorInfo = ts.chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); } function reportRelationError(message, source, target) { var sourceType = typeToString(source); var targetType = typeToString(target); if (sourceType === targetType) { sourceType = typeToString(source, /*enclosingDeclaration*/ undefined, 128 /* UseFullyQualifiedType */); targetType = typeToString(target, /*enclosingDeclaration*/ undefined, 128 /* UseFullyQualifiedType */); } reportError(message || ts.Diagnostics.Type_0_is_not_assignable_to_type_1, sourceType, targetType); } // Compare two types and return // Ternary.True if they are related with no assumptions, // Ternary.Maybe if they are related with assumptions of other relationships, or // Ternary.False if they are not related. function isRelatedTo(source, target, reportErrors, headMessage) { var result; // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases if (source === target) return -1 /* True */; if (relation === identityRelation) { return isIdenticalTo(source, target); } if (isTypeAny(target)) return -1 /* True */; if (source === undefinedType) return -1 /* True */; if (source === nullType && target !== undefinedType) return -1 /* True */; if (source.flags & 128 /* Enum */ && target === numberType) return -1 /* True */; if (source.flags & 256 /* StringLiteral */ && target === stringType) return -1 /* True */; if (relation === assignableRelation) { if (isTypeAny(source)) return -1 /* True */; if (source === numberType && target.flags & 128 /* Enum */) return -1 /* True */; } if (source.flags & 1048576 /* FreshObjectLiteral */) { if (hasExcessProperties(source, target, reportErrors)) { if (reportErrors) { reportRelationError(headMessage, source, target); } return 0 /* False */; } // Above we check for excess properties with respect to the entire target type. When union // and intersection types are further deconstructed on the target side, we don't want to // make the check again (as it might fail for a partial target type). Therefore we obtain // the regular source type and proceed with that. if (target.flags & 49152 /* UnionOrIntersection */) { source = getRegularTypeOfObjectLiteral(source); } } var saveErrorInfo = errorInfo; // Note that the "each" checks must precede the "some" checks to produce the correct results if (source.flags & 16384 /* Union */) { if (result = eachTypeRelatedToType(source, target, reportErrors)) { return result; } } else if (target.flags & 32768 /* Intersection */) { if (result = typeRelatedToEachType(source, target, reportErrors)) { return result; } } else { // It is necessary to try "some" checks on both sides because there may be nested "each" checks // on either side that need to be prioritized. For example, A | B = (A | B) & (C | D) or // A & B = (A & B) | (C & D). if (source.flags & 32768 /* Intersection */) { // If target is a union type the following check will report errors so we suppress them here if (result = someTypeRelatedToType(source, target, reportErrors && !(target.flags & 16384 /* Union */))) { return result; } } if (target.flags & 16384 /* Union */) { if (result = typeRelatedToSomeType(source, target, reportErrors)) { return result; } } } if (source.flags & 512 /* TypeParameter */) { var constraint = getConstraintOfTypeParameter(source); if (!constraint || constraint.flags & 1 /* Any */) { constraint = emptyObjectType; } // Report constraint errors only if the constraint is not the empty object type var reportConstraintErrors = reportErrors && constraint !== emptyObjectType; if (result = isRelatedTo(constraint, target, reportConstraintErrors)) { errorInfo = saveErrorInfo; return result; } } else { if (source.flags & 4096 /* Reference */ && target.flags & 4096 /* Reference */ && source.target === target.target) { // We have type references to same target type, see if relationship holds for all type arguments if (result = typeArgumentsRelatedTo(source, target, reportErrors)) { return result; } } // Even if relationship doesn't hold for unions, intersections, or generic type references, // it may hold in a structural comparison. var apparentType = getApparentType(source); // In a check of the form X = A & B, we will have previously checked if A relates to X or B relates // to X. Failing both of those we want to check if the aggregation of A and B's members structurally // relates to X. Thus, we include intersection types on the source side here. if (apparentType.flags & (80896 /* ObjectType */ | 32768 /* Intersection */) && target.flags & 80896 /* ObjectType */) { // Report structural errors only if we haven't reported any errors yet var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo; if (result = objectTypeRelatedTo(apparentType, source, target, reportStructuralErrors)) { errorInfo = saveErrorInfo; return result; } } } if (reportErrors) { reportRelationError(headMessage, source, target); } return 0 /* False */; } function isIdenticalTo(source, target) { var result; if (source.flags & 80896 /* ObjectType */ && target.flags & 80896 /* ObjectType */) { if (source.flags & 4096 /* Reference */ && target.flags & 4096 /* Reference */ && source.target === target.target) { // We have type references to same target type, see if all type arguments are identical if (result = typeArgumentsRelatedTo(source, target, /*reportErrors*/ false)) { return result; } } return objectTypeRelatedTo(source, source, target, /*reportErrors*/ false); } if (source.flags & 512 /* TypeParameter */ && target.flags & 512 /* TypeParameter */) { return typeParameterIdenticalTo(source, target); } if (source.flags & 16384 /* Union */ && target.flags & 16384 /* Union */ || source.flags & 32768 /* Intersection */ && target.flags & 32768 /* Intersection */) { if (result = eachTypeRelatedToSomeType(source, target)) { if (result &= eachTypeRelatedToSomeType(target, source)) { return result; } } } return 0 /* False */; } // Check if a property with the given name is known anywhere in the given type. In an object type, a property // is considered known if the object type is empty and the check is for assignability, if the object type has // index signatures, or if the property is actually declared in the object type. In a union or intersection // type, a property is considered known if it is known in any constituent type. function isKnownProperty(type, name) { if (type.flags & 80896 /* ObjectType */) { var resolved = resolveStructuredTypeMembers(type); if (relation === assignableRelation && (type === globalObjectType || resolved.properties.length === 0) || resolved.stringIndexType || resolved.numberIndexType || getPropertyOfType(type, name)) { return true; } } else if (type.flags & 49152 /* UnionOrIntersection */) { for (var _i = 0, _a = type.types; _i < _a.length; _i++) { var t = _a[_i]; if (isKnownProperty(t, name)) { return true; } } } return false; } function hasExcessProperties(source, target, reportErrors) { if (!(target.flags & 67108864 /* ObjectLiteralPatternWithComputedProperties */) && someConstituentTypeHasKind(target, 80896 /* ObjectType */)) { for (var _i = 0, _a = getPropertiesOfObjectType(source); _i < _a.length; _i++) { var prop = _a[_i]; if (!isKnownProperty(target, prop.name)) { if (reportErrors) { // We know *exactly* where things went wrong when comparing the types. // Use this property as the error node as this will be more helpful in // reasoning about what went wrong. errorNode = prop.valueDeclaration; reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target)); } return true; } } } return false; } function eachTypeRelatedToSomeType(source, target) { var result = -1 /* True */; var sourceTypes = source.types; for (var _i = 0, sourceTypes_1 = sourceTypes; _i < sourceTypes_1.length; _i++) { var sourceType = sourceTypes_1[_i]; var related = typeRelatedToSomeType(sourceType, target, false); if (!related) { return 0 /* False */; } result &= related; } return result; } function typeRelatedToSomeType(source, target, reportErrors) { var targetTypes = target.types; for (var i = 0, len = targetTypes.length; i < len; i++) { var related = isRelatedTo(source, targetTypes[i], reportErrors && i === len - 1); if (related) { return related; } } return 0 /* False */; } function typeRelatedToEachType(source, target, reportErrors) { var result = -1 /* True */; var targetTypes = target.types; for (var _i = 0, targetTypes_1 = targetTypes; _i < targetTypes_1.length; _i++) { var targetType = targetTypes_1[_i]; var related = isRelatedTo(source, targetType, reportErrors); if (!related) { return 0 /* False */; } result &= related; } return result; } function someTypeRelatedToType(source, target, reportErrors) { var sourceTypes = source.types; for (var i = 0, len = sourceTypes.length; i < len; i++) { var related = isRelatedTo(sourceTypes[i], target, reportErrors && i === len - 1); if (related) { return related; } } return 0 /* False */; } function eachTypeRelatedToType(source, target, reportErrors) { var result = -1 /* True */; var sourceTypes = source.types; for (var _i = 0, sourceTypes_2 = sourceTypes; _i < sourceTypes_2.length; _i++) { var sourceType = sourceTypes_2[_i]; var related = isRelatedTo(sourceType, target, reportErrors); if (!related) { return 0 /* False */; } result &= related; } return result; } function typeArgumentsRelatedTo(source, target, reportErrors) { var sources = source.typeArguments || emptyArray; var targets = target.typeArguments || emptyArray; if (sources.length !== targets.length && relation === identityRelation) { return 0 /* False */; } var result = -1 /* True */; for (var i = 0; i < targets.length; i++) { var related = isRelatedTo(sources[i], targets[i], reportErrors); if (!related) { return 0 /* False */; } result &= related; } return result; } function typeParameterIdenticalTo(source, target) { // covers case when both type parameters does not have constraint (both equal to noConstraintType) if (source.constraint === target.constraint) { return -1 /* True */; } if (source.constraint === noConstraintType || target.constraint === noConstraintType) { return 0 /* False */; } return isIdenticalTo(source.constraint, target.constraint); } // Determine if two object types are related by structure. First, check if the result is already available in the global cache. // Second, check if we have already started a comparison of the given two types in which case we assume the result to be true. // Third, check if both types are part of deeply nested chains of generic type instantiations and if so assume the types are // equal and infinitely expanding. Fourth, if we have reached a depth of 100 nested comparisons, assume we have runaway recursion // and issue an error. Otherwise, actually compare the structure of the two types. function objectTypeRelatedTo(apparentSource, originalSource, target, reportErrors) { if (overflow) { return 0 /* False */; } var id = relation !== identityRelation || apparentSource.id < target.id ? apparentSource.id + "," + target.id : target.id + "," + apparentSource.id; var related = relation[id]; if (related !== undefined) { // If we computed this relation already and it was failed and reported, or if we're not being asked to elaborate // errors, we can use the cached value. Otherwise, recompute the relation if (!elaborateErrors || (related === 3 /* FailedAndReported */)) { return related === 1 /* Succeeded */ ? -1 /* True */ : 0 /* False */; } } if (depth > 0) { for (var i = 0; i < depth; i++) { // If source and target are already being compared, consider them related with assumptions if (maybeStack[i][id]) { return 1 /* Maybe */; } } if (depth === 100) { overflow = true; return 0 /* False */; } } else { sourceStack = []; targetStack = []; maybeStack = []; expandingFlags = 0; } sourceStack[depth] = apparentSource; targetStack[depth] = target; maybeStack[depth] = {}; maybeStack[depth][id] = 1 /* Succeeded */; depth++; var saveExpandingFlags = expandingFlags; if (!(expandingFlags & 1) && isDeeplyNestedGeneric(apparentSource, sourceStack, depth)) expandingFlags |= 1; if (!(expandingFlags & 2) && isDeeplyNestedGeneric(target, targetStack, depth)) expandingFlags |= 2; var result; if (expandingFlags === 3) { result = 1 /* Maybe */; } else { result = propertiesRelatedTo(apparentSource, target, reportErrors); if (result) { result &= signaturesRelatedTo(apparentSource, target, 0 /* Call */, reportErrors); if (result) { result &= signaturesRelatedTo(apparentSource, target, 1 /* Construct */, reportErrors); if (result) { result &= stringIndexTypesRelatedTo(apparentSource, originalSource, target, reportErrors); if (result) { result &= numberIndexTypesRelatedTo(apparentSource, originalSource, target, reportErrors); } } } } } expandingFlags = saveExpandingFlags; depth--; if (result) { var maybeCache = maybeStack[depth]; // If result is definitely true, copy assumptions to global cache, else copy to next level up var destinationCache = (result === -1 /* True */ || depth === 0) ? relation : maybeStack[depth - 1]; ts.copyMap(maybeCache, destinationCache); } else { // A false result goes straight into global cache (when something is false under assumptions it // will also be false without assumptions) relation[id] = reportErrors ? 3 /* FailedAndReported */ : 2 /* Failed */; } return result; } function propertiesRelatedTo(source, target, reportErrors) { if (relation === identityRelation) { return propertiesIdenticalTo(source, target); } var result = -1 /* True */; var properties = getPropertiesOfObjectType(target); var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 524288 /* ObjectLiteral */); for (var _i = 0, properties_1 = properties; _i < properties_1.length; _i++) { var targetProp = properties_1[_i]; var sourceProp = getPropertyOfType(source, targetProp.name); if (sourceProp !== targetProp) { if (!sourceProp) { if (!(targetProp.flags & 536870912 /* Optional */) || requireOptionalProperties) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source)); } return 0 /* False */; } } else if (!(targetProp.flags & 134217728 /* Prototype */)) { var sourcePropFlags = getDeclarationFlagsFromSymbol(sourceProp); var targetPropFlags = getDeclarationFlagsFromSymbol(targetProp); if (sourcePropFlags & 16 /* Private */ || targetPropFlags & 16 /* Private */) { if (sourceProp.valueDeclaration !== targetProp.valueDeclaration) { if (reportErrors) { if (sourcePropFlags & 16 /* Private */ && targetPropFlags & 16 /* Private */) { reportError(ts.Diagnostics.Types_have_separate_declarations_of_a_private_property_0, symbolToString(targetProp)); } else { reportError(ts.Diagnostics.Property_0_is_private_in_type_1_but_not_in_type_2, symbolToString(targetProp), typeToString(sourcePropFlags & 16 /* Private */ ? source : target), typeToString(sourcePropFlags & 16 /* Private */ ? target : source)); } } return 0 /* False */; } } else if (targetPropFlags & 32 /* Protected */) { var sourceDeclaredInClass = sourceProp.parent && sourceProp.parent.flags & 32 /* Class */; var sourceClass = sourceDeclaredInClass ? getDeclaredTypeOfSymbol(sourceProp.parent) : undefined; var targetClass = getDeclaredTypeOfSymbol(targetProp.parent); if (!sourceClass || !hasBaseType(sourceClass, targetClass)) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2, symbolToString(targetProp), typeToString(sourceClass || source), typeToString(targetClass)); } return 0 /* False */; } } else if (sourcePropFlags & 32 /* Protected */) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_protected_in_type_1_but_public_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target)); } return 0 /* False */; } var related = isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors); if (!related) { if (reportErrors) { reportError(ts.Diagnostics.Types_of_property_0_are_incompatible, symbolToString(targetProp)); } return 0 /* False */; } result &= related; if (sourceProp.flags & 536870912 /* Optional */ && !(targetProp.flags & 536870912 /* Optional */)) { // TypeScript 1.0 spec (April 2014): 3.8.3 // S is a subtype of a type T, and T is a supertype of S if ... // S' and T are object types and, for each member M in T.. // M is a property and S' contains a property N where // if M is a required property, N is also a required property // (M - property in T) // (N - property in S) if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_optional_in_type_1_but_required_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target)); } return 0 /* False */; } } } } return result; } function propertiesIdenticalTo(source, target) { if (!(source.flags & 80896 /* ObjectType */ && target.flags & 80896 /* ObjectType */)) { return 0 /* False */; } var sourceProperties = getPropertiesOfObjectType(source); var targetProperties = getPropertiesOfObjectType(target); if (sourceProperties.length !== targetProperties.length) { return 0 /* False */; } var result = -1 /* True */; for (var _i = 0, sourceProperties_1 = sourceProperties; _i < sourceProperties_1.length; _i++) { var sourceProp = sourceProperties_1[_i]; var targetProp = getPropertyOfObjectType(target, sourceProp.name); if (!targetProp) { return 0 /* False */; } var related = compareProperties(sourceProp, targetProp, isRelatedTo); if (!related) { return 0 /* False */; } result &= related; } return result; } function signaturesRelatedTo(source, target, kind, reportErrors) { if (relation === identityRelation) { return signaturesIdenticalTo(source, target, kind); } if (target === anyFunctionType || source === anyFunctionType) { return -1 /* True */; } var sourceSignatures = getSignaturesOfType(source, kind); var targetSignatures = getSignaturesOfType(target, kind); var result = -1 /* True */; var saveErrorInfo = errorInfo; if (kind === 1 /* Construct */) { // Only want to compare the construct signatures for abstractness guarantees. // Because the "abstractness" of a class is the same across all construct signatures // (internally we are checking the corresponding declaration), it is enough to perform // the check and report an error once over all pairs of source and target construct signatures. // // sourceSig and targetSig are (possibly) undefined. // // Note that in an extends-clause, targetSignatures is stripped, so the check never proceeds. var sourceSig = sourceSignatures[0]; var targetSig = targetSignatures[0]; result &= abstractSignatureRelatedTo(source, sourceSig, target, targetSig); if (result !== -1 /* True */) { return result; } } outer: for (var _i = 0, targetSignatures_1 = targetSignatures; _i < targetSignatures_1.length; _i++) { var t = targetSignatures_1[_i]; if (!t.hasStringLiterals || target.flags & 262144 /* FromSignature */) { var localErrors = reportErrors; var checkedAbstractAssignability = false; for (var _a = 0, sourceSignatures_1 = sourceSignatures; _a < sourceSignatures_1.length; _a++) { var s = sourceSignatures_1[_a]; if (!s.hasStringLiterals || source.flags & 262144 /* FromSignature */) { var related = signatureRelatedTo(s, t, localErrors); if (related) { result &= related; errorInfo = saveErrorInfo; continue outer; } // Only report errors from the first failure localErrors = false; } } return 0 /* False */; } } return result; function abstractSignatureRelatedTo(source, sourceSig, target, targetSig) { if (sourceSig && targetSig) { var sourceDecl = source.symbol && getClassLikeDeclarationOfSymbol(source.symbol); var targetDecl = target.symbol && getClassLikeDeclarationOfSymbol(target.symbol); if (!sourceDecl) { // If the source object isn't itself a class declaration, it can be freely assigned, regardless // of whether the constructed object is abstract or not. return -1 /* True */; } var sourceErasedSignature = getErasedSignature(sourceSig); var targetErasedSignature = getErasedSignature(targetSig); var sourceReturnType = sourceErasedSignature && getReturnTypeOfSignature(sourceErasedSignature); var targetReturnType = targetErasedSignature && getReturnTypeOfSignature(targetErasedSignature); var sourceReturnDecl = sourceReturnType && sourceReturnType.symbol && getClassLikeDeclarationOfSymbol(sourceReturnType.symbol); var targetReturnDecl = targetReturnType && targetReturnType.symbol && getClassLikeDeclarationOfSymbol(targetReturnType.symbol); var sourceIsAbstract = sourceReturnDecl && sourceReturnDecl.flags & 128 /* Abstract */; var targetIsAbstract = targetReturnDecl && targetReturnDecl.flags & 128 /* Abstract */; if (sourceIsAbstract && !(targetIsAbstract && targetDecl)) { // if target isn't a class-declaration type, then it can be new'd, so we forbid the assignment. if (reportErrors) { reportError(ts.Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type); } return 0 /* False */; } } return -1 /* True */; } } function signatureRelatedTo(source, target, reportErrors) { if (source === target) { return -1 /* True */; } if (!target.hasRestParameter && source.minArgumentCount > target.parameters.length) { return 0 /* False */; } var sourceMax = source.parameters.length; var targetMax = target.parameters.length; var checkCount; if (source.hasRestParameter && target.hasRestParameter) { checkCount = sourceMax > targetMax ? sourceMax : targetMax; sourceMax--; targetMax--; } else if (source.hasRestParameter) { sourceMax--; checkCount = targetMax; } else if (target.hasRestParameter) { targetMax--; checkCount = sourceMax; } else { checkCount = sourceMax < targetMax ? sourceMax : targetMax; } // Spec 1.0 Section 3.8.3 & 3.8.4: // M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N source = getErasedSignature(source); target = getErasedSignature(target); var result = -1 /* True */; for (var i = 0; i < checkCount; i++) { var s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source); var t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target); var saveErrorInfo = errorInfo; var related = isRelatedTo(s, t, reportErrors); if (!related) { related = isRelatedTo(t, s, false); if (!related) { if (reportErrors) { reportError(ts.Diagnostics.Types_of_parameters_0_and_1_are_incompatible, source.parameters[i < sourceMax ? i : sourceMax].name, target.parameters[i < targetMax ? i : targetMax].name); } return 0 /* False */; } errorInfo = saveErrorInfo; } result &= related; } if (source.typePredicate && target.typePredicate) { var hasDifferentParameterIndex = source.typePredicate.parameterIndex !== target.typePredicate.parameterIndex; var hasDifferentTypes; if (hasDifferentParameterIndex || (hasDifferentTypes = !isTypeIdenticalTo(source.typePredicate.type, target.typePredicate.type))) { if (reportErrors) { var sourceParamText = source.typePredicate.parameterName; var targetParamText = target.typePredicate.parameterName; var sourceTypeText = typeToString(source.typePredicate.type); var targetTypeText = typeToString(target.typePredicate.type); if (hasDifferentParameterIndex) { reportError(ts.Diagnostics.Parameter_0_is_not_in_the_same_position_as_parameter_1, sourceParamText, targetParamText); } else if (hasDifferentTypes) { reportError(ts.Diagnostics.Type_0_is_not_assignable_to_type_1, sourceTypeText, targetTypeText); } reportError(ts.Diagnostics.Type_predicate_0_is_not_assignable_to_1, sourceParamText + " is " + sourceTypeText, targetParamText + " is " + targetTypeText); } return 0 /* False */; } } else if (!source.typePredicate && target.typePredicate) { if (reportErrors) { reportError(ts.Diagnostics.Signature_0_must_have_a_type_predicate, signatureToString(source)); } return 0 /* False */; } var targetReturnType = getReturnTypeOfSignature(target); if (targetReturnType === voidType) return result; var sourceReturnType = getReturnTypeOfSignature(source); return result & isRelatedTo(sourceReturnType, targetReturnType, reportErrors); } function signaturesIdenticalTo(source, target, kind) { var sourceSignatures = getSignaturesOfType(source, kind); var targetSignatures = getSignaturesOfType(target, kind); if (sourceSignatures.length !== targetSignatures.length) { return 0 /* False */; } var result = -1 /* True */; for (var i = 0, len = sourceSignatures.length; i < len; ++i) { var related = compareSignatures(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreReturnTypes*/ false, isRelatedTo); if (!related) { return 0 /* False */; } result &= related; } return result; } function stringIndexTypesRelatedTo(source, originalSource, target, reportErrors) { if (relation === identityRelation) { return indexTypesIdenticalTo(0 /* String */, source, target); } var targetType = getIndexTypeOfType(target, 0 /* String */); if (targetType) { if ((targetType.flags & 1 /* Any */) && !(originalSource.flags & 16777726 /* Primitive */)) { // non-primitive assignment to any is always allowed, eg // `var x: { [index: string]: any } = { property: 12 };` return -1 /* True */; } var sourceType = getIndexTypeOfType(source, 0 /* String */); if (!sourceType) { if (reportErrors) { reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } return 0 /* False */; } var related = isRelatedTo(sourceType, targetType, reportErrors); if (!related) { if (reportErrors) { reportError(ts.Diagnostics.Index_signatures_are_incompatible); } return 0 /* False */; } return related; } return -1 /* True */; } function numberIndexTypesRelatedTo(source, originalSource, target, reportErrors) { if (relation === identityRelation) { return indexTypesIdenticalTo(1 /* Number */, source, target); } var targetType = getIndexTypeOfType(target, 1 /* Number */); if (targetType) { if ((targetType.flags & 1 /* Any */) && !(originalSource.flags & 16777726 /* Primitive */)) { // non-primitive assignment to any is always allowed, eg // `var x: { [index: number]: any } = { property: 12 };` return -1 /* True */; } var sourceStringType = getIndexTypeOfType(source, 0 /* String */); var sourceNumberType = getIndexTypeOfType(source, 1 /* Number */); if (!(sourceStringType || sourceNumberType)) { if (reportErrors) { reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } return 0 /* False */; } var related; if (sourceStringType && sourceNumberType) { // If we know for sure we're testing both string and numeric index types then only report errors from the second one related = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors); } else { related = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors); } if (!related) { if (reportErrors) { reportError(ts.Diagnostics.Index_signatures_are_incompatible); } return 0 /* False */; } return related; } return -1 /* True */; } function indexTypesIdenticalTo(indexKind, source, target) { var targetType = getIndexTypeOfType(target, indexKind); var sourceType = getIndexTypeOfType(source, indexKind); if (!sourceType && !targetType) { return -1 /* True */; } if (sourceType && targetType) { return isRelatedTo(sourceType, targetType); } return 0 /* False */; } }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
checkTypeRelatedTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function reportError(message, arg0, arg1, arg2) { errorInfo = ts.chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
reportError
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function reportRelationError(message, source, target) { var sourceType = typeToString(source); var targetType = typeToString(target); if (sourceType === targetType) { sourceType = typeToString(source, /*enclosingDeclaration*/ undefined, 128 /* UseFullyQualifiedType */); targetType = typeToString(target, /*enclosingDeclaration*/ undefined, 128 /* UseFullyQualifiedType */); } reportError(message || ts.Diagnostics.Type_0_is_not_assignable_to_type_1, sourceType, targetType); }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
reportRelationError
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isRelatedTo(source, target, reportErrors, headMessage) { var result; // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases if (source === target) return -1 /* True */; if (relation === identityRelation) { return isIdenticalTo(source, target); } if (isTypeAny(target)) return -1 /* True */; if (source === undefinedType) return -1 /* True */; if (source === nullType && target !== undefinedType) return -1 /* True */; if (source.flags & 128 /* Enum */ && target === numberType) return -1 /* True */; if (source.flags & 256 /* StringLiteral */ && target === stringType) return -1 /* True */; if (relation === assignableRelation) { if (isTypeAny(source)) return -1 /* True */; if (source === numberType && target.flags & 128 /* Enum */) return -1 /* True */; } if (source.flags & 1048576 /* FreshObjectLiteral */) { if (hasExcessProperties(source, target, reportErrors)) { if (reportErrors) { reportRelationError(headMessage, source, target); } return 0 /* False */; } // Above we check for excess properties with respect to the entire target type. When union // and intersection types are further deconstructed on the target side, we don't want to // make the check again (as it might fail for a partial target type). Therefore we obtain // the regular source type and proceed with that. if (target.flags & 49152 /* UnionOrIntersection */) { source = getRegularTypeOfObjectLiteral(source); } } var saveErrorInfo = errorInfo; // Note that the "each" checks must precede the "some" checks to produce the correct results if (source.flags & 16384 /* Union */) { if (result = eachTypeRelatedToType(source, target, reportErrors)) { return result; } } else if (target.flags & 32768 /* Intersection */) { if (result = typeRelatedToEachType(source, target, reportErrors)) { return result; } } else { // It is necessary to try "some" checks on both sides because there may be nested "each" checks // on either side that need to be prioritized. For example, A | B = (A | B) & (C | D) or // A & B = (A & B) | (C & D). if (source.flags & 32768 /* Intersection */) { // If target is a union type the following check will report errors so we suppress them here if (result = someTypeRelatedToType(source, target, reportErrors && !(target.flags & 16384 /* Union */))) { return result; } } if (target.flags & 16384 /* Union */) { if (result = typeRelatedToSomeType(source, target, reportErrors)) { return result; } } } if (source.flags & 512 /* TypeParameter */) { var constraint = getConstraintOfTypeParameter(source); if (!constraint || constraint.flags & 1 /* Any */) { constraint = emptyObjectType; } // Report constraint errors only if the constraint is not the empty object type var reportConstraintErrors = reportErrors && constraint !== emptyObjectType; if (result = isRelatedTo(constraint, target, reportConstraintErrors)) { errorInfo = saveErrorInfo; return result; } } else { if (source.flags & 4096 /* Reference */ && target.flags & 4096 /* Reference */ && source.target === target.target) { // We have type references to same target type, see if relationship holds for all type arguments if (result = typeArgumentsRelatedTo(source, target, reportErrors)) { return result; } } // Even if relationship doesn't hold for unions, intersections, or generic type references, // it may hold in a structural comparison. var apparentType = getApparentType(source); // In a check of the form X = A & B, we will have previously checked if A relates to X or B relates // to X. Failing both of those we want to check if the aggregation of A and B's members structurally // relates to X. Thus, we include intersection types on the source side here. if (apparentType.flags & (80896 /* ObjectType */ | 32768 /* Intersection */) && target.flags & 80896 /* ObjectType */) { // Report structural errors only if we haven't reported any errors yet var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo; if (result = objectTypeRelatedTo(apparentType, source, target, reportStructuralErrors)) { errorInfo = saveErrorInfo; return result; } } } if (reportErrors) { reportRelationError(headMessage, source, target); } return 0 /* False */; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
isRelatedTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isIdenticalTo(source, target) { var result; if (source.flags & 80896 /* ObjectType */ && target.flags & 80896 /* ObjectType */) { if (source.flags & 4096 /* Reference */ && target.flags & 4096 /* Reference */ && source.target === target.target) { // We have type references to same target type, see if all type arguments are identical if (result = typeArgumentsRelatedTo(source, target, /*reportErrors*/ false)) { return result; } } return objectTypeRelatedTo(source, source, target, /*reportErrors*/ false); } if (source.flags & 512 /* TypeParameter */ && target.flags & 512 /* TypeParameter */) { return typeParameterIdenticalTo(source, target); } if (source.flags & 16384 /* Union */ && target.flags & 16384 /* Union */ || source.flags & 32768 /* Intersection */ && target.flags & 32768 /* Intersection */) { if (result = eachTypeRelatedToSomeType(source, target)) { if (result &= eachTypeRelatedToSomeType(target, source)) { return result; } } } return 0 /* False */; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
isIdenticalTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isKnownProperty(type, name) { if (type.flags & 80896 /* ObjectType */) { var resolved = resolveStructuredTypeMembers(type); if (relation === assignableRelation && (type === globalObjectType || resolved.properties.length === 0) || resolved.stringIndexType || resolved.numberIndexType || getPropertyOfType(type, name)) { return true; } } else if (type.flags & 49152 /* UnionOrIntersection */) { for (var _i = 0, _a = type.types; _i < _a.length; _i++) { var t = _a[_i]; if (isKnownProperty(t, name)) { return true; } } } return false; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
isKnownProperty
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function hasExcessProperties(source, target, reportErrors) { if (!(target.flags & 67108864 /* ObjectLiteralPatternWithComputedProperties */) && someConstituentTypeHasKind(target, 80896 /* ObjectType */)) { for (var _i = 0, _a = getPropertiesOfObjectType(source); _i < _a.length; _i++) { var prop = _a[_i]; if (!isKnownProperty(target, prop.name)) { if (reportErrors) { // We know *exactly* where things went wrong when comparing the types. // Use this property as the error node as this will be more helpful in // reasoning about what went wrong. errorNode = prop.valueDeclaration; reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target)); } return true; } } } return false; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
hasExcessProperties
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function eachTypeRelatedToSomeType(source, target) { var result = -1 /* True */; var sourceTypes = source.types; for (var _i = 0, sourceTypes_1 = sourceTypes; _i < sourceTypes_1.length; _i++) { var sourceType = sourceTypes_1[_i]; var related = typeRelatedToSomeType(sourceType, target, false); if (!related) { return 0 /* False */; } result &= related; } return result; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
eachTypeRelatedToSomeType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT