function getEnclosingBlockScopeContainer(node) {
        var current = node.parent;
        while (current) {
            if (isFunctionLike(current)) {
                return current;
            }
            switch (current.kind) {
                case 248 /* SourceFile */:
                case 220 /* CaseBlock */:
                case 244 /* CatchClause */:
                case 218 /* ModuleDeclaration */:
                case 199 /* ForStatement */:
                case 200 /* ForInStatement */:
                case 201 /* ForOfStatement */:
                    return current;
                case 192 /* Block */:
                    // function block is not considered block-scope container
                    // see comment in binder.ts: bind(...), case for SyntaxKind.Block
                    if (!isFunctionLike(current.parent)) {
                        return current;
                    }
            }
            current = current.parent;
        }
    }

Gets the nearest enclosing block scope container that has the provided node as a descendant, that is not the provided node.

Gets the nearest enclosing block scope container that has the provided node as a descendant that is not the provided node .


function isDeclarationName(name) {
        if (name.kind !== 69 /* Identifier */ && name.kind !== 9 /* StringLiteral */ && name.kind !== 8 /* NumericLiteral */) {
            return false;
        }
        var parent = name.parent;
        if (parent.kind === 226 /* ImportSpecifier */ || parent.kind === 230 /* ExportSpecifier */) {
            if (parent.propertyName) {
                return true;
            }
        }
        if (isDeclaration(parent)) {
            return parent.name === name;
        }
        return false;
    }

function
isDeclarationName
(
name
)
{
if
(
name
.
kind
!==
69
/* Identifier */
&&
name
.
kind
!==
9
/* StringLiteral */
&&
name
.
kind
!==
8
/* NumericLiteral */
)
{
return
false
;
}
var
parent
=
name
.
parent
;
if
(
parent
.
kind
===
226
/* ImportSpecifier */
||
parent
.
kind
===
230
/* ExportSpecifier */
)
{
if
(
parent
.
propertyName
)
{
return
true
;
}
}
if
(
isDeclaration
(
parent
)
)
{
return
parent
.
name
===
name
;
}
return
false
;
}

True if the given identifier, string literal, or number literal is the name of a declaration node

True if the given identifier string literal or number literal is the name of a declaration node


function isIdentifierName(node) {
        var parent = node.parent;
        switch (parent.kind) {
            case 141 /* PropertyDeclaration */:
            case 140 /* PropertySignature */:
            case 143 /* MethodDeclaration */:
            case 142 /* MethodSignature */:
            case 145 /* GetAccessor */:
            case 146 /* SetAccessor */:
            case 247 /* EnumMember */:
            case 245 /* PropertyAssignment */:
            case 166 /* PropertyAccessExpression */:
                // Name in member declaration or property name in property access
                return parent.name === node;
            case 135 /* QualifiedName */:
                // Name on right hand side of dot in a type query
                if (parent.right === node) {
                    while (parent.kind === 135 /* QualifiedName */) {
                        parent = parent.parent;
                    }
                    return parent.kind === 154 /* TypeQuery */;
                }
                return false;
            case 163 /* BindingElement */:
            case 226 /* ImportSpecifier */:
                // Property name in binding element or import specifier
                return parent.propertyName === node;
            case 230 /* ExportSpecifier */:
                // Any name in an export specifier
                return true;
        }
        return false;
    }

Return true if the given identifier is classified as an IdentifierName


function getExpandedCharCodes(input) {
        var output = [];
        var length = input.length;
        for (var i = 0; i < length; i++) {
            var charCode = input.charCodeAt(i);
            // handel utf8
            if (charCode < 0x80) {
                output.push(charCode);
            }
            else if (charCode < 0x800) {
                output.push((charCode >> 6) | 192);
                output.push((charCode & 63) | 128);
            }
            else if (charCode < 0x10000) {
                output.push((charCode >> 12) | 224);
                output.push(((charCode >> 6) & 63) | 128);
                output.push((charCode & 63) | 128);
            }
            else if (charCode < 0x20000) {
                output.push((charCode >> 18) | 240);
                output.push(((charCode >> 12) & 63) | 128);
                output.push(((charCode >> 6) & 63) | 128);
                output.push((charCode & 63) | 128);
            }
            else {
                ts.Debug.assert(false, "Unexpected code point");
            }
        }
        return output;
    }

function
getExpandedCharCodes
(
input
)
{
var
output
=
[
]
;
var
length
=
input
.
length
;
for
(
var
i
=
0
;
i
<
length
;
i
++
)
{
var
charCode
=
input
.
charCodeAt
(
i
)
;
// handel utf8
if
(
charCode
<
0x80
)
{
output
.
push
(
charCode
)
;
}
else
if
(
charCode
<
0x800
)
{
output
.
push
(
(
charCode
>>
6
)
|
192
)
;
output
.
push
(
(
charCode
&
63
)
|
128
)
;
}
else
if
(
charCode
<
0x10000
)
{
output
.
push
(
(
charCode
>>
12
)
|
224
)
;
output
.
push
(
(
(
charCode
>>
6
)
&
63
)
|
128
)
;
output
.
push
(
(
charCode
&
63
)
|
128
)
;
}
else
if
(
charCode
<
0x20000
)
{
output
.
push
(
(
charCode
>>
18
)
|
240
)
;
output
.
push
(
(
(
charCode
>>
12
)
&
63
)
|
128
)
;
output
.
push
(
(
(
charCode
>>
6
)
&
63
)
|
128
)
;
output
.
push
(
(
charCode
&
63
)
|
128
)
;
}
else
{
ts
.
Debug
.
assert
(
false
,
"Unexpected code point"
)
;
}
}
return
output
;
}

Replace each instance of non-ascii characters by one, two, three, or four escape sequences
representing the UTF-8 encoding of the character, and return the expanded char code list.

Replace each instance of non - ascii characters by one two three or four escape sequences representing the UTF - 8 encoding of the character and return the expanded char code list .


function textSpanContainsTextSpan(span, other) {
        return other.start >= span.start && textSpanEnd(other) <= textSpanEnd(span);
    }

function textSpanContainsTextSpan ( span , other ) { return other . start >= span . start && textSpanEnd ( other ) <= textSpanEnd ( span ) ; }

Returns true if 'span' contains 'other'.


function isListTerminator(kind) {
            if (token === 1 /* EndOfFileToken */) {
                // Being at the end of the file ends all lists.
                return true;
            }
            switch (kind) {
                case 1 /* BlockStatements */:
                case 2 /* SwitchClauses */:
                case 4 /* TypeMembers */:
                case 5 /* ClassMembers */:
                case 6 /* EnumMembers */:
                case 12 /* ObjectLiteralMembers */:
                case 9 /* ObjectBindingElements */:
                case 21 /* ImportOrExportSpecifiers */:
                    return token === 16 /* CloseBraceToken */;
                case 3 /* SwitchClauseStatements */:
                    return token === 16 /* CloseBraceToken */ || token === 71 /* CaseKeyword */ || token === 77 /* DefaultKeyword */;
                case 7 /* HeritageClauseElement */:
                    return token === 15 /* OpenBraceToken */ || token === 83 /* ExtendsKeyword */ || token === 106 /* ImplementsKeyword */;
                case 8 /* VariableDeclarations */:
                    return isVariableDeclaratorListTerminator();
                case 17 /* TypeParameters */:
                    // Tokens other than '>' are here for better error recovery
                    return token === 27 /* GreaterThanToken */ || token === 17 /* OpenParenToken */ || token === 15 /* OpenBraceToken */ || token === 83 /* ExtendsKeyword */ || token === 106 /* ImplementsKeyword */;
                case 11 /* ArgumentExpressions */:
                    // Tokens other than ')' are here for better error recovery
                    return token === 18 /* CloseParenToken */ || token === 23 /* SemicolonToken */;
                case 15 /* ArrayLiteralMembers */:
                case 19 /* TupleElementTypes */:
                case 10 /* ArrayBindingElements */:
                    return token === 20 /* CloseBracketToken */;
                case 16 /* Parameters */:
                    // Tokens other than ')' and ']' (the latter for index signatures) are here for better error recovery
                    return token === 18 /* CloseParenToken */ || token === 20 /* CloseBracketToken */ /*|| token === SyntaxKind.OpenBraceToken*/;
                case 18 /* TypeArguments */:
                    // Tokens other than '>' are here for better error recovery
                    return token === 27 /* GreaterThanToken */ || token === 17 /* OpenParenToken */;
                case 20 /* HeritageClauses */:
                    return token === 15 /* OpenBraceToken */ || token === 16 /* CloseBraceToken */;
                case 13 /* JsxAttributes */:
                    return token === 27 /* GreaterThanToken */ || token === 39 /* SlashToken */;
                case 14 /* JsxChildren */:
                    return token === 25 /* LessThanToken */ && lookAhead(nextTokenIsSlash);
                case 22 /* JSDocFunctionParameters */:
                    return token === 18 /* CloseParenToken */ || token === 54 /* ColonToken */ || token === 16 /* CloseBraceToken */;
                case 23 /* JSDocTypeArguments */:
                    return token === 27 /* GreaterThanToken */ || token === 16 /* CloseBraceToken */;
                case 25 /* JSDocTupleTypes */:
                    return token === 20 /* CloseBracketToken */ || token === 16 /* CloseBraceToken */;
                case 24 /* JSDocRecordMembers */:
                    return token === 16 /* CloseBraceToken */;
            }
        }


function parseEntityName(allowReservedWords, diagnosticMessage) {
            var entity = parseIdentifier(diagnosticMessage);
            while (parseOptional(21 /* DotToken */)) {
                var node = createNode(135 /* QualifiedName */, entity.pos);
                node.left = entity;
                node.right = parseRightSideOfDot(allowReservedWords);
                entity = finishNode(node);
            }
            return entity;
        }

function
parseEntityName
(
allowReservedWords
,
diagnosticMessage
)
{
var
entity
=
parseIdentifier
(
diagnosticMessage
)
;
while
(
parseOptional
(
21
/* DotToken */
)
)
{
var
node
=
createNode
(
135
/* QualifiedName */
,
entity
.
pos
)
;
node
.
left
=
entity
;
node
.
right
=
parseRightSideOfDot
(
allowReservedWords
)
;
entity
=
finishNode
(
node
)
;
}
return
entity
;
}

The allowReservedWords parameter controls whether reserved words are permitted after the first dot


function findHighestListElementThatStartsAtPosition(position) {
                // Clear out any cached state about the last node we found.
                currentArray = undefined;
                currentArrayIndex = -1 /* Value */;
                current = undefined;
                // Recurse into the source file to find the highest node at this position.
                forEachChild(sourceFile, visitNode, visitArray);
                return;
                function visitNode(node) {
                    if (position >= node.pos && position < node.end) {
                        // Position was within this node.  Keep searching deeper to find the node.
                        forEachChild(node, visitNode, visitArray);
                        // don't procede any futher in the search.
                        return true;
                    }
                    // position wasn't in this node, have to keep searching.
                    return false;
                }
                function visitArray(array) {
                    if (position >= array.pos && position < array.end) {
                        // position was in this array.  Search through this array to see if we find a
                        // viable element.
                        for (var i = 0, n = array.length; i < n; i++) {
                            var child = array[i];
                            if (child) {
                                if (child.pos === position) {
                                    // Found the right node.  We're done.
                                    currentArray = array;
                                    currentArrayIndex = i;
                                    current = child;
                                    return true;
                                }
                                else {
                                    if (child.pos < position && position < child.end) {
                                        // Position in somewhere within this child.  Search in it and
                                        // stop searching in this array.
                                        forEachChild(child, visitNode, visitArray);
                                        return true;
                                    }
                                }
                            }
                        }
                    }
                    // position wasn't in this array, have to keep searching.
                    return false;
                }
            }

Finds the highest element in the tree we can find that starts at the provided position. The element must be a direct child of some node list in the tree.  This way after we return it, we can easily return its next sibling in the list.

Finds the highest element in the tree we can find that starts at the provided position . The element must be a direct child of some node list in the tree . This way after we return it we can easily return its next sibling in the list .


function getSymbolOfPartOfRightHandSideOfImportEquals(entityName, importDeclaration) {
            if (!importDeclaration) {
                importDeclaration = ts.getAncestor(entityName, 221 /* ImportEqualsDeclaration */);
                ts.Debug.assert(importDeclaration !== undefined);
            }
            // There are three things we might try to look for. In the following examples,
            // the search term is enclosed in |...|:
            //
            //     import a = |b|; // Namespace
            //     import a = |b.c|; // Value, type, namespace
            //     import a = |b.c|.d; // Namespace
            if (entityName.kind === 69 /* Identifier */ && ts.isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
                entityName = entityName.parent;
            }
            // Check for case 1 and 3 in the above example
            if (entityName.kind === 69 /* Identifier */ || entityName.parent.kind === 135 /* QualifiedName */) {
                return resolveEntityName(entityName, 1536 /* Namespace */);
            }
            else {
                // Case 2 in above example
                // entityName.kind could be a QualifiedName or a Missing identifier
                ts.Debug.assert(entityName.parent.kind === 221 /* ImportEqualsDeclaration */);
                return resolveEntityName(entityName, 107455 /* Value */ | 793056 /* Type */ | 1536 /* Namespace */);
            }
        }

This function is only for imports with entity names


function resolveEntityName(name, meaning, ignoreErrors) {
            if (ts.nodeIsMissing(name)) {
                return undefined;
            }
            var symbol;
            if (name.kind === 69 /* Identifier */) {
                var message = meaning === 1536 /* Namespace */ ? ts.Diagnostics.Cannot_find_namespace_0 : ts.Diagnostics.Cannot_find_name_0;
                symbol = resolveName(name, name.text, meaning, ignoreErrors ? undefined : message, name);
                if (!symbol) {
                    return undefined;
                }
            }
            else if (name.kind === 135 /* QualifiedName */ || name.kind === 166 /* PropertyAccessExpression */) {
                var left = name.kind === 135 /* QualifiedName */ ? name.left : name.expression;
                var right = name.kind === 135 /* QualifiedName */ ? name.right : name.name;
                var namespace = resolveEntityName(left, 1536 /* Namespace */, ignoreErrors);
                if (!namespace || namespace === unknownSymbol || ts.nodeIsMissing(right)) {
                    return undefined;
                }
                symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning);
                if (!symbol) {
                    if (!ignoreErrors) {
                        error(right, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(namespace), ts.declarationNameToString(right));
                    }
                    return undefined;
                }
            }
            else {
                ts.Debug.fail("Unknown entity name kind.");
            }
            ts.Debug.assert((symbol.flags & 16777216 /* Instantiated */) === 0, "Should never get an instantiated symbol here.");
            return symbol.flags & meaning ? symbol : resolveAlias(symbol);
        }

Resolves a qualified name and any involved aliases


function isReservedMemberName(name) {
            return name.charCodeAt(0) === 95 /* _ */ &&
                name.charCodeAt(1) === 95 /* _ */ &&
                name.charCodeAt(2) !== 95 /* _ */ &&
                name.charCodeAt(2) !== 64 /* at */;
        }

function
isReservedMemberName
(
name
)
{
return
name
.
charCodeAt
(
0
)
===
95
/* _ */
&&
name
.
charCodeAt
(
1
)
===
95
/* _ */
&&
name
.
charCodeAt
(
2
)
!==
95
/* _ */
&&
name
.
charCodeAt
(
2
)
!==
64
/* at */
;
}

A reserved member name starts with two underscores, but the third character cannot be an underscore or the @ symbol. A third underscore indicates an escaped form of an identifer that started with at least two underscores. The @ character indicates that the name is denoted by a well known ES Symbol instance.

A reserved member name starts with two underscores but the third character cannot be an underscore or the


function isSymbolUsedInExportAssignment(symbol) {
                    if (exportAssignmentSymbol === symbol) {
                        return true;
                    }
                    if (exportAssignmentSymbol && !!(exportAssignmentSymbol.flags & 8388608 /* Alias */)) {
                        // if export assigned symbol is alias declaration, resolve the alias
                        resolvedExportSymbol = resolvedExportSymbol || resolveAlias(exportAssignmentSymbol);
                        if (resolvedExportSymbol === symbol) {
                            return true;
                        }
                        // Container of resolvedExportSymbol is visible
                        return ts.forEach(resolvedExportSymbol.declarations, function (current) {
                            while (current) {
                                if (current === node) {
                                    return true;
                                }
                                current = current.parent;
                            }
                        });
                    }
                }

Check if the symbol is used in export assignment


function getTypeOfPropertyOfType(type, name) {
            var prop = getPropertyOfType(type, name);
            return prop ? getTypeOfSymbol(prop) : undefined;
        }

function getTypeOfPropertyOfType ( type , name ) { var prop = getPropertyOfType ( type , name ) ; return prop ? getTypeOfSymbol ( prop ) : undefined ; }

Return the type of the given property in the given type, or undefined if no such property exists

Return the type of the given property in the given type or undefined if no such property exists


function getTypeForBindingElementParent(node) {
            var symbol = getSymbolOfNode(node);
            return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node);
        }

function getTypeForBindingElementParent ( node ) { var symbol = getSymbolOfNode ( node ) ; return symbol && getSymbolLinks ( symbol ) . type || getTypeForVariableLikeDeclaration ( node ) ; }

Return the type of a binding element parent. We check SymbolLinks first to see if a type has been assigned by contextual typing.

Return the type of a binding element parent . We check SymbolLinks first to see if a type has been assigned by contextual typing .


function getTypeForBindingElement(declaration) {
            var pattern = declaration.parent;
            var parentType = getTypeForBindingElementParent(pattern.parent);
            // If parent has the unknown (error) type, then so does this binding element
            if (parentType === unknownType) {
                return unknownType;
            }
            // If no type was specified or inferred for parent, or if the specified or inferred type is any,
            // infer from the initializer of the binding element if one is present. Otherwise, go with the
            // undefined or any type of the parent.
            if (!parentType || isTypeAny(parentType)) {
                if (declaration.initializer) {
                    return checkExpressionCached(declaration.initializer);
                }
                return parentType;
            }
            var type;
            if (pattern.kind === 161 /* ObjectBindingPattern */) {
                // Use explicitly specified property name ({ p: xxx } form), or otherwise the implied name ({ p } form)
                var name_10 = declaration.propertyName || declaration.name;
                // Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature,
                // or otherwise the type of the string index signature.
                type = getTypeOfPropertyOfType(parentType, name_10.text) ||
                    isNumericLiteralName(name_10.text) && getIndexTypeOfType(parentType, 1 /* Number */) ||
                    getIndexTypeOfType(parentType, 0 /* String */);
                if (!type) {
                    error(name_10, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_10));
                    return unknownType;
                }
            }
            else {
                // 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(parentType, pattern, /*allowStringInput*/ false);
                if (!declaration.dotDotDotToken) {
                    // Use specific property type when parent is a tuple or numeric index type when parent is an array
                    var propName = "" + ts.indexOf(pattern.elements, declaration);
                    type = isTupleLikeType(parentType)
                        ? getTypeOfPropertyOfType(parentType, propName)
                        : elementType;
                    if (!type) {
                        if (isTupleType(parentType)) {
                            error(declaration, ts.Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, typeToString(parentType), parentType.elementTypes.length, pattern.elements.length);
                        }
                        else {
                            error(declaration, ts.Diagnostics.Type_0_has_no_property_1, typeToString(parentType), propName);
                        }
                        return unknownType;
                    }
                }
                else {
                    // Rest element has an array type with the same element type as the parent type
                    type = createArrayType(elementType);
                }
            }
            return type;
        }

Return the inferred type for a binding element


function getTypeForVariableLikeDeclaration(declaration) {
            // A variable declared in a for..in statement is always of type any
            if (declaration.parent.parent.kind === 200 /* ForInStatement */) {
                return anyType;
            }
            if (declaration.parent.parent.kind === 201 /* ForOfStatement */) {
                // checkRightHandSideOfForOf will return undefined if the for-of expression type was
                // missing properties/signatures required to get its iteratedType (like
                // [Symbol.iterator] or next). This may be because we accessed properties from anyType,
                // or it may have led to an error inside getElementTypeOfIterable.
                return checkRightHandSideOfForOf(declaration.parent.parent.expression) || anyType;
            }
            if (ts.isBindingPattern(declaration.parent)) {
                return getTypeForBindingElement(declaration);
            }
            // Use type from type annotation if one is present
            if (declaration.type) {
                return getTypeFromTypeNode(declaration.type);
            }
            if (declaration.kind === 138 /* Parameter */) {
                var func = declaration.parent;
                // For a parameter of a set accessor, use the type of the get accessor if one is present
                if (func.kind === 146 /* SetAccessor */ && !ts.hasDynamicName(func)) {
                    var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 145 /* GetAccessor */);
                    if (getter) {
                        return getReturnTypeOfSignature(getSignatureFromDeclaration(getter));
                    }
                }
                // Use contextual parameter type if one is available
                var type = getContextuallyTypedParameterType(declaration);
                if (type) {
                    return type;
                }
            }
            // Use the type of the initializer expression if one is present
            if (declaration.initializer) {
                return checkExpressionCached(declaration.initializer);
            }
            // If it is a short-hand property assignment, use the type of the identifier
            if (declaration.kind === 246 /* ShorthandPropertyAssignment */) {
                return checkIdentifier(declaration.name);
            }
            // If the declaration specifies a binding pattern, use the type implied by the binding pattern
            if (ts.isBindingPattern(declaration.name)) {
                return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ false);
            }
            // No type specified and nothing can be inferred
            return undefined;
        }

Return the inferred type for a variable, parameter, or property declaration

Return the inferred type for a variable parameter or property declaration


function getTypeFromBindingElement(element, includePatternInType) {
            if (element.initializer) {
                return getWidenedType(checkExpressionCached(element.initializer));
            }
            if (ts.isBindingPattern(element.name)) {
                return getTypeFromBindingPattern(element.name, includePatternInType);
            }
            return anyType;
        }

function getTypeFromBindingElement ( element , includePatternInType ) { if ( element . initializer ) { return getWidenedType ( checkExpressionCached ( element . initializer ) ) ; } if ( ts . isBindingPattern ( element . name ) ) { return getTypeFromBindingPattern ( element . name , includePatternInType ) ; } return anyType ; }

Return the type implied by a binding pattern element. This is the type of the initializer of the element if one is present. Otherwise, if the element is itself a binding pattern, it is the type implied by the binding pattern. Otherwise, it is the type any.

Return the type implied by a binding pattern element . This is the type of the initializer of the element if one is present . Otherwise if the element is itself a binding pattern it is the type implied by the binding pattern . Otherwise it is the type any .


function getTypeFromObjectBindingPattern(pattern, includePatternInType) {
            var members = {};
            ts.forEach(pattern.elements, function (e) {
                var flags = 4 /* Property */ | 67108864 /* Transient */ | (e.initializer ? 536870912 /* Optional */ : 0);
                var name = e.propertyName || e.name;
                var symbol = createSymbol(flags, name.text);
                symbol.type = getTypeFromBindingElement(e, includePatternInType);
                symbol.bindingElement = e;
                members[symbol.name] = symbol;
            });
            var result = createAnonymousType(undefined, members, emptyArray, emptyArray, undefined, undefined);
            if (includePatternInType) {
                result.pattern = pattern;
            }
            return result;
        }

function
getTypeFromObjectBindingPattern
(
pattern
,
includePatternInType
)
{
var
members
=
{
}
;
ts
.
forEach
(
pattern
.
elements
,
function
(
e
)
{
var
flags
=
4
/* Property */
|
67108864
/* Transient */
|
(
e
.
initializer
536870912
/* Optional */
:
0
)
;
var
name
=
e
.
propertyName
||
e
.
name
;
var
symbol
=
createSymbol
(
flags
,
name
.
text
)
;
symbol
.
type
=
getTypeFromBindingElement
(
e
,
includePatternInType
)
;
symbol
.
bindingElement
=
e
;
members
[
symbol
.
name
]
=
symbol
;
}
)
;
var
result
=
createAnonymousType
(
undefined
,
members
,
emptyArray
,
emptyArray
,
undefined
,
undefined
)
;
if
(
includePatternInType
)
{
result
.
pattern
=
pattern
;
}
return
result
;
}

Return the type implied by an object binding pattern


function getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol) {
            var result;
            for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) {
                var node = _a[_i];
                if (node.kind === 215 /* InterfaceDeclaration */ || node.kind === 214 /* ClassDeclaration */ ||
                    node.kind === 186 /* ClassExpression */ || node.kind === 216 /* TypeAliasDeclaration */) {
                    var declaration = node;
                    if (declaration.typeParameters) {
                        result = appendTypeParameters(result, declaration.typeParameters);
                    }
                }
            }
            return result;
        }

The local type parameters are the combined set of type parameters from all declarations of the class, interface, or type alias.

The local type parameters are the combined set of type parameters from all declarations of the class interface or type alias .


function getBaseConstructorTypeOfClass(type) {
            if (!type.resolvedBaseConstructorType) {
                var baseTypeNode = getBaseTypeNodeOfClass(type);
                if (!baseTypeNode) {
                    return type.resolvedBaseConstructorType = undefinedType;
                }
                if (!pushTypeResolution(type, 1 /* ResolvedBaseConstructorType */)) {
                    return unknownType;
                }
                var baseConstructorType = checkExpression(baseTypeNode.expression);
                if (baseConstructorType.flags & 80896 /* ObjectType */) {
                    // Resolving the members of a class requires us to resolve the base class of that class.
                    // We force resolution here such that we catch circularities now.
                    resolveStructuredTypeMembers(baseConstructorType);
                }
                if (!popTypeResolution()) {
                    error(type.symbol.valueDeclaration, ts.Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_base_expression, symbolToString(type.symbol));
                    return type.resolvedBaseConstructorType = unknownType;
                }
                if (baseConstructorType !== unknownType && baseConstructorType !== nullType && !isConstructorType(baseConstructorType)) {
                    error(baseTypeNode.expression, ts.Diagnostics.Type_0_is_not_a_constructor_function_type, typeToString(baseConstructorType));
                    return type.resolvedBaseConstructorType = unknownType;
                }
                type.resolvedBaseConstructorType = baseConstructorType;
            }
            return type.resolvedBaseConstructorType;
        }

The base constructor of a class can resolve to undefinedType if the class has no extends clause, unknownType if an error occurred during resolution of the extends expression, nullType if the extends expression is the null value, or an object type with at least one construct signature.

The base constructor of a class can resolve to undefinedType if the class has no extends clause unknownType if an error occurred during resolution of the extends expression nullType if the extends expression is the null value or an object type with at least one construct signature .


function isIndependentTypeReference(node) {
            if (node.typeArguments) {
                for (var _i = 0, _a = node.typeArguments; _i < _a.length; _i++) {
                    var typeNode = _a[_i];
                    if (!isIndependentType(typeNode)) {
                        return false;
                    }
                }
            }
            return true;
        }

function isIndependentTypeReference ( node ) { if ( node . typeArguments ) { for ( var _i = 0 , _a = node . typeArguments ; _i < _a . length ; _i ++ ) { var typeNode = _a [ _i ] ; if ( ! isIndependentType ( typeNode ) ) { return false ; } } } return true ; }

A type reference is considered independent if each type argument is considered independent.

A type reference is considered independent if each type argument is considered independent .


function createInstantiatedSymbolTable(symbols, mapper, mappingThisOnly) {
            var result = {};
            for (var _i = 0; _i < symbols.length; _i++) {
                var symbol = symbols[_i];
                result[symbol.name] = mappingThisOnly && isIndependentMember(symbol) ? symbol : instantiateSymbol(symbol, mapper);
            }
            return result;
        }

function createInstantiatedSymbolTable ( symbols , mapper , mappingThisOnly ) { var result = { } ; for ( var _i = 0 ; _i < symbols . length ; _i ++ ) { var symbol = symbols [ _i ] ; result [ symbol . name ] = mappingThisOnly && isIndependentMember ( symbol ) ? symbol : instantiateSymbol ( symbol , mapper ) ; } return result ; }

The mappingThisOnly flag indicates that the only type parameter being mapped is "this". When the flag is true, we check symbols to see if we can quickly conclude they are free of "this" references, thus needing no instantiation.

The mappingThisOnly flag indicates that the only type parameter being mapped is this . When the flag is true we check symbols to see if we can quickly conclude they are free of this references thus needing no instantiation .


function getUnionSignatures(types, kind) {
            var signatureLists = ts.map(types, function (t) { return getSignaturesOfType(t, kind); });
            var result = undefined;
            for (var i = 0; i < signatureLists.length; i++) {
                for (var _i = 0, _a = signatureLists[i]; _i < _a.length; _i++) {
                    var signature = _a[_i];
                    // Only process signatures with parameter lists that aren't already in the result list
                    if (!result || !findMatchingSignature(result, signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ true)) {
                        var unionSignatures = findMatchingSignatures(signatureLists, signature, i);
                        if (unionSignatures) {
                            var s = signature;
                            // Union the result types when more than one signature matches
                            if (unionSignatures.length > 1) {
                                s = cloneSignature(signature);
                                // Clear resolved return type we possibly got from cloneSignature
                                s.resolvedReturnType = undefined;
                                s.unionSignatures = unionSignatures;
                            }
                            (result || (result = [])).push(s);
                        }
                    }
                }
            }
            return result || emptyArray;
        }

The signatures of a union type are those signatures that are present in each of the constituent types. Generic signatures must match exactly, but non-generic signatures are allowed to have extra optional parameters and may differ in return types. When signatures differ in return types, the resulting return type is the union of the constituent return types.

The signatures of a union type are those signatures that are present in each of the constituent types . Generic signatures must match exactly but non - generic signatures are allowed to have extra optional parameters and may differ in return types . When signatures differ in return types the resulting return type is the union of the constituent return types .


function getPropertyOfObjectType(type, name) {
            if (type.flags & 80896 /* ObjectType */) {
                var resolved = resolveStructuredTypeMembers(type);
                if (ts.hasProperty(resolved.members, name)) {
                    var symbol = resolved.members[name];
                    if (symbolIsValue(symbol)) {
                        return symbol;
                    }
                }
            }
        }

function
getPropertyOfObjectType
(
type
,
name
)
{
if
(
type
.
flags
&
80896
/* ObjectType */
)
{
var
resolved
=
resolveStructuredTypeMembers
(
type
)
;
if
(
ts
.
hasProperty
(
resolved
.
members
,
name
)
)
{
var
symbol
=
resolved
.
members
[
name
]
;
if
(
symbolIsValue
(
symbol
)
)
{
return
symbol
;
}
}
}
}

If the given type is an object type and that type has a property by the given name, return the symbol for that property.Otherwise return undefined.

If the given type is an object type and that type has a property by the given name return the symbol for that property . Otherwise return undefined .


function getApparentType(type) {
            if (type.flags & 512 /* TypeParameter */) {
                do {
                    type = getConstraintOfTypeParameter(type);
                } while (type && type.flags & 512 /* TypeParameter */);
                if (!type) {
                    type = emptyObjectType;
                }
            }
            if (type.flags & 258 /* StringLike */) {
                type = globalStringType;
            }
            else if (type.flags & 132 /* NumberLike */) {
                type = globalNumberType;
            }
            else if (type.flags & 8 /* Boolean */) {
                type = globalBooleanType;
            }
            else if (type.flags & 16777216 /* ESSymbol */) {
                type = globalESSymbolType;
            }
            return type;
        }

function
getApparentType
(
type
)
{
if
(
type
.
flags
&
512
/* TypeParameter */
)
{
do
{
type
=
getConstraintOfTypeParameter
(
type
)
;
}
while
(
type
&&
type
.
flags
&
512
/* TypeParameter */
)
;
if
(
!
type
)
{
type
=
emptyObjectType
;
}
}
if
(
type
.
flags
&
258
/* StringLike */
)
{
type
=
globalStringType
;
}
else
if
(
type
.
flags
&
132
/* NumberLike */
)
{
type
=
globalNumberType
;
}
else
if
(
type
.
flags
&
8
/* Boolean */
)
{
type
=
globalBooleanType
;
}
else
if
(
type
.
flags
&
16777216
/* ESSymbol */
)
{
type
=
globalESSymbolType
;
}
return
type
;
}

For a type parameter, return the base constraint of the type parameter. For the string, number,
boolean, and symbol primitive types, return the corresponding object types. Otherwise return the
type itself. Note that the apparent type of a union type is the union type itself.

For a type parameter return the base constraint of the type parameter . For the string number boolean and symbol primitive types return the corresponding object types . Otherwise return the type itself . Note that the apparent type of a union type is the union type itself .


function getPropertyOfType(type, name) {
            type = getApparentType(type);
            if (type.flags & 80896 /* ObjectType */) {
                var resolved = resolveStructuredTypeMembers(type);
                if (ts.hasProperty(resolved.members, name)) {
                    var symbol = resolved.members[name];
                    if (symbolIsValue(symbol)) {
                        return symbol;
                    }
                }
                if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) {
                    var symbol = getPropertyOfObjectType(globalFunctionType, name);
                    if (symbol) {
                        return symbol;
                    }
                }
                return getPropertyOfObjectType(globalObjectType, name);
            }
            if (type.flags & 49152 /* UnionOrIntersection */) {
                return getPropertyOfUnionOrIntersectionType(type, name);
            }
            return undefined;
        }

function
getPropertyOfType
(
type
,
name
)
{
type
=
getApparentType
(
type
)
;
if
(
type
.
flags
&
80896
/* ObjectType */
)
{
var
resolved
=
resolveStructuredTypeMembers
(
type
)
;
if
(
ts
.
hasProperty
(
resolved
.
members
,
name
)
)
{
var
symbol
=
resolved
.
members
[
name
]
;
if
(
symbolIsValue
(
symbol
)
)
{
return
symbol
;
}
}
if
(
resolved
===
anyFunctionType
||
resolved
.
callSignatures
.
length
||
resolved
.
constructSignatures
.
length
)
{
var
symbol
=
getPropertyOfObjectType
(
globalFunctionType
,
name
)
;
if
(
symbol
)
{
return
symbol
;
}
}
return
getPropertyOfObjectType
(
globalObjectType
,
name
)
;
}
if
(
type
.
flags
&
49152
/* UnionOrIntersection */
)
{
return
getPropertyOfUnionOrIntersectionType
(
type
,
name
)
;
}
return
undefined
;
}

Return the symbol for the property with the given name in the given type. Creates synthetic union properties when necessary, maps primitive types and type parameters are to their apparent types, and augments with properties from Object and Function as appropriate.

Return the symbol for the property with the given name in the given type . Creates synthetic union properties when necessary maps primitive types and type parameters are to their apparent types and augments with properties from Object and Function as appropriate .


function getPropagatingFlagsOfTypes(types) {
            var result = 0;
            for (var _i = 0; _i < types.length; _i++) {
                var type = types[_i];
                result |= type.flags;
            }
            return result & 14680064 /* PropagatingFlags */;
        }

function
getPropagatingFlagsOfTypes
(
types
)
{
var
result
=
0
;
for
(
var
_i
=
0
;
_i
<
types
.
length
;
_i
++
)
{
var
type
=
types
[
_i
]
;
result
|=
type
.
flags
;
}
return
result
&
14680064
/* PropagatingFlags */
;
}

This function is used to propagate certain flags when creating new object type references and union types. It is only necessary to do so if a constituent type might be the undefined type, the null type, the type of an object literal or the anyFunctionType. This is because there are operations in the type checker that care about the presence of such types at arbitrary depth in a containing type.

This function is used to propagate certain flags when creating new object type references and union types . It is only necessary to do so if a constituent type might be the undefined type the null type the type of an object literal or the anyFunctionType . This is because there are operations in the type checker that care about the presence of such types at arbitrary depth in a containing type .


function getTypeFromClassOrInterfaceReference(node, symbol) {
            var type = getDeclaredTypeOfSymbol(symbol);
            var typeParameters = type.localTypeParameters;
            if (typeParameters) {
                if (!node.typeArguments || node.typeArguments.length !== typeParameters.length) {
                    error(node, ts.Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, /*enclosingDeclaration*/ undefined, 1 /* WriteArrayAsGenericType */), typeParameters.length);
                    return unknownType;
                }
                // In a type reference, the outer type parameters of the referenced class or interface are automatically
                // supplied as type arguments and the type reference only specifies arguments for the local type parameters
                // of the class or interface.
                return createTypeReference(type, ts.concatenate(type.outerTypeParameters, ts.map(node.typeArguments, getTypeFromTypeNode)));
            }
            if (node.typeArguments) {
                error(node, ts.Diagnostics.Type_0_is_not_generic, typeToString(type));
                return unknownType;
            }
            return type;
        }

Get type from reference to class or interface


function getTypeFromTypeAliasReference(node, symbol) {
            var type = getDeclaredTypeOfSymbol(symbol);
            var links = getSymbolLinks(symbol);
            var typeParameters = links.typeParameters;
            if (typeParameters) {
                if (!node.typeArguments || node.typeArguments.length !== typeParameters.length) {
                    error(node, ts.Diagnostics.Generic_type_0_requires_1_type_argument_s, symbolToString(symbol), typeParameters.length);
                    return unknownType;
                }
                var typeArguments = ts.map(node.typeArguments, getTypeFromTypeNode);
                var id = getTypeListId(typeArguments);
                return links.instantiations[id] || (links.instantiations[id] = instantiateType(type, createTypeMapper(typeParameters, typeArguments)));
            }
            if (node.typeArguments) {
                error(node, ts.Diagnostics.Type_0_is_not_generic, symbolToString(symbol));
                return unknownType;
            }
            return type;
        }

Get type from reference to type alias. When a type alias is generic, the declared type of the type alias may include references to the type parameters of the alias. We replace those with the actual type arguments by instantiating the declared type. Instantiations are cached using the type identities of the type arguments as the key.

Get type from reference to type alias . When a type alias is generic the declared type of the type alias may include references to the type parameters of the alias . We replace those with the actual type arguments by instantiating the declared type . Instantiations are cached using the type identities of the type arguments as the key .


function addTypesToSet(typeSet, types, typeSetKind) {
            for (var _i = 0; _i < types.length; _i++) {
                var type = types[_i];
                addTypeToSet(typeSet, type, typeSetKind);
            }
        }

function addTypesToSet ( typeSet , types , typeSetKind ) { for ( var _i = 0 ; _i < types . length ; _i ++ ) { var type = types [ _i ] ; addTypeToSet ( typeSet , type , typeSetKind ) ; } }

Add the given types to the given type set. Order is preserved, duplicates are removed, and nested types of the given kind are flattened into the set.

Add the given types to the given type set . Order is preserved duplicates are removed and nested types of the given kind are flattened into the set .


function isKnownProperty(type, name) {
                if (type.flags & 80896 /* ObjectType */) {
                    var resolved = resolveStructuredTypeMembers(type);
                    if (relation === assignableRelation && (type === globalObjectType || resolved.properties.length === 0) ||
                        resolved.stringIndexType || resolved.numberIndexType || getPropertyOfType(type, name)) {
                        return true;
                    }
                    return false;
                }
                if (type.flags & 49152 /* UnionOrIntersection */) {
                    for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
                        var t = _a[_i];
                        if (isKnownProperty(t, name)) {
                            return true;
                        }
                    }
                    return false;
                }
                return true;
            }

function
isKnownProperty
(
type
,
name
)
{
if
(
type
.
flags
&
80896
/* ObjectType */
)
{
var
resolved
=
resolveStructuredTypeMembers
(
type
)
;
if
(
relation
===
assignableRelation
&&
(
type
===
globalObjectType
||
resolved
.
properties
.
length
===
0
)
||
resolved
.
stringIndexType
||
resolved
.
numberIndexType
||
getPropertyOfType
(
type
,
name
)
)
{
return
true
;
}
return
false
;
}
if
(
type
.
flags
&
49152
/* UnionOrIntersection */
)
{
for
(
var
_i
=
0
,
_a
=
type
.
types
;
_i
<
_a
.
length
;
_i
++
)
{
var
t
=
_a
[
_i
]
;
if
(
isKnownProperty
(
t
,
name
)
)
{
return
true
;
}
}
return
false
;
}
return
true
;
}

Check if a property with the given name is known anywhere in the given type. In an object type, a property is considered known if the object type is empty and the check is for assignability, if the object type has index signatures, or if the property is actually declared in the object type. In a union or intersection type, a property is considered known if it is known in any constituent type.

Check if a property with the given name is known anywhere in the given type . In an object type a property is considered known if the object type is empty and the check is for assignability if the object type has index signatures or if the property is actually declared in the object type . In a union or intersection type a property is considered known if it is known in any constituent type .


function objectTypeRelatedTo(source, target, reportErrors) {
                if (overflow) {
                    return 0 /* False */;
                }
                var id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id;
                var related = relation[id];
                if (related !== undefined) {
                    // If we computed this relation already and it was failed and reported, or if we're not being asked to elaborate
                    // errors, we can use the cached value. Otherwise, recompute the relation
                    if (!elaborateErrors || (related === 3 /* FailedAndReported */)) {
                        return related === 1 /* Succeeded */ ? -1 /* True */ : 0 /* False */;
                    }
                }
                if (depth > 0) {
                    for (var i = 0; i < depth; i++) {
                        // If source and target are already being compared, consider them related with assumptions
                        if (maybeStack[i][id]) {
                            return 1 /* Maybe */;
                        }
                    }
                    if (depth === 100) {
                        overflow = true;
                        return 0 /* False */;
                    }
                }
                else {
                    sourceStack = [];
                    targetStack = [];
                    maybeStack = [];
                    expandingFlags = 0;
                }
                sourceStack[depth] = source;
                targetStack[depth] = target;
                maybeStack[depth] = {};
                maybeStack[depth][id] = 1 /* Succeeded */;
                depth++;
                var saveExpandingFlags = expandingFlags;
                if (!(expandingFlags & 1) && isDeeplyNestedGeneric(source, sourceStack, depth))
                    expandingFlags |= 1;
                if (!(expandingFlags & 2) && isDeeplyNestedGeneric(target, targetStack, depth))
                    expandingFlags |= 2;
                var result;
                if (expandingFlags === 3) {
                    result = 1 /* Maybe */;
                }
                else {
                    result = propertiesRelatedTo(source, target, reportErrors);
                    if (result) {
                        result &= signaturesRelatedTo(source, target, 0 /* Call */, reportErrors);
                        if (result) {
                            result &= signaturesRelatedTo(source, target, 1 /* Construct */, reportErrors);
                            if (result) {
                                result &= stringIndexTypesRelatedTo(source, target, reportErrors);
                                if (result) {
                                    result &= numberIndexTypesRelatedTo(source, target, reportErrors);
                                }
                            }
                        }
                    }
                }
                expandingFlags = saveExpandingFlags;
                depth--;
                if (result) {
                    var maybeCache = maybeStack[depth];
                    // If result is definitely true, copy assumptions to global cache, else copy to next level up
                    var destinationCache = (result === -1 /* True */ || depth === 0) ? relation : maybeStack[depth - 1];
                    ts.copyMap(maybeCache, destinationCache);
                }
                else {
                    // A false result goes straight into global cache (when something is false under assumptions it
                    // will also be false without assumptions)
                    relation[id] = reportErrors ? 3 /* FailedAndReported */ : 2 /* Failed */;
                }
                return result;
            }

Determine if two object types are related by structure. First, check if the result is already available in the global cache. Second, check if we have already started a comparison of the given two types in which case we assume the result to be true. Third, check if both types are part of deeply nested chains of generic type instantiations and if so assume the types are equal and infinitely expanding. Fourth, if we have reached a depth of 100 nested comparisons, assume we have runaway recursion and issue an error. Otherwise, actually compare the structure of the two types.

Determine if two object types are related by structure . First check if the result is already available in the global cache . Second check if we have already started a comparison of the given two types in which case we assume the result to be true . Third check if both types are part of deeply nested chains of generic type instantiations and if so assume the types are equal and infinitely expanding . Fourth if we have reached a depth of 100 nested comparisons assume we have runaway recursion and issue an error . Otherwise actually compare the structure of the two types .


function isDeeplyNestedGeneric(type, stack, depth) {
            // We track type references (created by createTypeReference) and instantiated types (created by instantiateType)
            if (type.flags & (4096 /* Reference */ | 131072 /* Instantiated */) && depth >= 5) {
                var symbol = type.symbol;
                var count = 0;
                for (var i = 0; i < depth; i++) {
                    var t = stack[i];
                    if (t.flags & (4096 /* Reference */ | 131072 /* Instantiated */) && t.symbol === symbol) {
                        count++;
                        if (count >= 5)
                            return true;
                    }
                }
            }
            return false;
        }

Return true if the given type is part of a deeply nested chain of generic instantiations. We consider this to be the case when structural type comparisons have been started for 10 or more instantiations of the same generic type. It is possible, though highly unlikely, for this test to be true in a situation where a chain of instantiations is not infinitely expanding. Effectively, we will generate a false positive when two types are structurally equal to at least 10 levels, but unequal at some level beyond that.

Return true if the given type is part of a deeply nested chain of generic instantiations . We consider this to be the case when structural type comparisons have been started for 10 or more instantiations of the same generic type . It is possible though highly unlikely for this test to be true in a situation where a chain of instantiations is not infinitely expanding . Effectively we will generate a false positive when two types are structurally equal to at least 10 levels but unequal at some level beyond that .


function isVariableAssignedWithin(symbol, node) {
            var links = getNodeLinks(node);
            if (links.assignmentChecks) {
                var cachedResult = links.assignmentChecks[symbol.id];
                if (cachedResult !== undefined) {
                    return cachedResult;
                }
            }
            else {
                links.assignmentChecks = {};
            }
            return links.assignmentChecks[symbol.id] = isAssignedIn(node);
            function isAssignedInBinaryExpression(node) {
                if (node.operatorToken.kind >= 56 /* FirstAssignment */ && node.operatorToken.kind <= 68 /* LastAssignment */) {
                    var n = node.left;
                    while (n.kind === 172 /* ParenthesizedExpression */) {
                        n = n.expression;
                    }
                    if (n.kind === 69 /* Identifier */ && getResolvedSymbol(n) === symbol) {
                        return true;
                    }
                }
                return ts.forEachChild(node, isAssignedIn);
            }
            function isAssignedInVariableDeclaration(node) {
                if (!ts.isBindingPattern(node.name) && getSymbolOfNode(node) === symbol && hasInitializer(node)) {
                    return true;
                }
                return ts.forEachChild(node, isAssignedIn);
            }
            function isAssignedIn(node) {
                switch (node.kind) {
                    case 181 /* BinaryExpression */:
                        return isAssignedInBinaryExpression(node);
                    case 211 /* VariableDeclaration */:
                    case 163 /* BindingElement */:
                        return isAssignedInVariableDeclaration(node);
                    case 161 /* ObjectBindingPattern */:
                    case 162 /* ArrayBindingPattern */:
                    case 164 /* ArrayLiteralExpression */:
                    case 165 /* ObjectLiteralExpression */:
                    case 166 /* PropertyAccessExpression */:
                    case 167 /* ElementAccessExpression */:
                    case 168 /* CallExpression */:
                    case 169 /* NewExpression */:
                    case 171 /* TypeAssertionExpression */:
                    case 189 /* AsExpression */:
                    case 172 /* ParenthesizedExpression */:
                    case 179 /* PrefixUnaryExpression */:
                    case 175 /* DeleteExpression */:
                    case 178 /* AwaitExpression */:
                    case 176 /* TypeOfExpression */:
                    case 177 /* VoidExpression */:
                    case 180 /* PostfixUnaryExpression */:
                    case 184 /* YieldExpression */:
                    case 182 /* ConditionalExpression */:
                    case 185 /* SpreadElementExpression */:
                    case 192 /* Block */:
                    case 193 /* VariableStatement */:
                    case 195 /* ExpressionStatement */:
                    case 196 /* IfStatement */:
                    case 197 /* DoStatement */:
                    case 198 /* WhileStatement */:
                    case 199 /* ForStatement */:
                    case 200 /* ForInStatement */:
                    case 201 /* ForOfStatement */:
                    case 204 /* ReturnStatement */:
                    case 205 /* WithStatement */:
                    case 206 /* SwitchStatement */:
                    case 241 /* CaseClause */:
                    case 242 /* DefaultClause */:
                    case 207 /* LabeledStatement */:
                    case 208 /* ThrowStatement */:
                    case 209 /* TryStatement */:
                    case 244 /* CatchClause */:
                    case 233 /* JsxElement */:
                    case 234 /* JsxSelfClosingElement */:
                    case 238 /* JsxAttribute */:
                    case 239 /* JsxSpreadAttribute */:
                    case 235 /* JsxOpeningElement */:
                    case 240 /* JsxExpression */:
                        return ts.forEachChild(node, isAssignedIn);
                }
                return false;
            }
        }

function
isVariableAssignedWithin
(
symbol
,
node
)
{
var
links
=
getNodeLinks
(
node
)
;
if
(
links
.
assignmentChecks
)
{
var
cachedResult
=
links
.
assignmentChecks
[
symbol
.
id
]
;
if
(
cachedResult
!==
undefined
)
{
return
cachedResult
;
}
}
else
{
links
.
assignmentChecks
=
{
}
;
}
return
links
.
assignmentChecks
[
symbol
.
id
]
=
isAssignedIn
(
node
)
;
function
isAssignedInBinaryExpression
(
node
)
{
if
(
node
.
operatorToken
.
kind
>=
56
/* FirstAssignment */
&&
node
.
operatorToken
.
kind
<=
68
/* LastAssignment */
)
{
var
n
=
node
.
left
;
while
(
n
.
kind
===
172
/* ParenthesizedExpression */
)
{
n
=
n
.
expression
;
}
if
(
n
.
kind
===
69
/* Identifier */
&&
getResolvedSymbol
(
n
)
===
symbol
)
{
return
true
;
}
}
return
ts
.
forEachChild
(
node
,
isAssignedIn
)
;
}
function
isAssignedInVariableDeclaration
(
node
)
{
if
(
!
ts
.
isBindingPattern
(
node
.
name
)
&&
getSymbolOfNode
(
node
)
===
symbol
&&
hasInitializer
(
node
)
)
{
return
true
;
}
return
ts
.
forEachChild
(
node
,
isAssignedIn
)
;
}
function
isAssignedIn
(
node
)
{
switch
(
node
.
kind
)
{
case
181
/* BinaryExpression */
:
return
isAssignedInBinaryExpression
(
node
)
;
case
211
/* VariableDeclaration */
:
case
163
/* BindingElement */
:
return
isAssignedInVariableDeclaration
(
node
)
;
case
161
/* ObjectBindingPattern */
:
case
162
/* ArrayBindingPattern */
:
case
164
/* ArrayLiteralExpression */
:
case
165
/* ObjectLiteralExpression */
:
case
166
/* PropertyAccessExpression */
:
case
167
/* ElementAccessExpression */
:
case
168
/* CallExpression */
:
case
169
/* NewExpression */
:
case
171
/* TypeAssertionExpression */
:
case
189
/* AsExpression */
:
case
172
/* ParenthesizedExpression */
:
case
179
/* PrefixUnaryExpression */
:
case
175
/* DeleteExpression */
:
case
178
/* AwaitExpression */
:
case
176
/* TypeOfExpression */
:
case
177
/* VoidExpression */
:
case
180
/* PostfixUnaryExpression */
:
case
184
/* YieldExpression */
:
case
182
/* ConditionalExpression */
:
case
185
/* SpreadElementExpression */
:
case
192
/* Block */
:
case
193
/* VariableStatement */
:
case
195
/* ExpressionStatement */
:
case
196
/* IfStatement */
:
case
197
/* DoStatement */
:
case
198
/* WhileStatement */
:
case
199
/* ForStatement */
:
case
200
/* ForInStatement */
:
case
201
/* ForOfStatement */
:
case
204
/* ReturnStatement */
:
case
205
/* WithStatement */
:
case
206
/* SwitchStatement */
:
case
241
/* CaseClause */
:
case
242
/* DefaultClause */
:
case
207
/* LabeledStatement */
:
case
208
/* ThrowStatement */
:
case
209
/* TryStatement */
:
case
244
/* CatchClause */
:
case
233
/* JsxElement */
:
case
234
/* JsxSelfClosingElement */
:
case
238
/* JsxAttribute */
:
case
239
/* JsxSpreadAttribute */
:
case
235
/* JsxOpeningElement */
:
case
240
/* JsxExpression */
:
return
ts
.
forEachChild
(
node
,
isAssignedIn
)
;
}
return
false
;
}
}

Check if a given variable is assigned within a given syntax node


function narrowType(type, expr, assumeTrue) {
                switch (expr.kind) {
                    case 168 /* CallExpression */:
                        return narrowTypeByTypePredicate(type, expr, assumeTrue);
                    case 172 /* ParenthesizedExpression */:
                        return narrowType(type, expr.expression, assumeTrue);
                    case 181 /* BinaryExpression */:
                        var operator = expr.operatorToken.kind;
                        if (operator === 32 /* EqualsEqualsEqualsToken */ || operator === 33 /* ExclamationEqualsEqualsToken */) {
                            return narrowTypeByEquality(type, expr, assumeTrue);
                        }
                        else if (operator === 51 /* AmpersandAmpersandToken */) {
                            return narrowTypeByAnd(type, expr, assumeTrue);
                        }
                        else if (operator === 52 /* BarBarToken */) {
                            return narrowTypeByOr(type, expr, assumeTrue);
                        }
                        else if (operator === 91 /* InstanceOfKeyword */) {
                            return narrowTypeByInstanceof(type, expr, assumeTrue);
                        }
                        break;
                    case 179 /* PrefixUnaryExpression */:
                        if (expr.operator === 49 /* ExclamationToken */) {
                            return narrowType(type, expr.operand, !assumeTrue);
                        }
                        break;
                }
                return type;
            }

function
narrowType
(
type
,
expr
,
assumeTrue
)
{
switch
(
expr
.
kind
)
{
case
168
/* CallExpression */
:
return
narrowTypeByTypePredicate
(
type
,
expr
,
assumeTrue
)
;
case
172
/* ParenthesizedExpression */
:
return
narrowType
(
type
,
expr
.
expression
,
assumeTrue
)
;
case
181
/* BinaryExpression */
:
var
operator
=
expr
.
operatorToken
.
kind
;
if
(
operator
===
32
/* EqualsEqualsEqualsToken */
||
operator
===
33
/* ExclamationEqualsEqualsToken */
)
{
return
narrowTypeByEquality
(
type
,
expr
,
assumeTrue
)
;
}
else
if
(
operator
===
51
/* AmpersandAmpersandToken */
)
{
return
narrowTypeByAnd
(
type
,
expr
,
assumeTrue
)
;
}
else
if
(
operator
===
52
/* BarBarToken */
)
{
return
narrowTypeByOr
(
type
,
expr
,
assumeTrue
)
;
}
else
if
(
operator
===
91
/* InstanceOfKeyword */
)
{
return
narrowTypeByInstanceof
(
type
,
expr
,
assumeTrue
)
;
}
break
;
case
179
/* PrefixUnaryExpression */
:
if
(
expr
.
operator
===
49
/* ExclamationToken */
)
{
return
narrowType
(
type
,
expr
.
operand
,
!
assumeTrue
)
;
}
break
;
}
return
type
;
}

Narrow the given type based on the given expression having the assumed boolean value. The returned type will be a subtype or the same type as the argument.

Narrow the given type based on the given expression having the assumed boolean value . The returned type will be a subtype or the same type as the argument .


function getContextuallyTypedParameterType(parameter) {
            var func = parameter.parent;
            if (isFunctionExpressionOrArrowFunction(func) || ts.isObjectLiteralMethod(func)) {
                if (isContextSensitive(func)) {
                    var contextualSignature = getContextualSignature(func);
                    if (contextualSignature) {
                        var funcHasRestParameters = ts.hasRestParameter(func);
                        var len = func.parameters.length - (funcHasRestParameters ? 1 : 0);
                        var indexOfParameter = ts.indexOf(func.parameters, parameter);
                        if (indexOfParameter < len) {
                            return getTypeAtPosition(contextualSignature, indexOfParameter);
                        }
                        // If last parameter is contextually rest parameter get its type
                        if (funcHasRestParameters &&
                            indexOfParameter === (func.parameters.length - 1) &&
                            isRestParameterIndex(contextualSignature, func.parameters.length - 1)) {
                            return getTypeOfSymbol(ts.lastOrUndefined(contextualSignature.parameters));
                        }
                    }
                }
            }
            return undefined;
        }

Return contextual type of parameter or undefined if no contextual type is available


function getContextualTypeForInitializerExpression(node) {
            var declaration = node.parent;
            if (node === declaration.initializer) {
                if (declaration.type) {
                    return getTypeFromTypeNode(declaration.type);
                }
                if (declaration.kind === 138 /* Parameter */) {
                    var type = getContextuallyTypedParameterType(declaration);
                    if (type) {
                        return type;
                    }
                }
                if (ts.isBindingPattern(declaration.name)) {
                    return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ true);
                }
            }
            return undefined;
        }

In a variable, parameter or property declaration with a type annotation, the contextual type of an initializer expression is the type of the variable, parameter or property. Otherwise, in a parameter declaration of a contextually typed function expression, the contextual type of an initializer expression is the contextual type of the parameter. Otherwise, in a variable or parameter declaration with a binding pattern name, the contextual type of an initializer expression is the type implied by the binding pattern.

In a variable parameter or property declaration with a type annotation the contextual type of an initializer expression is the type of the variable parameter or property . Otherwise in a parameter declaration of a contextually typed function expression the contextual type of an initializer expression is the contextual type of the parameter . Otherwise in a variable or parameter declaration with a binding pattern name the contextual type of an initializer expression is the type implied by the binding pattern .


function applyToContextualType(type, mapper) {
            if (!(type.flags & 16384 /* Union */)) {
                return mapper(type);
            }
            var types = type.types;
            var mappedType;
            var mappedTypes;
            for (var _i = 0; _i < types.length; _i++) {
                var current = types[_i];
                var t = mapper(current);
                if (t) {
                    if (!mappedType) {
                        mappedType = t;
                    }
                    else if (!mappedTypes) {
                        mappedTypes = [mappedType, t];
                    }
                    else {
                        mappedTypes.push(t);
                    }
                }
            }
            return mappedTypes ? getUnionType(mappedTypes) : mappedType;
        }

function
applyToContextualType
(
type
,
mapper
)
{
if
(
!
(
type
.
flags
&
16384
/* Union */
)
)
{
return
mapper
(
type
)
;
}
var
types
=
type
.
types
;
var
mappedType
;
var
mappedTypes
;
for
(
var
_i
=
0
;
_i
<
types
.
length
;
_i
++
)
{
var
current
=
types
[
_i
]
;
var
t
=
mapper
(
current
)
;
if
(
t
)
{
if
(
!
mappedType
)
{
mappedType
=
t
;
}
else
if
(
!
mappedTypes
)
{
mappedTypes
=
[
mappedType
,
t
]
;
}
else
{
mappedTypes
.
push
(
t
)
;
}
}
}
return
mappedTypes
getUnionType
(
mappedTypes
)
:
mappedType
;
}

Apply a mapping function to a contextual type and return the resulting type. If the contextual type is a union type, the mapping function is applied to each constituent type and a union of the resulting types is returned.

Apply a mapping function to a contextual type and return the resulting type . If the contextual type is a union type the mapping function is applied to each constituent type and a union of the resulting types is returned .


function contextualTypeHasIndexSignature(type, kind) {
            return !!(type.flags & 16384 /* Union */ ? ts.forEach(type.types, function (t) { return getIndexTypeOfStructuredType(t, kind); }) : getIndexTypeOfStructuredType(type, kind));
        }

function
contextualTypeHasIndexSignature
(
type
,
kind
)
{
return
!
!
(
type
.
flags
&
16384
/* Union */
ts
.
forEach
(
type
.
types
,
function
(
t
)
{
return
getIndexTypeOfStructuredType
(
t
,
kind
)
;
}
)
:
getIndexTypeOfStructuredType
(
type
,
kind
)
)
;
}

Return true if the given contextual type provides an index signature of the given kind


function getContextualTypeForObjectLiteralMethod(node) {
            ts.Debug.assert(ts.isObjectLiteralMethod(node));
            if (isInsideWithStatementBody(node)) {
                // We cannot answer semantic questions within a with block, do not proceed any further
                return undefined;
            }
            return getContextualTypeForObjectLiteralElement(node);
        }

In an object literal contextually typed by a type T, the contextual type of a property assignment is the type of the matching property in T, if one exists. Otherwise, it is the type of the numeric index signature in T, if one exists. Otherwise, it is the type of the string index signature in T, if one exists.

In an object literal contextually typed by a type T the contextual type of a property assignment is the type of the matching property in T if one exists . Otherwise it is the type of the numeric index signature in T if one exists . Otherwise it is the type of the string index signature in T if one exists .


function getContextualTypeForElementExpression(node) {
            var arrayLiteral = node.parent;
            var type = getContextualType(arrayLiteral);
            if (type) {
                var index = ts.indexOf(arrayLiteral.elements, node);
                return getTypeOfPropertyOfContextualType(type, "" + index)
                    || getIndexTypeOfContextualType(type, 1 /* Number */)
                    || (languageVersion >= 2 /* ES6 */ ? getElementTypeOfIterable(type, /*errorNode*/ undefined) : undefined);
            }
            return undefined;
        }

function
getContextualTypeForElementExpression
(
node
)
{
var
arrayLiteral
=
node
.
parent
;
var
type
=
getContextualType
(
arrayLiteral
)
;
if
(
type
)
{
var
index
=
ts
.
indexOf
(
arrayLiteral
.
elements
,
node
)
;
return
getTypeOfPropertyOfContextualType
(
type
,
""
+
index
)
||
getIndexTypeOfContextualType
(
type
,
1
/* Number */
)
||
(
languageVersion
>=
2
/* ES6 */
getElementTypeOfIterable
(
type
,
/*errorNode*/
undefined
)
:
undefined
)
;
}
return
undefined
;
}

In an array literal contextually typed by a type T, the contextual type of an element expression at index N is the type of the property with the numeric name N in T, if one exists. Otherwise, if T has a numeric index signature, it is the type of the numeric index signature in T. Otherwise, in ES6 and higher, the contextual type is the iterated type of T.

In an array literal contextually typed by a type T the contextual type of an element expression at index N is the type of the property with the numeric name N in T if one exists . Otherwise if T has a numeric index signature it is the type of the numeric index signature in T . Otherwise in ES6 and higher the contextual type is the iterated type of T .


function getNonGenericSignature(type) {
            var signatures = getSignaturesOfStructuredType(type, 0 /* Call */);
            if (signatures.length === 1) {
                var signature = signatures[0];
                if (!signature.typeParameters) {
                    return signature;
                }
            }
        }

function
getNonGenericSignature
(
type
)
{
var
signatures
=
getSignaturesOfStructuredType
(
type
,
0
/* Call */
)
;
if
(
signatures
.
length
===
1
)
{
var
signature
=
signatures
[
0
]
;
if
(
!
signature
.
typeParameters
)
{
return
signature
;
}
}
}

If the given type is an object or union type, if that type has a single signature, and if that signature is non-generic, return the signature. Otherwise return undefined.

If the given type is an object or union type if that type has a single signature and if that signature is non - generic return the signature . Otherwise return undefined .


function getContextualSignature(node) {
            ts.Debug.assert(node.kind !== 143 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node));
            var type = ts.isObjectLiteralMethod(node)
                ? getContextualTypeForObjectLiteralMethod(node)
                : getContextualType(node);
            if (!type) {
                return undefined;
            }
            if (!(type.flags & 16384 /* Union */)) {
                return getNonGenericSignature(type);
            }
            var signatureList;
            var types = type.types;
            for (var _i = 0; _i < types.length; _i++) {
                var current = types[_i];
                var signature = getNonGenericSignature(current);
                if (signature) {
                    if (!signatureList) {
                        // This signature will contribute to contextual union signature
                        signatureList = [signature];
                    }
                    else if (!compareSignatures(signatureList[0], signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ true, compareTypes)) {
                        // Signatures aren't identical, do not use
                        return undefined;
                    }
                    else {
                        // Use this signature for contextual union signature
                        signatureList.push(signature);
                    }
                }
            }
            // Result is union of signatures collected (return type is union of return types of this signature set)
            var result;
            if (signatureList) {
                result = cloneSignature(signatureList[0]);
                // Clear resolved return type we possibly got from cloneSignature
                result.resolvedReturnType = undefined;
                result.unionSignatures = signatureList;
            }
            return result;
        }

Return the contextual signature for a given expression node. A contextual type provides a contextual signature if it has a single call signature and if that call signature is non-generic. If the contextual type is a union type, get the signature from each type possible and if they are all identical ignoring their return type, the result is same signature but with return type as union type of return types from these signatures

Return the contextual signature for a given expression node . A contextual type provides a contextual signature if it has a single call signature and if that call signature is non - generic . If the contextual type is a union type get the signature from each type possible and if they are all identical ignoring their return type the result is same signature but with return type as union type of return types from these signatures


function getJsxAttributePropertySymbol(attrib) {
            var attributesType = getJsxElementAttributesType(attrib.parent);
            var prop = getPropertyOfType(attributesType, attrib.name.text);
            return prop || unknownSymbol;
        }

function getJsxAttributePropertySymbol ( attrib ) { var attributesType = getJsxElementAttributesType ( attrib . parent ) ; var prop = getPropertyOfType ( attributesType , attrib . name . text ) ; return prop || unknownSymbol ; }

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.

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 .


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 & 256 /* 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 & (32 /* Private */ | 64 /* 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 & 32 /* 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 & 128 /* 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.

Check whether the requested property access is valid . Returns true if node is a valid property access and false otherwise .


function getPropertyNameForIndexedAccess(indexArgumentExpression, indexArgumentType) {
            if (indexArgumentExpression.kind === 9 /* StringLiteral */ || indexArgumentExpression.kind === 8 /* NumericLiteral */) {
                return indexArgumentExpression.text;
            }
            if (indexArgumentExpression.kind === 167 /* ElementAccessExpression */ || indexArgumentExpression.kind === 166 /* PropertyAccessExpression */) {
                var value = getConstantValue(indexArgumentExpression);
                if (value !== undefined) {
                    return value.toString();
                }
            }
            if (checkThatExpressionIsProperSymbolReference(indexArgumentExpression, indexArgumentType, /*reportError*/ false)) {
                var rightHandSideName = indexArgumentExpression.name.text;
                return ts.getPropertyNameForKnownSymbolName(rightHandSideName);
            }
            return undefined;
        }

If indexArgumentExpression is a string literal or number literal, returns its text.
If indexArgumentExpression is a constant value, returns its string value.
If indexArgumentExpression is a well known symbol, returns the property name corresponding
to this symbol, as long as it is a proper symbol reference.
Otherwise, returns undefined.

If indexArgumentExpression is a string literal or number literal returns its text . If indexArgumentExpression is a constant value returns its string value . If indexArgumentExpression is a well known symbol returns the property name corresponding to this symbol as long as it is a proper symbol reference . Otherwise returns undefined .


function getSingleCallSignature(type) {
            if (type.flags & 80896 /* ObjectType */) {
                var resolved = resolveStructuredTypeMembers(type);
                if (resolved.callSignatures.length === 1 && resolved.constructSignatures.length === 0 &&
                    resolved.properties.length === 0 && !resolved.stringIndexType && !resolved.numberIndexType) {
                    return resolved.callSignatures[0];
                }
            }
            return undefined;
        }

function
getSingleCallSignature
(
type
)
{
if
(
type
.
flags
&
80896
/* ObjectType */
)
{
var
resolved
=
resolveStructuredTypeMembers
(
type
)
;
if
(
resolved
.
callSignatures
.
length
===
1
&&
resolved
.
constructSignatures
.
length
===
0
&&
resolved
.
properties
.
length
===
0
&&
!
resolved
.
stringIndexType
&&
!
resolved
.
numberIndexType
)
{
return
resolved
.
callSignatures
[
0
]
;
}
}
return
undefined
;
}

If type has a single call signature and no other members, return that signature. Otherwise, return undefined.

If type has a single call signature and no other members return that signature . Otherwise return undefined .


function getEffectiveCallArguments(node) {
            var args;
            if (node.kind === 170 /* TaggedTemplateExpression */) {
                var template = node.template;
                args = [undefined];
                if (template.kind === 183 /* TemplateExpression */) {
                    ts.forEach(template.templateSpans, function (span) {
                        args.push(span.expression);
                    });
                }
            }
            else if (node.kind === 139 /* Decorator */) {
                // For a decorator, we return undefined as we will determine
                // the number and types of arguments for a decorator using
                // `getEffectiveArgumentCount` and `getEffectiveArgumentType` below.
                return undefined;
            }
            else {
                args = node.arguments || emptyArray;
            }
            return args;
        }

Returns the effective arguments for an expression that works like a function invocation.

If 'node' is a CallExpression or a NewExpression, then its argument list is returned.
If 'node' is a TaggedTemplateExpression, a new argument list is constructed from the substitution
expressions, where the first element of the list is `undefined`.
If 'node' is a Decorator, the argument list will be `undefined`, and its arguments and types
will be supplied from calls to `getEffectiveArgumentCount` and `getEffectiveArgumentType`.

Returns the effective arguments for an expression that works like a function invocation .


function getEffectiveDecoratorArgumentType(node, argIndex) {
            if (argIndex === 0) {
                return getEffectiveDecoratorFirstArgumentType(node.parent);
            }
            else if (argIndex === 1) {
                return getEffectiveDecoratorSecondArgumentType(node.parent);
            }
            else if (argIndex === 2) {
                return getEffectiveDecoratorThirdArgumentType(node.parent);
            }
            ts.Debug.fail("Decorators should not have a fourth synthetic argument.");
            return unknownType;
        }

Returns the effective argument type for the provided argument to a decorator.

Returns the effective argument type for the provided argument to a decorator .


function getEffectiveArgumentType(node, argIndex, arg) {
            // Decorators provide special arguments, a tagged template expression provides
            // a special first argument, and string literals get string literal types
            // unless we're reporting errors
            if (node.kind === 139 /* Decorator */) {
                return getEffectiveDecoratorArgumentType(node, argIndex);
            }
            else if (argIndex === 0 && node.kind === 170 /* TaggedTemplateExpression */) {
                return globalTemplateStringsArrayType;
            }
            // This is not a synthetic argument, so we return 'undefined'
            // to signal that the caller needs to check the argument.
            return undefined;
        }

Gets the effective argument type for an argument in a call expression.

Gets the effective argument type for an argument in a call expression .


function getEffectiveArgument(node, args, argIndex) {
            // For a decorator or the first argument of a tagged template expression we return undefined.
            if (node.kind === 139 /* Decorator */ ||
                (argIndex === 0 && node.kind === 170 /* TaggedTemplateExpression */)) {
                return undefined;
            }
            return args[argIndex];
        }

Gets the effective argument expression for an argument in a call expression.

Gets the effective argument expression for an argument in a call expression .


function getEffectiveArgumentErrorNode(node, argIndex, arg) {
            if (node.kind === 139 /* Decorator */) {
                // For a decorator, we use the expression of the decorator for error reporting.
                return node.expression;
            }
            else if (argIndex === 0 && node.kind === 170 /* TaggedTemplateExpression */) {
                // For a the first argument of a tagged template expression, we use the template of the tag for error reporting.
                return node.template;
            }
            else {
                return arg;
            }
        }

Gets the error node to use when reporting errors for an effective argument.

Gets the error node to use when reporting errors for an effective argument .


function getDiagnosticHeadMessageForDecoratorResolution(node) {
            switch (node.parent.kind) {
                case 214 /* ClassDeclaration */:
                case 186 /* ClassExpression */:
                    return ts.Diagnostics.Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression;
                case 138 /* Parameter */:
                    return ts.Diagnostics.Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression;
                case 141 /* PropertyDeclaration */:
                    return ts.Diagnostics.Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression;
                case 143 /* MethodDeclaration */:
                case 145 /* GetAccessor */:
                case 146 /* SetAccessor */:
                    return ts.Diagnostics.Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression;
            }
        }

Gets the localized diagnostic head message to use for errors when resolving a decorator as a call expression.

Gets the localized diagnostic head message to use for errors when resolving a decorator as a call expression .


function resolveDecorator(node, candidatesOutArray) {
            var funcType = checkExpression(node.expression);
            var apparentType = getApparentType(funcType);
            if (apparentType === unknownType) {
                return resolveErrorCall(node);
            }
            var callSignatures = getSignaturesOfType(apparentType, 0 /* Call */);
            if (funcType === anyType || (!callSignatures.length && !(funcType.flags & 16384 /* Union */) && isTypeAssignableTo(funcType, globalFunctionType))) {
                return resolveUntypedCall(node);
            }
            var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
            if (!callSignatures.length) {
                var errorInfo;
                errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature);
                errorInfo = ts.chainDiagnosticMessages(errorInfo, headMessage);
                diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(node, errorInfo));
                return resolveErrorCall(node);
            }
            return resolveCall(node, callSignatures, candidatesOutArray, headMessage);
        }

Resolves a decorator as if it were a call expression.

Resolves a decorator as if it were a call expression .


function getResolvedSignature(node, candidatesOutArray) {
            var links = getNodeLinks(node);
            // If getResolvedSignature has already been called, we will have cached the resolvedSignature.
            // However, it is possible that either candidatesOutArray was not passed in the first time,
            // or that a different candidatesOutArray was passed in. Therefore, we need to redo the work
            // to correctly fill the candidatesOutArray.
            if (!links.resolvedSignature || candidatesOutArray) {
                links.resolvedSignature = anySignature;
                if (node.kind === 168 /* CallExpression */) {
                    links.resolvedSignature = resolveCallExpression(node, candidatesOutArray);
                }
                else if (node.kind === 169 /* NewExpression */) {
                    links.resolvedSignature = resolveNewExpression(node, candidatesOutArray);
                }
                else if (node.kind === 170 /* TaggedTemplateExpression */) {
                    links.resolvedSignature = resolveTaggedTemplateExpression(node, candidatesOutArray);
                }
                else if (node.kind === 139 /* Decorator */) {
                    links.resolvedSignature = resolveDecorator(node, candidatesOutArray);
                }
                else {
                    ts.Debug.fail("Branch in 'getResolvedSignature' should be unreachable.");
                }
            }
            return links.resolvedSignature;
        }

candidatesOutArray is passed by signature help in the language service, and collectCandidates must fill it up with the appropriate candidate signatures

candidatesOutArray is passed by signature help in the language service and collectCandidates must fill it up with the appropriate candidate signatures


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;
                }
            }
            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.

Syntactically and semantically checks a call or new expression .