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 checkJsxSelfClosingElement(node) { checkJsxOpeningLikeElement(node); return jsxElementType || anyType; }
Detect if the mapper implies an inference context. Specifically, there are 4 possible values for a mapper. Let's go through each one of them: 1. undefined - this means we are not doing inferential typing, but we may do contextual typing, which could cause us to assign a parameter a type 2. identityMapper - means we want to avoid assigning a parameter a type, whether or not we are in inferential typing (context is undefined for the identityMapper) 3. a mapper created by createInferenceMapper - we are doing inferential typing, we want to assign types to parameters and fix type parameters (context is defined) 4. an instantiation mapper created by createTypeMapper or createTypeEraser - this should never be passed as the contextual mapper when checking an expression (context is undefined for these) isInferentialContext is detecting if we are in case 3
checkJsxSelfClosingElement
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function tagNamesAreEquivalent(lhs, rhs) { if (lhs.kind !== rhs.kind) { return false; } if (lhs.kind === 69 /* Identifier */) { return lhs.text === rhs.text; } return lhs.right.text === rhs.right.text && tagNamesAreEquivalent(lhs.left, rhs.left); }
Detect if the mapper implies an inference context. Specifically, there are 4 possible values for a mapper. Let's go through each one of them: 1. undefined - this means we are not doing inferential typing, but we may do contextual typing, which could cause us to assign a parameter a type 2. identityMapper - means we want to avoid assigning a parameter a type, whether or not we are in inferential typing (context is undefined for the identityMapper) 3. a mapper created by createInferenceMapper - we are doing inferential typing, we want to assign types to parameters and fix type parameters (context is defined) 4. an instantiation mapper created by createTypeMapper or createTypeEraser - this should never be passed as the contextual mapper when checking an expression (context is undefined for these) isInferentialContext is detecting if we are in case 3
tagNamesAreEquivalent
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkJsxElement(node) { // Check attributes checkJsxOpeningLikeElement(node.openingElement); // Check that the closing tag matches if (!tagNamesAreEquivalent(node.openingElement.tagName, node.closingElement.tagName)) { error(node.closingElement, ts.Diagnostics.Expected_corresponding_JSX_closing_tag_for_0, ts.getTextOfNode(node.openingElement.tagName)); } else { // Perform resolution on the closing tag so that rename/go to definition/etc work getJsxElementTagSymbol(node.closingElement); } // Check children for (var _i = 0, _a = node.children; _i < _a.length; _i++) { var child = _a[_i]; switch (child.kind) { case 240 /* JsxExpression */: checkJsxExpression(child); break; case 233 /* JsxElement */: checkJsxElement(child); break; case 234 /* JsxSelfClosingElement */: checkJsxSelfClosingElement(child); break; } } return jsxElementType || anyType; }
Detect if the mapper implies an inference context. Specifically, there are 4 possible values for a mapper. Let's go through each one of them: 1. undefined - this means we are not doing inferential typing, but we may do contextual typing, which could cause us to assign a parameter a type 2. identityMapper - means we want to avoid assigning a parameter a type, whether or not we are in inferential typing (context is undefined for the identityMapper) 3. a mapper created by createInferenceMapper - we are doing inferential typing, we want to assign types to parameters and fix type parameters (context is defined) 4. an instantiation mapper created by createTypeMapper or createTypeEraser - this should never be passed as the contextual mapper when checking an expression (context is undefined for these) isInferentialContext is detecting if we are in case 3
checkJsxElement
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isUnhyphenatedJsxName(name) { // - is the only character supported in JSX attribute names that isn't valid in JavaScript identifiers return name.indexOf("-") < 0; }
Returns true iff the JSX element name would be a valid JS identifier, ignoring restrictions about keywords not being identifiers
isUnhyphenatedJsxName
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getJsxElementPropertiesName() { // JSX var jsxNamespace = getGlobalSymbol(JsxNames.JSX, 1536 /* Namespace */, /*diagnosticMessage*/ undefined); // JSX.ElementAttributesProperty [symbol] var attribsPropTypeSym = jsxNamespace && getSymbol(jsxNamespace.exports, JsxNames.ElementAttributesPropertyNameContainer, 793056 /* Type */); // JSX.ElementAttributesProperty [type] var attribPropType = attribsPropTypeSym && getDeclaredTypeOfSymbol(attribsPropTypeSym); // The properites of JSX.ElementAttributesProperty var attribProperties = attribPropType && getPropertiesOfType(attribPropType); if (attribProperties) { // Element Attributes has zero properties, so the element attributes type will be the class instance type if (attribProperties.length === 0) { return ""; } else if (attribProperties.length === 1) { return attribProperties[0].name; } else { error(attribsPropTypeSym.declarations[0], ts.Diagnostics.The_global_type_JSX_0_may_not_have_more_than_one_property, JsxNames.ElementAttributesPropertyNameContainer); return undefined; } } else { // No interface exists, so the element attributes type will be an implicit any return undefined; } }
Given a JSX element that is a class element, finds the Element Instance Type. If the element is not a class element, or the class element type cannot be determined, returns 'undefined'. For example, in the element <MyClass>, the element instance type is `MyClass` (not `typeof MyClass`).
getJsxElementPropertiesName
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getJsxGlobalElementClassType() { if (!jsxElementClassType) { jsxElementClassType = getExportedTypeFromNamespace(JsxNames.JSX, JsxNames.ElementClass); } return jsxElementClassType; }
Given a JSX attribute, returns the symbol for the corresponds property of the element attributes type. Will return unknownSymbol for attributes that have no matching element attributes type property.
getJsxGlobalElementClassType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getJsxIntrinsicTagNames() { var intrinsics = getJsxIntrinsicElementsType(); return intrinsics ? getPropertiesOfType(intrinsics) : emptyArray; }
Given a JSX attribute, returns the symbol for the corresponds property of the element attributes type. Will return unknownSymbol for attributes that have no matching element attributes type property.
getJsxIntrinsicTagNames
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkJsxPreconditions(errorNode) { // Preconditions for using JSX if ((compilerOptions.jsx || 0 /* None */) === 0 /* None */) { error(errorNode, ts.Diagnostics.Cannot_use_JSX_unless_the_jsx_flag_is_provided); } if (jsxElementType === undefined) { if (compilerOptions.noImplicitAny) { error(errorNode, ts.Diagnostics.JSX_element_implicitly_has_type_any_because_the_global_type_JSX_Element_does_not_exist); } } }
Given a JSX attribute, returns the symbol for the corresponds property of the element attributes type. Will return unknownSymbol for attributes that have no matching element attributes type property.
checkJsxPreconditions
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkJsxOpeningLikeElement(node) { checkGrammarJsxElement(node); checkJsxPreconditions(node); // If we're compiling under --jsx react, the symbol 'React' should // be marked as 'used' so we don't incorrectly elide its import. And if there // is no 'React' symbol in scope, we should issue an error. if (compilerOptions.jsx === 2 /* React */) { var reactSym = resolveName(node.tagName, "React", 107455 /* Value */, ts.Diagnostics.Cannot_find_name_0, "React"); if (reactSym) { getSymbolLinks(reactSym).referenced = true; } } var targetAttributesType = getJsxElementAttributesType(node); var nameTable = {}; // Process this array in right-to-left order so we know which // attributes (mostly from spreads) are being overwritten and // thus should have their types ignored var sawSpreadedAny = false; for (var i = node.attributes.length - 1; i >= 0; i--) { if (node.attributes[i].kind === 238 /* JsxAttribute */) { checkJsxAttribute((node.attributes[i]), targetAttributesType, nameTable); } else { ts.Debug.assert(node.attributes[i].kind === 239 /* JsxSpreadAttribute */); var spreadType = checkJsxSpreadAttribute((node.attributes[i]), targetAttributesType, nameTable); if (isTypeAny(spreadType)) { sawSpreadedAny = true; } } } // Check that all required properties have been provided. If an 'any' // was spreaded in, though, assume that it provided all required properties if (targetAttributesType && !sawSpreadedAny) { var targetProperties = getPropertiesOfType(targetAttributesType); for (var i = 0; i < targetProperties.length; i++) { if (!(targetProperties[i].flags & 536870912 /* Optional */) && nameTable[targetProperties[i].name] === undefined) { error(node, ts.Diagnostics.Property_0_is_missing_in_type_1, targetProperties[i].name, typeToString(targetAttributesType)); } } } }
Given a JSX attribute, returns the symbol for the corresponds property of the element attributes type. Will return unknownSymbol for attributes that have no matching element attributes type property.
checkJsxOpeningLikeElement
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkJsxExpression(node) { if (node.expression) { return checkExpression(node.expression); } else { return unknownType; } }
Given a JSX attribute, returns the symbol for the corresponds property of the element attributes type. Will return unknownSymbol for attributes that have no matching element attributes type property.
checkJsxExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getDeclarationKindFromSymbol(s) { return s.valueDeclaration ? s.valueDeclaration.kind : 141 /* PropertyDeclaration */; }
Given a JSX attribute, returns the symbol for the corresponds property of the element attributes type. Will return unknownSymbol for attributes that have no matching element attributes type property.
getDeclarationKindFromSymbol
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getDeclarationFlagsFromSymbol(s) { return s.valueDeclaration ? ts.getCombinedNodeFlags(s.valueDeclaration) : s.flags & 134217728 /* Prototype */ ? 8 /* Public */ | 64 /* Static */ : 0; }
Given a JSX attribute, returns the symbol for the corresponds property of the element attributes type. Will return unknownSymbol for attributes that have no matching element attributes type property.
getDeclarationFlagsFromSymbol
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkClassPropertyAccess(node, left, type, prop) { var flags = getDeclarationFlagsFromSymbol(prop); var declaringClass = getDeclaredTypeOfSymbol(prop.parent); if (left.kind === 95 /* SuperKeyword */) { var errorNode = node.kind === 166 /* PropertyAccessExpression */ ? node.name : node.right; // TS 1.0 spec (April 2014): 4.8.2 // - In a constructor, instance member function, instance member accessor, or // instance member variable initializer where this references a derived class instance, // a super property access is permitted and must specify a public instance member function of the base class. // - In a static member function or static member accessor // where this references the constructor function object of a derived class, // a super property access is permitted and must specify a public static member function of the base class. if (getDeclarationKindFromSymbol(prop) !== 143 /* MethodDeclaration */) { // `prop` refers to a *property* declared in the super class // rather than a *method*, so it does not satisfy the above criteria. error(errorNode, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); return false; } if (flags & 128 /* Abstract */) { // A method cannot be accessed in a super property access if the method is abstract. // This error could mask a private property access error. But, a member // cannot simultaneously be private and abstract, so this will trigger an // additional error elsewhere. error(errorNode, ts.Diagnostics.Abstract_method_0_in_class_1_cannot_be_accessed_via_super_expression, symbolToString(prop), typeToString(declaringClass)); return false; } } // Public properties are otherwise accessible. if (!(flags & (16 /* Private */ | 32 /* Protected */))) { return true; } // Property is known to be private or protected at this point // Get the declaring and enclosing class instance types var enclosingClassDeclaration = ts.getContainingClass(node); var enclosingClass = enclosingClassDeclaration ? getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined; // Private property is accessible if declaring and enclosing class are the same if (flags & 16 /* Private */) { if (declaringClass !== enclosingClass) { error(node, ts.Diagnostics.Property_0_is_private_and_only_accessible_within_class_1, symbolToString(prop), typeToString(declaringClass)); return false; } return true; } // Property is known to be protected at this point // All protected properties of a supertype are accessible in a super access if (left.kind === 95 /* SuperKeyword */) { return true; } // A protected property is accessible in the declaring class and classes derived from it if (!enclosingClass || !hasBaseType(enclosingClass, declaringClass)) { error(node, ts.Diagnostics.Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses, symbolToString(prop), typeToString(declaringClass)); return false; } // No further restrictions for static properties if (flags & 64 /* Static */) { return true; } // An instance property must be accessed through an instance of the enclosing class if (type.flags & 33554432 /* ThisType */) { // get the original type -- represented as the type constraint of the 'this' type type = getConstraintOfTypeParameter(type); } // TODO: why is the first part of this check here? if (!(getTargetType(type).flags & (1024 /* Class */ | 2048 /* Interface */) && hasBaseType(type, enclosingClass))) { error(node, ts.Diagnostics.Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1, symbolToString(prop), typeToString(enclosingClass)); return false; } return true; }
Check whether the requested property access is valid. Returns true if node is a valid property access, and false otherwise. @param node The node to be checked. @param left The left hand side of the property access (e.g.: the super in `super.foo`). @param type The type of left. @param prop The symbol for the right hand side of the property access.
checkClassPropertyAccess
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkPropertyAccessExpression(node) { return checkPropertyAccessExpressionOrQualifiedName(node, node.expression, node.name); }
Check whether the requested property access is valid. Returns true if node is a valid property access, and false otherwise. @param node The node to be checked. @param left The left hand side of the property access (e.g.: the super in `super.foo`). @param type The type of left. @param prop The symbol for the right hand side of the property access.
checkPropertyAccessExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkQualifiedName(node) { return checkPropertyAccessExpressionOrQualifiedName(node, node.left, node.right); }
Check whether the requested property access is valid. Returns true if node is a valid property access, and false otherwise. @param node The node to be checked. @param left The left hand side of the property access (e.g.: the super in `super.foo`). @param type The type of left. @param prop The symbol for the right hand side of the property access.
checkQualifiedName
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkPropertyAccessExpressionOrQualifiedName(node, left, right) { var type = checkExpression(left); if (isTypeAny(type)) { return type; } var apparentType = getApparentType(getWidenedType(type)); if (apparentType === unknownType) { // handle cases when type is Type parameter with invalid constraint return unknownType; } var prop = getPropertyOfType(apparentType, right.text); if (!prop) { if (right.text) { error(right, ts.Diagnostics.Property_0_does_not_exist_on_type_1, ts.declarationNameToString(right), typeToString(type.flags & 33554432 /* ThisType */ ? apparentType : type)); } return unknownType; } getNodeLinks(node).resolvedSymbol = prop; if (prop.parent && prop.parent.flags & 32 /* Class */) { checkClassPropertyAccess(node, left, apparentType, prop); } return getTypeOfSymbol(prop); }
Check whether the requested property access is valid. Returns true if node is a valid property access, and false otherwise. @param node The node to be checked. @param left The left hand side of the property access (e.g.: the super in `super.foo`). @param type The type of left. @param prop The symbol for the right hand side of the property access.
checkPropertyAccessExpressionOrQualifiedName
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isValidPropertyAccess(node, propertyName) { var left = node.kind === 166 /* PropertyAccessExpression */ ? node.expression : node.left; var type = checkExpression(left); if (type !== unknownType && !isTypeAny(type)) { var prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & 32 /* Class */) { return checkClassPropertyAccess(node, left, type, prop); } } return true; }
Check whether the requested property access is valid. Returns true if node is a valid property access, and false otherwise. @param node The node to be checked. @param left The left hand side of the property access (e.g.: the super in `super.foo`). @param type The type of left. @param prop The symbol for the right hand side of the property access.
isValidPropertyAccess
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkIndexedAccess(node) { // Grammar checking if (!node.argumentExpression) { var sourceFile = getSourceFile(node); if (node.parent.kind === 169 /* NewExpression */ && node.parent.expression === node) { var start = ts.skipTrivia(sourceFile.text, node.expression.end); var end = node.end; grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead); } else { var start = node.end - "]".length; var end = node.end; grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Expression_expected); } } // Obtain base constraint such that we can bail out if the constraint is an unknown type var objectType = getApparentType(checkExpression(node.expression)); var indexType = node.argumentExpression ? checkExpression(node.argumentExpression) : unknownType; if (objectType === unknownType) { return unknownType; } var isConstEnum = isConstEnumObjectType(objectType); if (isConstEnum && (!node.argumentExpression || node.argumentExpression.kind !== 9 /* StringLiteral */)) { error(node.argumentExpression, ts.Diagnostics.A_const_enum_member_can_only_be_accessed_using_a_string_literal); return unknownType; } // TypeScript 1.0 spec (April 2014): 4.10 Property Access // - If IndexExpr is a string literal or a numeric literal and ObjExpr's apparent type has a property with the name // given by that literal(converted to its string representation in the case of a numeric literal), the property access is of the type of that property. // - Otherwise, if ObjExpr's apparent type has a numeric index signature and IndexExpr is of type Any, the Number primitive type, or an enum type, // the property access is of the type of that index signature. // - Otherwise, if ObjExpr's apparent type has a string index signature and IndexExpr is of type Any, the String or Number primitive type, or an enum type, // the property access is of the type of that index signature. // - Otherwise, if IndexExpr is of type Any, the String or Number primitive type, or an enum type, the property access is of type Any. // See if we can index as a property. if (node.argumentExpression) { var name_11 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); if (name_11 !== undefined) { var prop = getPropertyOfType(objectType, name_11); if (prop) { getNodeLinks(node).resolvedSymbol = prop; return getTypeOfSymbol(prop); } else if (isConstEnum) { error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_11, symbolToString(objectType.symbol)); return unknownType; } } } // Check for compatible indexer types. if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 258 /* StringLike */ | 132 /* NumberLike */ | 16777216 /* ESSymbol */)) { // Try to use a number indexer. if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, 132 /* NumberLike */)) { var numberIndexType = getIndexTypeOfType(objectType, 1 /* Number */); if (numberIndexType) { return numberIndexType; } } // Try to use string indexing. var stringIndexType = getIndexTypeOfType(objectType, 0 /* String */); if (stringIndexType) { return stringIndexType; } // Fall back to any. if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !isTypeAny(objectType)) { error(node, ts.Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type); } return anyType; } // REVIEW: Users should know the type that was actually used. error(node, ts.Diagnostics.An_index_expression_argument_must_be_of_type_string_number_symbol_or_any); return unknownType; }
Check whether the requested property access is valid. Returns true if node is a valid property access, and false otherwise. @param node The node to be checked. @param left The left hand side of the property access (e.g.: the super in `super.foo`). @param type The type of left. @param prop The symbol for the right hand side of the property access.
checkIndexedAccess
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getEffectiveDecoratorFirstArgumentType(node) { // The first argument to a decorator is its `target`. if (node.kind === 214 /* ClassDeclaration */) { // For a class decorator, the `target` is the type of the class (e.g. the // "static" or "constructor" side of the class) var classSymbol = getSymbolOfNode(node); return getTypeOfSymbol(classSymbol); } if (node.kind === 138 /* Parameter */) { // For a parameter decorator, the `target` is the parent type of the // parameter's containing method. node = node.parent; if (node.kind === 144 /* Constructor */) { var classSymbol = getSymbolOfNode(node); return getTypeOfSymbol(classSymbol); } } if (node.kind === 141 /* PropertyDeclaration */ || node.kind === 143 /* MethodDeclaration */ || node.kind === 145 /* GetAccessor */ || node.kind === 146 /* SetAccessor */) { // For a property or method decorator, the `target` is the // "static"-side type of the parent of the member if the member is // declared "static"; otherwise, it is the "instance"-side type of the // parent of the member. return getParentTypeOfClassElement(node); } ts.Debug.fail("Unsupported decorator target."); return unknownType; }
Returns the effective type of the first argument to a decorator. If 'node' is a class declaration or class expression, the effective argument type is the type of the static side of the class. If 'node' is a parameter declaration, the effective argument type is either the type of the static or instance side of the class for the parameter's parent method, depending on whether the method is declared static. For a constructor, the type is always the type of the static side of the class. If 'node' is a property, method, or accessor declaration, the effective argument type is the type of the static or instance side of the parent class for class element, depending on whether the element is declared static.
getEffectiveDecoratorFirstArgumentType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getEffectiveDecoratorThirdArgumentType(node) { // The third argument to a decorator is either its `descriptor` for a method decorator // or its `parameterIndex` for a paramter decorator if (node.kind === 214 /* ClassDeclaration */) { ts.Debug.fail("Class decorators should not have a third synthetic argument."); return unknownType; } if (node.kind === 138 /* Parameter */) { // The `parameterIndex` for a parameter decorator is always a number return numberType; } if (node.kind === 141 /* PropertyDeclaration */) { ts.Debug.fail("Property decorators should not have a third synthetic argument."); return unknownType; } if (node.kind === 143 /* MethodDeclaration */ || node.kind === 145 /* GetAccessor */ || node.kind === 146 /* SetAccessor */) { // The `descriptor` for a method decorator will be a `TypedPropertyDescriptor<T>` // for the type of the member. var propertyType = getTypeOfNode(node); return createTypedPropertyDescriptorType(propertyType); } ts.Debug.fail("Unsupported decorator target."); return unknownType; }
Returns the effective argument type for the third argument to a decorator. If 'node' is a parameter, the effective argument type is the number type. If 'node' is a method or accessor, the effective argument type is a `TypedPropertyDescriptor<T>` instantiated with the type of the member. Class and property decorators do not have a third effective argument.
getEffectiveDecoratorThirdArgumentType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function resolveCall(node, signatures, candidatesOutArray, headMessage) { var isTaggedTemplate = node.kind === 170 /* TaggedTemplateExpression */; var isDecorator = node.kind === 139 /* Decorator */; var typeArguments; if (!isTaggedTemplate && !isDecorator) { typeArguments = node.typeArguments; // We already perform checking on the type arguments on the class declaration itself. if (node.expression.kind !== 95 /* SuperKeyword */) { ts.forEach(typeArguments, checkSourceElement); } } var candidates = candidatesOutArray || []; // reorderCandidates fills up the candidates array directly reorderCandidates(signatures, candidates); if (!candidates.length) { reportError(ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); return resolveErrorCall(node); } var args = getEffectiveCallArguments(node); // The following applies to any value of 'excludeArgument[i]': // - true: the argument at 'i' is susceptible to a one-time permanent contextual typing. // - undefined: the argument at 'i' is *not* susceptible to permanent contextual typing. // - false: the argument at 'i' *was* and *has been* permanently contextually typed. // // The idea is that we will perform type argument inference & assignability checking once // without using the susceptible parameters that are functions, and once more for each of those // parameters, contextually typing each as we go along. // // For a tagged template, then the first argument be 'undefined' if necessary // because it represents a TemplateStringsArray. // // For a decorator, no arguments are susceptible to contextual typing due to the fact // decorators are applied to a declaration by the emitter, and not to an expression. var excludeArgument; if (!isDecorator) { // We do not need to call `getEffectiveArgumentCount` here as it only // applies when calculating the number of arguments for a decorator. for (var i = isTaggedTemplate ? 1 : 0; i < args.length; i++) { if (isContextSensitive(args[i])) { if (!excludeArgument) { excludeArgument = new Array(args.length); } excludeArgument[i] = true; } } } // The following variables are captured and modified by calls to chooseOverload. // If overload resolution or type argument inference fails, we want to report the // best error possible. The best error is one which says that an argument was not // assignable to a parameter. This implies that everything else about the overload // was fine. So if there is any overload that is only incorrect because of an // argument, we will report an error on that one. // // function foo(s: string) {} // function foo(n: number) {} // Report argument error on this overload // function foo() {} // foo(true); // // If none of the overloads even made it that far, there are two possibilities. // There was a problem with type arguments for some overload, in which case // report an error on that. Or none of the overloads even had correct arity, // in which case give an arity error. // // function foo<T>(x: T, y: T) {} // Report type argument inference error // function foo() {} // foo(0, true); // var candidateForArgumentError; var candidateForTypeArgumentError; var resultOfFailedInference; var result; // Section 4.12.1: // if the candidate list contains one or more signatures for which the type of each argument // expression is a subtype of each corresponding parameter type, the return type of the first // of those signatures becomes the return type of the function call. // Otherwise, the return type of the first signature in the candidate list becomes the return // type of the function call. // // Whether the call is an error is determined by assignability of the arguments. The subtype pass // is just important for choosing the best signature. So in the case where there is only one // signature, the subtype pass is useless. So skipping it is an optimization. if (candidates.length > 1) { result = chooseOverload(candidates, subtypeRelation); } if (!result) { // Reinitialize these pointers for round two candidateForArgumentError = undefined; candidateForTypeArgumentError = undefined; resultOfFailedInference = undefined; result = chooseOverload(candidates, assignableRelation); } if (result) { return result; } // No signatures were applicable. Now report errors based on the last applicable signature with // no arguments excluded from assignability checks. // If candidate is undefined, it means that no candidates had a suitable arity. In that case, // skip the checkApplicableSignature check. if (candidateForArgumentError) { // excludeArgument is undefined, in this case also equivalent to [undefined, undefined, ...] // The importance of excludeArgument is to prevent us from typing function expression parameters // in arguments too early. If possible, we'd like to only type them once we know the correct // overload. However, this matters for the case where the call is correct. When the call is // an error, we don't need to exclude any arguments, although it would cause no harm to do so. checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, /*excludeArgument*/ undefined, /*reportErrors*/ true); } else if (candidateForTypeArgumentError) { if (!isTaggedTemplate && !isDecorator && typeArguments) { checkTypeArguments(candidateForTypeArgumentError, node.typeArguments, [], /*reportErrors*/ true, headMessage); } else { ts.Debug.assert(resultOfFailedInference.failedTypeParameterIndex >= 0); var failedTypeParameter = candidateForTypeArgumentError.typeParameters[resultOfFailedInference.failedTypeParameterIndex]; var inferenceCandidates = getInferenceCandidates(resultOfFailedInference, resultOfFailedInference.failedTypeParameterIndex); var diagnosticChainHead = ts.chainDiagnosticMessages(/*details*/ undefined, // details will be provided by call to reportNoCommonSupertypeError ts.Diagnostics.The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly, typeToString(failedTypeParameter)); if (headMessage) { diagnosticChainHead = ts.chainDiagnosticMessages(diagnosticChainHead, headMessage); } reportNoCommonSupertypeError(inferenceCandidates, node.expression || node.tag, diagnosticChainHead); } } else { reportError(ts.Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); } // No signature was applicable. We have already reported the errors for the invalid signature. // If this is a type resolution session, e.g. Language Service, try to get better information that anySignature. // Pick the first candidate that matches the arity. This way we can get a contextual type for cases like: // declare function f(a: { xa: number; xb: number; }); // f({ | if (!produceDiagnostics) { for (var _i = 0, candidates_1 = candidates; _i < candidates_1.length; _i++) { var candidate = candidates_1[_i]; if (hasCorrectArity(node, args, candidate)) { if (candidate.typeParameters && typeArguments) { candidate = getSignatureInstantiation(candidate, ts.map(typeArguments, getTypeFromTypeNode)); } return candidate; } } } return resolveErrorCall(node); function reportError(message, arg0, arg1, arg2) { var errorInfo; errorInfo = ts.chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); if (headMessage) { errorInfo = ts.chainDiagnosticMessages(errorInfo, headMessage); } diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(node, errorInfo)); } function chooseOverload(candidates, relation) { for (var _i = 0, candidates_2 = candidates; _i < candidates_2.length; _i++) { var originalCandidate = candidates_2[_i]; if (!hasCorrectArity(node, args, originalCandidate)) { continue; } var candidate = void 0; var typeArgumentsAreValid = void 0; var inferenceContext = originalCandidate.typeParameters ? createInferenceContext(originalCandidate.typeParameters, /*inferUnionTypes*/ false) : undefined; while (true) { candidate = originalCandidate; if (candidate.typeParameters) { var typeArgumentTypes = void 0; if (typeArguments) { typeArgumentTypes = new Array(candidate.typeParameters.length); typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, /*reportErrors*/ false); } else { inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext); typeArgumentsAreValid = inferenceContext.failedTypeParameterIndex === undefined; typeArgumentTypes = inferenceContext.inferredTypes; } if (!typeArgumentsAreValid) { break; } candidate = getSignatureInstantiation(candidate, typeArgumentTypes); } if (!checkApplicableSignature(node, args, candidate, relation, excludeArgument, /*reportErrors*/ false)) { break; } var index = excludeArgument ? ts.indexOf(excludeArgument, true) : -1; if (index < 0) { return candidate; } excludeArgument[index] = false; } // A post-mortem of this iteration of the loop. The signature was not applicable, // so we want to track it as a candidate for reporting an error. If the candidate // had no type parameters, or had no issues related to type arguments, we can // report an error based on the arguments. If there was an issue with type // arguments, then we can only report an error based on the type arguments. if (originalCandidate.typeParameters) { var instantiatedCandidate = candidate; if (typeArgumentsAreValid) { candidateForArgumentError = instantiatedCandidate; } else { candidateForTypeArgumentError = originalCandidate; if (!typeArguments) { resultOfFailedInference = inferenceContext; } } } else { ts.Debug.assert(originalCandidate === candidate); candidateForArgumentError = originalCandidate; } } return undefined; } }
Gets the error node to use when reporting errors for an effective argument.
resolveCall
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) { var errorInfo; errorInfo = ts.chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); if (headMessage) { errorInfo = ts.chainDiagnosticMessages(errorInfo, headMessage); } diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(node, errorInfo)); }
Gets the error node to use when reporting errors for an effective argument.
reportError
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function chooseOverload(candidates, relation) { for (var _i = 0, candidates_2 = candidates; _i < candidates_2.length; _i++) { var originalCandidate = candidates_2[_i]; if (!hasCorrectArity(node, args, originalCandidate)) { continue; } var candidate = void 0; var typeArgumentsAreValid = void 0; var inferenceContext = originalCandidate.typeParameters ? createInferenceContext(originalCandidate.typeParameters, /*inferUnionTypes*/ false) : undefined; while (true) { candidate = originalCandidate; if (candidate.typeParameters) { var typeArgumentTypes = void 0; if (typeArguments) { typeArgumentTypes = new Array(candidate.typeParameters.length); typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, /*reportErrors*/ false); } else { inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext); typeArgumentsAreValid = inferenceContext.failedTypeParameterIndex === undefined; typeArgumentTypes = inferenceContext.inferredTypes; } if (!typeArgumentsAreValid) { break; } candidate = getSignatureInstantiation(candidate, typeArgumentTypes); } if (!checkApplicableSignature(node, args, candidate, relation, excludeArgument, /*reportErrors*/ false)) { break; } var index = excludeArgument ? ts.indexOf(excludeArgument, true) : -1; if (index < 0) { return candidate; } excludeArgument[index] = false; } // A post-mortem of this iteration of the loop. The signature was not applicable, // so we want to track it as a candidate for reporting an error. If the candidate // had no type parameters, or had no issues related to type arguments, we can // report an error based on the arguments. If there was an issue with type // arguments, then we can only report an error based on the type arguments. if (originalCandidate.typeParameters) { var instantiatedCandidate = candidate; if (typeArgumentsAreValid) { candidateForArgumentError = instantiatedCandidate; } else { candidateForTypeArgumentError = originalCandidate; if (!typeArguments) { resultOfFailedInference = inferenceContext; } } } else { ts.Debug.assert(originalCandidate === candidate); candidateForArgumentError = originalCandidate; } } return undefined; }
Gets the error node to use when reporting errors for an effective argument.
chooseOverload
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function resolveCallExpression(node, candidatesOutArray) { if (node.expression.kind === 95 /* SuperKeyword */) { var superType = checkSuperExpression(node.expression); if (superType !== unknownType) { // In super call, the candidate signatures are the matching arity signatures of the base constructor function instantiated // with the type arguments specified in the extends clause. var baseTypeNode = ts.getClassExtendsHeritageClauseElement(ts.getContainingClass(node)); var baseConstructors = getInstantiatedConstructorsForTypeArguments(superType, baseTypeNode.typeArguments); return resolveCall(node, baseConstructors, candidatesOutArray); } return resolveUntypedCall(node); } var funcType = checkExpression(node.expression); var apparentType = getApparentType(funcType); if (apparentType === unknownType) { // Another error has already been reported return resolveErrorCall(node); } // Technically, this signatures list may be incomplete. We are taking the apparent type, // but we are not including call signatures that may have been added to the Object or // Function interface, since they have none by default. This is a bit of a leap of faith // that the user will not add any. var callSignatures = getSignaturesOfType(apparentType, 0 /* Call */); var constructSignatures = getSignaturesOfType(apparentType, 1 /* Construct */); // TS 1.0 spec: 4.12 // If FuncExpr is of type Any, or of an object type that has no call or construct signatures // but is a subtype of the Function interface, the call is an untyped function call. In an // untyped function call no TypeArgs are permitted, Args can be any argument list, no contextual // types are provided for the argument expressions, and the result is always of type Any. // We exclude union types because we may have a union of function types that happen to have // no common signatures. if (isTypeAny(funcType) || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & 16384 /* Union */) && isTypeAssignableTo(funcType, globalFunctionType))) { // The unknownType indicates that an error already occured (and was reported). No // need to report another error in this case. if (funcType !== unknownType && node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } return resolveUntypedCall(node); } // If FuncExpr's apparent type(section 3.8.1) is a function type, the call is a typed function call. // TypeScript employs overload resolution in typed function calls in order to support functions // with multiple call signatures. if (!callSignatures.length) { if (constructSignatures.length) { error(node, ts.Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new, typeToString(funcType)); } else { error(node, ts.Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature); } return resolveErrorCall(node); } return resolveCall(node, callSignatures, candidatesOutArray); }
Gets the error node to use when reporting errors for an effective argument.
resolveCallExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function resolveNewExpression(node, candidatesOutArray) { if (node.arguments && languageVersion < 1 /* ES5 */) { var spreadIndex = getSpreadArgumentIndex(node.arguments); if (spreadIndex >= 0) { error(node.arguments[spreadIndex], ts.Diagnostics.Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher); } } var expressionType = checkExpression(node.expression); // If expressionType's apparent type(section 3.8.1) is an object type with one or // more construct signatures, the expression is processed in the same manner as a // function call, but using the construct signatures as the initial set of candidate // signatures for overload resolution. The result type of the function call becomes // the result type of the operation. expressionType = getApparentType(expressionType); if (expressionType === unknownType) { // Another error has already been reported return resolveErrorCall(node); } // If the expression is a class of abstract type, then it cannot be instantiated. // Note, only class declarations can be declared abstract. // In the case of a merged class-module or class-interface declaration, // only the class declaration node will have the Abstract flag set. var valueDecl = expressionType.symbol && getClassLikeDeclarationOfSymbol(expressionType.symbol); if (valueDecl && valueDecl.flags & 128 /* Abstract */) { error(node, ts.Diagnostics.Cannot_create_an_instance_of_the_abstract_class_0, ts.declarationNameToString(valueDecl.name)); return resolveErrorCall(node); } // TS 1.0 spec: 4.11 // If expressionType is of type Any, Args can be any argument // list and the result of the operation is of type Any. if (isTypeAny(expressionType)) { if (node.typeArguments) { error(node, ts.Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } return resolveUntypedCall(node); } // Technically, this signatures list may be incomplete. We are taking the apparent type, // but we are not including construct signatures that may have been added to the Object or // Function interface, since they have none by default. This is a bit of a leap of faith // that the user will not add any. var constructSignatures = getSignaturesOfType(expressionType, 1 /* Construct */); if (constructSignatures.length) { return resolveCall(node, constructSignatures, candidatesOutArray); } // If expressionType's apparent type is an object type with no construct signatures but // one or more call signatures, the expression is processed as a function call. A compile-time // error occurs if the result of the function call is not Void. The type of the result of the // operation is Any. var callSignatures = getSignaturesOfType(expressionType, 0 /* Call */); if (callSignatures.length) { var signature = resolveCall(node, callSignatures, candidatesOutArray); if (getReturnTypeOfSignature(signature) !== voidType) { error(node, ts.Diagnostics.Only_a_void_function_can_be_called_with_the_new_keyword); } return signature; } error(node, ts.Diagnostics.Cannot_use_new_with_an_expression_whose_type_lacks_a_call_or_construct_signature); return resolveErrorCall(node); }
Gets the error node to use when reporting errors for an effective argument.
resolveNewExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function resolveTaggedTemplateExpression(node, candidatesOutArray) { var tagType = checkExpression(node.tag); var apparentType = getApparentType(tagType); if (apparentType === unknownType) { // Another error has already been reported return resolveErrorCall(node); } var callSignatures = getSignaturesOfType(apparentType, 0 /* Call */); if (isTypeAny(tagType) || (!callSignatures.length && !(tagType.flags & 16384 /* Union */) && isTypeAssignableTo(tagType, globalFunctionType))) { return resolveUntypedCall(node); } if (!callSignatures.length) { error(node, ts.Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature); return resolveErrorCall(node); } return resolveCall(node, callSignatures, candidatesOutArray); }
Gets the error node to use when reporting errors for an effective argument.
resolveTaggedTemplateExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkCallExpression(node) { // Grammar checking; stop grammar-checking if checkGrammarTypeArguments return true checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node, node.arguments); var signature = getResolvedSignature(node); if (node.expression.kind === 95 /* SuperKeyword */) { return voidType; } if (node.kind === 169 /* NewExpression */) { var declaration = signature.declaration; if (declaration && declaration.kind !== 144 /* Constructor */ && declaration.kind !== 148 /* ConstructSignature */ && declaration.kind !== 153 /* ConstructorType */) { // When resolved signature is a call signature (and not a construct signature) the result type is any if (compilerOptions.noImplicitAny) { error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type); } return anyType; } } // In JavaScript files, calls to any identifier 'require' are treated as external module imports if (ts.isInJavaScriptFile(node) && ts.isRequireCall(node)) { return resolveExternalModuleTypeByLiteral(node.arguments[0]); } return getReturnTypeOfSignature(signature); }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkCallExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkTaggedTemplateExpression(node) { return getReturnTypeOfSignature(getResolvedSignature(node)); }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkTaggedTemplateExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkAssertion(node) { var exprType = getRegularTypeOfObjectLiteral(checkExpression(node.expression)); var targetType = getTypeFromTypeNode(node.type); if (produceDiagnostics && targetType !== unknownType) { var widenedType = getWidenedType(exprType); // Permit 'number[] | "foo"' to be asserted to 'string'. var bothAreStringLike = someConstituentTypeHasKind(targetType, 258 /* StringLike */) && someConstituentTypeHasKind(widenedType, 258 /* StringLike */); if (!bothAreStringLike && !(isTypeAssignableTo(targetType, widenedType))) { checkTypeAssignableTo(exprType, targetType, node, ts.Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); } } return targetType; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkAssertion
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getTypeAtPosition(signature, pos) { return signature.hasRestParameter ? pos < signature.parameters.length - 1 ? getTypeOfSymbol(signature.parameters[pos]) : getRestTypeOfSignature(signature) : pos < signature.parameters.length ? getTypeOfSymbol(signature.parameters[pos]) : anyType; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
getTypeAtPosition
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function assignContextualParameterTypes(signature, context, mapper) { var len = signature.parameters.length - (signature.hasRestParameter ? 1 : 0); for (var i = 0; i < len; i++) { var parameter = signature.parameters[i]; var contextualParameterType = getTypeAtPosition(context, i); assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, mapper); } if (signature.hasRestParameter && isRestParameterIndex(context, signature.parameters.length - 1)) { var parameter = ts.lastOrUndefined(signature.parameters); var contextualParameterType = getTypeOfSymbol(ts.lastOrUndefined(context.parameters)); assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, mapper); } }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
assignContextualParameterTypes
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function assignTypeToParameterAndFixTypeParameters(parameter, contextualType, mapper) { var links = getSymbolLinks(parameter); if (!links.type) { links.type = instantiateType(contextualType, mapper); assignBindingElementTypes(parameter.valueDeclaration); } else if (isInferentialContext(mapper)) { // Even if the parameter already has a type, it might be because it was given a type while // processing the function as an argument to a prior signature during overload resolution. // If this was the case, it may have caused some type parameters to be fixed. So here, // we need to ensure that type parameters at the same positions get fixed again. This is // done by calling instantiateType to attach the mapper to the contextualType, and then // calling inferTypes to force a walk of contextualType so that all the correct fixing // happens. The choice to pass in links.type may seem kind of arbitrary, but it serves // to make sure that all the correct positions in contextualType are reached by the walk. // Here is an example: // // interface Base { // baseProp; // } // interface Derived extends Base { // toBase(): Base; // } // // var derived: Derived; // // declare function foo<T>(x: T, func: (p: T) => T): T; // declare function foo<T>(x: T, func: (p: T) => T): T; // // var result = foo(derived, d => d.toBase()); // // We are typing d while checking the second overload. But we've already given d // a type (Derived) from the first overload. However, we still want to fix the // T in the second overload so that we do not infer Base as a candidate for T // (inferring Base would make type argument inference inconsistent between the two // overloads). inferTypes(mapper.context, links.type, instantiateType(contextualType, mapper)); } }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
assignTypeToParameterAndFixTypeParameters
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function createPromiseType(promisedType) { // creates a `Promise<T>` type where `T` is the promisedType argument var globalPromiseType = getGlobalPromiseType(); if (globalPromiseType !== emptyGenericType) { // if the promised type is itself a promise, get the underlying type; otherwise, fallback to the promised type promisedType = getAwaitedType(promisedType); return createTypeReference(globalPromiseType, [promisedType]); } return emptyObjectType; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
createPromiseType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getReturnTypeFromBody(func, contextualMapper) { var contextualSignature = getContextualSignatureForFunctionLikeDeclaration(func); if (!func.body) { return unknownType; } var isAsync = ts.isAsyncFunctionLike(func); var type; if (func.body.kind !== 192 /* Block */) { type = checkExpressionCached(func.body, contextualMapper); if (isAsync) { // From within an async function you can return either a non-promise value or a promise. Any // Promise/A+ compatible implementation will always assimilate any foreign promise, so the // return type of the body should be unwrapped to its awaited type, which we will wrap in // the native Promise<T> type later in this function. type = checkAwaitedType(type, func, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); } } else { var types; var funcIsGenerator = !!func.asteriskToken; if (funcIsGenerator) { types = checkAndAggregateYieldOperandTypes(func.body, contextualMapper); if (types.length === 0) { var iterableIteratorAny = createIterableIteratorType(anyType); if (compilerOptions.noImplicitAny) { error(func.asteriskToken, ts.Diagnostics.Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type, typeToString(iterableIteratorAny)); } return iterableIteratorAny; } } else { types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper, isAsync); if (types.length === 0) { if (isAsync) { // For an async function, the return type will not be void, but rather a Promise for void. var promiseType = createPromiseType(voidType); if (promiseType === emptyObjectType) { error(func, ts.Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type); return unknownType; } return promiseType; } else { return voidType; } } } // When yield/return statements are contextually typed we allow the return type to be a union type. // Otherwise we require the yield/return expressions to have a best common supertype. type = contextualSignature ? getUnionType(types) : getCommonSupertype(types); if (!type) { if (funcIsGenerator) { error(func, ts.Diagnostics.No_best_common_type_exists_among_yield_expressions); return createIterableIteratorType(unknownType); } else { error(func, ts.Diagnostics.No_best_common_type_exists_among_return_expressions); return unknownType; } } if (funcIsGenerator) { type = createIterableIteratorType(type); } } if (!contextualSignature) { reportErrorsFromWidening(func, type); } var widenedType = getWidenedType(type); if (isAsync) { // From within an async function you can return either a non-promise value or a promise. Any // Promise/A+ compatible implementation will always assimilate any foreign promise, so the // return type of the body is awaited type of the body, wrapped in a native Promise<T> type. var promiseType = createPromiseType(widenedType); if (promiseType === emptyObjectType) { error(func, ts.Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type); return unknownType; } return promiseType; } else { return widenedType; } }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
getReturnTypeFromBody
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkAndAggregateYieldOperandTypes(body, contextualMapper) { var aggregatedTypes = []; ts.forEachYieldExpression(body, function (yieldExpression) { var expr = yieldExpression.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); if (yieldExpression.asteriskToken) { // A yield* expression effectively yields everything that its operand yields type = checkElementTypeOfIterable(type, yieldExpression.expression); } if (!ts.contains(aggregatedTypes, type)) { aggregatedTypes.push(type); } } }); return aggregatedTypes; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkAndAggregateYieldOperandTypes
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkAndAggregateReturnExpressionTypes(body, contextualMapper, isAsync) { var aggregatedTypes = []; ts.forEachReturnStatement(body, function (returnStatement) { var expr = returnStatement.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); if (isAsync) { // From within an async function you can return either a non-promise value or a promise. Any // Promise/A+ compatible implementation will always assimilate any foreign promise, so the // return type of the body should be unwrapped to its awaited type, which should be wrapped in // the native Promise<T> type by the caller. type = checkAwaitedType(type, body.parent, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); } if (!ts.contains(aggregatedTypes, type)) { aggregatedTypes.push(type); } } }); return aggregatedTypes; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkAndAggregateReturnExpressionTypes
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkAllCodePathsInNonVoidFunctionReturnOrThrow(func, returnType) { if (!produceDiagnostics) { return; } // Functions that return 'void' or 'any' don't need any return expressions. if (returnType === voidType || isTypeAny(returnType)) { return; } // If all we have is a function signature, or an arrow function with an expression body, then there is nothing to check. // also if HasImplicitReturnValue flags is not set this means that all codepaths in function body end with return of throw if (ts.nodeIsMissing(func.body) || func.body.kind !== 192 /* Block */ || !(func.flags & 524288 /* HasImplicitReturn */)) { return; } if (func.flags & 1048576 /* HasExplicitReturn */) { if (compilerOptions.noImplicitReturns) { error(func.type, ts.Diagnostics.Not_all_code_paths_return_a_value); } } else { // This function does not conform to the specification. error(func.type, ts.Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value); } }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkAllCodePathsInNonVoidFunctionReturnOrThrow
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper) { ts.Debug.assert(node.kind !== 143 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); // Grammar checking var hasGrammarError = checkGrammarFunctionLikeDeclaration(node); if (!hasGrammarError && node.kind === 173 /* FunctionExpression */) { checkGrammarForGenerator(node); } // The identityMapper object is used to indicate that function expressions are wildcards if (contextualMapper === identityMapper && isContextSensitive(node)) { return anyFunctionType; } var isAsync = ts.isAsyncFunctionLike(node); if (isAsync) { emitAwaiter = true; } var links = getNodeLinks(node); var type = getTypeOfSymbol(node.symbol); var contextSensitive = isContextSensitive(node); var mightFixTypeParameters = contextSensitive && isInferentialContext(contextualMapper); // Check if function expression is contextually typed and assign parameter types if so. // See the comment in assignTypeToParameterAndFixTypeParameters to understand why we need to // check mightFixTypeParameters. if (mightFixTypeParameters || !(links.flags & 1024 /* ContextChecked */)) { var contextualSignature = getContextualSignature(node); // If a type check is started at a function expression that is an argument of a function call, obtaining the // contextual type may recursively get back to here during overload resolution of the call. If so, we will have // already assigned contextual types. var contextChecked = !!(links.flags & 1024 /* ContextChecked */); if (mightFixTypeParameters || !contextChecked) { links.flags |= 1024 /* ContextChecked */; if (contextualSignature) { var signature = getSignaturesOfType(type, 0 /* Call */)[0]; if (contextSensitive) { assignContextualParameterTypes(signature, contextualSignature, contextualMapper || identityMapper); } if (mightFixTypeParameters || !node.type && !signature.resolvedReturnType) { var returnType = getReturnTypeFromBody(node, contextualMapper); if (!signature.resolvedReturnType) { signature.resolvedReturnType = returnType; } } } if (!contextChecked) { checkSignatureDeclaration(node); } } } if (produceDiagnostics && node.kind !== 143 /* MethodDeclaration */ && node.kind !== 142 /* MethodSignature */) { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); } return type; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkFunctionExpressionOrObjectLiteralMethod
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkFunctionExpressionOrObjectLiteralMethodBody(node) { ts.Debug.assert(node.kind !== 143 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); var isAsync = ts.isAsyncFunctionLike(node); if (isAsync) { emitAwaiter = true; } var returnType = node.type && getTypeFromTypeNode(node.type); var promisedType; if (returnType && isAsync) { promisedType = checkAsyncFunctionReturnType(node); } if (returnType && !node.asteriskToken) { checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, isAsync ? promisedType : returnType); } if (node.body) { if (!node.type) { // There are some checks that are only performed in getReturnTypeFromBody, that may produce errors // we need. An example is the noImplicitAny errors resulting from widening the return expression // of a function. Because checking of function expression bodies is deferred, there was never an // appropriate time to do this during the main walk of the file (see the comment at the top of // checkFunctionExpressionBodies). So it must be done now. getReturnTypeOfSignature(getSignatureFromDeclaration(node)); } if (node.body.kind === 192 /* Block */) { checkSourceElement(node.body); } else { // From within an async function you can return either a non-promise value or a promise. Any // Promise/A+ compatible implementation will always assimilate any foreign promise, so we // should not be checking assignability of a promise to the return type. Instead, we need to // check assignability of the awaited type of the expression body against the promised type of // its return type annotation. var exprType = checkExpression(node.body); if (returnType) { if (isAsync) { var awaitedType = checkAwaitedType(exprType, node.body, ts.Diagnostics.Expression_body_for_async_arrow_function_does_not_have_a_valid_callable_then_member); checkTypeAssignableTo(awaitedType, promisedType, node.body); } else { checkTypeAssignableTo(exprType, returnType, node.body); } } checkFunctionAndClassExpressionBodies(node.body); } } }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkFunctionExpressionOrObjectLiteralMethodBody
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkArithmeticOperandType(operand, type, diagnostic) { if (!isTypeAnyOrAllConstituentTypesHaveKind(type, 132 /* NumberLike */)) { error(operand, diagnostic); return false; } return true; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkArithmeticOperandType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkReferenceExpression(n, invalidReferenceMessage, constantVariableMessage) { function findSymbol(n) { var symbol = getNodeLinks(n).resolvedSymbol; // Because we got the symbol from the resolvedSymbol property, it might be of kind // SymbolFlags.ExportValue. In this case it is necessary to get the actual export // symbol, which will have the correct flags set on it. return symbol && getExportSymbolOfValueSymbolIfExported(symbol); } function isReferenceOrErrorExpression(n) { // TypeScript 1.0 spec (April 2014): // Expressions are classified as values or references. // References are the subset of expressions that are permitted as the target of an assignment. // Specifically, references are combinations of identifiers(section 4.3), parentheses(section 4.7), // and property accesses(section 4.10). // All other expression constructs described in this chapter are classified as values. switch (n.kind) { case 69 /* Identifier */: { var symbol = findSymbol(n); // TypeScript 1.0 spec (April 2014): 4.3 // An identifier expression that references a variable or parameter is classified as a reference. // An identifier expression that references any other kind of entity is classified as a value(and therefore cannot be the target of an assignment). return !symbol || symbol === unknownSymbol || symbol === argumentsSymbol || (symbol.flags & 3 /* Variable */) !== 0; } case 166 /* PropertyAccessExpression */: { var symbol = findSymbol(n); // TypeScript 1.0 spec (April 2014): 4.10 // A property access expression is always classified as a reference. // NOTE (not in spec): assignment to enum members should not be allowed return !symbol || symbol === unknownSymbol || (symbol.flags & ~8 /* EnumMember */) !== 0; } case 167 /* ElementAccessExpression */: // old compiler doesn't check indexed access return true; case 172 /* ParenthesizedExpression */: return isReferenceOrErrorExpression(n.expression); default: return false; } } function isConstVariableReference(n) { switch (n.kind) { case 69 /* Identifier */: case 166 /* PropertyAccessExpression */: { var symbol = findSymbol(n); return symbol && (symbol.flags & 3 /* Variable */) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & 16384 /* Const */) !== 0; } case 167 /* ElementAccessExpression */: { var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 9 /* StringLiteral */) { var name_12 = index.text; var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_12); return prop && (prop.flags & 3 /* Variable */) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 16384 /* Const */) !== 0; } return false; } case 172 /* ParenthesizedExpression */: return isConstVariableReference(n.expression); default: return false; } } if (!isReferenceOrErrorExpression(n)) { error(n, invalidReferenceMessage); return false; } if (isConstVariableReference(n)) { error(n, constantVariableMessage); return false; } return true; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkReferenceExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function findSymbol(n) { var symbol = getNodeLinks(n).resolvedSymbol; // Because we got the symbol from the resolvedSymbol property, it might be of kind // SymbolFlags.ExportValue. In this case it is necessary to get the actual export // symbol, which will have the correct flags set on it. return symbol && getExportSymbolOfValueSymbolIfExported(symbol); }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
findSymbol
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isReferenceOrErrorExpression(n) { // TypeScript 1.0 spec (April 2014): // Expressions are classified as values or references. // References are the subset of expressions that are permitted as the target of an assignment. // Specifically, references are combinations of identifiers(section 4.3), parentheses(section 4.7), // and property accesses(section 4.10). // All other expression constructs described in this chapter are classified as values. switch (n.kind) { case 69 /* Identifier */: { var symbol = findSymbol(n); // TypeScript 1.0 spec (April 2014): 4.3 // An identifier expression that references a variable or parameter is classified as a reference. // An identifier expression that references any other kind of entity is classified as a value(and therefore cannot be the target of an assignment). return !symbol || symbol === unknownSymbol || symbol === argumentsSymbol || (symbol.flags & 3 /* Variable */) !== 0; } case 166 /* PropertyAccessExpression */: { var symbol = findSymbol(n); // TypeScript 1.0 spec (April 2014): 4.10 // A property access expression is always classified as a reference. // NOTE (not in spec): assignment to enum members should not be allowed return !symbol || symbol === unknownSymbol || (symbol.flags & ~8 /* EnumMember */) !== 0; } case 167 /* ElementAccessExpression */: // old compiler doesn't check indexed access return true; case 172 /* ParenthesizedExpression */: return isReferenceOrErrorExpression(n.expression); default: return false; } }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
isReferenceOrErrorExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isConstVariableReference(n) { switch (n.kind) { case 69 /* Identifier */: case 166 /* PropertyAccessExpression */: { var symbol = findSymbol(n); return symbol && (symbol.flags & 3 /* Variable */) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & 16384 /* Const */) !== 0; } case 167 /* ElementAccessExpression */: { var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 9 /* StringLiteral */) { var name_12 = index.text; var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_12); return prop && (prop.flags & 3 /* Variable */) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 16384 /* Const */) !== 0; } return false; } case 172 /* ParenthesizedExpression */: return isConstVariableReference(n.expression); default: return false; } }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
isConstVariableReference
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkDeleteExpression(node) { checkExpression(node.expression); return booleanType; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkDeleteExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkTypeOfExpression(node) { checkExpression(node.expression); return stringType; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkTypeOfExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkVoidExpression(node) { checkExpression(node.expression); return undefinedType; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkVoidExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkAwaitExpression(node) { // Grammar checking if (produceDiagnostics) { if (!(node.parserContextFlags & 8 /* Await */)) { grammarErrorOnFirstToken(node, ts.Diagnostics.await_expression_is_only_allowed_within_an_async_function); } if (isInParameterInitializerBeforeContainingFunction(node)) { error(node, ts.Diagnostics.await_expressions_cannot_be_used_in_a_parameter_initializer); } } var operandType = checkExpression(node.expression); return checkAwaitedType(operandType, node); }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkAwaitExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkPrefixUnaryExpression(node) { var operandType = checkExpression(node.operand); switch (node.operator) { case 35 /* PlusToken */: case 36 /* MinusToken */: case 50 /* TildeToken */: if (someConstituentTypeHasKind(operandType, 16777216 /* ESSymbol */)) { error(node.operand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(node.operator)); } return numberType; case 49 /* ExclamationToken */: return booleanType; case 41 /* PlusPlusToken */: case 42 /* MinusMinusToken */: var ok = checkArithmeticOperandType(node.operand, operandType, ts.Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type); if (ok) { // run check only if former checks succeeded to avoid reporting cascading errors checkReferenceExpression(node.operand, ts.Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer, ts.Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant); } return numberType; } return unknownType; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkPrefixUnaryExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkPostfixUnaryExpression(node) { var operandType = checkExpression(node.operand); var ok = checkArithmeticOperandType(node.operand, operandType, ts.Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type); if (ok) { // run check only if former checks succeeded to avoid reporting cascading errors checkReferenceExpression(node.operand, ts.Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer, ts.Diagnostics.The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant); } return numberType; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkPostfixUnaryExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function someConstituentTypeHasKind(type, kind) { if (type.flags & kind) { return true; } if (type.flags & 49152 /* UnionOrIntersection */) { var types = type.types; for (var _i = 0, types_9 = types; _i < types_9.length; _i++) { var current = types_9[_i]; if (current.flags & kind) { return true; } } return false; } return false; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
someConstituentTypeHasKind
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function allConstituentTypesHaveKind(type, kind) { if (type.flags & kind) { return true; } if (type.flags & 49152 /* UnionOrIntersection */) { var types = type.types; for (var _i = 0, types_10 = types; _i < types_10.length; _i++) { var current = types_10[_i]; if (!(current.flags & kind)) { return false; } } return true; } return false; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
allConstituentTypesHaveKind
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isConstEnumObjectType(type) { return type.flags & (80896 /* ObjectType */ | 65536 /* Anonymous */) && type.symbol && isConstEnumSymbol(type.symbol); }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
isConstEnumObjectType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isConstEnumSymbol(symbol) { return (symbol.flags & 128 /* ConstEnum */) !== 0; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
isConstEnumSymbol
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkInstanceOfExpression(left, right, leftType, rightType) { // TypeScript 1.0 spec (April 2014): 4.15.4 // The instanceof operator requires the left operand to be of type Any, an object type, or a type parameter type, // and the right operand to be of type Any or a subtype of the 'Function' interface type. // The result is always of the Boolean primitive type. // NOTE: do not raise error if leftType is unknown as related error was already reported if (allConstituentTypesHaveKind(leftType, 16777726 /* Primitive */)) { error(left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } // NOTE: do not raise error if right is unknown as related error was already reported if (!(isTypeAny(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) { error(right, ts.Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type); } return booleanType; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkInstanceOfExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkInExpression(left, right, leftType, rightType) { // TypeScript 1.0 spec (April 2014): 4.15.5 // The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type, // and the right operand to be of type Any, an object type, or a type parameter type. // The result is always of the Boolean primitive type. if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, 258 /* StringLike */ | 132 /* NumberLike */ | 16777216 /* ESSymbol */)) { error(left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, 80896 /* ObjectType */ | 512 /* TypeParameter */)) { error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkInExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkObjectLiteralAssignment(node, sourceType, contextualMapper) { var properties = node.properties; for (var _i = 0, properties_3 = properties; _i < properties_3.length; _i++) { var p = properties_3[_i]; if (p.kind === 245 /* PropertyAssignment */ || p.kind === 246 /* ShorthandPropertyAssignment */) { var name_13 = p.name; if (name_13.kind === 136 /* ComputedPropertyName */) { checkComputedPropertyName(name_13); } if (isComputedNonLiteralName(name_13)) { continue; } var text = getTextOfPropertyName(name_13); var type = isTypeAny(sourceType) ? sourceType : getTypeOfPropertyOfType(sourceType, text) || isNumericLiteralName(text) && getIndexTypeOfType(sourceType, 1 /* Number */) || getIndexTypeOfType(sourceType, 0 /* String */); if (type) { if (p.kind === 246 /* ShorthandPropertyAssignment */) { checkDestructuringAssignment(p, type); } else { // non-shorthand property assignments should always have initializers checkDestructuringAssignment(p.initializer, type); } } else { error(name_13, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_13)); } } else { error(p, ts.Diagnostics.Property_assignment_expected); } } return sourceType; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkObjectLiteralAssignment
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkArrayLiteralAssignment(node, sourceType, contextualMapper) { // This elementType will be used if the specific property corresponding to this index is not // present (aka the tuple element property). This call also checks that the parentType is in // fact an iterable or array (depending on target language). var elementType = checkIteratedTypeOrElementType(sourceType, node, /*allowStringInput*/ false) || unknownType; var elements = node.elements; for (var i = 0; i < elements.length; i++) { var e = elements[i]; if (e.kind !== 187 /* OmittedExpression */) { if (e.kind !== 185 /* SpreadElementExpression */) { var propName = "" + i; var type = isTypeAny(sourceType) ? sourceType : isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : elementType; if (type) { checkDestructuringAssignment(e, type, contextualMapper); } else { if (isTupleType(sourceType)) { error(e, ts.Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, typeToString(sourceType), sourceType.elementTypes.length, elements.length); } else { error(e, ts.Diagnostics.Type_0_has_no_property_1, typeToString(sourceType), propName); } } } else { if (i < elements.length - 1) { error(e, ts.Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern); } else { var restExpression = e.expression; if (restExpression.kind === 181 /* BinaryExpression */ && restExpression.operatorToken.kind === 56 /* EqualsToken */) { error(restExpression.operatorToken, ts.Diagnostics.A_rest_element_cannot_have_an_initializer); } else { checkDestructuringAssignment(restExpression, createArrayType(elementType), contextualMapper); } } } } } return sourceType; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkArrayLiteralAssignment
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkDestructuringAssignment(exprOrAssignment, sourceType, contextualMapper) { var target; if (exprOrAssignment.kind === 246 /* ShorthandPropertyAssignment */) { var prop = exprOrAssignment; if (prop.objectAssignmentInitializer) { checkBinaryLikeExpression(prop.name, prop.equalsToken, prop.objectAssignmentInitializer, contextualMapper); } target = exprOrAssignment.name; } else { target = exprOrAssignment; } if (target.kind === 181 /* BinaryExpression */ && target.operatorToken.kind === 56 /* EqualsToken */) { checkBinaryExpression(target, contextualMapper); target = target.left; } if (target.kind === 165 /* ObjectLiteralExpression */) { return checkObjectLiteralAssignment(target, sourceType, contextualMapper); } if (target.kind === 164 /* ArrayLiteralExpression */) { return checkArrayLiteralAssignment(target, sourceType, contextualMapper); } return checkReferenceAssignment(target, sourceType, contextualMapper); }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkDestructuringAssignment
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkReferenceAssignment(target, sourceType, contextualMapper) { var targetType = checkExpression(target, contextualMapper); if (checkReferenceExpression(target, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant)) { checkTypeAssignableTo(sourceType, targetType, target, /*headMessage*/ undefined); } return sourceType; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkReferenceAssignment
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkBinaryExpression(node, contextualMapper) { return checkBinaryLikeExpression(node.left, node.operatorToken, node.right, contextualMapper, node); }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkBinaryExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkBinaryLikeExpression(left, operatorToken, right, contextualMapper, errorNode) { var operator = operatorToken.kind; if (operator === 56 /* EqualsToken */ && (left.kind === 165 /* ObjectLiteralExpression */ || left.kind === 164 /* ArrayLiteralExpression */)) { return checkDestructuringAssignment(left, checkExpression(right, contextualMapper), contextualMapper); } var leftType = checkExpression(left, contextualMapper); var rightType = checkExpression(right, contextualMapper); switch (operator) { case 37 /* AsteriskToken */: case 38 /* AsteriskAsteriskToken */: case 59 /* AsteriskEqualsToken */: case 60 /* AsteriskAsteriskEqualsToken */: case 39 /* SlashToken */: case 61 /* SlashEqualsToken */: case 40 /* PercentToken */: case 62 /* PercentEqualsToken */: case 36 /* MinusToken */: case 58 /* MinusEqualsToken */: case 43 /* LessThanLessThanToken */: case 63 /* LessThanLessThanEqualsToken */: case 44 /* GreaterThanGreaterThanToken */: case 64 /* GreaterThanGreaterThanEqualsToken */: case 45 /* GreaterThanGreaterThanGreaterThanToken */: case 65 /* GreaterThanGreaterThanGreaterThanEqualsToken */: case 47 /* BarToken */: case 67 /* BarEqualsToken */: case 48 /* CaretToken */: case 68 /* CaretEqualsToken */: case 46 /* AmpersandToken */: case 66 /* AmpersandEqualsToken */: // TypeScript 1.0 spec (April 2014): 4.19.1 // These operators require their operands to be of type Any, the Number primitive type, // or an enum type. Operands of an enum type are treated // as having the primitive type Number. If one operand is the null or undefined value, // it is treated as having the type of the other operand. // The result is always of the Number primitive type. if (leftType.flags & (32 /* Undefined */ | 64 /* Null */)) leftType = rightType; if (rightType.flags & (32 /* Undefined */ | 64 /* Null */)) rightType = leftType; var suggestedOperator; // if a user tries to apply a bitwise operator to 2 boolean operands // try and return them a helpful suggestion if ((leftType.flags & 8 /* Boolean */) && (rightType.flags & 8 /* Boolean */) && (suggestedOperator = getSuggestedBooleanOperator(operatorToken.kind)) !== undefined) { error(errorNode || operatorToken, ts.Diagnostics.The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead, ts.tokenToString(operatorToken.kind), ts.tokenToString(suggestedOperator)); } else { // otherwise just check each operand separately and report errors as normal var leftOk = checkArithmeticOperandType(left, leftType, ts.Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); var rightOk = checkArithmeticOperandType(right, rightType, ts.Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type); if (leftOk && rightOk) { checkAssignmentOperator(numberType); } } return numberType; case 35 /* PlusToken */: case 57 /* PlusEqualsToken */: // TypeScript 1.0 spec (April 2014): 4.19.2 // The binary + operator requires both operands to be of the Number primitive type or an enum type, // or at least one of the operands to be of type Any or the String primitive type. // If one operand is the null or undefined value, it is treated as having the type of the other operand. if (leftType.flags & (32 /* Undefined */ | 64 /* Null */)) leftType = rightType; if (rightType.flags & (32 /* Undefined */ | 64 /* Null */)) rightType = leftType; var resultType; if (allConstituentTypesHaveKind(leftType, 132 /* NumberLike */) && allConstituentTypesHaveKind(rightType, 132 /* NumberLike */)) { // Operands of an enum type are treated as having the primitive type Number. // If both operands are of the Number primitive type, the result is of the Number primitive type. resultType = numberType; } else { if (allConstituentTypesHaveKind(leftType, 258 /* StringLike */) || allConstituentTypesHaveKind(rightType, 258 /* StringLike */)) { // If one or both operands are of the String primitive type, the result is of the String primitive type. resultType = stringType; } else if (isTypeAny(leftType) || isTypeAny(rightType)) { // Otherwise, the result is of type Any. // NOTE: unknown type here denotes error type. Old compiler treated this case as any type so do we. resultType = leftType === unknownType || rightType === unknownType ? unknownType : anyType; } // Symbols are not allowed at all in arithmetic expressions if (resultType && !checkForDisallowedESSymbolOperand(operator)) { return resultType; } } if (!resultType) { reportOperatorError(); return anyType; } if (operator === 57 /* PlusEqualsToken */) { checkAssignmentOperator(resultType); } return resultType; case 25 /* LessThanToken */: case 27 /* GreaterThanToken */: case 28 /* LessThanEqualsToken */: case 29 /* GreaterThanEqualsToken */: if (!checkForDisallowedESSymbolOperand(operator)) { return booleanType; } // Fall through case 30 /* EqualsEqualsToken */: case 31 /* ExclamationEqualsToken */: case 32 /* EqualsEqualsEqualsToken */: case 33 /* ExclamationEqualsEqualsToken */: // Permit 'number[] | "foo"' to be asserted to 'string'. if (someConstituentTypeHasKind(leftType, 258 /* StringLike */) && someConstituentTypeHasKind(rightType, 258 /* StringLike */)) { return booleanType; } if (!isTypeAssignableTo(leftType, rightType) && !isTypeAssignableTo(rightType, leftType)) { reportOperatorError(); } return booleanType; case 91 /* InstanceOfKeyword */: return checkInstanceOfExpression(left, right, leftType, rightType); case 90 /* InKeyword */: return checkInExpression(left, right, leftType, rightType); case 51 /* AmpersandAmpersandToken */: return rightType; case 52 /* BarBarToken */: return getUnionType([leftType, rightType]); case 56 /* EqualsToken */: checkAssignmentOperator(rightType); return getRegularTypeOfObjectLiteral(rightType); case 24 /* CommaToken */: return rightType; } // Return true if there was no error, false if there was an error. function checkForDisallowedESSymbolOperand(operator) { var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 16777216 /* ESSymbol */) ? left : someConstituentTypeHasKind(rightType, 16777216 /* ESSymbol */) ? right : undefined; if (offendingSymbolOperand) { error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator)); return false; } return true; } function getSuggestedBooleanOperator(operator) { switch (operator) { case 47 /* BarToken */: case 67 /* BarEqualsToken */: return 52 /* BarBarToken */; case 48 /* CaretToken */: case 68 /* CaretEqualsToken */: return 33 /* ExclamationEqualsEqualsToken */; case 46 /* AmpersandToken */: case 66 /* AmpersandEqualsToken */: return 51 /* AmpersandAmpersandToken */; default: return undefined; } } function checkAssignmentOperator(valueType) { if (produceDiagnostics && operator >= 56 /* FirstAssignment */ && operator <= 68 /* LastAssignment */) { // TypeScript 1.0 spec (April 2014): 4.17 // An assignment of the form // VarExpr = ValueExpr // requires VarExpr to be classified as a reference // A compound assignment furthermore requires VarExpr to be classified as a reference (section 4.1) // and the type of the non - compound operation to be assignable to the type of VarExpr. var ok = checkReferenceExpression(left, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); // Use default messages if (ok) { // to avoid cascading errors check assignability only if 'isReference' check succeeded and no errors were reported checkTypeAssignableTo(valueType, leftType, left, /*headMessage*/ undefined); } } } function reportOperatorError() { error(errorNode || operatorToken, ts.Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, ts.tokenToString(operatorToken.kind), typeToString(leftType), typeToString(rightType)); } }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkBinaryLikeExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkForDisallowedESSymbolOperand(operator) { var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 16777216 /* ESSymbol */) ? left : someConstituentTypeHasKind(rightType, 16777216 /* ESSymbol */) ? right : undefined; if (offendingSymbolOperand) { error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator)); return false; } return true; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkForDisallowedESSymbolOperand
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getSuggestedBooleanOperator(operator) { switch (operator) { case 47 /* BarToken */: case 67 /* BarEqualsToken */: return 52 /* BarBarToken */; case 48 /* CaretToken */: case 68 /* CaretEqualsToken */: return 33 /* ExclamationEqualsEqualsToken */; case 46 /* AmpersandToken */: case 66 /* AmpersandEqualsToken */: return 51 /* AmpersandAmpersandToken */; default: return undefined; } }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
getSuggestedBooleanOperator
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkAssignmentOperator(valueType) { if (produceDiagnostics && operator >= 56 /* FirstAssignment */ && operator <= 68 /* LastAssignment */) { // TypeScript 1.0 spec (April 2014): 4.17 // An assignment of the form // VarExpr = ValueExpr // requires VarExpr to be classified as a reference // A compound assignment furthermore requires VarExpr to be classified as a reference (section 4.1) // and the type of the non - compound operation to be assignable to the type of VarExpr. var ok = checkReferenceExpression(left, ts.Diagnostics.Invalid_left_hand_side_of_assignment_expression, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); // Use default messages if (ok) { // to avoid cascading errors check assignability only if 'isReference' check succeeded and no errors were reported checkTypeAssignableTo(valueType, leftType, left, /*headMessage*/ undefined); } } }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkAssignmentOperator
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function reportOperatorError() { error(errorNode || operatorToken, ts.Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, ts.tokenToString(operatorToken.kind), typeToString(leftType), typeToString(rightType)); }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
reportOperatorError
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isYieldExpressionInClass(node) { var current = node; var parent = node.parent; while (parent) { if (ts.isFunctionLike(parent) && current === parent.body) { return false; } else if (ts.isClassLike(current)) { return true; } current = parent; parent = parent.parent; } return false; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
isYieldExpressionInClass
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkYieldExpression(node) { // Grammar checking if (produceDiagnostics) { if (!(node.parserContextFlags & 2 /* Yield */) || isYieldExpressionInClass(node)) { grammarErrorOnFirstToken(node, ts.Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body); } if (isInParameterInitializerBeforeContainingFunction(node)) { error(node, ts.Diagnostics.yield_expressions_cannot_be_used_in_a_parameter_initializer); } } if (node.expression) { var func = ts.getContainingFunction(node); // If the user's code is syntactically correct, the func should always have a star. After all, // we are in a yield context. if (func && func.asteriskToken) { var expressionType = checkExpressionCached(node.expression, /*contextualMapper*/ undefined); var expressionElementType; var nodeIsYieldStar = !!node.asteriskToken; if (nodeIsYieldStar) { expressionElementType = checkElementTypeOfIterable(expressionType, node.expression); } // There is no point in doing an assignability check if the function // has no explicit return type because the return type is directly computed // from the yield expressions. if (func.type) { var signatureElementType = getElementTypeOfIterableIterator(getTypeFromTypeNode(func.type)) || anyType; if (nodeIsYieldStar) { checkTypeAssignableTo(expressionElementType, signatureElementType, node.expression, /*headMessage*/ undefined); } else { checkTypeAssignableTo(expressionType, signatureElementType, node.expression, /*headMessage*/ undefined); } } } } // Both yield and yield* expressions have type 'any' return anyType; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkYieldExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkConditionalExpression(node, contextualMapper) { checkExpression(node.condition); var type1 = checkExpression(node.whenTrue, contextualMapper); var type2 = checkExpression(node.whenFalse, contextualMapper); return getUnionType([type1, type2]); }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkConditionalExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkStringLiteralExpression(node) { var contextualType = getContextualType(node); if (contextualType && contextualTypeIsStringLiteralType(contextualType)) { return getStringLiteralType(node); } return stringType; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkStringLiteralExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkTemplateExpression(node) { // We just want to check each expressions, but we are unconcerned with // the type of each expression, as any value may be coerced into a string. // It is worth asking whether this is what we really want though. // A place where we actually *are* concerned with the expressions' types are // in tagged templates. ts.forEach(node.templateSpans, function (templateSpan) { checkExpression(templateSpan.expression); }); return stringType; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkTemplateExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkExpressionWithContextualType(node, contextualType, contextualMapper) { var saveContextualType = node.contextualType; node.contextualType = contextualType; var result = checkExpression(node, contextualMapper); node.contextualType = saveContextualType; return result; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkExpressionWithContextualType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkExpressionCached(node, contextualMapper) { var links = getNodeLinks(node); if (!links.resolvedType) { links.resolvedType = checkExpression(node, contextualMapper); } return links.resolvedType; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkExpressionCached
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkPropertyAssignment(node, contextualMapper) { // Do not use hasDynamicName here, because that returns false for well known symbols. // We want to perform checkComputedPropertyName for all computed properties, including // well known symbols. if (node.name.kind === 136 /* ComputedPropertyName */) { checkComputedPropertyName(node.name); } return checkExpression(node.initializer, contextualMapper); }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkPropertyAssignment
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkObjectLiteralMethod(node, contextualMapper) { // Grammar checking checkGrammarMethod(node); // Do not use hasDynamicName here, because that returns false for well known symbols. // We want to perform checkComputedPropertyName for all computed properties, including // well known symbols. if (node.name.kind === 136 /* ComputedPropertyName */) { checkComputedPropertyName(node.name); } var uninstantiatedType = checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); return instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper); }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkObjectLiteralMethod
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function instantiateTypeWithSingleGenericCallSignature(node, type, contextualMapper) { if (isInferentialContext(contextualMapper)) { var signature = getSingleCallSignature(type); if (signature && signature.typeParameters) { var contextualType = getApparentTypeOfContextualType(node); if (contextualType) { var contextualSignature = getSingleCallSignature(contextualType); if (contextualSignature && !contextualSignature.typeParameters) { return getOrCreateTypeFromSignature(instantiateSignatureInContextOf(signature, contextualSignature, contextualMapper)); } } } } return type; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
instantiateTypeWithSingleGenericCallSignature
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkExpression(node, contextualMapper) { var type; if (node.kind === 135 /* QualifiedName */) { type = checkQualifiedName(node); } else { var uninstantiatedType = checkExpressionWorker(node, contextualMapper); type = instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper); } if (isConstEnumObjectType(type)) { // enum object type for const enums are only permitted in: // - 'left' in property access // - 'object' in indexed access // - target in rhs of import statement var ok = (node.parent.kind === 166 /* PropertyAccessExpression */ && node.parent.expression === node) || (node.parent.kind === 167 /* ElementAccessExpression */ && node.parent.expression === node) || ((node.kind === 69 /* Identifier */ || node.kind === 135 /* QualifiedName */) && isInRightSideOfImportOrExportAssignment(node)); if (!ok) { error(node, ts.Diagnostics.const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment); } } return type; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkNumericLiteral(node) { // Grammar checking checkGrammarNumericLiteral(node); return numberType; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkNumericLiteral
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkExpressionWorker(node, contextualMapper) { switch (node.kind) { case 69 /* Identifier */: return checkIdentifier(node); case 97 /* ThisKeyword */: return checkThisExpression(node); case 95 /* SuperKeyword */: return checkSuperExpression(node); case 93 /* NullKeyword */: return nullType; case 99 /* TrueKeyword */: case 84 /* FalseKeyword */: return booleanType; case 8 /* NumericLiteral */: return checkNumericLiteral(node); case 183 /* TemplateExpression */: return checkTemplateExpression(node); case 9 /* StringLiteral */: return checkStringLiteralExpression(node); case 11 /* NoSubstitutionTemplateLiteral */: return stringType; case 10 /* RegularExpressionLiteral */: return globalRegExpType; case 164 /* ArrayLiteralExpression */: return checkArrayLiteral(node, contextualMapper); case 165 /* ObjectLiteralExpression */: return checkObjectLiteral(node, contextualMapper); case 166 /* PropertyAccessExpression */: return checkPropertyAccessExpression(node); case 167 /* ElementAccessExpression */: return checkIndexedAccess(node); case 168 /* CallExpression */: case 169 /* NewExpression */: return checkCallExpression(node); case 170 /* TaggedTemplateExpression */: return checkTaggedTemplateExpression(node); case 172 /* ParenthesizedExpression */: return checkExpression(node.expression, contextualMapper); case 186 /* ClassExpression */: return checkClassExpression(node); case 173 /* FunctionExpression */: case 174 /* ArrowFunction */: return checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); case 176 /* TypeOfExpression */: return checkTypeOfExpression(node); case 171 /* TypeAssertionExpression */: case 189 /* AsExpression */: return checkAssertion(node); case 175 /* DeleteExpression */: return checkDeleteExpression(node); case 177 /* VoidExpression */: return checkVoidExpression(node); case 178 /* AwaitExpression */: return checkAwaitExpression(node); case 179 /* PrefixUnaryExpression */: return checkPrefixUnaryExpression(node); case 180 /* PostfixUnaryExpression */: return checkPostfixUnaryExpression(node); case 181 /* BinaryExpression */: return checkBinaryExpression(node, contextualMapper); case 182 /* ConditionalExpression */: return checkConditionalExpression(node, contextualMapper); case 185 /* SpreadElementExpression */: return checkSpreadElementExpression(node, contextualMapper); case 187 /* OmittedExpression */: return undefinedType; case 184 /* YieldExpression */: return checkYieldExpression(node); case 240 /* JsxExpression */: return checkJsxExpression(node); case 233 /* JsxElement */: return checkJsxElement(node); case 234 /* JsxSelfClosingElement */: return checkJsxSelfClosingElement(node); case 235 /* JsxOpeningElement */: ts.Debug.fail("Shouldn't ever directly check a JsxOpeningElement"); } return unknownType; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkExpressionWorker
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkParameter(node) { // Grammar checking // It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the // Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code // or if its FunctionBody is strict code(11.1.5). // Grammar checking checkGrammarDecorators(node) || checkGrammarModifiers(node); checkVariableLikeDeclaration(node); var func = ts.getContainingFunction(node); if (node.flags & 56 /* AccessibilityModifier */) { func = ts.getContainingFunction(node); if (!(func.kind === 144 /* Constructor */ && ts.nodeIsPresent(func.body))) { error(node, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } } if (node.questionToken && ts.isBindingPattern(node.name) && func.body) { error(node, ts.Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature); } // Only check rest parameter type if it's not a binding pattern. Since binding patterns are // not allowed in a rest parameter, we already have an error from checkGrammarParameterList. if (node.dotDotDotToken && !ts.isBindingPattern(node.name) && !isArrayType(getTypeOfSymbol(node.symbol))) { error(node, ts.Diagnostics.A_rest_parameter_must_be_of_an_array_type); } }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkParameter
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isSyntacticallyValidGenerator(node) { if (!node.asteriskToken || !node.body) { return false; } return node.kind === 143 /* MethodDeclaration */ || node.kind === 213 /* FunctionDeclaration */ || node.kind === 173 /* FunctionExpression */; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
isSyntacticallyValidGenerator
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getTypePredicateParameterIndex(parameterList, parameter) { if (parameterList) { for (var i = 0; i < parameterList.length; i++) { var param = parameterList[i]; if (param.name.kind === 69 /* Identifier */ && param.name.text === parameter.text) { return i; } } } return -1; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
getTypePredicateParameterIndex
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isInLegalTypePredicatePosition(node) { switch (node.parent.kind) { case 174 /* ArrowFunction */: case 147 /* CallSignature */: case 213 /* FunctionDeclaration */: case 173 /* FunctionExpression */: case 152 /* FunctionType */: case 143 /* MethodDeclaration */: case 142 /* MethodSignature */: return node === node.parent.type; } return false; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
isInLegalTypePredicatePosition
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkSignatureDeclaration(node) { // Grammar checking if (node.kind === 149 /* IndexSignature */) { checkGrammarIndexSignature(node); } else if (node.kind === 152 /* FunctionType */ || node.kind === 213 /* FunctionDeclaration */ || node.kind === 153 /* ConstructorType */ || node.kind === 147 /* CallSignature */ || node.kind === 144 /* Constructor */ || node.kind === 148 /* ConstructSignature */) { checkGrammarFunctionLikeDeclaration(node); } checkTypeParameters(node.typeParameters); ts.forEach(node.parameters, checkParameter); if (node.type) { if (node.type.kind === 150 /* TypePredicate */) { var typePredicate = getSignatureFromDeclaration(node).typePredicate; var typePredicateNode = node.type; if (isInLegalTypePredicatePosition(typePredicateNode)) { if (typePredicate.parameterIndex >= 0) { if (node.parameters[typePredicate.parameterIndex].dotDotDotToken) { error(typePredicateNode.parameterName, ts.Diagnostics.A_type_predicate_cannot_reference_a_rest_parameter); } else { checkTypeAssignableTo(typePredicate.type, getTypeOfNode(node.parameters[typePredicate.parameterIndex]), typePredicateNode.type); } } else if (typePredicateNode.parameterName) { var hasReportedError = false; for (var _i = 0, _a = node.parameters; _i < _a.length; _i++) { var param = _a[_i]; if (hasReportedError) { break; } if (param.name.kind === 161 /* ObjectBindingPattern */ || param.name.kind === 162 /* ArrayBindingPattern */) { (function checkBindingPattern(pattern) { for (var _i = 0, _a = pattern.elements; _i < _a.length; _i++) { var element = _a[_i]; if (element.name.kind === 69 /* Identifier */ && element.name.text === typePredicate.parameterName) { error(typePredicateNode.parameterName, ts.Diagnostics.A_type_predicate_cannot_reference_element_0_in_a_binding_pattern, typePredicate.parameterName); hasReportedError = true; break; } else if (element.name.kind === 162 /* ArrayBindingPattern */ || element.name.kind === 161 /* ObjectBindingPattern */) { checkBindingPattern(element.name); } } })(param.name); } } if (!hasReportedError) { error(typePredicateNode.parameterName, ts.Diagnostics.Cannot_find_parameter_0, typePredicate.parameterName); } } } else { error(typePredicateNode, ts.Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods); } } else { checkSourceElement(node.type); } } if (produceDiagnostics) { checkCollisionWithArgumentsInGeneratedCode(node); if (compilerOptions.noImplicitAny && !node.type) { switch (node.kind) { case 148 /* ConstructSignature */: error(node, ts.Diagnostics.Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); break; case 147 /* CallSignature */: error(node, ts.Diagnostics.Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); break; } } if (node.type) { if (languageVersion >= 2 /* ES6 */ && isSyntacticallyValidGenerator(node)) { var returnType = getTypeFromTypeNode(node.type); if (returnType === voidType) { error(node.type, ts.Diagnostics.A_generator_cannot_have_a_void_type_annotation); } else { var generatorElementType = getElementTypeOfIterableIterator(returnType) || anyType; var iterableIteratorInstantiation = createIterableIteratorType(generatorElementType); // Naively, one could check that IterableIterator<any> is assignable to the return type annotation. // However, that would not catch the error in the following case. // // interface BadGenerator extends Iterable<number>, Iterator<string> { } // function* g(): BadGenerator { } // Iterable and Iterator have different types! // checkTypeAssignableTo(iterableIteratorInstantiation, returnType, node.type); } } } } checkSpecializedSignatureDeclaration(node); }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkSignatureDeclaration
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkTypeForDuplicateIndexSignatures(node) { if (node.kind === 215 /* InterfaceDeclaration */) { var nodeSymbol = getSymbolOfNode(node); // in case of merging interface declaration it is possible that we'll enter this check procedure several times for every declaration // to prevent this run check only for the first declaration of a given kind if (nodeSymbol.declarations.length > 0 && nodeSymbol.declarations[0] !== node) { return; } } // TypeScript 1.0 spec (April 2014) // 3.7.4: An object type can contain at most one string index signature and one numeric index signature. // 8.5: A class declaration can have at most one string index member declaration and one numeric index member declaration var indexSymbol = getIndexSymbol(getSymbolOfNode(node)); if (indexSymbol) { var seenNumericIndexer = false; var seenStringIndexer = false; for (var _i = 0, _a = indexSymbol.declarations; _i < _a.length; _i++) { var decl = _a[_i]; var declaration = decl; if (declaration.parameters.length === 1 && declaration.parameters[0].type) { switch (declaration.parameters[0].type.kind) { case 130 /* StringKeyword */: if (!seenStringIndexer) { seenStringIndexer = true; } else { error(declaration, ts.Diagnostics.Duplicate_string_index_signature); } break; case 128 /* NumberKeyword */: if (!seenNumericIndexer) { seenNumericIndexer = true; } else { error(declaration, ts.Diagnostics.Duplicate_number_index_signature); } break; } } } } }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkTypeForDuplicateIndexSignatures
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkPropertyDeclaration(node) { // Grammar checking checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarProperty(node) || checkGrammarComputedPropertyName(node.name); checkVariableLikeDeclaration(node); }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkPropertyDeclaration
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkMethodDeclaration(node) { // Grammar checking checkGrammarMethod(node) || checkGrammarComputedPropertyName(node.name); // Grammar checking for modifiers is done inside the function checkGrammarFunctionLikeDeclaration checkFunctionLikeDeclaration(node); // Abstract methods cannot have an implementation. // Extra checks are to avoid reporting multiple errors relating to the "abstractness" of the node. if (node.flags & 128 /* Abstract */ && node.body) { error(node, ts.Diagnostics.Method_0_cannot_have_an_implementation_because_it_is_marked_abstract, ts.declarationNameToString(node.name)); } }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkMethodDeclaration
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkConstructorDeclaration(node) { // Grammar check on signature of constructor and modifier of the constructor is done in checkSignatureDeclaration function. checkSignatureDeclaration(node); // Grammar check for checking only related to constructoDeclaration checkGrammarConstructorTypeParameters(node) || checkGrammarConstructorTypeAnnotation(node); checkSourceElement(node.body); var symbol = getSymbolOfNode(node); var firstDeclaration = ts.getDeclarationOfKind(symbol, node.kind); // Only type check the symbol once if (node === firstDeclaration) { checkFunctionOrConstructorSymbol(symbol); } // exit early in the case of signature - super checks are not relevant to them if (ts.nodeIsMissing(node.body)) { return; } if (!produceDiagnostics) { return; } function isSuperCallExpression(n) { return n.kind === 168 /* CallExpression */ && n.expression.kind === 95 /* SuperKeyword */; } function containsSuperCallAsComputedPropertyName(n) { return n.name && containsSuperCall(n.name); } function containsSuperCall(n) { if (isSuperCallExpression(n)) { return true; } else if (ts.isFunctionLike(n)) { return false; } else if (ts.isClassLike(n)) { return ts.forEach(n.members, containsSuperCallAsComputedPropertyName); } return ts.forEachChild(n, containsSuperCall); } function markThisReferencesAsErrors(n) { if (n.kind === 97 /* ThisKeyword */) { error(n, ts.Diagnostics.this_cannot_be_referenced_in_current_location); } else if (n.kind !== 173 /* FunctionExpression */ && n.kind !== 213 /* FunctionDeclaration */) { ts.forEachChild(n, markThisReferencesAsErrors); } } function isInstancePropertyWithInitializer(n) { return n.kind === 141 /* PropertyDeclaration */ && !(n.flags & 64 /* Static */) && !!n.initializer; } // TS 1.0 spec (April 2014): 8.3.2 // Constructors of classes with no extends clause may not contain super calls, whereas // constructors of derived classes must contain at least one super call somewhere in their function body. var containingClassDecl = node.parent; if (ts.getClassExtendsHeritageClauseElement(containingClassDecl)) { var containingClassSymbol = getSymbolOfNode(containingClassDecl); var containingClassInstanceType = getDeclaredTypeOfSymbol(containingClassSymbol); var baseConstructorType = getBaseConstructorTypeOfClass(containingClassInstanceType); if (containsSuperCall(node.body)) { if (baseConstructorType === nullType) { error(node, ts.Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null); } // The first statement in the body of a constructor (excluding prologue directives) must be a super call // if both of the following are true: // - The containing class is a derived class. // - The constructor declares parameter properties // or the containing class declares instance member variables with initializers. var superCallShouldBeFirst = ts.forEach(node.parent.members, isInstancePropertyWithInitializer) || ts.forEach(node.parameters, function (p) { return p.flags & (8 /* Public */ | 16 /* Private */ | 32 /* Protected */); }); // Skip past any prologue directives to find the first statement // to ensure that it was a super call. if (superCallShouldBeFirst) { var statements = node.body.statements; var superCallStatement; for (var _i = 0, statements_2 = statements; _i < statements_2.length; _i++) { var statement = statements_2[_i]; if (statement.kind === 195 /* ExpressionStatement */ && isSuperCallExpression(statement.expression)) { superCallStatement = statement; break; } if (!ts.isPrologueDirective(statement)) { break; } } if (!superCallStatement) { error(node, ts.Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties); } else { // In such a required super call, it is a compile-time error for argument expressions to reference this. markThisReferencesAsErrors(superCallStatement.expression); } } } else if (baseConstructorType !== nullType) { error(node, ts.Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call); } } }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkConstructorDeclaration
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isSuperCallExpression(n) { return n.kind === 168 /* CallExpression */ && n.expression.kind === 95 /* SuperKeyword */; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
isSuperCallExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function containsSuperCallAsComputedPropertyName(n) { return n.name && containsSuperCall(n.name); }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
containsSuperCallAsComputedPropertyName
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function containsSuperCall(n) { if (isSuperCallExpression(n)) { return true; } else if (ts.isFunctionLike(n)) { return false; } else if (ts.isClassLike(n)) { return ts.forEach(n.members, containsSuperCallAsComputedPropertyName); } return ts.forEachChild(n, containsSuperCall); }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
containsSuperCall
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function markThisReferencesAsErrors(n) { if (n.kind === 97 /* ThisKeyword */) { error(n, ts.Diagnostics.this_cannot_be_referenced_in_current_location); } else if (n.kind !== 173 /* FunctionExpression */ && n.kind !== 213 /* FunctionDeclaration */) { ts.forEachChild(n, markThisReferencesAsErrors); } }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
markThisReferencesAsErrors
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isInstancePropertyWithInitializer(n) { return n.kind === 141 /* PropertyDeclaration */ && !(n.flags & 64 /* Static */) && !!n.initializer; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
isInstancePropertyWithInitializer
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkAccessorDeclaration(node) { if (produceDiagnostics) { // Grammar checking accessors checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name); if (node.kind === 145 /* GetAccessor */) { if (!ts.isInAmbientContext(node) && ts.nodeIsPresent(node.body) && (node.flags & 524288 /* HasImplicitReturn */)) { if (node.flags & 1048576 /* HasExplicitReturn */) { if (compilerOptions.noImplicitReturns) { error(node.name, ts.Diagnostics.Not_all_code_paths_return_a_value); } } else { error(node.name, ts.Diagnostics.A_get_accessor_must_return_a_value); } } } if (!ts.hasDynamicName(node)) { // TypeScript 1.0 spec (April 2014): 8.4.3 // Accessors for the same member name must specify the same accessibility. var otherKind = node.kind === 145 /* GetAccessor */ ? 146 /* SetAccessor */ : 145 /* GetAccessor */; var otherAccessor = ts.getDeclarationOfKind(node.symbol, otherKind); if (otherAccessor) { if (((node.flags & 56 /* AccessibilityModifier */) !== (otherAccessor.flags & 56 /* AccessibilityModifier */))) { error(node.name, ts.Diagnostics.Getter_and_setter_accessors_do_not_agree_in_visibility); } var currentAccessorType = getAnnotatedAccessorType(node); var otherAccessorType = getAnnotatedAccessorType(otherAccessor); // TypeScript 1.0 spec (April 2014): 4.5 // If both accessors include type annotations, the specified types must be identical. if (currentAccessorType && otherAccessorType) { if (!isTypeIdenticalTo(currentAccessorType, otherAccessorType)) { error(node, ts.Diagnostics.get_and_set_accessor_must_have_the_same_type); } } } } getTypeOfAccessors(getSymbolOfNode(node)); } checkFunctionLikeDeclaration(node); }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkAccessorDeclaration
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkTypeArgumentConstraints(typeParameters, typeArguments) { var result = true; for (var i = 0; i < typeParameters.length; i++) { var constraint = getConstraintOfTypeParameter(typeParameters[i]); if (constraint) { var typeArgument = typeArguments[i]; result = result && checkTypeAssignableTo(getTypeFromTypeNode(typeArgument), constraint, typeArgument, ts.Diagnostics.Type_0_does_not_satisfy_the_constraint_1); } } return result; }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkTypeArgumentConstraints
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkTypeReferenceNode(node) { checkGrammarTypeArguments(node, node.typeArguments); var type = getTypeFromTypeReference(node); if (type !== unknownType && node.typeArguments) { // Do type argument local checks only if referenced type is successfully resolved ts.forEach(node.typeArguments, checkSourceElement); if (produceDiagnostics) { var symbol = getNodeLinks(node).resolvedSymbol; var typeParameters = symbol.flags & 524288 /* TypeAlias */ ? getSymbolLinks(symbol).typeParameters : type.target.localTypeParameters; checkTypeArgumentConstraints(typeParameters, node.typeArguments); } } }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkTypeReferenceNode
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkTypeLiteral(node) { ts.forEach(node.members, checkSourceElement); if (produceDiagnostics) { var type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); } }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkTypeLiteral
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkTupleType(node) { // Grammar checking var hasErrorFromDisallowedTrailingComma = checkGrammarForDisallowedTrailingComma(node.elementTypes); if (!hasErrorFromDisallowedTrailingComma && node.elementTypes.length === 0) { grammarErrorOnNode(node, ts.Diagnostics.A_tuple_type_element_list_cannot_be_empty); } ts.forEach(node.elementTypes, checkSourceElement); }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkTupleType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkUnionOrIntersectionType(node) { ts.forEach(node.types, checkSourceElement); }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
checkUnionOrIntersectionType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isPrivateWithinAmbient(node) { return (node.flags & 16 /* Private */) && ts.isInAmbientContext(node); }
Syntactically and semantically checks a call or new expression. @param node The call/new expression to be checked. @returns On success, the expression's signature's return type. On failure, anyType.
isPrivateWithinAmbient
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT