Input: All container nodes are kept on a linked list in declaration order . This list is used by the getLocalNameOfContainer function in the type checker to validate that the local name used for a container is unique . [CODESPLIT] function bindChildren ( node ) { // Before we recurse into a node's chilren, we first save the existing parent, container // and block-container.  Then after we pop out of processing the children, we restore // these saved values. var saveParent = parent ; var saveContainer = container ; var savedBlockScopeContainer = blockScopeContainer ; // This node will now be set as the parent of all of its children as we recurse into them. parent = node ; // Depending on what kind of node this is, we may have to adjust the current container // and block-container.   If the current node is a container, then it is automatically // considered the current block-container as well.  Also, for containers that we know // may contain locals, we proactively initialize the .locals field. We do this because // it's highly likely that the .locals will be needed to place some child in (for example, // a parameter, or variable declaration). // // However, we do not proactively create the .locals for block-containers because it's // totally normal and common for block-containers to never actually have a block-scoped // variable in them.  We don't want to end up allocating an object for every 'block' we // run into when most of them won't be necessary. // // Finally, if this is a block-container, then we clear out any existing .locals object // it may contain within it.  This happens in incremental scenarios.  Because we can be // reusing a node from a previous compilation, that node may have had 'locals' created // for it.  We must clear this so we don't accidently move any stale data forward from // a previous compilation. var containerFlags = getContainerFlags ( node ) ; if ( containerFlags & 1 /* IsContainer */ ) { container = blockScopeContainer = node ; if ( containerFlags & 4 /* HasLocals */ ) { container . locals = { } ; } addToContainerChain ( container ) ; } else if ( containerFlags & 2 /* IsBlockScopedContainer */ ) { blockScopeContainer = node ; blockScopeContainer . locals = undefined ; } if ( node . kind === 215 /* InterfaceDeclaration */ ) { seenThisKeyword = false ; ts . forEachChild ( node , bind ) ; node . flags = seenThisKeyword ? node . flags | 524288 /* ContainsThis */ : node . flags & ~ 524288 /* ContainsThis */ ; } else { ts . forEachChild ( node , bind ) ; } container = saveContainer ; parent = saveParent ; blockScopeContainer = savedBlockScopeContainer ; }


Input: This is a useful function for debugging purposes . [CODESPLIT] function nodePosToString ( node ) { var file = getSourceFileOfNode ( node ) ; var loc = ts . getLineAndCharacterOfPosition ( file , node . pos ) ; return file . fileName + "(" + ( loc . line + 1 ) + "," + ( loc . character + 1 ) + ")" ; }


Input: Returns true if this node is missing from the actual source code . A missing node is different from undefined / defined . When a node is undefined ( which can happen for optional nodes in the tree ) it is definitely missing . However a node may be defined but still be missing . This happens whenever the parser knows it needs to parse something but can t get anything in the source code that it expects at that location . For example : let a : ; Here the Type in the Type - Annotation is not - optional ( as there is a colon in the source code ) . So the parser will attempt to parse out a type and will create an actual node . However this node will be missing in the sense that no actual source - code / tokens are contained within it . [CODESPLIT] function nodeIsMissing ( node ) { if ( ! node ) { return true ; } return node . pos === node . end && node . pos >= 0 && node . kind !== 1 /* EndOfFileToken */ ; }


Input: Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like __proto__ [CODESPLIT] function escapeIdentifier ( identifier ) { return identifier . length >= 2 && identifier . charCodeAt ( 0 ) === 95 /* _ */ && identifier . charCodeAt ( 1 ) === 95 /* _ */ ? "_" + identifier : identifier ; }


Input: Remove extra underscore from escaped identifier [CODESPLIT] function unescapeIdentifier ( identifier ) { return identifier . length >= 3 && identifier . charCodeAt ( 0 ) === 95 /* _ */ && identifier . charCodeAt ( 1 ) === 95 /* _ */ && identifier . charCodeAt ( 2 ) === 95 /* _ */ ? identifier . substr ( 1 ) : identifier ; }


Input: Gets the nearest enclosing block scope container that has the provided node as a descendant that is not the provided node . [CODESPLIT] 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 ; } }


Input: Returns the node flags for this node and all relevant parent nodes . This is done so that nodes like variable declarations and binding elements can returned a view of their flags that includes the modifiers from their container . i . e . flags like export / declare aren t stored on the variable declaration directly but on the containing variable statement ( if it has one ) . Similarly flags for let / const are store on the variable declaration list . By calling this function all those flags are combined so that the client can treat the node as if it actually had those flags . [CODESPLIT] function getCombinedNodeFlags ( node ) { node = walkUpBindingElementsAndPatterns ( node ) ; var flags = node . flags ; if ( node . kind === 211 /* VariableDeclaration */ ) { node = node . parent ; } if ( node && node . kind === 212 /* VariableDeclarationList */ ) { flags |= node . flags ; node = node . parent ; } if ( node && node . kind === 193 /* VariableStatement */ ) { flags |= node . flags ; } return flags ; }


Input: Warning : This has the same semantics as the forEach family of functions in that traversal terminates in the event that visitor supplies a truthy value . [CODESPLIT] function forEachReturnStatement ( body , visitor ) { return traverse ( body ) ; function traverse ( node ) { switch ( node . kind ) { case 204 /* ReturnStatement */ : return visitor ( node ) ; case 220 /* CaseBlock */ : case 192 /* Block */ : case 196 /* IfStatement */ : case 197 /* DoStatement */ : case 198 /* WhileStatement */ : case 199 /* ForStatement */ : case 200 /* ForInStatement */ : case 201 /* ForOfStatement */ : case 205 /* WithStatement */ : case 206 /* SwitchStatement */ : case 241 /* CaseClause */ : case 242 /* DefaultClause */ : case 207 /* LabeledStatement */ : case 209 /* TryStatement */ : case 244 /* CatchClause */ : return ts . forEachChild ( node , traverse ) ; } } }


Input: True if the given identifier string literal or number literal is the name of a declaration node [CODESPLIT] 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 ; }


Input: Return true if the given identifier is classified as an IdentifierName [CODESPLIT] 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 ; }


Input: An alias symbol is created by one of the following declarations : import <symbol > = ... import <symbol > from ... import * as <symbol > from ... import { x as <symbol > } from ... export { x as <symbol > } from ... export = ... export default ... [CODESPLIT] function isAliasSymbolDeclaration ( node ) { return node . kind === 221 /* ImportEqualsDeclaration */ || node . kind === 223 /* ImportClause */ && ! ! node . name || node . kind === 224 /* NamespaceImport */ || node . kind === 226 /* ImportSpecifier */ || node . kind === 230 /* ExportSpecifier */ || node . kind === 227 /* ExportAssignment */ && node . expression . kind === 69 /* Identifier */ ; }


Input: A declaration has a dynamic name if both of the following are true : 1 . The declaration has a computed property name 2 . The computed name is * not * expressed as Symbol . <name > where name is a property of the Symbol constructor that denotes a built in Symbol . [CODESPLIT] function hasDynamicName ( declaration ) { return declaration . name && declaration . name . kind === 136 /* ComputedPropertyName */ && ! isWellKnownSymbolSyntactically ( declaration . name . expression ) ; }


Input: Based heavily on the abstract Quote / QuoteJSONString operation from ECMA - 262 ( 24 . 3 . 2 . 2 ) but augmented for a few select characters ( e . g . lineSeparator paragraphSeparator nextLine ) Note that this doesn t actually wrap the input in double quotes . [CODESPLIT] function escapeString ( s ) { s = escapedCharsRegExp . test ( s ) ? s . replace ( escapedCharsRegExp , getReplacement ) : s ; return s ; function getReplacement ( c ) { return escapedCharsMap [ c ] || get16BitUnicodeEscapeSequence ( c . charCodeAt ( 0 ) ) ; } }


Input: 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 . [CODESPLIT] 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 ; }


Input: Returns true if span contains other . [CODESPLIT] function textSpanContainsTextSpan ( span , other ) { return other . start >= span . start && textSpanEnd ( other ) <= textSpanEnd ( span ) ; }


Input: Invokes a callback for each child of the given node . The cbNode callback is invoked for all child nodes stored in properties . If a cbNodes callback is specified it is invoked for embedded arrays ; otherwise embedded arrays are flattened and the cbNode callback is invoked for each element . If a callback returns a truthy value iteration stops and that value is returned . Otherwise undefined is returned . [CODESPLIT] function forEachChild ( node , cbNode , cbNodeArray ) { if ( ! node ) { return ; } // The visitXXX functions could be written as local functions that close over the cbNode and cbNodeArray // callback parameters, but that causes a closure allocation for each invocation with noticeable effects // on performance. var visitNodes = cbNodeArray ? visitNodeArray : visitEachNode ; var cbNodes = cbNodeArray || cbNode ; switch ( node . kind ) { case 135 /* QualifiedName */ : return visitNode ( cbNode , node . left ) || visitNode ( cbNode , node . right ) ; case 137 /* TypeParameter */ : return visitNode ( cbNode , node . name ) || visitNode ( cbNode , node . constraint ) || visitNode ( cbNode , node . expression ) ; case 246 /* ShorthandPropertyAssignment */ : return visitNodes ( cbNodes , node . decorators ) || visitNodes ( cbNodes , node . modifiers ) || visitNode ( cbNode , node . name ) || visitNode ( cbNode , node . questionToken ) || visitNode ( cbNode , node . equalsToken ) || visitNode ( cbNode , node . objectAssignmentInitializer ) ; case 138 /* Parameter */ : case 141 /* PropertyDeclaration */ : case 140 /* PropertySignature */ : case 245 /* PropertyAssignment */ : case 211 /* VariableDeclaration */ : case 163 /* BindingElement */ : return visitNodes ( cbNodes , node . decorators ) || visitNodes ( cbNodes , node . modifiers ) || visitNode ( cbNode , node . propertyName ) || visitNode ( cbNode , node . dotDotDotToken ) || visitNode ( cbNode , node . name ) || visitNode ( cbNode , node . questionToken ) || visitNode ( cbNode , node . type ) || visitNode ( cbNode , node . initializer ) ; case 152 /* FunctionType */ : case 153 /* ConstructorType */ : case 147 /* CallSignature */ : case 148 /* ConstructSignature */ : case 149 /* IndexSignature */ : return visitNodes ( cbNodes , node . decorators ) || visitNodes ( cbNodes , node . modifiers ) || visitNodes ( cbNodes , node . typeParameters ) || visitNodes ( cbNodes , node . parameters ) || visitNode ( cbNode , node . type ) ; case 143 /* MethodDeclaration */ : case 142 /* MethodSignature */ : case 144 /* Constructor */ : case 145 /* GetAccessor */ : case 146 /* SetAccessor */ : case 173 /* FunctionExpression */ : case 213 /* FunctionDeclaration */ : case 174 /* ArrowFunction */ : return visitNodes ( cbNodes , node . decorators ) || visitNodes ( cbNodes , node . modifiers ) || visitNode ( cbNode , node . asteriskToken ) || visitNode ( cbNode , node . name ) || visitNode ( cbNode , node . questionToken ) || visitNodes ( cbNodes , node . typeParameters ) || visitNodes ( cbNodes , node . parameters ) || visitNode ( cbNode , node . type ) || visitNode ( cbNode , node . equalsGreaterThanToken ) || visitNode ( cbNode , node . body ) ; case 151 /* TypeReference */ : return visitNode ( cbNode , node . typeName ) || visitNodes ( cbNodes , node . typeArguments ) ; case 150 /* TypePredicate */ : return visitNode ( cbNode , node . parameterName ) || visitNode ( cbNode , node . type ) ; case 154 /* TypeQuery */ : return visitNode ( cbNode , node . exprName ) ; case 155 /* TypeLiteral */ : return visitNodes ( cbNodes , node . members ) ; case 156 /* ArrayType */ : return visitNode ( cbNode , node . elementType ) ; case 157 /* TupleType */ : return visitNodes ( cbNodes , node . elementTypes ) ; case 158 /* UnionType */ : case 159 /* IntersectionType */ : return visitNodes ( cbNodes , node . types ) ; case 160 /* ParenthesizedType */ : return visitNode ( cbNode , node . type ) ; case 161 /* ObjectBindingPattern */ : case 162 /* ArrayBindingPattern */ : return visitNodes ( cbNodes , node . elements ) ; case 164 /* ArrayLiteralExpression */ : return visitNodes ( cbNodes , node . elements ) ; case 165 /* ObjectLiteralExpression */ : return visitNodes ( cbNodes , node . properties ) ; case 166 /* PropertyAccessExpression */ : return visitNode ( cbNode , node . expression ) || visitNode ( cbNode , node . dotToken ) || visitNode ( cbNode , node . name ) ; case 167 /* ElementAccessExpression */ : return visitNode ( cbNode , node . expression ) || visitNode ( cbNode , node . argumentExpression ) ; case 168 /* CallExpression */ : case 169 /* NewExpression */ : return visitNode ( cbNode , node . expression ) || visitNodes ( cbNodes , node . typeArguments ) || visitNodes ( cbNodes , node . arguments ) ; case 170 /* TaggedTemplateExpression */ : return visitNode ( cbNode , node . tag ) || visitNode ( cbNode , node . template ) ; case 171 /* TypeAssertionExpression */ : return visitNode ( cbNode , node . type ) || visitNode ( cbNode , node . expression ) ; case 172 /* ParenthesizedExpression */ : return visitNode ( cbNode , node . expression ) ; case 175 /* DeleteExpression */ : return visitNode ( cbNode , node . expression ) ; case 176 /* TypeOfExpression */ : return visitNode ( cbNode , node . expression ) ; case 177 /* VoidExpression */ : return visitNode ( cbNode , node . expression ) ; case 179 /* PrefixUnaryExpression */ : return visitNode ( cbNode , node . operand ) ; case 184 /* YieldExpression */ : return visitNode ( cbNode , node . asteriskToken ) || visitNode ( cbNode , node . expression ) ; case 178 /* AwaitExpression */ : return visitNode ( cbNode , node . expression ) ; case 180 /* PostfixUnaryExpression */ : return visitNode ( cbNode , node . operand ) ; case 181 /* BinaryExpression */ : return visitNode ( cbNode , node . left ) || visitNode ( cbNode , node . operatorToken ) || visitNode ( cbNode , node . right ) ; case 189 /* AsExpression */ : return visitNode ( cbNode , node . expression ) || visitNode ( cbNode , node . type ) ; case 182 /* ConditionalExpression */ : return visitNode ( cbNode , node . condition ) || visitNode ( cbNode , node . questionToken ) || visitNode ( cbNode , node . whenTrue ) || visitNode ( cbNode , node . colonToken ) || visitNode ( cbNode , node . whenFalse ) ; case 185 /* SpreadElementExpression */ : return visitNode ( cbNode , node . expression ) ; case 192 /* Block */ : case 219 /* ModuleBlock */ : return visitNodes ( cbNodes , node . statements ) ; case 248 /* SourceFile */ : return visitNodes ( cbNodes , node . statements ) || visitNode ( cbNode , node . endOfFileToken ) ; case 193 /* VariableStatement */ : return visitNodes ( cbNodes , node . decorators ) || visitNodes ( cbNodes , node . modifiers ) || visitNode ( cbNode , node . declarationList ) ; case 212 /* VariableDeclarationList */ : return visitNodes ( cbNodes , node . declarations ) ; case 195 /* ExpressionStatement */ : return visitNode ( cbNode , node . expression ) ; case 196 /* IfStatement */ : return visitNode ( cbNode , node . expression ) || visitNode ( cbNode , node . thenStatement ) || visitNode ( cbNode , node . elseStatement ) ; case 197 /* DoStatement */ : return visitNode ( cbNode , node . statement ) || visitNode ( cbNode , node . expression ) ; case 198 /* WhileStatement */ : return visitNode ( cbNode , node . expression ) || visitNode ( cbNode , node . statement ) ; case 199 /* ForStatement */ : return visitNode ( cbNode , node . initializer ) || visitNode ( cbNode , node . condition ) || visitNode ( cbNode , node . incrementor ) || visitNode ( cbNode , node . statement ) ; case 200 /* ForInStatement */ : return visitNode ( cbNode , node . initializer ) || visitNode ( cbNode , node . expression ) || visitNode ( cbNode , node . statement ) ; case 201 /* ForOfStatement */ : return visitNode ( cbNode , node . initializer ) || visitNode ( cbNode , node . expression ) || visitNode ( cbNode , node . statement ) ; case 202 /* ContinueStatement */ : case 203 /* BreakStatement */ : return visitNode ( cbNode , node . label ) ; case 204 /* ReturnStatement */ : return visitNode ( cbNode , node . expression ) ; case 205 /* WithStatement */ : return visitNode ( cbNode , node . expression ) || visitNode ( cbNode , node . statement ) ; case 206 /* SwitchStatement */ : return visitNode ( cbNode , node . expression ) || visitNode ( cbNode , node . caseBlock ) ; case 220 /* CaseBlock */ : return visitNodes ( cbNodes , node . clauses ) ; case 241 /* CaseClause */ : return visitNode ( cbNode , node . expression ) || visitNodes ( cbNodes , node . statements ) ; case 242 /* DefaultClause */ : return visitNodes ( cbNodes , node . statements ) ; case 207 /* LabeledStatement */ : return visitNode ( cbNode , node . label ) || visitNode ( cbNode , node . statement ) ; case 208 /* ThrowStatement */ : return visitNode ( cbNode , node . expression ) ; case 209 /* TryStatement */ : return visitNode ( cbNode , node . tryBlock ) || visitNode ( cbNode , node . catchClause ) || visitNode ( cbNode , node . finallyBlock ) ; case 244 /* CatchClause */ : return visitNode ( cbNode , node . variableDeclaration ) || visitNode ( cbNode , node . block ) ; case 139 /* Decorator */ : return visitNode ( cbNode , node . expression ) ; case 214 /* ClassDeclaration */ : case 186 /* ClassExpression */ : return visitNodes ( cbNodes , node . decorators ) || visitNodes ( cbNodes , node . modifiers ) || visitNode ( cbNode , node . name ) || visitNodes ( cbNodes , node . typeParameters ) || visitNodes ( cbNodes , node . heritageClauses ) || visitNodes ( cbNodes , node . members ) ; case 215 /* InterfaceDeclaration */ : return visitNodes ( cbNodes , node . decorators ) || visitNodes ( cbNodes , node . modifiers ) || visitNode ( cbNode , node . name ) || visitNodes ( cbNodes , node . typeParameters ) || visitNodes ( cbNodes , node . heritageClauses ) || visitNodes ( cbNodes , node . members ) ; case 216 /* TypeAliasDeclaration */ : return visitNodes ( cbNodes , node . decorators ) || visitNodes ( cbNodes , node . modifiers ) || visitNode ( cbNode , node . name ) || visitNodes ( cbNodes , node . typeParameters ) || visitNode ( cbNode , node . type ) ; case 217 /* EnumDeclaration */ : return visitNodes ( cbNodes , node . decorators ) || visitNodes ( cbNodes , node . modifiers ) || visitNode ( cbNode , node . name ) || visitNodes ( cbNodes , node . members ) ; case 247 /* EnumMember */ : return visitNode ( cbNode , node . name ) || visitNode ( cbNode , node . initializer ) ; case 218 /* ModuleDeclaration */ : return visitNodes ( cbNodes , node . decorators ) || visitNodes ( cbNodes , node . modifiers ) || visitNode ( cbNode , node . name ) || visitNode ( cbNode , node . body ) ; case 221 /* ImportEqualsDeclaration */ : return visitNodes ( cbNodes , node . decorators ) || visitNodes ( cbNodes , node . modifiers ) || visitNode ( cbNode , node . name ) || visitNode ( cbNode , node . moduleReference ) ; case 222 /* ImportDeclaration */ : return visitNodes ( cbNodes , node . decorators ) || visitNodes ( cbNodes , node . modifiers ) || visitNode ( cbNode , node . importClause ) || visitNode ( cbNode , node . moduleSpecifier ) ; case 223 /* ImportClause */ : return visitNode ( cbNode , node . name ) || visitNode ( cbNode , node . namedBindings ) ; case 224 /* NamespaceImport */ : return visitNode ( cbNode , node . name ) ; case 225 /* NamedImports */ : case 229 /* NamedExports */ : return visitNodes ( cbNodes , node . elements ) ; case 228 /* ExportDeclaration */ : return visitNodes ( cbNodes , node . decorators ) || visitNodes ( cbNodes , node . modifiers ) || visitNode ( cbNode , node . exportClause ) || visitNode ( cbNode , node . moduleSpecifier ) ; case 226 /* ImportSpecifier */ : case 230 /* ExportSpecifier */ : return visitNode ( cbNode , node . propertyName ) || visitNode ( cbNode , node . name ) ; case 227 /* ExportAssignment */ : return visitNodes ( cbNodes , node . decorators ) || visitNodes ( cbNodes , node . modifiers ) || visitNode ( cbNode , node . expression ) ; case 183 /* TemplateExpression */ : return visitNode ( cbNode , node . head ) || visitNodes ( cbNodes , node . templateSpans ) ; case 190 /* TemplateSpan */ : return visitNode ( cbNode , node . expression ) || visitNode ( cbNode , node . literal ) ; case 136 /* ComputedPropertyName */ : return visitNode ( cbNode , node . expression ) ; case 243 /* HeritageClause */ : return visitNodes ( cbNodes , node . types ) ; case 188 /* ExpressionWithTypeArguments */ : return visitNode ( cbNode , node . expression ) || visitNodes ( cbNodes , node . typeArguments ) ; case 232 /* ExternalModuleReference */ : return visitNode ( cbNode , node . expression ) ; case 231 /* MissingDeclaration */ : return visitNodes ( cbNodes , node . decorators ) ; case 233 /* JsxElement */ : return visitNode ( cbNode , node . openingElement ) || visitNodes ( cbNodes , node . children ) || visitNode ( cbNode , node . closingElement ) ; case 234 /* JsxSelfClosingElement */ : case 235 /* JsxOpeningElement */ : return visitNode ( cbNode , node . tagName ) || visitNodes ( cbNodes , node . attributes ) ; case 238 /* JsxAttribute */ : return visitNode ( cbNode , node . name ) || visitNode ( cbNode , node . initializer ) ; case 239 /* JsxSpreadAttribute */ : return visitNode ( cbNode , node . expression ) ; case 240 /* JsxExpression */ : return visitNode ( cbNode , node . expression ) ; case 237 /* JsxClosingElement */ : return visitNode ( cbNode , node . tagName ) ; case 249 /* JSDocTypeExpression */ : return visitNode ( cbNode , node . type ) ; case 253 /* JSDocUnionType */ : return visitNodes ( cbNodes , node . types ) ; case 254 /* JSDocTupleType */ : return visitNodes ( cbNodes , node . types ) ; case 252 /* JSDocArrayType */ : return visitNode ( cbNode , node . elementType ) ; case 256 /* JSDocNonNullableType */ : return visitNode ( cbNode , node . type ) ; case 255 /* JSDocNullableType */ : return visitNode ( cbNode , node . type ) ; case 257 /* JSDocRecordType */ : return visitNodes ( cbNodes , node . members ) ; case 259 /* JSDocTypeReference */ : return visitNode ( cbNode , node . name ) || visitNodes ( cbNodes , node . typeArguments ) ; case 260 /* JSDocOptionalType */ : return visitNode ( cbNode , node . type ) ; case 261 /* JSDocFunctionType */ : return visitNodes ( cbNodes , node . parameters ) || visitNode ( cbNode , node . type ) ; case 262 /* JSDocVariadicType */ : return visitNode ( cbNode , node . type ) ; case 263 /* JSDocConstructorType */ : return visitNode ( cbNode , node . type ) ; case 264 /* JSDocThisType */ : return visitNode ( cbNode , node . type ) ; case 258 /* JSDocRecordMember */ : return visitNode ( cbNode , node . name ) || visitNode ( cbNode , node . type ) ; case 265 /* JSDocComment */ : return visitNodes ( cbNodes , node . tags ) ; case 267 /* JSDocParameterTag */ : return visitNode ( cbNode , node . preParameterName ) || visitNode ( cbNode , node . typeExpression ) || visitNode ( cbNode , node . postParameterName ) ; case 268 /* JSDocReturnTag */ : return visitNode ( cbNode , node . typeExpression ) ; case 269 /* JSDocTypeTag */ : return visitNode ( cbNode , node . typeExpression ) ; case 270 /* JSDocTemplateTag */ : return visitNodes ( cbNodes , node . typeParameters ) ; } }


Input: Produces a new SourceFile for the newText provided . The textChangeRange parameter indicates what changed between the text that this SourceFile has and the newText . The SourceFile will be created with the compiler attempting to reuse as many nodes from this file as possible . Note : this function mutates nodes from this SourceFile . That means any existing nodes from this SourceFile that are being held onto may change as a result ( including becoming detached from any SourceFile ) . It is recommended that this SourceFile not be used once update is called on it . [CODESPLIT] function updateSourceFile ( sourceFile , newText , textChangeRange , aggressiveChecks ) { return IncrementalParser . updateSourceFile ( sourceFile , newText , textChangeRange , aggressiveChecks ) ; }


Input: / * [CODESPLIT] function parseIsolatedJSDocComment ( content , start , length ) { return Parser . JSDocParser . parseIsolatedJSDocComment ( content , start , length ) ; }


Input: An identifier that starts with two underscores has an extra underscore character prepended to it to avoid issues with magic property names like __proto__ . The identifiers object is used to share a single string instance for each identifier in order to reduce memory consumption . [CODESPLIT] function createIdentifier ( isIdentifier , diagnosticMessage ) { identifierCount ++ ; if ( isIdentifier ) { var node = createNode ( 69 /* Identifier */ ) ; // Store original token kind if it is not just an Identifier so we can report appropriate error later in type checker if ( token !== 69 /* Identifier */ ) { node . originalKeywordKind = token ; } node . text = internIdentifier ( scanner . getTokenValue ( ) ) ; nextToken ( ) ; return finishNode ( node ) ; } return createMissingNode ( 69 /* Identifier */ , /*reportAtCurrentPosition*/ false , diagnosticMessage || ts . Diagnostics . Identifier_expected ) ; }


Input: True if positioned at a list terminator [CODESPLIT] 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 */ ; } }


Input: The allowReservedWords parameter controls whether reserved words are permitted after the first dot [CODESPLIT] 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 ; }


Input: TYPES [CODESPLIT] function parseTypeReferenceOrTypePredicate ( ) { var typeName = parseEntityName ( /*allowReservedWords*/ false , ts . Diagnostics . Type_expected ) ; if ( typeName . kind === 69 /* Identifier */ && token === 124 /* IsKeyword */ && ! scanner . hasPrecedingLineBreak ( ) ) { nextToken ( ) ; var node_1 = createNode ( 150 /* TypePredicate */ , typeName . pos ) ; node_1 . parameterName = typeName ; node_1 . type = parseType ( ) ; return finishNode ( node_1 ) ; } var node = createNode ( 151 /* TypeReference */ , typeName . pos ) ; node . typeName = typeName ; if ( ! scanner . hasPrecedingLineBreak ( ) && token === 25 /* LessThanToken */ ) { node . typeArguments = parseBracketedList ( 18 /* TypeArguments */ , parseType , 25 /* LessThanToken */ , 27 /* GreaterThanToken */ ) ; } return finishNode ( node ) ; }


Input: STATEMENTS [CODESPLIT] function parseBlock ( ignoreMissingOpenBrace , diagnosticMessage ) { var node = createNode ( 192 /* Block */ ) ; if ( parseExpected ( 15 /* OpenBraceToken */ , diagnosticMessage ) || ignoreMissingOpenBrace ) { node . statements = parseList ( 1 /* BlockStatements */ , parseStatement ) ; parseExpected ( 16 /* CloseBraceToken */ ) ; } else { node . statements = createMissingList ( ) ; } return finishNode ( node ) ; }


Input: TODO : Review for error recovery [CODESPLIT] function parseTryStatement ( ) { var node = createNode ( 209 /* TryStatement */ ) ; parseExpected ( 100 /* TryKeyword */ ) ; node . tryBlock = parseBlock ( /*ignoreMissingOpenBrace*/ false ) ; node . catchClause = token === 72 /* CatchKeyword */ ? parseCatchClause ( ) : undefined ; // If we don't have a catch clause, then we must have a finally clause.  Try to parse // one out no matter what. if ( ! node . catchClause || token === 85 /* FinallyKeyword */ ) { parseExpected ( 85 /* FinallyKeyword */ ) ; node . finallyBlock = parseBlock ( /*ignoreMissingOpenBrace*/ false ) ; } return finishNode ( node ) ; }


Input: DECLARATIONS [CODESPLIT] function parseArrayBindingElement ( ) { if ( token === 24 /* CommaToken */ ) { return createNode ( 187 /* OmittedExpression */ ) ; } var node = createNode ( 163 /* BindingElement */ ) ; node . dotDotDotToken = parseOptionalToken ( 22 /* DotDotDotToken */ ) ; node . name = parseIdentifierOrPattern ( ) ; node . initializer = parseBindingElementInitializer ( /*inParameter*/ false ) ; return finishNode ( node ) ; }


Input: Parses out a JSDoc type expression . The starting position should be right at the open curly in the type expression . Returns undefined if it encounters any errors while parsing . / * [CODESPLIT] function parseJSDocTypeExpression ( start , length ) { scanner . setText ( sourceText , start , length ) ; // Prime the first token for us to start processing. token = nextToken ( ) ; var result = createNode ( 249 /* JSDocTypeExpression */ ) ; parseExpected ( 15 /* OpenBraceToken */ ) ; result . type = parseJSDocTopLevelType ( ) ; parseExpected ( 16 /* CloseBraceToken */ ) ; fixupParentReferences ( result ) ; return finishNode ( result ) ; }


Input: 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 . [CODESPLIT] 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 ; } }


Input: Resolve a given name for a given meaning at a given location . An error is reported if the name was not found and the nameNotFoundMessage argument is not undefined . Returns the resolved symbol or undefined if no symbol with the given name can be found . [CODESPLIT] function resolveName ( location , name , meaning , nameNotFoundMessage , nameArg ) { var result ; var lastLocation ; var propertyWithInvalidInitializer ; var errorLocation = location ; var grandparent ; loop : while ( location ) { // Locals of a source file are not in scope (because they get merged into the global symbol table) if ( location . locals && ! isGlobalSourceFile ( location ) ) { if ( result = getSymbol ( location . locals , name , meaning ) ) { // Type parameters of a function are in scope in the entire function declaration, including the parameter // list and return type. However, local types are only in scope in the function body. if ( ! ( meaning & 793056 /* Type */ ) || ! ( result . flags & ( 793056 /* Type */ & ~ 262144 /* TypeParameter */ ) ) || ! ts . isFunctionLike ( location ) || lastLocation === location . body ) { break loop ; } result = undefined ; } } switch ( location . kind ) { case 248 /* SourceFile */ : if ( ! ts . isExternalModule ( location ) ) break ; case 218 /* ModuleDeclaration */ : var moduleExports = getSymbolOfNode ( location ) . exports ; if ( location . kind === 248 /* SourceFile */ || ( location . kind === 218 /* ModuleDeclaration */ && location . name . kind === 9 /* StringLiteral */ ) ) { // It's an external module. Because of module/namespace merging, a module's exports are in scope, // yet we never want to treat an export specifier as putting a member in scope. Therefore, // if the name we find is purely an export specifier, it is not actually considered in scope. // Two things to note about this: //     1. We have to check this without calling getSymbol. The problem with calling getSymbol //        on an export specifier is that it might find the export specifier itself, and try to //        resolve it as an alias. This will cause the checker to consider the export specifier //        a circular alias reference when it might not be. //     2. We check === SymbolFlags.Alias in order to check that the symbol is *purely* //        an alias. If we used &, we'd be throwing out symbols that have non alias aspects, //        which is not the desired behavior. if ( ts . hasProperty ( moduleExports , name ) && moduleExports [ name ] . flags === 8388608 /* Alias */ && ts . getDeclarationOfKind ( moduleExports [ name ] , 230 /* ExportSpecifier */ ) ) { break ; } result = moduleExports [ "default" ] ; var localSymbol = ts . getLocalSymbolForExportDefault ( result ) ; if ( result && localSymbol && ( result . flags & meaning ) && localSymbol . name === name ) { break loop ; } result = undefined ; } if ( result = getSymbol ( moduleExports , name , meaning & 8914931 /* ModuleMember */ ) ) { break loop ; } break ; case 217 /* EnumDeclaration */ : if ( result = getSymbol ( getSymbolOfNode ( location ) . exports , name , meaning & 8 /* EnumMember */ ) ) { break loop ; } break ; case 141 /* PropertyDeclaration */ : case 140 /* PropertySignature */ : // TypeScript 1.0 spec (April 2014): 8.4.1 // Initializer expressions for instance member variables are evaluated in the scope // of the class constructor body but are not permitted to reference parameters or // local variables of the constructor. This effectively means that entities from outer scopes // by the same name as a constructor parameter or local variable are inaccessible // in initializer expressions for instance member variables. if ( ts . isClassLike ( location . parent ) && ! ( location . flags & 128 /* Static */ ) ) { var ctor = findConstructorDeclaration ( location . parent ) ; if ( ctor && ctor . locals ) { if ( getSymbol ( ctor . locals , name , meaning & 107455 /* Value */ ) ) { // Remember the property node, it will be used later to report appropriate error propertyWithInvalidInitializer = location ; } } } break ; case 214 /* ClassDeclaration */ : case 186 /* ClassExpression */ : case 215 /* InterfaceDeclaration */ : if ( result = getSymbol ( getSymbolOfNode ( location ) . members , name , meaning & 793056 /* Type */ ) ) { if ( lastLocation && lastLocation . flags & 128 /* Static */ ) { // TypeScript 1.0 spec (April 2014): 3.4.1 // The scope of a type parameter extends over the entire declaration with which the type // parameter list is associated, with the exception of static member declarations in classes. error ( errorLocation , ts . Diagnostics . Static_members_cannot_reference_class_type_parameters ) ; return undefined ; } break loop ; } if ( location . kind === 186 /* ClassExpression */ && meaning & 32 /* Class */ ) { var className = location . name ; if ( className && name === className . text ) { result = location . symbol ; break loop ; } } break ; // It is not legal to reference a class's own type parameters from a computed property name that // belongs to the class. For example: // //   function foo<T>() { return '' } //   class C<T> { // <-- Class's own type parameter T //       [foo<T>()]() { } // <-- Reference to T from class's own computed property //   } // case 136 /* ComputedPropertyName */ : grandparent = location . parent . parent ; if ( ts . isClassLike ( grandparent ) || grandparent . kind === 215 /* InterfaceDeclaration */ ) { // A reference to this grandparent's type parameters would be an error if ( result = getSymbol ( getSymbolOfNode ( grandparent ) . members , name , meaning & 793056 /* Type */ ) ) { error ( errorLocation , ts . Diagnostics . A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type ) ; return undefined ; } } break ; case 143 /* MethodDeclaration */ : case 142 /* MethodSignature */ : case 144 /* Constructor */ : case 145 /* GetAccessor */ : case 146 /* SetAccessor */ : case 213 /* FunctionDeclaration */ : case 174 /* ArrowFunction */ : if ( meaning & 3 /* Variable */ && name === "arguments" ) { result = argumentsSymbol ; break loop ; } break ; case 173 /* FunctionExpression */ : if ( meaning & 3 /* Variable */ && name === "arguments" ) { result = argumentsSymbol ; break loop ; } if ( meaning & 16 /* Function */ ) { var functionName = location . name ; if ( functionName && name === functionName . text ) { result = location . symbol ; break loop ; } } break ; case 139 /* Decorator */ : // Decorators are resolved at the class declaration. Resolving at the parameter // or member would result in looking up locals in the method. // //   function y() {} //   class C { //       method(@y x, y) {} // <-- decorator y should be resolved at the class declaration, not the parameter. //   } // if ( location . parent && location . parent . kind === 138 /* Parameter */ ) { location = location . parent ; } // //   function y() {} //   class C { //       @y method(x, y) {} // <-- decorator y should be resolved at the class declaration, not the method. //   } // if ( location . parent && ts . isClassElement ( location . parent ) ) { location = location . parent ; } break ; } lastLocation = location ; location = location . parent ; } if ( ! result ) { result = getSymbol ( globals , name , meaning ) ; } if ( ! result ) { if ( nameNotFoundMessage ) { error ( errorLocation , nameNotFoundMessage , typeof nameArg === "string" ? nameArg : ts . declarationNameToString ( nameArg ) ) ; } return undefined ; } // Perform extra checks only if error reporting was requested if ( nameNotFoundMessage ) { if ( propertyWithInvalidInitializer ) { // We have a match, but the reference occurred within a property initializer and the identifier also binds // to a local variable in the constructor where the code will be emitted. var propertyName = propertyWithInvalidInitializer . name ; error ( errorLocation , ts . Diagnostics . Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor , ts . declarationNameToString ( propertyName ) , typeof nameArg === "string" ? nameArg : ts . declarationNameToString ( nameArg ) ) ; return undefined ; } // Only check for block-scoped variable if we are looking for the // name with variable meaning //      For example, //          declare module foo { //              interface bar {} //          } //      let foo/*1*/: foo/*2*/.bar; // The foo at /*1*/ and /*2*/ will share same symbol with two meaning // block - scope variable and namespace module. However, only when we // try to resolve name in /*1*/ which is used in variable position, // we want to check for block- scoped if ( meaning & 2 /* BlockScopedVariable */ ) { var exportOrLocalSymbol = getExportSymbolOfValueSymbolIfExported ( result ) ; if ( exportOrLocalSymbol . flags & 2 /* BlockScopedVariable */ ) { checkResolvedBlockScopedVariable ( exportOrLocalSymbol , errorLocation ) ; } } } return result ; }


Input: / * Starting from initial node walk up the parent chain until stopAt node is reached . If at any point current node is equal to parent node - return true . Return false if stopAt node is reached or isFunctionLike ( current ) === true . [CODESPLIT] function isSameScopeDescendentOf ( initial , parent , stopAt ) { if ( ! parent ) { return false ; } for ( var current = initial ; current && current !== stopAt && ! ts . isFunctionLike ( current ) ; current = current . parent ) { if ( current === parent ) { return true ; } } return false ; }


Input: This function creates a synthetic symbol that combines the value side of one symbol with the type / namespace side of another symbol . Consider this example : declare module graphics { interface Point { x : number ; y : number ; } } declare var graphics : { Point : new ( x : number y : number ) = > graphics . Point ; } declare module graphics { export = graphics ; } An import { Point } from graphics needs to create a symbol that combines the value side Point property with the type / namespace side interface Point . [CODESPLIT] function combineValueAndTypeSymbols ( valueSymbol , typeSymbol ) { if ( valueSymbol . flags & ( 793056 /* Type */ | 1536 /* Namespace */ ) ) { return valueSymbol ; } var result = createSymbol ( valueSymbol . flags | typeSymbol . flags , valueSymbol . name ) ; result . declarations = ts . concatenate ( valueSymbol . declarations , typeSymbol . declarations ) ; result . parent = valueSymbol . parent || typeSymbol . parent ; if ( valueSymbol . valueDeclaration ) result . valueDeclaration = valueSymbol . valueDeclaration ; if ( typeSymbol . members ) result . members = typeSymbol . members ; if ( valueSymbol . exports ) result . exports = valueSymbol . exports ; return result ; }


Input: When an alias symbol is referenced we need to mark the entity it references as referenced and in turn repeat that until we reach a non - alias or an exported entity ( which is always considered referenced ) . We do this by checking the target of the alias as an expression ( which recursively takes us back here if the target references another alias ) . [CODESPLIT] function markAliasSymbolAsReferenced ( symbol ) { var links = getSymbolLinks ( symbol ) ; if ( ! links . referenced ) { links . referenced = true ; var node = getDeclarationOfAliasSymbol ( symbol ) ; if ( node . kind === 227 /* ExportAssignment */ ) { // export default <symbol> checkExpressionCached ( node . expression ) ; } else if ( node . kind === 230 /* ExportSpecifier */ ) { // export { <symbol> } or export { <symbol> as foo } checkExpressionCached ( node . propertyName || node . name ) ; } else if ( ts . isInternalModuleImportEqualsDeclaration ( node ) ) { // import foo = <symbol> checkExpressionCached ( node . moduleReference ) ; } } }


Input: This function is only for imports with entity names [CODESPLIT] 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 */ ) ; } }


Input: Resolves a qualified name and any involved aliases [CODESPLIT] 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 ) ; }


Input: An external module with an export = declaration may be referenced as an ES6 module provided the export = references a symbol that is at least declared as a module or a variable . The target of the export = may combine other declarations with the module or variable ( e . g . a class / module function / module interface / variable ) . [CODESPLIT] function resolveESModuleSymbol ( moduleSymbol , moduleReferenceExpression ) { var symbol = resolveExternalModuleSymbol ( moduleSymbol ) ; if ( symbol && ! ( symbol . flags & ( 1536 /* Module */ | 3 /* Variable */ ) ) ) { error ( moduleReferenceExpression , ts . Diagnostics . Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct , symbolToString ( moduleSymbol ) ) ; symbol = undefined ; } return symbol ; }


Input: A reserved member name starts with two underscores but the third character cannot be an underscore or the [CODESPLIT] function isReservedMemberName ( name ) { return name . charCodeAt ( 0 ) === 95 /* _ */ && name . charCodeAt ( 1 ) === 95 /* _ */ && name . charCodeAt ( 2 ) !== 95 /* _ */ && name . charCodeAt ( 2 ) !== 64 /* at */ ; }


Input: Check if the symbol is used in export assignment [CODESPLIT] 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 ; } } ) ; } }


Input: Return the type of the given property in the given type or undefined if no such property exists [CODESPLIT] function getTypeOfPropertyOfType ( type , name ) { var prop = getPropertyOfType ( type , name ) ; return prop ? getTypeOfSymbol ( prop ) : undefined ; }


Input: Return the type of a binding element parent . We check SymbolLinks first to see if a type has been assigned by contextual typing . [CODESPLIT] function getTypeForBindingElementParent ( node ) { var symbol = getSymbolOfNode ( node ) ; return symbol && getSymbolLinks ( symbol ) . type || getTypeForVariableLikeDeclaration ( node ) ; }


Input: Return the inferred type for a binding element [CODESPLIT] 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 ; }


Input: Return the inferred type for a variable parameter or property declaration [CODESPLIT] 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 ; }


Input: 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 . [CODESPLIT] function getTypeFromBindingElement ( element , includePatternInType ) { if ( element . initializer ) { return getWidenedType ( checkExpressionCached ( element . initializer ) ) ; } if ( ts . isBindingPattern ( element . name ) ) { return getTypeFromBindingPattern ( element . name , includePatternInType ) ; } return anyType ; }


Input: Return the type implied by an object binding pattern [CODESPLIT] 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 ; }


Input: Return the type implied by a binding pattern . This is the type implied purely by the binding pattern itself and without regard to its context ( i . e . without regard any type annotation or initializer associated with the declaration in which the binding pattern is contained ) . For example the implied type of [ x y ] is [ any any ] and the implied type of { x y : z = 1 } is { x : any ; y : number ; } . The type implied by a binding pattern is used as the contextual type of an initializer associated with the binding pattern . Also for a destructuring parameter with no type annotation or initializer the type implied by the binding pattern becomes the type of the parameter . [CODESPLIT] function getTypeFromBindingPattern ( pattern , includePatternInType ) { return pattern . kind === 161 /* ObjectBindingPattern */ ? getTypeFromObjectBindingPattern ( pattern , includePatternInType ) : getTypeFromArrayBindingPattern ( pattern , includePatternInType ) ; }


Input: Return the type associated with a variable parameter or property declaration . In the simple case this is the type specified in a type annotation or inferred from an initializer . However in the case of a destructuring declaration it is a bit more involved . For example : var [ x s = ] = [ 1 one ] ; Here the array literal [ 1 one ] is contextually typed by the type [ any string ] which is the implied type of the binding pattern [ x s = ] . Because the contextual type is a tuple type the resulting type of [ 1 one ] is the tuple type [ number string ] . Thus the type inferred for x is number and the type inferred for s is string . [CODESPLIT] function getWidenedTypeForVariableLikeDeclaration ( declaration , reportErrors ) { var type = getTypeForVariableLikeDeclaration ( declaration ) ; if ( type ) { if ( reportErrors ) { reportErrorsFromWidening ( declaration , type ) ; } // During a normal type check we'll never get to here with a property assignment (the check of the containing // object literal uses a different path). We exclude widening only so that language services and type verification // tools see the actual type. return declaration . kind !== 245 /* PropertyAssignment */ ? getWidenedType ( type ) : type ; } // Rest parameters default to type any[], other parameters default to type any type = declaration . dotDotDotToken ? anyArrayType : anyType ; // Report implicit any errors unless this is a private property within an ambient declaration if ( reportErrors && compilerOptions . noImplicitAny ) { var root = ts . getRootDeclaration ( declaration ) ; if ( ! isPrivateWithinAmbient ( root ) && ! ( root . kind === 138 /* Parameter */ && isPrivateWithinAmbient ( root . parent ) ) ) { reportImplicitAnyError ( declaration , type ) ; } } return type ; }


Input: The local type parameters are the combined set of type parameters from all declarations of the class interface or type alias . [CODESPLIT] 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 ; }


Input: 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 . [CODESPLIT] 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 ; }


Input: A type reference is considered independent if each type argument is considered independent . [CODESPLIT] 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 ; }


Input: A variable - like declaration is considered independent ( free of this references ) if it has a type annotation that specifies an independent type or if it has no type annotation and no initializer ( and thus of type any ) . [CODESPLIT] function isIndependentVariableLikeDeclaration ( node ) { return node . type && isIndependentType ( node . type ) || ! node . type && ! node . initializer ; }


Input: A function - like declaration is considered independent ( free of this references ) if it has a return type annotation that is considered independent and if each parameter is considered independent . [CODESPLIT] function isIndependentFunctionLikeDeclaration ( node ) { if ( node . kind !== 144 /* Constructor */ && ( ! node . type || ! isIndependentType ( node . type ) ) ) { return false ; } for ( var _i = 0 , _a = node . parameters ; _i < _a . length ; _i ++ ) { var parameter = _a [ _i ] ; if ( ! isIndependentVariableLikeDeclaration ( parameter ) ) { return false ; } } return true ; }


Input: 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 . [CODESPLIT] 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 ; }


Input: 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 . [CODESPLIT] 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 ; }


Input: 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 . [CODESPLIT] 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 ; } } } }


Input: 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 . [CODESPLIT] 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 ; }


Input: 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 . [CODESPLIT] 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 ; }


Input: Return list of type parameters with duplicates removed ( duplicate identifier errors are generated in the actual type checking functions ) . [CODESPLIT] function getTypeParametersFromDeclaration ( typeParameterDeclarations ) { var result = [ ] ; ts . forEach ( typeParameterDeclarations , function ( node ) { var tp = getDeclaredTypeOfTypeParameter ( node . symbol ) ; if ( ! ts . contains ( result , tp ) ) { result . push ( tp ) ; } } ) ; return result ; }


Input: 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 . [CODESPLIT] 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 */ ; }


Input: Get type from reference to class or interface [CODESPLIT] 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 ; }


Input: 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 . [CODESPLIT] 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 ; }


Input: Get type from reference to named type that cannot be generic ( enum or type parameter ) [CODESPLIT] function getTypeFromNonGenericTypeReference ( node , symbol ) { if ( symbol . flags & 262144 /* TypeParameter */ && isTypeParameterReferenceIllegalInConstraint ( node , symbol ) ) { // TypeScript 1.0 spec (April 2014): 3.4.1 // Type parameters declared in a particular type parameter list // may not be referenced in constraints in that type parameter list // Implementation: such type references are resolved to 'unknown' type that usually denotes error return unknownType ; } if ( node . typeArguments ) { error ( node , ts . Diagnostics . Type_0_is_not_generic , symbolToString ( symbol ) ) ; return unknownType ; } return getDeclaredTypeOfSymbol ( symbol ) ; }


Input: Returns a type that is inside a namespace at the global scope e . g . getExportedTypeFromNamespace ( JSX Element ) returns the JSX . Element type [CODESPLIT] function getExportedTypeFromNamespace ( namespace , name ) { var namespaceSymbol = getGlobalSymbol ( namespace , 1536 /* Namespace */ , /*diagnosticMessage*/ undefined ) ; var typeSymbol = namespaceSymbol && getSymbol ( namespaceSymbol . exports , name , 793056 /* Type */ ) ; return typeSymbol && getDeclaredTypeOfSymbol ( typeSymbol ) ; }


Input: Creates a TypeReference for a generic TypedPropertyDescriptor<T > . [CODESPLIT] function createTypedPropertyDescriptorType ( propertyType ) { var globalTypedPropertyDescriptorType = getGlobalTypedPropertyDescriptorType ( ) ; return globalTypedPropertyDescriptorType !== emptyGenericType ? createTypeReference ( globalTypedPropertyDescriptorType , [ propertyType ] ) : emptyObjectType ; }


Input: 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 . [CODESPLIT] function addTypesToSet ( typeSet , types , typeSetKind ) { for ( var _i = 0 ; _i < types . length ; _i ++ ) { var type = types [ _i ] ; addTypeToSet ( typeSet , type , typeSetKind ) ; } }


Input: We reduce the constituent type set to only include types that aren t subtypes of other types unless the noSubtypeReduction flag is specified in which case we perform a simple deduplication based on object identity . Subtype reduction is possible only when union types are known not to circularly reference themselves ( as is the case with union types created by expression constructs such as array literals and the || and ? : operators ) . Named types can circularly reference themselves and therefore cannot be deduplicated during their declaration . For example type Item = string | (( ) = > Item is a named type that circularly references itself . [CODESPLIT] function getUnionType ( types , noSubtypeReduction ) { if ( types . length === 0 ) { return emptyObjectType ; } var typeSet = [ ] ; addTypesToSet ( typeSet , types , 16384 /* Union */ ) ; if ( containsTypeAny ( typeSet ) ) { return anyType ; } if ( noSubtypeReduction ) { removeAllButLast ( typeSet , undefinedType ) ; removeAllButLast ( typeSet , nullType ) ; } else { removeSubtypes ( typeSet ) ; } if ( typeSet . length === 1 ) { return typeSet [ 0 ] ; } var id = getTypeListId ( typeSet ) ; var type = unionTypes [ id ] ; if ( ! type ) { type = unionTypes [ id ] = createObjectType ( 16384 /* Union */ | getPropagatingFlagsOfTypes ( typeSet ) ) ; type . types = typeSet ; } return type ; }


Input: We do not perform structural deduplication on intersection types . Intersection types are created only by the & type operator and we can t reduce those because we want to support recursive intersection types . For example a type alias of the form type List<T > = T & { next : List<T > } cannot be reduced during its declaration . Also unlike union types the order of the constituent types is preserved in order that overload resolution for intersections of types with signatures can be deterministic . [CODESPLIT] function getIntersectionType ( types ) { if ( types . length === 0 ) { return emptyObjectType ; } var typeSet = [ ] ; addTypesToSet ( typeSet , types , 32768 /* Intersection */ ) ; if ( containsTypeAny ( typeSet ) ) { return anyType ; } if ( typeSet . length === 1 ) { return typeSet [ 0 ] ; } var id = getTypeListId ( typeSet ) ; var type = intersectionTypes [ id ] ; if ( ! type ) { type = intersectionTypes [ id ] = createObjectType ( 32768 /* Intersection */ | getPropagatingFlagsOfTypes ( typeSet ) ) ; type . types = typeSet ; } return type ; }