/Users/cevek/Dev/github/v8_IR_Analizer/node_modules/typescript/lib/typescript.js
isLineBreak:
(ch) { // ES5 7.3: // The ECMAScript line terminator characters are listed in Table 3. // Table 3: Line Terminator Characters // Code Unit Value Name Formal Name // \x5cu000A Line Feed <LF> // \x5cu000D Carriage Return <CR> // \x5cu2028 Line separator <LS> // \x5cu2029 Paragraph separator <PS> // Only the characters in Table 3 are treated as line terminators. Other new line or line // breaking characters are treated as white space but not as line terminators. return ch === 10 /* lineFeed */ || ch === 13 /* carriageReturn */ || ch === 8232 /* lineSeparator */ || ch === 8233 /* paragraphSeparator */; }
token:
() { return currentToken; }
nextToken:
() { return currentToken = scanner.scan(); }
parseOptional:
(t) { if (token() === t) { nextToken(); return true; } return false; }
getStartPos:
() { return startPos; }
isIdentifierPart:
(ch, languageVersion) { return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ || ch >= 48 /* _0 */ && ch <= 57 /* _9 */ || ch === 36 /* $ */ || ch === 95 /* _ */ || ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierPart(ch, languageVersion); }
scan:
() { startPos = pos; hasExtendedUnicodeEscape = false; precedingLineBreak = false; tokenIsUnterminated = false; while (true) { tokenPos = pos; if (pos >= end) { return token = 1 /* EndOfFileToken */; } var ch = text.charCodeAt(pos); // Special handling for shebang if (ch === 35 /* hash */ && pos === 0 && isShebangTrivia(text, pos)) { pos = scanShebangTrivia(text, pos); if (skipTrivia) { continue; } else { return token = 6 /* ShebangTrivia */; } } switch (ch) { case 10 /* lineFeed */: case 13 /* carriageReturn */: precedingLineBreak = true; if (skipTrivia) { pos++; continue; } else { if (ch === 13 /* carriageReturn */ && pos + 1 < end && text.charCodeAt(pos + 1) === 10 /* lineFeed */) { // consume both CR and LF pos += 2; } else { pos++; } return token = 4 /* NewLineTrivia */; } case 9 /* tab */: case 11 /* verticalTab */: case 12 /* formFeed */: case 32 /* space */: if (skipTrivia) { pos++; continue; } else { while (pos < end && isWhiteSpaceSingleLine(text.charCodeAt(pos))) { pos++; } return token = 5 /* WhitespaceTrivia */; } case 33 /* exclamation */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 34 /* ExclamationEqualsEqualsToken */; } return pos += 2, token = 32 /* ExclamationEqualsToken */; } pos++; return token = 50 /* ExclamationToken */; case 34 /* doubleQuote */: case 39 /* singleQuote */: tokenValue = scanString(); return token = 9 /* StringLiteral */; case 96 /* backtick */: return token = scanTemplateAndSetTokenValue(); case 37 /* percent */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 63 /* PercentEqualsToken */; } pos++; return token = 41 /* PercentToken */; case 38 /* ampersand */: if (text.charCodeAt(pos + 1) === 38 /* ampersand */) { return pos += 2, token = 52 /* AmpersandAmpersandToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 67 /* AmpersandEqualsToken */; } pos++; return token = 47 /* AmpersandToken */; case 40 /* openParen */: pos++; return token = 18 /* OpenParenToken */; case 41 /* closeParen */: pos++; return token = 19 /* CloseParenToken */; case 42 /* asterisk */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 60 /* AsteriskEqualsToken */; } if (text.charCodeAt(pos + 1) === 42 /* asterisk */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 61 /* AsteriskAsteriskEqualsToken */; } return pos += 2, token = 39 /* AsteriskAsteriskToken */; } pos++; return token = 38 /* AsteriskToken */; case 43 /* plus */: if (text.charCodeAt(pos + 1) === 43 /* plus */) { return pos += 2, token = 42 /* PlusPlusToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 58 /* PlusEqualsToken */; } pos++; return token = 36 /* PlusToken */; case 44 /* comma */: pos++; return token = 25 /* CommaToken */; case 45 /* minus */: if (text.charCodeAt(pos + 1) === 45 /* minus */) { return pos += 2, token = 43 /* MinusMinusToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 59 /* MinusEqualsToken */; } pos++; return token = 37 /* MinusToken */; case 46 /* dot */: if (isDigit(text.charCodeAt(pos + 1))) { tokenValue = scanNumber(); return token = 8 /* NumericLiteral */; } if (text.charCodeAt(pos + 1) === 46 /* dot */ && text.charCodeAt(pos + 2) === 46 /* dot */) { return pos += 3, token = 23 /* DotDotDotToken */; } pos++; return token = 22 /* DotToken */; case 47 /* slash */: // Single-line comment if (text.charCodeAt(pos + 1) === 47 /* slash */) { pos += 2; while (pos < end) { if (isLineBreak(text.charCodeAt(pos))) { break; } pos++; } if (skipTrivia) { continue; } else { return token = 2 /* SingleLineCommentTrivia */; } } // Multi-line comment if (text.charCodeAt(pos + 1) === 42 /* asterisk */) { pos += 2; var commentClosed = false; while (pos < end) { var ch_2 = text.charCodeAt(pos); if (ch_2 === 42 /* asterisk */ && text.charCodeAt(pos + 1) === 47 /* slash */) { pos += 2; commentClosed = true; break; } if (isLineBreak(ch_2)) { precedingLineBreak = true; } pos++; } if (!commentClosed) { error(ts.Diagnostics.Asterisk_Slash_expected); } if (skipTrivia) { continue; } else { tokenIsUnterminated = !commentClosed; return token = 3 /* MultiLineCommentTrivia */; } } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 62 /* SlashEqualsToken */; } pos++; return token = 40 /* SlashToken */; case 48 /* _0 */: if (pos + 2 < end && (text.charCodeAt(pos + 1) === 88 /* X */ || text.charCodeAt(pos + 1) === 120 /* x */)) { pos += 2; var value = scanMinimumNumberOfHexDigits(1); if (value < 0) { error(ts.Diagnostics.Hexadecimal_digit_expected); value = 0; } tokenValue = "" + value; return token = 8 /* NumericLiteral */; } else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 66 /* B */ || text.charCodeAt(pos + 1) === 98 /* b */)) { pos += 2; var value = scanBinaryOrOctalDigits(/* base */ 2); if (value < 0) { error(ts.Diagnostics.Binary_digit_expected); value = 0; } tokenValue = "" + value; return token = 8 /* NumericLiteral */; } else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 79 /* O */ || text.charCodeAt(pos + 1) === 111 /* o */)) { pos += 2; var value = scanBinaryOrOctalDigits(/* base */ 8); if (value < 0) { error(ts.Diagnostics.Octal_digit_expected); value = 0; } tokenValue = "" + value; return token = 8 /* NumericLiteral */; } // Try to parse as an octal if (pos + 1 < end && isOctalDigit(text.charCodeAt(pos + 1))) { tokenValue = "" + scanOctalDigits(); return token = 8 /* NumericLiteral */; } // This fall-through is a deviation from the EcmaScript grammar. The grammar says that a leading zero // can only be followed by an octal digit, a dot, or the end of the number literal. However, we are being // permissive and allowing decimal digits of the form 08* and 09* (which many browsers also do). case 49 /* _1 */: case 50 /* _2 */: case 51 /* _3 */: case 52 /* _4 */: case 53 /* _5 */: case 54 /* _6 */: case 55 /* _7 */: case 56 /* _8 */: case 57 /* _9 */: tokenValue = scanNumber(); return token = 8 /* NumericLiteral */; case 58 /* colon */: pos++; return token = 55 /* ColonToken */; case 59 /* semicolon */: pos++; return token = 24 /* SemicolonToken */; case 60 /* lessThan */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } else { return token = 7 /* ConflictMarkerTrivia */; } } if (text.charCodeAt(pos + 1) === 60 /* lessThan */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 64 /* LessThanLessThanEqualsToken */; } return pos += 2, token = 44 /* LessThanLessThanToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 29 /* LessThanEqualsToken */; } if (languageVariant === 1 /* JSX */ && text.charCodeAt(pos + 1) === 47 /* slash */ && text.charCodeAt(pos + 2) !== 42 /* asterisk */) { return pos += 2, token = 27 /* LessThanSlashToken */; } pos++; return token = 26 /* LessThanToken */; case 61 /* equals */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } else { return token = 7 /* ConflictMarkerTrivia */; } } if (text.charCodeAt(pos + 1) === 61 /* equals */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 33 /* EqualsEqualsEqualsToken */; } return pos += 2, token = 31 /* EqualsEqualsToken */; } if (text.charCodeAt(pos + 1) === 62 /* greaterThan */) { return pos += 2, token = 35 /* EqualsGreaterThanToken */; } pos++; return token = 57 /* EqualsToken */; case 62 /* greaterThan */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } else { return token = 7 /* ConflictMarkerTrivia */; } } pos++; return token = 28 /* GreaterThanToken */; case 63 /* question */: pos++; return token = 54 /* QuestionToken */; case 91 /* openBracket */: pos++; return token = 20 /* OpenBracketToken */; case 93 /* closeBracket */: pos++; return token = 21 /* CloseBracketToken */; case 94 /* caret */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 69 /* CaretEqualsToken */; } pos++; return token = 49 /* CaretToken */; case 123 /* openBrace */: pos++; return token = 16 /* OpenBraceToken */; case 124 /* bar */: if (text.charCodeAt(pos + 1) === 124 /* bar */) { return pos += 2, token = 53 /* BarBarToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 68 /* BarEqualsToken */; } pos++; return token = 48 /* BarToken */; case 125 /* closeBrace */: pos++; return token = 17 /* CloseBraceToken */; case 126 /* tilde */: pos++; return token = 51 /* TildeToken */; case 64 /* at */: pos++; return token = 56 /* AtToken */; case 92 /* backslash */: var cookedChar = peekUnicodeEscape(); if (cookedChar >= 0 && isIdentifierStart(cookedChar, languageVersion)) { pos += 6; tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts(); return token = getIdentifierToken(); } error(ts.Diagnostics.Invalid_character); pos++; return token = 0 /* Unknown */; default: if (isIdentifierStart(ch, languageVersion)) { pos++; while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos), languageVersion)) pos++; tokenValue = text.substring(tokenPos, pos); if (ch === 92 /* backslash */) { tokenValue += scanIdentifierParts(); } return token = getIdentifierToken(); } else if (isWhiteSpaceSingleLine(ch)) { pos++; continue; } else if (isLineBreak(ch)) { precedingLineBreak = true; pos++; continue; } error(ts.Diagnostics.Invalid_character); pos++; return token = 0 /* Unknown */; } } }
() { startPos = pos; hasExtendedUnicodeEscape = false; precedingLineBreak = false; tokenIsUnterminated = false; while (true) { tokenPos = pos; if (pos >= end) { return token = 1 /* EndOfFileToken */; } var ch = text.charCodeAt(pos); // Special handling for shebang if (ch === 35 /* hash */ && pos === 0 && isShebangTrivia(text, pos)) { pos = scanShebangTrivia(text, pos); if (skipTrivia) { continue; } else { return token = 6 /* ShebangTrivia */; } } switch (ch) { case 10 /* lineFeed */: case 13 /* carriageReturn */: precedingLineBreak = true; if (skipTrivia) { pos++; continue; } else { if (ch === 13 /* carriageReturn */ && pos + 1 < end && text.charCodeAt(pos + 1) === 10 /* lineFeed */) { // consume both CR and LF pos += 2; } else { pos++; } return token = 4 /* NewLineTrivia */; } case 9 /* tab */: case 11 /* verticalTab */: case 12 /* formFeed */: case 32 /* space */: if (skipTrivia) { pos++; continue; } else { while (pos < end && isWhiteSpaceSingleLine(text.charCodeAt(pos))) { pos++; } return token = 5 /* WhitespaceTrivia */; } case 33 /* exclamation */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 34 /* ExclamationEqualsEqualsToken */; } return pos += 2, token = 32 /* ExclamationEqualsToken */; } pos++; return token = 50 /* ExclamationToken */; case 34 /* doubleQuote */: case 39 /* singleQuote */: tokenValue = scanString(); return token = 9 /* StringLiteral */; case 96 /* backtick */: return token = scanTemplateAndSetTokenValue(); case 37 /* percent */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 63 /* PercentEqualsToken */; } pos++; return token = 41 /* PercentToken */; case 38 /* ampersand */: if (text.charCodeAt(pos + 1) === 38 /* ampersand */) { return pos += 2, token = 52 /* AmpersandAmpersandToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 67 /* AmpersandEqualsToken */; } pos++; return token = 47 /* AmpersandToken */; case 40 /* openParen */: pos++; return token = 18 /* OpenParenToken */; case 41 /* closeParen */: pos++; return token = 19 /* CloseParenToken */; case 42 /* asterisk */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 60 /* AsteriskEqualsToken */; } if (text.charCodeAt(pos + 1) === 42 /* asterisk */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 61 /* AsteriskAsteriskEqualsToken */; } return pos += 2, token = 39 /* AsteriskAsteriskToken */; } pos++; return token = 38 /* AsteriskToken */; case 43 /* plus */: if (text.charCodeAt(pos + 1) === 43 /* plus */) { return pos += 2, token = 42 /* PlusPlusToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 58 /* PlusEqualsToken */; } pos++; return token = 36 /* PlusToken */; case 44 /* comma */: pos++; return token = 25 /* CommaToken */; case 45 /* minus */: if (text.charCodeAt(pos + 1) === 45 /* minus */) { return pos += 2, token = 43 /* MinusMinusToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 59 /* MinusEqualsToken */; } pos++; return token = 37 /* MinusToken */; case 46 /* dot */: if (isDigit(text.charCodeAt(pos + 1))) { tokenValue = scanNumber(); return token = 8 /* NumericLiteral */; } if (text.charCodeAt(pos + 1) === 46 /* dot */ && text.charCodeAt(pos + 2) === 46 /* dot */) { return pos += 3, token = 23 /* DotDotDotToken */; } pos++; return token = 22 /* DotToken */; case 47 /* slash */: // Single-line comment if (text.charCodeAt(pos + 1) === 47 /* slash */) { pos += 2; while (pos < end) { if (isLineBreak(text.charCodeAt(pos))) { break; } pos++; } if (skipTrivia) { continue; } else { return token = 2 /* SingleLineCommentTrivia */; } } // Multi-line comment if (text.charCodeAt(pos + 1) === 42 /* asterisk */) { pos += 2; var commentClosed = false; while (pos < end) { var ch_2 = text.charCodeAt(pos); if (ch_2 === 42 /* asterisk */ && text.charCodeAt(pos + 1) === 47 /* slash */) { pos += 2; commentClosed = true; break; } if (isLineBreak(ch_2)) { precedingLineBreak = true; } pos++; } if (!commentClosed) { error(ts.Diagnostics.Asterisk_Slash_expected); } if (skipTrivia) { continue; } else { tokenIsUnterminated = !commentClosed; return token = 3 /* MultiLineCommentTrivia */; } } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 62 /* SlashEqualsToken */; } pos++; return token = 40 /* SlashToken */; case 48 /* _0 */: if (pos + 2 < end && (text.charCodeAt(pos + 1) === 88 /* X */ || text.charCodeAt(pos + 1) === 120 /* x */)) { pos += 2; var value = scanMinimumNumberOfHexDigits(1); if (value < 0) { error(ts.Diagnostics.Hexadecimal_digit_expected); value = 0; } tokenValue = "" + value; return token = 8 /* NumericLiteral */; } else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 66 /* B */ || text.charCodeAt(pos + 1) === 98 /* b */)) { pos += 2; var value = scanBinaryOrOctalDigits(/* base */ 2); if (value < 0) { error(ts.Diagnostics.Binary_digit_expected); value = 0; } tokenValue = "" + value; return token = 8 /* NumericLiteral */; } else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 79 /* O */ || text.charCodeAt(pos + 1) === 111 /* o */)) { pos += 2; var value = scanBinaryOrOctalDigits(/* base */ 8); if (value < 0) { error(ts.Diagnostics.Octal_digit_expected); value = 0; } tokenValue = "" + value; return token = 8 /* NumericLiteral */; } // Try to parse as an octal if (pos + 1 < end && isOctalDigit(text.charCodeAt(pos + 1))) { tokenValue = "" + scanOctalDigits(); return token = 8 /* NumericLiteral */; } // This fall-through is a deviation from the EcmaScript grammar. The grammar says that a leading zero // can only be followed by an octal digit, a dot, or the end of the number literal. However, we are being // permissive and allowing decimal digits of the form 08* and 09* (which many browsers also do). case 49 /* _1 */: case 50 /* _2 */: case 51 /* _3 */: case 52 /* _4 */: case 53 /* _5 */: case 54 /* _6 */: case 55 /* _7 */: case 56 /* _8 */: case 57 /* _9 */: tokenValue = scanNumber(); return token = 8 /* NumericLiteral */; case 58 /* colon */: pos++; return token = 55 /* ColonToken */; case 59 /* semicolon */: pos++; return token = 24 /* SemicolonToken */; case 60 /* lessThan */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } else { return token = 7 /* ConflictMarkerTrivia */; } } if (text.charCodeAt(pos + 1) === 60 /* lessThan */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 64 /* LessThanLessThanEqualsToken */; } return pos += 2, token = 44 /* LessThanLessThanToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 29 /* LessThanEqualsToken */; } if (languageVariant === 1 /* JSX */ && text.charCodeAt(pos + 1) === 47 /* slash */ && text.charCodeAt(pos + 2) !== 42 /* asterisk */) { return pos += 2, token = 27 /* LessThanSlashToken */; } pos++; return token = 26 /* LessThanToken */; case 61 /* equals */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } else { return token = 7 /* ConflictMarkerTrivia */; } } if (text.charCodeAt(pos + 1) === 61 /* equals */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 33 /* EqualsEqualsEqualsToken */; } return pos += 2, token = 31 /* EqualsEqualsToken */; } if (text.charCodeAt(pos + 1) === 62 /* greaterThan */) { return pos += 2, token = 35 /* EqualsGreaterThanToken */; } pos++; return token = 57 /* EqualsToken */; case 62 /* greaterThan */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } else { return token = 7 /* ConflictMarkerTrivia */; } } pos++; return token = 28 /* GreaterThanToken */; case 63 /* question */: pos++; return token = 54 /* QuestionToken */; case 91 /* openBracket */: pos++; return token = 20 /* OpenBracketToken */; case 93 /* closeBracket */: pos++; return token = 21 /* CloseBracketToken */; case 94 /* caret */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 69 /* CaretEqualsToken */; } pos++; return token = 49 /* CaretToken */; case 123 /* openBrace */: pos++; return token = 16 /* OpenBraceToken */; case 124 /* bar */: if (text.charCodeAt(pos + 1) === 124 /* bar */) { return pos += 2, token = 53 /* BarBarToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 68 /* BarEqualsToken */; } pos++; return token = 48 /* BarToken */; case 125 /* closeBrace */: pos++; return token = 17 /* CloseBraceToken */; case 126 /* tilde */: pos++; return token = 51 /* TildeToken */; case 64 /* at */: pos++; return token = 56 /* AtToken */; case 92 /* backslash */: var cookedChar = peekUnicodeEscape(); if (cookedChar >= 0 && isIdentifierStart(cookedChar, languageVersion)) { pos += 6; tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts(); return token = getIdentifierToken(); } error(ts.Diagnostics.Invalid_character); pos++; return token = 0 /* Unknown */; default: if (isIdentifierStart(ch, languageVersion)) { pos++; while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos), languageVersion)) pos++; tokenValue = text.substring(tokenPos, pos); if (ch === 92 /* backslash */) { tokenValue += scanIdentifierParts(); } return token = getIdentifierToken(); } else if (isWhiteSpaceSingleLine(ch)) { pos++; continue; } else if (isLineBreak(ch)) { precedingLineBreak = true; pos++; continue; } error(ts.Diagnostics.Invalid_character); pos++; return token = 0 /* Unknown */; } } }
() { startPos = pos; hasExtendedUnicodeEscape = false; precedingLineBreak = false; tokenIsUnterminated = false; while (true) { tokenPos = pos; if (pos >= end) { return token = 1 /* EndOfFileToken */; } var ch = text.charCodeAt(pos); // Special handling for shebang if (ch === 35 /* hash */ && pos === 0 && isShebangTrivia(text, pos)) { pos = scanShebangTrivia(text, pos); if (skipTrivia) { continue; } else { return token = 6 /* ShebangTrivia */; } } switch (ch) { case 10 /* lineFeed */: case 13 /* carriageReturn */: precedingLineBreak = true; if (skipTrivia) { pos++; continue; } else { if (ch === 13 /* carriageReturn */ && pos + 1 < end && text.charCodeAt(pos + 1) === 10 /* lineFeed */) { // consume both CR and LF pos += 2; } else { pos++; } return token = 4 /* NewLineTrivia */; } case 9 /* tab */: case 11 /* verticalTab */: case 12 /* formFeed */: case 32 /* space */: if (skipTrivia) { pos++; continue; } else { while (pos < end && isWhiteSpaceSingleLine(text.charCodeAt(pos))) { pos++; } return token = 5 /* WhitespaceTrivia */; } case 33 /* exclamation */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 34 /* ExclamationEqualsEqualsToken */; } return pos += 2, token = 32 /* ExclamationEqualsToken */; } pos++; return token = 50 /* ExclamationToken */; case 34 /* doubleQuote */: case 39 /* singleQuote */: tokenValue = scanString(); return token = 9 /* StringLiteral */; case 96 /* backtick */: return token = scanTemplateAndSetTokenValue(); case 37 /* percent */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 63 /* PercentEqualsToken */; } pos++; return token = 41 /* PercentToken */; case 38 /* ampersand */: if (text.charCodeAt(pos + 1) === 38 /* ampersand */) { return pos += 2, token = 52 /* AmpersandAmpersandToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 67 /* AmpersandEqualsToken */; } pos++; return token = 47 /* AmpersandToken */; case 40 /* openParen */: pos++; return token = 18 /* OpenParenToken */; case 41 /* closeParen */: pos++; return token = 19 /* CloseParenToken */; case 42 /* asterisk */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 60 /* AsteriskEqualsToken */; } if (text.charCodeAt(pos + 1) === 42 /* asterisk */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 61 /* AsteriskAsteriskEqualsToken */; } return pos += 2, token = 39 /* AsteriskAsteriskToken */; } pos++; return token = 38 /* AsteriskToken */; case 43 /* plus */: if (text.charCodeAt(pos + 1) === 43 /* plus */) { return pos += 2, token = 42 /* PlusPlusToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 58 /* PlusEqualsToken */; } pos++; return token = 36 /* PlusToken */; case 44 /* comma */: pos++; return token = 25 /* CommaToken */; case 45 /* minus */: if (text.charCodeAt(pos + 1) === 45 /* minus */) { return pos += 2, token = 43 /* MinusMinusToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 59 /* MinusEqualsToken */; } pos++; return token = 37 /* MinusToken */; case 46 /* dot */: if (isDigit(text.charCodeAt(pos + 1))) { tokenValue = scanNumber(); return token = 8 /* NumericLiteral */; } if (text.charCodeAt(pos + 1) === 46 /* dot */ && text.charCodeAt(pos + 2) === 46 /* dot */) { return pos += 3, token = 23 /* DotDotDotToken */; } pos++; return token = 22 /* DotToken */; case 47 /* slash */: // Single-line comment if (text.charCodeAt(pos + 1) === 47 /* slash */) { pos += 2; while (pos < end) { if (isLineBreak(text.charCodeAt(pos))) { break; } pos++; } if (skipTrivia) { continue; } else { return token = 2 /* SingleLineCommentTrivia */; } } // Multi-line comment if (text.charCodeAt(pos + 1) === 42 /* asterisk */) { pos += 2; var commentClosed = false; while (pos < end) { var ch_2 = text.charCodeAt(pos); if (ch_2 === 42 /* asterisk */ && text.charCodeAt(pos + 1) === 47 /* slash */) { pos += 2; commentClosed = true; break; } if (isLineBreak(ch_2)) { precedingLineBreak = true; } pos++; } if (!commentClosed) { error(ts.Diagnostics.Asterisk_Slash_expected); } if (skipTrivia) { continue; } else { tokenIsUnterminated = !commentClosed; return token = 3 /* MultiLineCommentTrivia */; } } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 62 /* SlashEqualsToken */; } pos++; return token = 40 /* SlashToken */; case 48 /* _0 */: if (pos + 2 < end && (text.charCodeAt(pos + 1) === 88 /* X */ || text.charCodeAt(pos + 1) === 120 /* x */)) { pos += 2; var value = scanMinimumNumberOfHexDigits(1); if (value < 0) { error(ts.Diagnostics.Hexadecimal_digit_expected); value = 0; } tokenValue = "" + value; return token = 8 /* NumericLiteral */; } else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 66 /* B */ || text.charCodeAt(pos + 1) === 98 /* b */)) { pos += 2; var value = scanBinaryOrOctalDigits(/* base */ 2); if (value < 0) { error(ts.Diagnostics.Binary_digit_expected); value = 0; } tokenValue = "" + value; return token = 8 /* NumericLiteral */; } else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 79 /* O */ || text.charCodeAt(pos + 1) === 111 /* o */)) { pos += 2; var value = scanBinaryOrOctalDigits(/* base */ 8); if (value < 0) { error(ts.Diagnostics.Octal_digit_expected); value = 0; } tokenValue = "" + value; return token = 8 /* NumericLiteral */; } // Try to parse as an octal if (pos + 1 < end && isOctalDigit(text.charCodeAt(pos + 1))) { tokenValue = "" + scanOctalDigits(); return token = 8 /* NumericLiteral */; } // This fall-through is a deviation from the EcmaScript grammar. The grammar says that a leading zero // can only be followed by an octal digit, a dot, or the end of the number literal. However, we are being // permissive and allowing decimal digits of the form 08* and 09* (which many browsers also do). case 49 /* _1 */: case 50 /* _2 */: case 51 /* _3 */: case 52 /* _4 */: case 53 /* _5 */: case 54 /* _6 */: case 55 /* _7 */: case 56 /* _8 */: case 57 /* _9 */: tokenValue = scanNumber(); return token = 8 /* NumericLiteral */; case 58 /* colon */: pos++; return token = 55 /* ColonToken */; case 59 /* semicolon */: pos++; return token = 24 /* SemicolonToken */; case 60 /* lessThan */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } else { return token = 7 /* ConflictMarkerTrivia */; } } if (text.charCodeAt(pos + 1) === 60 /* lessThan */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 64 /* LessThanLessThanEqualsToken */; } return pos += 2, token = 44 /* LessThanLessThanToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 29 /* LessThanEqualsToken */; } if (languageVariant === 1 /* JSX */ && text.charCodeAt(pos + 1) === 47 /* slash */ && text.charCodeAt(pos + 2) !== 42 /* asterisk */) { return pos += 2, token = 27 /* LessThanSlashToken */; } pos++; return token = 26 /* LessThanToken */; case 61 /* equals */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } else { return token = 7 /* ConflictMarkerTrivia */; } } if (text.charCodeAt(pos + 1) === 61 /* equals */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 33 /* EqualsEqualsEqualsToken */; } return pos += 2, token = 31 /* EqualsEqualsToken */; } if (text.charCodeAt(pos + 1) === 62 /* greaterThan */) { return pos += 2, token = 35 /* EqualsGreaterThanToken */; } pos++; return token = 57 /* EqualsToken */; case 62 /* greaterThan */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } else { return token = 7 /* ConflictMarkerTrivia */; } } pos++; return token = 28 /* GreaterThanToken */; case 63 /* question */: pos++; return token = 54 /* QuestionToken */; case 91 /* openBracket */: pos++; return token = 20 /* OpenBracketToken */; case 93 /* closeBracket */: pos++; return token = 21 /* CloseBracketToken */; case 94 /* caret */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 69 /* CaretEqualsToken */; } pos++; return token = 49 /* CaretToken */; case 123 /* openBrace */: pos++; return token = 16 /* OpenBraceToken */; case 124 /* bar */: if (text.charCodeAt(pos + 1) === 124 /* bar */) { return pos += 2, token = 53 /* BarBarToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 68 /* BarEqualsToken */; } pos++; return token = 48 /* BarToken */; case 125 /* closeBrace */: pos++; return token = 17 /* CloseBraceToken */; case 126 /* tilde */: pos++; return token = 51 /* TildeToken */; case 64 /* at */: pos++; return token = 56 /* AtToken */; case 92 /* backslash */: var cookedChar = peekUnicodeEscape(); if (cookedChar >= 0 && isIdentifierStart(cookedChar, languageVersion)) { pos += 6; tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts(); return token = getIdentifierToken(); } error(ts.Diagnostics.Invalid_character); pos++; return token = 0 /* Unknown */; default: if (isIdentifierStart(ch, languageVersion)) { pos++; while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos), languageVersion)) pos++; tokenValue = text.substring(tokenPos, pos); if (ch === 92 /* backslash */) { tokenValue += scanIdentifierParts(); } return token = getIdentifierToken(); } else if (isWhiteSpaceSingleLine(ch)) { pos++; continue; } else if (isLineBreak(ch)) { precedingLineBreak = true; pos++; continue; } error(ts.Diagnostics.Invalid_character); pos++; return token = 0 /* Unknown */; } } }
() { startPos = pos; hasExtendedUnicodeEscape = false; precedingLineBreak = false; tokenIsUnterminated = false; while (true) { tokenPos = pos; if (pos >= end) { return token = 1 /* EndOfFileToken */; } var ch = text.charCodeAt(pos); // Special handling for shebang if (ch === 35 /* hash */ && pos === 0 && isShebangTrivia(text, pos)) { pos = scanShebangTrivia(text, pos); if (skipTrivia) { continue; } else { return token = 6 /* ShebangTrivia */; } } switch (ch) { case 10 /* lineFeed */: case 13 /* carriageReturn */: precedingLineBreak = true; if (skipTrivia) { pos++; continue; } else { if (ch === 13 /* carriageReturn */ && pos + 1 < end && text.charCodeAt(pos + 1) === 10 /* lineFeed */) { // consume both CR and LF pos += 2; } else { pos++; } return token = 4 /* NewLineTrivia */; } case 9 /* tab */: case 11 /* verticalTab */: case 12 /* formFeed */: case 32 /* space */: if (skipTrivia) { pos++; continue; } else { while (pos < end && isWhiteSpaceSingleLine(text.charCodeAt(pos))) { pos++; } return token = 5 /* WhitespaceTrivia */; } case 33 /* exclamation */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 34 /* ExclamationEqualsEqualsToken */; } return pos += 2, token = 32 /* ExclamationEqualsToken */; } pos++; return token = 50 /* ExclamationToken */; case 34 /* doubleQuote */: case 39 /* singleQuote */: tokenValue = scanString(); return token = 9 /* StringLiteral */; case 96 /* backtick */: return token = scanTemplateAndSetTokenValue(); case 37 /* percent */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 63 /* PercentEqualsToken */; } pos++; return token = 41 /* PercentToken */; case 38 /* ampersand */: if (text.charCodeAt(pos + 1) === 38 /* ampersand */) { return pos += 2, token = 52 /* AmpersandAmpersandToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 67 /* AmpersandEqualsToken */; } pos++; return token = 47 /* AmpersandToken */; case 40 /* openParen */: pos++; return token = 18 /* OpenParenToken */; case 41 /* closeParen */: pos++; return token = 19 /* CloseParenToken */; case 42 /* asterisk */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 60 /* AsteriskEqualsToken */; } if (text.charCodeAt(pos + 1) === 42 /* asterisk */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 61 /* AsteriskAsteriskEqualsToken */; } return pos += 2, token = 39 /* AsteriskAsteriskToken */; } pos++; return token = 38 /* AsteriskToken */; case 43 /* plus */: if (text.charCodeAt(pos + 1) === 43 /* plus */) { return pos += 2, token = 42 /* PlusPlusToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 58 /* PlusEqualsToken */; } pos++; return token = 36 /* PlusToken */; case 44 /* comma */: pos++; return token = 25 /* CommaToken */; case 45 /* minus */: if (text.charCodeAt(pos + 1) === 45 /* minus */) { return pos += 2, token = 43 /* MinusMinusToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 59 /* MinusEqualsToken */; } pos++; return token = 37 /* MinusToken */; case 46 /* dot */: if (isDigit(text.charCodeAt(pos + 1))) { tokenValue = scanNumber(); return token = 8 /* NumericLiteral */; } if (text.charCodeAt(pos + 1) === 46 /* dot */ && text.charCodeAt(pos + 2) === 46 /* dot */) { return pos += 3, token = 23 /* DotDotDotToken */; } pos++; return token = 22 /* DotToken */; case 47 /* slash */: // Single-line comment if (text.charCodeAt(pos + 1) === 47 /* slash */) { pos += 2; while (pos < end) { if (isLineBreak(text.charCodeAt(pos))) { break; } pos++; } if (skipTrivia) { continue; } else { return token = 2 /* SingleLineCommentTrivia */; } } // Multi-line comment if (text.charCodeAt(pos + 1) === 42 /* asterisk */) { pos += 2; var commentClosed = false; while (pos < end) { var ch_2 = text.charCodeAt(pos); if (ch_2 === 42 /* asterisk */ && text.charCodeAt(pos + 1) === 47 /* slash */) { pos += 2; commentClosed = true; break; } if (isLineBreak(ch_2)) { precedingLineBreak = true; } pos++; } if (!commentClosed) { error(ts.Diagnostics.Asterisk_Slash_expected); } if (skipTrivia) { continue; } else { tokenIsUnterminated = !commentClosed; return token = 3 /* MultiLineCommentTrivia */; } } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 62 /* SlashEqualsToken */; } pos++; return token = 40 /* SlashToken */; case 48 /* _0 */: if (pos + 2 < end && (text.charCodeAt(pos + 1) === 88 /* X */ || text.charCodeAt(pos + 1) === 120 /* x */)) { pos += 2; var value = scanMinimumNumberOfHexDigits(1); if (value < 0) { error(ts.Diagnostics.Hexadecimal_digit_expected); value = 0; } tokenValue = "" + value; return token = 8 /* NumericLiteral */; } else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 66 /* B */ || text.charCodeAt(pos + 1) === 98 /* b */)) { pos += 2; var value = scanBinaryOrOctalDigits(/* base */ 2); if (value < 0) { error(ts.Diagnostics.Binary_digit_expected); value = 0; } tokenValue = "" + value; return token = 8 /* NumericLiteral */; } else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 79 /* O */ || text.charCodeAt(pos + 1) === 111 /* o */)) { pos += 2; var value = scanBinaryOrOctalDigits(/* base */ 8); if (value < 0) { error(ts.Diagnostics.Octal_digit_expected); value = 0; } tokenValue = "" + value; return token = 8 /* NumericLiteral */; } // Try to parse as an octal if (pos + 1 < end && isOctalDigit(text.charCodeAt(pos + 1))) { tokenValue = "" + scanOctalDigits(); return token = 8 /* NumericLiteral */; } // This fall-through is a deviation from the EcmaScript grammar. The grammar says that a leading zero // can only be followed by an octal digit, a dot, or the end of the number literal. However, we are being // permissive and allowing decimal digits of the form 08* and 09* (which many browsers also do). case 49 /* _1 */: case 50 /* _2 */: case 51 /* _3 */: case 52 /* _4 */: case 53 /* _5 */: case 54 /* _6 */: case 55 /* _7 */: case 56 /* _8 */: case 57 /* _9 */: tokenValue = scanNumber(); return token = 8 /* NumericLiteral */; case 58 /* colon */: pos++; return token = 55 /* ColonToken */; case 59 /* semicolon */: pos++; return token = 24 /* SemicolonToken */; case 60 /* lessThan */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } else { return token = 7 /* ConflictMarkerTrivia */; } } if (text.charCodeAt(pos + 1) === 60 /* lessThan */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 64 /* LessThanLessThanEqualsToken */; } return pos += 2, token = 44 /* LessThanLessThanToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 29 /* LessThanEqualsToken */; } if (languageVariant === 1 /* JSX */ && text.charCodeAt(pos + 1) === 47 /* slash */ && text.charCodeAt(pos + 2) !== 42 /* asterisk */) { return pos += 2, token = 27 /* LessThanSlashToken */; } pos++; return token = 26 /* LessThanToken */; case 61 /* equals */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } else { return token = 7 /* ConflictMarkerTrivia */; } } if (text.charCodeAt(pos + 1) === 61 /* equals */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 33 /* EqualsEqualsEqualsToken */; } return pos += 2, token = 31 /* EqualsEqualsToken */; } if (text.charCodeAt(pos + 1) === 62 /* greaterThan */) { return pos += 2, token = 35 /* EqualsGreaterThanToken */; } pos++; return token = 57 /* EqualsToken */; case 62 /* greaterThan */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } else { return token = 7 /* ConflictMarkerTrivia */; } } pos++; return token = 28 /* GreaterThanToken */; case 63 /* question */: pos++; return token = 54 /* QuestionToken */; case 91 /* openBracket */: pos++; return token = 20 /* OpenBracketToken */; case 93 /* closeBracket */: pos++; return token = 21 /* CloseBracketToken */; case 94 /* caret */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 69 /* CaretEqualsToken */; } pos++; return token = 49 /* CaretToken */; case 123 /* openBrace */: pos++; return token = 16 /* OpenBraceToken */; case 124 /* bar */: if (text.charCodeAt(pos + 1) === 124 /* bar */) { return pos += 2, token = 53 /* BarBarToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 68 /* BarEqualsToken */; } pos++; return token = 48 /* BarToken */; case 125 /* closeBrace */: pos++; return token = 17 /* CloseBraceToken */; case 126 /* tilde */: pos++; return token = 51 /* TildeToken */; case 64 /* at */: pos++; return token = 56 /* AtToken */; case 92 /* backslash */: var cookedChar = peekUnicodeEscape(); if (cookedChar >= 0 && isIdentifierStart(cookedChar, languageVersion)) { pos += 6; tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts(); return token = getIdentifierToken(); } error(ts.Diagnostics.Invalid_character); pos++; return token = 0 /* Unknown */; default: if (isIdentifierStart(ch, languageVersion)) { pos++; while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos), languageVersion)) pos++; tokenValue = text.substring(tokenPos, pos); if (ch === 92 /* backslash */) { tokenValue += scanIdentifierParts(); } return token = getIdentifierToken(); } else if (isWhiteSpaceSingleLine(ch)) { pos++; continue; } else if (isLineBreak(ch)) { precedingLineBreak = true; pos++; continue; } error(ts.Diagnostics.Invalid_character); pos++; return token = 0 /* Unknown */; } } }
() { startPos = pos; hasExtendedUnicodeEscape = false; precedingLineBreak = false; tokenIsUnterminated = false; while (true) { tokenPos = pos; if (pos >= end) { return token = 1 /* EndOfFileToken */; } var ch = text.charCodeAt(pos); // Special handling for shebang if (ch === 35 /* hash */ && pos === 0 && isShebangTrivia(text, pos)) { pos = scanShebangTrivia(text, pos); if (skipTrivia) { continue; } else { return token = 6 /* ShebangTrivia */; } } switch (ch) { case 10 /* lineFeed */: case 13 /* carriageReturn */: precedingLineBreak = true; if (skipTrivia) { pos++; continue; } else { if (ch === 13 /* carriageReturn */ && pos + 1 < end && text.charCodeAt(pos + 1) === 10 /* lineFeed */) { // consume both CR and LF pos += 2; } else { pos++; } return token = 4 /* NewLineTrivia */; } case 9 /* tab */: case 11 /* verticalTab */: case 12 /* formFeed */: case 32 /* space */: if (skipTrivia) { pos++; continue; } else { while (pos < end && isWhiteSpaceSingleLine(text.charCodeAt(pos))) { pos++; } return token = 5 /* WhitespaceTrivia */; } case 33 /* exclamation */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 34 /* ExclamationEqualsEqualsToken */; } return pos += 2, token = 32 /* ExclamationEqualsToken */; } pos++; return token = 50 /* ExclamationToken */; case 34 /* doubleQuote */: case 39 /* singleQuote */: tokenValue = scanString(); return token = 9 /* StringLiteral */; case 96 /* backtick */: return token = scanTemplateAndSetTokenValue(); case 37 /* percent */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 63 /* PercentEqualsToken */; } pos++; return token = 41 /* PercentToken */; case 38 /* ampersand */: if (text.charCodeAt(pos + 1) === 38 /* ampersand */) { return pos += 2, token = 52 /* AmpersandAmpersandToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 67 /* AmpersandEqualsToken */; } pos++; return token = 47 /* AmpersandToken */; case 40 /* openParen */: pos++; return token = 18 /* OpenParenToken */; case 41 /* closeParen */: pos++; return token = 19 /* CloseParenToken */; case 42 /* asterisk */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 60 /* AsteriskEqualsToken */; } if (text.charCodeAt(pos + 1) === 42 /* asterisk */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 61 /* AsteriskAsteriskEqualsToken */; } return pos += 2, token = 39 /* AsteriskAsteriskToken */; } pos++; return token = 38 /* AsteriskToken */; case 43 /* plus */: if (text.charCodeAt(pos + 1) === 43 /* plus */) { return pos += 2, token = 42 /* PlusPlusToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 58 /* PlusEqualsToken */; } pos++; return token = 36 /* PlusToken */; case 44 /* comma */: pos++; return token = 25 /* CommaToken */; case 45 /* minus */: if (text.charCodeAt(pos + 1) === 45 /* minus */) { return pos += 2, token = 43 /* MinusMinusToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 59 /* MinusEqualsToken */; } pos++; return token = 37 /* MinusToken */; case 46 /* dot */: if (isDigit(text.charCodeAt(pos + 1))) { tokenValue = scanNumber(); return token = 8 /* NumericLiteral */; } if (text.charCodeAt(pos + 1) === 46 /* dot */ && text.charCodeAt(pos + 2) === 46 /* dot */) { return pos += 3, token = 23 /* DotDotDotToken */; } pos++; return token = 22 /* DotToken */; case 47 /* slash */: // Single-line comment if (text.charCodeAt(pos + 1) === 47 /* slash */) { pos += 2; while (pos < end) { if (isLineBreak(text.charCodeAt(pos))) { break; } pos++; } if (skipTrivia) { continue; } else { return token = 2 /* SingleLineCommentTrivia */; } } // Multi-line comment if (text.charCodeAt(pos + 1) === 42 /* asterisk */) { pos += 2; var commentClosed = false; while (pos < end) { var ch_2 = text.charCodeAt(pos); if (ch_2 === 42 /* asterisk */ && text.charCodeAt(pos + 1) === 47 /* slash */) { pos += 2; commentClosed = true; break; } if (isLineBreak(ch_2)) { precedingLineBreak = true; } pos++; } if (!commentClosed) { error(ts.Diagnostics.Asterisk_Slash_expected); } if (skipTrivia) { continue; } else { tokenIsUnterminated = !commentClosed; return token = 3 /* MultiLineCommentTrivia */; } } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 62 /* SlashEqualsToken */; } pos++; return token = 40 /* SlashToken */; case 48 /* _0 */: if (pos + 2 < end && (text.charCodeAt(pos + 1) === 88 /* X */ || text.charCodeAt(pos + 1) === 120 /* x */)) { pos += 2; var value = scanMinimumNumberOfHexDigits(1); if (value < 0) { error(ts.Diagnostics.Hexadecimal_digit_expected); value = 0; } tokenValue = "" + value; return token = 8 /* NumericLiteral */; } else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 66 /* B */ || text.charCodeAt(pos + 1) === 98 /* b */)) { pos += 2; var value = scanBinaryOrOctalDigits(/* base */ 2); if (value < 0) { error(ts.Diagnostics.Binary_digit_expected); value = 0; } tokenValue = "" + value; return token = 8 /* NumericLiteral */; } else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 79 /* O */ || text.charCodeAt(pos + 1) === 111 /* o */)) { pos += 2; var value = scanBinaryOrOctalDigits(/* base */ 8); if (value < 0) { error(ts.Diagnostics.Octal_digit_expected); value = 0; } tokenValue = "" + value; return token = 8 /* NumericLiteral */; } // Try to parse as an octal if (pos + 1 < end && isOctalDigit(text.charCodeAt(pos + 1))) { tokenValue = "" + scanOctalDigits(); return token = 8 /* NumericLiteral */; } // This fall-through is a deviation from the EcmaScript grammar. The grammar says that a leading zero // can only be followed by an octal digit, a dot, or the end of the number literal. However, we are being // permissive and allowing decimal digits of the form 08* and 09* (which many browsers also do). case 49 /* _1 */: case 50 /* _2 */: case 51 /* _3 */: case 52 /* _4 */: case 53 /* _5 */: case 54 /* _6 */: case 55 /* _7 */: case 56 /* _8 */: case 57 /* _9 */: tokenValue = scanNumber(); return token = 8 /* NumericLiteral */; case 58 /* colon */: pos++; return token = 55 /* ColonToken */; case 59 /* semicolon */: pos++; return token = 24 /* SemicolonToken */; case 60 /* lessThan */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } else { return token = 7 /* ConflictMarkerTrivia */; } } if (text.charCodeAt(pos + 1) === 60 /* lessThan */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 64 /* LessThanLessThanEqualsToken */; } return pos += 2, token = 44 /* LessThanLessThanToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 29 /* LessThanEqualsToken */; } if (languageVariant === 1 /* JSX */ && text.charCodeAt(pos + 1) === 47 /* slash */ && text.charCodeAt(pos + 2) !== 42 /* asterisk */) { return pos += 2, token = 27 /* LessThanSlashToken */; } pos++; return token = 26 /* LessThanToken */; case 61 /* equals */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } else { return token = 7 /* ConflictMarkerTrivia */; } } if (text.charCodeAt(pos + 1) === 61 /* equals */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 33 /* EqualsEqualsEqualsToken */; } return pos += 2, token = 31 /* EqualsEqualsToken */; } if (text.charCodeAt(pos + 1) === 62 /* greaterThan */) { return pos += 2, token = 35 /* EqualsGreaterThanToken */; } pos++; return token = 57 /* EqualsToken */; case 62 /* greaterThan */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } else { return token = 7 /* ConflictMarkerTrivia */; } } pos++; return token = 28 /* GreaterThanToken */; case 63 /* question */: pos++; return token = 54 /* QuestionToken */; case 91 /* openBracket */: pos++; return token = 20 /* OpenBracketToken */; case 93 /* closeBracket */: pos++; return token = 21 /* CloseBracketToken */; case 94 /* caret */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 69 /* CaretEqualsToken */; } pos++; return token = 49 /* CaretToken */; case 123 /* openBrace */: pos++; return token = 16 /* OpenBraceToken */; case 124 /* bar */: if (text.charCodeAt(pos + 1) === 124 /* bar */) { return pos += 2, token = 53 /* BarBarToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 68 /* BarEqualsToken */; } pos++; return token = 48 /* BarToken */; case 125 /* closeBrace */: pos++; return token = 17 /* CloseBraceToken */; case 126 /* tilde */: pos++; return token = 51 /* TildeToken */; case 64 /* at */: pos++; return token = 56 /* AtToken */; case 92 /* backslash */: var cookedChar = peekUnicodeEscape(); if (cookedChar >= 0 && isIdentifierStart(cookedChar, languageVersion)) { pos += 6; tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts(); return token = getIdentifierToken(); } error(ts.Diagnostics.Invalid_character); pos++; return token = 0 /* Unknown */; default: if (isIdentifierStart(ch, languageVersion)) { pos++; while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos), languageVersion)) pos++; tokenValue = text.substring(tokenPos, pos); if (ch === 92 /* backslash */) { tokenValue += scanIdentifierParts(); } return token = getIdentifierToken(); } else if (isWhiteSpaceSingleLine(ch)) { pos++; continue; } else if (isLineBreak(ch)) { precedingLineBreak = true; pos++; continue; } error(ts.Diagnostics.Invalid_character); pos++; return token = 0 /* Unknown */; } } }
() { startPos = pos; hasExtendedUnicodeEscape = false; precedingLineBreak = false; tokenIsUnterminated = false; while (true) { tokenPos = pos; if (pos >= end) { return token = 1 /* EndOfFileToken */; } var ch = text.charCodeAt(pos); // Special handling for shebang if (ch === 35 /* hash */ && pos === 0 && isShebangTrivia(text, pos)) { pos = scanShebangTrivia(text, pos); if (skipTrivia) { continue; } else { return token = 6 /* ShebangTrivia */; } } switch (ch) { case 10 /* lineFeed */: case 13 /* carriageReturn */: precedingLineBreak = true; if (skipTrivia) { pos++; continue; } else { if (ch === 13 /* carriageReturn */ && pos + 1 < end && text.charCodeAt(pos + 1) === 10 /* lineFeed */) { // consume both CR and LF pos += 2; } else { pos++; } return token = 4 /* NewLineTrivia */; } case 9 /* tab */: case 11 /* verticalTab */: case 12 /* formFeed */: case 32 /* space */: if (skipTrivia) { pos++; continue; } else { while (pos < end && isWhiteSpaceSingleLine(text.charCodeAt(pos))) { pos++; } return token = 5 /* WhitespaceTrivia */; } case 33 /* exclamation */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 34 /* ExclamationEqualsEqualsToken */; } return pos += 2, token = 32 /* ExclamationEqualsToken */; } pos++; return token = 50 /* ExclamationToken */; case 34 /* doubleQuote */: case 39 /* singleQuote */: tokenValue = scanString(); return token = 9 /* StringLiteral */; case 96 /* backtick */: return token = scanTemplateAndSetTokenValue(); case 37 /* percent */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 63 /* PercentEqualsToken */; } pos++; return token = 41 /* PercentToken */; case 38 /* ampersand */: if (text.charCodeAt(pos + 1) === 38 /* ampersand */) { return pos += 2, token = 52 /* AmpersandAmpersandToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 67 /* AmpersandEqualsToken */; } pos++; return token = 47 /* AmpersandToken */; case 40 /* openParen */: pos++; return token = 18 /* OpenParenToken */; case 41 /* closeParen */: pos++; return token = 19 /* CloseParenToken */; case 42 /* asterisk */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 60 /* AsteriskEqualsToken */; } if (text.charCodeAt(pos + 1) === 42 /* asterisk */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 61 /* AsteriskAsteriskEqualsToken */; } return pos += 2, token = 39 /* AsteriskAsteriskToken */; } pos++; return token = 38 /* AsteriskToken */; case 43 /* plus */: if (text.charCodeAt(pos + 1) === 43 /* plus */) { return pos += 2, token = 42 /* PlusPlusToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 58 /* PlusEqualsToken */; } pos++; return token = 36 /* PlusToken */; case 44 /* comma */: pos++; return token = 25 /* CommaToken */; case 45 /* minus */: if (text.charCodeAt(pos + 1) === 45 /* minus */) { return pos += 2, token = 43 /* MinusMinusToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 59 /* MinusEqualsToken */; } pos++; return token = 37 /* MinusToken */; case 46 /* dot */: if (isDigit(text.charCodeAt(pos + 1))) { tokenValue = scanNumber(); return token = 8 /* NumericLiteral */; } if (text.charCodeAt(pos + 1) === 46 /* dot */ && text.charCodeAt(pos + 2) === 46 /* dot */) { return pos += 3, token = 23 /* DotDotDotToken */; } pos++; return token = 22 /* DotToken */; case 47 /* slash */: // Single-line comment if (text.charCodeAt(pos + 1) === 47 /* slash */) { pos += 2; while (pos < end) { if (isLineBreak(text.charCodeAt(pos))) { break; } pos++; } if (skipTrivia) { continue; } else { return token = 2 /* SingleLineCommentTrivia */; } } // Multi-line comment if (text.charCodeAt(pos + 1) === 42 /* asterisk */) { pos += 2; var commentClosed = false; while (pos < end) { var ch_2 = text.charCodeAt(pos); if (ch_2 === 42 /* asterisk */ && text.charCodeAt(pos + 1) === 47 /* slash */) { pos += 2; commentClosed = true; break; } if (isLineBreak(ch_2)) { precedingLineBreak = true; } pos++; } if (!commentClosed) { error(ts.Diagnostics.Asterisk_Slash_expected); } if (skipTrivia) { continue; } else { tokenIsUnterminated = !commentClosed; return token = 3 /* MultiLineCommentTrivia */; } } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 62 /* SlashEqualsToken */; } pos++; return token = 40 /* SlashToken */; case 48 /* _0 */: if (pos + 2 < end && (text.charCodeAt(pos + 1) === 88 /* X */ || text.charCodeAt(pos + 1) === 120 /* x */)) { pos += 2; var value = scanMinimumNumberOfHexDigits(1); if (value < 0) { error(ts.Diagnostics.Hexadecimal_digit_expected); value = 0; } tokenValue = "" + value; return token = 8 /* NumericLiteral */; } else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 66 /* B */ || text.charCodeAt(pos + 1) === 98 /* b */)) { pos += 2; var value = scanBinaryOrOctalDigits(/* base */ 2); if (value < 0) { error(ts.Diagnostics.Binary_digit_expected); value = 0; } tokenValue = "" + value; return token = 8 /* NumericLiteral */; } else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 79 /* O */ || text.charCodeAt(pos + 1) === 111 /* o */)) { pos += 2; var value = scanBinaryOrOctalDigits(/* base */ 8); if (value < 0) { error(ts.Diagnostics.Octal_digit_expected); value = 0; } tokenValue = "" + value; return token = 8 /* NumericLiteral */; } // Try to parse as an octal if (pos + 1 < end && isOctalDigit(text.charCodeAt(pos + 1))) { tokenValue = "" + scanOctalDigits(); return token = 8 /* NumericLiteral */; } // This fall-through is a deviation from the EcmaScript grammar. The grammar says that a leading zero // can only be followed by an octal digit, a dot, or the end of the number literal. However, we are being // permissive and allowing decimal digits of the form 08* and 09* (which many browsers also do). case 49 /* _1 */: case 50 /* _2 */: case 51 /* _3 */: case 52 /* _4 */: case 53 /* _5 */: case 54 /* _6 */: case 55 /* _7 */: case 56 /* _8 */: case 57 /* _9 */: tokenValue = scanNumber(); return token = 8 /* NumericLiteral */; case 58 /* colon */: pos++; return token = 55 /* ColonToken */; case 59 /* semicolon */: pos++; return token = 24 /* SemicolonToken */; case 60 /* lessThan */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } else { return token = 7 /* ConflictMarkerTrivia */; } } if (text.charCodeAt(pos + 1) === 60 /* lessThan */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 64 /* LessThanLessThanEqualsToken */; } return pos += 2, token = 44 /* LessThanLessThanToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 29 /* LessThanEqualsToken */; } if (languageVariant === 1 /* JSX */ && text.charCodeAt(pos + 1) === 47 /* slash */ && text.charCodeAt(pos + 2) !== 42 /* asterisk */) { return pos += 2, token = 27 /* LessThanSlashToken */; } pos++; return token = 26 /* LessThanToken */; case 61 /* equals */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } else { return token = 7 /* ConflictMarkerTrivia */; } } if (text.charCodeAt(pos + 1) === 61 /* equals */) { if (text.charCodeAt(pos + 2) === 61 /* equals */) { return pos += 3, token = 33 /* EqualsEqualsEqualsToken */; } return pos += 2, token = 31 /* EqualsEqualsToken */; } if (text.charCodeAt(pos + 1) === 62 /* greaterThan */) { return pos += 2, token = 35 /* EqualsGreaterThanToken */; } pos++; return token = 57 /* EqualsToken */; case 62 /* greaterThan */: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); if (skipTrivia) { continue; } else { return token = 7 /* ConflictMarkerTrivia */; } } pos++; return token = 28 /* GreaterThanToken */; case 63 /* question */: pos++; return token = 54 /* QuestionToken */; case 91 /* openBracket */: pos++; return token = 20 /* OpenBracketToken */; case 93 /* closeBracket */: pos++; return token = 21 /* CloseBracketToken */; case 94 /* caret */: if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 69 /* CaretEqualsToken */; } pos++; return token = 49 /* CaretToken */; case 123 /* openBrace */: pos++; return token = 16 /* OpenBraceToken */; case 124 /* bar */: if (text.charCodeAt(pos + 1) === 124 /* bar */) { return pos += 2, token = 53 /* BarBarToken */; } if (text.charCodeAt(pos + 1) === 61 /* equals */) { return pos += 2, token = 68 /* BarEqualsToken */; } pos++; return token = 48 /* BarToken */; case 125 /* closeBrace */: pos++; return token = 17 /* CloseBraceToken */; case 126 /* tilde */: pos++; return token = 51 /* TildeToken */; case 64 /* at */: pos++; return token = 56 /* AtToken */; case 92 /* backslash */: var cookedChar = peekUnicodeEscape(); if (cookedChar >= 0 && isIdentifierStart(cookedChar, languageVersion)) { pos += 6; tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts(); return token = getIdentifierToken(); } error(ts.Diagnostics.Invalid_character); pos++; return token = 0 /* Unknown */; default: if (isIdentifierStart(ch, languageVersion)) { pos++; while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos), languageVersion)) pos++; tokenValue = text.substring(tokenPos, pos); if (ch === 92 /* backslash */) { tokenValue += scanIdentifierParts(); } return token = getIdentifierToken(); } else if (isWhiteSpaceSingleLine(ch)) { pos++; continue; } else if (isLineBreak(ch)) { precedingLineBreak = true; pos++; continue; } error(ts.Diagnostics.Invalid_character); pos++; return token = 0 /* Unknown */; } } }
hasPrecedingLineBreak:
() { return precedingLineBreak; }
createNode:
(kind, pos) { nodeCount++; if (!(pos >= 0)) { pos = scanner.getStartPos(); } return kind >= 141 /* FirstNode */ ? new NodeConstructor(kind, pos, pos) : kind === 70 /* Identifier */ ? new IdentifierConstructor(kind, pos, pos) : new TokenConstructor(kind, pos, pos); }
finishNode:
(node, end) { node.end = end === undefined ? scanner.getStartPos() : end; if (contextFlags) { node.flags |= contextFlags; } // Keep track on the node if we encountered an error while parsing it. If we did, then // we cannot reuse the node incrementally. Once we've marked this node, clear out the // flag so that we don't mark any subsequent nodes. if (parseErrorBeforeNextFinishedNode) { parseErrorBeforeNextFinishedNode = false; node.flags |= 32768 /* ThisNodeHasError */; } return node; }
speculationHelper:
(callback, isLookAhead) { // Keep track of the state we'll need to rollback to if lookahead fails (or if the // caller asked us to always reset our state). var saveToken = currentToken; var saveParseDiagnosticsLength = parseDiagnostics.length; var saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; // Note: it is not actually necessary to save/restore the context flags here. That's // because the saving/restoring of these flags happens naturally through the recursive // descent nature of our parser. However, we still store this here just so we can // assert that invariant holds. var saveContextFlags = contextFlags; // If we're only looking ahead, then tell the scanner to only lookahead as well. // Otherwise, if we're actually speculatively parsing, then tell the scanner to do the // same. var result = isLookAhead ? scanner.lookAhead(callback) : scanner.tryScan(callback); ts.Debug.assert(saveContextFlags === contextFlags); // If our callback returned something 'falsy' or we're just looking ahead, // then unconditionally restore us to where we were. if (!result || isLookAhead) { currentToken = saveToken; parseDiagnostics.length = saveParseDiagnosticsLength; parseErrorBeforeNextFinishedNode = saveParseErrorBeforeNextFinishedNode; } return result; }
(callback, isLookahead) { var savePos = pos; var saveStartPos = startPos; var saveTokenPos = tokenPos; var saveToken = token; var saveTokenValue = tokenValue; var savePrecedingLineBreak = precedingLineBreak; var result = callback(); // If our callback returned something 'falsy' or we're just looking ahead, // then unconditionally restore us to where we were. if (!result || isLookahead) { pos = savePos; startPos = saveStartPos; tokenPos = saveTokenPos; token = saveToken; tokenValue = saveTokenValue; precedingLineBreak = savePrecedingLineBreak; } return result; }
getIdentifierToken:
() { // Reserved words are between 2 and 11 characters long and start with a lowercase letter var len = tokenValue.length; if (len >= 2 && len <= 11) { var ch = tokenValue.charCodeAt(0); if (ch >= 97 /* a */ && ch <= 122 /* z */ && hasOwnProperty.call(textToToken, tokenValue)) { return token = textToToken[tokenValue]; } } return token = 70 /* Identifier */; }
createIdentifier:
(isIdentifier, diagnosticMessage) { identifierCount++; if (isIdentifier) { var node = createNode(70 /* Identifier */); // Store original token kind if it is not just an Identifier so we can report appropriate error later in type checker if (token() !== 70 /* Identifier */) { node.originalKeywordKind = token(); } node.text = internIdentifier(scanner.getTokenValue()); nextToken(); return finishNode(node); } return createMissingNode(70 /* Identifier */, /*reportAtCurrentPosition*/ false, diagnosticMessage || ts.Diagnostics.Identifier_expected); }
getTokenValue:
() { return tokenValue; }
escapeIdentifier:
(identifier) { return identifier.length >= 2 && identifier.charCodeAt(0) === 95 /* _ */ && identifier.charCodeAt(1) === 95 /* _ */ ? "_" + identifier : identifier; }
nextJSDocToken:
() { return currentToken = scanner.scanJSDocToken(); }
getTokenText:
() { return text.substring(tokenPos, pos); }
parseIdentifier:
(diagnosticMessage) { return createIdentifier(isIdentifier(), diagnosticMessage); }
parseListElement:
(parsingContext, parseElement) { var node = currentNode(parsingContext); if (node) { return consumeNode(node); } return parseElement(); }
isWhiteSpaceSingleLine:
(ch) { // Note: nextLine is in the Zs space, and should be considered to be a whitespace. // It is explicitly not a line-break as it isn't in the exact set specified by EcmaScript. return ch === 32 /* space */ || ch === 9 /* tab */ || ch === 11 /* verticalTab */ || ch === 12 /* formFeed */ || ch === 160 /* nonBreakingSpace */ || ch === 133 /* nextLine */ || ch === 5760 /* ogham */ || ch >= 8192 /* enQuad */ && ch <= 8203 /* zeroWidthSpace */ || ch === 8239 /* narrowNoBreakSpace */ || ch === 8287 /* mathematicalSpace */ || ch === 12288 /* ideographicSpace */ || ch === 65279 /* byteOrderMark */; }
isIdentifier:
() { if (token() === 70 /* Identifier */) { return true; } // If we have a 'yield' keyword, and we're in the [yield] context, then 'yield' is // considered a keyword and is not an identifier. if (token() === 115 /* YieldKeyword */ && inYieldContext()) { return false; } // If we have a 'await' keyword, and we're in the [Await] context, then 'await' is // considered a keyword and is not an identifier. if (token() === 120 /* AwaitKeyword */ && inAwaitContext()) { return false; } return token() > 106 /* LastReservedWord */; }
isIdentifierStart:
(ch, languageVersion) { return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ || ch === 36 /* $ */ || ch === 95 /* _ */ || ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierStart(ch, languageVersion); }
pushComment:
(text) { if (!margin) { margin = indent; } comments.push(text); indent += text.length; }
(text) { if (!margin) { margin = indent; } comments.push(text); indent += text.length; }
Deopt: <JS Function doOutsideOfContext (SharedFunctionInfo 0x2c75c4af18d9)> (opt #33) @20, FP to SP delta: 248, caller sp: 0x7fff5fbfd6a0
getLeadingCommentRanges:
(text, pos) { return reduceEachLeadingCommentRange(text, pos, appendCommentRange, undefined, undefined); }
iterateCommentRanges:
(reduce, text, pos, trailing, cb, state, initial) { var pendingPos; var pendingEnd; var pendingKind; var pendingHasTrailingNewLine; var hasPendingCommentRange = false; var collecting = trailing || pos === 0; var accumulator = initial; scan: while (pos >= 0 && pos < text.length) { var ch = text.charCodeAt(pos); switch (ch) { case 13 /* carriageReturn */: if (text.charCodeAt(pos + 1) === 10 /* lineFeed */) { pos++; } case 10 /* lineFeed */: pos++; if (trailing) { break scan; } collecting = true; if (hasPendingCommentRange) { pendingHasTrailingNewLine = true; } continue; case 9 /* tab */: case 11 /* verticalTab */: case 12 /* formFeed */: case 32 /* space */: pos++; continue; case 47 /* slash */: var nextChar = text.charCodeAt(pos + 1); var hasTrailingNewLine = false; if (nextChar === 47 /* slash */ || nextChar === 42 /* asterisk */) { var kind = nextChar === 47 /* slash */ ? 2 /* SingleLineCommentTrivia */ : 3 /* MultiLineCommentTrivia */; var startPos = pos; pos += 2; if (nextChar === 47 /* slash */) { while (pos < text.length) { if (isLineBreak(text.charCodeAt(pos))) { hasTrailingNewLine = true; break; } pos++; } } else { while (pos < text.length) { if (text.charCodeAt(pos) === 42 /* asterisk */ && text.charCodeAt(pos + 1) === 47 /* slash */) { pos += 2; break; } pos++; } } if (collecting) { if (hasPendingCommentRange) { accumulator = cb(pendingPos, pendingEnd, pendingKind, pendingHasTrailingNewLine, state, accumulator); if (!reduce && accumulator) { // If we are not reducing and we have a truthy result, return it. return accumulator; } hasPendingCommentRange = false; } pendingPos = startPos; pendingEnd = pos; pendingKind = kind; pendingHasTrailingNewLine = hasTrailingNewLine; hasPendingCommentRange = true; } continue; } break scan; default: if (ch > 127 /* maxAsciiCharacter */ && (isWhiteSpace(ch))) { if (hasPendingCommentRange && isLineBreak(ch)) { pendingHasTrailingNewLine = true; } pos++; continue; } break scan; } } if (hasPendingCommentRange) { accumulator = cb(pendingPos, pendingEnd, pendingKind, pendingHasTrailingNewLine, state, accumulator); } return accumulator; }
tryParse:
(callback) { return speculationHelper(callback, /*isLookAhead*/ false); }
parseIntersectionTypeOrHigher:
() { return parseUnionOrIntersectionType(165 /* IntersectionType */, parseTypeOperatorOrHigher, 47 /* AmpersandToken */); }
parseTypeOperatorOrHigher:
() { switch (token()) { case 126 /* KeyOfKeyword */: return parseTypeOperator(126 /* KeyOfKeyword */); } return parseArrayTypeOrHigher(); }
isStartOfFunctionType:
() { if (token() === 26 /* LessThanToken */) { return true; } return token() === 18 /* OpenParenToken */ && lookAhead(isUnambiguouslyStartOfFunctionType); }
parseType:
() { // The rules about 'yield' only apply to actual code/expression contexts. They don't // apply to 'type' contexts. So we disable these parameters here before moving on. return doOutsideOfContext(20480 /* TypeExcludesFlags */, parseTypeWorker); }
doOutsideOfContext:
(context, func) { // contextFlagsToClear will contain only the context flags that are // currently set that we need to temporarily clear // We don't just blindly reset to the previous flags to ensure // that we do not mutate cached flags for the incremental // parser (ThisNodeHasError, ThisNodeOrAnySubNodesHasError, and // HasAggregatedChildData). var contextFlagsToClear = context & contextFlags; if (contextFlagsToClear) { // clear the requested context flags setContextFlag(/*val*/ false, contextFlagsToClear); var result = func(); // restore the context flags we just cleared setContextFlag(/*val*/ true, contextFlagsToClear); return result; } // no need to do anything special as we are not in any of the requested contexts return func(); }
(context, func) { // contextFlagsToClear will contain only the context flags that are // currently set that we need to temporarily clear // We don't just blindly reset to the previous flags to ensure // that we do not mutate cached flags for the incremental // parser (ThisNodeHasError, ThisNodeOrAnySubNodesHasError, and // HasAggregatedChildData). var contextFlagsToClear = context & contextFlags; if (contextFlagsToClear) { // clear the requested context flags setContextFlag(/*val*/ false, contextFlagsToClear); var result = func(); // restore the context flags we just cleared setContextFlag(/*val*/ true, contextFlagsToClear); return result; } // no need to do anything special as we are not in any of the requested contexts return func(); }
(context, func) { // contextFlagsToClear will contain only the context flags that are // currently set that we need to temporarily clear // We don't just blindly reset to the previous flags to ensure // that we do not mutate cached flags for the incremental // parser (ThisNodeHasError, ThisNodeOrAnySubNodesHasError, and // HasAggregatedChildData). var contextFlagsToClear = context & contextFlags; if (contextFlagsToClear) { // clear the requested context flags setContextFlag(/*val*/ false, contextFlagsToClear); var result = func(); // restore the context flags we just cleared setContextFlag(/*val*/ true, contextFlagsToClear); return result; } // no need to do anything special as we are not in any of the requested contexts return func(); }
getTokenPos:
() { return tokenPos; }
TokenOrIdentifierObject:
(pos, end) { // Set properties in same order as NodeObject this.pos = pos; this.end = end; this.flags = 0 /* None */; this.parent = undefined; }
parseTypeWorker:
() { if (isStartOfFunctionType()) { return parseFunctionOrConstructorType(158 /* FunctionType */); } if (token() === 93 /* NewKeyword */) { return parseFunctionOrConstructorType(159 /* ConstructorType */); } return parseUnionTypeOrHigher(); }
() { if (isStartOfFunctionType()) { return parseFunctionOrConstructorType(158 /* FunctionType */); } if (token() === 93 /* NewKeyword */) { return parseFunctionOrConstructorType(159 /* ConstructorType */); } return parseUnionTypeOrHigher(); }
() { if (isStartOfFunctionType()) { return parseFunctionOrConstructorType(158 /* FunctionType */); } if (token() === 93 /* NewKeyword */) { return parseFunctionOrConstructorType(159 /* ConstructorType */); } return parseUnionTypeOrHigher(); }
createNodeArray:
(elements, pos) { var array = (elements || []); if (!(pos >= 0)) { pos = getNodePos(); } array.pos = pos; array.end = pos; return array; }
lookAhead:
(callback) { return speculationHelper(callback, /*isLookAhead*/ true); }
(callback) { return speculationHelper(callback, /*isLookahead*/ true); }
Deopt: <JS Function doOutsideOfContext (SharedFunctionInfo 0x2c75c4af18d9)> (opt #58) @3, FP to SP delta: 248, caller sp: 0x7fff5fbfd848
Deopt: <JS Function isLiteralPropertyName (SharedFunctionInfo 0x2c75c4af3b59)> (opt #56) @6, FP to SP delta: 32, caller sp: 0x7fff5fbfdaf8
Deopt: <JS Function scan (SharedFunctionInfo 0x2142bdb54ae1)> (opt #43) @128, FP to SP delta: 128, caller sp: 0x7fff5fbfdba8
inContext:
(flags) { return (contextFlags & flags) !== 0; }
Deopt: <JS Function scan (SharedFunctionInfo 0x2142bdb54ae1)> (opt #16) @96, FP to SP delta: 96, caller sp: 0x7fff5fbfda40
setAwaitContext:
(val) { setContextFlag(val, 16384 /* AwaitContext */); }
tokenIsIdentifierOrKeyword:
(token) { return token >= 70 /* Identifier */; }
inDisallowInContext:
() { return inContext(2048 /* DisallowInContext */); }
parseExpected:
(kind, diagnosticMessage, shouldAdvance) { if (shouldAdvance === void 0) { shouldAdvance = true; } if (token() === kind) { if (shouldAdvance) { nextToken(); } return true; } // Report specific message if provided with one. Otherwise, report generic fallback message. if (diagnosticMessage) { parseErrorAtCurrentToken(diagnosticMessage); } else { parseErrorAtCurrentToken(ts.Diagnostics._0_expected, ts.tokenToString(kind)); } return false; }
getNodeEnd:
() { return scanner.getStartPos(); }
parseAnyContextualModifier:
() { return ts.isModifierKind(token()) && tryParse(nextTokenCanFollowModifier); }
parseOptionalToken:
(t) { if (token() === t) { return parseTokenNode(); } return undefined; }
parseKeywordAndNoDot:
() { var node = parseTokenNode(); return token() === 22 /* DotToken */ ? undefined : node; }
parseIdentifierOrPattern:
() { if (token() === 20 /* OpenBracketToken */) { return parseArrayBindingPattern(); } if (token() === 16 /* OpenBraceToken */) { return parseObjectBindingPattern(); } return parseIdentifier(); }
parseInitializer:
(inParameter) { if (token() !== 57 /* EqualsToken */) { // It's not uncommon during typing for the user to miss writing the '=' token. Check if // there is no newline after the last token and if we're on an expression. If so, parse // this as an equals-value clause with a missing equals. // NOTE: There are two places where we allow equals-value clauses. The first is in a // variable declarator. The second is with a parameter. For variable declarators // it's more likely that a { would be a allowed (as an object literal). While this // is also allowed for parameters, the risk is that we consume the { as an object // literal when it really will be for the block following the parameter. if (scanner.hasPrecedingLineBreak() || (inParameter && token() === 16 /* OpenBraceToken */) || !isStartOfExpression()) { // preceding line break, open brace in a parameter (likely a function body) or current token is not an expression - // do not try to parse initializer return undefined; } } // Initializer[In, Yield] : // = AssignmentExpression[?In, ?Yield] parseExpected(57 /* EqualsToken */); return parseAssignmentExpressionOrHigher(); }
isBinaryOperator:
() { if (inDisallowInContext() && token() === 91 /* InKeyword */) { return false; } return getBinaryOperatorPrecedence() > 0; }
isModifierKind:
(token) { switch (token) { case 116 /* AbstractKeyword */: case 119 /* AsyncKeyword */: case 75 /* ConstKeyword */: case 123 /* DeclareKeyword */: case 78 /* DefaultKeyword */: case 83 /* ExportKeyword */: case 113 /* PublicKeyword */: case 111 /* PrivateKeyword */: case 112 /* ProtectedKeyword */: case 130 /* ReadonlyKeyword */: case 114 /* StaticKeyword */: return true; } return false; }
isStartOfParameter:
() { return token() === 23 /* DotDotDotToken */ || isIdentifierOrPattern() || ts.isModifierKind(token()) || token() === 56 /* AtToken */ || token() === 98 /* ThisKeyword */; }
getNodePos:
() { return scanner.getStartPos(); }
isLiteralPropertyName:
() { return ts.tokenIsIdentifierOrKeyword(token()) || token() === 9 /* StringLiteral */ || token() === 8 /* NumericLiteral */; }
() { return ts.tokenIsIdentifierOrKeyword(token()) || token() === 9 /* StringLiteral */ || token() === 8 /* NumericLiteral */; }
tryScan:
(callback) { return speculationHelper(callback, /*isLookahead*/ false); }
parseSemicolon:
() { if (canParseSemicolon()) { if (token() === 24 /* SemicolonToken */) { // consume the semicolon if it was explicitly provided. nextToken(); } return true; } else { return parseExpected(24 /* SemicolonToken */); } }
getFullWidth:
(node) { return node.end - node.pos; }
parseParameterType:
() { if (parseOptional(55 /* ColonToken */)) { return parseType(); } return undefined; }
parseBindingElementInitializer:
(inParameter) { return inParameter ? parseParameterInitializer() : parseNonParameterInitializer(); }
getTrailingCommentRanges:
(text, pos) { return reduceEachTrailingCommentRange(text, pos, appendCommentRange, undefined, undefined); }
concatenate:
(array1, array2) { if (!some(array2)) return array1; if (!some(array1)) return array2; return array1.concat(array2); }
(array1, array2) { if (!some(array2)) return array1; if (!some(array1)) return array2; return array1.concat(array2); }
parseIdentifierName:
() { return createIdentifier(ts.tokenIsIdentifierOrKeyword(token())); }
isIndexSignature:
() { if (token() !== 20 /* OpenBracketToken */) { return false; } return lookAhead(isUnambiguouslyIndexSignature); }
parsePropertyName:
() { return parsePropertyNameWorker(/*allowComputedPropertyNames*/ true); }
parseTypeMember:
() { if (token() === 18 /* OpenParenToken */ || token() === 26 /* LessThanToken */) { return parseSignatureMember(153 /* CallSignature */); } if (token() === 93 /* NewKeyword */ && lookAhead(isStartOfConstructSignature)) { return parseSignatureMember(154 /* ConstructSignature */); } var fullStart = getNodePos(); var modifiers = parseModifiers(); if (isIndexSignature()) { return parseIndexSignatureDeclaration(fullStart, /*decorators*/ undefined, modifiers); } return parsePropertyOrMethodSignature(fullStart, modifiers); }
parseTypeMemberSemicolon:
() { // We allow type members to be separated by commas or (possibly ASI) semicolons. // First check if it was a comma. If so, we're done with the member. if (parseOptional(25 /* CommaToken */)) { return; } // Didn't have a comma. We must have a (possible ASI) semicolon. parseSemicolon(); }
parseTypeParameters:
() { if (token() === 26 /* LessThanToken */) { return parseBracketedList(18 /* TypeParameters */, parseTypeParameter, 26 /* LessThanToken */, 28 /* GreaterThanToken */); } }
getJSDocCommentRanges:
(node, text) { var commentRanges = (node.kind === 144 /* Parameter */ || node.kind === 143 /* TypeParameter */ || node.kind === 184 /* FunctionExpression */ || node.kind === 185 /* ArrowFunction */) ? ts.concatenate(ts.getTrailingCommentRanges(text, node.pos), ts.getLeadingCommentRanges(text, node.pos)) : getLeadingCommentRangesOfNodeFromText(node, text); // True if the comment starts with '/**' but not if it is '/**/' return ts.filter(commentRanges, function (comment) { return text.charCodeAt(comment.pos + 1) === 42 /* asterisk */ && text.charCodeAt(comment.pos + 2) === 42 /* asterisk */ && text.charCodeAt(comment.pos + 3) !== 47 /* slash */; }); }
parseTypeAnnotation:
() { return parseOptional(55 /* ColonToken */) ? parseType() : undefined; }
setContextFlag:
(val, flag) { if (val) { contextFlags |= flag; } else { contextFlags &= ~flag; } }
fillSignature:
(returnToken, yieldContext, awaitContext, requireCompleteParameterList, signature) { var returnTokenRequired = returnToken === 35 /* EqualsGreaterThanToken */; signature.typeParameters = parseTypeParameters(); signature.parameters = parseParameterList(yieldContext, awaitContext, requireCompleteParameterList); if (returnTokenRequired) { parseExpected(returnToken); signature.type = parseTypeOrTypePredicate(); } else if (parseOptional(returnToken)) { signature.type = parseTypeOrTypePredicate(); } }
(returnToken, yieldContext, awaitContext, requireCompleteParameterList, signature) { var returnTokenRequired = returnToken === 35 /* EqualsGreaterThanToken */; signature.typeParameters = parseTypeParameters(); signature.parameters = parseParameterList(yieldContext, awaitContext, requireCompleteParameterList); if (returnTokenRequired) { parseExpected(returnToken); signature.type = parseTypeOrTypePredicate(); } else if (parseOptional(returnToken)) { signature.type = parseTypeOrTypePredicate(); } }
parseParameterList:
(yieldContext, awaitContext, requireCompleteParameterList) { // FormalParameters [Yield,Await]: (modified) // [empty] // FormalParameterList[?Yield,Await] // // FormalParameter[Yield,Await]: (modified) // BindingElement[?Yield,Await] // // BindingElement [Yield,Await]: (modified) // SingleNameBinding[?Yield,?Await] // BindingPattern[?Yield,?Await]Initializer [In, ?Yield,?Await] opt // // SingleNameBinding [Yield,Await]: // BindingIdentifier[?Yield,?Await]Initializer [In, ?Yield,?Await] opt if (parseExpected(18 /* OpenParenToken */)) { var savedYieldContext = inYieldContext(); var savedAwaitContext = inAwaitContext(); setYieldContext(yieldContext); setAwaitContext(awaitContext); var result = parseDelimitedList(16 /* Parameters */, parseParameter); setYieldContext(savedYieldContext); setAwaitContext(savedAwaitContext); if (!parseExpected(19 /* CloseParenToken */) && requireCompleteParameterList) { // Caller insisted that we had to end with a ) We didn't. So just return // undefined here. return undefined; } return result; } // We didn't even have an open paren. If the caller requires a complete parameter list, // we definitely can't provide that. However, if they're ok with an incomplete one, // then just return an empty set of parameters. return requireCompleteParameterList ? undefined : createMissingList(); }
parseNonArrayType:
() { switch (token()) { case 118 /* AnyKeyword */: case 134 /* StringKeyword */: case 132 /* NumberKeyword */: case 121 /* BooleanKeyword */: case 135 /* SymbolKeyword */: case 137 /* UndefinedKeyword */: case 129 /* NeverKeyword */: // If these are followed by a dot, then parse these out as a dotted type reference instead. var node = tryParse(parseKeywordAndNoDot); return node || parseTypeReference(); case 9 /* StringLiteral */: case 8 /* NumericLiteral */: case 100 /* TrueKeyword */: case 85 /* FalseKeyword */: return parseLiteralTypeNode(); case 37 /* MinusToken */: return lookAhead(nextTokenIsNumericLiteral) ? parseLiteralTypeNode() : parseTypeReference(); case 104 /* VoidKeyword */: case 94 /* NullKeyword */: return parseTokenNode(); case 98 /* ThisKeyword */: { var thisKeyword = parseThisTypeNode(); if (token() === 125 /* IsKeyword */ && !scanner.hasPrecedingLineBreak()) { return parseThisTypePredicate(thisKeyword); } else { return thisKeyword; } } case 102 /* TypeOfKeyword */: return parseTypeQuery(); case 16 /* OpenBraceToken */: return lookAhead(isStartOfMappedType) ? parseMappedType() : parseTypeLiteral(); case 20 /* OpenBracketToken */: return parseTupleType(); case 18 /* OpenParenToken */: return parseParenthesizedType(); default: return parseTypeReference(); } }
isStartOfLeftHandSideExpression:
() { switch (token()) { case 98 /* ThisKeyword */: case 96 /* SuperKeyword */: case 94 /* NullKeyword */: case 100 /* TrueKeyword */: case 85 /* FalseKeyword */: case 8 /* NumericLiteral */: case 9 /* StringLiteral */: case 12 /* NoSubstitutionTemplateLiteral */: case 13 /* TemplateHead */: case 18 /* OpenParenToken */: case 20 /* OpenBracketToken */: case 16 /* OpenBraceToken */: case 88 /* FunctionKeyword */: case 74 /* ClassKeyword */: case 93 /* NewKeyword */: case 40 /* SlashToken */: case 62 /* SlashEqualsToken */: case 70 /* Identifier */: return true; default: return isIdentifier(); } }
parseTypePredicatePrefix:
() { var id = parseIdentifier(); if (token() === 125 /* IsKeyword */ && !scanner.hasPrecedingLineBreak()) { nextToken(); return id; } }
getBinaryOperatorPrecedence:
() { switch (token()) { case 53 /* BarBarToken */: return 1; case 52 /* AmpersandAmpersandToken */: return 2; case 48 /* BarToken */: return 3; case 49 /* CaretToken */: return 4; case 47 /* AmpersandToken */: return 5; case 31 /* EqualsEqualsToken */: case 32 /* ExclamationEqualsToken */: case 33 /* EqualsEqualsEqualsToken */: case 34 /* ExclamationEqualsEqualsToken */: return 6; case 26 /* LessThanToken */: case 28 /* GreaterThanToken */: case 29 /* LessThanEqualsToken */: case 30 /* GreaterThanEqualsToken */: case 92 /* InstanceOfKeyword */: case 91 /* InKeyword */: case 117 /* AsKeyword */: return 7; case 44 /* LessThanLessThanToken */: case 45 /* GreaterThanGreaterThanToken */: case 46 /* GreaterThanGreaterThanGreaterThanToken */: return 8; case 36 /* PlusToken */: case 37 /* MinusToken */: return 9; case 38 /* AsteriskToken */: case 40 /* SlashToken */: case 41 /* PercentToken */: return 10; case 39 /* AsteriskAsteriskToken */: return 11; } // -1 is lower than all other precedences. Returning it will cause binary expression // parsing to stop. return -1; }
isStartOfExpression:
() { if (isStartOfLeftHandSideExpression()) { return true; } switch (token()) { case 36 /* PlusToken */: case 37 /* MinusToken */: case 51 /* TildeToken */: case 50 /* ExclamationToken */: case 79 /* DeleteKeyword */: case 102 /* TypeOfKeyword */: case 104 /* VoidKeyword */: case 42 /* PlusPlusToken */: case 43 /* MinusMinusToken */: case 26 /* LessThanToken */: case 120 /* AwaitKeyword */: case 115 /* YieldKeyword */: // Yield/await always starts an expression. Either it is an identifier (in which case // it is definitely an expression). Or it's a keyword (either because we're in // a generator or async function, or in strict mode (or both)) and it started a yield or await expression. return true; default: // Error tolerance. If we see the start of some binary operator, we consider // that the start of an expression. That way we'll parse out a missing identifier, // give a good message about an identifier being missing, and then consume the // rest of the binary expression. if (isBinaryOperator()) { return true; } return isIdentifier(); } }
parseParameter:
() { var node = createNode(144 /* Parameter */); if (token() === 98 /* ThisKeyword */) { node.name = createIdentifier(/*isIdentifier*/ true, undefined); node.type = parseParameterType(); return finishNode(node); } node.decorators = parseDecorators(); node.modifiers = parseModifiers(); node.dotDotDotToken = parseOptionalToken(23 /* DotDotDotToken */); // FormalParameter [Yield,Await]: // BindingElement[?Yield,?Await] node.name = parseIdentifierOrPattern(); if (ts.getFullWidth(node.name) === 0 && !ts.hasModifiers(node) && ts.isModifierKind(token())) { // in cases like // 'use strict' // function foo(static) // isParameter('static') === true, because of isModifier('static') // however 'static' is not a legal identifier in a strict mode. // so result of this function will be ParameterDeclaration (flags = 0, name = missing, type = undefined, initializer = undefined) // and current token will not change => parsing of the enclosing parameter list will last till the end of time (or OOM) // to avoid this we'll advance cursor to the next token. nextToken(); } node.questionToken = parseOptionalToken(54 /* QuestionToken */); node.type = parseParameterType(); node.initializer = parseBindingElementInitializer(/*inParameter*/ true); // Do not check for initializers in an ambient context for parameters. This is not // a grammar error because the grammar allows arbitrary call signatures in // an ambient context. // It is actually not necessary for this to be an error at all. The reason is that // function/constructor implementations are syntactically disallowed in ambient // contexts. In addition, parameter initializers are semantically disallowed in // overload signatures. So parameter initializers are transitively disallowed in // ambient contexts. return addJSDocComment(finishNode(node)); }
() { var node = createNode(144 /* Parameter */); if (token() === 98 /* ThisKeyword */) { node.name = createIdentifier(/*isIdentifier*/ true, undefined); node.type = parseParameterType(); return finishNode(node); } node.decorators = parseDecorators(); node.modifiers = parseModifiers(); node.dotDotDotToken = parseOptionalToken(23 /* DotDotDotToken */); // FormalParameter [Yield,Await]: // BindingElement[?Yield,?Await] node.name = parseIdentifierOrPattern(); if (ts.getFullWidth(node.name) === 0 && !ts.hasModifiers(node) && ts.isModifierKind(token())) { // in cases like // 'use strict' // function foo(static) // isParameter('static') === true, because of isModifier('static') // however 'static' is not a legal identifier in a strict mode. // so result of this function will be ParameterDeclaration (flags = 0, name = missing, type = undefined, initializer = undefined) // and current token will not change => parsing of the enclosing parameter list will last till the end of time (or OOM) // to avoid this we'll advance cursor to the next token. nextToken(); } node.questionToken = parseOptionalToken(54 /* QuestionToken */); node.type = parseParameterType(); node.initializer = parseBindingElementInitializer(/*inParameter*/ true); // Do not check for initializers in an ambient context for parameters. This is not // a grammar error because the grammar allows arbitrary call signatures in // an ambient context. // It is actually not necessary for this to be an error at all. The reason is that // function/constructor implementations are syntactically disallowed in ambient // contexts. In addition, parameter initializers are semantically disallowed in // overload signatures. So parameter initializers are transitively disallowed in // ambient contexts. return addJSDocComment(finishNode(node)); }
parseTypeOrTypePredicate:
() { var typePredicateVariable = isIdentifier() && tryParse(parseTypePredicatePrefix); var type = parseType(); if (typePredicateVariable) { var node = createNode(156 /* TypePredicate */, typePredicateVariable.pos); node.parameterName = typePredicateVariable; node.type = type; return finishNode(node); } else { return type; } }
isStartOfDeclaration:
() { return lookAhead(isDeclaration); }
isListElement:
(parsingContext, inErrorRecovery) { var node = currentNode(parsingContext); if (node) { return true; } switch (parsingContext) { case 0 /* SourceElements */: case 1 /* BlockStatements */: case 3 /* SwitchClauseStatements */: // If we're in error recovery, then we don't want to treat ';' as an empty statement. // The problem is that ';' can show up in far too many contexts, and if we see one // and assume it's a statement, then we may bail out inappropriately from whatever // we're parsing. For example, if we have a semicolon in the middle of a class, then // we really don't want to assume the class is over and we're on a statement in the // outer module. We just want to consume and move on. return !(token() === 24 /* SemicolonToken */ && inErrorRecovery) && isStartOfStatement(); case 2 /* SwitchClauses */: return token() === 72 /* CaseKeyword */ || token() === 78 /* DefaultKeyword */; case 4 /* TypeMembers */: return lookAhead(isTypeMemberStart); case 5 /* ClassMembers */: // We allow semicolons as class elements (as specified by ES6) as long as we're // not in error recovery. If we're in error recovery, we don't want an errant // semicolon to be treated as a class member (since they're almost always used // for statements. return lookAhead(isClassMemberStart) || (token() === 24 /* SemicolonToken */ && !inErrorRecovery); case 6 /* EnumMembers */: // Include open bracket computed properties. This technically also lets in indexers, // which would be a candidate for improved error reporting. return token() === 20 /* OpenBracketToken */ || isLiteralPropertyName(); case 12 /* ObjectLiteralMembers */: return token() === 20 /* OpenBracketToken */ || token() === 38 /* AsteriskToken */ || token() === 23 /* DotDotDotToken */ || isLiteralPropertyName(); case 17 /* RestProperties */: return isLiteralPropertyName(); case 9 /* ObjectBindingElements */: return token() === 20 /* OpenBracketToken */ || token() === 23 /* DotDotDotToken */ || isLiteralPropertyName(); case 7 /* HeritageClauseElement */: // If we see { } then only consume it as an expression if it is followed by , or { // That way we won't consume the body of a class in its heritage clause. if (token() === 16 /* OpenBraceToken */) { return lookAhead(isValidHeritageClauseObjectLiteral); } if (!inErrorRecovery) { return isStartOfLeftHandSideExpression() && !isHeritageClauseExtendsOrImplementsKeyword(); } else { // If we're in error recovery we tighten up what we're willing to match. // That way we don't treat something like "this" as a valid heritage clause // element during recovery. return isIdentifier() && !isHeritageClauseExtendsOrImplementsKeyword(); } case 8 /* VariableDeclarations */: return isIdentifierOrPattern(); case 10 /* ArrayBindingElements */: return token() === 25 /* CommaToken */ || token() === 23 /* DotDotDotToken */ || isIdentifierOrPattern(); case 18 /* TypeParameters */: return isIdentifier(); case 11 /* ArgumentExpressions */: case 15 /* ArrayLiteralMembers */: return token() === 25 /* CommaToken */ || token() === 23 /* DotDotDotToken */ || isStartOfExpression(); case 16 /* Parameters */: return isStartOfParameter(); case 19 /* TypeArguments */: case 20 /* TupleElementTypes */: return token() === 25 /* CommaToken */ || isStartOfType(); case 21 /* HeritageClauses */: return isHeritageClause(); case 22 /* ImportOrExportSpecifiers */: return ts.tokenIsIdentifierOrKeyword(token()); case 13 /* JsxAttributes */: return ts.tokenIsIdentifierOrKeyword(token()) || token() === 16 /* OpenBraceToken */; case 14 /* JsxChildren */: return true; case 23 /* JSDocFunctionParameters */: case 24 /* JSDocTypeArguments */: case 26 /* JSDocTupleTypes */: return JSDocParser.isJSDocType(); case 25 /* JSDocRecordMembers */: return isSimplePropertyName(); } ts.Debug.fail("Non-exhaustive case in 'isListElement'."); }
(parsingContext, inErrorRecovery) { var node = currentNode(parsingContext); if (node) { return true; } switch (parsingContext) { case 0 /* SourceElements */: case 1 /* BlockStatements */: case 3 /* SwitchClauseStatements */: // If we're in error recovery, then we don't want to treat ';' as an empty statement. // The problem is that ';' can show up in far too many contexts, and if we see one // and assume it's a statement, then we may bail out inappropriately from whatever // we're parsing. For example, if we have a semicolon in the middle of a class, then // we really don't want to assume the class is over and we're on a statement in the // outer module. We just want to consume and move on. return !(token() === 24 /* SemicolonToken */ && inErrorRecovery) && isStartOfStatement(); case 2 /* SwitchClauses */: return token() === 72 /* CaseKeyword */ || token() === 78 /* DefaultKeyword */; case 4 /* TypeMembers */: return lookAhead(isTypeMemberStart); case 5 /* ClassMembers */: // We allow semicolons as class elements (as specified by ES6) as long as we're // not in error recovery. If we're in error recovery, we don't want an errant // semicolon to be treated as a class member (since they're almost always used // for statements. return lookAhead(isClassMemberStart) || (token() === 24 /* SemicolonToken */ && !inErrorRecovery); case 6 /* EnumMembers */: // Include open bracket computed properties. This technically also lets in indexers, // which would be a candidate for improved error reporting. return token() === 20 /* OpenBracketToken */ || isLiteralPropertyName(); case 12 /* ObjectLiteralMembers */: return token() === 20 /* OpenBracketToken */ || token() === 38 /* AsteriskToken */ || token() === 23 /* DotDotDotToken */ || isLiteralPropertyName(); case 17 /* RestProperties */: return isLiteralPropertyName(); case 9 /* ObjectBindingElements */: return token() === 20 /* OpenBracketToken */ || token() === 23 /* DotDotDotToken */ || isLiteralPropertyName(); case 7 /* HeritageClauseElement */: // If we see { } then only consume it as an expression if it is followed by , or { // That way we won't consume the body of a class in its heritage clause. if (token() === 16 /* OpenBraceToken */) { return lookAhead(isValidHeritageClauseObjectLiteral); } if (!inErrorRecovery) { return isStartOfLeftHandSideExpression() && !isHeritageClauseExtendsOrImplementsKeyword(); } else { // If we're in error recovery we tighten up what we're willing to match. // That way we don't treat something like "this" as a valid heritage clause // element during recovery. return isIdentifier() && !isHeritageClauseExtendsOrImplementsKeyword(); } case 8 /* VariableDeclarations */: return isIdentifierOrPattern(); case 10 /* ArrayBindingElements */: return token() === 25 /* CommaToken */ || token() === 23 /* DotDotDotToken */ || isIdentifierOrPattern(); case 18 /* TypeParameters */: return isIdentifier(); case 11 /* ArgumentExpressions */: case 15 /* ArrayLiteralMembers */: return token() === 25 /* CommaToken */ || token() === 23 /* DotDotDotToken */ || isStartOfExpression(); case 16 /* Parameters */: return isStartOfParameter(); case 19 /* TypeArguments */: case 20 /* TupleElementTypes */: return token() === 25 /* CommaToken */ || isStartOfType(); case 21 /* HeritageClauses */: return isHeritageClause(); case 22 /* ImportOrExportSpecifiers */: return ts.tokenIsIdentifierOrKeyword(token()); case 13 /* JsxAttributes */: return ts.tokenIsIdentifierOrKeyword(token()) || token() === 16 /* OpenBraceToken */; case 14 /* JsxChildren */: return true; case 23 /* JSDocFunctionParameters */: case 24 /* JSDocTypeArguments */: case 26 /* JSDocTupleTypes */: return JSDocParser.isJSDocType(); case 25 /* JSDocRecordMembers */: return isSimplePropertyName(); } ts.Debug.fail("Non-exhaustive case in 'isListElement'."); }
parseContextualModifier:
(t) { return token() === t && tryParse(nextTokenCanFollowModifier); }
inDecoratorContext:
() { return inContext(8192 /* DecoratorContext */); }
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 22 /* ImportOrExportSpecifiers */: return token() === 17 /* CloseBraceToken */; case 3 /* SwitchClauseStatements */: return token() === 17 /* CloseBraceToken */ || token() === 72 /* CaseKeyword */ || token() === 78 /* DefaultKeyword */; case 7 /* HeritageClauseElement */: return token() === 16 /* OpenBraceToken */ || token() === 84 /* ExtendsKeyword */ || token() === 107 /* ImplementsKeyword */; case 8 /* VariableDeclarations */: return isVariableDeclaratorListTerminator(); case 18 /* TypeParameters */: // Tokens other than '>' are here for better error recovery return token() === 28 /* GreaterThanToken */ || token() === 18 /* OpenParenToken */ || token() === 16 /* OpenBraceToken */ || token() === 84 /* ExtendsKeyword */ || token() === 107 /* ImplementsKeyword */; case 11 /* ArgumentExpressions */: // Tokens other than ')' are here for better error recovery return token() === 19 /* CloseParenToken */ || token() === 24 /* SemicolonToken */; case 15 /* ArrayLiteralMembers */: case 20 /* TupleElementTypes */: case 10 /* ArrayBindingElements */: return token() === 21 /* CloseBracketToken */; case 16 /* Parameters */: case 17 /* RestProperties */: // Tokens other than ')' and ']' (the latter for index signatures) are here for better error recovery return token() === 19 /* CloseParenToken */ || token() === 21 /* CloseBracketToken */ /*|| token === SyntaxKind.OpenBraceToken*/; case 19 /* TypeArguments */: // All other tokens should cause the type-argument to terminate except comma token return token() !== 25 /* CommaToken */; case 21 /* HeritageClauses */: return token() === 16 /* OpenBraceToken */ || token() === 17 /* CloseBraceToken */; case 13 /* JsxAttributes */: return token() === 28 /* GreaterThanToken */ || token() === 40 /* SlashToken */; case 14 /* JsxChildren */: return token() === 26 /* LessThanToken */ && lookAhead(nextTokenIsSlash); case 23 /* JSDocFunctionParameters */: return token() === 19 /* CloseParenToken */ || token() === 55 /* ColonToken */ || token() === 17 /* CloseBraceToken */; case 24 /* JSDocTypeArguments */: return token() === 28 /* GreaterThanToken */ || token() === 17 /* CloseBraceToken */; case 26 /* JSDocTupleTypes */: return token() === 21 /* CloseBracketToken */ || token() === 17 /* CloseBraceToken */; case 25 /* JSDocRecordMembers */: return token() === 17 /* CloseBraceToken */; } }
(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 22 /* ImportOrExportSpecifiers */: return token() === 17 /* CloseBraceToken */; case 3 /* SwitchClauseStatements */: return token() === 17 /* CloseBraceToken */ || token() === 72 /* CaseKeyword */ || token() === 78 /* DefaultKeyword */; case 7 /* HeritageClauseElement */: return token() === 16 /* OpenBraceToken */ || token() === 84 /* ExtendsKeyword */ || token() === 107 /* ImplementsKeyword */; case 8 /* VariableDeclarations */: return isVariableDeclaratorListTerminator(); case 18 /* TypeParameters */: // Tokens other than '>' are here for better error recovery return token() === 28 /* GreaterThanToken */ || token() === 18 /* OpenParenToken */ || token() === 16 /* OpenBraceToken */ || token() === 84 /* ExtendsKeyword */ || token() === 107 /* ImplementsKeyword */; case 11 /* ArgumentExpressions */: // Tokens other than ')' are here for better error recovery return token() === 19 /* CloseParenToken */ || token() === 24 /* SemicolonToken */; case 15 /* ArrayLiteralMembers */: case 20 /* TupleElementTypes */: case 10 /* ArrayBindingElements */: return token() === 21 /* CloseBracketToken */; case 16 /* Parameters */: case 17 /* RestProperties */: // Tokens other than ')' and ']' (the latter for index signatures) are here for better error recovery return token() === 19 /* CloseParenToken */ || token() === 21 /* CloseBracketToken */ /*|| token === SyntaxKind.OpenBraceToken*/; case 19 /* TypeArguments */: // All other tokens should cause the type-argument to terminate except comma token return token() !== 25 /* CommaToken */; case 21 /* HeritageClauses */: return token() === 16 /* OpenBraceToken */ || token() === 17 /* CloseBraceToken */; case 13 /* JsxAttributes */: return token() === 28 /* GreaterThanToken */ || token() === 40 /* SlashToken */; case 14 /* JsxChildren */: return token() === 26 /* LessThanToken */ && lookAhead(nextTokenIsSlash); case 23 /* JSDocFunctionParameters */: return token() === 19 /* CloseParenToken */ || token() === 55 /* ColonToken */ || token() === 17 /* CloseBraceToken */; case 24 /* JSDocTypeArguments */: return token() === 28 /* GreaterThanToken */ || token() === 17 /* CloseBraceToken */; case 26 /* JSDocTupleTypes */: return token() === 21 /* CloseBracketToken */ || token() === 17 /* CloseBraceToken */; case 25 /* JSDocRecordMembers */: return token() === 17 /* CloseBraceToken */; } }
parsePropertyOrMethodSignature:
(fullStart, modifiers) { var name = parsePropertyName(); var questionToken = parseOptionalToken(54 /* QuestionToken */); if (token() === 18 /* OpenParenToken */ || token() === 26 /* LessThanToken */) { var method = createNode(148 /* MethodSignature */, fullStart); method.modifiers = modifiers; method.name = name; method.questionToken = questionToken; // Method signatures don't exist in expression contexts. So they have neither // [Yield] nor [Await] fillSignature(55 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, method); parseTypeMemberSemicolon(); return addJSDocComment(finishNode(method)); } else { var property = createNode(146 /* PropertySignature */, fullStart); property.modifiers = modifiers; property.name = name; property.questionToken = questionToken; property.type = parseTypeAnnotation(); if (token() === 57 /* EqualsToken */) { // Although type literal properties cannot not have initializers, we attempt // to parse an initializer so we can report in the checker that an interface // property or type literal property cannot have an initializer. property.initializer = parseNonParameterInitializer(); } parseTypeMemberSemicolon(); return addJSDocComment(finishNode(property)); } }
parseTypeReference:
() { var typeName = parseEntityName(/*allowReservedWords*/ false, ts.Diagnostics.Type_expected); var node = createNode(157 /* TypeReference */, typeName.pos); node.typeName = typeName; if (!scanner.hasPrecedingLineBreak() && token() === 26 /* LessThanToken */) { node.typeArguments = parseBracketedList(19 /* TypeArguments */, parseType, 26 /* LessThanToken */, 28 /* GreaterThanToken */); } return finishNode(node); }
hasModifier:
(node, flags) { return (getModifierFlags(node) & flags) !== 0; }
canParseSemicolon:
() { // If there's a real semicolon, then we can always parse it out. if (token() === 24 /* SemicolonToken */) { return true; } // We can parse out an optional semicolon in ASI cases in the following cases. return token() === 17 /* CloseBraceToken */ || token() === 1 /* EndOfFileToken */ || scanner.hasPrecedingLineBreak(); }
parseLeftHandSideExpressionOrHigher:
() { // Original Ecma: // LeftHandSideExpression: See 11.2 // NewExpression // CallExpression // // Our simplification: // // LeftHandSideExpression: See 11.2 // MemberExpression // CallExpression // // See comment in parseMemberExpressionOrHigher on how we replaced NewExpression with // MemberExpression to make our lives easier. // // to best understand the below code, it's important to see how CallExpression expands // out into its own productions: // // CallExpression: // MemberExpression Arguments // CallExpression Arguments // CallExpression[Expression] // CallExpression.IdentifierName // super ( ArgumentListopt ) // super.IdentifierName // // Because of the recursion in these calls, we need to bottom out first. There are two // bottom out states we can run into. Either we see 'super' which must start either of // the last two CallExpression productions. Or we have a MemberExpression which either // completes the LeftHandSideExpression, or starts the beginning of the first four // CallExpression productions. var expression = token() === 96 /* SuperKeyword */ ? parseSuperExpression() : parseMemberExpressionOrHigher(); // Now, we *may* be complete. However, we might have consumed the start of a // CallExpression. As such, we need to consume the rest of it here to be complete. return parseCallExpressionRest(expression); }
parseMemberExpressionOrHigher:
() { // Note: to make our lives simpler, we decompose the the NewExpression productions and // place ObjectCreationExpression and FunctionExpression into PrimaryExpression. // like so: // // PrimaryExpression : See 11.1 // this // Identifier // Literal // ArrayLiteral // ObjectLiteral // (Expression) // FunctionExpression // new MemberExpression Arguments? // // MemberExpression : See 11.2 // PrimaryExpression // MemberExpression[Expression] // MemberExpression.IdentifierName // // CallExpression : See 11.2 // MemberExpression // CallExpression Arguments // CallExpression[Expression] // CallExpression.IdentifierName // // Technically this is ambiguous. i.e. CallExpression defines: // // CallExpression: // CallExpression Arguments // // If you see: "new Foo()" // // Then that could be treated as a single ObjectCreationExpression, or it could be // treated as the invocation of "new Foo". We disambiguate that in code (to match // the original grammar) by making sure that if we see an ObjectCreationExpression // we always consume arguments if they are there. So we treat "new Foo()" as an // object creation only, and not at all as an invocation) Another way to think // about this is that for every "new" that we see, we will consume an argument list if // it is there as part of the *associated* object creation node. Any additional // argument lists we see, will become invocation expressions. // // Because there are no other places in the grammar now that refer to FunctionExpression // or ObjectCreationExpression, it is safe to push down into the PrimaryExpression // production. // // Because CallExpression and MemberExpression are left recursive, we need to bottom out // of the recursion immediately. So we parse out a primary expression to start with. var expression = parsePrimaryExpression(); return parseMemberExpressionRest(expression); }
parseFunctionBlockOrSemicolon:
(isGenerator, isAsync, diagnosticMessage) { if (token() !== 16 /* OpenBraceToken */ && canParseSemicolon()) { parseSemicolon(); return; } return parseFunctionBlock(isGenerator, isAsync, /*ignoreMissingOpenBrace*/ false, diagnosticMessage); }
parseLiteralNode:
(internName) { return parseLiteralLikeNode(token(), internName); }
hasExtendedUnicodeEscape:
() { return hasExtendedUnicodeEscape; }
isUnterminated:
() { return tokenIsUnterminated; }
canFollowModifier:
() { return token() === 20 /* OpenBracketToken */ || token() === 16 /* OpenBraceToken */ || token() === 38 /* AsteriskToken */ || token() === 23 /* DotDotDotToken */ || isLiteralPropertyName(); }
isLeftHandSideExpression:
(node) { return isLeftHandSideExpressionKind(ts.skipPartiallyEmittedExpressions(node).kind); }
skipParameterStart:
() { if (ts.isModifierKind(token())) { // Skip modifiers parseModifiers(); } if (isIdentifier() || token() === 98 /* ThisKeyword */) { nextToken(); return true; } if (token() === 20 /* OpenBracketToken */ || token() === 16 /* OpenBraceToken */) { // Return true if we can parse an array or object binding pattern with no errors var previousErrorCount = parseDiagnostics.length; parseIdentifierOrPattern(); return previousErrorCount === parseDiagnostics.length; } return false; }
() { if (ts.isModifierKind(token())) { // Skip modifiers parseModifiers(); } if (isIdentifier() || token() === 98 /* ThisKeyword */) { nextToken(); return true; } if (token() === 20 /* OpenBracketToken */ || token() === 16 /* OpenBraceToken */) { // Return true if we can parse an array or object binding pattern with no errors var previousErrorCount = parseDiagnostics.length; parseIdentifierOrPattern(); return previousErrorCount === parseDiagnostics.length; } return false; }
parseDecorators:
() { var decorators; while (true) { var decoratorStart = getNodePos(); if (!parseOptional(56 /* AtToken */)) { break; } var decorator = createNode(145 /* Decorator */, decoratorStart); decorator.expression = doInDecoratorContext(parseLeftHandSideExpressionOrHigher); finishNode(decorator); if (!decorators) { decorators = createNodeArray([decorator], decoratorStart); } else { decorators.push(decorator); } } if (decorators) { decorators.end = getNodeEnd(); } return decorators; }
nextTokenIsIdentifierOnSameLine:
() { nextToken(); return !scanner.hasPrecedingLineBreak() && isIdentifier(); }
isDeclaration:
() { while (true) { switch (token()) { case 103 /* VarKeyword */: case 109 /* LetKeyword */: case 75 /* ConstKeyword */: case 88 /* FunctionKeyword */: case 74 /* ClassKeyword */: case 82 /* EnumKeyword */: return true; // 'declare', 'module', 'namespace', 'interface'* and 'type' are all legal JavaScript identifiers; // however, an identifier cannot be followed by another identifier on the same line. This is what we // count on to parse out the respective declarations. For instance, we exploit this to say that // // namespace n // // can be none other than the beginning of a namespace declaration, but need to respect that JavaScript sees // // namespace // n // // as the identifier 'namespace' on one line followed by the identifier 'n' on another. // We need to look one token ahead to see if it permissible to try parsing a declaration. // // *Note*: 'interface' is actually a strict mode reserved word. So while // // "use strict" // interface // I {} // // could be legal, it would add complexity for very little gain. case 108 /* InterfaceKeyword */: case 136 /* TypeKeyword */: return nextTokenIsIdentifierOnSameLine(); case 127 /* ModuleKeyword */: case 128 /* NamespaceKeyword */: return nextTokenIsIdentifierOrStringLiteralOnSameLine(); case 116 /* AbstractKeyword */: case 119 /* AsyncKeyword */: case 123 /* DeclareKeyword */: case 111 /* PrivateKeyword */: case 112 /* ProtectedKeyword */: case 113 /* PublicKeyword */: case 130 /* ReadonlyKeyword */: nextToken(); // ASI takes effect for this modifier. if (scanner.hasPrecedingLineBreak()) { return false; } continue; case 139 /* GlobalKeyword */: nextToken(); return token() === 16 /* OpenBraceToken */ || token() === 70 /* Identifier */ || token() === 83 /* ExportKeyword */; case 90 /* ImportKeyword */: nextToken(); return token() === 9 /* StringLiteral */ || token() === 38 /* AsteriskToken */ || token() === 16 /* OpenBraceToken */ || ts.tokenIsIdentifierOrKeyword(token()); case 83 /* ExportKeyword */: nextToken(); if (token() === 57 /* EqualsToken */ || token() === 38 /* AsteriskToken */ || token() === 16 /* OpenBraceToken */ || token() === 78 /* DefaultKeyword */ || token() === 117 /* AsKeyword */) { return true; } continue; case 114 /* StaticKeyword */: nextToken(); continue; default: return false; } } }
setDisallowInContext:
(val) { setContextFlag(val, 2048 /* DisallowInContext */); }
scanString:
(allowEscapes) { if (allowEscapes === void 0) { allowEscapes = true; } var quote = text.charCodeAt(pos); pos++; var result = ""; var start = pos; while (true) { if (pos >= end) { result += text.substring(start, pos); tokenIsUnterminated = true; error(ts.Diagnostics.Unterminated_string_literal); break; } var ch = text.charCodeAt(pos); if (ch === quote) { result += text.substring(start, pos); pos++; break; } if (ch === 92 /* backslash */ && allowEscapes) { result += text.substring(start, pos); result += scanEscapeSequence(); start = pos; continue; } if (isLineBreak(ch)) { result += text.substring(start, pos); tokenIsUnterminated = true; error(ts.Diagnostics.Unterminated_string_literal); break; } pos++; } return result; }
isStartOfStatement:
() { switch (token()) { case 56 /* AtToken */: case 24 /* SemicolonToken */: case 16 /* OpenBraceToken */: case 103 /* VarKeyword */: case 109 /* LetKeyword */: case 88 /* FunctionKeyword */: case 74 /* ClassKeyword */: case 82 /* EnumKeyword */: case 89 /* IfKeyword */: case 80 /* DoKeyword */: case 105 /* WhileKeyword */: case 87 /* ForKeyword */: case 76 /* ContinueKeyword */: case 71 /* BreakKeyword */: case 95 /* ReturnKeyword */: case 106 /* WithKeyword */: case 97 /* SwitchKeyword */: case 99 /* ThrowKeyword */: case 101 /* TryKeyword */: case 77 /* DebuggerKeyword */: // 'catch' and 'finally' do not actually indicate that the code is part of a statement, // however, we say they are here so that we may gracefully parse them and error later. case 73 /* CatchKeyword */: case 86 /* FinallyKeyword */: return true; case 75 /* ConstKeyword */: case 83 /* ExportKeyword */: case 90 /* ImportKeyword */: return isStartOfDeclaration(); case 119 /* AsyncKeyword */: case 123 /* DeclareKeyword */: case 108 /* InterfaceKeyword */: case 127 /* ModuleKeyword */: case 128 /* NamespaceKeyword */: case 136 /* TypeKeyword */: case 139 /* GlobalKeyword */: // When these don't start a declaration, they're an identifier in an expression statement return true; case 113 /* PublicKeyword */: case 111 /* PrivateKeyword */: case 112 /* ProtectedKeyword */: case 114 /* StaticKeyword */: case 130 /* ReadonlyKeyword */: // When these don't start a declaration, they may be the start of a class member if an identifier // immediately follows. Otherwise they're an identifier in an expression statement. return isStartOfDeclaration() || !lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine); default: return isStartOfExpression(); } }
parseStatement:
() { switch (token()) { case 24 /* SemicolonToken */: return parseEmptyStatement(); case 16 /* OpenBraceToken */: return parseBlock(/*ignoreMissingOpenBrace*/ false); case 103 /* VarKeyword */: return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined); case 109 /* LetKeyword */: if (isLetDeclaration()) { return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined); } break; case 88 /* FunctionKeyword */: return parseFunctionDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined); case 74 /* ClassKeyword */: return parseClassDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined); case 89 /* IfKeyword */: return parseIfStatement(); case 80 /* DoKeyword */: return parseDoStatement(); case 105 /* WhileKeyword */: return parseWhileStatement(); case 87 /* ForKeyword */: return parseForOrForInOrForOfStatement(); case 76 /* ContinueKeyword */: return parseBreakOrContinueStatement(214 /* ContinueStatement */); case 71 /* BreakKeyword */: return parseBreakOrContinueStatement(215 /* BreakStatement */); case 95 /* ReturnKeyword */: return parseReturnStatement(); case 106 /* WithKeyword */: return parseWithStatement(); case 97 /* SwitchKeyword */: return parseSwitchStatement(); case 99 /* ThrowKeyword */: return parseThrowStatement(); case 101 /* TryKeyword */: // Include 'catch' and 'finally' for error recovery. case 73 /* CatchKeyword */: case 86 /* FinallyKeyword */: return parseTryStatement(); case 77 /* DebuggerKeyword */: return parseDebuggerStatement(); case 56 /* AtToken */: return parseDeclaration(); case 119 /* AsyncKeyword */: case 108 /* InterfaceKeyword */: case 136 /* TypeKeyword */: case 127 /* ModuleKeyword */: case 128 /* NamespaceKeyword */: case 123 /* DeclareKeyword */: case 75 /* ConstKeyword */: case 82 /* EnumKeyword */: case 83 /* ExportKeyword */: case 90 /* ImportKeyword */: case 111 /* PrivateKeyword */: case 112 /* ProtectedKeyword */: case 113 /* PublicKeyword */: case 116 /* AbstractKeyword */: case 114 /* StaticKeyword */: case 130 /* ReadonlyKeyword */: case 139 /* GlobalKeyword */: if (isStartOfDeclaration()) { return parseDeclaration(); } break; } return parseExpressionOrLabeledStatement(); }
parseDeclaration:
() { var fullStart = getNodePos(); var decorators = parseDecorators(); var modifiers = parseModifiers(); switch (token()) { case 103 /* VarKeyword */: case 109 /* LetKeyword */: case 75 /* ConstKeyword */: return parseVariableStatement(fullStart, decorators, modifiers); case 88 /* FunctionKeyword */: return parseFunctionDeclaration(fullStart, decorators, modifiers); case 74 /* ClassKeyword */: return parseClassDeclaration(fullStart, decorators, modifiers); case 108 /* InterfaceKeyword */: return parseInterfaceDeclaration(fullStart, decorators, modifiers); case 136 /* TypeKeyword */: return parseTypeAliasDeclaration(fullStart, decorators, modifiers); case 82 /* EnumKeyword */: return parseEnumDeclaration(fullStart, decorators, modifiers); case 139 /* GlobalKeyword */: case 127 /* ModuleKeyword */: case 128 /* NamespaceKeyword */: return parseModuleDeclaration(fullStart, decorators, modifiers); case 90 /* ImportKeyword */: return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); case 83 /* ExportKeyword */: nextToken(); switch (token()) { case 78 /* DefaultKeyword */: case 57 /* EqualsToken */: return parseExportAssignment(fullStart, decorators, modifiers); case 117 /* AsKeyword */: return parseNamespaceExportDeclaration(fullStart, decorators, modifiers); default: return parseExportDeclaration(fullStart, decorators, modifiers); } default: if (decorators || modifiers) { // We reached this point because we encountered decorators and/or modifiers and assumed a declaration // would follow. For recovery and error reporting purposes, return an incomplete declaration. var node = createMissingNode(244 /* MissingDeclaration */, /*reportAtCurrentPosition*/ true, ts.Diagnostics.Declaration_expected); node.pos = fullStart; node.decorators = decorators; node.modifiers = modifiers; return finishNode(node); } } }
parseModifiers:
(permitInvalidConstAsModifier) { var modifiers; while (true) { var modifierStart = scanner.getStartPos(); var modifierKind = token(); if (token() === 75 /* ConstKeyword */ && permitInvalidConstAsModifier) { // We need to ensure that any subsequent modifiers appear on the same line // so that when 'const' is a standalone declaration, we don't issue an error. if (!tryParse(nextTokenIsOnSameLineAndCanFollowModifier)) { break; } } else { if (!parseAnyContextualModifier()) { break; } } var modifier = finishNode(createNode(modifierKind, modifierStart)); if (!modifiers) { modifiers = createNodeArray([modifier], modifierStart); } else { modifiers.push(modifier); } } if (modifiers) { modifiers.end = scanner.getStartPos(); } return modifiers; }
parsePrimaryExpression:
() { switch (token()) { case 8 /* NumericLiteral */: case 9 /* StringLiteral */: case 12 /* NoSubstitutionTemplateLiteral */: return parseLiteralNode(); case 98 /* ThisKeyword */: case 96 /* SuperKeyword */: case 94 /* NullKeyword */: case 100 /* TrueKeyword */: case 85 /* FalseKeyword */: return parseTokenNode(); case 18 /* OpenParenToken */: return parseParenthesizedExpression(); case 20 /* OpenBracketToken */: return parseArrayLiteralExpression(); case 16 /* OpenBraceToken */: return parseObjectLiteralExpression(); case 119 /* AsyncKeyword */: // Async arrow functions are parsed earlier in parseAssignmentExpressionOrHigher. // If we encounter `async [no LineTerminator here] function` then this is an async // function; otherwise, its an identifier. if (!lookAhead(nextTokenIsFunctionKeywordOnSameLine)) { break; } return parseFunctionExpression(); case 74 /* ClassKeyword */: return parseClassExpression(); case 88 /* FunctionKeyword */: return parseFunctionExpression(); case 93 /* NewKeyword */: return parseNewExpression(); case 40 /* SlashToken */: case 62 /* SlashEqualsToken */: if (reScanSlashToken() === 11 /* RegularExpressionLiteral */) { return parseLiteralNode(); } break; case 13 /* TemplateHead */: return parseTemplateExpression(); } return parseIdentifier(ts.Diagnostics.Expression_expected); }
parseArrayTypeOrHigher:
() { var type = parseNonArrayType(); while (!scanner.hasPrecedingLineBreak() && parseOptional(20 /* OpenBracketToken */)) { if (isStartOfType()) { var node = createNode(169 /* IndexedAccessType */, type.pos); node.objectType = type; node.indexType = parseType(); parseExpected(21 /* CloseBracketToken */); type = finishNode(node); } else { var node = createNode(162 /* ArrayType */, type.pos); node.elementType = type; parseExpected(21 /* CloseBracketToken */); type = finishNode(node); } } return type; }
() { var type = parseNonArrayType(); while (!scanner.hasPrecedingLineBreak() && parseOptional(20 /* OpenBracketToken */)) { if (isStartOfType()) { var node = createNode(169 /* IndexedAccessType */, type.pos); node.objectType = type; node.indexType = parseType(); parseExpected(21 /* CloseBracketToken */); type = finishNode(node); } else { var node = createNode(162 /* ArrayType */, type.pos); node.elementType = type; parseExpected(21 /* CloseBracketToken */); type = finishNode(node); } } return type; }
nextTokenCanFollowModifier:
() { if (token() === 75 /* ConstKeyword */) { // 'const' is only a modifier if followed by 'enum'. return nextToken() === 82 /* EnumKeyword */; } if (token() === 83 /* ExportKeyword */) { nextToken(); if (token() === 78 /* DefaultKeyword */) { return lookAhead(nextTokenIsClassOrFunctionOrAsync); } return token() !== 38 /* AsteriskToken */ && token() !== 117 /* AsKeyword */ && token() !== 16 /* OpenBraceToken */ && canFollowModifier(); } if (token() === 78 /* DefaultKeyword */) { return nextTokenIsClassOrFunctionOrAsync(); } if (token() === 114 /* StaticKeyword */) { nextToken(); return canFollowModifier(); } return nextTokenIsOnSameLineAndCanFollowModifier(); }
() { if (token() === 75 /* ConstKeyword */) { // 'const' is only a modifier if followed by 'enum'. return nextToken() === 82 /* EnumKeyword */; } if (token() === 83 /* ExportKeyword */) { nextToken(); if (token() === 78 /* DefaultKeyword */) { return lookAhead(nextTokenIsClassOrFunctionOrAsync); } return token() !== 38 /* AsteriskToken */ && token() !== 117 /* AsKeyword */ && token() !== 16 /* OpenBraceToken */ && canFollowModifier(); } if (token() === 78 /* DefaultKeyword */) { return nextTokenIsClassOrFunctionOrAsync(); } if (token() === 114 /* StaticKeyword */) { nextToken(); return canFollowModifier(); } return nextTokenIsOnSameLineAndCanFollowModifier(); }
addJSDocComment:
(node) { var comments = ts.getJSDocCommentRanges(node, sourceFile.text); if (comments) { for (var _i = 0, comments_2 = comments; _i < comments_2.length; _i++) { var comment = comments_2[_i]; var jsDoc = JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos); if (!jsDoc) { continue; } if (!node.jsDoc) { node.jsDoc = []; } node.jsDoc.push(jsDoc); } } return node; }
(node) { var comments = ts.getJSDocCommentRanges(node, sourceFile.text); if (comments) { for (var _i = 0, comments_2 = comments; _i < comments_2.length; _i++) { var comment = comments_2[_i]; var jsDoc = JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos); if (!jsDoc) { continue; } if (!node.jsDoc) { node.jsDoc = []; } node.jsDoc.push(jsDoc); } } return node; }
filter:
(array, f) { if (array) { var len = array.length; var i = 0; while (i < len && f(array[i])) i++; if (i < len) { var result = array.slice(0, i); i++; while (i < len) { var item = array[i]; if (f(item)) { result.push(item); } i++; } return result; } } return array; }
(array, f) { if (array) { var len = array.length; var i = 0; while (i < len && f(array[i])) i++; if (i < len) { var result = array.slice(0, i); i++; while (i < len) { var item = array[i]; if (f(item)) { result.push(item); } i++; } return result; } } return array; }
parseRightSideOfDot:
(allowIdentifierNames) { // Technically a keyword is valid here as all identifiers and keywords are identifier names. // However, often we'll encounter this in error situations when the identifier or keyword // is actually starting another valid construct. // // So, we check for the following specific case: // // name. // identifierOrKeyword identifierNameOrKeyword // // Note: the newlines are important here. For example, if that above code // were rewritten into: // // name.identifierOrKeyword // identifierNameOrKeyword // // Then we would consider it valid. That's because ASI would take effect and // the code would be implicitly: "name.identifierOrKeyword; identifierNameOrKeyword". // In the first case though, ASI will not take effect because there is not a // line terminator after the identifier or keyword. if (scanner.hasPrecedingLineBreak() && ts.tokenIsIdentifierOrKeyword(token())) { var matchesPattern = lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine); if (matchesPattern) { // Report that we need an identifier. However, report it right after the dot, // and not on the next token. This is because the next token might actually // be an identifier and the error would be quite confusing. return createMissingNode(70 /* Identifier */, /*reportAtCurrentPosition*/ true, ts.Diagnostics.Identifier_expected); } } return allowIdentifierNames ? parseIdentifierName() : parseIdentifier(); }
isUnambiguouslyStartOfFunctionType:
() { nextToken(); if (token() === 19 /* CloseParenToken */ || token() === 23 /* DotDotDotToken */) { // ( ) // ( ... return true; } if (skipParameterStart()) { // We successfully skipped modifiers (if any) and an identifier or binding pattern, // now see if we have something that indicates a parameter declaration if (token() === 55 /* ColonToken */ || token() === 25 /* CommaToken */ || token() === 54 /* QuestionToken */ || token() === 57 /* EqualsToken */) { // ( xxx : // ( xxx , // ( xxx ? // ( xxx = return true; } if (token() === 19 /* CloseParenToken */) { nextToken(); if (token() === 35 /* EqualsGreaterThanToken */) { // ( xxx ) => return true; } } } return false; }
parseObjectTypeMembers:
() { var members; if (parseExpected(16 /* OpenBraceToken */)) { members = parseList(4 /* TypeMembers */, parseTypeMember); parseExpected(17 /* CloseBraceToken */); } else { members = createMissingList(); } return members; }
Deopt: <JS Function nextTokenCanFollowModifier (SharedFunctionInfo 0x2c75c4af4159)> (opt #118) @50, FP to SP delta: 128, caller sp: 0x7fff5fbfd518
scanJSDocToken:
() { if (pos >= end) { return token = 1 /* EndOfFileToken */; } startPos = pos; tokenPos = pos; var ch = text.charCodeAt(pos); switch (ch) { case 9 /* tab */: case 11 /* verticalTab */: case 12 /* formFeed */: case 32 /* space */: while (pos < end && isWhiteSpaceSingleLine(text.charCodeAt(pos))) { pos++; } return token = 5 /* WhitespaceTrivia */; case 64 /* at */: pos++; return token = 56 /* AtToken */; case 10 /* lineFeed */: case 13 /* carriageReturn */: pos++; return token = 4 /* NewLineTrivia */; case 42 /* asterisk */: pos++; return token = 38 /* AsteriskToken */; case 123 /* openBrace */: pos++; return token = 16 /* OpenBraceToken */; case 125 /* closeBrace */: pos++; return token = 17 /* CloseBraceToken */; case 91 /* openBracket */: pos++; return token = 20 /* OpenBracketToken */; case 93 /* closeBracket */: pos++; return token = 21 /* CloseBracketToken */; case 61 /* equals */: pos++; return token = 57 /* EqualsToken */; case 44 /* comma */: pos++; return token = 25 /* CommaToken */; case 46 /* dot */: pos++; return token = 22 /* DotToken */; } if (isIdentifierStart(ch, 5 /* Latest */)) { pos++; while (isIdentifierPart(text.charCodeAt(pos), 5 /* Latest */) && pos < end) { pos++; } return token = 70 /* Identifier */; } else { return pos += 1, token = 0 /* Unknown */; } }
parseDelimitedList:
(kind, parseElement, considerSemicolonAsDelimiter) { var saveParsingContext = parsingContext; parsingContext |= 1 << kind; var result = createNodeArray(); var commaStart = -1; // Meaning the previous token was not a comma while (true) { if (isListElement(kind, /*inErrorRecovery*/ false)) { result.push(parseListElement(kind, parseElement)); commaStart = scanner.getTokenPos(); if (parseOptional(25 /* CommaToken */)) { continue; } commaStart = -1; // Back to the state where the last token was not a comma if (isListTerminator(kind)) { break; } // We didn't get a comma, and the list wasn't terminated, explicitly parse // out a comma so we give a good error message. parseExpected(25 /* CommaToken */); // If the token was a semicolon, and the caller allows that, then skip it and // continue. This ensures we get back on track and don't result in tons of // parse errors. For example, this can happen when people do things like use // a semicolon to delimit object literal members. Note: we'll have already // reported an error when we called parseExpected above. if (considerSemicolonAsDelimiter && token() === 24 /* SemicolonToken */ && !scanner.hasPrecedingLineBreak()) { nextToken(); } continue; } if (isListTerminator(kind)) { break; } if (abortParsingListOrMoveToNextToken(kind)) { break; } } // Recording the trailing comma is deliberately done after the previous // loop, and not just if we see a list terminator. This is because the list // may have ended incorrectly, but it is still important to know if there // was a trailing comma. // Check if the last token was a comma. if (commaStart >= 0) { // Always preserve a trailing comma by marking it on the NodeArray result.hasTrailingComma = true; } result.end = getNodeEnd(); parsingContext = saveParsingContext; return result; }
getTextPos:
() { return pos; }
parseVariableDeclaration:
() { var node = createNode(223 /* VariableDeclaration */); node.name = parseIdentifierOrPattern(); node.type = parseTypeAnnotation(); if (!isInOrOfKeyword(token())) { node.initializer = parseInitializer(/*inParameter*/ false); } return finishNode(node); }
isVariableDeclaratorListTerminator:
() { // If we can consume a semicolon (either explicitly, or with ASI), then consider us done // with parsing the list of variable declarators. if (canParseSemicolon()) { return true; } // in the case where we're parsing the variable declarator of a 'for-in' statement, we // are done if we see an 'in' keyword in front of us. Same with for-of if (isInOrOfKeyword(token())) { return true; } // ERROR RECOVERY TWEAK: // For better error recovery, if we see an '=>' then we just stop immediately. We've got an // arrow function here and it's going to be very unlikely that we'll resynchronize and get // another variable declaration. if (token() === 35 /* EqualsGreaterThanToken */) { return true; } // Keep trying to parse out variable declarators. return false; }
setText:
(newText, start, length) { text = newText || ""; end = length === undefined ? text.length : start + length; setTextPos(start || 0); }
parsePropertyNameWorker:
(allowComputedPropertyNames) { if (token() === 9 /* StringLiteral */ || token() === 8 /* NumericLiteral */) { return parseLiteralNode(/*internName*/ true); } if (allowComputedPropertyNames && token() === 20 /* OpenBracketToken */) { return parseComputedPropertyName(); } return parseIdentifierName(); }
parseJSDocComment:
(parent, start, length) { var saveToken = currentToken; var saveParseDiagnosticsLength = parseDiagnostics.length; var saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; var comment = parseJSDocCommentWorker(start, length); if (comment) { comment.parent = parent; } currentToken = saveToken; parseDiagnostics.length = saveParseDiagnosticsLength; parseErrorBeforeNextFinishedNode = saveParseErrorBeforeNextFinishedNode; return comment; }
parseLiteralLikeNode:
(kind, internName) { var node = createNode(kind); var text = scanner.getTokenValue(); node.text = internName ? internIdentifier(text) : text; if (scanner.hasExtendedUnicodeEscape()) { node.hasExtendedUnicodeEscape = true; } if (scanner.isUnterminated()) { node.isUnterminated = true; } var tokenPos = scanner.getTokenPos(); nextToken(); finishNode(node); // Octal literals are not allowed in strict mode or ES5 // Note that theoretically the following condition would hold true literals like 009, // which is not octal.But because of how the scanner separates the tokens, we would // never get a token like this. Instead, we would get 00 and 9 as two separate tokens. // We also do not need to check for negatives because any prefix operator would be part of a // parent unary expression. if (node.kind === 8 /* NumericLiteral */ && sourceText.charCodeAt(tokenPos) === 48 /* _0 */ && ts.isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) { node.isOctalLiteral = true; } return node; }
(kind, internName) { var node = createNode(kind); var text = scanner.getTokenValue(); node.text = internName ? internIdentifier(text) : text; if (scanner.hasExtendedUnicodeEscape()) { node.hasExtendedUnicodeEscape = true; } if (scanner.isUnterminated()) { node.isUnterminated = true; } var tokenPos = scanner.getTokenPos(); nextToken(); finishNode(node); // Octal literals are not allowed in strict mode or ES5 // Note that theoretically the following condition would hold true literals like 009, // which is not octal.But because of how the scanner separates the tokens, we would // never get a token like this. Instead, we would get 00 and 9 as two separate tokens. // We also do not need to check for negatives because any prefix operator would be part of a // parent unary expression. if (node.kind === 8 /* NumericLiteral */ && sourceText.charCodeAt(tokenPos) === 48 /* _0 */ && ts.isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) { node.isOctalLiteral = true; } return node; }
isLeftHandSideExpressionKind:
(kind) { return kind === 177 /* PropertyAccessExpression */ || kind === 178 /* ElementAccessExpression */ || kind === 180 /* NewExpression */ || kind === 179 /* CallExpression */ || kind === 246 /* JsxElement */ || kind === 247 /* JsxSelfClosingElement */ || kind === 181 /* TaggedTemplateExpression */ || kind === 175 /* ArrayLiteralExpression */ || kind === 183 /* ParenthesizedExpression */ || kind === 176 /* ObjectLiteralExpression */ || kind === 197 /* ClassExpression */ || kind === 184 /* FunctionExpression */ || kind === 70 /* Identifier */ || kind === 11 /* RegularExpressionLiteral */ || kind === 8 /* NumericLiteral */ || kind === 9 /* StringLiteral */ || kind === 12 /* NoSubstitutionTemplateLiteral */ || kind === 194 /* TemplateExpression */ || kind === 85 /* FalseKeyword */ || kind === 94 /* NullKeyword */ || kind === 98 /* ThisKeyword */ || kind === 100 /* TrueKeyword */ || kind === 96 /* SuperKeyword */ || kind === 201 /* NonNullExpression */; }
parseIncrementExpression:
() { if (token() === 42 /* PlusPlusToken */ || token() === 43 /* MinusMinusToken */) { var node = createNode(190 /* PrefixUnaryExpression */); node.operator = token(); nextToken(); node.operand = parseLeftHandSideExpressionOrHigher(); return finishNode(node); } else if (sourceFile.languageVariant === 1 /* JSX */ && token() === 26 /* LessThanToken */ && lookAhead(nextTokenIsIdentifierOrKeyword)) { // JSXElement is part of primaryExpression return parseJsxElementOrSelfClosingElement(/*inExpressionContext*/ true); } var expression = parseLeftHandSideExpressionOrHigher(); ts.Debug.assert(ts.isLeftHandSideExpression(expression)); if ((token() === 42 /* PlusPlusToken */ || token() === 43 /* MinusMinusToken */) && !scanner.hasPrecedingLineBreak()) { var node = createNode(191 /* PostfixUnaryExpression */, expression.pos); node.operand = expression; node.operator = token(); nextToken(); return finishNode(node); } return expression; }
parseSimpleUnaryExpression:
() { switch (token()) { case 36 /* PlusToken */: case 37 /* MinusToken */: case 51 /* TildeToken */: case 50 /* ExclamationToken */: return parsePrefixUnaryExpression(); case 79 /* DeleteKeyword */: return parseDeleteExpression(); case 102 /* TypeOfKeyword */: return parseTypeOfExpression(); case 104 /* VoidKeyword */: return parseVoidExpression(); case 26 /* LessThanToken */: // This is modified UnaryExpression grammar in TypeScript // UnaryExpression (modified): // < type > UnaryExpression return parseTypeAssertion(); case 120 /* AwaitKeyword */: if (isAwaitExpression()) { return parseAwaitExpression(); } default: return parseIncrementExpression(); } }
isKeyword:
(token) { return 71 /* FirstKeyword */ <= token && token <= 140 /* LastKeyword */; }
tryParseAccessorDeclaration:
(fullStart, decorators, modifiers) { if (parseContextualModifier(124 /* GetKeyword */)) { return parseAccessorDeclaration(151 /* GetAccessor */, fullStart, decorators, modifiers); } else if (parseContextualModifier(133 /* SetKeyword */)) { return parseAccessorDeclaration(152 /* SetAccessor */, fullStart, decorators, modifiers); } return undefined; }
parsePropertyOrMethodDeclaration:
(fullStart, decorators, modifiers) { var asteriskToken = parseOptionalToken(38 /* AsteriskToken */); var name = parsePropertyName(); // Note: this is not legal as per the grammar. But we allow it in the parser and // report an error in the grammar checker. var questionToken = parseOptionalToken(54 /* QuestionToken */); if (asteriskToken || token() === 18 /* OpenParenToken */ || token() === 26 /* LessThanToken */) { return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, ts.Diagnostics.or_expected); } else { return parsePropertyDeclaration(fullStart, decorators, modifiers, name, questionToken); } }
parseMethodDeclaration:
(fullStart, decorators, modifiers, asteriskToken, name, questionToken, diagnosticMessage) { var method = createNode(149 /* MethodDeclaration */, fullStart); method.decorators = decorators; method.modifiers = modifiers; method.asteriskToken = asteriskToken; method.name = name; method.questionToken = questionToken; var isGenerator = !!asteriskToken; var isAsync = ts.hasModifier(method, 256 /* Async */); fillSignature(55 /* ColonToken */, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, method); method.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, diagnosticMessage); return addJSDocComment(finishNode(method)); }
modifierToFlag:
(token) { switch (token) { case 114 /* StaticKeyword */: return 32 /* Static */; case 113 /* PublicKeyword */: return 4 /* Public */; case 112 /* ProtectedKeyword */: return 16 /* Protected */; case 111 /* PrivateKeyword */: return 8 /* Private */; case 116 /* AbstractKeyword */: return 128 /* Abstract */; case 83 /* ExportKeyword */: return 1 /* Export */; case 123 /* DeclareKeyword */: return 2 /* Ambient */; case 75 /* ConstKeyword */: return 2048 /* Const */; case 78 /* DefaultKeyword */: return 512 /* Default */; case 119 /* AsyncKeyword */: return 256 /* Async */; case 130 /* ReadonlyKeyword */: return 64 /* Readonly */; } return 0 /* None */; }
(token) { switch (token) { case 114 /* StaticKeyword */: return 32 /* Static */; case 113 /* PublicKeyword */: return 4 /* Public */; case 112 /* ProtectedKeyword */: return 16 /* Protected */; case 111 /* PrivateKeyword */: return 8 /* Private */; case 116 /* AbstractKeyword */: return 128 /* Abstract */; case 83 /* ExportKeyword */: return 1 /* Export */; case 123 /* DeclareKeyword */: return 2 /* Ambient */; case 75 /* ConstKeyword */: return 2048 /* Const */; case 78 /* DefaultKeyword */: return 512 /* Default */; case 119 /* AsyncKeyword */: return 256 /* Async */; case 130 /* ReadonlyKeyword */: return 64 /* Readonly */; } return 0 /* None */; }
parseFunctionDeclaration:
(fullStart, decorators, modifiers) { var node = createNode(225 /* FunctionDeclaration */, fullStart); node.decorators = decorators; node.modifiers = modifiers; parseExpected(88 /* FunctionKeyword */); node.asteriskToken = parseOptionalToken(38 /* AsteriskToken */); node.name = ts.hasModifier(node, 512 /* Default */) ? parseOptionalIdentifier() : parseIdentifier(); var isGenerator = !!node.asteriskToken; var isAsync = ts.hasModifier(node, 256 /* Async */); fillSignature(55 /* ColonToken */, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node); node.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, ts.Diagnostics.or_expected); return addJSDocComment(finishNode(node)); }
currentNode:
(parsingContext) { // If there is an outstanding parse error that we've encountered, but not attached to // some node, then we cannot get a node from the old source tree. This is because we // want to mark the next node we encounter as being unusable. // // Note: This may be too conservative. Perhaps we could reuse the node and set the bit // on it (or its leftmost child) as having the error. For now though, being conservative // is nice and likely won't ever affect perf. if (parseErrorBeforeNextFinishedNode) { return undefined; } if (!syntaxCursor) { // if we don't have a cursor, we could never return a node from the old tree. return undefined; } var node = syntaxCursor.currentNode(scanner.getStartPos()); // Can't reuse a missing node. if (ts.nodeIsMissing(node)) { return undefined; } // Can't reuse a node that intersected the change range. if (node.intersectsChange) { return undefined; } // Can't reuse a node that contains a parse error. This is necessary so that we // produce the same set of errors again. if (ts.containsParseError(node)) { return undefined; } // We can only reuse a node if it was parsed under the same strict mode that we're // currently in. i.e. if we originally parsed a node in non-strict mode, but then // the user added 'using strict' at the top of the file, then we can't use that node // again as the presence of strict mode may cause us to parse the tokens in the file // differently. // // Note: we *can* reuse tokens when the strict mode changes. That's because tokens // are unaffected by strict mode. It's just the parser will decide what to do with it // differently depending on what mode it is in. // // This also applies to all our other context flags as well. var nodeContextFlags = node.flags & 96256 /* ContextFlags */; if (nodeContextFlags !== contextFlags) { return undefined; } // Ok, we have a node that looks like it could be reused. Now verify that it is valid // in the current list parsing context that we're currently at. if (!canReuseNode(node, parsingContext)) { return undefined; } return node; }
parseVariableDeclarationList:
(inForStatementInitializer) { var node = createNode(224 /* VariableDeclarationList */); switch (token()) { case 103 /* VarKeyword */: break; case 109 /* LetKeyword */: node.flags |= 1 /* Let */; break; case 75 /* ConstKeyword */: node.flags |= 2 /* Const */; break; default: ts.Debug.fail(); } nextToken(); // The user may have written the following: // // for (let of X) { } // // In this case, we want to parse an empty declaration list, and then parse 'of' // as a keyword. The reason this is not automatic is that 'of' is a valid identifier. // So we need to look ahead to determine if 'of' should be treated as a keyword in // this context. // The checker will then give an error that there is an empty declaration list. if (token() === 140 /* OfKeyword */ && lookAhead(canFollowContextualOfKeyword)) { node.declarations = createMissingList(); } else { var savedDisallowIn = inDisallowInContext(); setDisallowInContext(inForStatementInitializer); node.declarations = parseDelimitedList(8 /* VariableDeclarations */, parseVariableDeclaration); setDisallowInContext(savedDisallowIn); } return finishNode(node); }
tryParseTypeExpression:
() { return tryParse(function () { skipWhitespace(); if (token() !== 16 /* OpenBraceToken */) { return undefined; } return parseJSDocTypeExpression(); }); }
parseTagComments:
(indent) { var comments = []; var state = 0 /* BeginningOfLine */; var margin; function pushComment(text) { if (!margin) { margin = indent; } comments.push(text); indent += text.length; } while (token() !== 56 /* AtToken */ && token() !== 1 /* EndOfFileToken */) { switch (token()) { case 4 /* NewLineTrivia */: if (state >= 1 /* SawAsterisk */) { state = 0 /* BeginningOfLine */; comments.push(scanner.getTokenText()); } indent = 0; break; case 56 /* AtToken */: // Done break; case 5 /* WhitespaceTrivia */: if (state === 2 /* SavingComments */) { pushComment(scanner.getTokenText()); } else { var whitespace = scanner.getTokenText(); // if the whitespace crosses the margin, take only the whitespace that passes the margin if (margin !== undefined && indent + whitespace.length > margin) { comments.push(whitespace.slice(margin - indent - 1)); } indent += whitespace.length; } break; case 38 /* AsteriskToken */: if (state === 0 /* BeginningOfLine */) { // leading asterisks start recording on the *next* (non-whitespace) token state = 1 /* SawAsterisk */; indent += scanner.getTokenText().length; break; } // FALLTHROUGH otherwise to record the * as a comment default: state = 2 /* SavingComments */; // leading identifiers start recording as well pushComment(scanner.getTokenText()); break; } if (token() === 56 /* AtToken */) { // Done break; } nextJSDocToken(); } removeLeadingNewlines(comments); removeTrailingNewlines(comments); return comments; }
parseJSDocIdentifierName:
() { return createJSDocIdentifier(ts.tokenIsIdentifierOrKeyword(token())); }
createJSDocIdentifier:
(isIdentifier) { if (!isIdentifier) { parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected); return undefined; } var pos = scanner.getTokenPos(); var end = scanner.getTextPos(); var result = createNode(70 /* Identifier */, pos); result.text = content.substring(pos, end); finishNode(result, end); nextJSDocToken(); return result; }
setTextPos:
(textPos) { ts.Debug.assert(textPos >= 0); pos = textPos; startPos = textPos; tokenPos = textPos; token = 0 /* Unknown */; precedingLineBreak = false; tokenValue = undefined; hasExtendedUnicodeEscape = false; tokenIsUnterminated = false; }
:
(comment) { return text.charCodeAt(comment.pos + 1) === 42 /* asterisk */ && text.charCodeAt(comment.pos + 2) === 42 /* asterisk */ && text.charCodeAt(comment.pos + 3) !== 47 /* slash */; }
(node) { return ts.hasModifier(node, 1 /* Export */) || node.kind === 234 /* ImportEqualsDeclaration */ && node.moduleReference.kind === 245 /* ExternalModuleReference */ || node.kind === 235 /* ImportDeclaration */ || node.kind === 240 /* ExportAssignment */ || node.kind === 241 /* ExportDeclaration */ ? node : undefined; }
(p) { seen[p.name] = { prop: p, containingType: type }; }
(p) { seen[p.name] = { prop: p, containingType: type }; }
(t) { return t === source ? target : t; }
(heritageElement) { if (!ts.isEntityNameExpression(heritageElement.expression)) { error(heritageElement.expression, ts.Diagnostics.An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments); } checkTypeReferenceNode(heritageElement); }
parseJSDocCommentWorker:
(start, length) { var content = sourceText; start = start || 0; var end = length === undefined ? content.length : start + length; length = end - start; ts.Debug.assert(start >= 0); ts.Debug.assert(start <= end); ts.Debug.assert(end <= content.length); var tags; var comments = []; var result; // Check for /** (JSDoc opening part) if (!isJsDocStart(content, start)) { return result; } // + 3 for leading /**, - 5 in total for /** */ scanner.scanRange(start + 3, length - 5, function () { // Initially we can parse out a tag. We also have seen a starting asterisk. // This is so that /** * @type */ doesn't parse. var advanceToken = true; var state = 1 /* SawAsterisk */; var margin = undefined; // + 4 for leading '/** ' var indent = start - Math.max(content.lastIndexOf("\x5cn", start), 0) + 4; function pushComment(text) { if (!margin) { margin = indent; } comments.push(text); indent += text.length; } nextJSDocToken(); while (token() === 5 /* WhitespaceTrivia */) { nextJSDocToken(); } if (token() === 4 /* NewLineTrivia */) { state = 0 /* BeginningOfLine */; indent = 0; nextJSDocToken(); } while (token() !== 1 /* EndOfFileToken */) { switch (token()) { case 56 /* AtToken */: if (state === 0 /* BeginningOfLine */ || state === 1 /* SawAsterisk */) { removeTrailingNewlines(comments); parseTag(indent); // NOTE: According to usejsdoc.org, a tag goes to end of line, except the last tag. // Real-world comments may break this rule, so "BeginningOfLine" will not be a real line beginning // for malformed examples like `/** @param {string} x @returns {number} the length */` state = 0 /* BeginningOfLine */; advanceToken = false; margin = undefined; indent++; } else { pushComment(scanner.getTokenText()); } break; case 4 /* NewLineTrivia */: comments.push(scanner.getTokenText()); state = 0 /* BeginningOfLine */; indent = 0; break; case 38 /* AsteriskToken */: var asterisk = scanner.getTokenText(); if (state === 1 /* SawAsterisk */ || state === 2 /* SavingComments */) { // If we've already seen an asterisk, then we can no longer parse a tag on this line state = 2 /* SavingComments */; pushComment(asterisk); } else { // Ignore the first asterisk on a line state = 1 /* SawAsterisk */; indent += asterisk.length; } break; case 70 /* Identifier */: // Anything else is doc comment text. We just save it. Because it // wasn't a tag, we can no longer parse a tag on this line until we hit the next // line break. pushComment(scanner.getTokenText()); state = 2 /* SavingComments */; break; case 5 /* WhitespaceTrivia */: // only collect whitespace if we're already saving comments or have just crossed the comment indent margin var whitespace = scanner.getTokenText(); if (state === 2 /* SavingComments */) { comments.push(whitespace); } else if (margin !== undefined && indent + whitespace.length > margin) { comments.push(whitespace.slice(margin - indent - 1)); } indent += whitespace.length; break; case 1 /* EndOfFileToken */: break; default: // anything other than whitespace or asterisk at the beginning of the line starts the comment text state = 2 /* SavingComments */; pushComment(scanner.getTokenText()); break; } if (advanceToken) { nextJSDocToken(); } else { advanceToken = true; } } removeLeadingNewlines(comments); removeTrailingNewlines(comments); result = createJSDocComment(); }); return result; function removeLeadingNewlines(comments) { while (comments.length && (comments[0] === "\x5cn" || comments[0] === "\x5cr")) { comments.shift(); } } function removeTrailingNewlines(comments) { while (comments.length && (comments[comments.length - 1] === "\x5cn" || comments[comments.length - 1] === "\x5cr")) { comments.pop(); } } function isJsDocStart(content, start) { return content.charCodeAt(start) === 47 /* slash */ && content.charCodeAt(start + 1) === 42 /* asterisk */ && content.charCodeAt(start + 2) === 42 /* asterisk */ && content.charCodeAt(start + 3) !== 42 /* asterisk */; } function createJSDocComment() { var result = createNode(278 /* JSDocComment */, start); result.tags = tags; result.comment = comments.length ? comments.join("") : undefined; return finishNode(result, end); } function skipWhitespace() { while (token() === 5 /* WhitespaceTrivia */ || token() === 4 /* NewLineTrivia */) { nextJSDocToken(); } } function parseTag(indent) { ts.Debug.assert(token() === 56 /* AtToken */); var atToken = createNode(56 /* AtToken */, scanner.getTokenPos()); atToken.end = scanner.getTextPos(); nextJSDocToken(); var tagName = parseJSDocIdentifierName(); skipWhitespace(); if (!tagName) { return; } var tag; if (tagName) { switch (tagName.text) { case "augments": tag = parseAugmentsTag(atToken, tagName); break; case "param": tag = parseParamTag(atToken, tagName); break; case "return": case "returns": tag = parseReturnTag(atToken, tagName); break; case "template": tag = parseTemplateTag(atToken, tagName); break; case "type": tag = parseTypeTag(atToken, tagName); break; case "typedef": tag = parseTypedefTag(atToken, tagName); break; default: tag = parseUnknownTag(atToken, tagName); break; } } else { tag = parseUnknownTag(atToken, tagName); } if (!tag) { // a badly malformed tag should not be added to the list of tags return; } addTag(tag, parseTagComments(indent + tag.end - tag.pos)); } function parseTagComments(indent) { var comments = []; var state = 0 /* BeginningOfLine */; var margin; function pushComment(text) { if (!margin) { margin = indent; } comments.push(text); indent += text.length; } while (token() !== 56 /* AtToken */ && token() !== 1 /* EndOfFileToken */) { switch (token()) { case 4 /* NewLineTrivia */: if (state >= 1 /* SawAsterisk */) { state = 0 /* BeginningOfLine */; comments.push(scanner.getTokenText()); } indent = 0; break; case 56 /* AtToken */: // Done break; case 5 /* WhitespaceTrivia */: if (state === 2 /* SavingComments */) { pushComment(scanner.getTokenText()); } else { var whitespace = scanner.getTokenText(); // if the whitespace crosses the margin, take only the whitespace that passes the margin if (margin !== undefined && indent + whitespace.length > margin) { comments.push(whitespace.slice(margin - indent - 1)); } indent += whitespace.length; } break; case 38 /* AsteriskToken */: if (state === 0 /* BeginningOfLine */) { // leading asterisks start recording on the *next* (non-whitespace) token state = 1 /* SawAsterisk */; indent += scanner.getTokenText().length; break; } // FALLTHROUGH otherwise to record the * as a comment default: state = 2 /* SavingComments */; // leading identifiers start recording as well pushComment(scanner.getTokenText()); break; } if (token() === 56 /* AtToken */) { // Done break; } nextJSDocToken(); } removeLeadingNewlines(comments); removeTrailingNewlines(comments); return comments; } function parseUnknownTag(atToken, tagName) { var result = createNode(279 /* JSDocTag */, atToken.pos); result.atToken = atToken; result.tagName = tagName; return finishNode(result); } function addTag(tag, comments) { tag.comment = comments.join(""); if (!tags) { tags = createNodeArray([tag], tag.pos); } else { tags.push(tag); } tags.end = tag.end; } function tryParseTypeExpression() { return tryParse(function () { skipWhitespace(); if (token() !== 16 /* OpenBraceToken */) { return undefined; } return parseJSDocTypeExpression(); }); } function parseParamTag(atToken, tagName) { var typeExpression = tryParseTypeExpression(); skipWhitespace(); var name; var isBracketed; // Looking for something like '[foo]' or 'foo' if (parseOptionalToken(20 /* OpenBracketToken */)) { name = parseJSDocIdentifierName(); skipWhitespace(); isBracketed = true; // May have an optional default, e.g. '[foo = 42]' if (parseOptionalToken(57 /* EqualsToken */)) { parseExpression(); } parseExpected(21 /* CloseBracketToken */); } else if (ts.tokenIsIdentifierOrKeyword(token())) { name = parseJSDocIdentifierName(); } if (!name) { parseErrorAtPosition(scanner.getStartPos(), 0, ts.Diagnostics.Identifier_expected); return undefined; } var preName, postName; if (typeExpression) { postName = name; } else { preName = name; } if (!typeExpression) { typeExpression = tryParseTypeExpression(); } var result = createNode(281 /* JSDocParameterTag */, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.preParameterName = preName; result.typeExpression = typeExpression; result.postParameterName = postName; result.parameterName = postName || preName; result.isBracketed = isBracketed; return finishNode(result); } function parseReturnTag(atToken, tagName) { if (ts.forEach(tags, function (t) { return t.kind === 282 /* JSDocReturnTag */; })) { parseErrorAtPosition(tagName.pos, scanner.getTokenPos() - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); } var result = createNode(282 /* JSDocReturnTag */, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.typeExpression = tryParseTypeExpression(); return finishNode(result); } function parseTypeTag(atToken, tagName) { if (ts.forEach(tags, function (t) { return t.kind === 283 /* JSDocTypeTag */; })) { parseErrorAtPosition(tagName.pos, scanner.getTokenPos() - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); } var result = createNode(283 /* JSDocTypeTag */, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.typeExpression = tryParseTypeExpression(); return finishNode(result); } function parsePropertyTag(atToken, tagName) { var typeExpression = tryParseTypeExpression(); skipWhitespace(); var name = parseJSDocIdentifierName(); skipWhitespace(); if (!name) { parseErrorAtPosition(scanner.getStartPos(), /*length*/ 0, ts.Diagnostics.Identifier_expected); return undefined; } var result = createNode(286 /* JSDocPropertyTag */, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.name = name; result.typeExpression = typeExpression; return finishNode(result); } function parseAugmentsTag(atToken, tagName) { var typeExpression = tryParseTypeExpression(); var result = createNode(280 /* JSDocAugmentsTag */, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.typeExpression = typeExpression; return finishNode(result); } function parseTypedefTag(atToken, tagName) { var typeExpression = tryParseTypeExpression(); skipWhitespace(); var typedefTag = createNode(285 /* JSDocTypedefTag */, atToken.pos); typedefTag.atToken = atToken; typedefTag.tagName = tagName; typedefTag.fullName = parseJSDocTypeNameWithNamespace(/*flags*/ 0); if (typedefTag.fullName) { var rightNode = typedefTag.fullName; while (rightNode.kind !== 70 /* Identifier */) { rightNode = rightNode.body; } typedefTag.name = rightNode; } typedefTag.typeExpression = typeExpression; skipWhitespace(); if (typeExpression) { if (typeExpression.type.kind === 272 /* JSDocTypeReference */) { var jsDocTypeReference = typeExpression.type; if (jsDocTypeReference.name.kind === 70 /* Identifier */) { var name_14 = jsDocTypeReference.name; if (name_14.text === "Object") { typedefTag.jsDocTypeLiteral = scanChildTags(); } } } if (!typedefTag.jsDocTypeLiteral) { typedefTag.jsDocTypeLiteral = typeExpression.type; } } else { typedefTag.jsDocTypeLiteral = scanChildTags(); } return finishNode(typedefTag); function scanChildTags() { var jsDocTypeLiteral = createNode(287 /* JSDocTypeLiteral */, scanner.getStartPos()); var resumePos = scanner.getStartPos(); var canParseTag = true; var seenAsterisk = false; var parentTagTerminated = false; while (token() !== 1 /* EndOfFileToken */ && !parentTagTerminated) { nextJSDocToken(); switch (token()) { case 56 /* AtToken */: if (canParseTag) { parentTagTerminated = !tryParseChildTag(jsDocTypeLiteral); if (!parentTagTerminated) { resumePos = scanner.getStartPos(); } } seenAsterisk = false; break; case 4 /* NewLineTrivia */: resumePos = scanner.getStartPos() - 1; canParseTag = true; seenAsterisk = false; break; case 38 /* AsteriskToken */: if (seenAsterisk) { canParseTag = false; } seenAsterisk = true; break; case 70 /* Identifier */: canParseTag = false; case 1 /* EndOfFileToken */: break; } } scanner.setTextPos(resumePos); return finishNode(jsDocTypeLiteral); } function parseJSDocTypeNameWithNamespace(flags) { var pos = scanner.getTokenPos(); var typeNameOrNamespaceName = parseJSDocIdentifierName(); if (typeNameOrNamespaceName && parseOptional(22 /* DotToken */)) { var jsDocNamespaceNode = createNode(230 /* ModuleDeclaration */, pos); jsDocNamespaceNode.flags |= flags; jsDocNamespaceNode.name = typeNameOrNamespaceName; jsDocNamespaceNode.body = parseJSDocTypeNameWithNamespace(4 /* NestedNamespace */); return jsDocNamespaceNode; } if (typeNameOrNamespaceName && flags & 4 /* NestedNamespace */) { typeNameOrNamespaceName.isInJSDocNamespace = true; } return typeNameOrNamespaceName; } } function tryParseChildTag(parentTag) { ts.Debug.assert(token() === 56 /* AtToken */); var atToken = createNode(56 /* AtToken */, scanner.getStartPos()); atToken.end = scanner.getTextPos(); nextJSDocToken(); var tagName = parseJSDocIdentifierName(); skipWhitespace(); if (!tagName) { return false; } switch (tagName.text) { case "type": if (parentTag.jsDocTypeTag) { // already has a @type tag, terminate the parent tag now. return false; } parentTag.jsDocTypeTag = parseTypeTag(atToken, tagName); return true; case "prop": case "property": var propertyTag = parsePropertyTag(atToken, tagName); if (propertyTag) { if (!parentTag.jsDocPropertyTags) { parentTag.jsDocPropertyTags = []; } parentTag.jsDocPropertyTags.push(propertyTag); return true; } // Error parsing property tag return false; } return false; } function parseTemplateTag(atToken, tagName) { if (ts.forEach(tags, function (t) { return t.kind === 284 /* JSDocTemplateTag */; })) { parseErrorAtPosition(tagName.pos, scanner.getTokenPos() - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); } // Type parameter list looks like '@template T,U,V' var typeParameters = createNodeArray(); while (true) { var name_15 = parseJSDocIdentifierName(); skipWhitespace(); if (!name_15) { parseErrorAtPosition(scanner.getStartPos(), 0, ts.Diagnostics.Identifier_expected); return undefined; } var typeParameter = createNode(143 /* TypeParameter */, name_15.pos); typeParameter.name = name_15; finishNode(typeParameter); typeParameters.push(typeParameter); if (token() === 25 /* CommaToken */) { nextJSDocToken(); skipWhitespace(); } else { break; } } var result = createNode(284 /* JSDocTemplateTag */, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.typeParameters = typeParameters; finishNode(result); typeParameters.end = result.end; return result; } function nextJSDocToken() { return currentToken = scanner.scanJSDocToken(); } function parseJSDocIdentifierName() { return createJSDocIdentifier(ts.tokenIsIdentifierOrKeyword(token())); } function createJSDocIdentifier(isIdentifier) { if (!isIdentifier) { parseErrorAtCurrentToken(ts.Diagnostics.Identifier_expected); return undefined; } var pos = scanner.getTokenPos(); var end = scanner.getTextPos(); var result = createNode(70 /* Identifier */, pos); result.text = content.substring(pos, end); finishNode(result, end); nextJSDocToken(); return result; } }
removeTrailingNewlines:
(comments) { while (comments.length && (comments[comments.length - 1] === "\x5cn" || comments[comments.length - 1] === "\x5cr")) { comments.pop(); } }
parseTag:
(indent) { ts.Debug.assert(token() === 56 /* AtToken */); var atToken = createNode(56 /* AtToken */, scanner.getTokenPos()); atToken.end = scanner.getTextPos(); nextJSDocToken(); var tagName = parseJSDocIdentifierName(); skipWhitespace(); if (!tagName) { return; } var tag; if (tagName) { switch (tagName.text) { case "augments": tag = parseAugmentsTag(atToken, tagName); break; case "param": tag = parseParamTag(atToken, tagName); break; case "return": case "returns": tag = parseReturnTag(atToken, tagName); break; case "template": tag = parseTemplateTag(atToken, tagName); break; case "type": tag = parseTypeTag(atToken, tagName); break; case "typedef": tag = parseTypedefTag(atToken, tagName); break; default: tag = parseUnknownTag(atToken, tagName); break; } } else { tag = parseUnknownTag(atToken, tagName); } if (!tag) { // a badly malformed tag should not be added to the list of tags return; } addTag(tag, parseTagComments(indent + tag.end - tag.pos)); }
addTag:
(tag, comments) { tag.comment = comments.join(""); if (!tags) { tags = createNodeArray([tag], tag.pos); } else { tags.push(tag); } tags.end = tag.end; }
skipWhitespace:
() { while (token() === 5 /* WhitespaceTrivia */ || token() === 4 /* NewLineTrivia */) { nextJSDocToken(); } }
parseParamTag:
(atToken, tagName) { var typeExpression = tryParseTypeExpression(); skipWhitespace(); var name; var isBracketed; // Looking for something like '[foo]' or 'foo' if (parseOptionalToken(20 /* OpenBracketToken */)) { name = parseJSDocIdentifierName(); skipWhitespace(); isBracketed = true; // May have an optional default, e.g. '[foo = 42]' if (parseOptionalToken(57 /* EqualsToken */)) { parseExpression(); } parseExpected(21 /* CloseBracketToken */); } else if (ts.tokenIsIdentifierOrKeyword(token())) { name = parseJSDocIdentifierName(); } if (!name) { parseErrorAtPosition(scanner.getStartPos(), 0, ts.Diagnostics.Identifier_expected); return undefined; } var preName, postName; if (typeExpression) { postName = name; } else { preName = name; } if (!typeExpression) { typeExpression = tryParseTypeExpression(); } var result = createNode(281 /* JSDocParameterTag */, atToken.pos); result.atToken = atToken; result.tagName = tagName; result.preParameterName = preName; result.typeExpression = typeExpression; result.postParameterName = postName; result.parameterName = postName || preName; result.isBracketed = isBracketed; return finishNode(result); }
isStartOfType:
() { switch (token()) { case 118 /* AnyKeyword */: case 134 /* StringKeyword */: case 132 /* NumberKeyword */: case 121 /* BooleanKeyword */: case 135 /* SymbolKeyword */: case 104 /* VoidKeyword */: case 137 /* UndefinedKeyword */: case 94 /* NullKeyword */: case 98 /* ThisKeyword */: case 102 /* TypeOfKeyword */: case 129 /* NeverKeyword */: case 16 /* OpenBraceToken */: case 20 /* OpenBracketToken */: case 26 /* LessThanToken */: case 48 /* BarToken */: case 47 /* AmpersandToken */: case 93 /* NewKeyword */: case 9 /* StringLiteral */: case 8 /* NumericLiteral */: case 100 /* TrueKeyword */: case 85 /* FalseKeyword */: return true; case 37 /* MinusToken */: return lookAhead(nextTokenIsNumericLiteral); case 18 /* OpenParenToken */: // Only consider '(' the start of a type if followed by ')', '...', an identifier, a modifier, // or something that starts a type. We don't want to consider things like '(1)' a type. return lookAhead(isStartOfParenthesizedOrFunctionType); default: return isIdentifier(); } }
parseList:
(kind, parseElement) { var saveParsingContext = parsingContext; parsingContext |= 1 << kind; var result = createNodeArray(); while (!isListTerminator(kind)) { if (isListElement(kind, /*inErrorRecovery*/ false)) { var element = parseListElement(kind, parseElement); result.push(element); continue; } if (abortParsingListOrMoveToNextToken(kind)) { break; } } result.end = getNodeEnd(); parsingContext = saveParsingContext; return result; }
parseExpressionWithTypeArguments:
() { var node = createNode(199 /* ExpressionWithTypeArguments */); node.expression = parseLeftHandSideExpressionOrHigher(); if (token() === 26 /* LessThanToken */) { node.typeArguments = parseBracketedList(19 /* TypeArguments */, parseType, 26 /* LessThanToken */, 28 /* GreaterThanToken */); } return finishNode(node); }
parseHeritageClause:
() { if (token() === 84 /* ExtendsKeyword */ || token() === 107 /* ImplementsKeyword */) { var node = createNode(255 /* HeritageClause */); node.token = token(); nextToken(); node.types = parseDelimitedList(7 /* HeritageClauseElement */, parseExpressionWithTypeArguments); return finishNode(node); } return undefined; }
parseMemberExpressionRest:
(expression) { while (true) { var dotToken = parseOptionalToken(22 /* DotToken */); if (dotToken) { var propertyAccess = createNode(177 /* PropertyAccessExpression */, expression.pos); propertyAccess.expression = expression; propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true); expression = finishNode(propertyAccess); continue; } if (token() === 50 /* ExclamationToken */ && !scanner.hasPrecedingLineBreak()) { nextToken(); var nonNullExpression = createNode(201 /* NonNullExpression */, expression.pos); nonNullExpression.expression = expression; expression = finishNode(nonNullExpression); continue; } // when in the [Decorator] context, we do not parse ElementAccess as it could be part of a ComputedPropertyName if (!inDecoratorContext() && parseOptional(20 /* OpenBracketToken */)) { var indexedAccess = createNode(178 /* ElementAccessExpression */, expression.pos); indexedAccess.expression = expression; // It's not uncommon for a user to write: "new Type[]". // Check for that common pattern and report a better error message. if (token() !== 21 /* CloseBracketToken */) { indexedAccess.argumentExpression = allowInAnd(parseExpression); if (indexedAccess.argumentExpression.kind === 9 /* StringLiteral */ || indexedAccess.argumentExpression.kind === 8 /* NumericLiteral */) { var literal = indexedAccess.argumentExpression; literal.text = internIdentifier(literal.text); } } parseExpected(21 /* CloseBracketToken */); expression = finishNode(indexedAccess); continue; } if (token() === 12 /* NoSubstitutionTemplateLiteral */ || token() === 13 /* TemplateHead */) { var tagExpression = createNode(181 /* TaggedTemplateExpression */, expression.pos); tagExpression.tag = expression; tagExpression.template = token() === 12 /* NoSubstitutionTemplateLiteral */ ? parseLiteralNode() : parseTemplateExpression(); expression = finishNode(tagExpression); continue; } return expression; } }
isStartOfMappedType:
() { nextToken(); if (token() === 130 /* ReadonlyKeyword */) { nextToken(); } return token() === 20 /* OpenBracketToken */ && nextTokenIsIdentifier() && nextToken() === 91 /* InKeyword */; }
parseTypeLiteral:
() { var node = createNode(161 /* TypeLiteral */); node.members = parseObjectTypeMembers(); return finishNode(node); }
isStartOfConstructSignature:
() { nextToken(); return token() === 18 /* OpenParenToken */ || token() === 26 /* LessThanToken */; }
parseTypeParameter:
() { var node = createNode(143 /* TypeParameter */); node.name = parseIdentifier(); if (parseOptional(84 /* ExtendsKeyword */)) { // It's not uncommon for people to write improper constraints to a generic. If the // user writes a constraint that is an expression and not an actual type, then parse // it out as an expression (so we can recover well), but report that a type is needed // instead. if (isStartOfType() || !isStartOfExpression()) { node.constraint = parseType(); } else { // It was not a type, and it looked like an expression. Parse out an expression // here so we recover well. Note: it is important that we call parseUnaryExpression // and not parseExpression here. If the user has: // // <T extends ""> // // We do *not* want to consume the > as we're consuming the expression for "". node.expression = parseUnaryExpressionOrHigher(); } } return finishNode(node); }
parseTypeOperator:
(operator) { var node = createNode(168 /* TypeOperator */); parseExpected(operator); node.operator = operator; node.type = parseTypeOperatorOrHigher(); return finishNode(node); }
collectModuleReferences:
(node, inAmbientModule) { switch (node.kind) { case 235 /* ImportDeclaration */: case 234 /* ImportEqualsDeclaration */: case 241 /* ExportDeclaration */: var moduleNameExpr = ts.getExternalModuleName(node); if (!moduleNameExpr || moduleNameExpr.kind !== 9 /* StringLiteral */) { break; } if (!moduleNameExpr.text) { break; } // TypeScript 1.0 spec (April 2014): 12.1.6 // An ExternalImportDeclaration in an AmbientExternalModuleDeclaration may reference other external modules // only through top - level external module names. Relative external module names are not permitted. if (!inAmbientModule || !ts.isExternalModuleNameRelative(moduleNameExpr.text)) { (imports || (imports = [])).push(moduleNameExpr); } break; case 230 /* ModuleDeclaration */: if (ts.isAmbientModule(node) && (inAmbientModule || ts.hasModifier(node, 2 /* Ambient */) || ts.isDeclarationFile(file))) { var moduleName = node.name; // Ambient module declarations can be interpreted as augmentations for some existing external modules. // This will happen in two cases: // - if current file is external module then module augmentation is a ambient module declaration defined in the top level scope // - if current file is not external module then module augmentation is an ambient module declaration with non-relative module name // immediately nested in top level ambient module declaration . if (isExternalModuleFile || (inAmbientModule && !ts.isExternalModuleNameRelative(moduleName.text))) { (moduleAugmentations || (moduleAugmentations = [])).push(moduleName); } else if (!inAmbientModule) { if (isDtsFile) { // for global .d.ts files record name of ambient module (ambientModules || (ambientModules = [])).push(moduleName.text); } // An AmbientExternalModuleDeclaration declares an external module. // This type of declaration is permitted only in the global module. // The StringLiteral must specify a top - level external module name. // Relative external module names are not permitted // NOTE: body of ambient module is always a module block, if it exists var body = node.body; if (body) { for (var _i = 0, _a = body.statements; _i < _a.length; _i++) { var statement = _a[_i]; collectModuleReferences(statement, /*inAmbientModule*/ true); } } } } } }
Deopt: <JS Function modifierToFlag (SharedFunctionInfo 0x2c75c4ad5a81)> (opt #150) @1, FP to SP delta: 24, caller sp: 0x7fff5fbfd838
visitNodeArray:
(cbNodes, nodes) { if (nodes) { return cbNodes(nodes); } }
isAmbientModule:
(node) { return node && node.kind === 230 /* ModuleDeclaration */ && (node.name.kind === 9 /* StringLiteral */ || isGlobalScopeAugmentation(node)); }
(node) { return node && node.kind === 230 /* ModuleDeclaration */ && (node.name.kind === 9 /* StringLiteral */ || isGlobalScopeAugmentation(node)); }
(node) { return node && node.kind === 230 /* ModuleDeclaration */ && (node.name.kind === 9 /* StringLiteral */ || isGlobalScopeAugmentation(node)); }
(node) { return node && node.kind === 230 /* ModuleDeclaration */ && (node.name.kind === 9 /* StringLiteral */ || isGlobalScopeAugmentation(node)); }
isInJavaScriptFile:
(node) { return node && !!(node.flags & 65536 /* JavaScriptFile */); }
isExpression:
(node) { return isExpressionKind(ts.skipPartiallyEmittedExpressions(node).kind); }
(node) { return isExpressionKind(ts.skipPartiallyEmittedExpressions(node).kind); }
bind:
(node) { if (!node) { return; } node.parent = parent; var saveInStrictMode = inStrictMode; // First we bind declaration nodes to a symbol if possible. We'll both create a symbol // and then potentially add the symbol to an appropriate symbol table. Possible // destination symbol tables are: // // 1) The 'exports' table of the current container's symbol. // 2) The 'members' table of the current container's symbol. // 3) The 'locals' table of the current container. // // However, not all symbols will end up in any of these tables. 'Anonymous' symbols // (like TypeLiterals for example) will not be put in any table. bindWorker(node); // Then we recurse into the children of the node to bind them as well. For certain // symbols we do specialized work when we recurse. For example, we'll keep track of // the current 'container' node when it changes. This helps us know which symbol table // a local should go into for example. Since terminal nodes are known not to have // children, as an optimization we don't process those. if (node.kind > 140 /* LastToken */) { var saveParent = parent; parent = node; var containerFlags = getContainerFlags(node); if (containerFlags === 0 /* None */) { bindChildren(node); } else { bindContainer(node, containerFlags); } parent = saveParent; } else if (!skipTransformFlagAggregation && (node.transformFlags & 536870912 /* HasComputedFlags */) === 0) { subtreeTransformFlags |= computeTransformFlagsForNode(node, 0); } inStrictMode = saveInStrictMode; }
SymbolObject:
(flags, name) { this.flags = flags; this.name = name; }
createSymbol:
(flags, name) { symbolCount++; return new Symbol(flags, name); }
(flags, name) { symbolCount++; return new Symbol(flags, name); }
declareSymbolAndAddToSymbolTable:
(node, symbolFlags, symbolExcludes) { // Just call this directly so that the return type of this function stays "void". return declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes); }
bindEachChild:
(node) { ts.forEachChild(node, bind, bindEach); }
bindWorker:
(node) { switch (node.kind) { /* Strict mode checks */ case 70 /* Identifier */: // for typedef type names with namespaces, bind the new jsdoc type symbol here // because it requires all containing namespaces to be in effect, namely the // current "blockScopeContainer" needs to be set to its immediate namespace parent. if (node.isInJSDocNamespace) { var parentNode = node.parent; while (parentNode && parentNode.kind !== 285 /* JSDocTypedefTag */) { parentNode = parentNode.parent; } bindBlockScopedDeclaration(parentNode, 524288 /* TypeAlias */, 793064 /* TypeAliasExcludes */); break; } case 98 /* ThisKeyword */: if (currentFlow && (ts.isExpression(node) || parent.kind === 258 /* ShorthandPropertyAssignment */)) { node.flowNode = currentFlow; } return checkStrictModeIdentifier(node); case 177 /* PropertyAccessExpression */: if (currentFlow && isNarrowableReference(node)) { node.flowNode = currentFlow; } break; case 192 /* BinaryExpression */: if (ts.isInJavaScriptFile(node)) { var specialKind = ts.getSpecialPropertyAssignmentKind(node); switch (specialKind) { case 1 /* ExportsProperty */: bindExportsPropertyAssignment(node); break; case 2 /* ModuleExports */: bindModuleExportsAssignment(node); break; case 3 /* PrototypeProperty */: bindPrototypePropertyAssignment(node); break; case 4 /* ThisProperty */: bindThisPropertyAssignment(node); break; case 0 /* None */: // Nothing to do break; default: ts.Debug.fail("Unknown special property assignment kind"); } } return checkStrictModeBinaryExpression(node); case 256 /* CatchClause */: return checkStrictModeCatchClause(node); case 186 /* DeleteExpression */: return checkStrictModeDeleteExpression(node); case 8 /* NumericLiteral */: return checkStrictModeNumericLiteral(node); case 191 /* PostfixUnaryExpression */: return checkStrictModePostfixUnaryExpression(node); case 190 /* PrefixUnaryExpression */: return checkStrictModePrefixUnaryExpression(node); case 217 /* WithStatement */: return checkStrictModeWithStatement(node); case 167 /* ThisType */: seenThisKeyword = true; return; case 156 /* TypePredicate */: return checkTypePredicate(node); case 143 /* TypeParameter */: return declareSymbolAndAddToSymbolTable(node, 262144 /* TypeParameter */, 530920 /* TypeParameterExcludes */); case 144 /* Parameter */: return bindParameter(node); case 223 /* VariableDeclaration */: case 174 /* BindingElement */: return bindVariableDeclarationOrBindingElement(node); case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: case 271 /* JSDocRecordMember */: return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 0 /* PropertyExcludes */); case 286 /* JSDocPropertyTag */: return bindJSDocProperty(node); case 257 /* PropertyAssignment */: case 258 /* ShorthandPropertyAssignment */: return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 0 /* PropertyExcludes */); case 260 /* EnumMember */: return bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 900095 /* EnumMemberExcludes */); case 259 /* SpreadAssignment */: case 251 /* JsxSpreadAttribute */: var root = container; var hasRest = false; while (root.parent) { if (root.kind === 176 /* ObjectLiteralExpression */ && root.parent.kind === 192 /* BinaryExpression */ && root.parent.operatorToken.kind === 57 /* EqualsToken */ && root.parent.left === root) { hasRest = true; break; } root = root.parent; } return; case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: return declareSymbolAndAddToSymbolTable(node, 131072 /* Signature */, 0 /* None */); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: // If this is an ObjectLiteralExpression method, then it sits in the same space // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same // name. return bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), ts.isObjectLiteralMethod(node) ? 0 /* PropertyExcludes */ : 99263 /* MethodExcludes */); case 225 /* FunctionDeclaration */: return bindFunctionDeclaration(node); case 150 /* Constructor */: return declareSymbolAndAddToSymbolTable(node, 16384 /* Constructor */, /*symbolExcludes:*/ 0 /* None */); case 151 /* GetAccessor */: return bindPropertyOrMethodOrAccessor(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */); case 152 /* SetAccessor */: return bindPropertyOrMethodOrAccessor(node, 65536 /* SetAccessor */, 74687 /* SetAccessorExcludes */); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 274 /* JSDocFunctionType */: return bindFunctionOrConstructorType(node); case 161 /* TypeLiteral */: case 170 /* MappedType */: case 287 /* JSDocTypeLiteral */: case 270 /* JSDocRecordType */: return bindAnonymousDeclaration(node, 2048 /* TypeLiteral */, "__type"); case 176 /* ObjectLiteralExpression */: return bindObjectLiteralExpression(node); case 184 /* FunctionExpression */: case 185 /* ArrowFunction */: return bindFunctionExpression(node); case 179 /* CallExpression */: if (ts.isInJavaScriptFile(node)) { bindCallExpression(node); } break; // Members of classes, interfaces, and modules case 197 /* ClassExpression */: case 226 /* ClassDeclaration */: // All classes are automatically in strict mode in ES6. inStrictMode = true; return bindClassLikeDeclaration(node); case 227 /* InterfaceDeclaration */: return bindBlockScopedDeclaration(node, 64 /* Interface */, 792968 /* InterfaceExcludes */); case 285 /* JSDocTypedefTag */: if (!node.fullName || node.fullName.kind === 70 /* Identifier */) { return bindBlockScopedDeclaration(node, 524288 /* TypeAlias */, 793064 /* TypeAliasExcludes */); } break; case 228 /* TypeAliasDeclaration */: return bindBlockScopedDeclaration(node, 524288 /* TypeAlias */, 793064 /* TypeAliasExcludes */); case 229 /* EnumDeclaration */: return bindEnumDeclaration(node); case 230 /* ModuleDeclaration */: return bindModuleDeclaration(node); // Imports and exports case 234 /* ImportEqualsDeclaration */: case 237 /* NamespaceImport */: case 239 /* ImportSpecifier */: case 243 /* ExportSpecifier */: return declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */); case 233 /* NamespaceExportDeclaration */: return bindNamespaceExportDeclaration(node); case 236 /* ImportClause */: return bindImportClause(node); case 241 /* ExportDeclaration */: return bindExportDeclaration(node); case 240 /* ExportAssignment */: return bindExportAssignment(node); case 261 /* SourceFile */: updateStrictModeStatementList(node.statements); return bindSourceFileIfExternalModule(); case 204 /* Block */: if (!ts.isFunctionLike(node.parent)) { return; } // Fall through case 231 /* ModuleBlock */: return updateStrictModeStatementList(node.statements); } }
(node) { switch (node.kind) { /* Strict mode checks */ case 70 /* Identifier */: // for typedef type names with namespaces, bind the new jsdoc type symbol here // because it requires all containing namespaces to be in effect, namely the // current "blockScopeContainer" needs to be set to its immediate namespace parent. if (node.isInJSDocNamespace) { var parentNode = node.parent; while (parentNode && parentNode.kind !== 285 /* JSDocTypedefTag */) { parentNode = parentNode.parent; } bindBlockScopedDeclaration(parentNode, 524288 /* TypeAlias */, 793064 /* TypeAliasExcludes */); break; } case 98 /* ThisKeyword */: if (currentFlow && (ts.isExpression(node) || parent.kind === 258 /* ShorthandPropertyAssignment */)) { node.flowNode = currentFlow; } return checkStrictModeIdentifier(node); case 177 /* PropertyAccessExpression */: if (currentFlow && isNarrowableReference(node)) { node.flowNode = currentFlow; } break; case 192 /* BinaryExpression */: if (ts.isInJavaScriptFile(node)) { var specialKind = ts.getSpecialPropertyAssignmentKind(node); switch (specialKind) { case 1 /* ExportsProperty */: bindExportsPropertyAssignment(node); break; case 2 /* ModuleExports */: bindModuleExportsAssignment(node); break; case 3 /* PrototypeProperty */: bindPrototypePropertyAssignment(node); break; case 4 /* ThisProperty */: bindThisPropertyAssignment(node); break; case 0 /* None */: // Nothing to do break; default: ts.Debug.fail("Unknown special property assignment kind"); } } return checkStrictModeBinaryExpression(node); case 256 /* CatchClause */: return checkStrictModeCatchClause(node); case 186 /* DeleteExpression */: return checkStrictModeDeleteExpression(node); case 8 /* NumericLiteral */: return checkStrictModeNumericLiteral(node); case 191 /* PostfixUnaryExpression */: return checkStrictModePostfixUnaryExpression(node); case 190 /* PrefixUnaryExpression */: return checkStrictModePrefixUnaryExpression(node); case 217 /* WithStatement */: return checkStrictModeWithStatement(node); case 167 /* ThisType */: seenThisKeyword = true; return; case 156 /* TypePredicate */: return checkTypePredicate(node); case 143 /* TypeParameter */: return declareSymbolAndAddToSymbolTable(node, 262144 /* TypeParameter */, 530920 /* TypeParameterExcludes */); case 144 /* Parameter */: return bindParameter(node); case 223 /* VariableDeclaration */: case 174 /* BindingElement */: return bindVariableDeclarationOrBindingElement(node); case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: case 271 /* JSDocRecordMember */: return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 0 /* PropertyExcludes */); case 286 /* JSDocPropertyTag */: return bindJSDocProperty(node); case 257 /* PropertyAssignment */: case 258 /* ShorthandPropertyAssignment */: return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 0 /* PropertyExcludes */); case 260 /* EnumMember */: return bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 900095 /* EnumMemberExcludes */); case 259 /* SpreadAssignment */: case 251 /* JsxSpreadAttribute */: var root = container; var hasRest = false; while (root.parent) { if (root.kind === 176 /* ObjectLiteralExpression */ && root.parent.kind === 192 /* BinaryExpression */ && root.parent.operatorToken.kind === 57 /* EqualsToken */ && root.parent.left === root) { hasRest = true; break; } root = root.parent; } return; case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: return declareSymbolAndAddToSymbolTable(node, 131072 /* Signature */, 0 /* None */); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: // If this is an ObjectLiteralExpression method, then it sits in the same space // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same // name. return bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), ts.isObjectLiteralMethod(node) ? 0 /* PropertyExcludes */ : 99263 /* MethodExcludes */); case 225 /* FunctionDeclaration */: return bindFunctionDeclaration(node); case 150 /* Constructor */: return declareSymbolAndAddToSymbolTable(node, 16384 /* Constructor */, /*symbolExcludes:*/ 0 /* None */); case 151 /* GetAccessor */: return bindPropertyOrMethodOrAccessor(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */); case 152 /* SetAccessor */: return bindPropertyOrMethodOrAccessor(node, 65536 /* SetAccessor */, 74687 /* SetAccessorExcludes */); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 274 /* JSDocFunctionType */: return bindFunctionOrConstructorType(node); case 161 /* TypeLiteral */: case 170 /* MappedType */: case 287 /* JSDocTypeLiteral */: case 270 /* JSDocRecordType */: return bindAnonymousDeclaration(node, 2048 /* TypeLiteral */, "__type"); case 176 /* ObjectLiteralExpression */: return bindObjectLiteralExpression(node); case 184 /* FunctionExpression */: case 185 /* ArrowFunction */: return bindFunctionExpression(node); case 179 /* CallExpression */: if (ts.isInJavaScriptFile(node)) { bindCallExpression(node); } break; // Members of classes, interfaces, and modules case 197 /* ClassExpression */: case 226 /* ClassDeclaration */: // All classes are automatically in strict mode in ES6. inStrictMode = true; return bindClassLikeDeclaration(node); case 227 /* InterfaceDeclaration */: return bindBlockScopedDeclaration(node, 64 /* Interface */, 792968 /* InterfaceExcludes */); case 285 /* JSDocTypedefTag */: if (!node.fullName || node.fullName.kind === 70 /* Identifier */) { return bindBlockScopedDeclaration(node, 524288 /* TypeAlias */, 793064 /* TypeAliasExcludes */); } break; case 228 /* TypeAliasDeclaration */: return bindBlockScopedDeclaration(node, 524288 /* TypeAlias */, 793064 /* TypeAliasExcludes */); case 229 /* EnumDeclaration */: return bindEnumDeclaration(node); case 230 /* ModuleDeclaration */: return bindModuleDeclaration(node); // Imports and exports case 234 /* ImportEqualsDeclaration */: case 237 /* NamespaceImport */: case 239 /* ImportSpecifier */: case 243 /* ExportSpecifier */: return declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */); case 233 /* NamespaceExportDeclaration */: return bindNamespaceExportDeclaration(node); case 236 /* ImportClause */: return bindImportClause(node); case 241 /* ExportDeclaration */: return bindExportDeclaration(node); case 240 /* ExportAssignment */: return bindExportAssignment(node); case 261 /* SourceFile */: updateStrictModeStatementList(node.statements); return bindSourceFileIfExternalModule(); case 204 /* Block */: if (!ts.isFunctionLike(node.parent)) { return; } // Fall through case 231 /* ModuleBlock */: return updateStrictModeStatementList(node.statements); } }
(node) { switch (node.kind) { /* Strict mode checks */ case 70 /* Identifier */: // for typedef type names with namespaces, bind the new jsdoc type symbol here // because it requires all containing namespaces to be in effect, namely the // current "blockScopeContainer" needs to be set to its immediate namespace parent. if (node.isInJSDocNamespace) { var parentNode = node.parent; while (parentNode && parentNode.kind !== 285 /* JSDocTypedefTag */) { parentNode = parentNode.parent; } bindBlockScopedDeclaration(parentNode, 524288 /* TypeAlias */, 793064 /* TypeAliasExcludes */); break; } case 98 /* ThisKeyword */: if (currentFlow && (ts.isExpression(node) || parent.kind === 258 /* ShorthandPropertyAssignment */)) { node.flowNode = currentFlow; } return checkStrictModeIdentifier(node); case 177 /* PropertyAccessExpression */: if (currentFlow && isNarrowableReference(node)) { node.flowNode = currentFlow; } break; case 192 /* BinaryExpression */: if (ts.isInJavaScriptFile(node)) { var specialKind = ts.getSpecialPropertyAssignmentKind(node); switch (specialKind) { case 1 /* ExportsProperty */: bindExportsPropertyAssignment(node); break; case 2 /* ModuleExports */: bindModuleExportsAssignment(node); break; case 3 /* PrototypeProperty */: bindPrototypePropertyAssignment(node); break; case 4 /* ThisProperty */: bindThisPropertyAssignment(node); break; case 0 /* None */: // Nothing to do break; default: ts.Debug.fail("Unknown special property assignment kind"); } } return checkStrictModeBinaryExpression(node); case 256 /* CatchClause */: return checkStrictModeCatchClause(node); case 186 /* DeleteExpression */: return checkStrictModeDeleteExpression(node); case 8 /* NumericLiteral */: return checkStrictModeNumericLiteral(node); case 191 /* PostfixUnaryExpression */: return checkStrictModePostfixUnaryExpression(node); case 190 /* PrefixUnaryExpression */: return checkStrictModePrefixUnaryExpression(node); case 217 /* WithStatement */: return checkStrictModeWithStatement(node); case 167 /* ThisType */: seenThisKeyword = true; return; case 156 /* TypePredicate */: return checkTypePredicate(node); case 143 /* TypeParameter */: return declareSymbolAndAddToSymbolTable(node, 262144 /* TypeParameter */, 530920 /* TypeParameterExcludes */); case 144 /* Parameter */: return bindParameter(node); case 223 /* VariableDeclaration */: case 174 /* BindingElement */: return bindVariableDeclarationOrBindingElement(node); case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: case 271 /* JSDocRecordMember */: return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 0 /* PropertyExcludes */); case 286 /* JSDocPropertyTag */: return bindJSDocProperty(node); case 257 /* PropertyAssignment */: case 258 /* ShorthandPropertyAssignment */: return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 0 /* PropertyExcludes */); case 260 /* EnumMember */: return bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 900095 /* EnumMemberExcludes */); case 259 /* SpreadAssignment */: case 251 /* JsxSpreadAttribute */: var root = container; var hasRest = false; while (root.parent) { if (root.kind === 176 /* ObjectLiteralExpression */ && root.parent.kind === 192 /* BinaryExpression */ && root.parent.operatorToken.kind === 57 /* EqualsToken */ && root.parent.left === root) { hasRest = true; break; } root = root.parent; } return; case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: return declareSymbolAndAddToSymbolTable(node, 131072 /* Signature */, 0 /* None */); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: // If this is an ObjectLiteralExpression method, then it sits in the same space // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same // name. return bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), ts.isObjectLiteralMethod(node) ? 0 /* PropertyExcludes */ : 99263 /* MethodExcludes */); case 225 /* FunctionDeclaration */: return bindFunctionDeclaration(node); case 150 /* Constructor */: return declareSymbolAndAddToSymbolTable(node, 16384 /* Constructor */, /*symbolExcludes:*/ 0 /* None */); case 151 /* GetAccessor */: return bindPropertyOrMethodOrAccessor(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */); case 152 /* SetAccessor */: return bindPropertyOrMethodOrAccessor(node, 65536 /* SetAccessor */, 74687 /* SetAccessorExcludes */); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 274 /* JSDocFunctionType */: return bindFunctionOrConstructorType(node); case 161 /* TypeLiteral */: case 170 /* MappedType */: case 287 /* JSDocTypeLiteral */: case 270 /* JSDocRecordType */: return bindAnonymousDeclaration(node, 2048 /* TypeLiteral */, "__type"); case 176 /* ObjectLiteralExpression */: return bindObjectLiteralExpression(node); case 184 /* FunctionExpression */: case 185 /* ArrowFunction */: return bindFunctionExpression(node); case 179 /* CallExpression */: if (ts.isInJavaScriptFile(node)) { bindCallExpression(node); } break; // Members of classes, interfaces, and modules case 197 /* ClassExpression */: case 226 /* ClassDeclaration */: // All classes are automatically in strict mode in ES6. inStrictMode = true; return bindClassLikeDeclaration(node); case 227 /* InterfaceDeclaration */: return bindBlockScopedDeclaration(node, 64 /* Interface */, 792968 /* InterfaceExcludes */); case 285 /* JSDocTypedefTag */: if (!node.fullName || node.fullName.kind === 70 /* Identifier */) { return bindBlockScopedDeclaration(node, 524288 /* TypeAlias */, 793064 /* TypeAliasExcludes */); } break; case 228 /* TypeAliasDeclaration */: return bindBlockScopedDeclaration(node, 524288 /* TypeAlias */, 793064 /* TypeAliasExcludes */); case 229 /* EnumDeclaration */: return bindEnumDeclaration(node); case 230 /* ModuleDeclaration */: return bindModuleDeclaration(node); // Imports and exports case 234 /* ImportEqualsDeclaration */: case 237 /* NamespaceImport */: case 239 /* ImportSpecifier */: case 243 /* ExportSpecifier */: return declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */); case 233 /* NamespaceExportDeclaration */: return bindNamespaceExportDeclaration(node); case 236 /* ImportClause */: return bindImportClause(node); case 241 /* ExportDeclaration */: return bindExportDeclaration(node); case 240 /* ExportAssignment */: return bindExportAssignment(node); case 261 /* SourceFile */: updateStrictModeStatementList(node.statements); return bindSourceFileIfExternalModule(); case 204 /* Block */: if (!ts.isFunctionLike(node.parent)) { return; } // Fall through case 231 /* ModuleBlock */: return updateStrictModeStatementList(node.statements); } }
(node) { switch (node.kind) { /* Strict mode checks */ case 70 /* Identifier */: // for typedef type names with namespaces, bind the new jsdoc type symbol here // because it requires all containing namespaces to be in effect, namely the // current "blockScopeContainer" needs to be set to its immediate namespace parent. if (node.isInJSDocNamespace) { var parentNode = node.parent; while (parentNode && parentNode.kind !== 285 /* JSDocTypedefTag */) { parentNode = parentNode.parent; } bindBlockScopedDeclaration(parentNode, 524288 /* TypeAlias */, 793064 /* TypeAliasExcludes */); break; } case 98 /* ThisKeyword */: if (currentFlow && (ts.isExpression(node) || parent.kind === 258 /* ShorthandPropertyAssignment */)) { node.flowNode = currentFlow; } return checkStrictModeIdentifier(node); case 177 /* PropertyAccessExpression */: if (currentFlow && isNarrowableReference(node)) { node.flowNode = currentFlow; } break; case 192 /* BinaryExpression */: if (ts.isInJavaScriptFile(node)) { var specialKind = ts.getSpecialPropertyAssignmentKind(node); switch (specialKind) { case 1 /* ExportsProperty */: bindExportsPropertyAssignment(node); break; case 2 /* ModuleExports */: bindModuleExportsAssignment(node); break; case 3 /* PrototypeProperty */: bindPrototypePropertyAssignment(node); break; case 4 /* ThisProperty */: bindThisPropertyAssignment(node); break; case 0 /* None */: // Nothing to do break; default: ts.Debug.fail("Unknown special property assignment kind"); } } return checkStrictModeBinaryExpression(node); case 256 /* CatchClause */: return checkStrictModeCatchClause(node); case 186 /* DeleteExpression */: return checkStrictModeDeleteExpression(node); case 8 /* NumericLiteral */: return checkStrictModeNumericLiteral(node); case 191 /* PostfixUnaryExpression */: return checkStrictModePostfixUnaryExpression(node); case 190 /* PrefixUnaryExpression */: return checkStrictModePrefixUnaryExpression(node); case 217 /* WithStatement */: return checkStrictModeWithStatement(node); case 167 /* ThisType */: seenThisKeyword = true; return; case 156 /* TypePredicate */: return checkTypePredicate(node); case 143 /* TypeParameter */: return declareSymbolAndAddToSymbolTable(node, 262144 /* TypeParameter */, 530920 /* TypeParameterExcludes */); case 144 /* Parameter */: return bindParameter(node); case 223 /* VariableDeclaration */: case 174 /* BindingElement */: return bindVariableDeclarationOrBindingElement(node); case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: case 271 /* JSDocRecordMember */: return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 0 /* PropertyExcludes */); case 286 /* JSDocPropertyTag */: return bindJSDocProperty(node); case 257 /* PropertyAssignment */: case 258 /* ShorthandPropertyAssignment */: return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 0 /* PropertyExcludes */); case 260 /* EnumMember */: return bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 900095 /* EnumMemberExcludes */); case 259 /* SpreadAssignment */: case 251 /* JsxSpreadAttribute */: var root = container; var hasRest = false; while (root.parent) { if (root.kind === 176 /* ObjectLiteralExpression */ && root.parent.kind === 192 /* BinaryExpression */ && root.parent.operatorToken.kind === 57 /* EqualsToken */ && root.parent.left === root) { hasRest = true; break; } root = root.parent; } return; case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: return declareSymbolAndAddToSymbolTable(node, 131072 /* Signature */, 0 /* None */); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: // If this is an ObjectLiteralExpression method, then it sits in the same space // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same // name. return bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), ts.isObjectLiteralMethod(node) ? 0 /* PropertyExcludes */ : 99263 /* MethodExcludes */); case 225 /* FunctionDeclaration */: return bindFunctionDeclaration(node); case 150 /* Constructor */: return declareSymbolAndAddToSymbolTable(node, 16384 /* Constructor */, /*symbolExcludes:*/ 0 /* None */); case 151 /* GetAccessor */: return bindPropertyOrMethodOrAccessor(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */); case 152 /* SetAccessor */: return bindPropertyOrMethodOrAccessor(node, 65536 /* SetAccessor */, 74687 /* SetAccessorExcludes */); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 274 /* JSDocFunctionType */: return bindFunctionOrConstructorType(node); case 161 /* TypeLiteral */: case 170 /* MappedType */: case 287 /* JSDocTypeLiteral */: case 270 /* JSDocRecordType */: return bindAnonymousDeclaration(node, 2048 /* TypeLiteral */, "__type"); case 176 /* ObjectLiteralExpression */: return bindObjectLiteralExpression(node); case 184 /* FunctionExpression */: case 185 /* ArrowFunction */: return bindFunctionExpression(node); case 179 /* CallExpression */: if (ts.isInJavaScriptFile(node)) { bindCallExpression(node); } break; // Members of classes, interfaces, and modules case 197 /* ClassExpression */: case 226 /* ClassDeclaration */: // All classes are automatically in strict mode in ES6. inStrictMode = true; return bindClassLikeDeclaration(node); case 227 /* InterfaceDeclaration */: return bindBlockScopedDeclaration(node, 64 /* Interface */, 792968 /* InterfaceExcludes */); case 285 /* JSDocTypedefTag */: if (!node.fullName || node.fullName.kind === 70 /* Identifier */) { return bindBlockScopedDeclaration(node, 524288 /* TypeAlias */, 793064 /* TypeAliasExcludes */); } break; case 228 /* TypeAliasDeclaration */: return bindBlockScopedDeclaration(node, 524288 /* TypeAlias */, 793064 /* TypeAliasExcludes */); case 229 /* EnumDeclaration */: return bindEnumDeclaration(node); case 230 /* ModuleDeclaration */: return bindModuleDeclaration(node); // Imports and exports case 234 /* ImportEqualsDeclaration */: case 237 /* NamespaceImport */: case 239 /* ImportSpecifier */: case 243 /* ExportSpecifier */: return declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */); case 233 /* NamespaceExportDeclaration */: return bindNamespaceExportDeclaration(node); case 236 /* ImportClause */: return bindImportClause(node); case 241 /* ExportDeclaration */: return bindExportDeclaration(node); case 240 /* ExportAssignment */: return bindExportAssignment(node); case 261 /* SourceFile */: updateStrictModeStatementList(node.statements); return bindSourceFileIfExternalModule(); case 204 /* Block */: if (!ts.isFunctionLike(node.parent)) { return; } // Fall through case 231 /* ModuleBlock */: return updateStrictModeStatementList(node.statements); } }
(node) { switch (node.kind) { /* Strict mode checks */ case 70 /* Identifier */: // for typedef type names with namespaces, bind the new jsdoc type symbol here // because it requires all containing namespaces to be in effect, namely the // current "blockScopeContainer" needs to be set to its immediate namespace parent. if (node.isInJSDocNamespace) { var parentNode = node.parent; while (parentNode && parentNode.kind !== 285 /* JSDocTypedefTag */) { parentNode = parentNode.parent; } bindBlockScopedDeclaration(parentNode, 524288 /* TypeAlias */, 793064 /* TypeAliasExcludes */); break; } case 98 /* ThisKeyword */: if (currentFlow && (ts.isExpression(node) || parent.kind === 258 /* ShorthandPropertyAssignment */)) { node.flowNode = currentFlow; } return checkStrictModeIdentifier(node); case 177 /* PropertyAccessExpression */: if (currentFlow && isNarrowableReference(node)) { node.flowNode = currentFlow; } break; case 192 /* BinaryExpression */: if (ts.isInJavaScriptFile(node)) { var specialKind = ts.getSpecialPropertyAssignmentKind(node); switch (specialKind) { case 1 /* ExportsProperty */: bindExportsPropertyAssignment(node); break; case 2 /* ModuleExports */: bindModuleExportsAssignment(node); break; case 3 /* PrototypeProperty */: bindPrototypePropertyAssignment(node); break; case 4 /* ThisProperty */: bindThisPropertyAssignment(node); break; case 0 /* None */: // Nothing to do break; default: ts.Debug.fail("Unknown special property assignment kind"); } } return checkStrictModeBinaryExpression(node); case 256 /* CatchClause */: return checkStrictModeCatchClause(node); case 186 /* DeleteExpression */: return checkStrictModeDeleteExpression(node); case 8 /* NumericLiteral */: return checkStrictModeNumericLiteral(node); case 191 /* PostfixUnaryExpression */: return checkStrictModePostfixUnaryExpression(node); case 190 /* PrefixUnaryExpression */: return checkStrictModePrefixUnaryExpression(node); case 217 /* WithStatement */: return checkStrictModeWithStatement(node); case 167 /* ThisType */: seenThisKeyword = true; return; case 156 /* TypePredicate */: return checkTypePredicate(node); case 143 /* TypeParameter */: return declareSymbolAndAddToSymbolTable(node, 262144 /* TypeParameter */, 530920 /* TypeParameterExcludes */); case 144 /* Parameter */: return bindParameter(node); case 223 /* VariableDeclaration */: case 174 /* BindingElement */: return bindVariableDeclarationOrBindingElement(node); case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: case 271 /* JSDocRecordMember */: return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 0 /* PropertyExcludes */); case 286 /* JSDocPropertyTag */: return bindJSDocProperty(node); case 257 /* PropertyAssignment */: case 258 /* ShorthandPropertyAssignment */: return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 0 /* PropertyExcludes */); case 260 /* EnumMember */: return bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 900095 /* EnumMemberExcludes */); case 259 /* SpreadAssignment */: case 251 /* JsxSpreadAttribute */: var root = container; var hasRest = false; while (root.parent) { if (root.kind === 176 /* ObjectLiteralExpression */ && root.parent.kind === 192 /* BinaryExpression */ && root.parent.operatorToken.kind === 57 /* EqualsToken */ && root.parent.left === root) { hasRest = true; break; } root = root.parent; } return; case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: return declareSymbolAndAddToSymbolTable(node, 131072 /* Signature */, 0 /* None */); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: // If this is an ObjectLiteralExpression method, then it sits in the same space // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same // name. return bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), ts.isObjectLiteralMethod(node) ? 0 /* PropertyExcludes */ : 99263 /* MethodExcludes */); case 225 /* FunctionDeclaration */: return bindFunctionDeclaration(node); case 150 /* Constructor */: return declareSymbolAndAddToSymbolTable(node, 16384 /* Constructor */, /*symbolExcludes:*/ 0 /* None */); case 151 /* GetAccessor */: return bindPropertyOrMethodOrAccessor(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */); case 152 /* SetAccessor */: return bindPropertyOrMethodOrAccessor(node, 65536 /* SetAccessor */, 74687 /* SetAccessorExcludes */); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 274 /* JSDocFunctionType */: return bindFunctionOrConstructorType(node); case 161 /* TypeLiteral */: case 170 /* MappedType */: case 287 /* JSDocTypeLiteral */: case 270 /* JSDocRecordType */: return bindAnonymousDeclaration(node, 2048 /* TypeLiteral */, "__type"); case 176 /* ObjectLiteralExpression */: return bindObjectLiteralExpression(node); case 184 /* FunctionExpression */: case 185 /* ArrowFunction */: return bindFunctionExpression(node); case 179 /* CallExpression */: if (ts.isInJavaScriptFile(node)) { bindCallExpression(node); } break; // Members of classes, interfaces, and modules case 197 /* ClassExpression */: case 226 /* ClassDeclaration */: // All classes are automatically in strict mode in ES6. inStrictMode = true; return bindClassLikeDeclaration(node); case 227 /* InterfaceDeclaration */: return bindBlockScopedDeclaration(node, 64 /* Interface */, 792968 /* InterfaceExcludes */); case 285 /* JSDocTypedefTag */: if (!node.fullName || node.fullName.kind === 70 /* Identifier */) { return bindBlockScopedDeclaration(node, 524288 /* TypeAlias */, 793064 /* TypeAliasExcludes */); } break; case 228 /* TypeAliasDeclaration */: return bindBlockScopedDeclaration(node, 524288 /* TypeAlias */, 793064 /* TypeAliasExcludes */); case 229 /* EnumDeclaration */: return bindEnumDeclaration(node); case 230 /* ModuleDeclaration */: return bindModuleDeclaration(node); // Imports and exports case 234 /* ImportEqualsDeclaration */: case 237 /* NamespaceImport */: case 239 /* ImportSpecifier */: case 243 /* ExportSpecifier */: return declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */); case 233 /* NamespaceExportDeclaration */: return bindNamespaceExportDeclaration(node); case 236 /* ImportClause */: return bindImportClause(node); case 241 /* ExportDeclaration */: return bindExportDeclaration(node); case 240 /* ExportAssignment */: return bindExportAssignment(node); case 261 /* SourceFile */: updateStrictModeStatementList(node.statements); return bindSourceFileIfExternalModule(); case 204 /* Block */: if (!ts.isFunctionLike(node.parent)) { return; } // Fall through case 231 /* ModuleBlock */: return updateStrictModeStatementList(node.statements); } }
(node) { switch (node.kind) { /* Strict mode checks */ case 70 /* Identifier */: // for typedef type names with namespaces, bind the new jsdoc type symbol here // because it requires all containing namespaces to be in effect, namely the // current "blockScopeContainer" needs to be set to its immediate namespace parent. if (node.isInJSDocNamespace) { var parentNode = node.parent; while (parentNode && parentNode.kind !== 285 /* JSDocTypedefTag */) { parentNode = parentNode.parent; } bindBlockScopedDeclaration(parentNode, 524288 /* TypeAlias */, 793064 /* TypeAliasExcludes */); break; } case 98 /* ThisKeyword */: if (currentFlow && (ts.isExpression(node) || parent.kind === 258 /* ShorthandPropertyAssignment */)) { node.flowNode = currentFlow; } return checkStrictModeIdentifier(node); case 177 /* PropertyAccessExpression */: if (currentFlow && isNarrowableReference(node)) { node.flowNode = currentFlow; } break; case 192 /* BinaryExpression */: if (ts.isInJavaScriptFile(node)) { var specialKind = ts.getSpecialPropertyAssignmentKind(node); switch (specialKind) { case 1 /* ExportsProperty */: bindExportsPropertyAssignment(node); break; case 2 /* ModuleExports */: bindModuleExportsAssignment(node); break; case 3 /* PrototypeProperty */: bindPrototypePropertyAssignment(node); break; case 4 /* ThisProperty */: bindThisPropertyAssignment(node); break; case 0 /* None */: // Nothing to do break; default: ts.Debug.fail("Unknown special property assignment kind"); } } return checkStrictModeBinaryExpression(node); case 256 /* CatchClause */: return checkStrictModeCatchClause(node); case 186 /* DeleteExpression */: return checkStrictModeDeleteExpression(node); case 8 /* NumericLiteral */: return checkStrictModeNumericLiteral(node); case 191 /* PostfixUnaryExpression */: return checkStrictModePostfixUnaryExpression(node); case 190 /* PrefixUnaryExpression */: return checkStrictModePrefixUnaryExpression(node); case 217 /* WithStatement */: return checkStrictModeWithStatement(node); case 167 /* ThisType */: seenThisKeyword = true; return; case 156 /* TypePredicate */: return checkTypePredicate(node); case 143 /* TypeParameter */: return declareSymbolAndAddToSymbolTable(node, 262144 /* TypeParameter */, 530920 /* TypeParameterExcludes */); case 144 /* Parameter */: return bindParameter(node); case 223 /* VariableDeclaration */: case 174 /* BindingElement */: return bindVariableDeclarationOrBindingElement(node); case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: case 271 /* JSDocRecordMember */: return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 0 /* PropertyExcludes */); case 286 /* JSDocPropertyTag */: return bindJSDocProperty(node); case 257 /* PropertyAssignment */: case 258 /* ShorthandPropertyAssignment */: return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 0 /* PropertyExcludes */); case 260 /* EnumMember */: return bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 900095 /* EnumMemberExcludes */); case 259 /* SpreadAssignment */: case 251 /* JsxSpreadAttribute */: var root = container; var hasRest = false; while (root.parent) { if (root.kind === 176 /* ObjectLiteralExpression */ && root.parent.kind === 192 /* BinaryExpression */ && root.parent.operatorToken.kind === 57 /* EqualsToken */ && root.parent.left === root) { hasRest = true; break; } root = root.parent; } return; case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: return declareSymbolAndAddToSymbolTable(node, 131072 /* Signature */, 0 /* None */); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: // If this is an ObjectLiteralExpression method, then it sits in the same space // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same // name. return bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), ts.isObjectLiteralMethod(node) ? 0 /* PropertyExcludes */ : 99263 /* MethodExcludes */); case 225 /* FunctionDeclaration */: return bindFunctionDeclaration(node); case 150 /* Constructor */: return declareSymbolAndAddToSymbolTable(node, 16384 /* Constructor */, /*symbolExcludes:*/ 0 /* None */); case 151 /* GetAccessor */: return bindPropertyOrMethodOrAccessor(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */); case 152 /* SetAccessor */: return bindPropertyOrMethodOrAccessor(node, 65536 /* SetAccessor */, 74687 /* SetAccessorExcludes */); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 274 /* JSDocFunctionType */: return bindFunctionOrConstructorType(node); case 161 /* TypeLiteral */: case 170 /* MappedType */: case 287 /* JSDocTypeLiteral */: case 270 /* JSDocRecordType */: return bindAnonymousDeclaration(node, 2048 /* TypeLiteral */, "__type"); case 176 /* ObjectLiteralExpression */: return bindObjectLiteralExpression(node); case 184 /* FunctionExpression */: case 185 /* ArrowFunction */: return bindFunctionExpression(node); case 179 /* CallExpression */: if (ts.isInJavaScriptFile(node)) { bindCallExpression(node); } break; // Members of classes, interfaces, and modules case 197 /* ClassExpression */: case 226 /* ClassDeclaration */: // All classes are automatically in strict mode in ES6. inStrictMode = true; return bindClassLikeDeclaration(node); case 227 /* InterfaceDeclaration */: return bindBlockScopedDeclaration(node, 64 /* Interface */, 792968 /* InterfaceExcludes */); case 285 /* JSDocTypedefTag */: if (!node.fullName || node.fullName.kind === 70 /* Identifier */) { return bindBlockScopedDeclaration(node, 524288 /* TypeAlias */, 793064 /* TypeAliasExcludes */); } break; case 228 /* TypeAliasDeclaration */: return bindBlockScopedDeclaration(node, 524288 /* TypeAlias */, 793064 /* TypeAliasExcludes */); case 229 /* EnumDeclaration */: return bindEnumDeclaration(node); case 230 /* ModuleDeclaration */: return bindModuleDeclaration(node); // Imports and exports case 234 /* ImportEqualsDeclaration */: case 237 /* NamespaceImport */: case 239 /* ImportSpecifier */: case 243 /* ExportSpecifier */: return declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */); case 233 /* NamespaceExportDeclaration */: return bindNamespaceExportDeclaration(node); case 236 /* ImportClause */: return bindImportClause(node); case 241 /* ExportDeclaration */: return bindExportDeclaration(node); case 240 /* ExportAssignment */: return bindExportAssignment(node); case 261 /* SourceFile */: updateStrictModeStatementList(node.statements); return bindSourceFileIfExternalModule(); case 204 /* Block */: if (!ts.isFunctionLike(node.parent)) { return; } // Fall through case 231 /* ModuleBlock */: return updateStrictModeStatementList(node.statements); } }
isDynamicName:
(name) { return name.kind === 142 /* ComputedPropertyName */ && !isStringOrNumericLiteral(name.expression) && !isWellKnownSymbolSyntactically(name.expression); }
(name) { return name.kind === 142 /* ComputedPropertyName */ && !isStringOrNumericLiteral(name.expression) && !isWellKnownSymbolSyntactically(name.expression); }
(name) { return name.kind === 142 /* ComputedPropertyName */ && !isStringOrNumericLiteral(name.expression) && !isWellKnownSymbolSyntactically(name.expression); }
isBindingPattern:
(node) { if (node) { var kind = node.kind; return kind === 173 /* ArrayBindingPattern */ || kind === 172 /* ObjectBindingPattern */; } return false; }
(node) { if (node) { var kind = node.kind; return kind === 173 /* ArrayBindingPattern */ || kind === 172 /* ObjectBindingPattern */; } return false; }
(node) { if (node) { var kind = node.kind; return kind === 173 /* ArrayBindingPattern */ || kind === 172 /* ObjectBindingPattern */; } return false; }
bindPropertyOrMethodOrAccessor:
(node, symbolFlags, symbolExcludes) { if (!ts.isDeclarationFile(file) && !ts.isInAmbientContext(node)) { if (ts.isAsyncFunctionLike(node)) { emitFlags |= 1024 /* HasAsyncFunctions */; } } if (currentFlow && ts.isObjectLiteralOrClassExpressionMethod(node)) { node.flowNode = currentFlow; } return ts.hasDynamicName(node) ? bindAnonymousDeclaration(node, symbolFlags, "__computed") : declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes); }
isObjectLiteralOrClassExpressionMethod:
(node) { return node.kind === 149 /* MethodDeclaration */ && (node.parent.kind === 176 /* ObjectLiteralExpression */ || node.parent.kind === 197 /* ClassExpression */); }
(node) { return node.kind === 149 /* MethodDeclaration */ && (node.parent.kind === 176 /* ObjectLiteralExpression */ || node.parent.kind === 197 /* ClassExpression */); }
(node) { return node.kind === 149 /* MethodDeclaration */ && (node.parent.kind === 176 /* ObjectLiteralExpression */ || node.parent.kind === 197 /* ClassExpression */); }
(node) { return node.kind === 149 /* MethodDeclaration */ && (node.parent.kind === 176 /* ObjectLiteralExpression */ || node.parent.kind === 197 /* ClassExpression */); }
getContainerFlags:
(node) { switch (node.kind) { case 197 /* ClassExpression */: case 226 /* ClassDeclaration */: case 229 /* EnumDeclaration */: case 176 /* ObjectLiteralExpression */: case 161 /* TypeLiteral */: case 287 /* JSDocTypeLiteral */: case 270 /* JSDocRecordType */: return 1 /* IsContainer */; case 227 /* InterfaceDeclaration */: return 1 /* IsContainer */ | 64 /* IsInterface */; case 274 /* JSDocFunctionType */: case 230 /* ModuleDeclaration */: case 228 /* TypeAliasDeclaration */: case 170 /* MappedType */: return 1 /* IsContainer */ | 32 /* HasLocals */; case 261 /* SourceFile */: return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */; case 149 /* MethodDeclaration */: if (ts.isObjectLiteralOrClassExpressionMethod(node)) { return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */ | 8 /* IsFunctionLike */ | 128 /* IsObjectLiteralOrClassExpressionMethod */; } case 150 /* Constructor */: case 225 /* FunctionDeclaration */: case 148 /* MethodSignature */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: case 158 /* FunctionType */: case 159 /* ConstructorType */: return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */ | 8 /* IsFunctionLike */; case 184 /* FunctionExpression */: case 185 /* ArrowFunction */: return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */ | 8 /* IsFunctionLike */ | 16 /* IsFunctionExpression */; case 231 /* ModuleBlock */: return 4 /* IsControlFlowContainer */; case 147 /* PropertyDeclaration */: return node.initializer ? 4 /* IsControlFlowContainer */ : 0; case 256 /* CatchClause */: case 211 /* ForStatement */: case 212 /* ForInStatement */: case 213 /* ForOfStatement */: case 232 /* CaseBlock */: return 2 /* IsBlockScopedContainer */; case 204 /* Block */: // do not treat blocks directly inside a function as a block-scoped-container. // Locals that reside in this block should go to the function locals. Otherwise 'x' // would not appear to be a redeclaration of a block scoped local in the following // example: // // function foo() { // var x; // let x; // } // // If we placed 'var x' into the function locals and 'let x' into the locals of // the block, then there would be no collision. // // By not creating a new block-scoped-container here, we ensure that both 'var x' // and 'let x' go into the Function-container's locals, and we do get a collision // conflict. return ts.isFunctionLike(node.parent) ? 0 /* None */ : 2 /* IsBlockScopedContainer */; } return 0 /* None */; }
(node) { switch (node.kind) { case 197 /* ClassExpression */: case 226 /* ClassDeclaration */: case 229 /* EnumDeclaration */: case 176 /* ObjectLiteralExpression */: case 161 /* TypeLiteral */: case 287 /* JSDocTypeLiteral */: case 270 /* JSDocRecordType */: return 1 /* IsContainer */; case 227 /* InterfaceDeclaration */: return 1 /* IsContainer */ | 64 /* IsInterface */; case 274 /* JSDocFunctionType */: case 230 /* ModuleDeclaration */: case 228 /* TypeAliasDeclaration */: case 170 /* MappedType */: return 1 /* IsContainer */ | 32 /* HasLocals */; case 261 /* SourceFile */: return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */; case 149 /* MethodDeclaration */: if (ts.isObjectLiteralOrClassExpressionMethod(node)) { return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */ | 8 /* IsFunctionLike */ | 128 /* IsObjectLiteralOrClassExpressionMethod */; } case 150 /* Constructor */: case 225 /* FunctionDeclaration */: case 148 /* MethodSignature */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: case 158 /* FunctionType */: case 159 /* ConstructorType */: return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */ | 8 /* IsFunctionLike */; case 184 /* FunctionExpression */: case 185 /* ArrowFunction */: return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */ | 8 /* IsFunctionLike */ | 16 /* IsFunctionExpression */; case 231 /* ModuleBlock */: return 4 /* IsControlFlowContainer */; case 147 /* PropertyDeclaration */: return node.initializer ? 4 /* IsControlFlowContainer */ : 0; case 256 /* CatchClause */: case 211 /* ForStatement */: case 212 /* ForInStatement */: case 213 /* ForOfStatement */: case 232 /* CaseBlock */: return 2 /* IsBlockScopedContainer */; case 204 /* Block */: // do not treat blocks directly inside a function as a block-scoped-container. // Locals that reside in this block should go to the function locals. Otherwise 'x' // would not appear to be a redeclaration of a block scoped local in the following // example: // // function foo() { // var x; // let x; // } // // If we placed 'var x' into the function locals and 'let x' into the locals of // the block, then there would be no collision. // // By not creating a new block-scoped-container here, we ensure that both 'var x' // and 'let x' go into the Function-container's locals, and we do get a collision // conflict. return ts.isFunctionLike(node.parent) ? 0 /* None */ : 2 /* IsBlockScopedContainer */; } return 0 /* None */; }
(node) { switch (node.kind) { case 197 /* ClassExpression */: case 226 /* ClassDeclaration */: case 229 /* EnumDeclaration */: case 176 /* ObjectLiteralExpression */: case 161 /* TypeLiteral */: case 287 /* JSDocTypeLiteral */: case 270 /* JSDocRecordType */: return 1 /* IsContainer */; case 227 /* InterfaceDeclaration */: return 1 /* IsContainer */ | 64 /* IsInterface */; case 274 /* JSDocFunctionType */: case 230 /* ModuleDeclaration */: case 228 /* TypeAliasDeclaration */: case 170 /* MappedType */: return 1 /* IsContainer */ | 32 /* HasLocals */; case 261 /* SourceFile */: return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */; case 149 /* MethodDeclaration */: if (ts.isObjectLiteralOrClassExpressionMethod(node)) { return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */ | 8 /* IsFunctionLike */ | 128 /* IsObjectLiteralOrClassExpressionMethod */; } case 150 /* Constructor */: case 225 /* FunctionDeclaration */: case 148 /* MethodSignature */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: case 158 /* FunctionType */: case 159 /* ConstructorType */: return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */ | 8 /* IsFunctionLike */; case 184 /* FunctionExpression */: case 185 /* ArrowFunction */: return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */ | 8 /* IsFunctionLike */ | 16 /* IsFunctionExpression */; case 231 /* ModuleBlock */: return 4 /* IsControlFlowContainer */; case 147 /* PropertyDeclaration */: return node.initializer ? 4 /* IsControlFlowContainer */ : 0; case 256 /* CatchClause */: case 211 /* ForStatement */: case 212 /* ForInStatement */: case 213 /* ForOfStatement */: case 232 /* CaseBlock */: return 2 /* IsBlockScopedContainer */; case 204 /* Block */: // do not treat blocks directly inside a function as a block-scoped-container. // Locals that reside in this block should go to the function locals. Otherwise 'x' // would not appear to be a redeclaration of a block scoped local in the following // example: // // function foo() { // var x; // let x; // } // // If we placed 'var x' into the function locals and 'let x' into the locals of // the block, then there would be no collision. // // By not creating a new block-scoped-container here, we ensure that both 'var x' // and 'let x' go into the Function-container's locals, and we do get a collision // conflict. return ts.isFunctionLike(node.parent) ? 0 /* None */ : 2 /* IsBlockScopedContainer */; } return 0 /* None */; }
Deopt: <JS Function isObjectLiteralMethod (SharedFunctionInfo 0x2c75c4acf6c1)> (opt #264) @6, FP to SP delta: 24, caller sp: 0x7fff5fbfc870
Deopt: <JS Function isObjectLiteralOrClassExpressionMethod (SharedFunctionInfo 0x2c75c4acf781)> (opt #262) @4, FP to SP delta: 24, caller sp: 0x7fff5fbfc7f8
Deopt: <JS Function declareSymbolAndAddToSymbolTableWorker (SharedFunctionInfo 0x2142bdb5b941)> (opt #270) @17, FP to SP delta: 64, caller sp: 0x7fff5fbfc7f8
bindChildrenWorker:
(node) { // Binding of JsDocComment should be done before the current block scope container changes. // because the scope of JsDocComment should not be affected by whether the current node is a // container or not. if (ts.isInJavaScriptFile(node) && node.jsDoc) { ts.forEach(node.jsDoc, bind); } if (checkUnreachable(node)) { bindEachChild(node); return; } switch (node.kind) { case 210 /* WhileStatement */: bindWhileStatement(node); break; case 209 /* DoStatement */: bindDoStatement(node); break; case 211 /* ForStatement */: bindForStatement(node); break; case 212 /* ForInStatement */: case 213 /* ForOfStatement */: bindForInOrForOfStatement(node); break; case 208 /* IfStatement */: bindIfStatement(node); break; case 216 /* ReturnStatement */: case 220 /* ThrowStatement */: bindReturnOrThrow(node); break; case 215 /* BreakStatement */: case 214 /* ContinueStatement */: bindBreakOrContinueStatement(node); break; case 221 /* TryStatement */: bindTryStatement(node); break; case 218 /* SwitchStatement */: bindSwitchStatement(node); break; case 232 /* CaseBlock */: bindCaseBlock(node); break; case 253 /* CaseClause */: bindCaseClause(node); break; case 219 /* LabeledStatement */: bindLabeledStatement(node); break; case 190 /* PrefixUnaryExpression */: bindPrefixUnaryExpressionFlow(node); break; case 191 /* PostfixUnaryExpression */: bindPostfixUnaryExpressionFlow(node); break; case 192 /* BinaryExpression */: bindBinaryExpressionFlow(node); break; case 186 /* DeleteExpression */: bindDeleteExpressionFlow(node); break; case 193 /* ConditionalExpression */: bindConditionalExpressionFlow(node); break; case 223 /* VariableDeclaration */: bindVariableDeclarationFlow(node); break; case 179 /* CallExpression */: bindCallExpressionFlow(node); break; default: bindEachChild(node); break; } }
(node) { // Binding of JsDocComment should be done before the current block scope container changes. // because the scope of JsDocComment should not be affected by whether the current node is a // container or not. if (ts.isInJavaScriptFile(node) && node.jsDoc) { ts.forEach(node.jsDoc, bind); } if (checkUnreachable(node)) { bindEachChild(node); return; } switch (node.kind) { case 210 /* WhileStatement */: bindWhileStatement(node); break; case 209 /* DoStatement */: bindDoStatement(node); break; case 211 /* ForStatement */: bindForStatement(node); break; case 212 /* ForInStatement */: case 213 /* ForOfStatement */: bindForInOrForOfStatement(node); break; case 208 /* IfStatement */: bindIfStatement(node); break; case 216 /* ReturnStatement */: case 220 /* ThrowStatement */: bindReturnOrThrow(node); break; case 215 /* BreakStatement */: case 214 /* ContinueStatement */: bindBreakOrContinueStatement(node); break; case 221 /* TryStatement */: bindTryStatement(node); break; case 218 /* SwitchStatement */: bindSwitchStatement(node); break; case 232 /* CaseBlock */: bindCaseBlock(node); break; case 253 /* CaseClause */: bindCaseClause(node); break; case 219 /* LabeledStatement */: bindLabeledStatement(node); break; case 190 /* PrefixUnaryExpression */: bindPrefixUnaryExpressionFlow(node); break; case 191 /* PostfixUnaryExpression */: bindPostfixUnaryExpressionFlow(node); break; case 192 /* BinaryExpression */: bindBinaryExpressionFlow(node); break; case 186 /* DeleteExpression */: bindDeleteExpressionFlow(node); break; case 193 /* ConditionalExpression */: bindConditionalExpressionFlow(node); break; case 223 /* VariableDeclaration */: bindVariableDeclarationFlow(node); break; case 179 /* CallExpression */: bindCallExpressionFlow(node); break; default: bindEachChild(node); break; } }
nodeIsPresent:
(node) { return !nodeIsMissing(node); }
isParameterPropertyDeclaration:
(node) { return ts.hasModifier(node, 92 /* ParameterPropertyModifier */) && node.parent.kind === 150 /* Constructor */ && ts.isClassLike(node.parent.parent); }
addDeclarationToSymbol:
(symbol, node, symbolFlags) { symbol.flags |= symbolFlags; node.symbol = symbol; if (!symbol.declarations) { symbol.declarations = []; } symbol.declarations.push(node); if (symbolFlags & 1952 /* HasExports */ && !symbol.exports) { symbol.exports = ts.createMap(); } if (symbolFlags & 6240 /* HasMembers */ && !symbol.members) { symbol.members = ts.createMap(); } if (symbolFlags & 107455 /* Value */) { var valueDeclaration = symbol.valueDeclaration; if (!valueDeclaration || (valueDeclaration.kind !== node.kind && valueDeclaration.kind === 230 /* ModuleDeclaration */)) { // other kinds of value declarations take precedence over modules symbol.valueDeclaration = node; } } }
(symbol, node, symbolFlags) { symbol.flags |= symbolFlags; node.symbol = symbol; if (!symbol.declarations) { symbol.declarations = []; } symbol.declarations.push(node); if (symbolFlags & 1952 /* HasExports */ && !symbol.exports) { symbol.exports = ts.createMap(); } if (symbolFlags & 6240 /* HasMembers */ && !symbol.members) { symbol.members = ts.createMap(); } if (symbolFlags & 107455 /* Value */) { var valueDeclaration = symbol.valueDeclaration; if (!valueDeclaration || (valueDeclaration.kind !== node.kind && valueDeclaration.kind === 230 /* ModuleDeclaration */)) { // other kinds of value declarations take precedence over modules symbol.valueDeclaration = node; } } }
(symbol, node, symbolFlags) { symbol.flags |= symbolFlags; node.symbol = symbol; if (!symbol.declarations) { symbol.declarations = []; } symbol.declarations.push(node); if (symbolFlags & 1952 /* HasExports */ && !symbol.exports) { symbol.exports = ts.createMap(); } if (symbolFlags & 6240 /* HasMembers */ && !symbol.members) { symbol.members = ts.createMap(); } if (symbolFlags & 107455 /* Value */) { var valueDeclaration = symbol.valueDeclaration; if (!valueDeclaration || (valueDeclaration.kind !== node.kind && valueDeclaration.kind === 230 /* ModuleDeclaration */)) { // other kinds of value declarations take precedence over modules symbol.valueDeclaration = node; } } }
(symbol, node, symbolFlags) { symbol.flags |= symbolFlags; node.symbol = symbol; if (!symbol.declarations) { symbol.declarations = []; } symbol.declarations.push(node); if (symbolFlags & 1952 /* HasExports */ && !symbol.exports) { symbol.exports = ts.createMap(); } if (symbolFlags & 6240 /* HasMembers */ && !symbol.members) { symbol.members = ts.createMap(); } if (symbolFlags & 107455 /* Value */) { var valueDeclaration = symbol.valueDeclaration; if (!valueDeclaration || (valueDeclaration.kind !== node.kind && valueDeclaration.kind === 230 /* ModuleDeclaration */)) { // other kinds of value declarations take precedence over modules symbol.valueDeclaration = node; } } }
Deopt: <JS Function getDeclarationName (SharedFunctionInfo 0x2142bdb58d01)> (opt #247) @18, FP to SP delta: 40, caller sp: 0x7fff5fbfd860
Deopt: <JS Function forEachChild (SharedFunctionInfo 0x2c75c4af0811)> (opt #252) @65, FP to SP delta: 760, caller sp: 0x7fff5fbfcfe0
Deopt: <JS Function isBindingPattern (SharedFunctionInfo 0x2c75c4ad8f01)> (opt #229) @3, FP to SP delta: 24, caller sp: 0x7fff5fbfc9d0
Deopt: <JS Function forEachChild (SharedFunctionInfo 0x2c75c4af0811)> (opt #252) @199, FP to SP delta: 760, caller sp: 0x7fff5fbfd520
Deopt: <JS Function forEachChild (SharedFunctionInfo 0x2c75c4af0811)> (opt #252) @84, FP to SP delta: 760, caller sp: 0x7fff5fbfd9f8
Deopt: <JS Function bindWorker (SharedFunctionInfo 0x2142bdb5d081)> (opt #250) @131, FP to SP delta: 248, caller sp: 0x7fff5fbfcf10
Deopt: <JS Function addDeclarationToSymbol (SharedFunctionInfo 0x2142bdb58c41)> (opt #254) @16, FP to SP delta: 56, caller sp: 0x7fff5fbfd398
Deopt: <JS Function declareSymbolAndAddToSymbolTableWorker (SharedFunctionInfo 0x2142bdb5b941)> (opt #253) @21, FP to SP delta: 64, caller sp: 0x7fff5fbfcd20
Deopt: <JS Function getContainerFlags (SharedFunctionInfo 0x2142bdb5b701)> (opt #205) @4, FP to SP delta: 40, caller sp: 0x7fff5fbfce00
Deopt: <JS Function isObjectLiteralOrClassExpressionMethod (SharedFunctionInfo 0x2c75c4acf781)> (opt #251) @3, FP to SP delta: 24, caller sp: 0x7fff5fbfd230
(symbol, node, symbolFlags) { symbol.flags |= symbolFlags; node.symbol = symbol; if (!symbol.declarations) { symbol.declarations = []; } symbol.declarations.push(node); if (symbolFlags & 1952 /* HasExports */ && !symbol.exports) { symbol.exports = ts.createMap(); } if (symbolFlags & 6240 /* HasMembers */ && !symbol.members) { symbol.members = ts.createMap(); } if (symbolFlags & 107455 /* Value */) { var valueDeclaration = symbol.valueDeclaration; if (!valueDeclaration || (valueDeclaration.kind !== node.kind && valueDeclaration.kind === 230 /* ModuleDeclaration */)) { // other kinds of value declarations take precedence over modules symbol.valueDeclaration = node; } } }
(symbol, node, symbolFlags) { symbol.flags |= symbolFlags; node.symbol = symbol; if (!symbol.declarations) { symbol.declarations = []; } symbol.declarations.push(node); if (symbolFlags & 1952 /* HasExports */ && !symbol.exports) { symbol.exports = ts.createMap(); } if (symbolFlags & 6240 /* HasMembers */ && !symbol.members) { symbol.members = ts.createMap(); } if (symbolFlags & 107455 /* Value */) { var valueDeclaration = symbol.valueDeclaration; if (!valueDeclaration || (valueDeclaration.kind !== node.kind && valueDeclaration.kind === 230 /* ModuleDeclaration */)) { // other kinds of value declarations take precedence over modules symbol.valueDeclaration = node; } } }
(symbol, node, symbolFlags) { symbol.flags |= symbolFlags; node.symbol = symbol; if (!symbol.declarations) { symbol.declarations = []; } symbol.declarations.push(node); if (symbolFlags & 1952 /* HasExports */ && !symbol.exports) { symbol.exports = ts.createMap(); } if (symbolFlags & 6240 /* HasMembers */ && !symbol.members) { symbol.members = ts.createMap(); } if (symbolFlags & 107455 /* Value */) { var valueDeclaration = symbol.valueDeclaration; if (!valueDeclaration || (valueDeclaration.kind !== node.kind && valueDeclaration.kind === 230 /* ModuleDeclaration */)) { // other kinds of value declarations take precedence over modules symbol.valueDeclaration = node; } } }
Deopt: <JS Function getCombinedNodeFlags (SharedFunctionInfo 0x2c75c4adfaa9)> (opt #282) @9, FP to SP delta: 48, caller sp: 0x7fff5fbfce20
Deopt: <JS Function forEachChild (SharedFunctionInfo 0x2c75c4af0811)> (opt #275) @131, FP to SP delta: 776, caller sp: 0x7fff5fbfce60
Deopt: <JS Function declareSymbolAndAddToSymbolTableWorker (SharedFunctionInfo 0x2142bdb5b941)> (opt #280) @11, FP to SP delta: 64, caller sp: 0x7fff5fbfcad0
Deopt: <JS Function forEachChild (SharedFunctionInfo 0x2c75c4af0811)> (opt #275) @241, FP to SP delta: 776, caller sp: 0x7fff5fbfd480
Deopt: <JS Function forEachChild (SharedFunctionInfo 0x2c75c4af0811)> (opt #275) @129, FP to SP delta: 776, caller sp: 0x7fff5fbfd9b0
declareSymbol:
(symbolTable, parent, node, includes, excludes) { ts.Debug.assert(!ts.hasDynamicName(node)); var isDefaultExport = ts.hasModifier(node, 512 /* Default */); // The exported symbol for an export default function/class node is always named "default" var name = isDefaultExport && parent ? "default" : getDeclarationName(node); var symbol; if (name === undefined) { symbol = createSymbol(0 /* None */, "__missing"); } else { // Check and see if the symbol table already has a symbol with this name. If not, // create a new symbol with this name and add it to the table. Note that we don't // give the new symbol any flags *yet*. This ensures that it will not conflict // with the 'excludes' flags we pass in. // // If we do get an existing symbol, see if it conflicts with the new symbol we're // creating. For example, a 'var' symbol and a 'class' symbol will conflict within // the same symbol table. If we have a conflict, report the issue on each // declaration we have for this symbol, and then create a new symbol for this // declaration. // // Note that when properties declared in Javascript constructors // (marked by isReplaceableByMethod) conflict with another symbol, the property loses. // Always. This allows the common Javascript pattern of overwriting a prototype method // with an bound instance method of the same type: `this.method = this.method.bind(this)` // // If we created a new symbol, either because we didn't have a symbol with this name // in the symbol table, or we conflicted with an existing symbol, then just add this // node as the sole declaration of the new symbol. // // Otherwise, we'll be merging into a compatible existing symbol (for example when // you have multiple 'vars' with the same name in the same container). In this case // just add this node into the declarations list of the symbol. symbol = symbolTable[name] || (symbolTable[name] = createSymbol(0 /* None */, name)); if (name && (includes & 788448 /* Classifiable */)) { classifiableNames[name] = name; } if (symbol.flags & excludes) { if (symbol.isReplaceableByMethod) { // Javascript constructor-declared symbols can be discarded in favor of // prototype symbols like methods. symbol = symbolTable[name] = createSymbol(0 /* None */, name); } else { if (node.name) { node.name.parent = node; } // Report errors every position with duplicate declaration // Report errors on previous encountered declarations var message_1 = symbol.flags & 2 /* BlockScopedVariable */ ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; if (symbol.declarations && symbol.declarations.length) { // If the current node is a default export of some sort, then check if // there are any other default exports that we need to error on. // We'll know whether we have other default exports depending on if `symbol` already has a declaration list set. if (isDefaultExport) { message_1 = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; } else { // This is to properly report an error in the case "export default { }" is after export default of class declaration or function declaration. // Error on multiple export default in the following case: // 1. multiple export default of class declaration or function declaration by checking NodeFlags.Default // 2. multiple export default of export assignment. This one doesn't have NodeFlags.Default on (as export default doesn't considered as modifiers) if (symbol.declarations && symbol.declarations.length && (isDefaultExport || (node.kind === 240 /* ExportAssignment */ && !node.isExportEquals))) { message_1 = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; } } } ts.forEach(symbol.declarations, function (declaration) { file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name || declaration, message_1, getDisplayName(declaration))); }); file.bindDiagnostics.push(ts.createDiagnosticForNode(node.name || node, message_1, getDisplayName(node))); symbol = createSymbol(0 /* None */, name); } } } addDeclarationToSymbol(symbol, node, includes); symbol.parent = parent; return symbol; }
(symbolTable, parent, node, includes, excludes) { ts.Debug.assert(!ts.hasDynamicName(node)); var isDefaultExport = ts.hasModifier(node, 512 /* Default */); // The exported symbol for an export default function/class node is always named "default" var name = isDefaultExport && parent ? "default" : getDeclarationName(node); var symbol; if (name === undefined) { symbol = createSymbol(0 /* None */, "__missing"); } else { // Check and see if the symbol table already has a symbol with this name. If not, // create a new symbol with this name and add it to the table. Note that we don't // give the new symbol any flags *yet*. This ensures that it will not conflict // with the 'excludes' flags we pass in. // // If we do get an existing symbol, see if it conflicts with the new symbol we're // creating. For example, a 'var' symbol and a 'class' symbol will conflict within // the same symbol table. If we have a conflict, report the issue on each // declaration we have for this symbol, and then create a new symbol for this // declaration. // // Note that when properties declared in Javascript constructors // (marked by isReplaceableByMethod) conflict with another symbol, the property loses. // Always. This allows the common Javascript pattern of overwriting a prototype method // with an bound instance method of the same type: `this.method = this.method.bind(this)` // // If we created a new symbol, either because we didn't have a symbol with this name // in the symbol table, or we conflicted with an existing symbol, then just add this // node as the sole declaration of the new symbol. // // Otherwise, we'll be merging into a compatible existing symbol (for example when // you have multiple 'vars' with the same name in the same container). In this case // just add this node into the declarations list of the symbol. symbol = symbolTable[name] || (symbolTable[name] = createSymbol(0 /* None */, name)); if (name && (includes & 788448 /* Classifiable */)) { classifiableNames[name] = name; } if (symbol.flags & excludes) { if (symbol.isReplaceableByMethod) { // Javascript constructor-declared symbols can be discarded in favor of // prototype symbols like methods. symbol = symbolTable[name] = createSymbol(0 /* None */, name); } else { if (node.name) { node.name.parent = node; } // Report errors every position with duplicate declaration // Report errors on previous encountered declarations var message_1 = symbol.flags & 2 /* BlockScopedVariable */ ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; if (symbol.declarations && symbol.declarations.length) { // If the current node is a default export of some sort, then check if // there are any other default exports that we need to error on. // We'll know whether we have other default exports depending on if `symbol` already has a declaration list set. if (isDefaultExport) { message_1 = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; } else { // This is to properly report an error in the case "export default { }" is after export default of class declaration or function declaration. // Error on multiple export default in the following case: // 1. multiple export default of class declaration or function declaration by checking NodeFlags.Default // 2. multiple export default of export assignment. This one doesn't have NodeFlags.Default on (as export default doesn't considered as modifiers) if (symbol.declarations && symbol.declarations.length && (isDefaultExport || (node.kind === 240 /* ExportAssignment */ && !node.isExportEquals))) { message_1 = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; } } } ts.forEach(symbol.declarations, function (declaration) { file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name || declaration, message_1, getDisplayName(declaration))); }); file.bindDiagnostics.push(ts.createDiagnosticForNode(node.name || node, message_1, getDisplayName(node))); symbol = createSymbol(0 /* None */, name); } } } addDeclarationToSymbol(symbol, node, includes); symbol.parent = parent; return symbol; }
declareSymbolAndAddToSymbolTableWorker:
(node, symbolFlags, symbolExcludes) { switch (container.kind) { // Modules, source files, and classes need specialized handling for how their // members are declared (for example, a member of a class will go into a specific // symbol table depending on if it is static or not). We defer to specialized // handlers to take care of declaring these child members. case 230 /* ModuleDeclaration */: return declareModuleMember(node, symbolFlags, symbolExcludes); case 261 /* SourceFile */: return declareSourceFileMember(node, symbolFlags, symbolExcludes); case 197 /* ClassExpression */: case 226 /* ClassDeclaration */: return declareClassMember(node, symbolFlags, symbolExcludes); case 229 /* EnumDeclaration */: return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); case 161 /* TypeLiteral */: case 176 /* ObjectLiteralExpression */: case 227 /* InterfaceDeclaration */: case 270 /* JSDocRecordType */: case 287 /* JSDocTypeLiteral */: // Interface/Object-types always have their children added to the 'members' of // their container. They are only accessible through an instance of their // container, and are never in scope otherwise (even inside the body of the // object / type / interface declaring them). An exception is type parameters, // which are in scope without qualification (similar to 'locals'). return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 225 /* FunctionDeclaration */: case 184 /* FunctionExpression */: case 185 /* ArrowFunction */: case 274 /* JSDocFunctionType */: case 228 /* TypeAliasDeclaration */: case 170 /* MappedType */: // All the children of these container types are never visible through another // symbol (i.e. through another symbol's 'exports' or 'members'). Instead, // they're only accessed 'lexically' (i.e. from code that exists underneath // their container in the tree. To accomplish this, we simply add their declared // symbol to the 'locals' of the container. These symbols can then be found as // the type checker walks up the containers, checking them for matching names. return declareSymbol(container.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes); } }
(node, symbolFlags, symbolExcludes) { switch (container.kind) { // Modules, source files, and classes need specialized handling for how their // members are declared (for example, a member of a class will go into a specific // symbol table depending on if it is static or not). We defer to specialized // handlers to take care of declaring these child members. case 230 /* ModuleDeclaration */: return declareModuleMember(node, symbolFlags, symbolExcludes); case 261 /* SourceFile */: return declareSourceFileMember(node, symbolFlags, symbolExcludes); case 197 /* ClassExpression */: case 226 /* ClassDeclaration */: return declareClassMember(node, symbolFlags, symbolExcludes); case 229 /* EnumDeclaration */: return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); case 161 /* TypeLiteral */: case 176 /* ObjectLiteralExpression */: case 227 /* InterfaceDeclaration */: case 270 /* JSDocRecordType */: case 287 /* JSDocTypeLiteral */: // Interface/Object-types always have their children added to the 'members' of // their container. They are only accessible through an instance of their // container, and are never in scope otherwise (even inside the body of the // object / type / interface declaring them). An exception is type parameters, // which are in scope without qualification (similar to 'locals'). return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 225 /* FunctionDeclaration */: case 184 /* FunctionExpression */: case 185 /* ArrowFunction */: case 274 /* JSDocFunctionType */: case 228 /* TypeAliasDeclaration */: case 170 /* MappedType */: // All the children of these container types are never visible through another // symbol (i.e. through another symbol's 'exports' or 'members'). Instead, // they're only accessed 'lexically' (i.e. from code that exists underneath // their container in the tree. To accomplish this, we simply add their declared // symbol to the 'locals' of the container. These symbols can then be found as // the type checker walks up the containers, checking them for matching names. return declareSymbol(container.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes); } }
(node, symbolFlags, symbolExcludes) { switch (container.kind) { // Modules, source files, and classes need specialized handling for how their // members are declared (for example, a member of a class will go into a specific // symbol table depending on if it is static or not). We defer to specialized // handlers to take care of declaring these child members. case 230 /* ModuleDeclaration */: return declareModuleMember(node, symbolFlags, symbolExcludes); case 261 /* SourceFile */: return declareSourceFileMember(node, symbolFlags, symbolExcludes); case 197 /* ClassExpression */: case 226 /* ClassDeclaration */: return declareClassMember(node, symbolFlags, symbolExcludes); case 229 /* EnumDeclaration */: return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); case 161 /* TypeLiteral */: case 176 /* ObjectLiteralExpression */: case 227 /* InterfaceDeclaration */: case 270 /* JSDocRecordType */: case 287 /* JSDocTypeLiteral */: // Interface/Object-types always have their children added to the 'members' of // their container. They are only accessible through an instance of their // container, and are never in scope otherwise (even inside the body of the // object / type / interface declaring them). An exception is type parameters, // which are in scope without qualification (similar to 'locals'). return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 225 /* FunctionDeclaration */: case 184 /* FunctionExpression */: case 185 /* ArrowFunction */: case 274 /* JSDocFunctionType */: case 228 /* TypeAliasDeclaration */: case 170 /* MappedType */: // All the children of these container types are never visible through another // symbol (i.e. through another symbol's 'exports' or 'members'). Instead, // they're only accessed 'lexically' (i.e. from code that exists underneath // their container in the tree. To accomplish this, we simply add their declared // symbol to the 'locals' of the container. These symbols can then be found as // the type checker walks up the containers, checking them for matching names. return declareSymbol(container.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes); } }
(node, symbolFlags, symbolExcludes) { switch (container.kind) { // Modules, source files, and classes need specialized handling for how their // members are declared (for example, a member of a class will go into a specific // symbol table depending on if it is static or not). We defer to specialized // handlers to take care of declaring these child members. case 230 /* ModuleDeclaration */: return declareModuleMember(node, symbolFlags, symbolExcludes); case 261 /* SourceFile */: return declareSourceFileMember(node, symbolFlags, symbolExcludes); case 197 /* ClassExpression */: case 226 /* ClassDeclaration */: return declareClassMember(node, symbolFlags, symbolExcludes); case 229 /* EnumDeclaration */: return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); case 161 /* TypeLiteral */: case 176 /* ObjectLiteralExpression */: case 227 /* InterfaceDeclaration */: case 270 /* JSDocRecordType */: case 287 /* JSDocTypeLiteral */: // Interface/Object-types always have their children added to the 'members' of // their container. They are only accessible through an instance of their // container, and are never in scope otherwise (even inside the body of the // object / type / interface declaring them). An exception is type parameters, // which are in scope without qualification (similar to 'locals'). return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 225 /* FunctionDeclaration */: case 184 /* FunctionExpression */: case 185 /* ArrowFunction */: case 274 /* JSDocFunctionType */: case 228 /* TypeAliasDeclaration */: case 170 /* MappedType */: // All the children of these container types are never visible through another // symbol (i.e. through another symbol's 'exports' or 'members'). Instead, // they're only accessed 'lexically' (i.e. from code that exists underneath // their container in the tree. To accomplish this, we simply add their declared // symbol to the 'locals' of the container. These symbols can then be found as // the type checker walks up the containers, checking them for matching names. return declareSymbol(container.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes); } }
(node, symbolFlags, symbolExcludes) { switch (container.kind) { // Modules, source files, and classes need specialized handling for how their // members are declared (for example, a member of a class will go into a specific // symbol table depending on if it is static or not). We defer to specialized // handlers to take care of declaring these child members. case 230 /* ModuleDeclaration */: return declareModuleMember(node, symbolFlags, symbolExcludes); case 261 /* SourceFile */: return declareSourceFileMember(node, symbolFlags, symbolExcludes); case 197 /* ClassExpression */: case 226 /* ClassDeclaration */: return declareClassMember(node, symbolFlags, symbolExcludes); case 229 /* EnumDeclaration */: return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); case 161 /* TypeLiteral */: case 176 /* ObjectLiteralExpression */: case 227 /* InterfaceDeclaration */: case 270 /* JSDocRecordType */: case 287 /* JSDocTypeLiteral */: // Interface/Object-types always have their children added to the 'members' of // their container. They are only accessible through an instance of their // container, and are never in scope otherwise (even inside the body of the // object / type / interface declaring them). An exception is type parameters, // which are in scope without qualification (similar to 'locals'). return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 225 /* FunctionDeclaration */: case 184 /* FunctionExpression */: case 185 /* ArrowFunction */: case 274 /* JSDocFunctionType */: case 228 /* TypeAliasDeclaration */: case 170 /* MappedType */: // All the children of these container types are never visible through another // symbol (i.e. through another symbol's 'exports' or 'members'). Instead, // they're only accessed 'lexically' (i.e. from code that exists underneath // their container in the tree. To accomplish this, we simply add their declared // symbol to the 'locals' of the container. These symbols can then be found as // the type checker walks up the containers, checking them for matching names. return declareSymbol(container.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes); } }
(node, symbolFlags, symbolExcludes) { switch (container.kind) { // Modules, source files, and classes need specialized handling for how their // members are declared (for example, a member of a class will go into a specific // symbol table depending on if it is static or not). We defer to specialized // handlers to take care of declaring these child members. case 230 /* ModuleDeclaration */: return declareModuleMember(node, symbolFlags, symbolExcludes); case 261 /* SourceFile */: return declareSourceFileMember(node, symbolFlags, symbolExcludes); case 197 /* ClassExpression */: case 226 /* ClassDeclaration */: return declareClassMember(node, symbolFlags, symbolExcludes); case 229 /* EnumDeclaration */: return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); case 161 /* TypeLiteral */: case 176 /* ObjectLiteralExpression */: case 227 /* InterfaceDeclaration */: case 270 /* JSDocRecordType */: case 287 /* JSDocTypeLiteral */: // Interface/Object-types always have their children added to the 'members' of // their container. They are only accessible through an instance of their // container, and are never in scope otherwise (even inside the body of the // object / type / interface declaring them). An exception is type parameters, // which are in scope without qualification (similar to 'locals'). return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 225 /* FunctionDeclaration */: case 184 /* FunctionExpression */: case 185 /* ArrowFunction */: case 274 /* JSDocFunctionType */: case 228 /* TypeAliasDeclaration */: case 170 /* MappedType */: // All the children of these container types are never visible through another // symbol (i.e. through another symbol's 'exports' or 'members'). Instead, // they're only accessed 'lexically' (i.e. from code that exists underneath // their container in the tree. To accomplish this, we simply add their declared // symbol to the 'locals' of the container. These symbols can then be found as // the type checker walks up the containers, checking them for matching names. return declareSymbol(container.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes); } }
(node, symbolFlags, symbolExcludes) { switch (container.kind) { // Modules, source files, and classes need specialized handling for how their // members are declared (for example, a member of a class will go into a specific // symbol table depending on if it is static or not). We defer to specialized // handlers to take care of declaring these child members. case 230 /* ModuleDeclaration */: return declareModuleMember(node, symbolFlags, symbolExcludes); case 261 /* SourceFile */: return declareSourceFileMember(node, symbolFlags, symbolExcludes); case 197 /* ClassExpression */: case 226 /* ClassDeclaration */: return declareClassMember(node, symbolFlags, symbolExcludes); case 229 /* EnumDeclaration */: return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); case 161 /* TypeLiteral */: case 176 /* ObjectLiteralExpression */: case 227 /* InterfaceDeclaration */: case 270 /* JSDocRecordType */: case 287 /* JSDocTypeLiteral */: // Interface/Object-types always have their children added to the 'members' of // their container. They are only accessible through an instance of their // container, and are never in scope otherwise (even inside the body of the // object / type / interface declaring them). An exception is type parameters, // which are in scope without qualification (similar to 'locals'). return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 225 /* FunctionDeclaration */: case 184 /* FunctionExpression */: case 185 /* ArrowFunction */: case 274 /* JSDocFunctionType */: case 228 /* TypeAliasDeclaration */: case 170 /* MappedType */: // All the children of these container types are never visible through another // symbol (i.e. through another symbol's 'exports' or 'members'). Instead, // they're only accessed 'lexically' (i.e. from code that exists underneath // their container in the tree. To accomplish this, we simply add their declared // symbol to the 'locals' of the container. These symbols can then be found as // the type checker walks up the containers, checking them for matching names. return declareSymbol(container.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes); } }
isObjectLiteralMethod:
(node) { return node && node.kind === 149 /* MethodDeclaration */ && node.parent.kind === 176 /* ObjectLiteralExpression */; }
Deopt: <JS Function bindWorker (SharedFunctionInfo 0x2142bdb5d081)> (opt #200) @110, FP to SP delta: 192, caller sp: 0x7fff5fbfd0d8
Deopt: <JS Function isExpression (SharedFunctionInfo 0x2c75c4ada041)> (opt #194) @4, FP to SP delta: 56, caller sp: 0x7fff5fbfd070
(node) { return node && node.kind === 149 /* MethodDeclaration */ && node.parent.kind === 176 /* ObjectLiteralExpression */; }
(node) { return node && node.kind === 149 /* MethodDeclaration */ && node.parent.kind === 176 /* ObjectLiteralExpression */; }
Deopt: <JS Function addDeclarationToSymbol (SharedFunctionInfo 0x2142bdb58c41)> (opt #269) @16, FP to SP delta: 64, caller sp: 0x7fff5fbfcc80
isExpressionKind:
(kind) { return kind === 193 /* ConditionalExpression */ || kind === 195 /* YieldExpression */ || kind === 185 /* ArrowFunction */ || kind === 192 /* BinaryExpression */ || kind === 196 /* SpreadElement */ || kind === 200 /* AsExpression */ || kind === 198 /* OmittedExpression */ || isUnaryExpressionKind(kind); }
bindParameter:
(node) { if (inStrictMode) { // It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a // strict mode FunctionLikeDeclaration or FunctionExpression(13.1) checkStrictModeEvalOrArguments(node, node.name); } if (ts.isBindingPattern(node.name)) { bindAnonymousDeclaration(node, 1 /* FunctionScopedVariable */, getDestructuringParameterName(node)); } else { declareSymbolAndAddToSymbolTable(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */); } // If this is a property-parameter, then also declare the property symbol into the // containing class. if (ts.isParameterPropertyDeclaration(node)) { var classDeclaration = node.parent.parent; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 0 /* PropertyExcludes */); } }
(node) { if (inStrictMode) { // It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a // strict mode FunctionLikeDeclaration or FunctionExpression(13.1) checkStrictModeEvalOrArguments(node, node.name); } if (ts.isBindingPattern(node.name)) { bindAnonymousDeclaration(node, 1 /* FunctionScopedVariable */, getDestructuringParameterName(node)); } else { declareSymbolAndAddToSymbolTable(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */); } // If this is a property-parameter, then also declare the property symbol into the // containing class. if (ts.isParameterPropertyDeclaration(node)) { var classDeclaration = node.parent.parent; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 0 /* PropertyExcludes */); } }
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 141 /* QualifiedName */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); case 143 /* TypeParameter */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.constraint) || visitNode(cbNode, node.expression); case 258 /* 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 259 /* SpreadAssignment */: return visitNode(cbNode, node.expression); case 144 /* Parameter */: case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: case 257 /* PropertyAssignment */: case 223 /* VariableDeclaration */: case 174 /* 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 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 184 /* FunctionExpression */: case 225 /* FunctionDeclaration */: case 185 /* 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 157 /* TypeReference */: return visitNode(cbNode, node.typeName) || visitNodes(cbNodes, node.typeArguments); case 156 /* TypePredicate */: return visitNode(cbNode, node.parameterName) || visitNode(cbNode, node.type); case 160 /* TypeQuery */: return visitNode(cbNode, node.exprName); case 161 /* TypeLiteral */: return visitNodes(cbNodes, node.members); case 162 /* ArrayType */: return visitNode(cbNode, node.elementType); case 163 /* TupleType */: return visitNodes(cbNodes, node.elementTypes); case 164 /* UnionType */: case 165 /* IntersectionType */: return visitNodes(cbNodes, node.types); case 166 /* ParenthesizedType */: case 168 /* TypeOperator */: return visitNode(cbNode, node.type); case 169 /* IndexedAccessType */: return visitNode(cbNode, node.objectType) || visitNode(cbNode, node.indexType); case 170 /* MappedType */: return visitNode(cbNode, node.readonlyToken) || visitNode(cbNode, node.typeParameter) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.type); case 171 /* LiteralType */: return visitNode(cbNode, node.literal); case 172 /* ObjectBindingPattern */: case 173 /* ArrayBindingPattern */: return visitNodes(cbNodes, node.elements); case 175 /* ArrayLiteralExpression */: return visitNodes(cbNodes, node.elements); case 176 /* ObjectLiteralExpression */: return visitNodes(cbNodes, node.properties); case 177 /* PropertyAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.name); case 178 /* ElementAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); case 179 /* CallExpression */: case 180 /* NewExpression */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); case 181 /* TaggedTemplateExpression */: return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); case 182 /* TypeAssertionExpression */: return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); case 183 /* ParenthesizedExpression */: return visitNode(cbNode, node.expression); case 186 /* DeleteExpression */: return visitNode(cbNode, node.expression); case 187 /* TypeOfExpression */: return visitNode(cbNode, node.expression); case 188 /* VoidExpression */: return visitNode(cbNode, node.expression); case 190 /* PrefixUnaryExpression */: return visitNode(cbNode, node.operand); case 195 /* YieldExpression */: return visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.expression); case 189 /* AwaitExpression */: return visitNode(cbNode, node.expression); case 191 /* PostfixUnaryExpression */: return visitNode(cbNode, node.operand); case 192 /* BinaryExpression */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.operatorToken) || visitNode(cbNode, node.right); case 200 /* AsExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.type); case 201 /* NonNullExpression */: return visitNode(cbNode, node.expression); case 193 /* ConditionalExpression */: return visitNode(cbNode, node.condition) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.colonToken) || visitNode(cbNode, node.whenFalse); case 196 /* SpreadElement */: return visitNode(cbNode, node.expression); case 204 /* Block */: case 231 /* ModuleBlock */: return visitNodes(cbNodes, node.statements); case 261 /* SourceFile */: return visitNodes(cbNodes, node.statements) || visitNode(cbNode, node.endOfFileToken); case 205 /* VariableStatement */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.declarationList); case 224 /* VariableDeclarationList */: return visitNodes(cbNodes, node.declarations); case 207 /* ExpressionStatement */: return visitNode(cbNode, node.expression); case 208 /* IfStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.thenStatement) || visitNode(cbNode, node.elseStatement); case 209 /* DoStatement */: return visitNode(cbNode, node.statement) || visitNode(cbNode, node.expression); case 210 /* WhileStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 211 /* ForStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.condition) || visitNode(cbNode, node.incrementor) || visitNode(cbNode, node.statement); case 212 /* ForInStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 213 /* ForOfStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 214 /* ContinueStatement */: case 215 /* BreakStatement */: return visitNode(cbNode, node.label); case 216 /* ReturnStatement */: return visitNode(cbNode, node.expression); case 217 /* WithStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 218 /* SwitchStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.caseBlock); case 232 /* CaseBlock */: return visitNodes(cbNodes, node.clauses); case 253 /* CaseClause */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.statements); case 254 /* DefaultClause */: return visitNodes(cbNodes, node.statements); case 219 /* LabeledStatement */: return visitNode(cbNode, node.label) || visitNode(cbNode, node.statement); case 220 /* ThrowStatement */: return visitNode(cbNode, node.expression); case 221 /* TryStatement */: return visitNode(cbNode, node.tryBlock) || visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); case 256 /* CatchClause */: return visitNode(cbNode, node.variableDeclaration) || visitNode(cbNode, node.block); case 145 /* Decorator */: return visitNode(cbNode, node.expression); case 226 /* ClassDeclaration */: case 197 /* 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 227 /* 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 228 /* TypeAliasDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNode(cbNode, node.type); case 229 /* EnumDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.members); case 260 /* EnumMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 230 /* ModuleDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.body); case 234 /* ImportEqualsDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.moduleReference); case 235 /* ImportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.importClause) || visitNode(cbNode, node.moduleSpecifier); case 236 /* ImportClause */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.namedBindings); case 233 /* NamespaceExportDeclaration */: return visitNode(cbNode, node.name); case 237 /* NamespaceImport */: return visitNode(cbNode, node.name); case 238 /* NamedImports */: case 242 /* NamedExports */: return visitNodes(cbNodes, node.elements); case 241 /* ExportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.exportClause) || visitNode(cbNode, node.moduleSpecifier); case 239 /* ImportSpecifier */: case 243 /* ExportSpecifier */: return visitNode(cbNode, node.propertyName) || visitNode(cbNode, node.name); case 240 /* ExportAssignment */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.expression); case 194 /* TemplateExpression */: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); case 202 /* TemplateSpan */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal); case 142 /* ComputedPropertyName */: return visitNode(cbNode, node.expression); case 255 /* HeritageClause */: return visitNodes(cbNodes, node.types); case 199 /* ExpressionWithTypeArguments */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments); case 245 /* ExternalModuleReference */: return visitNode(cbNode, node.expression); case 244 /* MissingDeclaration */: return visitNodes(cbNodes, node.decorators); case 246 /* JsxElement */: return visitNode(cbNode, node.openingElement) || visitNodes(cbNodes, node.children) || visitNode(cbNode, node.closingElement); case 247 /* JsxSelfClosingElement */: case 248 /* JsxOpeningElement */: return visitNode(cbNode, node.tagName) || visitNodes(cbNodes, node.attributes); case 250 /* JsxAttribute */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 251 /* JsxSpreadAttribute */: return visitNode(cbNode, node.expression); case 252 /* JsxExpression */: return visitNode(cbNode, node.expression); case 249 /* JsxClosingElement */: return visitNode(cbNode, node.tagName); case 262 /* JSDocTypeExpression */: return visitNode(cbNode, node.type); case 266 /* JSDocUnionType */: return visitNodes(cbNodes, node.types); case 267 /* JSDocTupleType */: return visitNodes(cbNodes, node.types); case 265 /* JSDocArrayType */: return visitNode(cbNode, node.elementType); case 269 /* JSDocNonNullableType */: return visitNode(cbNode, node.type); case 268 /* JSDocNullableType */: return visitNode(cbNode, node.type); case 270 /* JSDocRecordType */: return visitNode(cbNode, node.literal); case 272 /* JSDocTypeReference */: return visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeArguments); case 273 /* JSDocOptionalType */: return visitNode(cbNode, node.type); case 274 /* JSDocFunctionType */: return visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 275 /* JSDocVariadicType */: return visitNode(cbNode, node.type); case 276 /* JSDocConstructorType */: return visitNode(cbNode, node.type); case 277 /* JSDocThisType */: return visitNode(cbNode, node.type); case 271 /* JSDocRecordMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.type); case 278 /* JSDocComment */: return visitNodes(cbNodes, node.tags); case 281 /* JSDocParameterTag */: return visitNode(cbNode, node.preParameterName) || visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.postParameterName); case 282 /* JSDocReturnTag */: return visitNode(cbNode, node.typeExpression); case 283 /* JSDocTypeTag */: return visitNode(cbNode, node.typeExpression); case 280 /* JSDocAugmentsTag */: return visitNode(cbNode, node.typeExpression); case 284 /* JSDocTemplateTag */: return visitNodes(cbNodes, node.typeParameters); case 285 /* JSDocTypedefTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.fullName) || visitNode(cbNode, node.name) || visitNode(cbNode, node.jsDocTypeLiteral); case 287 /* JSDocTypeLiteral */: return visitNodes(cbNodes, node.jsDocPropertyTags); case 286 /* JSDocPropertyTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.name); case 294 /* PartiallyEmittedExpression */: return visitNode(cbNode, node.expression); case 288 /* JSDocLiteralType */: return visitNode(cbNode, node.literal); } }
(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 141 /* QualifiedName */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); case 143 /* TypeParameter */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.constraint) || visitNode(cbNode, node.expression); case 258 /* 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 259 /* SpreadAssignment */: return visitNode(cbNode, node.expression); case 144 /* Parameter */: case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: case 257 /* PropertyAssignment */: case 223 /* VariableDeclaration */: case 174 /* 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 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 184 /* FunctionExpression */: case 225 /* FunctionDeclaration */: case 185 /* 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 157 /* TypeReference */: return visitNode(cbNode, node.typeName) || visitNodes(cbNodes, node.typeArguments); case 156 /* TypePredicate */: return visitNode(cbNode, node.parameterName) || visitNode(cbNode, node.type); case 160 /* TypeQuery */: return visitNode(cbNode, node.exprName); case 161 /* TypeLiteral */: return visitNodes(cbNodes, node.members); case 162 /* ArrayType */: return visitNode(cbNode, node.elementType); case 163 /* TupleType */: return visitNodes(cbNodes, node.elementTypes); case 164 /* UnionType */: case 165 /* IntersectionType */: return visitNodes(cbNodes, node.types); case 166 /* ParenthesizedType */: case 168 /* TypeOperator */: return visitNode(cbNode, node.type); case 169 /* IndexedAccessType */: return visitNode(cbNode, node.objectType) || visitNode(cbNode, node.indexType); case 170 /* MappedType */: return visitNode(cbNode, node.readonlyToken) || visitNode(cbNode, node.typeParameter) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.type); case 171 /* LiteralType */: return visitNode(cbNode, node.literal); case 172 /* ObjectBindingPattern */: case 173 /* ArrayBindingPattern */: return visitNodes(cbNodes, node.elements); case 175 /* ArrayLiteralExpression */: return visitNodes(cbNodes, node.elements); case 176 /* ObjectLiteralExpression */: return visitNodes(cbNodes, node.properties); case 177 /* PropertyAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.name); case 178 /* ElementAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); case 179 /* CallExpression */: case 180 /* NewExpression */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); case 181 /* TaggedTemplateExpression */: return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); case 182 /* TypeAssertionExpression */: return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); case 183 /* ParenthesizedExpression */: return visitNode(cbNode, node.expression); case 186 /* DeleteExpression */: return visitNode(cbNode, node.expression); case 187 /* TypeOfExpression */: return visitNode(cbNode, node.expression); case 188 /* VoidExpression */: return visitNode(cbNode, node.expression); case 190 /* PrefixUnaryExpression */: return visitNode(cbNode, node.operand); case 195 /* YieldExpression */: return visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.expression); case 189 /* AwaitExpression */: return visitNode(cbNode, node.expression); case 191 /* PostfixUnaryExpression */: return visitNode(cbNode, node.operand); case 192 /* BinaryExpression */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.operatorToken) || visitNode(cbNode, node.right); case 200 /* AsExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.type); case 201 /* NonNullExpression */: return visitNode(cbNode, node.expression); case 193 /* ConditionalExpression */: return visitNode(cbNode, node.condition) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.colonToken) || visitNode(cbNode, node.whenFalse); case 196 /* SpreadElement */: return visitNode(cbNode, node.expression); case 204 /* Block */: case 231 /* ModuleBlock */: return visitNodes(cbNodes, node.statements); case 261 /* SourceFile */: return visitNodes(cbNodes, node.statements) || visitNode(cbNode, node.endOfFileToken); case 205 /* VariableStatement */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.declarationList); case 224 /* VariableDeclarationList */: return visitNodes(cbNodes, node.declarations); case 207 /* ExpressionStatement */: return visitNode(cbNode, node.expression); case 208 /* IfStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.thenStatement) || visitNode(cbNode, node.elseStatement); case 209 /* DoStatement */: return visitNode(cbNode, node.statement) || visitNode(cbNode, node.expression); case 210 /* WhileStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 211 /* ForStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.condition) || visitNode(cbNode, node.incrementor) || visitNode(cbNode, node.statement); case 212 /* ForInStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 213 /* ForOfStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 214 /* ContinueStatement */: case 215 /* BreakStatement */: return visitNode(cbNode, node.label); case 216 /* ReturnStatement */: return visitNode(cbNode, node.expression); case 217 /* WithStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 218 /* SwitchStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.caseBlock); case 232 /* CaseBlock */: return visitNodes(cbNodes, node.clauses); case 253 /* CaseClause */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.statements); case 254 /* DefaultClause */: return visitNodes(cbNodes, node.statements); case 219 /* LabeledStatement */: return visitNode(cbNode, node.label) || visitNode(cbNode, node.statement); case 220 /* ThrowStatement */: return visitNode(cbNode, node.expression); case 221 /* TryStatement */: return visitNode(cbNode, node.tryBlock) || visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); case 256 /* CatchClause */: return visitNode(cbNode, node.variableDeclaration) || visitNode(cbNode, node.block); case 145 /* Decorator */: return visitNode(cbNode, node.expression); case 226 /* ClassDeclaration */: case 197 /* 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 227 /* 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 228 /* TypeAliasDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNode(cbNode, node.type); case 229 /* EnumDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.members); case 260 /* EnumMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 230 /* ModuleDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.body); case 234 /* ImportEqualsDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.moduleReference); case 235 /* ImportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.importClause) || visitNode(cbNode, node.moduleSpecifier); case 236 /* ImportClause */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.namedBindings); case 233 /* NamespaceExportDeclaration */: return visitNode(cbNode, node.name); case 237 /* NamespaceImport */: return visitNode(cbNode, node.name); case 238 /* NamedImports */: case 242 /* NamedExports */: return visitNodes(cbNodes, node.elements); case 241 /* ExportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.exportClause) || visitNode(cbNode, node.moduleSpecifier); case 239 /* ImportSpecifier */: case 243 /* ExportSpecifier */: return visitNode(cbNode, node.propertyName) || visitNode(cbNode, node.name); case 240 /* ExportAssignment */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.expression); case 194 /* TemplateExpression */: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); case 202 /* TemplateSpan */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal); case 142 /* ComputedPropertyName */: return visitNode(cbNode, node.expression); case 255 /* HeritageClause */: return visitNodes(cbNodes, node.types); case 199 /* ExpressionWithTypeArguments */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments); case 245 /* ExternalModuleReference */: return visitNode(cbNode, node.expression); case 244 /* MissingDeclaration */: return visitNodes(cbNodes, node.decorators); case 246 /* JsxElement */: return visitNode(cbNode, node.openingElement) || visitNodes(cbNodes, node.children) || visitNode(cbNode, node.closingElement); case 247 /* JsxSelfClosingElement */: case 248 /* JsxOpeningElement */: return visitNode(cbNode, node.tagName) || visitNodes(cbNodes, node.attributes); case 250 /* JsxAttribute */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 251 /* JsxSpreadAttribute */: return visitNode(cbNode, node.expression); case 252 /* JsxExpression */: return visitNode(cbNode, node.expression); case 249 /* JsxClosingElement */: return visitNode(cbNode, node.tagName); case 262 /* JSDocTypeExpression */: return visitNode(cbNode, node.type); case 266 /* JSDocUnionType */: return visitNodes(cbNodes, node.types); case 267 /* JSDocTupleType */: return visitNodes(cbNodes, node.types); case 265 /* JSDocArrayType */: return visitNode(cbNode, node.elementType); case 269 /* JSDocNonNullableType */: return visitNode(cbNode, node.type); case 268 /* JSDocNullableType */: return visitNode(cbNode, node.type); case 270 /* JSDocRecordType */: return visitNode(cbNode, node.literal); case 272 /* JSDocTypeReference */: return visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeArguments); case 273 /* JSDocOptionalType */: return visitNode(cbNode, node.type); case 274 /* JSDocFunctionType */: return visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 275 /* JSDocVariadicType */: return visitNode(cbNode, node.type); case 276 /* JSDocConstructorType */: return visitNode(cbNode, node.type); case 277 /* JSDocThisType */: return visitNode(cbNode, node.type); case 271 /* JSDocRecordMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.type); case 278 /* JSDocComment */: return visitNodes(cbNodes, node.tags); case 281 /* JSDocParameterTag */: return visitNode(cbNode, node.preParameterName) || visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.postParameterName); case 282 /* JSDocReturnTag */: return visitNode(cbNode, node.typeExpression); case 283 /* JSDocTypeTag */: return visitNode(cbNode, node.typeExpression); case 280 /* JSDocAugmentsTag */: return visitNode(cbNode, node.typeExpression); case 284 /* JSDocTemplateTag */: return visitNodes(cbNodes, node.typeParameters); case 285 /* JSDocTypedefTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.fullName) || visitNode(cbNode, node.name) || visitNode(cbNode, node.jsDocTypeLiteral); case 287 /* JSDocTypeLiteral */: return visitNodes(cbNodes, node.jsDocPropertyTags); case 286 /* JSDocPropertyTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.name); case 294 /* PartiallyEmittedExpression */: return visitNode(cbNode, node.expression); case 288 /* JSDocLiteralType */: return visitNode(cbNode, node.literal); } }
(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 141 /* QualifiedName */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); case 143 /* TypeParameter */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.constraint) || visitNode(cbNode, node.expression); case 258 /* 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 259 /* SpreadAssignment */: return visitNode(cbNode, node.expression); case 144 /* Parameter */: case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: case 257 /* PropertyAssignment */: case 223 /* VariableDeclaration */: case 174 /* 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 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 184 /* FunctionExpression */: case 225 /* FunctionDeclaration */: case 185 /* 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 157 /* TypeReference */: return visitNode(cbNode, node.typeName) || visitNodes(cbNodes, node.typeArguments); case 156 /* TypePredicate */: return visitNode(cbNode, node.parameterName) || visitNode(cbNode, node.type); case 160 /* TypeQuery */: return visitNode(cbNode, node.exprName); case 161 /* TypeLiteral */: return visitNodes(cbNodes, node.members); case 162 /* ArrayType */: return visitNode(cbNode, node.elementType); case 163 /* TupleType */: return visitNodes(cbNodes, node.elementTypes); case 164 /* UnionType */: case 165 /* IntersectionType */: return visitNodes(cbNodes, node.types); case 166 /* ParenthesizedType */: case 168 /* TypeOperator */: return visitNode(cbNode, node.type); case 169 /* IndexedAccessType */: return visitNode(cbNode, node.objectType) || visitNode(cbNode, node.indexType); case 170 /* MappedType */: return visitNode(cbNode, node.readonlyToken) || visitNode(cbNode, node.typeParameter) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.type); case 171 /* LiteralType */: return visitNode(cbNode, node.literal); case 172 /* ObjectBindingPattern */: case 173 /* ArrayBindingPattern */: return visitNodes(cbNodes, node.elements); case 175 /* ArrayLiteralExpression */: return visitNodes(cbNodes, node.elements); case 176 /* ObjectLiteralExpression */: return visitNodes(cbNodes, node.properties); case 177 /* PropertyAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.name); case 178 /* ElementAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); case 179 /* CallExpression */: case 180 /* NewExpression */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); case 181 /* TaggedTemplateExpression */: return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); case 182 /* TypeAssertionExpression */: return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); case 183 /* ParenthesizedExpression */: return visitNode(cbNode, node.expression); case 186 /* DeleteExpression */: return visitNode(cbNode, node.expression); case 187 /* TypeOfExpression */: return visitNode(cbNode, node.expression); case 188 /* VoidExpression */: return visitNode(cbNode, node.expression); case 190 /* PrefixUnaryExpression */: return visitNode(cbNode, node.operand); case 195 /* YieldExpression */: return visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.expression); case 189 /* AwaitExpression */: return visitNode(cbNode, node.expression); case 191 /* PostfixUnaryExpression */: return visitNode(cbNode, node.operand); case 192 /* BinaryExpression */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.operatorToken) || visitNode(cbNode, node.right); case 200 /* AsExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.type); case 201 /* NonNullExpression */: return visitNode(cbNode, node.expression); case 193 /* ConditionalExpression */: return visitNode(cbNode, node.condition) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.colonToken) || visitNode(cbNode, node.whenFalse); case 196 /* SpreadElement */: return visitNode(cbNode, node.expression); case 204 /* Block */: case 231 /* ModuleBlock */: return visitNodes(cbNodes, node.statements); case 261 /* SourceFile */: return visitNodes(cbNodes, node.statements) || visitNode(cbNode, node.endOfFileToken); case 205 /* VariableStatement */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.declarationList); case 224 /* VariableDeclarationList */: return visitNodes(cbNodes, node.declarations); case 207 /* ExpressionStatement */: return visitNode(cbNode, node.expression); case 208 /* IfStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.thenStatement) || visitNode(cbNode, node.elseStatement); case 209 /* DoStatement */: return visitNode(cbNode, node.statement) || visitNode(cbNode, node.expression); case 210 /* WhileStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 211 /* ForStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.condition) || visitNode(cbNode, node.incrementor) || visitNode(cbNode, node.statement); case 212 /* ForInStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 213 /* ForOfStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 214 /* ContinueStatement */: case 215 /* BreakStatement */: return visitNode(cbNode, node.label); case 216 /* ReturnStatement */: return visitNode(cbNode, node.expression); case 217 /* WithStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 218 /* SwitchStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.caseBlock); case 232 /* CaseBlock */: return visitNodes(cbNodes, node.clauses); case 253 /* CaseClause */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.statements); case 254 /* DefaultClause */: return visitNodes(cbNodes, node.statements); case 219 /* LabeledStatement */: return visitNode(cbNode, node.label) || visitNode(cbNode, node.statement); case 220 /* ThrowStatement */: return visitNode(cbNode, node.expression); case 221 /* TryStatement */: return visitNode(cbNode, node.tryBlock) || visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); case 256 /* CatchClause */: return visitNode(cbNode, node.variableDeclaration) || visitNode(cbNode, node.block); case 145 /* Decorator */: return visitNode(cbNode, node.expression); case 226 /* ClassDeclaration */: case 197 /* 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 227 /* 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 228 /* TypeAliasDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNode(cbNode, node.type); case 229 /* EnumDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.members); case 260 /* EnumMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 230 /* ModuleDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.body); case 234 /* ImportEqualsDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.moduleReference); case 235 /* ImportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.importClause) || visitNode(cbNode, node.moduleSpecifier); case 236 /* ImportClause */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.namedBindings); case 233 /* NamespaceExportDeclaration */: return visitNode(cbNode, node.name); case 237 /* NamespaceImport */: return visitNode(cbNode, node.name); case 238 /* NamedImports */: case 242 /* NamedExports */: return visitNodes(cbNodes, node.elements); case 241 /* ExportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.exportClause) || visitNode(cbNode, node.moduleSpecifier); case 239 /* ImportSpecifier */: case 243 /* ExportSpecifier */: return visitNode(cbNode, node.propertyName) || visitNode(cbNode, node.name); case 240 /* ExportAssignment */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.expression); case 194 /* TemplateExpression */: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); case 202 /* TemplateSpan */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal); case 142 /* ComputedPropertyName */: return visitNode(cbNode, node.expression); case 255 /* HeritageClause */: return visitNodes(cbNodes, node.types); case 199 /* ExpressionWithTypeArguments */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments); case 245 /* ExternalModuleReference */: return visitNode(cbNode, node.expression); case 244 /* MissingDeclaration */: return visitNodes(cbNodes, node.decorators); case 246 /* JsxElement */: return visitNode(cbNode, node.openingElement) || visitNodes(cbNodes, node.children) || visitNode(cbNode, node.closingElement); case 247 /* JsxSelfClosingElement */: case 248 /* JsxOpeningElement */: return visitNode(cbNode, node.tagName) || visitNodes(cbNodes, node.attributes); case 250 /* JsxAttribute */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 251 /* JsxSpreadAttribute */: return visitNode(cbNode, node.expression); case 252 /* JsxExpression */: return visitNode(cbNode, node.expression); case 249 /* JsxClosingElement */: return visitNode(cbNode, node.tagName); case 262 /* JSDocTypeExpression */: return visitNode(cbNode, node.type); case 266 /* JSDocUnionType */: return visitNodes(cbNodes, node.types); case 267 /* JSDocTupleType */: return visitNodes(cbNodes, node.types); case 265 /* JSDocArrayType */: return visitNode(cbNode, node.elementType); case 269 /* JSDocNonNullableType */: return visitNode(cbNode, node.type); case 268 /* JSDocNullableType */: return visitNode(cbNode, node.type); case 270 /* JSDocRecordType */: return visitNode(cbNode, node.literal); case 272 /* JSDocTypeReference */: return visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeArguments); case 273 /* JSDocOptionalType */: return visitNode(cbNode, node.type); case 274 /* JSDocFunctionType */: return visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 275 /* JSDocVariadicType */: return visitNode(cbNode, node.type); case 276 /* JSDocConstructorType */: return visitNode(cbNode, node.type); case 277 /* JSDocThisType */: return visitNode(cbNode, node.type); case 271 /* JSDocRecordMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.type); case 278 /* JSDocComment */: return visitNodes(cbNodes, node.tags); case 281 /* JSDocParameterTag */: return visitNode(cbNode, node.preParameterName) || visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.postParameterName); case 282 /* JSDocReturnTag */: return visitNode(cbNode, node.typeExpression); case 283 /* JSDocTypeTag */: return visitNode(cbNode, node.typeExpression); case 280 /* JSDocAugmentsTag */: return visitNode(cbNode, node.typeExpression); case 284 /* JSDocTemplateTag */: return visitNodes(cbNodes, node.typeParameters); case 285 /* JSDocTypedefTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.fullName) || visitNode(cbNode, node.name) || visitNode(cbNode, node.jsDocTypeLiteral); case 287 /* JSDocTypeLiteral */: return visitNodes(cbNodes, node.jsDocPropertyTags); case 286 /* JSDocPropertyTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.name); case 294 /* PartiallyEmittedExpression */: return visitNode(cbNode, node.expression); case 288 /* JSDocLiteralType */: return visitNode(cbNode, node.literal); } }
(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 141 /* QualifiedName */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); case 143 /* TypeParameter */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.constraint) || visitNode(cbNode, node.expression); case 258 /* 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 259 /* SpreadAssignment */: return visitNode(cbNode, node.expression); case 144 /* Parameter */: case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: case 257 /* PropertyAssignment */: case 223 /* VariableDeclaration */: case 174 /* 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 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 184 /* FunctionExpression */: case 225 /* FunctionDeclaration */: case 185 /* 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 157 /* TypeReference */: return visitNode(cbNode, node.typeName) || visitNodes(cbNodes, node.typeArguments); case 156 /* TypePredicate */: return visitNode(cbNode, node.parameterName) || visitNode(cbNode, node.type); case 160 /* TypeQuery */: return visitNode(cbNode, node.exprName); case 161 /* TypeLiteral */: return visitNodes(cbNodes, node.members); case 162 /* ArrayType */: return visitNode(cbNode, node.elementType); case 163 /* TupleType */: return visitNodes(cbNodes, node.elementTypes); case 164 /* UnionType */: case 165 /* IntersectionType */: return visitNodes(cbNodes, node.types); case 166 /* ParenthesizedType */: case 168 /* TypeOperator */: return visitNode(cbNode, node.type); case 169 /* IndexedAccessType */: return visitNode(cbNode, node.objectType) || visitNode(cbNode, node.indexType); case 170 /* MappedType */: return visitNode(cbNode, node.readonlyToken) || visitNode(cbNode, node.typeParameter) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.type); case 171 /* LiteralType */: return visitNode(cbNode, node.literal); case 172 /* ObjectBindingPattern */: case 173 /* ArrayBindingPattern */: return visitNodes(cbNodes, node.elements); case 175 /* ArrayLiteralExpression */: return visitNodes(cbNodes, node.elements); case 176 /* ObjectLiteralExpression */: return visitNodes(cbNodes, node.properties); case 177 /* PropertyAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.name); case 178 /* ElementAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); case 179 /* CallExpression */: case 180 /* NewExpression */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); case 181 /* TaggedTemplateExpression */: return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); case 182 /* TypeAssertionExpression */: return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); case 183 /* ParenthesizedExpression */: return visitNode(cbNode, node.expression); case 186 /* DeleteExpression */: return visitNode(cbNode, node.expression); case 187 /* TypeOfExpression */: return visitNode(cbNode, node.expression); case 188 /* VoidExpression */: return visitNode(cbNode, node.expression); case 190 /* PrefixUnaryExpression */: return visitNode(cbNode, node.operand); case 195 /* YieldExpression */: return visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.expression); case 189 /* AwaitExpression */: return visitNode(cbNode, node.expression); case 191 /* PostfixUnaryExpression */: return visitNode(cbNode, node.operand); case 192 /* BinaryExpression */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.operatorToken) || visitNode(cbNode, node.right); case 200 /* AsExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.type); case 201 /* NonNullExpression */: return visitNode(cbNode, node.expression); case 193 /* ConditionalExpression */: return visitNode(cbNode, node.condition) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.colonToken) || visitNode(cbNode, node.whenFalse); case 196 /* SpreadElement */: return visitNode(cbNode, node.expression); case 204 /* Block */: case 231 /* ModuleBlock */: return visitNodes(cbNodes, node.statements); case 261 /* SourceFile */: return visitNodes(cbNodes, node.statements) || visitNode(cbNode, node.endOfFileToken); case 205 /* VariableStatement */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.declarationList); case 224 /* VariableDeclarationList */: return visitNodes(cbNodes, node.declarations); case 207 /* ExpressionStatement */: return visitNode(cbNode, node.expression); case 208 /* IfStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.thenStatement) || visitNode(cbNode, node.elseStatement); case 209 /* DoStatement */: return visitNode(cbNode, node.statement) || visitNode(cbNode, node.expression); case 210 /* WhileStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 211 /* ForStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.condition) || visitNode(cbNode, node.incrementor) || visitNode(cbNode, node.statement); case 212 /* ForInStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 213 /* ForOfStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 214 /* ContinueStatement */: case 215 /* BreakStatement */: return visitNode(cbNode, node.label); case 216 /* ReturnStatement */: return visitNode(cbNode, node.expression); case 217 /* WithStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 218 /* SwitchStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.caseBlock); case 232 /* CaseBlock */: return visitNodes(cbNodes, node.clauses); case 253 /* CaseClause */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.statements); case 254 /* DefaultClause */: return visitNodes(cbNodes, node.statements); case 219 /* LabeledStatement */: return visitNode(cbNode, node.label) || visitNode(cbNode, node.statement); case 220 /* ThrowStatement */: return visitNode(cbNode, node.expression); case 221 /* TryStatement */: return visitNode(cbNode, node.tryBlock) || visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); case 256 /* CatchClause */: return visitNode(cbNode, node.variableDeclaration) || visitNode(cbNode, node.block); case 145 /* Decorator */: return visitNode(cbNode, node.expression); case 226 /* ClassDeclaration */: case 197 /* 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 227 /* 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 228 /* TypeAliasDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNode(cbNode, node.type); case 229 /* EnumDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.members); case 260 /* EnumMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 230 /* ModuleDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.body); case 234 /* ImportEqualsDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.moduleReference); case 235 /* ImportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.importClause) || visitNode(cbNode, node.moduleSpecifier); case 236 /* ImportClause */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.namedBindings); case 233 /* NamespaceExportDeclaration */: return visitNode(cbNode, node.name); case 237 /* NamespaceImport */: return visitNode(cbNode, node.name); case 238 /* NamedImports */: case 242 /* NamedExports */: return visitNodes(cbNodes, node.elements); case 241 /* ExportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.exportClause) || visitNode(cbNode, node.moduleSpecifier); case 239 /* ImportSpecifier */: case 243 /* ExportSpecifier */: return visitNode(cbNode, node.propertyName) || visitNode(cbNode, node.name); case 240 /* ExportAssignment */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.expression); case 194 /* TemplateExpression */: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); case 202 /* TemplateSpan */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal); case 142 /* ComputedPropertyName */: return visitNode(cbNode, node.expression); case 255 /* HeritageClause */: return visitNodes(cbNodes, node.types); case 199 /* ExpressionWithTypeArguments */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments); case 245 /* ExternalModuleReference */: return visitNode(cbNode, node.expression); case 244 /* MissingDeclaration */: return visitNodes(cbNodes, node.decorators); case 246 /* JsxElement */: return visitNode(cbNode, node.openingElement) || visitNodes(cbNodes, node.children) || visitNode(cbNode, node.closingElement); case 247 /* JsxSelfClosingElement */: case 248 /* JsxOpeningElement */: return visitNode(cbNode, node.tagName) || visitNodes(cbNodes, node.attributes); case 250 /* JsxAttribute */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 251 /* JsxSpreadAttribute */: return visitNode(cbNode, node.expression); case 252 /* JsxExpression */: return visitNode(cbNode, node.expression); case 249 /* JsxClosingElement */: return visitNode(cbNode, node.tagName); case 262 /* JSDocTypeExpression */: return visitNode(cbNode, node.type); case 266 /* JSDocUnionType */: return visitNodes(cbNodes, node.types); case 267 /* JSDocTupleType */: return visitNodes(cbNodes, node.types); case 265 /* JSDocArrayType */: return visitNode(cbNode, node.elementType); case 269 /* JSDocNonNullableType */: return visitNode(cbNode, node.type); case 268 /* JSDocNullableType */: return visitNode(cbNode, node.type); case 270 /* JSDocRecordType */: return visitNode(cbNode, node.literal); case 272 /* JSDocTypeReference */: return visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeArguments); case 273 /* JSDocOptionalType */: return visitNode(cbNode, node.type); case 274 /* JSDocFunctionType */: return visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 275 /* JSDocVariadicType */: return visitNode(cbNode, node.type); case 276 /* JSDocConstructorType */: return visitNode(cbNode, node.type); case 277 /* JSDocThisType */: return visitNode(cbNode, node.type); case 271 /* JSDocRecordMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.type); case 278 /* JSDocComment */: return visitNodes(cbNodes, node.tags); case 281 /* JSDocParameterTag */: return visitNode(cbNode, node.preParameterName) || visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.postParameterName); case 282 /* JSDocReturnTag */: return visitNode(cbNode, node.typeExpression); case 283 /* JSDocTypeTag */: return visitNode(cbNode, node.typeExpression); case 280 /* JSDocAugmentsTag */: return visitNode(cbNode, node.typeExpression); case 284 /* JSDocTemplateTag */: return visitNodes(cbNodes, node.typeParameters); case 285 /* JSDocTypedefTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.fullName) || visitNode(cbNode, node.name) || visitNode(cbNode, node.jsDocTypeLiteral); case 287 /* JSDocTypeLiteral */: return visitNodes(cbNodes, node.jsDocPropertyTags); case 286 /* JSDocPropertyTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.name); case 294 /* PartiallyEmittedExpression */: return visitNode(cbNode, node.expression); case 288 /* JSDocLiteralType */: return visitNode(cbNode, node.literal); } }
(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 141 /* QualifiedName */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); case 143 /* TypeParameter */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.constraint) || visitNode(cbNode, node.expression); case 258 /* 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 259 /* SpreadAssignment */: return visitNode(cbNode, node.expression); case 144 /* Parameter */: case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: case 257 /* PropertyAssignment */: case 223 /* VariableDeclaration */: case 174 /* 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 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 184 /* FunctionExpression */: case 225 /* FunctionDeclaration */: case 185 /* 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 157 /* TypeReference */: return visitNode(cbNode, node.typeName) || visitNodes(cbNodes, node.typeArguments); case 156 /* TypePredicate */: return visitNode(cbNode, node.parameterName) || visitNode(cbNode, node.type); case 160 /* TypeQuery */: return visitNode(cbNode, node.exprName); case 161 /* TypeLiteral */: return visitNodes(cbNodes, node.members); case 162 /* ArrayType */: return visitNode(cbNode, node.elementType); case 163 /* TupleType */: return visitNodes(cbNodes, node.elementTypes); case 164 /* UnionType */: case 165 /* IntersectionType */: return visitNodes(cbNodes, node.types); case 166 /* ParenthesizedType */: case 168 /* TypeOperator */: return visitNode(cbNode, node.type); case 169 /* IndexedAccessType */: return visitNode(cbNode, node.objectType) || visitNode(cbNode, node.indexType); case 170 /* MappedType */: return visitNode(cbNode, node.readonlyToken) || visitNode(cbNode, node.typeParameter) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.type); case 171 /* LiteralType */: return visitNode(cbNode, node.literal); case 172 /* ObjectBindingPattern */: case 173 /* ArrayBindingPattern */: return visitNodes(cbNodes, node.elements); case 175 /* ArrayLiteralExpression */: return visitNodes(cbNodes, node.elements); case 176 /* ObjectLiteralExpression */: return visitNodes(cbNodes, node.properties); case 177 /* PropertyAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.name); case 178 /* ElementAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); case 179 /* CallExpression */: case 180 /* NewExpression */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); case 181 /* TaggedTemplateExpression */: return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); case 182 /* TypeAssertionExpression */: return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); case 183 /* ParenthesizedExpression */: return visitNode(cbNode, node.expression); case 186 /* DeleteExpression */: return visitNode(cbNode, node.expression); case 187 /* TypeOfExpression */: return visitNode(cbNode, node.expression); case 188 /* VoidExpression */: return visitNode(cbNode, node.expression); case 190 /* PrefixUnaryExpression */: return visitNode(cbNode, node.operand); case 195 /* YieldExpression */: return visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.expression); case 189 /* AwaitExpression */: return visitNode(cbNode, node.expression); case 191 /* PostfixUnaryExpression */: return visitNode(cbNode, node.operand); case 192 /* BinaryExpression */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.operatorToken) || visitNode(cbNode, node.right); case 200 /* AsExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.type); case 201 /* NonNullExpression */: return visitNode(cbNode, node.expression); case 193 /* ConditionalExpression */: return visitNode(cbNode, node.condition) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.colonToken) || visitNode(cbNode, node.whenFalse); case 196 /* SpreadElement */: return visitNode(cbNode, node.expression); case 204 /* Block */: case 231 /* ModuleBlock */: return visitNodes(cbNodes, node.statements); case 261 /* SourceFile */: return visitNodes(cbNodes, node.statements) || visitNode(cbNode, node.endOfFileToken); case 205 /* VariableStatement */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.declarationList); case 224 /* VariableDeclarationList */: return visitNodes(cbNodes, node.declarations); case 207 /* ExpressionStatement */: return visitNode(cbNode, node.expression); case 208 /* IfStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.thenStatement) || visitNode(cbNode, node.elseStatement); case 209 /* DoStatement */: return visitNode(cbNode, node.statement) || visitNode(cbNode, node.expression); case 210 /* WhileStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 211 /* ForStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.condition) || visitNode(cbNode, node.incrementor) || visitNode(cbNode, node.statement); case 212 /* ForInStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 213 /* ForOfStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 214 /* ContinueStatement */: case 215 /* BreakStatement */: return visitNode(cbNode, node.label); case 216 /* ReturnStatement */: return visitNode(cbNode, node.expression); case 217 /* WithStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 218 /* SwitchStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.caseBlock); case 232 /* CaseBlock */: return visitNodes(cbNodes, node.clauses); case 253 /* CaseClause */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.statements); case 254 /* DefaultClause */: return visitNodes(cbNodes, node.statements); case 219 /* LabeledStatement */: return visitNode(cbNode, node.label) || visitNode(cbNode, node.statement); case 220 /* ThrowStatement */: return visitNode(cbNode, node.expression); case 221 /* TryStatement */: return visitNode(cbNode, node.tryBlock) || visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); case 256 /* CatchClause */: return visitNode(cbNode, node.variableDeclaration) || visitNode(cbNode, node.block); case 145 /* Decorator */: return visitNode(cbNode, node.expression); case 226 /* ClassDeclaration */: case 197 /* 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 227 /* 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 228 /* TypeAliasDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNode(cbNode, node.type); case 229 /* EnumDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.members); case 260 /* EnumMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 230 /* ModuleDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.body); case 234 /* ImportEqualsDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.moduleReference); case 235 /* ImportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.importClause) || visitNode(cbNode, node.moduleSpecifier); case 236 /* ImportClause */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.namedBindings); case 233 /* NamespaceExportDeclaration */: return visitNode(cbNode, node.name); case 237 /* NamespaceImport */: return visitNode(cbNode, node.name); case 238 /* NamedImports */: case 242 /* NamedExports */: return visitNodes(cbNodes, node.elements); case 241 /* ExportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.exportClause) || visitNode(cbNode, node.moduleSpecifier); case 239 /* ImportSpecifier */: case 243 /* ExportSpecifier */: return visitNode(cbNode, node.propertyName) || visitNode(cbNode, node.name); case 240 /* ExportAssignment */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.expression); case 194 /* TemplateExpression */: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); case 202 /* TemplateSpan */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal); case 142 /* ComputedPropertyName */: return visitNode(cbNode, node.expression); case 255 /* HeritageClause */: return visitNodes(cbNodes, node.types); case 199 /* ExpressionWithTypeArguments */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments); case 245 /* ExternalModuleReference */: return visitNode(cbNode, node.expression); case 244 /* MissingDeclaration */: return visitNodes(cbNodes, node.decorators); case 246 /* JsxElement */: return visitNode(cbNode, node.openingElement) || visitNodes(cbNodes, node.children) || visitNode(cbNode, node.closingElement); case 247 /* JsxSelfClosingElement */: case 248 /* JsxOpeningElement */: return visitNode(cbNode, node.tagName) || visitNodes(cbNodes, node.attributes); case 250 /* JsxAttribute */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 251 /* JsxSpreadAttribute */: return visitNode(cbNode, node.expression); case 252 /* JsxExpression */: return visitNode(cbNode, node.expression); case 249 /* JsxClosingElement */: return visitNode(cbNode, node.tagName); case 262 /* JSDocTypeExpression */: return visitNode(cbNode, node.type); case 266 /* JSDocUnionType */: return visitNodes(cbNodes, node.types); case 267 /* JSDocTupleType */: return visitNodes(cbNodes, node.types); case 265 /* JSDocArrayType */: return visitNode(cbNode, node.elementType); case 269 /* JSDocNonNullableType */: return visitNode(cbNode, node.type); case 268 /* JSDocNullableType */: return visitNode(cbNode, node.type); case 270 /* JSDocRecordType */: return visitNode(cbNode, node.literal); case 272 /* JSDocTypeReference */: return visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeArguments); case 273 /* JSDocOptionalType */: return visitNode(cbNode, node.type); case 274 /* JSDocFunctionType */: return visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 275 /* JSDocVariadicType */: return visitNode(cbNode, node.type); case 276 /* JSDocConstructorType */: return visitNode(cbNode, node.type); case 277 /* JSDocThisType */: return visitNode(cbNode, node.type); case 271 /* JSDocRecordMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.type); case 278 /* JSDocComment */: return visitNodes(cbNodes, node.tags); case 281 /* JSDocParameterTag */: return visitNode(cbNode, node.preParameterName) || visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.postParameterName); case 282 /* JSDocReturnTag */: return visitNode(cbNode, node.typeExpression); case 283 /* JSDocTypeTag */: return visitNode(cbNode, node.typeExpression); case 280 /* JSDocAugmentsTag */: return visitNode(cbNode, node.typeExpression); case 284 /* JSDocTemplateTag */: return visitNodes(cbNodes, node.typeParameters); case 285 /* JSDocTypedefTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.fullName) || visitNode(cbNode, node.name) || visitNode(cbNode, node.jsDocTypeLiteral); case 287 /* JSDocTypeLiteral */: return visitNodes(cbNodes, node.jsDocPropertyTags); case 286 /* JSDocPropertyTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.name); case 294 /* PartiallyEmittedExpression */: return visitNode(cbNode, node.expression); case 288 /* JSDocLiteralType */: return visitNode(cbNode, node.literal); } }
(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 141 /* QualifiedName */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); case 143 /* TypeParameter */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.constraint) || visitNode(cbNode, node.expression); case 258 /* 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 259 /* SpreadAssignment */: return visitNode(cbNode, node.expression); case 144 /* Parameter */: case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: case 257 /* PropertyAssignment */: case 223 /* VariableDeclaration */: case 174 /* 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 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 184 /* FunctionExpression */: case 225 /* FunctionDeclaration */: case 185 /* 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 157 /* TypeReference */: return visitNode(cbNode, node.typeName) || visitNodes(cbNodes, node.typeArguments); case 156 /* TypePredicate */: return visitNode(cbNode, node.parameterName) || visitNode(cbNode, node.type); case 160 /* TypeQuery */: return visitNode(cbNode, node.exprName); case 161 /* TypeLiteral */: return visitNodes(cbNodes, node.members); case 162 /* ArrayType */: return visitNode(cbNode, node.elementType); case 163 /* TupleType */: return visitNodes(cbNodes, node.elementTypes); case 164 /* UnionType */: case 165 /* IntersectionType */: return visitNodes(cbNodes, node.types); case 166 /* ParenthesizedType */: case 168 /* TypeOperator */: return visitNode(cbNode, node.type); case 169 /* IndexedAccessType */: return visitNode(cbNode, node.objectType) || visitNode(cbNode, node.indexType); case 170 /* MappedType */: return visitNode(cbNode, node.readonlyToken) || visitNode(cbNode, node.typeParameter) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.type); case 171 /* LiteralType */: return visitNode(cbNode, node.literal); case 172 /* ObjectBindingPattern */: case 173 /* ArrayBindingPattern */: return visitNodes(cbNodes, node.elements); case 175 /* ArrayLiteralExpression */: return visitNodes(cbNodes, node.elements); case 176 /* ObjectLiteralExpression */: return visitNodes(cbNodes, node.properties); case 177 /* PropertyAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.name); case 178 /* ElementAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); case 179 /* CallExpression */: case 180 /* NewExpression */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); case 181 /* TaggedTemplateExpression */: return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); case 182 /* TypeAssertionExpression */: return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); case 183 /* ParenthesizedExpression */: return visitNode(cbNode, node.expression); case 186 /* DeleteExpression */: return visitNode(cbNode, node.expression); case 187 /* TypeOfExpression */: return visitNode(cbNode, node.expression); case 188 /* VoidExpression */: return visitNode(cbNode, node.expression); case 190 /* PrefixUnaryExpression */: return visitNode(cbNode, node.operand); case 195 /* YieldExpression */: return visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.expression); case 189 /* AwaitExpression */: return visitNode(cbNode, node.expression); case 191 /* PostfixUnaryExpression */: return visitNode(cbNode, node.operand); case 192 /* BinaryExpression */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.operatorToken) || visitNode(cbNode, node.right); case 200 /* AsExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.type); case 201 /* NonNullExpression */: return visitNode(cbNode, node.expression); case 193 /* ConditionalExpression */: return visitNode(cbNode, node.condition) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.colonToken) || visitNode(cbNode, node.whenFalse); case 196 /* SpreadElement */: return visitNode(cbNode, node.expression); case 204 /* Block */: case 231 /* ModuleBlock */: return visitNodes(cbNodes, node.statements); case 261 /* SourceFile */: return visitNodes(cbNodes, node.statements) || visitNode(cbNode, node.endOfFileToken); case 205 /* VariableStatement */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.declarationList); case 224 /* VariableDeclarationList */: return visitNodes(cbNodes, node.declarations); case 207 /* ExpressionStatement */: return visitNode(cbNode, node.expression); case 208 /* IfStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.thenStatement) || visitNode(cbNode, node.elseStatement); case 209 /* DoStatement */: return visitNode(cbNode, node.statement) || visitNode(cbNode, node.expression); case 210 /* WhileStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 211 /* ForStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.condition) || visitNode(cbNode, node.incrementor) || visitNode(cbNode, node.statement); case 212 /* ForInStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 213 /* ForOfStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 214 /* ContinueStatement */: case 215 /* BreakStatement */: return visitNode(cbNode, node.label); case 216 /* ReturnStatement */: return visitNode(cbNode, node.expression); case 217 /* WithStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 218 /* SwitchStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.caseBlock); case 232 /* CaseBlock */: return visitNodes(cbNodes, node.clauses); case 253 /* CaseClause */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.statements); case 254 /* DefaultClause */: return visitNodes(cbNodes, node.statements); case 219 /* LabeledStatement */: return visitNode(cbNode, node.label) || visitNode(cbNode, node.statement); case 220 /* ThrowStatement */: return visitNode(cbNode, node.expression); case 221 /* TryStatement */: return visitNode(cbNode, node.tryBlock) || visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); case 256 /* CatchClause */: return visitNode(cbNode, node.variableDeclaration) || visitNode(cbNode, node.block); case 145 /* Decorator */: return visitNode(cbNode, node.expression); case 226 /* ClassDeclaration */: case 197 /* 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 227 /* 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 228 /* TypeAliasDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNode(cbNode, node.type); case 229 /* EnumDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.members); case 260 /* EnumMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 230 /* ModuleDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.body); case 234 /* ImportEqualsDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.moduleReference); case 235 /* ImportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.importClause) || visitNode(cbNode, node.moduleSpecifier); case 236 /* ImportClause */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.namedBindings); case 233 /* NamespaceExportDeclaration */: return visitNode(cbNode, node.name); case 237 /* NamespaceImport */: return visitNode(cbNode, node.name); case 238 /* NamedImports */: case 242 /* NamedExports */: return visitNodes(cbNodes, node.elements); case 241 /* ExportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.exportClause) || visitNode(cbNode, node.moduleSpecifier); case 239 /* ImportSpecifier */: case 243 /* ExportSpecifier */: return visitNode(cbNode, node.propertyName) || visitNode(cbNode, node.name); case 240 /* ExportAssignment */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.expression); case 194 /* TemplateExpression */: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); case 202 /* TemplateSpan */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal); case 142 /* ComputedPropertyName */: return visitNode(cbNode, node.expression); case 255 /* HeritageClause */: return visitNodes(cbNodes, node.types); case 199 /* ExpressionWithTypeArguments */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments); case 245 /* ExternalModuleReference */: return visitNode(cbNode, node.expression); case 244 /* MissingDeclaration */: return visitNodes(cbNodes, node.decorators); case 246 /* JsxElement */: return visitNode(cbNode, node.openingElement) || visitNodes(cbNodes, node.children) || visitNode(cbNode, node.closingElement); case 247 /* JsxSelfClosingElement */: case 248 /* JsxOpeningElement */: return visitNode(cbNode, node.tagName) || visitNodes(cbNodes, node.attributes); case 250 /* JsxAttribute */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 251 /* JsxSpreadAttribute */: return visitNode(cbNode, node.expression); case 252 /* JsxExpression */: return visitNode(cbNode, node.expression); case 249 /* JsxClosingElement */: return visitNode(cbNode, node.tagName); case 262 /* JSDocTypeExpression */: return visitNode(cbNode, node.type); case 266 /* JSDocUnionType */: return visitNodes(cbNodes, node.types); case 267 /* JSDocTupleType */: return visitNodes(cbNodes, node.types); case 265 /* JSDocArrayType */: return visitNode(cbNode, node.elementType); case 269 /* JSDocNonNullableType */: return visitNode(cbNode, node.type); case 268 /* JSDocNullableType */: return visitNode(cbNode, node.type); case 270 /* JSDocRecordType */: return visitNode(cbNode, node.literal); case 272 /* JSDocTypeReference */: return visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeArguments); case 273 /* JSDocOptionalType */: return visitNode(cbNode, node.type); case 274 /* JSDocFunctionType */: return visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 275 /* JSDocVariadicType */: return visitNode(cbNode, node.type); case 276 /* JSDocConstructorType */: return visitNode(cbNode, node.type); case 277 /* JSDocThisType */: return visitNode(cbNode, node.type); case 271 /* JSDocRecordMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.type); case 278 /* JSDocComment */: return visitNodes(cbNodes, node.tags); case 281 /* JSDocParameterTag */: return visitNode(cbNode, node.preParameterName) || visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.postParameterName); case 282 /* JSDocReturnTag */: return visitNode(cbNode, node.typeExpression); case 283 /* JSDocTypeTag */: return visitNode(cbNode, node.typeExpression); case 280 /* JSDocAugmentsTag */: return visitNode(cbNode, node.typeExpression); case 284 /* JSDocTemplateTag */: return visitNodes(cbNodes, node.typeParameters); case 285 /* JSDocTypedefTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.fullName) || visitNode(cbNode, node.name) || visitNode(cbNode, node.jsDocTypeLiteral); case 287 /* JSDocTypeLiteral */: return visitNodes(cbNodes, node.jsDocPropertyTags); case 286 /* JSDocPropertyTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.name); case 294 /* PartiallyEmittedExpression */: return visitNode(cbNode, node.expression); case 288 /* JSDocLiteralType */: return visitNode(cbNode, node.literal); } }
(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 141 /* QualifiedName */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); case 143 /* TypeParameter */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.constraint) || visitNode(cbNode, node.expression); case 258 /* 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 259 /* SpreadAssignment */: return visitNode(cbNode, node.expression); case 144 /* Parameter */: case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: case 257 /* PropertyAssignment */: case 223 /* VariableDeclaration */: case 174 /* 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 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 184 /* FunctionExpression */: case 225 /* FunctionDeclaration */: case 185 /* 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 157 /* TypeReference */: return visitNode(cbNode, node.typeName) || visitNodes(cbNodes, node.typeArguments); case 156 /* TypePredicate */: return visitNode(cbNode, node.parameterName) || visitNode(cbNode, node.type); case 160 /* TypeQuery */: return visitNode(cbNode, node.exprName); case 161 /* TypeLiteral */: return visitNodes(cbNodes, node.members); case 162 /* ArrayType */: return visitNode(cbNode, node.elementType); case 163 /* TupleType */: return visitNodes(cbNodes, node.elementTypes); case 164 /* UnionType */: case 165 /* IntersectionType */: return visitNodes(cbNodes, node.types); case 166 /* ParenthesizedType */: case 168 /* TypeOperator */: return visitNode(cbNode, node.type); case 169 /* IndexedAccessType */: return visitNode(cbNode, node.objectType) || visitNode(cbNode, node.indexType); case 170 /* MappedType */: return visitNode(cbNode, node.readonlyToken) || visitNode(cbNode, node.typeParameter) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.type); case 171 /* LiteralType */: return visitNode(cbNode, node.literal); case 172 /* ObjectBindingPattern */: case 173 /* ArrayBindingPattern */: return visitNodes(cbNodes, node.elements); case 175 /* ArrayLiteralExpression */: return visitNodes(cbNodes, node.elements); case 176 /* ObjectLiteralExpression */: return visitNodes(cbNodes, node.properties); case 177 /* PropertyAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.name); case 178 /* ElementAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); case 179 /* CallExpression */: case 180 /* NewExpression */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); case 181 /* TaggedTemplateExpression */: return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); case 182 /* TypeAssertionExpression */: return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); case 183 /* ParenthesizedExpression */: return visitNode(cbNode, node.expression); case 186 /* DeleteExpression */: return visitNode(cbNode, node.expression); case 187 /* TypeOfExpression */: return visitNode(cbNode, node.expression); case 188 /* VoidExpression */: return visitNode(cbNode, node.expression); case 190 /* PrefixUnaryExpression */: return visitNode(cbNode, node.operand); case 195 /* YieldExpression */: return visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.expression); case 189 /* AwaitExpression */: return visitNode(cbNode, node.expression); case 191 /* PostfixUnaryExpression */: return visitNode(cbNode, node.operand); case 192 /* BinaryExpression */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.operatorToken) || visitNode(cbNode, node.right); case 200 /* AsExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.type); case 201 /* NonNullExpression */: return visitNode(cbNode, node.expression); case 193 /* ConditionalExpression */: return visitNode(cbNode, node.condition) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.colonToken) || visitNode(cbNode, node.whenFalse); case 196 /* SpreadElement */: return visitNode(cbNode, node.expression); case 204 /* Block */: case 231 /* ModuleBlock */: return visitNodes(cbNodes, node.statements); case 261 /* SourceFile */: return visitNodes(cbNodes, node.statements) || visitNode(cbNode, node.endOfFileToken); case 205 /* VariableStatement */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.declarationList); case 224 /* VariableDeclarationList */: return visitNodes(cbNodes, node.declarations); case 207 /* ExpressionStatement */: return visitNode(cbNode, node.expression); case 208 /* IfStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.thenStatement) || visitNode(cbNode, node.elseStatement); case 209 /* DoStatement */: return visitNode(cbNode, node.statement) || visitNode(cbNode, node.expression); case 210 /* WhileStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 211 /* ForStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.condition) || visitNode(cbNode, node.incrementor) || visitNode(cbNode, node.statement); case 212 /* ForInStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 213 /* ForOfStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 214 /* ContinueStatement */: case 215 /* BreakStatement */: return visitNode(cbNode, node.label); case 216 /* ReturnStatement */: return visitNode(cbNode, node.expression); case 217 /* WithStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 218 /* SwitchStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.caseBlock); case 232 /* CaseBlock */: return visitNodes(cbNodes, node.clauses); case 253 /* CaseClause */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.statements); case 254 /* DefaultClause */: return visitNodes(cbNodes, node.statements); case 219 /* LabeledStatement */: return visitNode(cbNode, node.label) || visitNode(cbNode, node.statement); case 220 /* ThrowStatement */: return visitNode(cbNode, node.expression); case 221 /* TryStatement */: return visitNode(cbNode, node.tryBlock) || visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); case 256 /* CatchClause */: return visitNode(cbNode, node.variableDeclaration) || visitNode(cbNode, node.block); case 145 /* Decorator */: return visitNode(cbNode, node.expression); case 226 /* ClassDeclaration */: case 197 /* 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 227 /* 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 228 /* TypeAliasDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNode(cbNode, node.type); case 229 /* EnumDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.members); case 260 /* EnumMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 230 /* ModuleDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.body); case 234 /* ImportEqualsDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.moduleReference); case 235 /* ImportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.importClause) || visitNode(cbNode, node.moduleSpecifier); case 236 /* ImportClause */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.namedBindings); case 233 /* NamespaceExportDeclaration */: return visitNode(cbNode, node.name); case 237 /* NamespaceImport */: return visitNode(cbNode, node.name); case 238 /* NamedImports */: case 242 /* NamedExports */: return visitNodes(cbNodes, node.elements); case 241 /* ExportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.exportClause) || visitNode(cbNode, node.moduleSpecifier); case 239 /* ImportSpecifier */: case 243 /* ExportSpecifier */: return visitNode(cbNode, node.propertyName) || visitNode(cbNode, node.name); case 240 /* ExportAssignment */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.expression); case 194 /* TemplateExpression */: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); case 202 /* TemplateSpan */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal); case 142 /* ComputedPropertyName */: return visitNode(cbNode, node.expression); case 255 /* HeritageClause */: return visitNodes(cbNodes, node.types); case 199 /* ExpressionWithTypeArguments */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments); case 245 /* ExternalModuleReference */: return visitNode(cbNode, node.expression); case 244 /* MissingDeclaration */: return visitNodes(cbNodes, node.decorators); case 246 /* JsxElement */: return visitNode(cbNode, node.openingElement) || visitNodes(cbNodes, node.children) || visitNode(cbNode, node.closingElement); case 247 /* JsxSelfClosingElement */: case 248 /* JsxOpeningElement */: return visitNode(cbNode, node.tagName) || visitNodes(cbNodes, node.attributes); case 250 /* JsxAttribute */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 251 /* JsxSpreadAttribute */: return visitNode(cbNode, node.expression); case 252 /* JsxExpression */: return visitNode(cbNode, node.expression); case 249 /* JsxClosingElement */: return visitNode(cbNode, node.tagName); case 262 /* JSDocTypeExpression */: return visitNode(cbNode, node.type); case 266 /* JSDocUnionType */: return visitNodes(cbNodes, node.types); case 267 /* JSDocTupleType */: return visitNodes(cbNodes, node.types); case 265 /* JSDocArrayType */: return visitNode(cbNode, node.elementType); case 269 /* JSDocNonNullableType */: return visitNode(cbNode, node.type); case 268 /* JSDocNullableType */: return visitNode(cbNode, node.type); case 270 /* JSDocRecordType */: return visitNode(cbNode, node.literal); case 272 /* JSDocTypeReference */: return visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeArguments); case 273 /* JSDocOptionalType */: return visitNode(cbNode, node.type); case 274 /* JSDocFunctionType */: return visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 275 /* JSDocVariadicType */: return visitNode(cbNode, node.type); case 276 /* JSDocConstructorType */: return visitNode(cbNode, node.type); case 277 /* JSDocThisType */: return visitNode(cbNode, node.type); case 271 /* JSDocRecordMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.type); case 278 /* JSDocComment */: return visitNodes(cbNodes, node.tags); case 281 /* JSDocParameterTag */: return visitNode(cbNode, node.preParameterName) || visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.postParameterName); case 282 /* JSDocReturnTag */: return visitNode(cbNode, node.typeExpression); case 283 /* JSDocTypeTag */: return visitNode(cbNode, node.typeExpression); case 280 /* JSDocAugmentsTag */: return visitNode(cbNode, node.typeExpression); case 284 /* JSDocTemplateTag */: return visitNodes(cbNodes, node.typeParameters); case 285 /* JSDocTypedefTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.fullName) || visitNode(cbNode, node.name) || visitNode(cbNode, node.jsDocTypeLiteral); case 287 /* JSDocTypeLiteral */: return visitNodes(cbNodes, node.jsDocPropertyTags); case 286 /* JSDocPropertyTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.name); case 294 /* PartiallyEmittedExpression */: return visitNode(cbNode, node.expression); case 288 /* JSDocLiteralType */: return visitNode(cbNode, node.literal); } }
(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 141 /* QualifiedName */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); case 143 /* TypeParameter */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.constraint) || visitNode(cbNode, node.expression); case 258 /* 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 259 /* SpreadAssignment */: return visitNode(cbNode, node.expression); case 144 /* Parameter */: case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: case 257 /* PropertyAssignment */: case 223 /* VariableDeclaration */: case 174 /* 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 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 184 /* FunctionExpression */: case 225 /* FunctionDeclaration */: case 185 /* 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 157 /* TypeReference */: return visitNode(cbNode, node.typeName) || visitNodes(cbNodes, node.typeArguments); case 156 /* TypePredicate */: return visitNode(cbNode, node.parameterName) || visitNode(cbNode, node.type); case 160 /* TypeQuery */: return visitNode(cbNode, node.exprName); case 161 /* TypeLiteral */: return visitNodes(cbNodes, node.members); case 162 /* ArrayType */: return visitNode(cbNode, node.elementType); case 163 /* TupleType */: return visitNodes(cbNodes, node.elementTypes); case 164 /* UnionType */: case 165 /* IntersectionType */: return visitNodes(cbNodes, node.types); case 166 /* ParenthesizedType */: case 168 /* TypeOperator */: return visitNode(cbNode, node.type); case 169 /* IndexedAccessType */: return visitNode(cbNode, node.objectType) || visitNode(cbNode, node.indexType); case 170 /* MappedType */: return visitNode(cbNode, node.readonlyToken) || visitNode(cbNode, node.typeParameter) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.type); case 171 /* LiteralType */: return visitNode(cbNode, node.literal); case 172 /* ObjectBindingPattern */: case 173 /* ArrayBindingPattern */: return visitNodes(cbNodes, node.elements); case 175 /* ArrayLiteralExpression */: return visitNodes(cbNodes, node.elements); case 176 /* ObjectLiteralExpression */: return visitNodes(cbNodes, node.properties); case 177 /* PropertyAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.name); case 178 /* ElementAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); case 179 /* CallExpression */: case 180 /* NewExpression */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); case 181 /* TaggedTemplateExpression */: return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); case 182 /* TypeAssertionExpression */: return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); case 183 /* ParenthesizedExpression */: return visitNode(cbNode, node.expression); case 186 /* DeleteExpression */: return visitNode(cbNode, node.expression); case 187 /* TypeOfExpression */: return visitNode(cbNode, node.expression); case 188 /* VoidExpression */: return visitNode(cbNode, node.expression); case 190 /* PrefixUnaryExpression */: return visitNode(cbNode, node.operand); case 195 /* YieldExpression */: return visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.expression); case 189 /* AwaitExpression */: return visitNode(cbNode, node.expression); case 191 /* PostfixUnaryExpression */: return visitNode(cbNode, node.operand); case 192 /* BinaryExpression */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.operatorToken) || visitNode(cbNode, node.right); case 200 /* AsExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.type); case 201 /* NonNullExpression */: return visitNode(cbNode, node.expression); case 193 /* ConditionalExpression */: return visitNode(cbNode, node.condition) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.colonToken) || visitNode(cbNode, node.whenFalse); case 196 /* SpreadElement */: return visitNode(cbNode, node.expression); case 204 /* Block */: case 231 /* ModuleBlock */: return visitNodes(cbNodes, node.statements); case 261 /* SourceFile */: return visitNodes(cbNodes, node.statements) || visitNode(cbNode, node.endOfFileToken); case 205 /* VariableStatement */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.declarationList); case 224 /* VariableDeclarationList */: return visitNodes(cbNodes, node.declarations); case 207 /* ExpressionStatement */: return visitNode(cbNode, node.expression); case 208 /* IfStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.thenStatement) || visitNode(cbNode, node.elseStatement); case 209 /* DoStatement */: return visitNode(cbNode, node.statement) || visitNode(cbNode, node.expression); case 210 /* WhileStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 211 /* ForStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.condition) || visitNode(cbNode, node.incrementor) || visitNode(cbNode, node.statement); case 212 /* ForInStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 213 /* ForOfStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 214 /* ContinueStatement */: case 215 /* BreakStatement */: return visitNode(cbNode, node.label); case 216 /* ReturnStatement */: return visitNode(cbNode, node.expression); case 217 /* WithStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 218 /* SwitchStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.caseBlock); case 232 /* CaseBlock */: return visitNodes(cbNodes, node.clauses); case 253 /* CaseClause */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.statements); case 254 /* DefaultClause */: return visitNodes(cbNodes, node.statements); case 219 /* LabeledStatement */: return visitNode(cbNode, node.label) || visitNode(cbNode, node.statement); case 220 /* ThrowStatement */: return visitNode(cbNode, node.expression); case 221 /* TryStatement */: return visitNode(cbNode, node.tryBlock) || visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); case 256 /* CatchClause */: return visitNode(cbNode, node.variableDeclaration) || visitNode(cbNode, node.block); case 145 /* Decorator */: return visitNode(cbNode, node.expression); case 226 /* ClassDeclaration */: case 197 /* 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 227 /* 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 228 /* TypeAliasDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNode(cbNode, node.type); case 229 /* EnumDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.members); case 260 /* EnumMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 230 /* ModuleDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.body); case 234 /* ImportEqualsDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.moduleReference); case 235 /* ImportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.importClause) || visitNode(cbNode, node.moduleSpecifier); case 236 /* ImportClause */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.namedBindings); case 233 /* NamespaceExportDeclaration */: return visitNode(cbNode, node.name); case 237 /* NamespaceImport */: return visitNode(cbNode, node.name); case 238 /* NamedImports */: case 242 /* NamedExports */: return visitNodes(cbNodes, node.elements); case 241 /* ExportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.exportClause) || visitNode(cbNode, node.moduleSpecifier); case 239 /* ImportSpecifier */: case 243 /* ExportSpecifier */: return visitNode(cbNode, node.propertyName) || visitNode(cbNode, node.name); case 240 /* ExportAssignment */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.expression); case 194 /* TemplateExpression */: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); case 202 /* TemplateSpan */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal); case 142 /* ComputedPropertyName */: return visitNode(cbNode, node.expression); case 255 /* HeritageClause */: return visitNodes(cbNodes, node.types); case 199 /* ExpressionWithTypeArguments */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments); case 245 /* ExternalModuleReference */: return visitNode(cbNode, node.expression); case 244 /* MissingDeclaration */: return visitNodes(cbNodes, node.decorators); case 246 /* JsxElement */: return visitNode(cbNode, node.openingElement) || visitNodes(cbNodes, node.children) || visitNode(cbNode, node.closingElement); case 247 /* JsxSelfClosingElement */: case 248 /* JsxOpeningElement */: return visitNode(cbNode, node.tagName) || visitNodes(cbNodes, node.attributes); case 250 /* JsxAttribute */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 251 /* JsxSpreadAttribute */: return visitNode(cbNode, node.expression); case 252 /* JsxExpression */: return visitNode(cbNode, node.expression); case 249 /* JsxClosingElement */: return visitNode(cbNode, node.tagName); case 262 /* JSDocTypeExpression */: return visitNode(cbNode, node.type); case 266 /* JSDocUnionType */: return visitNodes(cbNodes, node.types); case 267 /* JSDocTupleType */: return visitNodes(cbNodes, node.types); case 265 /* JSDocArrayType */: return visitNode(cbNode, node.elementType); case 269 /* JSDocNonNullableType */: return visitNode(cbNode, node.type); case 268 /* JSDocNullableType */: return visitNode(cbNode, node.type); case 270 /* JSDocRecordType */: return visitNode(cbNode, node.literal); case 272 /* JSDocTypeReference */: return visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeArguments); case 273 /* JSDocOptionalType */: return visitNode(cbNode, node.type); case 274 /* JSDocFunctionType */: return visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 275 /* JSDocVariadicType */: return visitNode(cbNode, node.type); case 276 /* JSDocConstructorType */: return visitNode(cbNode, node.type); case 277 /* JSDocThisType */: return visitNode(cbNode, node.type); case 271 /* JSDocRecordMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.type); case 278 /* JSDocComment */: return visitNodes(cbNodes, node.tags); case 281 /* JSDocParameterTag */: return visitNode(cbNode, node.preParameterName) || visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.postParameterName); case 282 /* JSDocReturnTag */: return visitNode(cbNode, node.typeExpression); case 283 /* JSDocTypeTag */: return visitNode(cbNode, node.typeExpression); case 280 /* JSDocAugmentsTag */: return visitNode(cbNode, node.typeExpression); case 284 /* JSDocTemplateTag */: return visitNodes(cbNodes, node.typeParameters); case 285 /* JSDocTypedefTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.fullName) || visitNode(cbNode, node.name) || visitNode(cbNode, node.jsDocTypeLiteral); case 287 /* JSDocTypeLiteral */: return visitNodes(cbNodes, node.jsDocPropertyTags); case 286 /* JSDocPropertyTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.name); case 294 /* PartiallyEmittedExpression */: return visitNode(cbNode, node.expression); case 288 /* JSDocLiteralType */: return visitNode(cbNode, node.literal); } }
(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 141 /* QualifiedName */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); case 143 /* TypeParameter */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.constraint) || visitNode(cbNode, node.expression); case 258 /* 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 259 /* SpreadAssignment */: return visitNode(cbNode, node.expression); case 144 /* Parameter */: case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: case 257 /* PropertyAssignment */: case 223 /* VariableDeclaration */: case 174 /* 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 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 184 /* FunctionExpression */: case 225 /* FunctionDeclaration */: case 185 /* 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 157 /* TypeReference */: return visitNode(cbNode, node.typeName) || visitNodes(cbNodes, node.typeArguments); case 156 /* TypePredicate */: return visitNode(cbNode, node.parameterName) || visitNode(cbNode, node.type); case 160 /* TypeQuery */: return visitNode(cbNode, node.exprName); case 161 /* TypeLiteral */: return visitNodes(cbNodes, node.members); case 162 /* ArrayType */: return visitNode(cbNode, node.elementType); case 163 /* TupleType */: return visitNodes(cbNodes, node.elementTypes); case 164 /* UnionType */: case 165 /* IntersectionType */: return visitNodes(cbNodes, node.types); case 166 /* ParenthesizedType */: case 168 /* TypeOperator */: return visitNode(cbNode, node.type); case 169 /* IndexedAccessType */: return visitNode(cbNode, node.objectType) || visitNode(cbNode, node.indexType); case 170 /* MappedType */: return visitNode(cbNode, node.readonlyToken) || visitNode(cbNode, node.typeParameter) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.type); case 171 /* LiteralType */: return visitNode(cbNode, node.literal); case 172 /* ObjectBindingPattern */: case 173 /* ArrayBindingPattern */: return visitNodes(cbNodes, node.elements); case 175 /* ArrayLiteralExpression */: return visitNodes(cbNodes, node.elements); case 176 /* ObjectLiteralExpression */: return visitNodes(cbNodes, node.properties); case 177 /* PropertyAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.name); case 178 /* ElementAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); case 179 /* CallExpression */: case 180 /* NewExpression */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); case 181 /* TaggedTemplateExpression */: return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); case 182 /* TypeAssertionExpression */: return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); case 183 /* ParenthesizedExpression */: return visitNode(cbNode, node.expression); case 186 /* DeleteExpression */: return visitNode(cbNode, node.expression); case 187 /* TypeOfExpression */: return visitNode(cbNode, node.expression); case 188 /* VoidExpression */: return visitNode(cbNode, node.expression); case 190 /* PrefixUnaryExpression */: return visitNode(cbNode, node.operand); case 195 /* YieldExpression */: return visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.expression); case 189 /* AwaitExpression */: return visitNode(cbNode, node.expression); case 191 /* PostfixUnaryExpression */: return visitNode(cbNode, node.operand); case 192 /* BinaryExpression */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.operatorToken) || visitNode(cbNode, node.right); case 200 /* AsExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.type); case 201 /* NonNullExpression */: return visitNode(cbNode, node.expression); case 193 /* ConditionalExpression */: return visitNode(cbNode, node.condition) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.colonToken) || visitNode(cbNode, node.whenFalse); case 196 /* SpreadElement */: return visitNode(cbNode, node.expression); case 204 /* Block */: case 231 /* ModuleBlock */: return visitNodes(cbNodes, node.statements); case 261 /* SourceFile */: return visitNodes(cbNodes, node.statements) || visitNode(cbNode, node.endOfFileToken); case 205 /* VariableStatement */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.declarationList); case 224 /* VariableDeclarationList */: return visitNodes(cbNodes, node.declarations); case 207 /* ExpressionStatement */: return visitNode(cbNode, node.expression); case 208 /* IfStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.thenStatement) || visitNode(cbNode, node.elseStatement); case 209 /* DoStatement */: return visitNode(cbNode, node.statement) || visitNode(cbNode, node.expression); case 210 /* WhileStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 211 /* ForStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.condition) || visitNode(cbNode, node.incrementor) || visitNode(cbNode, node.statement); case 212 /* ForInStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 213 /* ForOfStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 214 /* ContinueStatement */: case 215 /* BreakStatement */: return visitNode(cbNode, node.label); case 216 /* ReturnStatement */: return visitNode(cbNode, node.expression); case 217 /* WithStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 218 /* SwitchStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.caseBlock); case 232 /* CaseBlock */: return visitNodes(cbNodes, node.clauses); case 253 /* CaseClause */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.statements); case 254 /* DefaultClause */: return visitNodes(cbNodes, node.statements); case 219 /* LabeledStatement */: return visitNode(cbNode, node.label) || visitNode(cbNode, node.statement); case 220 /* ThrowStatement */: return visitNode(cbNode, node.expression); case 221 /* TryStatement */: return visitNode(cbNode, node.tryBlock) || visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); case 256 /* CatchClause */: return visitNode(cbNode, node.variableDeclaration) || visitNode(cbNode, node.block); case 145 /* Decorator */: return visitNode(cbNode, node.expression); case 226 /* ClassDeclaration */: case 197 /* 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 227 /* 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 228 /* TypeAliasDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNode(cbNode, node.type); case 229 /* EnumDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.members); case 260 /* EnumMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 230 /* ModuleDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.body); case 234 /* ImportEqualsDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.moduleReference); case 235 /* ImportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.importClause) || visitNode(cbNode, node.moduleSpecifier); case 236 /* ImportClause */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.namedBindings); case 233 /* NamespaceExportDeclaration */: return visitNode(cbNode, node.name); case 237 /* NamespaceImport */: return visitNode(cbNode, node.name); case 238 /* NamedImports */: case 242 /* NamedExports */: return visitNodes(cbNodes, node.elements); case 241 /* ExportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.exportClause) || visitNode(cbNode, node.moduleSpecifier); case 239 /* ImportSpecifier */: case 243 /* ExportSpecifier */: return visitNode(cbNode, node.propertyName) || visitNode(cbNode, node.name); case 240 /* ExportAssignment */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.expression); case 194 /* TemplateExpression */: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); case 202 /* TemplateSpan */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal); case 142 /* ComputedPropertyName */: return visitNode(cbNode, node.expression); case 255 /* HeritageClause */: return visitNodes(cbNodes, node.types); case 199 /* ExpressionWithTypeArguments */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments); case 245 /* ExternalModuleReference */: return visitNode(cbNode, node.expression); case 244 /* MissingDeclaration */: return visitNodes(cbNodes, node.decorators); case 246 /* JsxElement */: return visitNode(cbNode, node.openingElement) || visitNodes(cbNodes, node.children) || visitNode(cbNode, node.closingElement); case 247 /* JsxSelfClosingElement */: case 248 /* JsxOpeningElement */: return visitNode(cbNode, node.tagName) || visitNodes(cbNodes, node.attributes); case 250 /* JsxAttribute */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 251 /* JsxSpreadAttribute */: return visitNode(cbNode, node.expression); case 252 /* JsxExpression */: return visitNode(cbNode, node.expression); case 249 /* JsxClosingElement */: return visitNode(cbNode, node.tagName); case 262 /* JSDocTypeExpression */: return visitNode(cbNode, node.type); case 266 /* JSDocUnionType */: return visitNodes(cbNodes, node.types); case 267 /* JSDocTupleType */: return visitNodes(cbNodes, node.types); case 265 /* JSDocArrayType */: return visitNode(cbNode, node.elementType); case 269 /* JSDocNonNullableType */: return visitNode(cbNode, node.type); case 268 /* JSDocNullableType */: return visitNode(cbNode, node.type); case 270 /* JSDocRecordType */: return visitNode(cbNode, node.literal); case 272 /* JSDocTypeReference */: return visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeArguments); case 273 /* JSDocOptionalType */: return visitNode(cbNode, node.type); case 274 /* JSDocFunctionType */: return visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 275 /* JSDocVariadicType */: return visitNode(cbNode, node.type); case 276 /* JSDocConstructorType */: return visitNode(cbNode, node.type); case 277 /* JSDocThisType */: return visitNode(cbNode, node.type); case 271 /* JSDocRecordMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.type); case 278 /* JSDocComment */: return visitNodes(cbNodes, node.tags); case 281 /* JSDocParameterTag */: return visitNode(cbNode, node.preParameterName) || visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.postParameterName); case 282 /* JSDocReturnTag */: return visitNode(cbNode, node.typeExpression); case 283 /* JSDocTypeTag */: return visitNode(cbNode, node.typeExpression); case 280 /* JSDocAugmentsTag */: return visitNode(cbNode, node.typeExpression); case 284 /* JSDocTemplateTag */: return visitNodes(cbNodes, node.typeParameters); case 285 /* JSDocTypedefTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.fullName) || visitNode(cbNode, node.name) || visitNode(cbNode, node.jsDocTypeLiteral); case 287 /* JSDocTypeLiteral */: return visitNodes(cbNodes, node.jsDocPropertyTags); case 286 /* JSDocPropertyTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.name); case 294 /* PartiallyEmittedExpression */: return visitNode(cbNode, node.expression); case 288 /* JSDocLiteralType */: return visitNode(cbNode, node.literal); } }
(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 141 /* QualifiedName */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); case 143 /* TypeParameter */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.constraint) || visitNode(cbNode, node.expression); case 258 /* 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 259 /* SpreadAssignment */: return visitNode(cbNode, node.expression); case 144 /* Parameter */: case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: case 257 /* PropertyAssignment */: case 223 /* VariableDeclaration */: case 174 /* 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 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 184 /* FunctionExpression */: case 225 /* FunctionDeclaration */: case 185 /* 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 157 /* TypeReference */: return visitNode(cbNode, node.typeName) || visitNodes(cbNodes, node.typeArguments); case 156 /* TypePredicate */: return visitNode(cbNode, node.parameterName) || visitNode(cbNode, node.type); case 160 /* TypeQuery */: return visitNode(cbNode, node.exprName); case 161 /* TypeLiteral */: return visitNodes(cbNodes, node.members); case 162 /* ArrayType */: return visitNode(cbNode, node.elementType); case 163 /* TupleType */: return visitNodes(cbNodes, node.elementTypes); case 164 /* UnionType */: case 165 /* IntersectionType */: return visitNodes(cbNodes, node.types); case 166 /* ParenthesizedType */: case 168 /* TypeOperator */: return visitNode(cbNode, node.type); case 169 /* IndexedAccessType */: return visitNode(cbNode, node.objectType) || visitNode(cbNode, node.indexType); case 170 /* MappedType */: return visitNode(cbNode, node.readonlyToken) || visitNode(cbNode, node.typeParameter) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.type); case 171 /* LiteralType */: return visitNode(cbNode, node.literal); case 172 /* ObjectBindingPattern */: case 173 /* ArrayBindingPattern */: return visitNodes(cbNodes, node.elements); case 175 /* ArrayLiteralExpression */: return visitNodes(cbNodes, node.elements); case 176 /* ObjectLiteralExpression */: return visitNodes(cbNodes, node.properties); case 177 /* PropertyAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.name); case 178 /* ElementAccessExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); case 179 /* CallExpression */: case 180 /* NewExpression */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); case 181 /* TaggedTemplateExpression */: return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); case 182 /* TypeAssertionExpression */: return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); case 183 /* ParenthesizedExpression */: return visitNode(cbNode, node.expression); case 186 /* DeleteExpression */: return visitNode(cbNode, node.expression); case 187 /* TypeOfExpression */: return visitNode(cbNode, node.expression); case 188 /* VoidExpression */: return visitNode(cbNode, node.expression); case 190 /* PrefixUnaryExpression */: return visitNode(cbNode, node.operand); case 195 /* YieldExpression */: return visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.expression); case 189 /* AwaitExpression */: return visitNode(cbNode, node.expression); case 191 /* PostfixUnaryExpression */: return visitNode(cbNode, node.operand); case 192 /* BinaryExpression */: return visitNode(cbNode, node.left) || visitNode(cbNode, node.operatorToken) || visitNode(cbNode, node.right); case 200 /* AsExpression */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.type); case 201 /* NonNullExpression */: return visitNode(cbNode, node.expression); case 193 /* ConditionalExpression */: return visitNode(cbNode, node.condition) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.colonToken) || visitNode(cbNode, node.whenFalse); case 196 /* SpreadElement */: return visitNode(cbNode, node.expression); case 204 /* Block */: case 231 /* ModuleBlock */: return visitNodes(cbNodes, node.statements); case 261 /* SourceFile */: return visitNodes(cbNodes, node.statements) || visitNode(cbNode, node.endOfFileToken); case 205 /* VariableStatement */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.declarationList); case 224 /* VariableDeclarationList */: return visitNodes(cbNodes, node.declarations); case 207 /* ExpressionStatement */: return visitNode(cbNode, node.expression); case 208 /* IfStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.thenStatement) || visitNode(cbNode, node.elseStatement); case 209 /* DoStatement */: return visitNode(cbNode, node.statement) || visitNode(cbNode, node.expression); case 210 /* WhileStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 211 /* ForStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.condition) || visitNode(cbNode, node.incrementor) || visitNode(cbNode, node.statement); case 212 /* ForInStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 213 /* ForOfStatement */: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 214 /* ContinueStatement */: case 215 /* BreakStatement */: return visitNode(cbNode, node.label); case 216 /* ReturnStatement */: return visitNode(cbNode, node.expression); case 217 /* WithStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); case 218 /* SwitchStatement */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.caseBlock); case 232 /* CaseBlock */: return visitNodes(cbNodes, node.clauses); case 253 /* CaseClause */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.statements); case 254 /* DefaultClause */: return visitNodes(cbNodes, node.statements); case 219 /* LabeledStatement */: return visitNode(cbNode, node.label) || visitNode(cbNode, node.statement); case 220 /* ThrowStatement */: return visitNode(cbNode, node.expression); case 221 /* TryStatement */: return visitNode(cbNode, node.tryBlock) || visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); case 256 /* CatchClause */: return visitNode(cbNode, node.variableDeclaration) || visitNode(cbNode, node.block); case 145 /* Decorator */: return visitNode(cbNode, node.expression); case 226 /* ClassDeclaration */: case 197 /* 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 227 /* 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 228 /* TypeAliasDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNode(cbNode, node.type); case 229 /* EnumDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.members); case 260 /* EnumMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 230 /* ModuleDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.body); case 234 /* ImportEqualsDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.moduleReference); case 235 /* ImportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.importClause) || visitNode(cbNode, node.moduleSpecifier); case 236 /* ImportClause */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.namedBindings); case 233 /* NamespaceExportDeclaration */: return visitNode(cbNode, node.name); case 237 /* NamespaceImport */: return visitNode(cbNode, node.name); case 238 /* NamedImports */: case 242 /* NamedExports */: return visitNodes(cbNodes, node.elements); case 241 /* ExportDeclaration */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.exportClause) || visitNode(cbNode, node.moduleSpecifier); case 239 /* ImportSpecifier */: case 243 /* ExportSpecifier */: return visitNode(cbNode, node.propertyName) || visitNode(cbNode, node.name); case 240 /* ExportAssignment */: return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.expression); case 194 /* TemplateExpression */: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); case 202 /* TemplateSpan */: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal); case 142 /* ComputedPropertyName */: return visitNode(cbNode, node.expression); case 255 /* HeritageClause */: return visitNodes(cbNodes, node.types); case 199 /* ExpressionWithTypeArguments */: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments); case 245 /* ExternalModuleReference */: return visitNode(cbNode, node.expression); case 244 /* MissingDeclaration */: return visitNodes(cbNodes, node.decorators); case 246 /* JsxElement */: return visitNode(cbNode, node.openingElement) || visitNodes(cbNodes, node.children) || visitNode(cbNode, node.closingElement); case 247 /* JsxSelfClosingElement */: case 248 /* JsxOpeningElement */: return visitNode(cbNode, node.tagName) || visitNodes(cbNodes, node.attributes); case 250 /* JsxAttribute */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); case 251 /* JsxSpreadAttribute */: return visitNode(cbNode, node.expression); case 252 /* JsxExpression */: return visitNode(cbNode, node.expression); case 249 /* JsxClosingElement */: return visitNode(cbNode, node.tagName); case 262 /* JSDocTypeExpression */: return visitNode(cbNode, node.type); case 266 /* JSDocUnionType */: return visitNodes(cbNodes, node.types); case 267 /* JSDocTupleType */: return visitNodes(cbNodes, node.types); case 265 /* JSDocArrayType */: return visitNode(cbNode, node.elementType); case 269 /* JSDocNonNullableType */: return visitNode(cbNode, node.type); case 268 /* JSDocNullableType */: return visitNode(cbNode, node.type); case 270 /* JSDocRecordType */: return visitNode(cbNode, node.literal); case 272 /* JSDocTypeReference */: return visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeArguments); case 273 /* JSDocOptionalType */: return visitNode(cbNode, node.type); case 274 /* JSDocFunctionType */: return visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); case 275 /* JSDocVariadicType */: return visitNode(cbNode, node.type); case 276 /* JSDocConstructorType */: return visitNode(cbNode, node.type); case 277 /* JSDocThisType */: return visitNode(cbNode, node.type); case 271 /* JSDocRecordMember */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.type); case 278 /* JSDocComment */: return visitNodes(cbNodes, node.tags); case 281 /* JSDocParameterTag */: return visitNode(cbNode, node.preParameterName) || visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.postParameterName); case 282 /* JSDocReturnTag */: return visitNode(cbNode, node.typeExpression); case 283 /* JSDocTypeTag */: return visitNode(cbNode, node.typeExpression); case 280 /* JSDocAugmentsTag */: return visitNode(cbNode, node.typeExpression); case 284 /* JSDocTemplateTag */: return visitNodes(cbNodes, node.typeParameters); case 285 /* JSDocTypedefTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.fullName) || visitNode(cbNode, node.name) || visitNode(cbNode, node.jsDocTypeLiteral); case 287 /* JSDocTypeLiteral */: return visitNodes(cbNodes, node.jsDocPropertyTags); case 286 /* JSDocPropertyTag */: return visitNode(cbNode, node.typeExpression) || visitNode(cbNode, node.name); case 294 /* PartiallyEmittedExpression */: return visitNode(cbNode, node.expression); case 288 /* JSDocLiteralType */: return visitNode(cbNode, node.literal); } }
bindFunctionOrConstructorType:
(node) { // For a given function symbol "<...>(...) => T" we want to generate a symbol identical // to the one we would get for: { <...>(...): T } // // We do that by making an anonymous type literal symbol, and then setting the function // symbol as its sole member. To the rest of the system, this symbol will be indistinguishable // from an actual type literal symbol you would have gotten had you used the long form. var symbol = createSymbol(131072 /* Signature */, getDeclarationName(node)); addDeclarationToSymbol(symbol, node, 131072 /* Signature */); var typeLiteralSymbol = createSymbol(2048 /* TypeLiteral */, "__type"); addDeclarationToSymbol(typeLiteralSymbol, node, 2048 /* TypeLiteral */); typeLiteralSymbol.members = ts.createMap(); typeLiteralSymbol.members[symbol.name] = symbol; }
bindBlockScopedDeclaration:
(node, symbolFlags, symbolExcludes) { switch (blockScopeContainer.kind) { case 230 /* ModuleDeclaration */: declareModuleMember(node, symbolFlags, symbolExcludes); break; case 261 /* SourceFile */: if (ts.isExternalModule(container)) { declareModuleMember(node, symbolFlags, symbolExcludes); break; } // fall through. default: if (!blockScopeContainer.locals) { blockScopeContainer.locals = ts.createMap(); addToContainerChain(blockScopeContainer); } declareSymbol(blockScopeContainer.locals, undefined, node, symbolFlags, symbolExcludes); } }
(node, symbolFlags, symbolExcludes) { switch (blockScopeContainer.kind) { case 230 /* ModuleDeclaration */: declareModuleMember(node, symbolFlags, symbolExcludes); break; case 261 /* SourceFile */: if (ts.isExternalModule(container)) { declareModuleMember(node, symbolFlags, symbolExcludes); break; } // fall through. default: if (!blockScopeContainer.locals) { blockScopeContainer.locals = ts.createMap(); addToContainerChain(blockScopeContainer); } declareSymbol(blockScopeContainer.locals, undefined, node, symbolFlags, symbolExcludes); } }
forEach:
(array, callback) { if (array) { for (var i = 0, len = array.length; i < len; i++) { var result = callback(array[i], i); if (result) { return result; } } } return undefined; }
Deopt: <JS Function isDynamicName (SharedFunctionInfo 0x2c75c4ad29c1)> (opt #201) @2, FP to SP delta: 24, caller sp: 0x7fff5fbfd690
Deopt: <JS Function forEachChild (SharedFunctionInfo 0x2c75c4af0811)> (opt #223) @314, FP to SP delta: 728, caller sp: 0x7fff5fbfd720
Deopt: <JS Function addDeclarationToSymbol (SharedFunctionInfo 0x2142bdb58c41)> (opt #224) @30, FP to SP delta: 48, caller sp: 0x7fff5fbfd5d8
Deopt: <JS Function forEachChild (SharedFunctionInfo 0x2c75c4af0811)> (opt #223) @134, FP to SP delta: 728, caller sp: 0x7fff5fbfdc90
(array, callback) { if (array) { for (var i = 0, len = array.length; i < len; i++) { var result = callback(array[i], i); if (result) { return result; } } } return undefined; }
bindContainer:
(node, containerFlags) { // Before we recurse into a node's children, 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 saveContainer = container; var savedBlockScopeContainer = blockScopeContainer; // 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 accidentally move any stale data forward from // a previous compilation. if (containerFlags & 1 /* IsContainer */) { container = blockScopeContainer = node; if (containerFlags & 32 /* HasLocals */) { container.locals = ts.createMap(); } addToContainerChain(container); } else if (containerFlags & 2 /* IsBlockScopedContainer */) { blockScopeContainer = node; blockScopeContainer.locals = undefined; } if (containerFlags & 4 /* IsControlFlowContainer */) { var saveCurrentFlow = currentFlow; var saveBreakTarget = currentBreakTarget; var saveContinueTarget = currentContinueTarget; var saveReturnTarget = currentReturnTarget; var saveActiveLabels = activeLabels; var saveHasExplicitReturn = hasExplicitReturn; var isIIFE = containerFlags & 16 /* IsFunctionExpression */ && !ts.hasModifier(node, 256 /* Async */) && !!ts.getImmediatelyInvokedFunctionExpression(node); // A non-async IIFE is considered part of the containing control flow. Return statements behave // similarly to break statements that exit to a label just past the statement body. if (isIIFE) { currentReturnTarget = createBranchLabel(); } else { currentFlow = { flags: 2 /* Start */ }; if (containerFlags & (16 /* IsFunctionExpression */ | 128 /* IsObjectLiteralOrClassExpressionMethod */)) { currentFlow.container = node; } currentReturnTarget = undefined; } currentBreakTarget = undefined; currentContinueTarget = undefined; activeLabels = undefined; hasExplicitReturn = false; bindChildren(node); // Reset all reachability check related flags on node (for incremental scenarios) node.flags &= ~1408 /* ReachabilityAndEmitFlags */; if (!(currentFlow.flags & 1 /* Unreachable */) && containerFlags & 8 /* IsFunctionLike */ && ts.nodeIsPresent(node.body)) { node.flags |= 128 /* HasImplicitReturn */; if (hasExplicitReturn) node.flags |= 256 /* HasExplicitReturn */; } if (node.kind === 261 /* SourceFile */) { node.flags |= emitFlags; } if (isIIFE) { addAntecedent(currentReturnTarget, currentFlow); currentFlow = finishFlowLabel(currentReturnTarget); } else { currentFlow = saveCurrentFlow; } currentBreakTarget = saveBreakTarget; currentContinueTarget = saveContinueTarget; currentReturnTarget = saveReturnTarget; activeLabels = saveActiveLabels; hasExplicitReturn = saveHasExplicitReturn; } else if (containerFlags & 64 /* IsInterface */) { seenThisKeyword = false; bindChildren(node); node.flags = seenThisKeyword ? node.flags | 64 /* ContainsThis */ : node.flags & ~64 /* ContainsThis */; } else { bindChildren(node); } container = saveContainer; blockScopeContainer = savedBlockScopeContainer; }
(node, containerFlags) { // Before we recurse into a node's children, 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 saveContainer = container; var savedBlockScopeContainer = blockScopeContainer; // 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 accidentally move any stale data forward from // a previous compilation. if (containerFlags & 1 /* IsContainer */) { container = blockScopeContainer = node; if (containerFlags & 32 /* HasLocals */) { container.locals = ts.createMap(); } addToContainerChain(container); } else if (containerFlags & 2 /* IsBlockScopedContainer */) { blockScopeContainer = node; blockScopeContainer.locals = undefined; } if (containerFlags & 4 /* IsControlFlowContainer */) { var saveCurrentFlow = currentFlow; var saveBreakTarget = currentBreakTarget; var saveContinueTarget = currentContinueTarget; var saveReturnTarget = currentReturnTarget; var saveActiveLabels = activeLabels; var saveHasExplicitReturn = hasExplicitReturn; var isIIFE = containerFlags & 16 /* IsFunctionExpression */ && !ts.hasModifier(node, 256 /* Async */) && !!ts.getImmediatelyInvokedFunctionExpression(node); // A non-async IIFE is considered part of the containing control flow. Return statements behave // similarly to break statements that exit to a label just past the statement body. if (isIIFE) { currentReturnTarget = createBranchLabel(); } else { currentFlow = { flags: 2 /* Start */ }; if (containerFlags & (16 /* IsFunctionExpression */ | 128 /* IsObjectLiteralOrClassExpressionMethod */)) { currentFlow.container = node; } currentReturnTarget = undefined; } currentBreakTarget = undefined; currentContinueTarget = undefined; activeLabels = undefined; hasExplicitReturn = false; bindChildren(node); // Reset all reachability check related flags on node (for incremental scenarios) node.flags &= ~1408 /* ReachabilityAndEmitFlags */; if (!(currentFlow.flags & 1 /* Unreachable */) && containerFlags & 8 /* IsFunctionLike */ && ts.nodeIsPresent(node.body)) { node.flags |= 128 /* HasImplicitReturn */; if (hasExplicitReturn) node.flags |= 256 /* HasExplicitReturn */; } if (node.kind === 261 /* SourceFile */) { node.flags |= emitFlags; } if (isIIFE) { addAntecedent(currentReturnTarget, currentFlow); currentFlow = finishFlowLabel(currentReturnTarget); } else { currentFlow = saveCurrentFlow; } currentBreakTarget = saveBreakTarget; currentContinueTarget = saveContinueTarget; currentReturnTarget = saveReturnTarget; activeLabels = saveActiveLabels; hasExplicitReturn = saveHasExplicitReturn; } else if (containerFlags & 64 /* IsInterface */) { seenThisKeyword = false; bindChildren(node); node.flags = seenThisKeyword ? node.flags | 64 /* ContainsThis */ : node.flags & ~64 /* ContainsThis */; } else { bindChildren(node); } container = saveContainer; blockScopeContainer = savedBlockScopeContainer; }
skipPartiallyEmittedExpressions:
(node) { while (node.kind === 294 /* PartiallyEmittedExpression */) { node = node.expression; } return node; }
Deopt: <JS Function forEachChild (SharedFunctionInfo 0x2c75c4af0811)> (opt #230) @206, FP to SP delta: 744, caller sp: 0x7fff5fbfcd80
Deopt: <JS Function forEachChild (SharedFunctionInfo 0x2c75c4af0811)> (opt #230) @378, FP to SP delta: 744, caller sp: 0x7fff5fbfd188
Deopt: <JS Function forEachChild (SharedFunctionInfo 0x2c75c4af0811)> (opt #230) @313, FP to SP delta: 744, caller sp: 0x7fff5fbfd680
bindVariableDeclarationOrBindingElement:
(node) { if (inStrictMode) { checkStrictModeEvalOrArguments(node, node.name); } if (!ts.isBindingPattern(node.name)) { if (ts.isBlockOrCatchScoped(node)) { bindBlockScopedVariableDeclaration(node); } else if (ts.isParameterDeclaration(node)) { // It is safe to walk up parent chain to find whether the node is a destructing parameter declaration // because its parent chain has already been set up, since parents are set before descending into children. // // If node is a binding element in parameter declaration, we need to use ParameterExcludes. // Using ParameterExcludes flag allows the compiler to report an error on duplicate identifiers in Parameter Declaration // For example: // function foo([a,a]) {} // Duplicate Identifier error // function bar(a,a) {} // Duplicate Identifier error, parameter declaration in this case is handled in bindParameter // // which correctly set excluded symbols declareSymbolAndAddToSymbolTable(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */); } else { declareSymbolAndAddToSymbolTable(node, 1 /* FunctionScopedVariable */, 107454 /* FunctionScopedVariableExcludes */); } } }
isBlockOrCatchScoped:
(declaration) { return (ts.getCombinedNodeFlags(declaration) & 3 /* BlockScoped */) !== 0 || isCatchClauseVariableDeclarationOrBindingElement(declaration); }
getCombinedNodeFlags:
(node) { node = walkUpBindingElementsAndPatterns(node); var flags = node.flags; if (node.kind === 223 /* VariableDeclaration */) { node = node.parent; } if (node && node.kind === 224 /* VariableDeclarationList */) { flags |= node.flags; node = node.parent; } if (node && node.kind === 205 /* VariableStatement */) { flags |= node.flags; } return flags; }
(node) { node = walkUpBindingElementsAndPatterns(node); var flags = node.flags; if (node.kind === 223 /* VariableDeclaration */) { node = node.parent; } if (node && node.kind === 224 /* VariableDeclarationList */) { flags |= node.flags; node = node.parent; } if (node && node.kind === 205 /* VariableStatement */) { flags |= node.flags; } return flags; }
(node) { node = walkUpBindingElementsAndPatterns(node); var flags = node.flags; if (node.kind === 223 /* VariableDeclaration */) { node = node.parent; } if (node && node.kind === 224 /* VariableDeclarationList */) { flags |= node.flags; node = node.parent; } if (node && node.kind === 205 /* VariableStatement */) { flags |= node.flags; } return flags; }
(node) { node = walkUpBindingElementsAndPatterns(node); var flags = node.flags; if (node.kind === 223 /* VariableDeclaration */) { node = node.parent; } if (node && node.kind === 224 /* VariableDeclarationList */) { flags |= node.flags; node = node.parent; } if (node && node.kind === 205 /* VariableStatement */) { flags |= node.flags; } return flags; }
createMap:
(template) { var map = createObject(null); // tslint:disable-line:no-null-keyword // Using 'delete' on an object causes V8 to put the object in dictionary mode. // This disables creation of hidden classes, which are expensive when an object is // constantly changing shape. map["__"] = undefined; delete map["__"]; // Copies keys/values from template. Note that for..in will not throw if // template is undefined, and instead will just exit the loop. for (var key in template) if (hasOwnProperty.call(template, key)) { map[key] = template[key]; } return map; }
Deopt: <JS Function createMap (SharedFunctionInfo 0x3735bafe0bb9)> (opt #239) @20, FP to SP delta: 72, caller sp: 0x7fff5fbfdb28
(template) { var map = createObject(null); // tslint:disable-line:no-null-keyword // Using 'delete' on an object causes V8 to put the object in dictionary mode. // This disables creation of hidden classes, which are expensive when an object is // constantly changing shape. map["__"] = undefined; delete map["__"]; // Copies keys/values from template. Note that for..in will not throw if // template is undefined, and instead will just exit the loop. for (var key in template) if (hasOwnProperty.call(template, key)) { map[key] = template[key]; } return map; }
Deopt: <JS Function createMap (SharedFunctionInfo 0x3735bafe0bb9)> (opt #266) @20, FP to SP delta: 72, caller sp: 0x7fff5fbfd510
(template) { var map = createObject(null); // tslint:disable-line:no-null-keyword // Using 'delete' on an object causes V8 to put the object in dictionary mode. // This disables creation of hidden classes, which are expensive when an object is // constantly changing shape. map["__"] = undefined; delete map["__"]; // Copies keys/values from template. Note that for..in will not throw if // template is undefined, and instead will just exit the loop. for (var key in template) if (hasOwnProperty.call(template, key)) { map[key] = template[key]; } return map; }
Deopt: <JS Function createMap (SharedFunctionInfo 0x3735bafe0bb9)> (opt #514) @20, FP to SP delta: 72, caller sp: 0x7fff5fbfdbd8
isParameterDeclaration:
(node) { var root = getRootDeclaration(node); return root.kind === 144 /* Parameter */; }
(node) { var root = getRootDeclaration(node); return root.kind === 144 /* Parameter */; }
checkUnreachable:
(node) { if (!(currentFlow.flags & 1 /* Unreachable */)) { return false; } if (currentFlow === unreachableFlow) { var reportError = // report error on all statements except empty ones (ts.isStatementButNotDeclaration(node) && node.kind !== 206 /* EmptyStatement */) || // report error on class declarations node.kind === 226 /* ClassDeclaration */ || // report error on instantiated modules or const-enums only modules if preserveConstEnums is set (node.kind === 230 /* ModuleDeclaration */ && shouldReportErrorOnModuleDeclaration(node)) || // report error on regular enums and const enums if preserveConstEnums is set (node.kind === 229 /* EnumDeclaration */ && (!ts.isConstEnumDeclaration(node) || options.preserveConstEnums)); if (reportError) { currentFlow = reportedUnreachableFlow; // unreachable code is reported if // - user has explicitly asked about it AND // - statement is in not ambient context (statements in ambient context is already an error // so we should not report extras) AND // - node is not variable statement OR // - node is block scoped variable statement OR // - node is not block scoped variable statement and at least one variable declaration has initializer // Rationale: we don't want to report errors on non-initialized var's since they are hoisted // On the other side we do want to report errors on non-initialized 'lets' because of TDZ var reportUnreachableCode = !options.allowUnreachableCode && !ts.isInAmbientContext(node) && (node.kind !== 205 /* VariableStatement */ || ts.getCombinedNodeFlags(node.declarationList) & 3 /* BlockScoped */ || ts.forEach(node.declarationList.declarations, function (d) { return d.initializer; })); if (reportUnreachableCode) { errorOnFirstToken(node, ts.Diagnostics.Unreachable_code_detected); } } } return true; }
bindChildren:
(node) { if (skipTransformFlagAggregation) { bindChildrenWorker(node); } else if (node.transformFlags & 536870912 /* HasComputedFlags */) { skipTransformFlagAggregation = true; bindChildrenWorker(node); skipTransformFlagAggregation = false; subtreeTransformFlags |= node.transformFlags & ~getTransformFlagsSubtreeExclusions(node.kind); } else { var savedSubtreeTransformFlags = subtreeTransformFlags; subtreeTransformFlags = 0; bindChildrenWorker(node); subtreeTransformFlags = savedSubtreeTransformFlags | computeTransformFlagsForNode(node, subtreeTransformFlags); } }
hasDynamicName:
(declaration) { return declaration.name && isDynamicName(declaration.name); }
getModifierFlags:
(node) { if (node.modifierFlagsCache & 536870912 /* HasComputedFlags */) { return node.modifierFlagsCache & ~536870912 /* HasComputedFlags */; } var flags = 0 /* None */; if (node.modifiers) { for (var _i = 0, _a = node.modifiers; _i < _a.length; _i++) { var modifier = _a[_i]; flags |= modifierToFlag(modifier.kind); } } if (node.flags & 4 /* NestedNamespace */ || (node.kind === 70 /* Identifier */ && node.isInJSDocNamespace)) { flags |= 1 /* Export */; } node.modifierFlagsCache = flags | 536870912 /* HasComputedFlags */; return flags; }
checkStrictModeIdentifier:
(node) { if (inStrictMode && node.originalKeywordKind >= 107 /* FirstFutureReservedWord */ && node.originalKeywordKind <= 115 /* LastFutureReservedWord */ && !ts.isIdentifierName(node) && !ts.isInAmbientContext(node)) { // Report error only if there are no parse errors in file if (!file.parseDiagnostics.length) { file.bindDiagnostics.push(ts.createDiagnosticForNode(node, getStrictModeIdentifierMessage(node), ts.declarationNameToString(node))); } } }
Deopt: <JS Function forEachChild (SharedFunctionInfo 0x2c75c4af0811)> (opt #234) @264, FP to SP delta: 752, caller sp: 0x7fff5fbfd350
Deopt: <JS Function forEachChild (SharedFunctionInfo 0x2c75c4af0811)> (opt #234) @380, FP to SP delta: 752, caller sp: 0x7fff5fbfd758
Deopt: <JS Function forEachChild (SharedFunctionInfo 0x2c75c4af0811)> (opt #234) @132, FP to SP delta: 752, caller sp: 0x7fff5fbfdc50
getDeclarationName:
(node) { if (node.name) { if (ts.isAmbientModule(node)) { return ts.isGlobalScopeAugmentation(node) ? "__global" : "\x5c"" + node.name.text + "\x5c""; } if (node.name.kind === 142 /* ComputedPropertyName */) { var nameExpression = node.name.expression; // treat computed property names where expression is string/numeric literal as just string/numeric literal if (ts.isStringOrNumericLiteral(nameExpression)) { return nameExpression.text; } ts.Debug.assert(ts.isWellKnownSymbolSyntactically(nameExpression)); return ts.getPropertyNameForKnownSymbolName(nameExpression.name.text); } return node.name.text; } switch (node.kind) { case 150 /* Constructor */: return "__constructor"; case 158 /* FunctionType */: case 153 /* CallSignature */: return "__call"; case 159 /* ConstructorType */: case 154 /* ConstructSignature */: return "__new"; case 155 /* IndexSignature */: return "__index"; case 241 /* ExportDeclaration */: return "__export"; case 240 /* ExportAssignment */: return node.isExportEquals ? "export=" : "default"; case 192 /* BinaryExpression */: switch (ts.getSpecialPropertyAssignmentKind(node)) { case 2 /* ModuleExports */: // module.exports = ... return "export="; case 1 /* ExportsProperty */: case 4 /* ThisProperty */: // exports.x = ... or this.y = ... return node.left.name.text; case 3 /* PrototypeProperty */: // className.prototype.methodName = ... return node.left.expression.name.text; } ts.Debug.fail("Unknown binary declaration kind"); break; case 225 /* FunctionDeclaration */: case 226 /* ClassDeclaration */: return ts.hasModifier(node, 512 /* Default */) ? "default" : undefined; case 274 /* JSDocFunctionType */: return ts.isJSDocConstructSignature(node) ? "__new" : "__call"; case 144 /* Parameter */: // Parameters with names are handled at the top of this function. Parameters // without names can only come from JSDocFunctionTypes. ts.Debug.assert(node.parent.kind === 274 /* JSDocFunctionType */); var functionType = node.parent; var index = ts.indexOf(functionType.parameters, node); return "arg" + index; case 285 /* JSDocTypedefTag */: var parentNode = node.parent && node.parent.parent; var nameFromParentNode = void 0; if (parentNode && parentNode.kind === 205 /* VariableStatement */) { if (parentNode.declarationList.declarations.length > 0) { var nameIdentifier = parentNode.declarationList.declarations[0].name; if (nameIdentifier.kind === 70 /* Identifier */) { nameFromParentNode = nameIdentifier.text; } } } return nameFromParentNode; } }
Deopt: <JS Function forEachChild (SharedFunctionInfo 0x2c75c4af0811)> (opt #246) @289, FP to SP delta: 752, caller sp: 0x7fff5fbfdc50
visitNode:
(cbNode, node) { if (node) { return cbNode(node); } }
Deopt: <JS Function addDeclarationToSymbol (SharedFunctionInfo 0x2142bdb58c41)> (opt #232) @30, FP to SP delta: 48, caller sp: 0x7fff5fbfdb40
checkStrictModeEvalOrArguments:
(contextNode, name) { if (name && name.kind === 70 /* Identifier */) { var identifier = name; if (isEvalOrArgumentsIdentifier(identifier)) { // We check first if the name is inside class declaration or class expression; if so give explicit message // otherwise report generic error message. var span_3 = ts.getErrorSpanForNode(file, name); file.bindDiagnostics.push(ts.createFileDiagnostic(file, span_3.start, span_3.length, getStrictModeEvalOrArgumentsMessage(contextNode), identifier.text)); } } }
getCombinedModifierFlags:
(node) { node = walkUpBindingElementsAndPatterns(node); var flags = ts.getModifierFlags(node); if (node.kind === 223 /* VariableDeclaration */) { node = node.parent; } if (node && node.kind === 224 /* VariableDeclarationList */) { flags |= ts.getModifierFlags(node); node = node.parent; } if (node && node.kind === 205 /* VariableStatement */) { flags |= ts.getModifierFlags(node); } return flags; }
(node) { node = walkUpBindingElementsAndPatterns(node); var flags = ts.getModifierFlags(node); if (node.kind === 223 /* VariableDeclaration */) { node = node.parent; } if (node && node.kind === 224 /* VariableDeclarationList */) { flags |= ts.getModifierFlags(node); node = node.parent; } if (node && node.kind === 205 /* VariableStatement */) { flags |= ts.getModifierFlags(node); } return flags; }
bindFunctionDeclaration:
(node) { if (!ts.isDeclarationFile(file) && !ts.isInAmbientContext(node)) { if (ts.isAsyncFunctionLike(node)) { emitFlags |= 1024 /* HasAsyncFunctions */; } } checkStrictModeFunctionName(node); if (inStrictMode) { checkStrictModeFunctionDeclaration(node); bindBlockScopedDeclaration(node, 16 /* Function */, 106927 /* FunctionExcludes */); } else { declareSymbolAndAddToSymbolTable(node, 16 /* Function */, 106927 /* FunctionExcludes */); } }
declareModuleMember:
(node, symbolFlags, symbolExcludes) { var hasExportModifier = ts.getCombinedModifierFlags(node) & 1 /* Export */; if (symbolFlags & 8388608 /* Alias */) { if (node.kind === 243 /* ExportSpecifier */ || (node.kind === 234 /* ImportEqualsDeclaration */ && hasExportModifier)) { return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); } else { return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } } else { // Exported module members are given 2 symbols: A local symbol that is classified with an ExportValue, // ExportType, or ExportContainer flag, and an associated export symbol with all the correct flags set // on it. There are 2 main reasons: // // 1. We treat locals and exports of the same name as mutually exclusive within a container. // That means the binder will issue a Duplicate Identifier error if you mix locals and exports // with the same name in the same container. // TODO: Make this a more specific error and decouple it from the exclusion logic. // 2. When we checkIdentifier in the checker, we set its resolved symbol to the local symbol, // but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way // when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope. // NOTE: Nested ambient modules always should go to to 'locals' table to prevent their automatic merge // during global merging in the checker. Why? The only case when ambient module is permitted inside another module is module augmentation // and this case is specially handled. Module augmentations should only be merged with original module definition // and should never be merged directly with other augmentation, and the latter case would be possible if automatic merge is allowed. var isJSDocTypedefInJSDocNamespace = node.kind === 285 /* JSDocTypedefTag */ && node.name && node.name.kind === 70 /* Identifier */ && node.name.isInJSDocNamespace; if ((!ts.isAmbientModule(node) && (hasExportModifier || container.flags & 32 /* ExportContext */)) || isJSDocTypedefInJSDocNamespace) { var exportKind = (symbolFlags & 107455 /* Value */ ? 1048576 /* ExportValue */ : 0) | (symbolFlags & 793064 /* Type */ ? 2097152 /* ExportType */ : 0) | (symbolFlags & 1920 /* Namespace */ ? 4194304 /* ExportNamespace */ : 0); var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); node.localSymbol = local; return local; } else { return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } } }
Deopt: <JS Function isAmbientModule (SharedFunctionInfo 0x2c75c4acd741)> (opt #192) @4, FP to SP delta: 24, caller sp: 0x7fff5fbfcbf8
Deopt: <JS Function forEachChild (SharedFunctionInfo 0x2c75c4af0811)> (opt #271) @118, FP to SP delta: 776, caller sp: 0x7fff5fbfce60
Deopt: <JS Function getCombinedNodeFlags (SharedFunctionInfo 0x2c75c4adfaa9)> (opt #238) @16, FP to SP delta: 48, caller sp: 0x7fff5fbfc450
Deopt: <JS Function declareModuleMember (SharedFunctionInfo 0x2142bdb58f41)> (opt #272) @18, FP to SP delta: 72, caller sp: 0x7fff5fbfc440
(node, symbolFlags, symbolExcludes) { var hasExportModifier = ts.getCombinedModifierFlags(node) & 1 /* Export */; if (symbolFlags & 8388608 /* Alias */) { if (node.kind === 243 /* ExportSpecifier */ || (node.kind === 234 /* ImportEqualsDeclaration */ && hasExportModifier)) { return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); } else { return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } } else { // Exported module members are given 2 symbols: A local symbol that is classified with an ExportValue, // ExportType, or ExportContainer flag, and an associated export symbol with all the correct flags set // on it. There are 2 main reasons: // // 1. We treat locals and exports of the same name as mutually exclusive within a container. // That means the binder will issue a Duplicate Identifier error if you mix locals and exports // with the same name in the same container. // TODO: Make this a more specific error and decouple it from the exclusion logic. // 2. When we checkIdentifier in the checker, we set its resolved symbol to the local symbol, // but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way // when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope. // NOTE: Nested ambient modules always should go to to 'locals' table to prevent their automatic merge // during global merging in the checker. Why? The only case when ambient module is permitted inside another module is module augmentation // and this case is specially handled. Module augmentations should only be merged with original module definition // and should never be merged directly with other augmentation, and the latter case would be possible if automatic merge is allowed. var isJSDocTypedefInJSDocNamespace = node.kind === 285 /* JSDocTypedefTag */ && node.name && node.name.kind === 70 /* Identifier */ && node.name.isInJSDocNamespace; if ((!ts.isAmbientModule(node) && (hasExportModifier || container.flags & 32 /* ExportContext */)) || isJSDocTypedefInJSDocNamespace) { var exportKind = (symbolFlags & 107455 /* Value */ ? 1048576 /* ExportValue */ : 0) | (symbolFlags & 793064 /* Type */ ? 2097152 /* ExportType */ : 0) | (symbolFlags & 1920 /* Namespace */ ? 4194304 /* ExportNamespace */ : 0); var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); node.localSymbol = local; return local; } else { return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } } }
Deopt: <JS Function forEachChild (SharedFunctionInfo 0x2c75c4af0811)> (opt #249) @177, FP to SP delta: 752, caller sp: 0x7fff5fbfdf78
Deopt: <JS Function bindContainer (SharedFunctionInfo 0x2142bdb59001)> (opt #231) @25, FP to SP delta: 168, caller sp: 0x7fff5fbfe0e8
declareClassMember:
(node, symbolFlags, symbolExcludes) { return ts.hasModifier(node, 32 /* Static */) ? declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes) : declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); }
isDeclarationKind:
(kind) { return kind === 185 /* ArrowFunction */ || kind === 174 /* BindingElement */ || kind === 226 /* ClassDeclaration */ || kind === 197 /* ClassExpression */ || kind === 150 /* Constructor */ || kind === 229 /* EnumDeclaration */ || kind === 260 /* EnumMember */ || kind === 243 /* ExportSpecifier */ || kind === 225 /* FunctionDeclaration */ || kind === 184 /* FunctionExpression */ || kind === 151 /* GetAccessor */ || kind === 236 /* ImportClause */ || kind === 234 /* ImportEqualsDeclaration */ || kind === 239 /* ImportSpecifier */ || kind === 227 /* InterfaceDeclaration */ || kind === 149 /* MethodDeclaration */ || kind === 148 /* MethodSignature */ || kind === 230 /* ModuleDeclaration */ || kind === 233 /* NamespaceExportDeclaration */ || kind === 237 /* NamespaceImport */ || kind === 144 /* Parameter */ || kind === 257 /* PropertyAssignment */ || kind === 147 /* PropertyDeclaration */ || kind === 146 /* PropertySignature */ || kind === 152 /* SetAccessor */ || kind === 258 /* ShorthandPropertyAssignment */ || kind === 228 /* TypeAliasDeclaration */ || kind === 143 /* TypeParameter */ || kind === 223 /* VariableDeclaration */ || kind === 285 /* JSDocTypedefTag */; }
checkGrammarTopLevelElementForRequiredDeclareModifier:
(node) { // A declare modifier is required for any top level .d.ts declaration except export=, export default, export as namespace // interfaces and imports categories: // // DeclarationElement: // ExportAssignment // export_opt InterfaceDeclaration // export_opt TypeAliasDeclaration // export_opt ImportDeclaration // export_opt ExternalImportDeclaration // export_opt AmbientDeclaration // // TODO: The spec needs to be amended to reflect this grammar. if (node.kind === 227 /* InterfaceDeclaration */ || node.kind === 228 /* TypeAliasDeclaration */ || node.kind === 235 /* ImportDeclaration */ || node.kind === 234 /* ImportEqualsDeclaration */ || node.kind === 241 /* ExportDeclaration */ || node.kind === 240 /* ExportAssignment */ || node.kind === 233 /* NamespaceExportDeclaration */ || ts.getModifierFlags(node) & (2 /* Ambient */ | 1 /* Export */ | 512 /* Default */)) { return false; } return grammarErrorOnFirstToken(node, ts.Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file); }
Deopt: <JS Function checkGrammarTopLevelElementForRequiredDeclareModifier (SharedFunctionInfo 0x3fca5861ad11)> (opt #286) @4, FP to SP delta: 32, caller sp: 0x7fff5fbfe0d0
Deopt: <JS Function hasDynamicName (SharedFunctionInfo 0x2c75c4ad2901)> (opt #243) @6, FP to SP delta: 32, caller sp: 0x7fff5fbfdfe0
Deopt: <JS Function forEach (SharedFunctionInfo 0x3735bafe0df9)> (opt #227) @8, FP to SP delta: 40, caller sp: 0x7fff5fbfdfe0
Deopt: <JS Function forEach (SharedFunctionInfo 0x3735bafe0df9)> (opt #227) @7, FP to SP delta: 40, caller sp: 0x7fff5fbfe158
Deopt: <JS Function isDynamicName (SharedFunctionInfo 0x2c75c4ad29c1)> (opt #228) @2, FP to SP delta: 24, caller sp: 0x7fff5fbfdfa0
getMergedSymbol:
(symbol) { var merged; return symbol && symbol.mergeId && (merged = mergedSymbols[symbol.mergeId]) ? merged : symbol; }
(symbol) { var merged; return symbol && symbol.mergeId && (merged = mergedSymbols[symbol.mergeId]) ? merged : symbol; }
getSymbolId:
(symbol) { if (!symbol.id) { symbol.id = nextSymbolId; nextSymbolId++; } return symbol.id; }
reportObviousModifierErrors:
(node) { return !node.modifiers ? false : shouldReportBadModifier(node) ? grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here) : undefined; }
checkSourceElement:
(node) { if (!node) { return; } var kind = node.kind; if (cancellationToken) { // Only bother checking on a few construct kinds. We don't want to be excessively // hitting the cancellation token on every node we check. switch (kind) { case 230 /* ModuleDeclaration */: case 226 /* ClassDeclaration */: case 227 /* InterfaceDeclaration */: case 225 /* FunctionDeclaration */: cancellationToken.throwIfCancellationRequested(); } } switch (kind) { case 143 /* TypeParameter */: return checkTypeParameter(node); case 144 /* Parameter */: return checkParameter(node); case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: return checkPropertyDeclaration(node); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: return checkSignatureDeclaration(node); case 155 /* IndexSignature */: return checkSignatureDeclaration(node); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: return checkMethodDeclaration(node); case 150 /* Constructor */: return checkConstructorDeclaration(node); case 151 /* GetAccessor */: case 152 /* SetAccessor */: return checkAccessorDeclaration(node); case 157 /* TypeReference */: return checkTypeReferenceNode(node); case 156 /* TypePredicate */: return checkTypePredicate(node); case 160 /* TypeQuery */: return checkTypeQuery(node); case 161 /* TypeLiteral */: return checkTypeLiteral(node); case 162 /* ArrayType */: return checkArrayType(node); case 163 /* TupleType */: return checkTupleType(node); case 164 /* UnionType */: case 165 /* IntersectionType */: return checkUnionOrIntersectionType(node); case 166 /* ParenthesizedType */: case 168 /* TypeOperator */: return checkSourceElement(node.type); case 169 /* IndexedAccessType */: return checkIndexedAccessType(node); case 170 /* MappedType */: return checkMappedType(node); case 225 /* FunctionDeclaration */: return checkFunctionDeclaration(node); case 204 /* Block */: case 231 /* ModuleBlock */: return checkBlock(node); case 205 /* VariableStatement */: return checkVariableStatement(node); case 207 /* ExpressionStatement */: return checkExpressionStatement(node); case 208 /* IfStatement */: return checkIfStatement(node); case 209 /* DoStatement */: return checkDoStatement(node); case 210 /* WhileStatement */: return checkWhileStatement(node); case 211 /* ForStatement */: return checkForStatement(node); case 212 /* ForInStatement */: return checkForInStatement(node); case 213 /* ForOfStatement */: return checkForOfStatement(node); case 214 /* ContinueStatement */: case 215 /* BreakStatement */: return checkBreakOrContinueStatement(node); case 216 /* ReturnStatement */: return checkReturnStatement(node); case 217 /* WithStatement */: return checkWithStatement(node); case 218 /* SwitchStatement */: return checkSwitchStatement(node); case 219 /* LabeledStatement */: return checkLabeledStatement(node); case 220 /* ThrowStatement */: return checkThrowStatement(node); case 221 /* TryStatement */: return checkTryStatement(node); case 223 /* VariableDeclaration */: return checkVariableDeclaration(node); case 174 /* BindingElement */: return checkBindingElement(node); case 226 /* ClassDeclaration */: return checkClassDeclaration(node); case 227 /* InterfaceDeclaration */: return checkInterfaceDeclaration(node); case 228 /* TypeAliasDeclaration */: return checkTypeAliasDeclaration(node); case 229 /* EnumDeclaration */: return checkEnumDeclaration(node); case 230 /* ModuleDeclaration */: return checkModuleDeclaration(node); case 235 /* ImportDeclaration */: return checkImportDeclaration(node); case 234 /* ImportEqualsDeclaration */: return checkImportEqualsDeclaration(node); case 241 /* ExportDeclaration */: return checkExportDeclaration(node); case 240 /* ExportAssignment */: return checkExportAssignment(node); case 206 /* EmptyStatement */: checkGrammarStatementInAmbientContext(node); return; case 222 /* DebuggerStatement */: checkGrammarStatementInAmbientContext(node); return; case 244 /* MissingDeclaration */: return checkMissingDeclaration(node); } }
(node) { if (!node) { return; } var kind = node.kind; if (cancellationToken) { // Only bother checking on a few construct kinds. We don't want to be excessively // hitting the cancellation token on every node we check. switch (kind) { case 230 /* ModuleDeclaration */: case 226 /* ClassDeclaration */: case 227 /* InterfaceDeclaration */: case 225 /* FunctionDeclaration */: cancellationToken.throwIfCancellationRequested(); } } switch (kind) { case 143 /* TypeParameter */: return checkTypeParameter(node); case 144 /* Parameter */: return checkParameter(node); case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: return checkPropertyDeclaration(node); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: return checkSignatureDeclaration(node); case 155 /* IndexSignature */: return checkSignatureDeclaration(node); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: return checkMethodDeclaration(node); case 150 /* Constructor */: return checkConstructorDeclaration(node); case 151 /* GetAccessor */: case 152 /* SetAccessor */: return checkAccessorDeclaration(node); case 157 /* TypeReference */: return checkTypeReferenceNode(node); case 156 /* TypePredicate */: return checkTypePredicate(node); case 160 /* TypeQuery */: return checkTypeQuery(node); case 161 /* TypeLiteral */: return checkTypeLiteral(node); case 162 /* ArrayType */: return checkArrayType(node); case 163 /* TupleType */: return checkTupleType(node); case 164 /* UnionType */: case 165 /* IntersectionType */: return checkUnionOrIntersectionType(node); case 166 /* ParenthesizedType */: case 168 /* TypeOperator */: return checkSourceElement(node.type); case 169 /* IndexedAccessType */: return checkIndexedAccessType(node); case 170 /* MappedType */: return checkMappedType(node); case 225 /* FunctionDeclaration */: return checkFunctionDeclaration(node); case 204 /* Block */: case 231 /* ModuleBlock */: return checkBlock(node); case 205 /* VariableStatement */: return checkVariableStatement(node); case 207 /* ExpressionStatement */: return checkExpressionStatement(node); case 208 /* IfStatement */: return checkIfStatement(node); case 209 /* DoStatement */: return checkDoStatement(node); case 210 /* WhileStatement */: return checkWhileStatement(node); case 211 /* ForStatement */: return checkForStatement(node); case 212 /* ForInStatement */: return checkForInStatement(node); case 213 /* ForOfStatement */: return checkForOfStatement(node); case 214 /* ContinueStatement */: case 215 /* BreakStatement */: return checkBreakOrContinueStatement(node); case 216 /* ReturnStatement */: return checkReturnStatement(node); case 217 /* WithStatement */: return checkWithStatement(node); case 218 /* SwitchStatement */: return checkSwitchStatement(node); case 219 /* LabeledStatement */: return checkLabeledStatement(node); case 220 /* ThrowStatement */: return checkThrowStatement(node); case 221 /* TryStatement */: return checkTryStatement(node); case 223 /* VariableDeclaration */: return checkVariableDeclaration(node); case 174 /* BindingElement */: return checkBindingElement(node); case 226 /* ClassDeclaration */: return checkClassDeclaration(node); case 227 /* InterfaceDeclaration */: return checkInterfaceDeclaration(node); case 228 /* TypeAliasDeclaration */: return checkTypeAliasDeclaration(node); case 229 /* EnumDeclaration */: return checkEnumDeclaration(node); case 230 /* ModuleDeclaration */: return checkModuleDeclaration(node); case 235 /* ImportDeclaration */: return checkImportDeclaration(node); case 234 /* ImportEqualsDeclaration */: return checkImportEqualsDeclaration(node); case 241 /* ExportDeclaration */: return checkExportDeclaration(node); case 240 /* ExportAssignment */: return checkExportAssignment(node); case 206 /* EmptyStatement */: checkGrammarStatementInAmbientContext(node); return; case 222 /* DebuggerStatement */: checkGrammarStatementInAmbientContext(node); return; case 244 /* MissingDeclaration */: return checkMissingDeclaration(node); } }
(node) { if (!node) { return; } var kind = node.kind; if (cancellationToken) { // Only bother checking on a few construct kinds. We don't want to be excessively // hitting the cancellation token on every node we check. switch (kind) { case 230 /* ModuleDeclaration */: case 226 /* ClassDeclaration */: case 227 /* InterfaceDeclaration */: case 225 /* FunctionDeclaration */: cancellationToken.throwIfCancellationRequested(); } } switch (kind) { case 143 /* TypeParameter */: return checkTypeParameter(node); case 144 /* Parameter */: return checkParameter(node); case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: return checkPropertyDeclaration(node); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: return checkSignatureDeclaration(node); case 155 /* IndexSignature */: return checkSignatureDeclaration(node); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: return checkMethodDeclaration(node); case 150 /* Constructor */: return checkConstructorDeclaration(node); case 151 /* GetAccessor */: case 152 /* SetAccessor */: return checkAccessorDeclaration(node); case 157 /* TypeReference */: return checkTypeReferenceNode(node); case 156 /* TypePredicate */: return checkTypePredicate(node); case 160 /* TypeQuery */: return checkTypeQuery(node); case 161 /* TypeLiteral */: return checkTypeLiteral(node); case 162 /* ArrayType */: return checkArrayType(node); case 163 /* TupleType */: return checkTupleType(node); case 164 /* UnionType */: case 165 /* IntersectionType */: return checkUnionOrIntersectionType(node); case 166 /* ParenthesizedType */: case 168 /* TypeOperator */: return checkSourceElement(node.type); case 169 /* IndexedAccessType */: return checkIndexedAccessType(node); case 170 /* MappedType */: return checkMappedType(node); case 225 /* FunctionDeclaration */: return checkFunctionDeclaration(node); case 204 /* Block */: case 231 /* ModuleBlock */: return checkBlock(node); case 205 /* VariableStatement */: return checkVariableStatement(node); case 207 /* ExpressionStatement */: return checkExpressionStatement(node); case 208 /* IfStatement */: return checkIfStatement(node); case 209 /* DoStatement */: return checkDoStatement(node); case 210 /* WhileStatement */: return checkWhileStatement(node); case 211 /* ForStatement */: return checkForStatement(node); case 212 /* ForInStatement */: return checkForInStatement(node); case 213 /* ForOfStatement */: return checkForOfStatement(node); case 214 /* ContinueStatement */: case 215 /* BreakStatement */: return checkBreakOrContinueStatement(node); case 216 /* ReturnStatement */: return checkReturnStatement(node); case 217 /* WithStatement */: return checkWithStatement(node); case 218 /* SwitchStatement */: return checkSwitchStatement(node); case 219 /* LabeledStatement */: return checkLabeledStatement(node); case 220 /* ThrowStatement */: return checkThrowStatement(node); case 221 /* TryStatement */: return checkTryStatement(node); case 223 /* VariableDeclaration */: return checkVariableDeclaration(node); case 174 /* BindingElement */: return checkBindingElement(node); case 226 /* ClassDeclaration */: return checkClassDeclaration(node); case 227 /* InterfaceDeclaration */: return checkInterfaceDeclaration(node); case 228 /* TypeAliasDeclaration */: return checkTypeAliasDeclaration(node); case 229 /* EnumDeclaration */: return checkEnumDeclaration(node); case 230 /* ModuleDeclaration */: return checkModuleDeclaration(node); case 235 /* ImportDeclaration */: return checkImportDeclaration(node); case 234 /* ImportEqualsDeclaration */: return checkImportEqualsDeclaration(node); case 241 /* ExportDeclaration */: return checkExportDeclaration(node); case 240 /* ExportAssignment */: return checkExportAssignment(node); case 206 /* EmptyStatement */: checkGrammarStatementInAmbientContext(node); return; case 222 /* DebuggerStatement */: checkGrammarStatementInAmbientContext(node); return; case 244 /* MissingDeclaration */: return checkMissingDeclaration(node); } }
(node) { if (!node) { return; } var kind = node.kind; if (cancellationToken) { // Only bother checking on a few construct kinds. We don't want to be excessively // hitting the cancellation token on every node we check. switch (kind) { case 230 /* ModuleDeclaration */: case 226 /* ClassDeclaration */: case 227 /* InterfaceDeclaration */: case 225 /* FunctionDeclaration */: cancellationToken.throwIfCancellationRequested(); } } switch (kind) { case 143 /* TypeParameter */: return checkTypeParameter(node); case 144 /* Parameter */: return checkParameter(node); case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: return checkPropertyDeclaration(node); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: return checkSignatureDeclaration(node); case 155 /* IndexSignature */: return checkSignatureDeclaration(node); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: return checkMethodDeclaration(node); case 150 /* Constructor */: return checkConstructorDeclaration(node); case 151 /* GetAccessor */: case 152 /* SetAccessor */: return checkAccessorDeclaration(node); case 157 /* TypeReference */: return checkTypeReferenceNode(node); case 156 /* TypePredicate */: return checkTypePredicate(node); case 160 /* TypeQuery */: return checkTypeQuery(node); case 161 /* TypeLiteral */: return checkTypeLiteral(node); case 162 /* ArrayType */: return checkArrayType(node); case 163 /* TupleType */: return checkTupleType(node); case 164 /* UnionType */: case 165 /* IntersectionType */: return checkUnionOrIntersectionType(node); case 166 /* ParenthesizedType */: case 168 /* TypeOperator */: return checkSourceElement(node.type); case 169 /* IndexedAccessType */: return checkIndexedAccessType(node); case 170 /* MappedType */: return checkMappedType(node); case 225 /* FunctionDeclaration */: return checkFunctionDeclaration(node); case 204 /* Block */: case 231 /* ModuleBlock */: return checkBlock(node); case 205 /* VariableStatement */: return checkVariableStatement(node); case 207 /* ExpressionStatement */: return checkExpressionStatement(node); case 208 /* IfStatement */: return checkIfStatement(node); case 209 /* DoStatement */: return checkDoStatement(node); case 210 /* WhileStatement */: return checkWhileStatement(node); case 211 /* ForStatement */: return checkForStatement(node); case 212 /* ForInStatement */: return checkForInStatement(node); case 213 /* ForOfStatement */: return checkForOfStatement(node); case 214 /* ContinueStatement */: case 215 /* BreakStatement */: return checkBreakOrContinueStatement(node); case 216 /* ReturnStatement */: return checkReturnStatement(node); case 217 /* WithStatement */: return checkWithStatement(node); case 218 /* SwitchStatement */: return checkSwitchStatement(node); case 219 /* LabeledStatement */: return checkLabeledStatement(node); case 220 /* ThrowStatement */: return checkThrowStatement(node); case 221 /* TryStatement */: return checkTryStatement(node); case 223 /* VariableDeclaration */: return checkVariableDeclaration(node); case 174 /* BindingElement */: return checkBindingElement(node); case 226 /* ClassDeclaration */: return checkClassDeclaration(node); case 227 /* InterfaceDeclaration */: return checkInterfaceDeclaration(node); case 228 /* TypeAliasDeclaration */: return checkTypeAliasDeclaration(node); case 229 /* EnumDeclaration */: return checkEnumDeclaration(node); case 230 /* ModuleDeclaration */: return checkModuleDeclaration(node); case 235 /* ImportDeclaration */: return checkImportDeclaration(node); case 234 /* ImportEqualsDeclaration */: return checkImportEqualsDeclaration(node); case 241 /* ExportDeclaration */: return checkExportDeclaration(node); case 240 /* ExportAssignment */: return checkExportAssignment(node); case 206 /* EmptyStatement */: checkGrammarStatementInAmbientContext(node); return; case 222 /* DebuggerStatement */: checkGrammarStatementInAmbientContext(node); return; case 244 /* MissingDeclaration */: return checkMissingDeclaration(node); } }
(node) { if (!node) { return; } var kind = node.kind; if (cancellationToken) { // Only bother checking on a few construct kinds. We don't want to be excessively // hitting the cancellation token on every node we check. switch (kind) { case 230 /* ModuleDeclaration */: case 226 /* ClassDeclaration */: case 227 /* InterfaceDeclaration */: case 225 /* FunctionDeclaration */: cancellationToken.throwIfCancellationRequested(); } } switch (kind) { case 143 /* TypeParameter */: return checkTypeParameter(node); case 144 /* Parameter */: return checkParameter(node); case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: return checkPropertyDeclaration(node); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: return checkSignatureDeclaration(node); case 155 /* IndexSignature */: return checkSignatureDeclaration(node); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: return checkMethodDeclaration(node); case 150 /* Constructor */: return checkConstructorDeclaration(node); case 151 /* GetAccessor */: case 152 /* SetAccessor */: return checkAccessorDeclaration(node); case 157 /* TypeReference */: return checkTypeReferenceNode(node); case 156 /* TypePredicate */: return checkTypePredicate(node); case 160 /* TypeQuery */: return checkTypeQuery(node); case 161 /* TypeLiteral */: return checkTypeLiteral(node); case 162 /* ArrayType */: return checkArrayType(node); case 163 /* TupleType */: return checkTupleType(node); case 164 /* UnionType */: case 165 /* IntersectionType */: return checkUnionOrIntersectionType(node); case 166 /* ParenthesizedType */: case 168 /* TypeOperator */: return checkSourceElement(node.type); case 169 /* IndexedAccessType */: return checkIndexedAccessType(node); case 170 /* MappedType */: return checkMappedType(node); case 225 /* FunctionDeclaration */: return checkFunctionDeclaration(node); case 204 /* Block */: case 231 /* ModuleBlock */: return checkBlock(node); case 205 /* VariableStatement */: return checkVariableStatement(node); case 207 /* ExpressionStatement */: return checkExpressionStatement(node); case 208 /* IfStatement */: return checkIfStatement(node); case 209 /* DoStatement */: return checkDoStatement(node); case 210 /* WhileStatement */: return checkWhileStatement(node); case 211 /* ForStatement */: return checkForStatement(node); case 212 /* ForInStatement */: return checkForInStatement(node); case 213 /* ForOfStatement */: return checkForOfStatement(node); case 214 /* ContinueStatement */: case 215 /* BreakStatement */: return checkBreakOrContinueStatement(node); case 216 /* ReturnStatement */: return checkReturnStatement(node); case 217 /* WithStatement */: return checkWithStatement(node); case 218 /* SwitchStatement */: return checkSwitchStatement(node); case 219 /* LabeledStatement */: return checkLabeledStatement(node); case 220 /* ThrowStatement */: return checkThrowStatement(node); case 221 /* TryStatement */: return checkTryStatement(node); case 223 /* VariableDeclaration */: return checkVariableDeclaration(node); case 174 /* BindingElement */: return checkBindingElement(node); case 226 /* ClassDeclaration */: return checkClassDeclaration(node); case 227 /* InterfaceDeclaration */: return checkInterfaceDeclaration(node); case 228 /* TypeAliasDeclaration */: return checkTypeAliasDeclaration(node); case 229 /* EnumDeclaration */: return checkEnumDeclaration(node); case 230 /* ModuleDeclaration */: return checkModuleDeclaration(node); case 235 /* ImportDeclaration */: return checkImportDeclaration(node); case 234 /* ImportEqualsDeclaration */: return checkImportEqualsDeclaration(node); case 241 /* ExportDeclaration */: return checkExportDeclaration(node); case 240 /* ExportAssignment */: return checkExportAssignment(node); case 206 /* EmptyStatement */: checkGrammarStatementInAmbientContext(node); return; case 222 /* DebuggerStatement */: checkGrammarStatementInAmbientContext(node); return; case 244 /* MissingDeclaration */: return checkMissingDeclaration(node); } }
(node) { if (!node) { return; } var kind = node.kind; if (cancellationToken) { // Only bother checking on a few construct kinds. We don't want to be excessively // hitting the cancellation token on every node we check. switch (kind) { case 230 /* ModuleDeclaration */: case 226 /* ClassDeclaration */: case 227 /* InterfaceDeclaration */: case 225 /* FunctionDeclaration */: cancellationToken.throwIfCancellationRequested(); } } switch (kind) { case 143 /* TypeParameter */: return checkTypeParameter(node); case 144 /* Parameter */: return checkParameter(node); case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: return checkPropertyDeclaration(node); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: return checkSignatureDeclaration(node); case 155 /* IndexSignature */: return checkSignatureDeclaration(node); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: return checkMethodDeclaration(node); case 150 /* Constructor */: return checkConstructorDeclaration(node); case 151 /* GetAccessor */: case 152 /* SetAccessor */: return checkAccessorDeclaration(node); case 157 /* TypeReference */: return checkTypeReferenceNode(node); case 156 /* TypePredicate */: return checkTypePredicate(node); case 160 /* TypeQuery */: return checkTypeQuery(node); case 161 /* TypeLiteral */: return checkTypeLiteral(node); case 162 /* ArrayType */: return checkArrayType(node); case 163 /* TupleType */: return checkTupleType(node); case 164 /* UnionType */: case 165 /* IntersectionType */: return checkUnionOrIntersectionType(node); case 166 /* ParenthesizedType */: case 168 /* TypeOperator */: return checkSourceElement(node.type); case 169 /* IndexedAccessType */: return checkIndexedAccessType(node); case 170 /* MappedType */: return checkMappedType(node); case 225 /* FunctionDeclaration */: return checkFunctionDeclaration(node); case 204 /* Block */: case 231 /* ModuleBlock */: return checkBlock(node); case 205 /* VariableStatement */: return checkVariableStatement(node); case 207 /* ExpressionStatement */: return checkExpressionStatement(node); case 208 /* IfStatement */: return checkIfStatement(node); case 209 /* DoStatement */: return checkDoStatement(node); case 210 /* WhileStatement */: return checkWhileStatement(node); case 211 /* ForStatement */: return checkForStatement(node); case 212 /* ForInStatement */: return checkForInStatement(node); case 213 /* ForOfStatement */: return checkForOfStatement(node); case 214 /* ContinueStatement */: case 215 /* BreakStatement */: return checkBreakOrContinueStatement(node); case 216 /* ReturnStatement */: return checkReturnStatement(node); case 217 /* WithStatement */: return checkWithStatement(node); case 218 /* SwitchStatement */: return checkSwitchStatement(node); case 219 /* LabeledStatement */: return checkLabeledStatement(node); case 220 /* ThrowStatement */: return checkThrowStatement(node); case 221 /* TryStatement */: return checkTryStatement(node); case 223 /* VariableDeclaration */: return checkVariableDeclaration(node); case 174 /* BindingElement */: return checkBindingElement(node); case 226 /* ClassDeclaration */: return checkClassDeclaration(node); case 227 /* InterfaceDeclaration */: return checkInterfaceDeclaration(node); case 228 /* TypeAliasDeclaration */: return checkTypeAliasDeclaration(node); case 229 /* EnumDeclaration */: return checkEnumDeclaration(node); case 230 /* ModuleDeclaration */: return checkModuleDeclaration(node); case 235 /* ImportDeclaration */: return checkImportDeclaration(node); case 234 /* ImportEqualsDeclaration */: return checkImportEqualsDeclaration(node); case 241 /* ExportDeclaration */: return checkExportDeclaration(node); case 240 /* ExportAssignment */: return checkExportAssignment(node); case 206 /* EmptyStatement */: checkGrammarStatementInAmbientContext(node); return; case 222 /* DebuggerStatement */: checkGrammarStatementInAmbientContext(node); return; case 244 /* MissingDeclaration */: return checkMissingDeclaration(node); } }
(node) { if (!node) { return; } var kind = node.kind; if (cancellationToken) { // Only bother checking on a few construct kinds. We don't want to be excessively // hitting the cancellation token on every node we check. switch (kind) { case 230 /* ModuleDeclaration */: case 226 /* ClassDeclaration */: case 227 /* InterfaceDeclaration */: case 225 /* FunctionDeclaration */: cancellationToken.throwIfCancellationRequested(); } } switch (kind) { case 143 /* TypeParameter */: return checkTypeParameter(node); case 144 /* Parameter */: return checkParameter(node); case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: return checkPropertyDeclaration(node); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: return checkSignatureDeclaration(node); case 155 /* IndexSignature */: return checkSignatureDeclaration(node); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: return checkMethodDeclaration(node); case 150 /* Constructor */: return checkConstructorDeclaration(node); case 151 /* GetAccessor */: case 152 /* SetAccessor */: return checkAccessorDeclaration(node); case 157 /* TypeReference */: return checkTypeReferenceNode(node); case 156 /* TypePredicate */: return checkTypePredicate(node); case 160 /* TypeQuery */: return checkTypeQuery(node); case 161 /* TypeLiteral */: return checkTypeLiteral(node); case 162 /* ArrayType */: return checkArrayType(node); case 163 /* TupleType */: return checkTupleType(node); case 164 /* UnionType */: case 165 /* IntersectionType */: return checkUnionOrIntersectionType(node); case 166 /* ParenthesizedType */: case 168 /* TypeOperator */: return checkSourceElement(node.type); case 169 /* IndexedAccessType */: return checkIndexedAccessType(node); case 170 /* MappedType */: return checkMappedType(node); case 225 /* FunctionDeclaration */: return checkFunctionDeclaration(node); case 204 /* Block */: case 231 /* ModuleBlock */: return checkBlock(node); case 205 /* VariableStatement */: return checkVariableStatement(node); case 207 /* ExpressionStatement */: return checkExpressionStatement(node); case 208 /* IfStatement */: return checkIfStatement(node); case 209 /* DoStatement */: return checkDoStatement(node); case 210 /* WhileStatement */: return checkWhileStatement(node); case 211 /* ForStatement */: return checkForStatement(node); case 212 /* ForInStatement */: return checkForInStatement(node); case 213 /* ForOfStatement */: return checkForOfStatement(node); case 214 /* ContinueStatement */: case 215 /* BreakStatement */: return checkBreakOrContinueStatement(node); case 216 /* ReturnStatement */: return checkReturnStatement(node); case 217 /* WithStatement */: return checkWithStatement(node); case 218 /* SwitchStatement */: return checkSwitchStatement(node); case 219 /* LabeledStatement */: return checkLabeledStatement(node); case 220 /* ThrowStatement */: return checkThrowStatement(node); case 221 /* TryStatement */: return checkTryStatement(node); case 223 /* VariableDeclaration */: return checkVariableDeclaration(node); case 174 /* BindingElement */: return checkBindingElement(node); case 226 /* ClassDeclaration */: return checkClassDeclaration(node); case 227 /* InterfaceDeclaration */: return checkInterfaceDeclaration(node); case 228 /* TypeAliasDeclaration */: return checkTypeAliasDeclaration(node); case 229 /* EnumDeclaration */: return checkEnumDeclaration(node); case 230 /* ModuleDeclaration */: return checkModuleDeclaration(node); case 235 /* ImportDeclaration */: return checkImportDeclaration(node); case 234 /* ImportEqualsDeclaration */: return checkImportEqualsDeclaration(node); case 241 /* ExportDeclaration */: return checkExportDeclaration(node); case 240 /* ExportAssignment */: return checkExportAssignment(node); case 206 /* EmptyStatement */: checkGrammarStatementInAmbientContext(node); return; case 222 /* DebuggerStatement */: checkGrammarStatementInAmbientContext(node); return; case 244 /* MissingDeclaration */: return checkMissingDeclaration(node); } }
(node) { if (!node) { return; } var kind = node.kind; if (cancellationToken) { // Only bother checking on a few construct kinds. We don't want to be excessively // hitting the cancellation token on every node we check. switch (kind) { case 230 /* ModuleDeclaration */: case 226 /* ClassDeclaration */: case 227 /* InterfaceDeclaration */: case 225 /* FunctionDeclaration */: cancellationToken.throwIfCancellationRequested(); } } switch (kind) { case 143 /* TypeParameter */: return checkTypeParameter(node); case 144 /* Parameter */: return checkParameter(node); case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: return checkPropertyDeclaration(node); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: return checkSignatureDeclaration(node); case 155 /* IndexSignature */: return checkSignatureDeclaration(node); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: return checkMethodDeclaration(node); case 150 /* Constructor */: return checkConstructorDeclaration(node); case 151 /* GetAccessor */: case 152 /* SetAccessor */: return checkAccessorDeclaration(node); case 157 /* TypeReference */: return checkTypeReferenceNode(node); case 156 /* TypePredicate */: return checkTypePredicate(node); case 160 /* TypeQuery */: return checkTypeQuery(node); case 161 /* TypeLiteral */: return checkTypeLiteral(node); case 162 /* ArrayType */: return checkArrayType(node); case 163 /* TupleType */: return checkTupleType(node); case 164 /* UnionType */: case 165 /* IntersectionType */: return checkUnionOrIntersectionType(node); case 166 /* ParenthesizedType */: case 168 /* TypeOperator */: return checkSourceElement(node.type); case 169 /* IndexedAccessType */: return checkIndexedAccessType(node); case 170 /* MappedType */: return checkMappedType(node); case 225 /* FunctionDeclaration */: return checkFunctionDeclaration(node); case 204 /* Block */: case 231 /* ModuleBlock */: return checkBlock(node); case 205 /* VariableStatement */: return checkVariableStatement(node); case 207 /* ExpressionStatement */: return checkExpressionStatement(node); case 208 /* IfStatement */: return checkIfStatement(node); case 209 /* DoStatement */: return checkDoStatement(node); case 210 /* WhileStatement */: return checkWhileStatement(node); case 211 /* ForStatement */: return checkForStatement(node); case 212 /* ForInStatement */: return checkForInStatement(node); case 213 /* ForOfStatement */: return checkForOfStatement(node); case 214 /* ContinueStatement */: case 215 /* BreakStatement */: return checkBreakOrContinueStatement(node); case 216 /* ReturnStatement */: return checkReturnStatement(node); case 217 /* WithStatement */: return checkWithStatement(node); case 218 /* SwitchStatement */: return checkSwitchStatement(node); case 219 /* LabeledStatement */: return checkLabeledStatement(node); case 220 /* ThrowStatement */: return checkThrowStatement(node); case 221 /* TryStatement */: return checkTryStatement(node); case 223 /* VariableDeclaration */: return checkVariableDeclaration(node); case 174 /* BindingElement */: return checkBindingElement(node); case 226 /* ClassDeclaration */: return checkClassDeclaration(node); case 227 /* InterfaceDeclaration */: return checkInterfaceDeclaration(node); case 228 /* TypeAliasDeclaration */: return checkTypeAliasDeclaration(node); case 229 /* EnumDeclaration */: return checkEnumDeclaration(node); case 230 /* ModuleDeclaration */: return checkModuleDeclaration(node); case 235 /* ImportDeclaration */: return checkImportDeclaration(node); case 234 /* ImportEqualsDeclaration */: return checkImportEqualsDeclaration(node); case 241 /* ExportDeclaration */: return checkExportDeclaration(node); case 240 /* ExportAssignment */: return checkExportAssignment(node); case 206 /* EmptyStatement */: checkGrammarStatementInAmbientContext(node); return; case 222 /* DebuggerStatement */: checkGrammarStatementInAmbientContext(node); return; case 244 /* MissingDeclaration */: return checkMissingDeclaration(node); } }
getEffectiveDeclarationFlags:
(n, flagsToCheck) { var flags = ts.getCombinedModifierFlags(n); // children of classes (even ambient classes) should not be marked as ambient or export // because those flags have no useful semantics there. if (n.parent.kind !== 227 /* InterfaceDeclaration */ && n.parent.kind !== 226 /* ClassDeclaration */ && n.parent.kind !== 197 /* ClassExpression */ && ts.isInAmbientContext(n)) { if (!(flags & 2 /* Ambient */)) { // It is nested in an ambient context, which means it is automatically exported flags |= 1 /* Export */; } flags |= 2 /* Ambient */; } return flags & flagsToCheck; }
(n, flagsToCheck) { var flags = ts.getCombinedModifierFlags(n); // children of classes (even ambient classes) should not be marked as ambient or export // because those flags have no useful semantics there. if (n.parent.kind !== 227 /* InterfaceDeclaration */ && n.parent.kind !== 226 /* ClassDeclaration */ && n.parent.kind !== 197 /* ClassExpression */ && ts.isInAmbientContext(n)) { if (!(flags & 2 /* Ambient */)) { // It is nested in an ambient context, which means it is automatically exported flags |= 1 /* Export */; } flags |= 2 /* Ambient */; } return flags & flagsToCheck; }
(n, flagsToCheck) { var flags = ts.getCombinedModifierFlags(n); // children of classes (even ambient classes) should not be marked as ambient or export // because those flags have no useful semantics there. if (n.parent.kind !== 227 /* InterfaceDeclaration */ && n.parent.kind !== 226 /* ClassDeclaration */ && n.parent.kind !== 197 /* ClassExpression */ && ts.isInAmbientContext(n)) { if (!(flags & 2 /* Ambient */)) { // It is nested in an ambient context, which means it is automatically exported flags |= 1 /* Export */; } flags |= 2 /* Ambient */; } return flags & flagsToCheck; }
getNodeLinks:
(node) { var nodeId = getNodeId(node); return nodeLinks[nodeId] || (nodeLinks[nodeId] = { flags: 0 }); }
getWidenedTypeForVariableLikeDeclaration:
(declaration, reportErrors) { var type = getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true); 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. if (declaration.kind === 257 /* PropertyAssignment */) { return type; } return getWidenedType(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) { if (!declarationBelongsToPrivateAmbientMember(declaration)) { reportImplicitAnyError(declaration, type); } } return type; }
(declaration, reportErrors) { var type = getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true); 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. if (declaration.kind === 257 /* PropertyAssignment */) { return type; } return getWidenedType(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) { if (!declarationBelongsToPrivateAmbientMember(declaration)) { reportImplicitAnyError(declaration, type); } } return type; }
convertAutoToAny:
(type) { return type === autoType ? anyType : type === autoArrayType ? anyArrayType : type; }
hasQuestionToken:
(node) { if (node) { switch (node.kind) { case 144 /* Parameter */: case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 258 /* ShorthandPropertyAssignment */: case 257 /* PropertyAssignment */: case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: return node.questionToken !== undefined; } } return false; }
(node) { if (node) { switch (node.kind) { case 144 /* Parameter */: case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 258 /* ShorthandPropertyAssignment */: case 257 /* PropertyAssignment */: case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: return node.questionToken !== undefined; } } return false; }
(node) { if (node) { switch (node.kind) { case 144 /* Parameter */: case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 258 /* ShorthandPropertyAssignment */: case 257 /* PropertyAssignment */: case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: return node.questionToken !== undefined; } } return false; }
(node) { if (node) { switch (node.kind) { case 144 /* Parameter */: case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 258 /* ShorthandPropertyAssignment */: case 257 /* PropertyAssignment */: case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: return node.questionToken !== undefined; } } return false; }
getSymbolLinks:
(symbol) { if (symbol.flags & 67108864 /* Transient */) return symbol; var id = getSymbolId(symbol); return symbolLinks[id] || (symbolLinks[id] = {}); }
(symbol) { if (symbol.flags & 67108864 /* Transient */) return symbol; var id = getSymbolId(symbol); return symbolLinks[id] || (symbolLinks[id] = {}); }
(symbol) { if (symbol.flags & 67108864 /* Transient */) return symbol; var id = getSymbolId(symbol); return symbolLinks[id] || (symbolLinks[id] = {}); }
isAsyncFunctionLike:
(node) { return isFunctionLike(node) && hasModifier(node, 256 /* Async */) && !isAccessor(node); }
nodeIsMissing:
(node) { if (node === undefined) { return true; } return node.pos === node.end && node.pos >= 0 && node.kind !== 1 /* EndOfFileToken */; }
(node) { if (node === undefined) { return true; } return node.pos === node.end && node.pos >= 0 && node.kind !== 1 /* EndOfFileToken */; }
(node) { if (node === undefined) { return true; } return node.pos === node.end && node.pos >= 0 && node.kind !== 1 /* EndOfFileToken */; }
(node) { if (node === undefined) { return true; } return node.pos === node.end && node.pos >= 0 && node.kind !== 1 /* EndOfFileToken */; }
Deopt: <JS Function isIndependentMember (SharedFunctionInfo 0x3fa1587f4139)> (opt #555) @33, FP to SP delta: 72, caller sp: 0x7fff5fbfd660
isClassLike:
(node) { return node && (node.kind === 226 /* ClassDeclaration */ || node.kind === 197 /* ClassExpression */); }
(node) { return node && (node.kind === 226 /* ClassDeclaration */ || node.kind === 197 /* ClassExpression */); }
checkCollisionWithCapturedThisVariable:
(node, name) { if (needCollisionCheckForIdentifier(node, name, "_this")) { potentialThisCollisions.push(node); } }
isReservedMemberName:
(name) { return name.charCodeAt(0) === 95 /* _ */ && name.charCodeAt(1) === 95 /* _ */ && name.charCodeAt(2) !== 95 /* _ */ && name.charCodeAt(2) !== 64 /* at */; }
lastOrUndefined:
(array) { return array && array.length > 0 ? array[array.length - 1] : undefined; }
(array) { return array && array.length > 0 ? array[array.length - 1] : undefined; }
isDeclaredRestParam:
(node) { return node && node.dotDotDotToken !== undefined; }
checkGrammarForNonSymbolComputedProperty:
(node, message) { if (ts.isDynamicName(node)) { return grammarErrorOnNode(node, message); } }
checkCollisionWithArgumentsInGeneratedCode:
(node) { // no rest parameters \x5c declaration context \x5c overload - no codegen impact if (!ts.hasDeclaredRestParameter(node) || ts.isInAmbientContext(node) || ts.nodeIsMissing(node.body)) { return; } ts.forEach(node.parameters, function (p) { if (p.name && !ts.isBindingPattern(p.name) && p.name.text === argumentsSymbol.name) { error(p, ts.Diagnostics.Duplicate_identifier_arguments_Compiler_uses_arguments_to_initialize_rest_parameters); } }); }
hasDeclaredRestParameter:
(s) { return isDeclaredRestParam(ts.lastOrUndefined(s.parameters)); }
registerForUnusedIdentifiersCheck:
(node) { if (deferredUnusedIdentifierNodes) { deferredUnusedIdentifierNodes.push(node); } }
checkGrammarFunctionLikeDeclaration:
(node) { // Prevent cascading error by short-circuit var file = ts.getSourceFileOfNode(node); return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarTypeParameterList(node.typeParameters, file) || checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file); }
isCatchClauseVariableDeclarationOrBindingElement:
(declaration) { var node = getRootDeclaration(declaration); return node.kind === 223 /* VariableDeclaration */ && node.parent.kind === 256 /* CatchClause */; }
(declaration) { var node = getRootDeclaration(declaration); return node.kind === 223 /* VariableDeclaration */ && node.parent.kind === 256 /* CatchClause */; }
isFunctionLikeKind:
(kind) { switch (kind) { case 150 /* Constructor */: case 184 /* FunctionExpression */: case 225 /* FunctionDeclaration */: case 185 /* ArrowFunction */: case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: case 158 /* FunctionType */: case 159 /* ConstructorType */: return true; } return false; }
isSourceFileJavaScript:
(file) { return isInJavaScriptFile(file); }
getTypeFromTypeNode:
(node) { switch (node.kind) { case 118 /* AnyKeyword */: case 263 /* JSDocAllType */: case 264 /* JSDocUnknownType */: return anyType; case 134 /* StringKeyword */: return stringType; case 132 /* NumberKeyword */: return numberType; case 121 /* BooleanKeyword */: return booleanType; case 135 /* SymbolKeyword */: return esSymbolType; case 104 /* VoidKeyword */: return voidType; case 137 /* UndefinedKeyword */: return undefinedType; case 94 /* NullKeyword */: return nullType; case 129 /* NeverKeyword */: return neverType; case 289 /* JSDocNullKeyword */: return nullType; case 290 /* JSDocUndefinedKeyword */: return undefinedType; case 291 /* JSDocNeverKeyword */: return neverType; case 167 /* ThisType */: case 98 /* ThisKeyword */: return getTypeFromThisTypeNode(node); case 171 /* LiteralType */: return getTypeFromLiteralTypeNode(node); case 288 /* JSDocLiteralType */: return getTypeFromLiteralTypeNode(node.literal); case 157 /* TypeReference */: case 272 /* JSDocTypeReference */: return getTypeFromTypeReference(node); case 156 /* TypePredicate */: return booleanType; case 199 /* ExpressionWithTypeArguments */: return getTypeFromTypeReference(node); case 160 /* TypeQuery */: return getTypeFromTypeQueryNode(node); case 162 /* ArrayType */: case 265 /* JSDocArrayType */: return getTypeFromArrayTypeNode(node); case 163 /* TupleType */: return getTypeFromTupleTypeNode(node); case 164 /* UnionType */: case 266 /* JSDocUnionType */: return getTypeFromUnionTypeNode(node); case 165 /* IntersectionType */: return getTypeFromIntersectionTypeNode(node); case 166 /* ParenthesizedType */: case 268 /* JSDocNullableType */: case 269 /* JSDocNonNullableType */: case 276 /* JSDocConstructorType */: case 277 /* JSDocThisType */: case 273 /* JSDocOptionalType */: return getTypeFromTypeNode(node.type); case 270 /* JSDocRecordType */: return getTypeFromTypeNode(node.literal); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 161 /* TypeLiteral */: case 287 /* JSDocTypeLiteral */: case 274 /* JSDocFunctionType */: return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); case 168 /* TypeOperator */: return getTypeFromTypeOperatorNode(node); case 169 /* IndexedAccessType */: return getTypeFromIndexedAccessTypeNode(node); case 170 /* MappedType */: return getTypeFromMappedTypeNode(node); // This function assumes that an identifier or qualified name is a type expression // Callers should first ensure this by calling isTypeNode case 70 /* Identifier */: case 141 /* QualifiedName */: var symbol = getSymbolAtLocation(node); return symbol && getDeclaredTypeOfSymbol(symbol); case 267 /* JSDocTupleType */: return getTypeFromJSDocTupleType(node); case 275 /* JSDocVariadicType */: return getTypeFromJSDocVariadicType(node); default: return unknownType; } }
(node) { switch (node.kind) { case 118 /* AnyKeyword */: case 263 /* JSDocAllType */: case 264 /* JSDocUnknownType */: return anyType; case 134 /* StringKeyword */: return stringType; case 132 /* NumberKeyword */: return numberType; case 121 /* BooleanKeyword */: return booleanType; case 135 /* SymbolKeyword */: return esSymbolType; case 104 /* VoidKeyword */: return voidType; case 137 /* UndefinedKeyword */: return undefinedType; case 94 /* NullKeyword */: return nullType; case 129 /* NeverKeyword */: return neverType; case 289 /* JSDocNullKeyword */: return nullType; case 290 /* JSDocUndefinedKeyword */: return undefinedType; case 291 /* JSDocNeverKeyword */: return neverType; case 167 /* ThisType */: case 98 /* ThisKeyword */: return getTypeFromThisTypeNode(node); case 171 /* LiteralType */: return getTypeFromLiteralTypeNode(node); case 288 /* JSDocLiteralType */: return getTypeFromLiteralTypeNode(node.literal); case 157 /* TypeReference */: case 272 /* JSDocTypeReference */: return getTypeFromTypeReference(node); case 156 /* TypePredicate */: return booleanType; case 199 /* ExpressionWithTypeArguments */: return getTypeFromTypeReference(node); case 160 /* TypeQuery */: return getTypeFromTypeQueryNode(node); case 162 /* ArrayType */: case 265 /* JSDocArrayType */: return getTypeFromArrayTypeNode(node); case 163 /* TupleType */: return getTypeFromTupleTypeNode(node); case 164 /* UnionType */: case 266 /* JSDocUnionType */: return getTypeFromUnionTypeNode(node); case 165 /* IntersectionType */: return getTypeFromIntersectionTypeNode(node); case 166 /* ParenthesizedType */: case 268 /* JSDocNullableType */: case 269 /* JSDocNonNullableType */: case 276 /* JSDocConstructorType */: case 277 /* JSDocThisType */: case 273 /* JSDocOptionalType */: return getTypeFromTypeNode(node.type); case 270 /* JSDocRecordType */: return getTypeFromTypeNode(node.literal); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 161 /* TypeLiteral */: case 287 /* JSDocTypeLiteral */: case 274 /* JSDocFunctionType */: return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); case 168 /* TypeOperator */: return getTypeFromTypeOperatorNode(node); case 169 /* IndexedAccessType */: return getTypeFromIndexedAccessTypeNode(node); case 170 /* MappedType */: return getTypeFromMappedTypeNode(node); // This function assumes that an identifier or qualified name is a type expression // Callers should first ensure this by calling isTypeNode case 70 /* Identifier */: case 141 /* QualifiedName */: var symbol = getSymbolAtLocation(node); return symbol && getDeclaredTypeOfSymbol(symbol); case 267 /* JSDocTupleType */: return getTypeFromJSDocTupleType(node); case 275 /* JSDocVariadicType */: return getTypeFromJSDocVariadicType(node); default: return unknownType; } }
(node) { switch (node.kind) { case 118 /* AnyKeyword */: case 263 /* JSDocAllType */: case 264 /* JSDocUnknownType */: return anyType; case 134 /* StringKeyword */: return stringType; case 132 /* NumberKeyword */: return numberType; case 121 /* BooleanKeyword */: return booleanType; case 135 /* SymbolKeyword */: return esSymbolType; case 104 /* VoidKeyword */: return voidType; case 137 /* UndefinedKeyword */: return undefinedType; case 94 /* NullKeyword */: return nullType; case 129 /* NeverKeyword */: return neverType; case 289 /* JSDocNullKeyword */: return nullType; case 290 /* JSDocUndefinedKeyword */: return undefinedType; case 291 /* JSDocNeverKeyword */: return neverType; case 167 /* ThisType */: case 98 /* ThisKeyword */: return getTypeFromThisTypeNode(node); case 171 /* LiteralType */: return getTypeFromLiteralTypeNode(node); case 288 /* JSDocLiteralType */: return getTypeFromLiteralTypeNode(node.literal); case 157 /* TypeReference */: case 272 /* JSDocTypeReference */: return getTypeFromTypeReference(node); case 156 /* TypePredicate */: return booleanType; case 199 /* ExpressionWithTypeArguments */: return getTypeFromTypeReference(node); case 160 /* TypeQuery */: return getTypeFromTypeQueryNode(node); case 162 /* ArrayType */: case 265 /* JSDocArrayType */: return getTypeFromArrayTypeNode(node); case 163 /* TupleType */: return getTypeFromTupleTypeNode(node); case 164 /* UnionType */: case 266 /* JSDocUnionType */: return getTypeFromUnionTypeNode(node); case 165 /* IntersectionType */: return getTypeFromIntersectionTypeNode(node); case 166 /* ParenthesizedType */: case 268 /* JSDocNullableType */: case 269 /* JSDocNonNullableType */: case 276 /* JSDocConstructorType */: case 277 /* JSDocThisType */: case 273 /* JSDocOptionalType */: return getTypeFromTypeNode(node.type); case 270 /* JSDocRecordType */: return getTypeFromTypeNode(node.literal); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 161 /* TypeLiteral */: case 287 /* JSDocTypeLiteral */: case 274 /* JSDocFunctionType */: return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); case 168 /* TypeOperator */: return getTypeFromTypeOperatorNode(node); case 169 /* IndexedAccessType */: return getTypeFromIndexedAccessTypeNode(node); case 170 /* MappedType */: return getTypeFromMappedTypeNode(node); // This function assumes that an identifier or qualified name is a type expression // Callers should first ensure this by calling isTypeNode case 70 /* Identifier */: case 141 /* QualifiedName */: var symbol = getSymbolAtLocation(node); return symbol && getDeclaredTypeOfSymbol(symbol); case 267 /* JSDocTupleType */: return getTypeFromJSDocTupleType(node); case 275 /* JSDocVariadicType */: return getTypeFromJSDocVariadicType(node); default: return unknownType; } }
(node) { switch (node.kind) { case 118 /* AnyKeyword */: case 263 /* JSDocAllType */: case 264 /* JSDocUnknownType */: return anyType; case 134 /* StringKeyword */: return stringType; case 132 /* NumberKeyword */: return numberType; case 121 /* BooleanKeyword */: return booleanType; case 135 /* SymbolKeyword */: return esSymbolType; case 104 /* VoidKeyword */: return voidType; case 137 /* UndefinedKeyword */: return undefinedType; case 94 /* NullKeyword */: return nullType; case 129 /* NeverKeyword */: return neverType; case 289 /* JSDocNullKeyword */: return nullType; case 290 /* JSDocUndefinedKeyword */: return undefinedType; case 291 /* JSDocNeverKeyword */: return neverType; case 167 /* ThisType */: case 98 /* ThisKeyword */: return getTypeFromThisTypeNode(node); case 171 /* LiteralType */: return getTypeFromLiteralTypeNode(node); case 288 /* JSDocLiteralType */: return getTypeFromLiteralTypeNode(node.literal); case 157 /* TypeReference */: case 272 /* JSDocTypeReference */: return getTypeFromTypeReference(node); case 156 /* TypePredicate */: return booleanType; case 199 /* ExpressionWithTypeArguments */: return getTypeFromTypeReference(node); case 160 /* TypeQuery */: return getTypeFromTypeQueryNode(node); case 162 /* ArrayType */: case 265 /* JSDocArrayType */: return getTypeFromArrayTypeNode(node); case 163 /* TupleType */: return getTypeFromTupleTypeNode(node); case 164 /* UnionType */: case 266 /* JSDocUnionType */: return getTypeFromUnionTypeNode(node); case 165 /* IntersectionType */: return getTypeFromIntersectionTypeNode(node); case 166 /* ParenthesizedType */: case 268 /* JSDocNullableType */: case 269 /* JSDocNonNullableType */: case 276 /* JSDocConstructorType */: case 277 /* JSDocThisType */: case 273 /* JSDocOptionalType */: return getTypeFromTypeNode(node.type); case 270 /* JSDocRecordType */: return getTypeFromTypeNode(node.literal); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 161 /* TypeLiteral */: case 287 /* JSDocTypeLiteral */: case 274 /* JSDocFunctionType */: return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); case 168 /* TypeOperator */: return getTypeFromTypeOperatorNode(node); case 169 /* IndexedAccessType */: return getTypeFromIndexedAccessTypeNode(node); case 170 /* MappedType */: return getTypeFromMappedTypeNode(node); // This function assumes that an identifier or qualified name is a type expression // Callers should first ensure this by calling isTypeNode case 70 /* Identifier */: case 141 /* QualifiedName */: var symbol = getSymbolAtLocation(node); return symbol && getDeclaredTypeOfSymbol(symbol); case 267 /* JSDocTupleType */: return getTypeFromJSDocTupleType(node); case 275 /* JSDocVariadicType */: return getTypeFromJSDocVariadicType(node); default: return unknownType; } }
(node) { switch (node.kind) { case 118 /* AnyKeyword */: case 263 /* JSDocAllType */: case 264 /* JSDocUnknownType */: return anyType; case 134 /* StringKeyword */: return stringType; case 132 /* NumberKeyword */: return numberType; case 121 /* BooleanKeyword */: return booleanType; case 135 /* SymbolKeyword */: return esSymbolType; case 104 /* VoidKeyword */: return voidType; case 137 /* UndefinedKeyword */: return undefinedType; case 94 /* NullKeyword */: return nullType; case 129 /* NeverKeyword */: return neverType; case 289 /* JSDocNullKeyword */: return nullType; case 290 /* JSDocUndefinedKeyword */: return undefinedType; case 291 /* JSDocNeverKeyword */: return neverType; case 167 /* ThisType */: case 98 /* ThisKeyword */: return getTypeFromThisTypeNode(node); case 171 /* LiteralType */: return getTypeFromLiteralTypeNode(node); case 288 /* JSDocLiteralType */: return getTypeFromLiteralTypeNode(node.literal); case 157 /* TypeReference */: case 272 /* JSDocTypeReference */: return getTypeFromTypeReference(node); case 156 /* TypePredicate */: return booleanType; case 199 /* ExpressionWithTypeArguments */: return getTypeFromTypeReference(node); case 160 /* TypeQuery */: return getTypeFromTypeQueryNode(node); case 162 /* ArrayType */: case 265 /* JSDocArrayType */: return getTypeFromArrayTypeNode(node); case 163 /* TupleType */: return getTypeFromTupleTypeNode(node); case 164 /* UnionType */: case 266 /* JSDocUnionType */: return getTypeFromUnionTypeNode(node); case 165 /* IntersectionType */: return getTypeFromIntersectionTypeNode(node); case 166 /* ParenthesizedType */: case 268 /* JSDocNullableType */: case 269 /* JSDocNonNullableType */: case 276 /* JSDocConstructorType */: case 277 /* JSDocThisType */: case 273 /* JSDocOptionalType */: return getTypeFromTypeNode(node.type); case 270 /* JSDocRecordType */: return getTypeFromTypeNode(node.literal); case 158 /* FunctionType */: case 159 /* ConstructorType */: case 161 /* TypeLiteral */: case 287 /* JSDocTypeLiteral */: case 274 /* JSDocFunctionType */: return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); case 168 /* TypeOperator */: return getTypeFromTypeOperatorNode(node); case 169 /* IndexedAccessType */: return getTypeFromIndexedAccessTypeNode(node); case 170 /* MappedType */: return getTypeFromMappedTypeNode(node); // This function assumes that an identifier or qualified name is a type expression // Callers should first ensure this by calling isTypeNode case 70 /* Identifier */: case 141 /* QualifiedName */: var symbol = getSymbolAtLocation(node); return symbol && getDeclaredTypeOfSymbol(symbol); case 267 /* JSDocTupleType */: return getTypeFromJSDocTupleType(node); case 275 /* JSDocVariadicType */: return getTypeFromJSDocVariadicType(node); default: return unknownType; } }
createType:
(flags) { var result = new Type(checker, flags); typeCount++; result.id = typeCount; return result; }
getApparentType:
(type) { var t = type.flags & 540672 /* TypeVariable */ ? getApparentTypeOfTypeVariable(type) : type; return t.flags & 262178 /* StringLike */ ? globalStringType : t.flags & 340 /* NumberLike */ ? globalNumberType : t.flags & 136 /* BooleanLike */ ? globalBooleanType : t.flags & 512 /* ESSymbol */ ? getGlobalESSymbolType() : t; }
symbolIsValue:
(symbol) { // If it is an instantiated symbol, then it is a value if the symbol it is an // instantiation of is a value. if (symbol.flags & 16777216 /* Instantiated */) { return symbolIsValue(getSymbolLinks(symbol).target); } // If the symbol has the value flag, it is trivially a value. if (symbol.flags & 107455 /* Value */) { return true; } // If it is an alias, then it is a value if the symbol it resolves to is a value. if (symbol.flags & 8388608 /* Alias */) { return (resolveAlias(symbol).flags & 107455 /* Value */) !== 0; } return false; }
(symbol) { // If it is an instantiated symbol, then it is a value if the symbol it is an // instantiation of is a value. if (symbol.flags & 16777216 /* Instantiated */) { return symbolIsValue(getSymbolLinks(symbol).target); } // If the symbol has the value flag, it is trivially a value. if (symbol.flags & 107455 /* Value */) { return true; } // If it is an alias, then it is a value if the symbol it resolves to is a value. if (symbol.flags & 8388608 /* Alias */) { return (resolveAlias(symbol).flags & 107455 /* Value */) !== 0; } return false; }
(symbol) { // If it is an instantiated symbol, then it is a value if the symbol it is an // instantiation of is a value. if (symbol.flags & 16777216 /* Instantiated */) { return symbolIsValue(getSymbolLinks(symbol).target); } // If the symbol has the value flag, it is trivially a value. if (symbol.flags & 107455 /* Value */) { return true; } // If it is an alias, then it is a value if the symbol it resolves to is a value. if (symbol.flags & 8388608 /* Alias */) { return (resolveAlias(symbol).flags & 107455 /* Value */) !== 0; } return false; }
(symbol) { // If it is an instantiated symbol, then it is a value if the symbol it is an // instantiation of is a value. if (symbol.flags & 16777216 /* Instantiated */) { return symbolIsValue(getSymbolLinks(symbol).target); } // If the symbol has the value flag, it is trivially a value. if (symbol.flags & 107455 /* Value */) { return true; } // If it is an alias, then it is a value if the symbol it resolves to is a value. if (symbol.flags & 8388608 /* Alias */) { return (resolveAlias(symbol).flags & 107455 /* Value */) !== 0; } return false; }
(symbol) { // If it is an instantiated symbol, then it is a value if the symbol it is an // instantiation of is a value. if (symbol.flags & 16777216 /* Instantiated */) { return symbolIsValue(getSymbolLinks(symbol).target); } // If the symbol has the value flag, it is trivially a value. if (symbol.flags & 107455 /* Value */) { return true; } // If it is an alias, then it is a value if the symbol it resolves to is a value. if (symbol.flags & 8388608 /* Alias */) { return (resolveAlias(symbol).flags & 107455 /* Value */) !== 0; } return false; }
popTypeResolution:
() { resolutionTargets.pop(); resolutionPropertyNames.pop(); return resolutionResults.pop(); }
Deopt: <JS Function getMergedSymbol (SharedFunctionInfo 0x3fa1587ef339)> (opt #287) @3, FP to SP delta: 24, caller sp: 0x7fff5fbfdea8
Deopt: <JS Function getSymbolLinks (SharedFunctionInfo 0x3fa1587ecf39)> (opt #296) @11, FP to SP delta: 40, caller sp: 0x7fff5fbfdef0
Deopt: <JS Function symbolIsValue (SharedFunctionInfo 0x3fa1587ef639)> (opt #317) @2, FP to SP delta: 56, caller sp: 0x7fff5fbfdcf8
Deopt: <JS Function getSymbolId (SharedFunctionInfo 0x3f04510bec9)> (opt #288) @9, FP to SP delta: 24, caller sp: 0x7fff5fbfdd08
Deopt: <JS Function lastOrUndefined (SharedFunctionInfo 0x3735bafe25f9)> (opt #302) @3, FP to SP delta: 24, caller sp: 0x7fff5fbfdb38
isGlobalSourceFile:
(node) { return node.kind === 261 /* SourceFile */ && !ts.isExternalOrCommonJsModule(node); }
getIndexSymbol:
(symbol) { return symbol.members["__index"]; }
addOptionality:
(type, optional) { return strictNullChecks && optional ? includeFalsyTypes(type, 2048 /* Undefined */) : type; }
getSymbol:
(symbols, name, meaning) { if (meaning) { var symbol = symbols[name]; if (symbol) { ts.Debug.assert((symbol.flags & 16777216 /* Instantiated */) === 0, "Should never get an instantiated symbol here."); if (symbol.flags & meaning) { return symbol; } if (symbol.flags & 8388608 /* Alias */) { var target = resolveAlias(symbol); // Unknown symbol means an error occurred in alias resolution, treat it as positive answer to avoid cascading errors if (target === unknownSymbol || target.flags & meaning) { return symbol; } } } } // return undefined if we can't find a symbol. }
(symbols, name, meaning) { if (meaning) { var symbol = symbols[name]; if (symbol) { ts.Debug.assert((symbol.flags & 16777216 /* Instantiated */) === 0, "Should never get an instantiated symbol here."); if (symbol.flags & meaning) { return symbol; } if (symbol.flags & 8388608 /* Alias */) { var target = resolveAlias(symbol); // Unknown symbol means an error occurred in alias resolution, treat it as positive answer to avoid cascading errors if (target === unknownSymbol || target.flags & meaning) { return symbol; } } } } // return undefined if we can't find a symbol. }
(symbols, name, meaning) { if (meaning) { var symbol = symbols[name]; if (symbol) { ts.Debug.assert((symbol.flags & 16777216 /* Instantiated */) === 0, "Should never get an instantiated symbol here."); if (symbol.flags & meaning) { return symbol; } if (symbol.flags & 8388608 /* Alias */) { var target = resolveAlias(symbol); // Unknown symbol means an error occurred in alias resolution, treat it as positive answer to avoid cascading errors if (target === unknownSymbol || target.flags & meaning) { return symbol; } } } } // return undefined if we can't find a symbol. }
(symbols, name, meaning) { if (meaning) { var symbol = symbols[name]; if (symbol) { ts.Debug.assert((symbol.flags & 16777216 /* Instantiated */) === 0, "Should never get an instantiated symbol here."); if (symbol.flags & meaning) { return symbol; } if (symbol.flags & 8388608 /* Alias */) { var target = resolveAlias(symbol); // Unknown symbol means an error occurred in alias resolution, treat it as positive answer to avoid cascading errors if (target === unknownSymbol || target.flags & meaning) { return symbol; } } } } // return undefined if we can't find a symbol. }
Deopt: <JS Function checkInheritedPropertiesAreIdentical (SharedFunctionInfo 0x3fca58614951)> (opt #515) @85, FP to SP delta: 352, caller sp: 0x7fff5fbfdce8
Deopt: <JS Function isRelatedTo (SharedFunctionInfo 0x298f55ec1c31)> (opt #539) @79, FP to SP delta: 304, caller sp: 0x7fff5fbfdbb8
(symbols, name, meaning) { if (meaning) { var symbol = symbols[name]; if (symbol) { ts.Debug.assert((symbol.flags & 16777216 /* Instantiated */) === 0, "Should never get an instantiated symbol here."); if (symbol.flags & meaning) { return symbol; } if (symbol.flags & 8388608 /* Alias */) { var target = resolveAlias(symbol); // Unknown symbol means an error occurred in alias resolution, treat it as positive answer to avoid cascading errors if (target === unknownSymbol || target.flags & meaning) { return symbol; } } } } // return undefined if we can't find a symbol. }
(symbols, name, meaning) { if (meaning) { var symbol = symbols[name]; if (symbol) { ts.Debug.assert((symbol.flags & 16777216 /* Instantiated */) === 0, "Should never get an instantiated symbol here."); if (symbol.flags & meaning) { return symbol; } if (symbol.flags & 8388608 /* Alias */) { var target = resolveAlias(symbol); // Unknown symbol means an error occurred in alias resolution, treat it as positive answer to avoid cascading errors if (target === unknownSymbol || target.flags & meaning) { return symbol; } } } } // return undefined if we can't find a symbol. }
getInterfaceBaseTypeNodes:
(node) { var heritageClause = getHeritageClause(node.heritageClauses, 84 /* ExtendsKeyword */); return heritageClause ? heritageClause.types : undefined; }
(node) { var heritageClause = getHeritageClause(node.heritageClauses, 84 /* ExtendsKeyword */); return heritageClause ? heritageClause.types : undefined; }
(node) { var heritageClause = getHeritageClause(node.heritageClauses, 84 /* ExtendsKeyword */); return heritageClause ? heritageClause.types : undefined; }
resolveName:
(location, name, meaning, nameNotFoundMessage, nameArg) { var result; var lastLocation; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; var isInExternalModule = false; 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)) { var useResult = true; if (ts.isFunctionLike(location) && lastLocation && lastLocation !== location.body) { // symbol lookup restrictions for function-like declarations // - 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. // - parameters are only in the scope of function body // This restriction does not apply to JSDoc comment types because they are parented // at a higher level than type parameters would normally be if (meaning & result.flags & 793064 /* Type */ && lastLocation.kind !== 278 /* JSDocComment */) { useResult = result.flags & 262144 /* TypeParameter */ ? lastLocation === location.type || lastLocation.kind === 144 /* Parameter */ || lastLocation.kind === 143 /* TypeParameter */ : false; } if (meaning & 107455 /* Value */ && result.flags & 1 /* FunctionScopedVariable */) { // parameters are visible only inside function body, parameter list and return type // technically for parameter list case here we might mix parameters and variables declared in function, // however it is detected separately when checking initializers of parameters // to make sure that they reference no variables declared after them. useResult = lastLocation.kind === 144 /* Parameter */ || (lastLocation === location.type && result.valueDeclaration.kind === 144 /* Parameter */); } } if (useResult) { break loop; } else { result = undefined; } } } switch (location.kind) { case 261 /* SourceFile */: if (!ts.isExternalOrCommonJsModule(location)) break; isInExternalModule = true; case 230 /* ModuleDeclaration */: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 261 /* SourceFile */ || ts.isAmbientModule(location)) { // It's an external module. First see if the module has an export default and if the local // name of that export default matches. if (result = moduleExports["default"]) { var localSymbol = ts.getLocalSymbolForExportDefault(result); if (localSymbol && (result.flags & meaning) && localSymbol.name === name) { break loop; } result = undefined; } // 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 (moduleExports[name] && moduleExports[name].flags === 8388608 /* Alias */ && ts.getDeclarationOfKind(moduleExports[name], 243 /* ExportSpecifier */)) { break; } } if (result = getSymbol(moduleExports, name, meaning & 8914931 /* ModuleMember */)) { break loop; } break; case 229 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8 /* EnumMember */)) { break loop; } break; case 147 /* PropertyDeclaration */: case 146 /* 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) && !(ts.getModifierFlags(location) & 32 /* 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 226 /* ClassDeclaration */: case 197 /* ClassExpression */: case 227 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793064 /* Type */)) { if (lastLocation && ts.getModifierFlags(lastLocation) & 32 /* 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 === 197 /* 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 142 /* ComputedPropertyName */: grandparent = location.parent.parent; if (ts.isClassLike(grandparent) || grandparent.kind === 227 /* InterfaceDeclaration */) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793064 /* Type */)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); return undefined; } } break; case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 225 /* FunctionDeclaration */: case 185 /* ArrowFunction */: if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } break; case 184 /* 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 145 /* 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 === 144 /* 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 && nameNotFoundMessage && noUnusedIdentifiers) { result.isReferenced = true; } if (!result) { result = getSymbol(globals, name, meaning); } if (!result) { if (nameNotFoundMessage) { if (!errorLocation || !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && !checkAndReportErrorForExtendingInterface(errorLocation) && !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) && !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning)) { 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 {} // } // const 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); } } // If we're in an external module, we can't reference value symbols created from UMD export declarations if (result && isInExternalModule && (meaning & 107455 /* Value */) === 107455 /* Value */) { var decls = result.declarations; if (decls && decls.length === 1 && decls[0].kind === 233 /* NamespaceExportDeclaration */) { error(errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, name); } } } return result; }
(location, name, meaning, nameNotFoundMessage, nameArg) { var result; var lastLocation; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; var isInExternalModule = false; 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)) { var useResult = true; if (ts.isFunctionLike(location) && lastLocation && lastLocation !== location.body) { // symbol lookup restrictions for function-like declarations // - 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. // - parameters are only in the scope of function body // This restriction does not apply to JSDoc comment types because they are parented // at a higher level than type parameters would normally be if (meaning & result.flags & 793064 /* Type */ && lastLocation.kind !== 278 /* JSDocComment */) { useResult = result.flags & 262144 /* TypeParameter */ ? lastLocation === location.type || lastLocation.kind === 144 /* Parameter */ || lastLocation.kind === 143 /* TypeParameter */ : false; } if (meaning & 107455 /* Value */ && result.flags & 1 /* FunctionScopedVariable */) { // parameters are visible only inside function body, parameter list and return type // technically for parameter list case here we might mix parameters and variables declared in function, // however it is detected separately when checking initializers of parameters // to make sure that they reference no variables declared after them. useResult = lastLocation.kind === 144 /* Parameter */ || (lastLocation === location.type && result.valueDeclaration.kind === 144 /* Parameter */); } } if (useResult) { break loop; } else { result = undefined; } } } switch (location.kind) { case 261 /* SourceFile */: if (!ts.isExternalOrCommonJsModule(location)) break; isInExternalModule = true; case 230 /* ModuleDeclaration */: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 261 /* SourceFile */ || ts.isAmbientModule(location)) { // It's an external module. First see if the module has an export default and if the local // name of that export default matches. if (result = moduleExports["default"]) { var localSymbol = ts.getLocalSymbolForExportDefault(result); if (localSymbol && (result.flags & meaning) && localSymbol.name === name) { break loop; } result = undefined; } // 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 (moduleExports[name] && moduleExports[name].flags === 8388608 /* Alias */ && ts.getDeclarationOfKind(moduleExports[name], 243 /* ExportSpecifier */)) { break; } } if (result = getSymbol(moduleExports, name, meaning & 8914931 /* ModuleMember */)) { break loop; } break; case 229 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8 /* EnumMember */)) { break loop; } break; case 147 /* PropertyDeclaration */: case 146 /* 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) && !(ts.getModifierFlags(location) & 32 /* 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 226 /* ClassDeclaration */: case 197 /* ClassExpression */: case 227 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793064 /* Type */)) { if (lastLocation && ts.getModifierFlags(lastLocation) & 32 /* 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 === 197 /* 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 142 /* ComputedPropertyName */: grandparent = location.parent.parent; if (ts.isClassLike(grandparent) || grandparent.kind === 227 /* InterfaceDeclaration */) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793064 /* Type */)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); return undefined; } } break; case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 225 /* FunctionDeclaration */: case 185 /* ArrowFunction */: if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } break; case 184 /* 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 145 /* 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 === 144 /* 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 && nameNotFoundMessage && noUnusedIdentifiers) { result.isReferenced = true; } if (!result) { result = getSymbol(globals, name, meaning); } if (!result) { if (nameNotFoundMessage) { if (!errorLocation || !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && !checkAndReportErrorForExtendingInterface(errorLocation) && !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) && !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning)) { 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 {} // } // const 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); } } // If we're in an external module, we can't reference value symbols created from UMD export declarations if (result && isInExternalModule && (meaning & 107455 /* Value */) === 107455 /* Value */) { var decls = result.declarations; if (decls && decls.length === 1 && decls[0].kind === 233 /* NamespaceExportDeclaration */) { error(errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, name); } } } return result; }
(location, name, meaning, nameNotFoundMessage, nameArg) { var result; var lastLocation; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; var isInExternalModule = false; 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)) { var useResult = true; if (ts.isFunctionLike(location) && lastLocation && lastLocation !== location.body) { // symbol lookup restrictions for function-like declarations // - 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. // - parameters are only in the scope of function body // This restriction does not apply to JSDoc comment types because they are parented // at a higher level than type parameters would normally be if (meaning & result.flags & 793064 /* Type */ && lastLocation.kind !== 278 /* JSDocComment */) { useResult = result.flags & 262144 /* TypeParameter */ ? lastLocation === location.type || lastLocation.kind === 144 /* Parameter */ || lastLocation.kind === 143 /* TypeParameter */ : false; } if (meaning & 107455 /* Value */ && result.flags & 1 /* FunctionScopedVariable */) { // parameters are visible only inside function body, parameter list and return type // technically for parameter list case here we might mix parameters and variables declared in function, // however it is detected separately when checking initializers of parameters // to make sure that they reference no variables declared after them. useResult = lastLocation.kind === 144 /* Parameter */ || (lastLocation === location.type && result.valueDeclaration.kind === 144 /* Parameter */); } } if (useResult) { break loop; } else { result = undefined; } } } switch (location.kind) { case 261 /* SourceFile */: if (!ts.isExternalOrCommonJsModule(location)) break; isInExternalModule = true; case 230 /* ModuleDeclaration */: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 261 /* SourceFile */ || ts.isAmbientModule(location)) { // It's an external module. First see if the module has an export default and if the local // name of that export default matches. if (result = moduleExports["default"]) { var localSymbol = ts.getLocalSymbolForExportDefault(result); if (localSymbol && (result.flags & meaning) && localSymbol.name === name) { break loop; } result = undefined; } // 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 (moduleExports[name] && moduleExports[name].flags === 8388608 /* Alias */ && ts.getDeclarationOfKind(moduleExports[name], 243 /* ExportSpecifier */)) { break; } } if (result = getSymbol(moduleExports, name, meaning & 8914931 /* ModuleMember */)) { break loop; } break; case 229 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8 /* EnumMember */)) { break loop; } break; case 147 /* PropertyDeclaration */: case 146 /* 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) && !(ts.getModifierFlags(location) & 32 /* 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 226 /* ClassDeclaration */: case 197 /* ClassExpression */: case 227 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793064 /* Type */)) { if (lastLocation && ts.getModifierFlags(lastLocation) & 32 /* 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 === 197 /* 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 142 /* ComputedPropertyName */: grandparent = location.parent.parent; if (ts.isClassLike(grandparent) || grandparent.kind === 227 /* InterfaceDeclaration */) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793064 /* Type */)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); return undefined; } } break; case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 225 /* FunctionDeclaration */: case 185 /* ArrowFunction */: if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } break; case 184 /* 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 145 /* 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 === 144 /* 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 && nameNotFoundMessage && noUnusedIdentifiers) { result.isReferenced = true; } if (!result) { result = getSymbol(globals, name, meaning); } if (!result) { if (nameNotFoundMessage) { if (!errorLocation || !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && !checkAndReportErrorForExtendingInterface(errorLocation) && !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) && !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning)) { 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 {} // } // const 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); } } // If we're in an external module, we can't reference value symbols created from UMD export declarations if (result && isInExternalModule && (meaning & 107455 /* Value */) === 107455 /* Value */) { var decls = result.declarations; if (decls && decls.length === 1 && decls[0].kind === 233 /* NamespaceExportDeclaration */) { error(errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, name); } } } return result; }
(location, name, meaning, nameNotFoundMessage, nameArg) { var result; var lastLocation; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; var isInExternalModule = false; 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)) { var useResult = true; if (ts.isFunctionLike(location) && lastLocation && lastLocation !== location.body) { // symbol lookup restrictions for function-like declarations // - 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. // - parameters are only in the scope of function body // This restriction does not apply to JSDoc comment types because they are parented // at a higher level than type parameters would normally be if (meaning & result.flags & 793064 /* Type */ && lastLocation.kind !== 278 /* JSDocComment */) { useResult = result.flags & 262144 /* TypeParameter */ ? lastLocation === location.type || lastLocation.kind === 144 /* Parameter */ || lastLocation.kind === 143 /* TypeParameter */ : false; } if (meaning & 107455 /* Value */ && result.flags & 1 /* FunctionScopedVariable */) { // parameters are visible only inside function body, parameter list and return type // technically for parameter list case here we might mix parameters and variables declared in function, // however it is detected separately when checking initializers of parameters // to make sure that they reference no variables declared after them. useResult = lastLocation.kind === 144 /* Parameter */ || (lastLocation === location.type && result.valueDeclaration.kind === 144 /* Parameter */); } } if (useResult) { break loop; } else { result = undefined; } } } switch (location.kind) { case 261 /* SourceFile */: if (!ts.isExternalOrCommonJsModule(location)) break; isInExternalModule = true; case 230 /* ModuleDeclaration */: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 261 /* SourceFile */ || ts.isAmbientModule(location)) { // It's an external module. First see if the module has an export default and if the local // name of that export default matches. if (result = moduleExports["default"]) { var localSymbol = ts.getLocalSymbolForExportDefault(result); if (localSymbol && (result.flags & meaning) && localSymbol.name === name) { break loop; } result = undefined; } // 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 (moduleExports[name] && moduleExports[name].flags === 8388608 /* Alias */ && ts.getDeclarationOfKind(moduleExports[name], 243 /* ExportSpecifier */)) { break; } } if (result = getSymbol(moduleExports, name, meaning & 8914931 /* ModuleMember */)) { break loop; } break; case 229 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8 /* EnumMember */)) { break loop; } break; case 147 /* PropertyDeclaration */: case 146 /* 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) && !(ts.getModifierFlags(location) & 32 /* 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 226 /* ClassDeclaration */: case 197 /* ClassExpression */: case 227 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793064 /* Type */)) { if (lastLocation && ts.getModifierFlags(lastLocation) & 32 /* 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 === 197 /* 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 142 /* ComputedPropertyName */: grandparent = location.parent.parent; if (ts.isClassLike(grandparent) || grandparent.kind === 227 /* InterfaceDeclaration */) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793064 /* Type */)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); return undefined; } } break; case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 225 /* FunctionDeclaration */: case 185 /* ArrowFunction */: if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } break; case 184 /* 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 145 /* 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 === 144 /* 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 && nameNotFoundMessage && noUnusedIdentifiers) { result.isReferenced = true; } if (!result) { result = getSymbol(globals, name, meaning); } if (!result) { if (nameNotFoundMessage) { if (!errorLocation || !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && !checkAndReportErrorForExtendingInterface(errorLocation) && !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) && !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning)) { 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 {} // } // const 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); } } // If we're in an external module, we can't reference value symbols created from UMD export declarations if (result && isInExternalModule && (meaning & 107455 /* Value */) === 107455 /* Value */) { var decls = result.declarations; if (decls && decls.length === 1 && decls[0].kind === 233 /* NamespaceExportDeclaration */) { error(errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, name); } } } return result; }
(location, name, meaning, nameNotFoundMessage, nameArg) { var result; var lastLocation; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; var isInExternalModule = false; 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)) { var useResult = true; if (ts.isFunctionLike(location) && lastLocation && lastLocation !== location.body) { // symbol lookup restrictions for function-like declarations // - 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. // - parameters are only in the scope of function body // This restriction does not apply to JSDoc comment types because they are parented // at a higher level than type parameters would normally be if (meaning & result.flags & 793064 /* Type */ && lastLocation.kind !== 278 /* JSDocComment */) { useResult = result.flags & 262144 /* TypeParameter */ ? lastLocation === location.type || lastLocation.kind === 144 /* Parameter */ || lastLocation.kind === 143 /* TypeParameter */ : false; } if (meaning & 107455 /* Value */ && result.flags & 1 /* FunctionScopedVariable */) { // parameters are visible only inside function body, parameter list and return type // technically for parameter list case here we might mix parameters and variables declared in function, // however it is detected separately when checking initializers of parameters // to make sure that they reference no variables declared after them. useResult = lastLocation.kind === 144 /* Parameter */ || (lastLocation === location.type && result.valueDeclaration.kind === 144 /* Parameter */); } } if (useResult) { break loop; } else { result = undefined; } } } switch (location.kind) { case 261 /* SourceFile */: if (!ts.isExternalOrCommonJsModule(location)) break; isInExternalModule = true; case 230 /* ModuleDeclaration */: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 261 /* SourceFile */ || ts.isAmbientModule(location)) { // It's an external module. First see if the module has an export default and if the local // name of that export default matches. if (result = moduleExports["default"]) { var localSymbol = ts.getLocalSymbolForExportDefault(result); if (localSymbol && (result.flags & meaning) && localSymbol.name === name) { break loop; } result = undefined; } // 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 (moduleExports[name] && moduleExports[name].flags === 8388608 /* Alias */ && ts.getDeclarationOfKind(moduleExports[name], 243 /* ExportSpecifier */)) { break; } } if (result = getSymbol(moduleExports, name, meaning & 8914931 /* ModuleMember */)) { break loop; } break; case 229 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8 /* EnumMember */)) { break loop; } break; case 147 /* PropertyDeclaration */: case 146 /* 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) && !(ts.getModifierFlags(location) & 32 /* 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 226 /* ClassDeclaration */: case 197 /* ClassExpression */: case 227 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793064 /* Type */)) { if (lastLocation && ts.getModifierFlags(lastLocation) & 32 /* 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 === 197 /* 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 142 /* ComputedPropertyName */: grandparent = location.parent.parent; if (ts.isClassLike(grandparent) || grandparent.kind === 227 /* InterfaceDeclaration */) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793064 /* Type */)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); return undefined; } } break; case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 225 /* FunctionDeclaration */: case 185 /* ArrowFunction */: if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } break; case 184 /* 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 145 /* 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 === 144 /* 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 && nameNotFoundMessage && noUnusedIdentifiers) { result.isReferenced = true; } if (!result) { result = getSymbol(globals, name, meaning); } if (!result) { if (nameNotFoundMessage) { if (!errorLocation || !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && !checkAndReportErrorForExtendingInterface(errorLocation) && !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) && !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning)) { 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 {} // } // const 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); } } // If we're in an external module, we can't reference value symbols created from UMD export declarations if (result && isInExternalModule && (meaning & 107455 /* Value */) === 107455 /* Value */) { var decls = result.declarations; if (decls && decls.length === 1 && decls[0].kind === 233 /* NamespaceExportDeclaration */) { error(errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, name); } } } return result; }
(location, name, meaning, nameNotFoundMessage, nameArg) { var result; var lastLocation; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; var isInExternalModule = false; 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)) { var useResult = true; if (ts.isFunctionLike(location) && lastLocation && lastLocation !== location.body) { // symbol lookup restrictions for function-like declarations // - 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. // - parameters are only in the scope of function body // This restriction does not apply to JSDoc comment types because they are parented // at a higher level than type parameters would normally be if (meaning & result.flags & 793064 /* Type */ && lastLocation.kind !== 278 /* JSDocComment */) { useResult = result.flags & 262144 /* TypeParameter */ ? lastLocation === location.type || lastLocation.kind === 144 /* Parameter */ || lastLocation.kind === 143 /* TypeParameter */ : false; } if (meaning & 107455 /* Value */ && result.flags & 1 /* FunctionScopedVariable */) { // parameters are visible only inside function body, parameter list and return type // technically for parameter list case here we might mix parameters and variables declared in function, // however it is detected separately when checking initializers of parameters // to make sure that they reference no variables declared after them. useResult = lastLocation.kind === 144 /* Parameter */ || (lastLocation === location.type && result.valueDeclaration.kind === 144 /* Parameter */); } } if (useResult) { break loop; } else { result = undefined; } } } switch (location.kind) { case 261 /* SourceFile */: if (!ts.isExternalOrCommonJsModule(location)) break; isInExternalModule = true; case 230 /* ModuleDeclaration */: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 261 /* SourceFile */ || ts.isAmbientModule(location)) { // It's an external module. First see if the module has an export default and if the local // name of that export default matches. if (result = moduleExports["default"]) { var localSymbol = ts.getLocalSymbolForExportDefault(result); if (localSymbol && (result.flags & meaning) && localSymbol.name === name) { break loop; } result = undefined; } // 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 (moduleExports[name] && moduleExports[name].flags === 8388608 /* Alias */ && ts.getDeclarationOfKind(moduleExports[name], 243 /* ExportSpecifier */)) { break; } } if (result = getSymbol(moduleExports, name, meaning & 8914931 /* ModuleMember */)) { break loop; } break; case 229 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8 /* EnumMember */)) { break loop; } break; case 147 /* PropertyDeclaration */: case 146 /* 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) && !(ts.getModifierFlags(location) & 32 /* 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 226 /* ClassDeclaration */: case 197 /* ClassExpression */: case 227 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793064 /* Type */)) { if (lastLocation && ts.getModifierFlags(lastLocation) & 32 /* 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 === 197 /* 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 142 /* ComputedPropertyName */: grandparent = location.parent.parent; if (ts.isClassLike(grandparent) || grandparent.kind === 227 /* InterfaceDeclaration */) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793064 /* Type */)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); return undefined; } } break; case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 225 /* FunctionDeclaration */: case 185 /* ArrowFunction */: if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } break; case 184 /* 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 145 /* 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 === 144 /* 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 && nameNotFoundMessage && noUnusedIdentifiers) { result.isReferenced = true; } if (!result) { result = getSymbol(globals, name, meaning); } if (!result) { if (nameNotFoundMessage) { if (!errorLocation || !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && !checkAndReportErrorForExtendingInterface(errorLocation) && !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) && !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning)) { 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 {} // } // const 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); } } // If we're in an external module, we can't reference value symbols created from UMD export declarations if (result && isInExternalModule && (meaning & 107455 /* Value */) === 107455 /* Value */) { var decls = result.declarations; if (decls && decls.length === 1 && decls[0].kind === 233 /* NamespaceExportDeclaration */) { error(errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, name); } } } return result; }
(location, name, meaning, nameNotFoundMessage, nameArg) { var result; var lastLocation; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; var isInExternalModule = false; 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)) { var useResult = true; if (ts.isFunctionLike(location) && lastLocation && lastLocation !== location.body) { // symbol lookup restrictions for function-like declarations // - 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. // - parameters are only in the scope of function body // This restriction does not apply to JSDoc comment types because they are parented // at a higher level than type parameters would normally be if (meaning & result.flags & 793064 /* Type */ && lastLocation.kind !== 278 /* JSDocComment */) { useResult = result.flags & 262144 /* TypeParameter */ ? lastLocation === location.type || lastLocation.kind === 144 /* Parameter */ || lastLocation.kind === 143 /* TypeParameter */ : false; } if (meaning & 107455 /* Value */ && result.flags & 1 /* FunctionScopedVariable */) { // parameters are visible only inside function body, parameter list and return type // technically for parameter list case here we might mix parameters and variables declared in function, // however it is detected separately when checking initializers of parameters // to make sure that they reference no variables declared after them. useResult = lastLocation.kind === 144 /* Parameter */ || (lastLocation === location.type && result.valueDeclaration.kind === 144 /* Parameter */); } } if (useResult) { break loop; } else { result = undefined; } } } switch (location.kind) { case 261 /* SourceFile */: if (!ts.isExternalOrCommonJsModule(location)) break; isInExternalModule = true; case 230 /* ModuleDeclaration */: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 261 /* SourceFile */ || ts.isAmbientModule(location)) { // It's an external module. First see if the module has an export default and if the local // name of that export default matches. if (result = moduleExports["default"]) { var localSymbol = ts.getLocalSymbolForExportDefault(result); if (localSymbol && (result.flags & meaning) && localSymbol.name === name) { break loop; } result = undefined; } // 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 (moduleExports[name] && moduleExports[name].flags === 8388608 /* Alias */ && ts.getDeclarationOfKind(moduleExports[name], 243 /* ExportSpecifier */)) { break; } } if (result = getSymbol(moduleExports, name, meaning & 8914931 /* ModuleMember */)) { break loop; } break; case 229 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8 /* EnumMember */)) { break loop; } break; case 147 /* PropertyDeclaration */: case 146 /* 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) && !(ts.getModifierFlags(location) & 32 /* 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 226 /* ClassDeclaration */: case 197 /* ClassExpression */: case 227 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793064 /* Type */)) { if (lastLocation && ts.getModifierFlags(lastLocation) & 32 /* 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 === 197 /* 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 142 /* ComputedPropertyName */: grandparent = location.parent.parent; if (ts.isClassLike(grandparent) || grandparent.kind === 227 /* InterfaceDeclaration */) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793064 /* Type */)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); return undefined; } } break; case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 225 /* FunctionDeclaration */: case 185 /* ArrowFunction */: if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } break; case 184 /* 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 145 /* 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 === 144 /* 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 && nameNotFoundMessage && noUnusedIdentifiers) { result.isReferenced = true; } if (!result) { result = getSymbol(globals, name, meaning); } if (!result) { if (nameNotFoundMessage) { if (!errorLocation || !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && !checkAndReportErrorForExtendingInterface(errorLocation) && !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) && !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning)) { 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 {} // } // const 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); } } // If we're in an external module, we can't reference value symbols created from UMD export declarations if (result && isInExternalModule && (meaning & 107455 /* Value */) === 107455 /* Value */) { var decls = result.declarations; if (decls && decls.length === 1 && decls[0].kind === 233 /* NamespaceExportDeclaration */) { error(errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, name); } } } return result; }
(location, name, meaning, nameNotFoundMessage, nameArg) { var result; var lastLocation; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; var isInExternalModule = false; 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)) { var useResult = true; if (ts.isFunctionLike(location) && lastLocation && lastLocation !== location.body) { // symbol lookup restrictions for function-like declarations // - 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. // - parameters are only in the scope of function body // This restriction does not apply to JSDoc comment types because they are parented // at a higher level than type parameters would normally be if (meaning & result.flags & 793064 /* Type */ && lastLocation.kind !== 278 /* JSDocComment */) { useResult = result.flags & 262144 /* TypeParameter */ ? lastLocation === location.type || lastLocation.kind === 144 /* Parameter */ || lastLocation.kind === 143 /* TypeParameter */ : false; } if (meaning & 107455 /* Value */ && result.flags & 1 /* FunctionScopedVariable */) { // parameters are visible only inside function body, parameter list and return type // technically for parameter list case here we might mix parameters and variables declared in function, // however it is detected separately when checking initializers of parameters // to make sure that they reference no variables declared after them. useResult = lastLocation.kind === 144 /* Parameter */ || (lastLocation === location.type && result.valueDeclaration.kind === 144 /* Parameter */); } } if (useResult) { break loop; } else { result = undefined; } } } switch (location.kind) { case 261 /* SourceFile */: if (!ts.isExternalOrCommonJsModule(location)) break; isInExternalModule = true; case 230 /* ModuleDeclaration */: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 261 /* SourceFile */ || ts.isAmbientModule(location)) { // It's an external module. First see if the module has an export default and if the local // name of that export default matches. if (result = moduleExports["default"]) { var localSymbol = ts.getLocalSymbolForExportDefault(result); if (localSymbol && (result.flags & meaning) && localSymbol.name === name) { break loop; } result = undefined; } // 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 (moduleExports[name] && moduleExports[name].flags === 8388608 /* Alias */ && ts.getDeclarationOfKind(moduleExports[name], 243 /* ExportSpecifier */)) { break; } } if (result = getSymbol(moduleExports, name, meaning & 8914931 /* ModuleMember */)) { break loop; } break; case 229 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8 /* EnumMember */)) { break loop; } break; case 147 /* PropertyDeclaration */: case 146 /* 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) && !(ts.getModifierFlags(location) & 32 /* 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 226 /* ClassDeclaration */: case 197 /* ClassExpression */: case 227 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793064 /* Type */)) { if (lastLocation && ts.getModifierFlags(lastLocation) & 32 /* 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 === 197 /* 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 142 /* ComputedPropertyName */: grandparent = location.parent.parent; if (ts.isClassLike(grandparent) || grandparent.kind === 227 /* InterfaceDeclaration */) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793064 /* Type */)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); return undefined; } } break; case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 225 /* FunctionDeclaration */: case 185 /* ArrowFunction */: if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } break; case 184 /* 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 145 /* 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 === 144 /* 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 && nameNotFoundMessage && noUnusedIdentifiers) { result.isReferenced = true; } if (!result) { result = getSymbol(globals, name, meaning); } if (!result) { if (nameNotFoundMessage) { if (!errorLocation || !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && !checkAndReportErrorForExtendingInterface(errorLocation) && !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) && !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning)) { 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 {} // } // const 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); } } // If we're in an external module, we can't reference value symbols created from UMD export declarations if (result && isInExternalModule && (meaning & 107455 /* Value */) === 107455 /* Value */) { var decls = result.declarations; if (decls && decls.length === 1 && decls[0].kind === 233 /* NamespaceExportDeclaration */) { error(errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, name); } } } return result; }
(location, name, meaning, nameNotFoundMessage, nameArg) { var result; var lastLocation; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; var isInExternalModule = false; 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)) { var useResult = true; if (ts.isFunctionLike(location) && lastLocation && lastLocation !== location.body) { // symbol lookup restrictions for function-like declarations // - 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. // - parameters are only in the scope of function body // This restriction does not apply to JSDoc comment types because they are parented // at a higher level than type parameters would normally be if (meaning & result.flags & 793064 /* Type */ && lastLocation.kind !== 278 /* JSDocComment */) { useResult = result.flags & 262144 /* TypeParameter */ ? lastLocation === location.type || lastLocation.kind === 144 /* Parameter */ || lastLocation.kind === 143 /* TypeParameter */ : false; } if (meaning & 107455 /* Value */ && result.flags & 1 /* FunctionScopedVariable */) { // parameters are visible only inside function body, parameter list and return type // technically for parameter list case here we might mix parameters and variables declared in function, // however it is detected separately when checking initializers of parameters // to make sure that they reference no variables declared after them. useResult = lastLocation.kind === 144 /* Parameter */ || (lastLocation === location.type && result.valueDeclaration.kind === 144 /* Parameter */); } } if (useResult) { break loop; } else { result = undefined; } } } switch (location.kind) { case 261 /* SourceFile */: if (!ts.isExternalOrCommonJsModule(location)) break; isInExternalModule = true; case 230 /* ModuleDeclaration */: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 261 /* SourceFile */ || ts.isAmbientModule(location)) { // It's an external module. First see if the module has an export default and if the local // name of that export default matches. if (result = moduleExports["default"]) { var localSymbol = ts.getLocalSymbolForExportDefault(result); if (localSymbol && (result.flags & meaning) && localSymbol.name === name) { break loop; } result = undefined; } // 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 (moduleExports[name] && moduleExports[name].flags === 8388608 /* Alias */ && ts.getDeclarationOfKind(moduleExports[name], 243 /* ExportSpecifier */)) { break; } } if (result = getSymbol(moduleExports, name, meaning & 8914931 /* ModuleMember */)) { break loop; } break; case 229 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8 /* EnumMember */)) { break loop; } break; case 147 /* PropertyDeclaration */: case 146 /* 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) && !(ts.getModifierFlags(location) & 32 /* 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 226 /* ClassDeclaration */: case 197 /* ClassExpression */: case 227 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793064 /* Type */)) { if (lastLocation && ts.getModifierFlags(lastLocation) & 32 /* 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 === 197 /* 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 142 /* ComputedPropertyName */: grandparent = location.parent.parent; if (ts.isClassLike(grandparent) || grandparent.kind === 227 /* InterfaceDeclaration */) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793064 /* Type */)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); return undefined; } } break; case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 225 /* FunctionDeclaration */: case 185 /* ArrowFunction */: if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } break; case 184 /* 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 145 /* 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 === 144 /* 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 && nameNotFoundMessage && noUnusedIdentifiers) { result.isReferenced = true; } if (!result) { result = getSymbol(globals, name, meaning); } if (!result) { if (nameNotFoundMessage) { if (!errorLocation || !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && !checkAndReportErrorForExtendingInterface(errorLocation) && !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) && !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning)) { 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 {} // } // const 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); } } // If we're in an external module, we can't reference value symbols created from UMD export declarations if (result && isInExternalModule && (meaning & 107455 /* Value */) === 107455 /* Value */) { var decls = result.declarations; if (decls && decls.length === 1 && decls[0].kind === 233 /* NamespaceExportDeclaration */) { error(errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, name); } } } return result; }
(location, name, meaning, nameNotFoundMessage, nameArg) { var result; var lastLocation; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; var isInExternalModule = false; 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)) { var useResult = true; if (ts.isFunctionLike(location) && lastLocation && lastLocation !== location.body) { // symbol lookup restrictions for function-like declarations // - 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. // - parameters are only in the scope of function body // This restriction does not apply to JSDoc comment types because they are parented // at a higher level than type parameters would normally be if (meaning & result.flags & 793064 /* Type */ && lastLocation.kind !== 278 /* JSDocComment */) { useResult = result.flags & 262144 /* TypeParameter */ ? lastLocation === location.type || lastLocation.kind === 144 /* Parameter */ || lastLocation.kind === 143 /* TypeParameter */ : false; } if (meaning & 107455 /* Value */ && result.flags & 1 /* FunctionScopedVariable */) { // parameters are visible only inside function body, parameter list and return type // technically for parameter list case here we might mix parameters and variables declared in function, // however it is detected separately when checking initializers of parameters // to make sure that they reference no variables declared after them. useResult = lastLocation.kind === 144 /* Parameter */ || (lastLocation === location.type && result.valueDeclaration.kind === 144 /* Parameter */); } } if (useResult) { break loop; } else { result = undefined; } } } switch (location.kind) { case 261 /* SourceFile */: if (!ts.isExternalOrCommonJsModule(location)) break; isInExternalModule = true; case 230 /* ModuleDeclaration */: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 261 /* SourceFile */ || ts.isAmbientModule(location)) { // It's an external module. First see if the module has an export default and if the local // name of that export default matches. if (result = moduleExports["default"]) { var localSymbol = ts.getLocalSymbolForExportDefault(result); if (localSymbol && (result.flags & meaning) && localSymbol.name === name) { break loop; } result = undefined; } // 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 (moduleExports[name] && moduleExports[name].flags === 8388608 /* Alias */ && ts.getDeclarationOfKind(moduleExports[name], 243 /* ExportSpecifier */)) { break; } } if (result = getSymbol(moduleExports, name, meaning & 8914931 /* ModuleMember */)) { break loop; } break; case 229 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8 /* EnumMember */)) { break loop; } break; case 147 /* PropertyDeclaration */: case 146 /* 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) && !(ts.getModifierFlags(location) & 32 /* 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 226 /* ClassDeclaration */: case 197 /* ClassExpression */: case 227 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793064 /* Type */)) { if (lastLocation && ts.getModifierFlags(lastLocation) & 32 /* 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 === 197 /* 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 142 /* ComputedPropertyName */: grandparent = location.parent.parent; if (ts.isClassLike(grandparent) || grandparent.kind === 227 /* InterfaceDeclaration */) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793064 /* Type */)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); return undefined; } } break; case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 225 /* FunctionDeclaration */: case 185 /* ArrowFunction */: if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } break; case 184 /* 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 145 /* 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 === 144 /* 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 && nameNotFoundMessage && noUnusedIdentifiers) { result.isReferenced = true; } if (!result) { result = getSymbol(globals, name, meaning); } if (!result) { if (nameNotFoundMessage) { if (!errorLocation || !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && !checkAndReportErrorForExtendingInterface(errorLocation) && !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) && !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning)) { 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 {} // } // const 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); } } // If we're in an external module, we can't reference value symbols created from UMD export declarations if (result && isInExternalModule && (meaning & 107455 /* Value */) === 107455 /* Value */) { var decls = result.declarations; if (decls && decls.length === 1 && decls[0].kind === 233 /* NamespaceExportDeclaration */) { error(errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, name); } } } return result; }
(location, name, meaning, nameNotFoundMessage, nameArg) { var result; var lastLocation; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; var isInExternalModule = false; 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)) { var useResult = true; if (ts.isFunctionLike(location) && lastLocation && lastLocation !== location.body) { // symbol lookup restrictions for function-like declarations // - 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. // - parameters are only in the scope of function body // This restriction does not apply to JSDoc comment types because they are parented // at a higher level than type parameters would normally be if (meaning & result.flags & 793064 /* Type */ && lastLocation.kind !== 278 /* JSDocComment */) { useResult = result.flags & 262144 /* TypeParameter */ ? lastLocation === location.type || lastLocation.kind === 144 /* Parameter */ || lastLocation.kind === 143 /* TypeParameter */ : false; } if (meaning & 107455 /* Value */ && result.flags & 1 /* FunctionScopedVariable */) { // parameters are visible only inside function body, parameter list and return type // technically for parameter list case here we might mix parameters and variables declared in function, // however it is detected separately when checking initializers of parameters // to make sure that they reference no variables declared after them. useResult = lastLocation.kind === 144 /* Parameter */ || (lastLocation === location.type && result.valueDeclaration.kind === 144 /* Parameter */); } } if (useResult) { break loop; } else { result = undefined; } } } switch (location.kind) { case 261 /* SourceFile */: if (!ts.isExternalOrCommonJsModule(location)) break; isInExternalModule = true; case 230 /* ModuleDeclaration */: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 261 /* SourceFile */ || ts.isAmbientModule(location)) { // It's an external module. First see if the module has an export default and if the local // name of that export default matches. if (result = moduleExports["default"]) { var localSymbol = ts.getLocalSymbolForExportDefault(result); if (localSymbol && (result.flags & meaning) && localSymbol.name === name) { break loop; } result = undefined; } // 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 (moduleExports[name] && moduleExports[name].flags === 8388608 /* Alias */ && ts.getDeclarationOfKind(moduleExports[name], 243 /* ExportSpecifier */)) { break; } } if (result = getSymbol(moduleExports, name, meaning & 8914931 /* ModuleMember */)) { break loop; } break; case 229 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8 /* EnumMember */)) { break loop; } break; case 147 /* PropertyDeclaration */: case 146 /* 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) && !(ts.getModifierFlags(location) & 32 /* 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 226 /* ClassDeclaration */: case 197 /* ClassExpression */: case 227 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793064 /* Type */)) { if (lastLocation && ts.getModifierFlags(lastLocation) & 32 /* 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 === 197 /* 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 142 /* ComputedPropertyName */: grandparent = location.parent.parent; if (ts.isClassLike(grandparent) || grandparent.kind === 227 /* InterfaceDeclaration */) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793064 /* Type */)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); return undefined; } } break; case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 225 /* FunctionDeclaration */: case 185 /* ArrowFunction */: if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } break; case 184 /* 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 145 /* 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 === 144 /* 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 && nameNotFoundMessage && noUnusedIdentifiers) { result.isReferenced = true; } if (!result) { result = getSymbol(globals, name, meaning); } if (!result) { if (nameNotFoundMessage) { if (!errorLocation || !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && !checkAndReportErrorForExtendingInterface(errorLocation) && !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) && !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning)) { 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 {} // } // const 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); } } // If we're in an external module, we can't reference value symbols created from UMD export declarations if (result && isInExternalModule && (meaning & 107455 /* Value */) === 107455 /* Value */) { var decls = result.declarations; if (decls && decls.length === 1 && decls[0].kind === 233 /* NamespaceExportDeclaration */) { error(errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, name); } } } return result; }
(location, name, meaning, nameNotFoundMessage, nameArg) { var result; var lastLocation; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; var isInExternalModule = false; 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)) { var useResult = true; if (ts.isFunctionLike(location) && lastLocation && lastLocation !== location.body) { // symbol lookup restrictions for function-like declarations // - 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. // - parameters are only in the scope of function body // This restriction does not apply to JSDoc comment types because they are parented // at a higher level than type parameters would normally be if (meaning & result.flags & 793064 /* Type */ && lastLocation.kind !== 278 /* JSDocComment */) { useResult = result.flags & 262144 /* TypeParameter */ ? lastLocation === location.type || lastLocation.kind === 144 /* Parameter */ || lastLocation.kind === 143 /* TypeParameter */ : false; } if (meaning & 107455 /* Value */ && result.flags & 1 /* FunctionScopedVariable */) { // parameters are visible only inside function body, parameter list and return type // technically for parameter list case here we might mix parameters and variables declared in function, // however it is detected separately when checking initializers of parameters // to make sure that they reference no variables declared after them. useResult = lastLocation.kind === 144 /* Parameter */ || (lastLocation === location.type && result.valueDeclaration.kind === 144 /* Parameter */); } } if (useResult) { break loop; } else { result = undefined; } } } switch (location.kind) { case 261 /* SourceFile */: if (!ts.isExternalOrCommonJsModule(location)) break; isInExternalModule = true; case 230 /* ModuleDeclaration */: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 261 /* SourceFile */ || ts.isAmbientModule(location)) { // It's an external module. First see if the module has an export default and if the local // name of that export default matches. if (result = moduleExports["default"]) { var localSymbol = ts.getLocalSymbolForExportDefault(result); if (localSymbol && (result.flags & meaning) && localSymbol.name === name) { break loop; } result = undefined; } // 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 (moduleExports[name] && moduleExports[name].flags === 8388608 /* Alias */ && ts.getDeclarationOfKind(moduleExports[name], 243 /* ExportSpecifier */)) { break; } } if (result = getSymbol(moduleExports, name, meaning & 8914931 /* ModuleMember */)) { break loop; } break; case 229 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8 /* EnumMember */)) { break loop; } break; case 147 /* PropertyDeclaration */: case 146 /* 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) && !(ts.getModifierFlags(location) & 32 /* 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 226 /* ClassDeclaration */: case 197 /* ClassExpression */: case 227 /* InterfaceDeclaration */: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793064 /* Type */)) { if (lastLocation && ts.getModifierFlags(lastLocation) & 32 /* 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 === 197 /* 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 142 /* ComputedPropertyName */: grandparent = location.parent.parent; if (ts.isClassLike(grandparent) || grandparent.kind === 227 /* InterfaceDeclaration */) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793064 /* Type */)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); return undefined; } } break; case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 225 /* FunctionDeclaration */: case 185 /* ArrowFunction */: if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } break; case 184 /* 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 145 /* 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 === 144 /* 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 && nameNotFoundMessage && noUnusedIdentifiers) { result.isReferenced = true; } if (!result) { result = getSymbol(globals, name, meaning); } if (!result) { if (nameNotFoundMessage) { if (!errorLocation || !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && !checkAndReportErrorForExtendingInterface(errorLocation) && !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) && !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning)) { 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 {} // } // const 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); } } // If we're in an external module, we can't reference value symbols created from UMD export declarations if (result && isInExternalModule && (meaning & 107455 /* Value */) === 107455 /* Value */) { var decls = result.declarations; if (decls && decls.length === 1 && decls[0].kind === 233 /* NamespaceExportDeclaration */) { error(errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, name); } } } return result; }
checkGrammarTypeArguments:
(node, typeArguments) { return checkGrammarForDisallowedTrailingComma(typeArguments) || checkGrammarForAtLeastOneTypeArgument(node, typeArguments); }
getTypeFromNonGenericTypeReference:
(node, symbol) { if (node.typeArguments) { error(node, ts.Diagnostics.Type_0_is_not_generic, symbolToString(symbol)); return unknownType; } return getDeclaredTypeOfSymbol(symbol); }
getDeclaredTypeOfTypeParameter:
(symbol) { var links = getSymbolLinks(symbol); if (!links.declaredType) { var type = createType(16384 /* TypeParameter */); type.symbol = symbol; if (!ts.getDeclarationOfKind(symbol, 143 /* TypeParameter */).constraint) { type.constraint = noConstraintType; } links.declaredType = type; } return links.declaredType; }
(symbol) { var links = getSymbolLinks(symbol); if (!links.declaredType) { var type = createType(16384 /* TypeParameter */); type.symbol = symbol; if (!ts.getDeclarationOfKind(symbol, 143 /* TypeParameter */).constraint) { type.constraint = noConstraintType; } links.declaredType = type; } return links.declaredType; }
createObjectType:
(objectFlags, symbol) { var type = createType(32768 /* Object */); type.objectFlags = objectFlags; type.symbol = symbol; return type; }
getTypeFromTypeReference:
(node) { var links = getNodeLinks(node); if (!links.resolvedType) { var symbol = void 0; var type = void 0; if (node.kind === 272 /* JSDocTypeReference */) { var typeReferenceName = getTypeReferenceName(node); symbol = resolveTypeReferenceName(typeReferenceName); type = getTypeReferenceType(node, symbol); } else { // We only support expressions that are simple qualified names. For other expressions this produces undefined. var typeNameOrExpression = node.kind === 157 /* TypeReference */ ? node.typeName : ts.isEntityNameExpression(node.expression) ? node.expression : undefined; symbol = typeNameOrExpression && resolveEntityName(typeNameOrExpression, 793064 /* Type */) || unknownSymbol; type = symbol === unknownSymbol ? unknownType : symbol.flags & (32 /* Class */ | 64 /* Interface */) ? getTypeFromClassOrInterfaceReference(node, symbol) : symbol.flags & 524288 /* TypeAlias */ ? getTypeFromTypeAliasReference(node, symbol) : getTypeFromNonGenericTypeReference(node, symbol); } // Cache both the resolved symbol and the resolved type. The resolved symbol is needed in when we check the // type reference in checkTypeReferenceOrExpressionWithTypeArguments. links.resolvedSymbol = symbol; links.resolvedType = type; } return links.resolvedType; }
checkCollisionWithRequireExportsInGeneratedCode:
(node, name) { // No need to check for require or exports for ES6 modules and later if (modulekind >= ts.ModuleKind.ES2015) { return; } if (!needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) { return; } // Uninstantiated modules shouldnt do this check if (node.kind === 230 /* ModuleDeclaration */ && ts.getModuleInstanceState(node) !== 1 /* Instantiated */) { return; } // In case of variable declaration, node.parent is variable statement so look at the variable statement's parent var parent = getDeclarationContainer(node); if (parent.kind === 261 /* SourceFile */ && ts.isExternalOrCommonJsModule(parent)) { // If the declaration happens to be in external module, report error that require and exports are reserved keywords error(name, ts.Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_a_module, ts.declarationNameToString(name), ts.declarationNameToString(name)); } }
isExternalOrCommonJsModule:
(file) { return (file.externalModuleIndicator || file.commonJsModuleIndicator) !== undefined; }
(file) { return (file.externalModuleIndicator || file.commonJsModuleIndicator) !== undefined; }
Deopt: <JS Function nodeIsMissing (SharedFunctionInfo 0x2c75c4acca81)> (opt #531) @2, FP to SP delta: 24, caller sp: 0x7fff5fbfd7c0
checkParameter:
(node) { // Grammar checking // It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the // Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code // or if its FunctionBody is strict code(11.1.5). // Grammar checking checkGrammarDecorators(node) || checkGrammarModifiers(node); checkVariableLikeDeclaration(node); var func = ts.getContainingFunction(node); if (ts.getModifierFlags(node) & 92 /* ParameterPropertyModifier */) { func = ts.getContainingFunction(node); if (!(func.kind === 150 /* Constructor */ && ts.nodeIsPresent(func.body))) { error(node, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } } if (node.questionToken && ts.isBindingPattern(node.name) && func.body) { error(node, ts.Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature); } if (node.name.text === "this") { if (ts.indexOf(func.parameters, node) !== 0) { error(node, ts.Diagnostics.A_this_parameter_must_be_the_first_parameter); } if (func.kind === 150 /* Constructor */ || func.kind === 154 /* ConstructSignature */ || func.kind === 159 /* ConstructorType */) { error(node, ts.Diagnostics.A_constructor_cannot_have_a_this_parameter); } } // Only check rest parameter type if it's not a binding pattern. Since binding patterns are // not allowed in a rest parameter, we already have an error from checkGrammarParameterList. if (node.dotDotDotToken && !ts.isBindingPattern(node.name) && !isArrayType(getTypeOfSymbol(node.symbol))) { error(node, ts.Diagnostics.A_rest_parameter_must_be_of_an_array_type); } }
(node) { // Grammar checking // It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the // Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code // or if its FunctionBody is strict code(11.1.5). // Grammar checking checkGrammarDecorators(node) || checkGrammarModifiers(node); checkVariableLikeDeclaration(node); var func = ts.getContainingFunction(node); if (ts.getModifierFlags(node) & 92 /* ParameterPropertyModifier */) { func = ts.getContainingFunction(node); if (!(func.kind === 150 /* Constructor */ && ts.nodeIsPresent(func.body))) { error(node, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } } if (node.questionToken && ts.isBindingPattern(node.name) && func.body) { error(node, ts.Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature); } if (node.name.text === "this") { if (ts.indexOf(func.parameters, node) !== 0) { error(node, ts.Diagnostics.A_this_parameter_must_be_the_first_parameter); } if (func.kind === 150 /* Constructor */ || func.kind === 154 /* ConstructSignature */ || func.kind === 159 /* ConstructorType */) { error(node, ts.Diagnostics.A_constructor_cannot_have_a_this_parameter); } } // Only check rest parameter type if it's not a binding pattern. Since binding patterns are // not allowed in a rest parameter, we already have an error from checkGrammarParameterList. if (node.dotDotDotToken && !ts.isBindingPattern(node.name) && !isArrayType(getTypeOfSymbol(node.symbol))) { error(node, ts.Diagnostics.A_rest_parameter_must_be_of_an_array_type); } }
getDeclaredTypeOfSymbol:
(symbol) { ts.Debug.assert((symbol.flags & 16777216 /* Instantiated */) === 0); if (symbol.flags & (32 /* Class */ | 64 /* Interface */)) { return getDeclaredTypeOfClassOrInterface(symbol); } if (symbol.flags & 524288 /* TypeAlias */) { return getDeclaredTypeOfTypeAlias(symbol); } if (symbol.flags & 262144 /* TypeParameter */) { return getDeclaredTypeOfTypeParameter(symbol); } if (symbol.flags & 384 /* Enum */) { return getDeclaredTypeOfEnum(symbol); } if (symbol.flags & 8 /* EnumMember */) { return getDeclaredTypeOfEnumMember(symbol); } if (symbol.flags & 8388608 /* Alias */) { return getDeclaredTypeOfAlias(symbol); } return unknownType; }
(symbol) { ts.Debug.assert((symbol.flags & 16777216 /* Instantiated */) === 0); if (symbol.flags & (32 /* Class */ | 64 /* Interface */)) { return getDeclaredTypeOfClassOrInterface(symbol); } if (symbol.flags & 524288 /* TypeAlias */) { return getDeclaredTypeOfTypeAlias(symbol); } if (symbol.flags & 262144 /* TypeParameter */) { return getDeclaredTypeOfTypeParameter(symbol); } if (symbol.flags & 384 /* Enum */) { return getDeclaredTypeOfEnum(symbol); } if (symbol.flags & 8 /* EnumMember */) { return getDeclaredTypeOfEnumMember(symbol); } if (symbol.flags & 8388608 /* Alias */) { return getDeclaredTypeOfAlias(symbol); } return unknownType; }
isNumericName:
(name) { return name.kind === 142 /* ComputedPropertyName */ ? isNumericComputedName(name) : isNumericLiteralName(name.text); }
(name) { return name.kind === 142 /* ComputedPropertyName */ ? isNumericComputedName(name) : isNumericLiteralName(name.text); }
instantiateType:
(type, mapper) { if (type && mapper !== identityMapper) { // If we are instantiating a type that has a top-level type alias, obtain the instantiation through // the type alias instead in order to share instantiations for the same type arguments. This can // dramatically reduce the number of structurally identical types we generate. Note that we can only // perform this optimization for top-level type aliases. Consider: // // function f1<T>(x: T) { // type Foo<X> = { x: X, t: T }; // let obj: Foo<T> = { x: x }; // return obj; // } // function f2<U>(x: U) { return f1(x); } // let z = f2(42); // // Above, the declaration of f2 has an inferred return type that is an instantiation of f1's Foo<X> // equivalent to { x: U, t: U }. When instantiating this return type, we can't go back to Foo<X>'s // cache because all cached instantiations are of the form { x: ???, t: T }, i.e. they have not been // instantiated for T. Instead, we need to further instantiate the { x: U, t: U } form. if (type.aliasSymbol && isTopLevelTypeAlias(type.aliasSymbol)) { if (type.aliasTypeArguments) { return getTypeAliasInstantiation(type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper)); } return type; } return instantiateTypeNoAlias(type, mapper); } return type; }
Deopt: <JS Function isNumericName (SharedFunctionInfo 0x3fca58608e81)> (opt #341) @2, FP to SP delta: 24, caller sp: 0x7fff5fbfde40
(type, mapper) { if (type && mapper !== identityMapper) { // If we are instantiating a type that has a top-level type alias, obtain the instantiation through // the type alias instead in order to share instantiations for the same type arguments. This can // dramatically reduce the number of structurally identical types we generate. Note that we can only // perform this optimization for top-level type aliases. Consider: // // function f1<T>(x: T) { // type Foo<X> = { x: X, t: T }; // let obj: Foo<T> = { x: x }; // return obj; // } // function f2<U>(x: U) { return f1(x); } // let z = f2(42); // // Above, the declaration of f2 has an inferred return type that is an instantiation of f1's Foo<X> // equivalent to { x: U, t: U }. When instantiating this return type, we can't go back to Foo<X>'s // cache because all cached instantiations are of the form { x: ???, t: T }, i.e. they have not been // instantiated for T. Instead, we need to further instantiate the { x: U, t: U } form. if (type.aliasSymbol && isTopLevelTypeAlias(type.aliasSymbol)) { if (type.aliasTypeArguments) { return getTypeAliasInstantiation(type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper)); } return type; } return instantiateTypeNoAlias(type, mapper); } return type; }
getAliasSymbolForTypeNode:
(node) { return node.parent.kind === 228 /* TypeAliasDeclaration */ ? getSymbolOfNode(node.parent) : undefined; }
getTypeOfVariableOrParameterOrProperty:
(symbol) { var links = getSymbolLinks(symbol); if (!links.type) { // Handle prototype property if (symbol.flags & 134217728 /* Prototype */) { return links.type = getTypeOfPrototypeProperty(symbol); } // Handle catch clause variables var declaration = symbol.valueDeclaration; if (ts.isCatchClauseVariableDeclarationOrBindingElement(declaration)) { return links.type = anyType; } // Handle export default expressions if (declaration.kind === 240 /* ExportAssignment */) { return links.type = checkExpression(declaration.expression); } if (declaration.flags & 65536 /* JavaScriptFile */ && declaration.kind === 286 /* JSDocPropertyTag */ && declaration.typeExpression) { return links.type = getTypeFromTypeNode(declaration.typeExpression.type); } // Handle variable, parameter or property if (!pushTypeResolution(symbol, 0 /* Type */)) { return unknownType; } var type = void 0; // Handle certain special assignment kinds, which happen to union across multiple declarations: // * module.exports = expr // * exports.p = expr // * this.p = expr // * className.prototype.method = expr if (declaration.kind === 192 /* BinaryExpression */ || declaration.kind === 177 /* PropertyAccessExpression */ && declaration.parent.kind === 192 /* BinaryExpression */) { // Use JS Doc type if present on parent expression statement if (declaration.flags & 65536 /* JavaScriptFile */) { var jsdocType = ts.getJSDocType(declaration.parent); if (jsdocType) { return links.type = getTypeFromTypeNode(jsdocType); } } var declaredTypes = ts.map(symbol.declarations, function (decl) { return decl.kind === 192 /* BinaryExpression */ ? checkExpressionCached(decl.right) : checkExpressionCached(decl.parent.right); }); type = getUnionType(declaredTypes, /*subtypeReduction*/ true); } else { type = getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true); } if (!popTypeResolution()) { type = reportCircularityError(symbol); } links.type = type; } return links.type; }
(symbol) { var links = getSymbolLinks(symbol); if (!links.type) { // Handle prototype property if (symbol.flags & 134217728 /* Prototype */) { return links.type = getTypeOfPrototypeProperty(symbol); } // Handle catch clause variables var declaration = symbol.valueDeclaration; if (ts.isCatchClauseVariableDeclarationOrBindingElement(declaration)) { return links.type = anyType; } // Handle export default expressions if (declaration.kind === 240 /* ExportAssignment */) { return links.type = checkExpression(declaration.expression); } if (declaration.flags & 65536 /* JavaScriptFile */ && declaration.kind === 286 /* JSDocPropertyTag */ && declaration.typeExpression) { return links.type = getTypeFromTypeNode(declaration.typeExpression.type); } // Handle variable, parameter or property if (!pushTypeResolution(symbol, 0 /* Type */)) { return unknownType; } var type = void 0; // Handle certain special assignment kinds, which happen to union across multiple declarations: // * module.exports = expr // * exports.p = expr // * this.p = expr // * className.prototype.method = expr if (declaration.kind === 192 /* BinaryExpression */ || declaration.kind === 177 /* PropertyAccessExpression */ && declaration.parent.kind === 192 /* BinaryExpression */) { // Use JS Doc type if present on parent expression statement if (declaration.flags & 65536 /* JavaScriptFile */) { var jsdocType = ts.getJSDocType(declaration.parent); if (jsdocType) { return links.type = getTypeFromTypeNode(jsdocType); } } var declaredTypes = ts.map(symbol.declarations, function (decl) { return decl.kind === 192 /* BinaryExpression */ ? checkExpressionCached(decl.right) : checkExpressionCached(decl.parent.right); }); type = getUnionType(declaredTypes, /*subtypeReduction*/ true); } else { type = getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true); } if (!popTypeResolution()) { type = reportCircularityError(symbol); } links.type = type; } return links.type; }
(symbol) { var links = getSymbolLinks(symbol); if (!links.type) { // Handle prototype property if (symbol.flags & 134217728 /* Prototype */) { return links.type = getTypeOfPrototypeProperty(symbol); } // Handle catch clause variables var declaration = symbol.valueDeclaration; if (ts.isCatchClauseVariableDeclarationOrBindingElement(declaration)) { return links.type = anyType; } // Handle export default expressions if (declaration.kind === 240 /* ExportAssignment */) { return links.type = checkExpression(declaration.expression); } if (declaration.flags & 65536 /* JavaScriptFile */ && declaration.kind === 286 /* JSDocPropertyTag */ && declaration.typeExpression) { return links.type = getTypeFromTypeNode(declaration.typeExpression.type); } // Handle variable, parameter or property if (!pushTypeResolution(symbol, 0 /* Type */)) { return unknownType; } var type = void 0; // Handle certain special assignment kinds, which happen to union across multiple declarations: // * module.exports = expr // * exports.p = expr // * this.p = expr // * className.prototype.method = expr if (declaration.kind === 192 /* BinaryExpression */ || declaration.kind === 177 /* PropertyAccessExpression */ && declaration.parent.kind === 192 /* BinaryExpression */) { // Use JS Doc type if present on parent expression statement if (declaration.flags & 65536 /* JavaScriptFile */) { var jsdocType = ts.getJSDocType(declaration.parent); if (jsdocType) { return links.type = getTypeFromTypeNode(jsdocType); } } var declaredTypes = ts.map(symbol.declarations, function (decl) { return decl.kind === 192 /* BinaryExpression */ ? checkExpressionCached(decl.right) : checkExpressionCached(decl.parent.right); }); type = getUnionType(declaredTypes, /*subtypeReduction*/ true); } else { type = getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true); } if (!popTypeResolution()) { type = reportCircularityError(symbol); } links.type = type; } return links.type; }
(symbol) { var links = getSymbolLinks(symbol); if (!links.type) { // Handle prototype property if (symbol.flags & 134217728 /* Prototype */) { return links.type = getTypeOfPrototypeProperty(symbol); } // Handle catch clause variables var declaration = symbol.valueDeclaration; if (ts.isCatchClauseVariableDeclarationOrBindingElement(declaration)) { return links.type = anyType; } // Handle export default expressions if (declaration.kind === 240 /* ExportAssignment */) { return links.type = checkExpression(declaration.expression); } if (declaration.flags & 65536 /* JavaScriptFile */ && declaration.kind === 286 /* JSDocPropertyTag */ && declaration.typeExpression) { return links.type = getTypeFromTypeNode(declaration.typeExpression.type); } // Handle variable, parameter or property if (!pushTypeResolution(symbol, 0 /* Type */)) { return unknownType; } var type = void 0; // Handle certain special assignment kinds, which happen to union across multiple declarations: // * module.exports = expr // * exports.p = expr // * this.p = expr // * className.prototype.method = expr if (declaration.kind === 192 /* BinaryExpression */ || declaration.kind === 177 /* PropertyAccessExpression */ && declaration.parent.kind === 192 /* BinaryExpression */) { // Use JS Doc type if present on parent expression statement if (declaration.flags & 65536 /* JavaScriptFile */) { var jsdocType = ts.getJSDocType(declaration.parent); if (jsdocType) { return links.type = getTypeFromTypeNode(jsdocType); } } var declaredTypes = ts.map(symbol.declarations, function (decl) { return decl.kind === 192 /* BinaryExpression */ ? checkExpressionCached(decl.right) : checkExpressionCached(decl.parent.right); }); type = getUnionType(declaredTypes, /*subtypeReduction*/ true); } else { type = getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true); } if (!popTypeResolution()) { type = reportCircularityError(symbol); } links.type = type; } return links.type; }
(symbol) { var links = getSymbolLinks(symbol); if (!links.type) { // Handle prototype property if (symbol.flags & 134217728 /* Prototype */) { return links.type = getTypeOfPrototypeProperty(symbol); } // Handle catch clause variables var declaration = symbol.valueDeclaration; if (ts.isCatchClauseVariableDeclarationOrBindingElement(declaration)) { return links.type = anyType; } // Handle export default expressions if (declaration.kind === 240 /* ExportAssignment */) { return links.type = checkExpression(declaration.expression); } if (declaration.flags & 65536 /* JavaScriptFile */ && declaration.kind === 286 /* JSDocPropertyTag */ && declaration.typeExpression) { return links.type = getTypeFromTypeNode(declaration.typeExpression.type); } // Handle variable, parameter or property if (!pushTypeResolution(symbol, 0 /* Type */)) { return unknownType; } var type = void 0; // Handle certain special assignment kinds, which happen to union across multiple declarations: // * module.exports = expr // * exports.p = expr // * this.p = expr // * className.prototype.method = expr if (declaration.kind === 192 /* BinaryExpression */ || declaration.kind === 177 /* PropertyAccessExpression */ && declaration.parent.kind === 192 /* BinaryExpression */) { // Use JS Doc type if present on parent expression statement if (declaration.flags & 65536 /* JavaScriptFile */) { var jsdocType = ts.getJSDocType(declaration.parent); if (jsdocType) { return links.type = getTypeFromTypeNode(jsdocType); } } var declaredTypes = ts.map(symbol.declarations, function (decl) { return decl.kind === 192 /* BinaryExpression */ ? checkExpressionCached(decl.right) : checkExpressionCached(decl.parent.right); }); type = getUnionType(declaredTypes, /*subtypeReduction*/ true); } else { type = getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true); } if (!popTypeResolution()) { type = reportCircularityError(symbol); } links.type = type; } return links.type; }
resolveEntityName:
(name, meaning, ignoreErrors, dontResolveAlias, location) { if (ts.nodeIsMissing(name)) { return undefined; } var symbol; if (name.kind === 70 /* Identifier */) { var message = meaning === 1920 /* Namespace */ ? ts.Diagnostics.Cannot_find_namespace_0 : ts.Diagnostics.Cannot_find_name_0; symbol = resolveName(location || name, name.text, meaning, ignoreErrors ? undefined : message, name); if (!symbol) { return undefined; } } else if (name.kind === 141 /* QualifiedName */ || name.kind === 177 /* PropertyAccessExpression */) { var left = name.kind === 141 /* QualifiedName */ ? name.left : name.expression; var right = name.kind === 141 /* QualifiedName */ ? name.right : name.name; var namespace = resolveEntityName(left, 1920 /* Namespace */, ignoreErrors, /*dontResolveAlias*/ false, location); if (!namespace || ts.nodeIsMissing(right)) { return undefined; } else if (namespace === unknownSymbol) { return namespace; } symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning); if (!symbol) { if (!ignoreErrors) { error(right, ts.Diagnostics.Namespace_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) || dontResolveAlias ? symbol : resolveAlias(symbol); }
(name, meaning, ignoreErrors, dontResolveAlias, location) { if (ts.nodeIsMissing(name)) { return undefined; } var symbol; if (name.kind === 70 /* Identifier */) { var message = meaning === 1920 /* Namespace */ ? ts.Diagnostics.Cannot_find_namespace_0 : ts.Diagnostics.Cannot_find_name_0; symbol = resolveName(location || name, name.text, meaning, ignoreErrors ? undefined : message, name); if (!symbol) { return undefined; } } else if (name.kind === 141 /* QualifiedName */ || name.kind === 177 /* PropertyAccessExpression */) { var left = name.kind === 141 /* QualifiedName */ ? name.left : name.expression; var right = name.kind === 141 /* QualifiedName */ ? name.right : name.name; var namespace = resolveEntityName(left, 1920 /* Namespace */, ignoreErrors, /*dontResolveAlias*/ false, location); if (!namespace || ts.nodeIsMissing(right)) { return undefined; } else if (namespace === unknownSymbol) { return namespace; } symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning); if (!symbol) { if (!ignoreErrors) { error(right, ts.Diagnostics.Namespace_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) || dontResolveAlias ? symbol : resolveAlias(symbol); }
(name, meaning, ignoreErrors, dontResolveAlias, location) { if (ts.nodeIsMissing(name)) { return undefined; } var symbol; if (name.kind === 70 /* Identifier */) { var message = meaning === 1920 /* Namespace */ ? ts.Diagnostics.Cannot_find_namespace_0 : ts.Diagnostics.Cannot_find_name_0; symbol = resolveName(location || name, name.text, meaning, ignoreErrors ? undefined : message, name); if (!symbol) { return undefined; } } else if (name.kind === 141 /* QualifiedName */ || name.kind === 177 /* PropertyAccessExpression */) { var left = name.kind === 141 /* QualifiedName */ ? name.left : name.expression; var right = name.kind === 141 /* QualifiedName */ ? name.right : name.name; var namespace = resolveEntityName(left, 1920 /* Namespace */, ignoreErrors, /*dontResolveAlias*/ false, location); if (!namespace || ts.nodeIsMissing(right)) { return undefined; } else if (namespace === unknownSymbol) { return namespace; } symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning); if (!symbol) { if (!ignoreErrors) { error(right, ts.Diagnostics.Namespace_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) || dontResolveAlias ? symbol : resolveAlias(symbol); }
getTypeOfInstantiatedSymbol:
(symbol) { var links = getSymbolLinks(symbol); if (!links.type) { if (!pushTypeResolution(symbol, 0 /* Type */)) { return unknownType; } var type = instantiateType(getTypeOfSymbol(links.target), links.mapper); if (!popTypeResolution()) { type = reportCircularityError(symbol); } links.type = type; } return links.type; }
(symbol) { var links = getSymbolLinks(symbol); if (!links.type) { if (!pushTypeResolution(symbol, 0 /* Type */)) { return unknownType; } var type = instantiateType(getTypeOfSymbol(links.target), links.mapper); if (!popTypeResolution()) { type = reportCircularityError(symbol); } links.type = type; } return links.type; }
instantiateTypes:
(types, mapper) { return instantiateList(types, mapper, instantiateType); }
(types, mapper) { return instantiateList(types, mapper, instantiateType); }
(types, mapper) { return instantiateList(types, mapper, instantiateType); }
checkMethodDeclaration:
(node) { // Grammar checking checkGrammarMethod(node) || checkGrammarComputedPropertyName(node.name); // Grammar checking for modifiers is done inside the function checkGrammarFunctionLikeDeclaration checkFunctionOrMethodDeclaration(node); // Abstract methods cannot have an implementation. // Extra checks are to avoid reporting multiple errors relating to the "abstractness" of the node. if (ts.getModifierFlags(node) & 128 /* Abstract */ && node.body) { error(node, ts.Diagnostics.Method_0_cannot_have_an_implementation_because_it_is_marked_abstract, ts.declarationNameToString(node.name)); } }
(node) { // Grammar checking checkGrammarMethod(node) || checkGrammarComputedPropertyName(node.name); // Grammar checking for modifiers is done inside the function checkGrammarFunctionLikeDeclaration checkFunctionOrMethodDeclaration(node); // Abstract methods cannot have an implementation. // Extra checks are to avoid reporting multiple errors relating to the "abstractness" of the node. if (ts.getModifierFlags(node) & 128 /* Abstract */ && node.body) { error(node, ts.Diagnostics.Method_0_cannot_have_an_implementation_because_it_is_marked_abstract, ts.declarationNameToString(node.name)); } }
(node) { // Grammar checking checkGrammarMethod(node) || checkGrammarComputedPropertyName(node.name); // Grammar checking for modifiers is done inside the function checkGrammarFunctionLikeDeclaration checkFunctionOrMethodDeclaration(node); // Abstract methods cannot have an implementation. // Extra checks are to avoid reporting multiple errors relating to the "abstractness" of the node. if (ts.getModifierFlags(node) & 128 /* Abstract */ && node.body) { error(node, ts.Diagnostics.Method_0_cannot_have_an_implementation_because_it_is_marked_abstract, ts.declarationNameToString(node.name)); } }
(node) { // Grammar checking checkGrammarMethod(node) || checkGrammarComputedPropertyName(node.name); // Grammar checking for modifiers is done inside the function checkGrammarFunctionLikeDeclaration checkFunctionOrMethodDeclaration(node); // Abstract methods cannot have an implementation. // Extra checks are to avoid reporting multiple errors relating to the "abstractness" of the node. if (ts.getModifierFlags(node) & 128 /* Abstract */ && node.body) { error(node, ts.Diagnostics.Method_0_cannot_have_an_implementation_because_it_is_marked_abstract, ts.declarationNameToString(node.name)); } }
instantiateCached:
(type, mapper, instantiator) { var instantiations = mapper.instantiations || (mapper.instantiations = []); return instantiations[type.id] || (instantiations[type.id] = instantiator(type, mapper)); }
instantiateAnonymousType:
(type, mapper) { var result = createObjectType(16 /* Anonymous */ | 64 /* Instantiated */, type.symbol); result.target = type.objectFlags & 64 /* Instantiated */ ? type.target : type; result.mapper = type.objectFlags & 64 /* Instantiated */ ? combineTypeMappers(type.mapper, mapper) : mapper; result.aliasSymbol = type.aliasSymbol; result.aliasTypeArguments = instantiateTypes(type.aliasTypeArguments, mapper); return result; }
(type, mapper) { var result = createObjectType(16 /* Anonymous */ | 64 /* Instantiated */, type.symbol); result.target = type.objectFlags & 64 /* Instantiated */ ? type.target : type; result.mapper = type.objectFlags & 64 /* Instantiated */ ? combineTypeMappers(type.mapper, mapper) : mapper; result.aliasSymbol = type.aliasSymbol; result.aliasTypeArguments = instantiateTypes(type.aliasTypeArguments, mapper); return result; }
(type, mapper) { var result = createObjectType(16 /* Anonymous */ | 64 /* Instantiated */, type.symbol); result.target = type.objectFlags & 64 /* Instantiated */ ? type.target : type; result.mapper = type.objectFlags & 64 /* Instantiated */ ? combineTypeMappers(type.mapper, mapper) : mapper; result.aliasSymbol = type.aliasSymbol; result.aliasTypeArguments = instantiateTypes(type.aliasTypeArguments, mapper); return result; }
getTypeOfSymbol:
(symbol) { if (symbol.flags & 16777216 /* Instantiated */) { return getTypeOfInstantiatedSymbol(symbol); } if (symbol.flags & (3 /* Variable */ | 4 /* Property */)) { return getTypeOfVariableOrParameterOrProperty(symbol); } if (symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) { return getTypeOfFuncClassEnumModule(symbol); } if (symbol.flags & 8 /* EnumMember */) { return getTypeOfEnumMember(symbol); } if (symbol.flags & 98304 /* Accessor */) { return getTypeOfAccessors(symbol); } if (symbol.flags & 8388608 /* Alias */) { return getTypeOfAlias(symbol); } return unknownType; }
(symbol) { if (symbol.flags & 16777216 /* Instantiated */) { return getTypeOfInstantiatedSymbol(symbol); } if (symbol.flags & (3 /* Variable */ | 4 /* Property */)) { return getTypeOfVariableOrParameterOrProperty(symbol); } if (symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) { return getTypeOfFuncClassEnumModule(symbol); } if (symbol.flags & 8 /* EnumMember */) { return getTypeOfEnumMember(symbol); } if (symbol.flags & 98304 /* Accessor */) { return getTypeOfAccessors(symbol); } if (symbol.flags & 8388608 /* Alias */) { return getTypeOfAlias(symbol); } return unknownType; }
(symbol) { if (symbol.flags & 16777216 /* Instantiated */) { return getTypeOfInstantiatedSymbol(symbol); } if (symbol.flags & (3 /* Variable */ | 4 /* Property */)) { return getTypeOfVariableOrParameterOrProperty(symbol); } if (symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) { return getTypeOfFuncClassEnumModule(symbol); } if (symbol.flags & 8 /* EnumMember */) { return getTypeOfEnumMember(symbol); } if (symbol.flags & 98304 /* Accessor */) { return getTypeOfAccessors(symbol); } if (symbol.flags & 8388608 /* Alias */) { return getTypeOfAlias(symbol); } return unknownType; }
(symbol) { if (symbol.flags & 16777216 /* Instantiated */) { return getTypeOfInstantiatedSymbol(symbol); } if (symbol.flags & (3 /* Variable */ | 4 /* Property */)) { return getTypeOfVariableOrParameterOrProperty(symbol); } if (symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) { return getTypeOfFuncClassEnumModule(symbol); } if (symbol.flags & 8 /* EnumMember */) { return getTypeOfEnumMember(symbol); } if (symbol.flags & 98304 /* Accessor */) { return getTypeOfAccessors(symbol); } if (symbol.flags & 8388608 /* Alias */) { return getTypeOfAlias(symbol); } return unknownType; }
(symbol) { if (symbol.flags & 16777216 /* Instantiated */) { return getTypeOfInstantiatedSymbol(symbol); } if (symbol.flags & (3 /* Variable */ | 4 /* Property */)) { return getTypeOfVariableOrParameterOrProperty(symbol); } if (symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) { return getTypeOfFuncClassEnumModule(symbol); } if (symbol.flags & 8 /* EnumMember */) { return getTypeOfEnumMember(symbol); } if (symbol.flags & 98304 /* Accessor */) { return getTypeOfAccessors(symbol); } if (symbol.flags & 8388608 /* Alias */) { return getTypeOfAlias(symbol); } return unknownType; }
(symbol) { if (symbol.flags & 16777216 /* Instantiated */) { return getTypeOfInstantiatedSymbol(symbol); } if (symbol.flags & (3 /* Variable */ | 4 /* Property */)) { return getTypeOfVariableOrParameterOrProperty(symbol); } if (symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) { return getTypeOfFuncClassEnumModule(symbol); } if (symbol.flags & 8 /* EnumMember */) { return getTypeOfEnumMember(symbol); } if (symbol.flags & 98304 /* Accessor */) { return getTypeOfAccessors(symbol); } if (symbol.flags & 8388608 /* Alias */) { return getTypeOfAlias(symbol); } return unknownType; }
isIndependentMember:
(symbol) { if (symbol.declarations && symbol.declarations.length === 1) { var declaration = symbol.declarations[0]; if (declaration) { switch (declaration.kind) { case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: return isIndependentVariableLikeDeclaration(declaration); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: return isIndependentFunctionLikeDeclaration(declaration); } } } return false; }
(symbol) { if (symbol.declarations && symbol.declarations.length === 1) { var declaration = symbol.declarations[0]; if (declaration) { switch (declaration.kind) { case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: return isIndependentVariableLikeDeclaration(declaration); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: return isIndependentFunctionLikeDeclaration(declaration); } } } return false; }
(symbol) { if (symbol.declarations && symbol.declarations.length === 1) { var declaration = symbol.declarations[0]; if (declaration) { switch (declaration.kind) { case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: return isIndependentVariableLikeDeclaration(declaration); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: return isIndependentFunctionLikeDeclaration(declaration); } } } return false; }
(symbol) { if (symbol.declarations && symbol.declarations.length === 1) { var declaration = symbol.declarations[0]; if (declaration) { switch (declaration.kind) { case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: return isIndependentVariableLikeDeclaration(declaration); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: return isIndependentFunctionLikeDeclaration(declaration); } } } return false; }
(symbol) { if (symbol.declarations && symbol.declarations.length === 1) { var declaration = symbol.declarations[0]; if (declaration) { switch (declaration.kind) { case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: return isIndependentVariableLikeDeclaration(declaration); case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: return isIndependentFunctionLikeDeclaration(declaration); } } } return false; }
getDeclaredTypeOfClassOrInterface:
(symbol) { var links = getSymbolLinks(symbol); if (!links.declaredType) { var kind = symbol.flags & 32 /* Class */ ? 1 /* Class */ : 2 /* Interface */; var type = links.declaredType = createObjectType(kind, symbol); var outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol); var localTypeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); // A class or interface is generic if it has type parameters or a "this" type. We always give classes a "this" type // because it is not feasible to analyze all members to determine if the "this" type escapes the class (in particular, // property types inferred from initializers and method return types inferred from return statements are very hard // to exhaustively analyze). We give interfaces a "this" type if we can't definitely determine that they are free of // "this" references. if (outerTypeParameters || localTypeParameters || kind === 1 /* Class */ || !isIndependentInterface(symbol)) { type.objectFlags |= 4 /* Reference */; type.typeParameters = ts.concatenate(outerTypeParameters, localTypeParameters); type.outerTypeParameters = outerTypeParameters; type.localTypeParameters = localTypeParameters; type.instantiations = ts.createMap(); type.instantiations[getTypeListId(type.typeParameters)] = type; type.target = type; type.typeArguments = type.typeParameters; type.thisType = createType(16384 /* TypeParameter */); type.thisType.isThisType = true; type.thisType.symbol = symbol; type.thisType.constraint = type; } } return links.declaredType; }
(symbol) { var links = getSymbolLinks(symbol); if (!links.declaredType) { var kind = symbol.flags & 32 /* Class */ ? 1 /* Class */ : 2 /* Interface */; var type = links.declaredType = createObjectType(kind, symbol); var outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol); var localTypeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); // A class or interface is generic if it has type parameters or a "this" type. We always give classes a "this" type // because it is not feasible to analyze all members to determine if the "this" type escapes the class (in particular, // property types inferred from initializers and method return types inferred from return statements are very hard // to exhaustively analyze). We give interfaces a "this" type if we can't definitely determine that they are free of // "this" references. if (outerTypeParameters || localTypeParameters || kind === 1 /* Class */ || !isIndependentInterface(symbol)) { type.objectFlags |= 4 /* Reference */; type.typeParameters = ts.concatenate(outerTypeParameters, localTypeParameters); type.outerTypeParameters = outerTypeParameters; type.localTypeParameters = localTypeParameters; type.instantiations = ts.createMap(); type.instantiations[getTypeListId(type.typeParameters)] = type; type.target = type; type.typeArguments = type.typeParameters; type.thisType = createType(16384 /* TypeParameter */); type.thisType.isThisType = true; type.thisType.symbol = symbol; type.thisType.constraint = type; } } return links.declaredType; }
(symbol) { var links = getSymbolLinks(symbol); if (!links.declaredType) { var kind = symbol.flags & 32 /* Class */ ? 1 /* Class */ : 2 /* Interface */; var type = links.declaredType = createObjectType(kind, symbol); var outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol); var localTypeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); // A class or interface is generic if it has type parameters or a "this" type. We always give classes a "this" type // because it is not feasible to analyze all members to determine if the "this" type escapes the class (in particular, // property types inferred from initializers and method return types inferred from return statements are very hard // to exhaustively analyze). We give interfaces a "this" type if we can't definitely determine that they are free of // "this" references. if (outerTypeParameters || localTypeParameters || kind === 1 /* Class */ || !isIndependentInterface(symbol)) { type.objectFlags |= 4 /* Reference */; type.typeParameters = ts.concatenate(outerTypeParameters, localTypeParameters); type.outerTypeParameters = outerTypeParameters; type.localTypeParameters = localTypeParameters; type.instantiations = ts.createMap(); type.instantiations[getTypeListId(type.typeParameters)] = type; type.target = type; type.typeArguments = type.typeParameters; type.thisType = createType(16384 /* TypeParameter */); type.thisType.isThisType = true; type.thisType.symbol = symbol; type.thisType.constraint = type; } } return links.declaredType; }
(symbol) { var links = getSymbolLinks(symbol); if (!links.declaredType) { var kind = symbol.flags & 32 /* Class */ ? 1 /* Class */ : 2 /* Interface */; var type = links.declaredType = createObjectType(kind, symbol); var outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol); var localTypeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); // A class or interface is generic if it has type parameters or a "this" type. We always give classes a "this" type // because it is not feasible to analyze all members to determine if the "this" type escapes the class (in particular, // property types inferred from initializers and method return types inferred from return statements are very hard // to exhaustively analyze). We give interfaces a "this" type if we can't definitely determine that they are free of // "this" references. if (outerTypeParameters || localTypeParameters || kind === 1 /* Class */ || !isIndependentInterface(symbol)) { type.objectFlags |= 4 /* Reference */; type.typeParameters = ts.concatenate(outerTypeParameters, localTypeParameters); type.outerTypeParameters = outerTypeParameters; type.localTypeParameters = localTypeParameters; type.instantiations = ts.createMap(); type.instantiations[getTypeListId(type.typeParameters)] = type; type.target = type; type.typeArguments = type.typeParameters; type.thisType = createType(16384 /* TypeParameter */); type.thisType.isThisType = true; type.thisType.symbol = symbol; type.thisType.constraint = type; } } return links.declaredType; }
getAliasTypeArgumentsForTypeNode:
(node) { var symbol = getAliasSymbolForTypeNode(node); return symbol ? getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol) : undefined; }
(node) { var symbol = getAliasSymbolForTypeNode(node); return symbol ? getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol) : undefined; }
isNumericLiteralName:
(name) { // The intent of numeric names is that // - they are names with text in a numeric form, and that // - setting properties/indexing with them is always equivalent to doing so with the numeric literal 'numLit', // acquired by applying the abstract 'ToNumber' operation on the name's text. // // The subtlety is in the latter portion, as we cannot reliably say that anything that looks like a numeric literal is a numeric name. // In fact, it is the case that the text of the name must be equal to 'ToString(numLit)' for this to hold. // // Consider the property name '"0xF00D"'. When one indexes with '0xF00D', they are actually indexing with the value of 'ToString(0xF00D)' // according to the ECMAScript specification, so it is actually as if the user indexed with the string '"61453"'. // Thus, the text of all numeric literals equivalent to '61543' such as '0xF00D', '0xf00D', '0170015', etc. are not valid numeric names // because their 'ToString' representation is not equal to their original text. // This is motivated by ECMA-262 sections 9.3.1, 9.8.1, 11.1.5, and 11.2.1. // // Here, we test whether 'ToString(ToNumber(name))' is exactly equal to 'name'. // The '+' prefix operator is equivalent here to applying the abstract ToNumber operation. // Applying the 'toString()' method on a number gives us the abstract ToString operation on a number. // // Note that this accepts the values 'Infinity', '-Infinity', and 'NaN', and that this is intentional. // This is desired behavior, because when indexing with them as numeric entities, you are indexing // with the strings '"Infinity"', '"-Infinity"', and '"NaN"' respectively. return (+name).toString() === name; }
hasProperty:
(map, key) { return hasOwnProperty.call(map, key); }
getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode:
(node) { var links = getNodeLinks(node); if (!links.resolvedType) { // Deferred resolution of members is handled by resolveObjectTypeMembers var aliasSymbol = getAliasSymbolForTypeNode(node); if (ts.isEmpty(node.symbol.members) && !aliasSymbol) { links.resolvedType = emptyTypeLiteralType; } else { var type = createObjectType(16 /* Anonymous */, node.symbol); type.aliasSymbol = aliasSymbol; type.aliasTypeArguments = getAliasTypeArgumentsForTypeNode(node); links.resolvedType = type; } } return links.resolvedType; }
(node) { var links = getNodeLinks(node); if (!links.resolvedType) { // Deferred resolution of members is handled by resolveObjectTypeMembers var aliasSymbol = getAliasSymbolForTypeNode(node); if (ts.isEmpty(node.symbol.members) && !aliasSymbol) { links.resolvedType = emptyTypeLiteralType; } else { var type = createObjectType(16 /* Anonymous */, node.symbol); type.aliasSymbol = aliasSymbol; type.aliasTypeArguments = getAliasTypeArgumentsForTypeNode(node); links.resolvedType = type; } } return links.resolvedType; }
(node) { var links = getNodeLinks(node); if (!links.resolvedType) { // Deferred resolution of members is handled by resolveObjectTypeMembers var aliasSymbol = getAliasSymbolForTypeNode(node); if (ts.isEmpty(node.symbol.members) && !aliasSymbol) { links.resolvedType = emptyTypeLiteralType; } else { var type = createObjectType(16 /* Anonymous */, node.symbol); type.aliasSymbol = aliasSymbol; type.aliasTypeArguments = getAliasTypeArgumentsForTypeNode(node); links.resolvedType = type; } } return links.resolvedType; }
(node) { var links = getNodeLinks(node); if (!links.resolvedType) { // Deferred resolution of members is handled by resolveObjectTypeMembers var aliasSymbol = getAliasSymbolForTypeNode(node); if (ts.isEmpty(node.symbol.members) && !aliasSymbol) { links.resolvedType = emptyTypeLiteralType; } else { var type = createObjectType(16 /* Anonymous */, node.symbol); type.aliasSymbol = aliasSymbol; type.aliasTypeArguments = getAliasTypeArgumentsForTypeNode(node); links.resolvedType = type; } } return links.resolvedType; }
instantiateSymbol:
(symbol, mapper) { if (symbol.flags & 16777216 /* Instantiated */) { var links = getSymbolLinks(symbol); // If symbol being instantiated is itself a instantiation, fetch the original target and combine the // type mappers. This ensures that original type identities are properly preserved and that aliases // always reference a non-aliases. symbol = links.target; mapper = combineTypeMappers(links.mapper, mapper); } // Keep the flags from the symbol we're instantiating. Mark that is instantiated, and // also transient so that we can just store data on it directly. var result = createSymbol(16777216 /* Instantiated */ | 67108864 /* Transient */ | symbol.flags, symbol.name); result.declarations = symbol.declarations; result.parent = symbol.parent; result.target = symbol; result.mapper = mapper; if (symbol.valueDeclaration) { result.valueDeclaration = symbol.valueDeclaration; } return result; }
(symbol, mapper) { if (symbol.flags & 16777216 /* Instantiated */) { var links = getSymbolLinks(symbol); // If symbol being instantiated is itself a instantiation, fetch the original target and combine the // type mappers. This ensures that original type identities are properly preserved and that aliases // always reference a non-aliases. symbol = links.target; mapper = combineTypeMappers(links.mapper, mapper); } // Keep the flags from the symbol we're instantiating. Mark that is instantiated, and // also transient so that we can just store data on it directly. var result = createSymbol(16777216 /* Instantiated */ | 67108864 /* Transient */ | symbol.flags, symbol.name); result.declarations = symbol.declarations; result.parent = symbol.parent; result.target = symbol; result.mapper = mapper; if (symbol.valueDeclaration) { result.valueDeclaration = symbol.valueDeclaration; } return result; }
checkGrammarMethod:
(node) { if (checkGrammarDisallowedModifiersOnObjectLiteralExpressionMethod(node) || checkGrammarFunctionLikeDeclaration(node) || checkGrammarForGenerator(node)) { return true; } if (node.parent.kind === 176 /* ObjectLiteralExpression */) { if (checkGrammarForInvalidQuestionMark(node.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional)) { return true; } else if (node.body === undefined) { return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); } } if (ts.isClassLike(node.parent)) { // Technically, computed properties in ambient contexts is disallowed // for property declarations and accessors too, not just methods. // However, property declarations disallow computed names in general, // and accessors are not allowed in ambient contexts in general, // so this error only really matters for methods. if (ts.isInAmbientContext(node)) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_ambient_context_must_directly_refer_to_a_built_in_symbol); } else if (!node.body) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_method_overload_must_directly_refer_to_a_built_in_symbol); } } else if (node.parent.kind === 227 /* InterfaceDeclaration */) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol); } else if (node.parent.kind === 161 /* TypeLiteral */) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol); } }
(node) { if (checkGrammarDisallowedModifiersOnObjectLiteralExpressionMethod(node) || checkGrammarFunctionLikeDeclaration(node) || checkGrammarForGenerator(node)) { return true; } if (node.parent.kind === 176 /* ObjectLiteralExpression */) { if (checkGrammarForInvalidQuestionMark(node.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional)) { return true; } else if (node.body === undefined) { return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); } } if (ts.isClassLike(node.parent)) { // Technically, computed properties in ambient contexts is disallowed // for property declarations and accessors too, not just methods. // However, property declarations disallow computed names in general, // and accessors are not allowed in ambient contexts in general, // so this error only really matters for methods. if (ts.isInAmbientContext(node)) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_ambient_context_must_directly_refer_to_a_built_in_symbol); } else if (!node.body) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_method_overload_must_directly_refer_to_a_built_in_symbol); } } else if (node.parent.kind === 227 /* InterfaceDeclaration */) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol); } else if (node.parent.kind === 161 /* TypeLiteral */) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol); } }
(node) { if (checkGrammarDisallowedModifiersOnObjectLiteralExpressionMethod(node) || checkGrammarFunctionLikeDeclaration(node) || checkGrammarForGenerator(node)) { return true; } if (node.parent.kind === 176 /* ObjectLiteralExpression */) { if (checkGrammarForInvalidQuestionMark(node.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional)) { return true; } else if (node.body === undefined) { return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); } } if (ts.isClassLike(node.parent)) { // Technically, computed properties in ambient contexts is disallowed // for property declarations and accessors too, not just methods. // However, property declarations disallow computed names in general, // and accessors are not allowed in ambient contexts in general, // so this error only really matters for methods. if (ts.isInAmbientContext(node)) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_ambient_context_must_directly_refer_to_a_built_in_symbol); } else if (!node.body) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_method_overload_must_directly_refer_to_a_built_in_symbol); } } else if (node.parent.kind === 227 /* InterfaceDeclaration */) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol); } else if (node.parent.kind === 161 /* TypeLiteral */) { return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol); } }
checkTypeNameIsReserved:
(name, message) { // TS 1.0 spec (April 2014): 3.6.1 // The predefined type keywords are reserved and cannot be used as names of user defined types. switch (name.text) { case "any": case "number": case "boolean": case "string": case "symbol": case "void": error(name, message, name.text); } }
checkSignatureDeclaration:
(node) { // Grammar checking if (node.kind === 155 /* IndexSignature */) { checkGrammarIndexSignature(node); } else if (node.kind === 158 /* FunctionType */ || node.kind === 225 /* FunctionDeclaration */ || node.kind === 159 /* ConstructorType */ || node.kind === 153 /* CallSignature */ || node.kind === 150 /* Constructor */ || node.kind === 154 /* ConstructSignature */) { checkGrammarFunctionLikeDeclaration(node); } if (ts.isAsyncFunctionLike(node) && languageVersion < 4 /* ES2017 */) { checkExternalEmitHelpers(node, 64 /* Awaiter */); if (languageVersion < 2 /* ES2015 */) { checkExternalEmitHelpers(node, 128 /* Generator */); } } checkTypeParameters(node.typeParameters); ts.forEach(node.parameters, checkParameter); if (node.type) { checkSourceElement(node.type); } if (produceDiagnostics) { checkCollisionWithArgumentsInGeneratedCode(node); if (compilerOptions.noImplicitAny && !node.type) { switch (node.kind) { case 154 /* ConstructSignature */: error(node, ts.Diagnostics.Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); break; case 153 /* CallSignature */: error(node, ts.Diagnostics.Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); break; } } if (node.type) { if (languageVersion >= 2 /* ES2015 */ && isSyntacticallyValidGenerator(node)) { var returnType = getTypeFromTypeNode(node.type); if (returnType === voidType) { error(node.type, ts.Diagnostics.A_generator_cannot_have_a_void_type_annotation); } else { var generatorElementType = getElementTypeOfIterableIterator(returnType) || anyType; var iterableIteratorInstantiation = createIterableIteratorType(generatorElementType); // Naively, one could check that IterableIterator<any> is assignable to the return type annotation. // However, that would not catch the error in the following case. // // interface BadGenerator extends Iterable<number>, Iterator<string> { } // function* g(): BadGenerator { } // Iterable and Iterator have different types! // checkTypeAssignableTo(iterableIteratorInstantiation, returnType, node.type); } } else if (ts.isAsyncFunctionLike(node)) { checkAsyncFunctionReturnType(node); } } if (noUnusedIdentifiers && !node.body) { checkUnusedTypeParameters(node); } } }
(node) { // Grammar checking if (node.kind === 155 /* IndexSignature */) { checkGrammarIndexSignature(node); } else if (node.kind === 158 /* FunctionType */ || node.kind === 225 /* FunctionDeclaration */ || node.kind === 159 /* ConstructorType */ || node.kind === 153 /* CallSignature */ || node.kind === 150 /* Constructor */ || node.kind === 154 /* ConstructSignature */) { checkGrammarFunctionLikeDeclaration(node); } if (ts.isAsyncFunctionLike(node) && languageVersion < 4 /* ES2017 */) { checkExternalEmitHelpers(node, 64 /* Awaiter */); if (languageVersion < 2 /* ES2015 */) { checkExternalEmitHelpers(node, 128 /* Generator */); } } checkTypeParameters(node.typeParameters); ts.forEach(node.parameters, checkParameter); if (node.type) { checkSourceElement(node.type); } if (produceDiagnostics) { checkCollisionWithArgumentsInGeneratedCode(node); if (compilerOptions.noImplicitAny && !node.type) { switch (node.kind) { case 154 /* ConstructSignature */: error(node, ts.Diagnostics.Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); break; case 153 /* CallSignature */: error(node, ts.Diagnostics.Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); break; } } if (node.type) { if (languageVersion >= 2 /* ES2015 */ && isSyntacticallyValidGenerator(node)) { var returnType = getTypeFromTypeNode(node.type); if (returnType === voidType) { error(node.type, ts.Diagnostics.A_generator_cannot_have_a_void_type_annotation); } else { var generatorElementType = getElementTypeOfIterableIterator(returnType) || anyType; var iterableIteratorInstantiation = createIterableIteratorType(generatorElementType); // Naively, one could check that IterableIterator<any> is assignable to the return type annotation. // However, that would not catch the error in the following case. // // interface BadGenerator extends Iterable<number>, Iterator<string> { } // function* g(): BadGenerator { } // Iterable and Iterator have different types! // checkTypeAssignableTo(iterableIteratorInstantiation, returnType, node.type); } } else if (ts.isAsyncFunctionLike(node)) { checkAsyncFunctionReturnType(node); } } if (noUnusedIdentifiers && !node.body) { checkUnusedTypeParameters(node); } } }
checkTypeReferenceNode:
(node) { checkGrammarTypeArguments(node, node.typeArguments); var type = getTypeFromTypeReference(node); if (type !== unknownType) { if (node.typeArguments) { // Do type argument local checks only if referenced type is successfully resolved ts.forEach(node.typeArguments, checkSourceElement); if (produceDiagnostics) { var symbol = getNodeLinks(node).resolvedSymbol; var typeParameters = symbol.flags & 524288 /* TypeAlias */ ? getSymbolLinks(symbol).typeParameters : type.target.localTypeParameters; checkTypeArgumentConstraints(typeParameters, node.typeArguments); } } if (type.flags & 16 /* Enum */ && !type.memberTypes && getNodeLinks(node).resolvedSymbol.flags & 8 /* EnumMember */) { error(node, ts.Diagnostics.Enum_type_0_has_members_with_initializers_that_are_not_literals, typeToString(type)); } } }
(node) { checkGrammarTypeArguments(node, node.typeArguments); var type = getTypeFromTypeReference(node); if (type !== unknownType) { if (node.typeArguments) { // Do type argument local checks only if referenced type is successfully resolved ts.forEach(node.typeArguments, checkSourceElement); if (produceDiagnostics) { var symbol = getNodeLinks(node).resolvedSymbol; var typeParameters = symbol.flags & 524288 /* TypeAlias */ ? getSymbolLinks(symbol).typeParameters : type.target.localTypeParameters; checkTypeArgumentConstraints(typeParameters, node.typeArguments); } } if (type.flags & 16 /* Enum */ && !type.memberTypes && getNodeLinks(node).resolvedSymbol.flags & 8 /* EnumMember */) { error(node, ts.Diagnostics.Enum_type_0_has_members_with_initializers_that_are_not_literals, typeToString(type)); } } }
getIndexTypeOfType:
(type, kind) { return getIndexTypeOfStructuredType(getApparentType(type), kind); }
getTypeFromClassOrInterfaceReference:
(node, symbol) { var type = getDeclaredTypeOfSymbol(getMergedSymbol(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; }
(node, symbol) { var type = getDeclaredTypeOfSymbol(getMergedSymbol(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; }
isInAmbientContext:
(node) { while (node) { if (hasModifier(node, 2 /* Ambient */) || (node.kind === 261 /* SourceFile */ && node.isDeclarationFile)) { return true; } node = node.parent; } return false; }
(node) { while (node) { if (hasModifier(node, 2 /* Ambient */) || (node.kind === 261 /* SourceFile */ && node.isDeclarationFile)) { return true; } node = node.parent; } return false; }
(node) { while (node) { if (hasModifier(node, 2 /* Ambient */) || (node.kind === 261 /* SourceFile */ && node.isDeclarationFile)) { return true; } node = node.parent; } return false; }
getTypeWithThisArgument:
(type, thisArgument) { if (getObjectFlags(type) & 4 /* Reference */) { return createTypeReference(type.target, ts.concatenate(type.typeArguments, [thisArgument || type.target.thisType])); } return type; }
(type, thisArgument) { if (getObjectFlags(type) & 4 /* Reference */) { return createTypeReference(type.target, ts.concatenate(type.typeArguments, [thisArgument || type.target.thisType])); } return type; }
getSignaturesOfType:
(type, kind) { return getSignaturesOfStructuredType(getApparentType(type), kind); }
(type, kind) { return getSignaturesOfStructuredType(getApparentType(type), kind); }
resolveStructuredTypeMembers:
(type) { if (!type.members) { if (type.flags & 32768 /* Object */) { if (type.objectFlags & 4 /* Reference */) { resolveTypeReferenceMembers(type); } else if (type.objectFlags & 3 /* ClassOrInterface */) { resolveClassOrInterfaceMembers(type); } else if (type.objectFlags & 16 /* Anonymous */) { resolveAnonymousTypeMembers(type); } else if (type.objectFlags & 32 /* Mapped */) { resolveMappedTypeMembers(type); } } else if (type.flags & 65536 /* Union */) { resolveUnionTypeMembers(type); } else if (type.flags & 131072 /* Intersection */) { resolveIntersectionTypeMembers(type); } } return type; }
(type) { if (!type.members) { if (type.flags & 32768 /* Object */) { if (type.objectFlags & 4 /* Reference */) { resolveTypeReferenceMembers(type); } else if (type.objectFlags & 3 /* ClassOrInterface */) { resolveClassOrInterfaceMembers(type); } else if (type.objectFlags & 16 /* Anonymous */) { resolveAnonymousTypeMembers(type); } else if (type.objectFlags & 32 /* Mapped */) { resolveMappedTypeMembers(type); } } else if (type.flags & 65536 /* Union */) { resolveUnionTypeMembers(type); } else if (type.flags & 131072 /* Intersection */) { resolveIntersectionTypeMembers(type); } } return type; }
(type) { if (!type.members) { if (type.flags & 32768 /* Object */) { if (type.objectFlags & 4 /* Reference */) { resolveTypeReferenceMembers(type); } else if (type.objectFlags & 3 /* ClassOrInterface */) { resolveClassOrInterfaceMembers(type); } else if (type.objectFlags & 16 /* Anonymous */) { resolveAnonymousTypeMembers(type); } else if (type.objectFlags & 32 /* Mapped */) { resolveMappedTypeMembers(type); } } else if (type.flags & 65536 /* Union */) { resolveUnionTypeMembers(type); } else if (type.flags & 131072 /* Intersection */) { resolveIntersectionTypeMembers(type); } } return type; }
(type) { if (!type.members) { if (type.flags & 32768 /* Object */) { if (type.objectFlags & 4 /* Reference */) { resolveTypeReferenceMembers(type); } else if (type.objectFlags & 3 /* ClassOrInterface */) { resolveClassOrInterfaceMembers(type); } else if (type.objectFlags & 16 /* Anonymous */) { resolveAnonymousTypeMembers(type); } else if (type.objectFlags & 32 /* Mapped */) { resolveMappedTypeMembers(type); } } else if (type.flags & 65536 /* Union */) { resolveUnionTypeMembers(type); } else if (type.flags & 131072 /* Intersection */) { resolveIntersectionTypeMembers(type); } } return type; }
(type) { if (!type.members) { if (type.flags & 32768 /* Object */) { if (type.objectFlags & 4 /* Reference */) { resolveTypeReferenceMembers(type); } else if (type.objectFlags & 3 /* ClassOrInterface */) { resolveClassOrInterfaceMembers(type); } else if (type.objectFlags & 16 /* Anonymous */) { resolveAnonymousTypeMembers(type); } else if (type.objectFlags & 32 /* Mapped */) { resolveMappedTypeMembers(type); } } else if (type.flags & 65536 /* Union */) { resolveUnionTypeMembers(type); } else if (type.flags & 131072 /* Intersection */) { resolveIntersectionTypeMembers(type); } } return type; }
(type) { if (!type.members) { if (type.flags & 32768 /* Object */) { if (type.objectFlags & 4 /* Reference */) { resolveTypeReferenceMembers(type); } else if (type.objectFlags & 3 /* ClassOrInterface */) { resolveClassOrInterfaceMembers(type); } else if (type.objectFlags & 16 /* Anonymous */) { resolveAnonymousTypeMembers(type); } else if (type.objectFlags & 32 /* Mapped */) { resolveMappedTypeMembers(type); } } else if (type.flags & 65536 /* Union */) { resolveUnionTypeMembers(type); } else if (type.flags & 131072 /* Intersection */) { resolveIntersectionTypeMembers(type); } } return type; }
(type) { if (!type.members) { if (type.flags & 32768 /* Object */) { if (type.objectFlags & 4 /* Reference */) { resolveTypeReferenceMembers(type); } else if (type.objectFlags & 3 /* ClassOrInterface */) { resolveClassOrInterfaceMembers(type); } else if (type.objectFlags & 16 /* Anonymous */) { resolveAnonymousTypeMembers(type); } else if (type.objectFlags & 32 /* Mapped */) { resolveMappedTypeMembers(type); } } else if (type.flags & 65536 /* Union */) { resolveUnionTypeMembers(type); } else if (type.flags & 131072 /* Intersection */) { resolveIntersectionTypeMembers(type); } } return type; }
(type) { if (!type.members) { if (type.flags & 32768 /* Object */) { if (type.objectFlags & 4 /* Reference */) { resolveTypeReferenceMembers(type); } else if (type.objectFlags & 3 /* ClassOrInterface */) { resolveClassOrInterfaceMembers(type); } else if (type.objectFlags & 16 /* Anonymous */) { resolveAnonymousTypeMembers(type); } else if (type.objectFlags & 32 /* Mapped */) { resolveMappedTypeMembers(type); } } else if (type.flags & 65536 /* Union */) { resolveUnionTypeMembers(type); } else if (type.flags & 131072 /* Intersection */) { resolveIntersectionTypeMembers(type); } } return type; }
checkPropertyDeclaration:
(node) { // Grammar checking checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarProperty(node) || checkGrammarComputedPropertyName(node.name); checkVariableLikeDeclaration(node); }
(node) { // Grammar checking checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarProperty(node) || checkGrammarComputedPropertyName(node.name); checkVariableLikeDeclaration(node); }
getBaseTypes:
(type) { if (!type.resolvedBaseTypes) { if (type.objectFlags & 8 /* Tuple */) { type.resolvedBaseTypes = [createArrayType(getUnionType(type.typeParameters))]; } else if (type.symbol.flags & (32 /* Class */ | 64 /* Interface */)) { if (type.symbol.flags & 32 /* Class */) { resolveBaseTypesOfClass(type); } if (type.symbol.flags & 64 /* Interface */) { resolveBaseTypesOfInterface(type); } } else { ts.Debug.fail("type must be class or interface"); } } return type.resolvedBaseTypes; }
(type) { if (!type.resolvedBaseTypes) { if (type.objectFlags & 8 /* Tuple */) { type.resolvedBaseTypes = [createArrayType(getUnionType(type.typeParameters))]; } else if (type.symbol.flags & (32 /* Class */ | 64 /* Interface */)) { if (type.symbol.flags & 32 /* Class */) { resolveBaseTypesOfClass(type); } if (type.symbol.flags & 64 /* Interface */) { resolveBaseTypesOfInterface(type); } } else { ts.Debug.fail("type must be class or interface"); } } return type.resolvedBaseTypes; }
(type) { if (!type.resolvedBaseTypes) { if (type.objectFlags & 8 /* Tuple */) { type.resolvedBaseTypes = [createArrayType(getUnionType(type.typeParameters))]; } else if (type.symbol.flags & (32 /* Class */ | 64 /* Interface */)) { if (type.symbol.flags & 32 /* Class */) { resolveBaseTypesOfClass(type); } if (type.symbol.flags & 64 /* Interface */) { resolveBaseTypesOfInterface(type); } } else { ts.Debug.fail("type must be class or interface"); } } return type.resolvedBaseTypes; }
getIndexInfoOfType:
(type, kind) { return getIndexInfoOfStructuredType(getApparentType(type), kind); }
getIndexInfoOfSymbol:
(symbol, kind) { var declaration = getIndexDeclarationOfSymbol(symbol, kind); if (declaration) { return createIndexInfo(declaration.type ? getTypeFromTypeNode(declaration.type) : anyType, (ts.getModifierFlags(declaration) & 64 /* Readonly */) !== 0, declaration); } return undefined; }
getOuterTypeParametersOfClassOrInterface:
(symbol) { var declaration = symbol.flags & 32 /* Class */ ? symbol.valueDeclaration : ts.getDeclarationOfKind(symbol, 227 /* InterfaceDeclaration */); return appendOuterTypeParameters(undefined, declaration); }
checkGrammarProperty:
(node) { if (ts.isClassLike(node.parent)) { if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol)) { return true; } } else if (node.parent.kind === 227 /* InterfaceDeclaration */) { if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol)) { return true; } if (node.initializer) { return grammarErrorOnNode(node.initializer, ts.Diagnostics.An_interface_property_cannot_have_an_initializer); } } else if (node.parent.kind === 161 /* TypeLiteral */) { if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol)) { return true; } if (node.initializer) { return grammarErrorOnNode(node.initializer, ts.Diagnostics.A_type_literal_property_cannot_have_an_initializer); } } if (ts.isInAmbientContext(node) && node.initializer) { return grammarErrorOnFirstToken(node.initializer, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); } }
(node) { if (ts.isClassLike(node.parent)) { if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol)) { return true; } } else if (node.parent.kind === 227 /* InterfaceDeclaration */) { if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol)) { return true; } if (node.initializer) { return grammarErrorOnNode(node.initializer, ts.Diagnostics.An_interface_property_cannot_have_an_initializer); } } else if (node.parent.kind === 161 /* TypeLiteral */) { if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol)) { return true; } if (node.initializer) { return grammarErrorOnNode(node.initializer, ts.Diagnostics.A_type_literal_property_cannot_have_an_initializer); } } if (ts.isInAmbientContext(node) && node.initializer) { return grammarErrorOnFirstToken(node.initializer, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); } }
(node) { if (ts.isClassLike(node.parent)) { if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol)) { return true; } } else if (node.parent.kind === 227 /* InterfaceDeclaration */) { if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol)) { return true; } if (node.initializer) { return grammarErrorOnNode(node.initializer, ts.Diagnostics.An_interface_property_cannot_have_an_initializer); } } else if (node.parent.kind === 161 /* TypeLiteral */) { if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol)) { return true; } if (node.initializer) { return grammarErrorOnNode(node.initializer, ts.Diagnostics.A_type_literal_property_cannot_have_an_initializer); } } if (ts.isInAmbientContext(node) && node.initializer) { return grammarErrorOnFirstToken(node.initializer, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); } }
isEntityNameExpression:
(node) { return node.kind === 70 /* Identifier */ || node.kind === 177 /* PropertyAccessExpression */ && isEntityNameExpression(node.expression); }
(node) { return node.kind === 70 /* Identifier */ || node.kind === 177 /* PropertyAccessExpression */ && isEntityNameExpression(node.expression); }
getTargetType:
(type) { return getObjectFlags(type) & 4 /* Reference */ ? type.target : type; }
(type) { return getObjectFlags(type) & 4 /* Reference */ ? type.target : type; }
getPropertyOfType:
(type, name) { type = getApparentType(type); if (type.flags & 32768 /* Object */) { var resolved = resolveStructuredTypeMembers(type); var symbol = resolved.members[name]; if (symbol && symbolIsValue(symbol)) { return symbol; } if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { var symbol_1 = getPropertyOfObjectType(globalFunctionType, name); if (symbol_1) { return symbol_1; } } return getPropertyOfObjectType(globalObjectType, name); } if (type.flags & 196608 /* UnionOrIntersection */) { return getPropertyOfUnionOrIntersectionType(type, name); } return undefined; }
(type, name) { type = getApparentType(type); if (type.flags & 32768 /* Object */) { var resolved = resolveStructuredTypeMembers(type); var symbol = resolved.members[name]; if (symbol && symbolIsValue(symbol)) { return symbol; } if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { var symbol_1 = getPropertyOfObjectType(globalFunctionType, name); if (symbol_1) { return symbol_1; } } return getPropertyOfObjectType(globalObjectType, name); } if (type.flags & 196608 /* UnionOrIntersection */) { return getPropertyOfUnionOrIntersectionType(type, name); } return undefined; }
(type, name) { type = getApparentType(type); if (type.flags & 32768 /* Object */) { var resolved = resolveStructuredTypeMembers(type); var symbol = resolved.members[name]; if (symbol && symbolIsValue(symbol)) { return symbol; } if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { var symbol_1 = getPropertyOfObjectType(globalFunctionType, name); if (symbol_1) { return symbol_1; } } return getPropertyOfObjectType(globalObjectType, name); } if (type.flags & 196608 /* UnionOrIntersection */) { return getPropertyOfUnionOrIntersectionType(type, name); } return undefined; }
(type, name) { type = getApparentType(type); if (type.flags & 32768 /* Object */) { var resolved = resolveStructuredTypeMembers(type); var symbol = resolved.members[name]; if (symbol && symbolIsValue(symbol)) { return symbol; } if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { var symbol_1 = getPropertyOfObjectType(globalFunctionType, name); if (symbol_1) { return symbol_1; } } return getPropertyOfObjectType(globalObjectType, name); } if (type.flags & 196608 /* UnionOrIntersection */) { return getPropertyOfUnionOrIntersectionType(type, name); } return undefined; }
(type, name) { type = getApparentType(type); if (type.flags & 32768 /* Object */) { var resolved = resolveStructuredTypeMembers(type); var symbol = resolved.members[name]; if (symbol && symbolIsValue(symbol)) { return symbol; } if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { var symbol_1 = getPropertyOfObjectType(globalFunctionType, name); if (symbol_1) { return symbol_1; } } return getPropertyOfObjectType(globalObjectType, name); } if (type.flags & 196608 /* UnionOrIntersection */) { return getPropertyOfUnionOrIntersectionType(type, name); } return undefined; }
(type, name) { type = getApparentType(type); if (type.flags & 32768 /* Object */) { var resolved = resolveStructuredTypeMembers(type); var symbol = resolved.members[name]; if (symbol && symbolIsValue(symbol)) { return symbol; } if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { var symbol_1 = getPropertyOfObjectType(globalFunctionType, name); if (symbol_1) { return symbol_1; } } return getPropertyOfObjectType(globalObjectType, name); } if (type.flags & 196608 /* UnionOrIntersection */) { return getPropertyOfUnionOrIntersectionType(type, name); } return undefined; }
(type, name) { type = getApparentType(type); if (type.flags & 32768 /* Object */) { var resolved = resolveStructuredTypeMembers(type); var symbol = resolved.members[name]; if (symbol && symbolIsValue(symbol)) { return symbol; } if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { var symbol_1 = getPropertyOfObjectType(globalFunctionType, name); if (symbol_1) { return symbol_1; } } return getPropertyOfObjectType(globalObjectType, name); } if (type.flags & 196608 /* UnionOrIntersection */) { return getPropertyOfUnionOrIntersectionType(type, name); } return undefined; }
(type, name) { type = getApparentType(type); if (type.flags & 32768 /* Object */) { var resolved = resolveStructuredTypeMembers(type); var symbol = resolved.members[name]; if (symbol && symbolIsValue(symbol)) { return symbol; } if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { var symbol_1 = getPropertyOfObjectType(globalFunctionType, name); if (symbol_1) { return symbol_1; } } return getPropertyOfObjectType(globalObjectType, name); } if (type.flags & 196608 /* UnionOrIntersection */) { return getPropertyOfUnionOrIntersectionType(type, name); } return undefined; }
getSignaturesOfStructuredType:
(type, kind) { if (type.flags & 229376 /* StructuredType */) { var resolved = resolveStructuredTypeMembers(type); return kind === 0 /* Call */ ? resolved.callSignatures : resolved.constructSignatures; } return emptyArray; }
Deopt: <JS Function getSignaturesOfStructuredType (SharedFunctionInfo 0x3fa1587f5dc1)> (opt #393) @2, FP to SP delta: 24, caller sp: 0x7fff5fbfdad0
Deopt: <JS Function resolveName (SharedFunctionInfo 0x3fa1587ed479)> (opt #377) @19, FP to SP delta: 320, caller sp: 0x7fff5fbfd510
Deopt: <JS Function instantiateCached (SharedFunctionInfo 0x3fa1587faf81)> (opt #353) @6, FP to SP delta: 40, caller sp: 0x7fff5fbfd8b0
Deopt: <JS Function instantiateAnonymousType (SharedFunctionInfo 0x3fa1587fb941)> (opt #354) @2, FP to SP delta: 48, caller sp: 0x7fff5fbfd850
Deopt: <JS Function checkParameter (SharedFunctionInfo 0x3fca5860f901)> (opt #338) @28, FP to SP delta: 112, caller sp: 0x7fff5fbfdd40
Deopt: <JS Function checkMethodDeclaration (SharedFunctionInfo 0x3fca58610141)> (opt #352) @5, FP to SP delta: 32, caller sp: 0x7fff5fbfdf20
checkFunctionOrMethodDeclaration:
(node) { checkDecorators(node); checkSignatureDeclaration(node); var isAsync = ts.isAsyncFunctionLike(node); // Do not use hasDynamicName here, because that returns false for well known symbols. // We want to perform checkComputedPropertyName for all computed properties, including // well known symbols. if (node.name && node.name.kind === 142 /* ComputedPropertyName */) { // This check will account for methods in class/interface declarations, // as well as accessors in classes/object literals checkComputedPropertyName(node.name); } if (!ts.hasDynamicName(node)) { // first we want to check the local symbol that contain this declaration // - if node.localSymbol !== undefined - this is current declaration is exported and localSymbol points to the local symbol // - if node.localSymbol === undefined - this node is non-exported so we can just pick the result of getSymbolOfNode var symbol = getSymbolOfNode(node); var localSymbol = node.localSymbol || symbol; // Since the javascript won't do semantic analysis like typescript, // if the javascript file comes before the typescript file and both contain same name functions, // checkFunctionOrConstructorSymbol wouldn't be called if we didnt ignore javascript function. var firstDeclaration = ts.forEach(localSymbol.declarations, // Get first non javascript function declaration function (declaration) { return declaration.kind === node.kind && !ts.isSourceFileJavaScript(ts.getSourceFileOfNode(declaration)) ? declaration : undefined; }); // Only type check the symbol once if (node === firstDeclaration) { checkFunctionOrConstructorSymbol(localSymbol); } if (symbol.parent) { // run check once for the first declaration if (ts.getDeclarationOfKind(symbol, node.kind) === node) { // run check on export symbol to check that modifiers agree across all exported declarations checkFunctionOrConstructorSymbol(symbol); } } } checkSourceElement(node.body); if (!node.asteriskToken) { var returnOrPromisedType = node.type && (isAsync ? checkAsyncFunctionReturnType(node) : getTypeFromTypeNode(node.type)); checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, returnOrPromisedType); } if (produceDiagnostics && !node.type) { // Report an implicit any error if there is no body, no explicit return type, and node is not a private method // in an ambient context if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !isPrivateWithinAmbient(node)) { reportImplicitAnyError(node, anyType); } if (node.asteriskToken && ts.nodeIsPresent(node.body)) { // A generator with a body and no type annotation can still cause errors. It can error if the // yielded values have no common supertype, or it can give an implicit any error if it has no // yielded values. The only way to trigger these errors is to try checking its return type. getReturnTypeOfSignature(getSignatureFromDeclaration(node)); } } registerForUnusedIdentifiersCheck(node); }
(node) { checkDecorators(node); checkSignatureDeclaration(node); var isAsync = ts.isAsyncFunctionLike(node); // Do not use hasDynamicName here, because that returns false for well known symbols. // We want to perform checkComputedPropertyName for all computed properties, including // well known symbols. if (node.name && node.name.kind === 142 /* ComputedPropertyName */) { // This check will account for methods in class/interface declarations, // as well as accessors in classes/object literals checkComputedPropertyName(node.name); } if (!ts.hasDynamicName(node)) { // first we want to check the local symbol that contain this declaration // - if node.localSymbol !== undefined - this is current declaration is exported and localSymbol points to the local symbol // - if node.localSymbol === undefined - this node is non-exported so we can just pick the result of getSymbolOfNode var symbol = getSymbolOfNode(node); var localSymbol = node.localSymbol || symbol; // Since the javascript won't do semantic analysis like typescript, // if the javascript file comes before the typescript file and both contain same name functions, // checkFunctionOrConstructorSymbol wouldn't be called if we didnt ignore javascript function. var firstDeclaration = ts.forEach(localSymbol.declarations, // Get first non javascript function declaration function (declaration) { return declaration.kind === node.kind && !ts.isSourceFileJavaScript(ts.getSourceFileOfNode(declaration)) ? declaration : undefined; }); // Only type check the symbol once if (node === firstDeclaration) { checkFunctionOrConstructorSymbol(localSymbol); } if (symbol.parent) { // run check once for the first declaration if (ts.getDeclarationOfKind(symbol, node.kind) === node) { // run check on export symbol to check that modifiers agree across all exported declarations checkFunctionOrConstructorSymbol(symbol); } } } checkSourceElement(node.body); if (!node.asteriskToken) { var returnOrPromisedType = node.type && (isAsync ? checkAsyncFunctionReturnType(node) : getTypeFromTypeNode(node.type)); checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, returnOrPromisedType); } if (produceDiagnostics && !node.type) { // Report an implicit any error if there is no body, no explicit return type, and node is not a private method // in an ambient context if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !isPrivateWithinAmbient(node)) { reportImplicitAnyError(node, anyType); } if (node.asteriskToken && ts.nodeIsPresent(node.body)) { // A generator with a body and no type annotation can still cause errors. It can error if the // yielded values have no common supertype, or it can give an implicit any error if it has no // yielded values. The only way to trigger these errors is to try checking its return type. getReturnTypeOfSignature(getSignatureFromDeclaration(node)); } } registerForUnusedIdentifiersCheck(node); }
(node) { checkDecorators(node); checkSignatureDeclaration(node); var isAsync = ts.isAsyncFunctionLike(node); // Do not use hasDynamicName here, because that returns false for well known symbols. // We want to perform checkComputedPropertyName for all computed properties, including // well known symbols. if (node.name && node.name.kind === 142 /* ComputedPropertyName */) { // This check will account for methods in class/interface declarations, // as well as accessors in classes/object literals checkComputedPropertyName(node.name); } if (!ts.hasDynamicName(node)) { // first we want to check the local symbol that contain this declaration // - if node.localSymbol !== undefined - this is current declaration is exported and localSymbol points to the local symbol // - if node.localSymbol === undefined - this node is non-exported so we can just pick the result of getSymbolOfNode var symbol = getSymbolOfNode(node); var localSymbol = node.localSymbol || symbol; // Since the javascript won't do semantic analysis like typescript, // if the javascript file comes before the typescript file and both contain same name functions, // checkFunctionOrConstructorSymbol wouldn't be called if we didnt ignore javascript function. var firstDeclaration = ts.forEach(localSymbol.declarations, // Get first non javascript function declaration function (declaration) { return declaration.kind === node.kind && !ts.isSourceFileJavaScript(ts.getSourceFileOfNode(declaration)) ? declaration : undefined; }); // Only type check the symbol once if (node === firstDeclaration) { checkFunctionOrConstructorSymbol(localSymbol); } if (symbol.parent) { // run check once for the first declaration if (ts.getDeclarationOfKind(symbol, node.kind) === node) { // run check on export symbol to check that modifiers agree across all exported declarations checkFunctionOrConstructorSymbol(symbol); } } } checkSourceElement(node.body); if (!node.asteriskToken) { var returnOrPromisedType = node.type && (isAsync ? checkAsyncFunctionReturnType(node) : getTypeFromTypeNode(node.type)); checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, returnOrPromisedType); } if (produceDiagnostics && !node.type) { // Report an implicit any error if there is no body, no explicit return type, and node is not a private method // in an ambient context if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !isPrivateWithinAmbient(node)) { reportImplicitAnyError(node, anyType); } if (node.asteriskToken && ts.nodeIsPresent(node.body)) { // A generator with a body and no type annotation can still cause errors. It can error if the // yielded values have no common supertype, or it can give an implicit any error if it has no // yielded values. The only way to trigger these errors is to try checking its return type. getReturnTypeOfSignature(getSignatureFromDeclaration(node)); } } registerForUnusedIdentifiersCheck(node); }
createSignature:
(declaration, typeParameters, thisParameter, parameters, resolvedReturnType, typePredicate, minArgumentCount, hasRestParameter, hasLiteralTypes) { var sig = new Signature(checker); sig.declaration = declaration; sig.typeParameters = typeParameters; sig.parameters = parameters; sig.thisParameter = thisParameter; sig.resolvedReturnType = resolvedReturnType; sig.typePredicate = typePredicate; sig.minArgumentCount = minArgumentCount; sig.hasRestParameter = hasRestParameter; sig.hasLiteralTypes = hasLiteralTypes; return sig; }
getTypeFromUnionTypeNode:
(node) { var links = getNodeLinks(node); if (!links.resolvedType) { links.resolvedType = getUnionType(ts.map(node.types, getTypeFromTypeNode), /*subtypeReduction*/ false, getAliasSymbolForTypeNode(node), getAliasTypeArgumentsForTypeNode(node)); } return links.resolvedType; }
(node) { var links = getNodeLinks(node); if (!links.resolvedType) { links.resolvedType = getUnionType(ts.map(node.types, getTypeFromTypeNode), /*subtypeReduction*/ false, getAliasSymbolForTypeNode(node), getAliasTypeArgumentsForTypeNode(node)); } return links.resolvedType; }
(node) { var links = getNodeLinks(node); if (!links.resolvedType) { links.resolvedType = getUnionType(ts.map(node.types, getTypeFromTypeNode), /*subtypeReduction*/ false, getAliasSymbolForTypeNode(node), getAliasTypeArgumentsForTypeNode(node)); } return links.resolvedType; }
addTypeToUnion:
(typeSet, type) { var flags = type.flags; if (flags & 65536 /* Union */) { addTypesToUnion(typeSet, type.types); } else if (flags & 1 /* Any */) { typeSet.containsAny = true; } else if (!strictNullChecks && flags & 6144 /* Nullable */) { if (flags & 2048 /* Undefined */) typeSet.containsUndefined = true; if (flags & 4096 /* Null */) typeSet.containsNull = true; if (!(flags & 2097152 /* ContainsWideningType */)) typeSet.containsNonWideningType = true; } else if (!(flags & 8192 /* Never */)) { if (flags & 2 /* String */) typeSet.containsString = true; if (flags & 4 /* Number */) typeSet.containsNumber = true; if (flags & 96 /* StringOrNumberLiteral */) typeSet.containsStringOrNumberLiteral = true; var len = typeSet.length; var index = len && type.id > typeSet[len - 1].id ? ~len : binarySearchTypes(typeSet, type); if (index < 0) { if (!(flags & 32768 /* Object */ && type.objectFlags & 16 /* Anonymous */ && type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */) && containsIdenticalType(typeSet, type))) { typeSet.splice(~index, 0, type); } } } }
(typeSet, type) { var flags = type.flags; if (flags & 65536 /* Union */) { addTypesToUnion(typeSet, type.types); } else if (flags & 1 /* Any */) { typeSet.containsAny = true; } else if (!strictNullChecks && flags & 6144 /* Nullable */) { if (flags & 2048 /* Undefined */) typeSet.containsUndefined = true; if (flags & 4096 /* Null */) typeSet.containsNull = true; if (!(flags & 2097152 /* ContainsWideningType */)) typeSet.containsNonWideningType = true; } else if (!(flags & 8192 /* Never */)) { if (flags & 2 /* String */) typeSet.containsString = true; if (flags & 4 /* Number */) typeSet.containsNumber = true; if (flags & 96 /* StringOrNumberLiteral */) typeSet.containsStringOrNumberLiteral = true; var len = typeSet.length; var index = len && type.id > typeSet[len - 1].id ? ~len : binarySearchTypes(typeSet, type); if (index < 0) { if (!(flags & 32768 /* Object */ && type.objectFlags & 16 /* Anonymous */ && type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */) && containsIdenticalType(typeSet, type))) { typeSet.splice(~index, 0, type); } } } }
(typeSet, type) { var flags = type.flags; if (flags & 65536 /* Union */) { addTypesToUnion(typeSet, type.types); } else if (flags & 1 /* Any */) { typeSet.containsAny = true; } else if (!strictNullChecks && flags & 6144 /* Nullable */) { if (flags & 2048 /* Undefined */) typeSet.containsUndefined = true; if (flags & 4096 /* Null */) typeSet.containsNull = true; if (!(flags & 2097152 /* ContainsWideningType */)) typeSet.containsNonWideningType = true; } else if (!(flags & 8192 /* Never */)) { if (flags & 2 /* String */) typeSet.containsString = true; if (flags & 4 /* Number */) typeSet.containsNumber = true; if (flags & 96 /* StringOrNumberLiteral */) typeSet.containsStringOrNumberLiteral = true; var len = typeSet.length; var index = len && type.id > typeSet[len - 1].id ? ~len : binarySearchTypes(typeSet, type); if (index < 0) { if (!(flags & 32768 /* Object */ && type.objectFlags & 16 /* Anonymous */ && type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */) && containsIdenticalType(typeSet, type))) { typeSet.splice(~index, 0, type); } } } }
(typeSet, type) { var flags = type.flags; if (flags & 65536 /* Union */) { addTypesToUnion(typeSet, type.types); } else if (flags & 1 /* Any */) { typeSet.containsAny = true; } else if (!strictNullChecks && flags & 6144 /* Nullable */) { if (flags & 2048 /* Undefined */) typeSet.containsUndefined = true; if (flags & 4096 /* Null */) typeSet.containsNull = true; if (!(flags & 2097152 /* ContainsWideningType */)) typeSet.containsNonWideningType = true; } else if (!(flags & 8192 /* Never */)) { if (flags & 2 /* String */) typeSet.containsString = true; if (flags & 4 /* Number */) typeSet.containsNumber = true; if (flags & 96 /* StringOrNumberLiteral */) typeSet.containsStringOrNumberLiteral = true; var len = typeSet.length; var index = len && type.id > typeSet[len - 1].id ? ~len : binarySearchTypes(typeSet, type); if (index < 0) { if (!(flags & 32768 /* Object */ && type.objectFlags & 16 /* Anonymous */ && type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */) && containsIdenticalType(typeSet, type))) { typeSet.splice(~index, 0, type); } } } }
(typeSet, type) { var flags = type.flags; if (flags & 65536 /* Union */) { addTypesToUnion(typeSet, type.types); } else if (flags & 1 /* Any */) { typeSet.containsAny = true; } else if (!strictNullChecks && flags & 6144 /* Nullable */) { if (flags & 2048 /* Undefined */) typeSet.containsUndefined = true; if (flags & 4096 /* Null */) typeSet.containsNull = true; if (!(flags & 2097152 /* ContainsWideningType */)) typeSet.containsNonWideningType = true; } else if (!(flags & 8192 /* Never */)) { if (flags & 2 /* String */) typeSet.containsString = true; if (flags & 4 /* Number */) typeSet.containsNumber = true; if (flags & 96 /* StringOrNumberLiteral */) typeSet.containsStringOrNumberLiteral = true; var len = typeSet.length; var index = len && type.id > typeSet[len - 1].id ? ~len : binarySearchTypes(typeSet, type); if (index < 0) { if (!(flags & 32768 /* Object */ && type.objectFlags & 16 /* Anonymous */ && type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */) && containsIdenticalType(typeSet, type))) { typeSet.splice(~index, 0, type); } } } }
(typeSet, type) { var flags = type.flags; if (flags & 65536 /* Union */) { addTypesToUnion(typeSet, type.types); } else if (flags & 1 /* Any */) { typeSet.containsAny = true; } else if (!strictNullChecks && flags & 6144 /* Nullable */) { if (flags & 2048 /* Undefined */) typeSet.containsUndefined = true; if (flags & 4096 /* Null */) typeSet.containsNull = true; if (!(flags & 2097152 /* ContainsWideningType */)) typeSet.containsNonWideningType = true; } else if (!(flags & 8192 /* Never */)) { if (flags & 2 /* String */) typeSet.containsString = true; if (flags & 4 /* Number */) typeSet.containsNumber = true; if (flags & 96 /* StringOrNumberLiteral */) typeSet.containsStringOrNumberLiteral = true; var len = typeSet.length; var index = len && type.id > typeSet[len - 1].id ? ~len : binarySearchTypes(typeSet, type); if (index < 0) { if (!(flags & 32768 /* Object */ && type.objectFlags & 16 /* Anonymous */ && type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */) && containsIdenticalType(typeSet, type))) { typeSet.splice(~index, 0, type); } } } }
(typeSet, type) { var flags = type.flags; if (flags & 65536 /* Union */) { addTypesToUnion(typeSet, type.types); } else if (flags & 1 /* Any */) { typeSet.containsAny = true; } else if (!strictNullChecks && flags & 6144 /* Nullable */) { if (flags & 2048 /* Undefined */) typeSet.containsUndefined = true; if (flags & 4096 /* Null */) typeSet.containsNull = true; if (!(flags & 2097152 /* ContainsWideningType */)) typeSet.containsNonWideningType = true; } else if (!(flags & 8192 /* Never */)) { if (flags & 2 /* String */) typeSet.containsString = true; if (flags & 4 /* Number */) typeSet.containsNumber = true; if (flags & 96 /* StringOrNumberLiteral */) typeSet.containsStringOrNumberLiteral = true; var len = typeSet.length; var index = len && type.id > typeSet[len - 1].id ? ~len : binarySearchTypes(typeSet, type); if (index < 0) { if (!(flags & 32768 /* Object */ && type.objectFlags & 16 /* Anonymous */ && type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */) && containsIdenticalType(typeSet, type))) { typeSet.splice(~index, 0, type); } } } }
checkUnionOrIntersectionType:
(node) { ts.forEach(node.types, checkSourceElement); }
pushTypeResolution:
(target, propertyName) { var resolutionCycleStartIndex = findResolutionCycleStartIndex(target, propertyName); if (resolutionCycleStartIndex >= 0) { // A cycle was found var length_2 = resolutionTargets.length; for (var i = resolutionCycleStartIndex; i < length_2; i++) { resolutionResults[i] = false; } return false; } resolutionTargets.push(target); resolutionResults.push(/*items*/ true); resolutionPropertyNames.push(propertyName); return true; }
isJSDocConstructSignature:
(node) { return node.kind === 274 /* JSDocFunctionType */ && node.parameters.length > 0 && node.parameters[0].type.kind === 276 /* JSDocConstructorType */; }
hasRestParameter:
(s) { return isRestParameter(ts.lastOrUndefined(s.parameters)); }
getTypeParametersFromJSDocTemplate:
(declaration) { if (declaration.flags & 65536 /* JavaScriptFile */) { var templateTag = ts.getJSDocTemplateTag(declaration); if (templateTag) { return getTypeParametersFromDeclaration(templateTag.typeParameters); } } return undefined; }
Deopt: <JS Function checkFunctionOrMethodDeclaration (SharedFunctionInfo 0x3fca586117c1)> (opt #405) @32, FP to SP delta: 152, caller sp: 0x7fff5fbfddc8
Deopt: <JS Function isInAmbientContext (SharedFunctionInfo 0x2c75c4ad1c41)> (opt #370) @7, FP to SP delta: 40, caller sp: 0x7fff5fbfdc58
Deopt: <JS Function resolveName (SharedFunctionInfo 0x3fa1587ed479)> (opt #394) @87, FP to SP delta: 320, caller sp: 0x7fff5fbfd8d0
getUnionType:
(types, subtypeReduction, aliasSymbol, aliasTypeArguments) { if (types.length === 0) { return neverType; } if (types.length === 1) { return types[0]; } var typeSet = []; addTypesToUnion(typeSet, types); if (typeSet.containsAny) { return anyType; } if (subtypeReduction) { removeSubtypes(typeSet); } else if (typeSet.containsStringOrNumberLiteral) { removeRedundantLiteralTypes(typeSet); } if (typeSet.length === 0) { return typeSet.containsNull ? typeSet.containsNonWideningType ? nullType : nullWideningType : typeSet.containsUndefined ? typeSet.containsNonWideningType ? undefinedType : undefinedWideningType : neverType; } return getUnionTypeFromSortedList(typeSet, aliasSymbol, aliasTypeArguments); }
(types, subtypeReduction, aliasSymbol, aliasTypeArguments) { if (types.length === 0) { return neverType; } if (types.length === 1) { return types[0]; } var typeSet = []; addTypesToUnion(typeSet, types); if (typeSet.containsAny) { return anyType; } if (subtypeReduction) { removeSubtypes(typeSet); } else if (typeSet.containsStringOrNumberLiteral) { removeRedundantLiteralTypes(typeSet); } if (typeSet.length === 0) { return typeSet.containsNull ? typeSet.containsNonWideningType ? nullType : nullWideningType : typeSet.containsUndefined ? typeSet.containsNonWideningType ? undefinedType : undefinedWideningType : neverType; } return getUnionTypeFromSortedList(typeSet, aliasSymbol, aliasTypeArguments); }
shouldReportBadModifier:
(node) { switch (node.kind) { case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 150 /* Constructor */: case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 155 /* IndexSignature */: case 230 /* ModuleDeclaration */: case 235 /* ImportDeclaration */: case 234 /* ImportEqualsDeclaration */: case 241 /* ExportDeclaration */: case 240 /* ExportAssignment */: case 184 /* FunctionExpression */: case 185 /* ArrowFunction */: case 144 /* Parameter */: return false; default: if (node.parent.kind === 231 /* ModuleBlock */ || node.parent.kind === 261 /* SourceFile */) { return false; } switch (node.kind) { case 225 /* FunctionDeclaration */: return nodeHasAnyModifiersExcept(node, 119 /* AsyncKeyword */); case 226 /* ClassDeclaration */: return nodeHasAnyModifiersExcept(node, 116 /* AbstractKeyword */); case 227 /* InterfaceDeclaration */: case 205 /* VariableStatement */: case 228 /* TypeAliasDeclaration */: return true; case 229 /* EnumDeclaration */: return nodeHasAnyModifiersExcept(node, 75 /* ConstKeyword */); default: ts.Debug.fail(); return false; } } }
(node) { switch (node.kind) { case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 150 /* Constructor */: case 147 /* PropertyDeclaration */: case 146 /* PropertySignature */: case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 155 /* IndexSignature */: case 230 /* ModuleDeclaration */: case 235 /* ImportDeclaration */: case 234 /* ImportEqualsDeclaration */: case 241 /* ExportDeclaration */: case 240 /* ExportAssignment */: case 184 /* FunctionExpression */: case 185 /* ArrowFunction */: case 144 /* Parameter */: return false; default: if (node.parent.kind === 231 /* ModuleBlock */ || node.parent.kind === 261 /* SourceFile */) { return false; } switch (node.kind) { case 225 /* FunctionDeclaration */: return nodeHasAnyModifiersExcept(node, 119 /* AsyncKeyword */); case 226 /* ClassDeclaration */: return nodeHasAnyModifiersExcept(node, 116 /* AbstractKeyword */); case 227 /* InterfaceDeclaration */: case 205 /* VariableStatement */: case 228 /* TypeAliasDeclaration */: return true; case 229 /* EnumDeclaration */: return nodeHasAnyModifiersExcept(node, 75 /* ConstKeyword */); default: ts.Debug.fail(); return false; } } }
checkGrammarParameterList:
(parameters) { var seenOptionalParameter = false; var parameterCount = parameters.length; for (var i = 0; i < parameterCount; i++) { var parameter = parameters[i]; if (parameter.dotDotDotToken) { if (i !== (parameterCount - 1)) { return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list); } if (ts.isBindingPattern(parameter.name)) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_element_cannot_contain_a_binding_pattern); } if (parameter.questionToken) { return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.A_rest_parameter_cannot_be_optional); } if (parameter.initializer) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_cannot_have_an_initializer); } } else if (parameter.questionToken) { seenOptionalParameter = true; if (parameter.initializer) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.Parameter_cannot_have_question_mark_and_initializer); } } else if (seenOptionalParameter && !parameter.initializer) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter); } } }
resolveClassOrInterfaceMembers:
(type) { resolveObjectTypeMembers(type, resolveDeclaredMembers(type), emptyArray, emptyArray); }
getLiteralTypeFromPropertyName:
(prop) { return getDeclarationModifierFlagsFromSymbol(prop) & 24 /* NonPublicAccessibilityModifier */ || ts.startsWith(prop.name, "__@") ? neverType : getLiteralTypeForText(32 /* StringLiteral */, ts.unescapeIdentifier(prop.name)); }
startsWith:
(str, prefix) { return str.lastIndexOf(prefix, 0) === 0; }
unescapeIdentifier:
(identifier) { return identifier.length >= 3 && identifier.charCodeAt(0) === 95 /* _ */ && identifier.charCodeAt(1) === 95 /* _ */ && identifier.charCodeAt(2) === 95 /* _ */ ? identifier.substr(1) : identifier; }
isSimpleTypeRelatedTo:
(source, target, relation, errorReporter) { if (target.flags & 8192 /* Never */) return false; if (target.flags & 1 /* Any */ || source.flags & 8192 /* Never */) return true; if (source.flags & 262178 /* StringLike */ && target.flags & 2 /* String */) return true; if (source.flags & 340 /* NumberLike */ && target.flags & 4 /* Number */) return true; if (source.flags & 136 /* BooleanLike */ && target.flags & 8 /* Boolean */) return true; if (source.flags & 256 /* EnumLiteral */ && target.flags & 16 /* Enum */ && source.baseType === target) return true; if (source.flags & 16 /* Enum */ && target.flags & 16 /* Enum */ && isEnumTypeRelatedTo(source, target, errorReporter)) return true; if (source.flags & 2048 /* Undefined */ && (!strictNullChecks || target.flags & (2048 /* Undefined */ | 1024 /* Void */))) return true; if (source.flags & 4096 /* Null */ && (!strictNullChecks || target.flags & 4096 /* Null */)) return true; if (relation === assignableRelation || relation === comparableRelation) { if (source.flags & 1 /* Any */) return true; if ((source.flags & 4 /* Number */ | source.flags & 64 /* NumberLiteral */) && target.flags & 272 /* EnumLike */) return true; if (source.flags & 256 /* EnumLiteral */ && target.flags & 256 /* EnumLiteral */ && source.text === target.text && isEnumTypeRelatedTo(source.baseType, target.baseType, errorReporter)) { return true; } if (source.flags & 256 /* EnumLiteral */ && target.flags & 16 /* Enum */ && isEnumTypeRelatedTo(target, source.baseType, errorReporter)) { return true; } } return false; }
(source, target, relation, errorReporter) { if (target.flags & 8192 /* Never */) return false; if (target.flags & 1 /* Any */ || source.flags & 8192 /* Never */) return true; if (source.flags & 262178 /* StringLike */ && target.flags & 2 /* String */) return true; if (source.flags & 340 /* NumberLike */ && target.flags & 4 /* Number */) return true; if (source.flags & 136 /* BooleanLike */ && target.flags & 8 /* Boolean */) return true; if (source.flags & 256 /* EnumLiteral */ && target.flags & 16 /* Enum */ && source.baseType === target) return true; if (source.flags & 16 /* Enum */ && target.flags & 16 /* Enum */ && isEnumTypeRelatedTo(source, target, errorReporter)) return true; if (source.flags & 2048 /* Undefined */ && (!strictNullChecks || target.flags & (2048 /* Undefined */ | 1024 /* Void */))) return true; if (source.flags & 4096 /* Null */ && (!strictNullChecks || target.flags & 4096 /* Null */)) return true; if (relation === assignableRelation || relation === comparableRelation) { if (source.flags & 1 /* Any */) return true; if ((source.flags & 4 /* Number */ | source.flags & 64 /* NumberLiteral */) && target.flags & 272 /* EnumLike */) return true; if (source.flags & 256 /* EnumLiteral */ && target.flags & 256 /* EnumLiteral */ && source.text === target.text && isEnumTypeRelatedTo(source.baseType, target.baseType, errorReporter)) { return true; } if (source.flags & 256 /* EnumLiteral */ && target.flags & 16 /* Enum */ && isEnumTypeRelatedTo(target, source.baseType, errorReporter)) { return true; } } return false; }
Deopt: <JS Function isRelatedTo (SharedFunctionInfo 0x298f55ec1c31)> (opt #443) @57, FP to SP delta: 304, caller sp: 0x7fff5fbfd9f0
(source, target, relation, errorReporter) { if (target.flags & 8192 /* Never */) return false; if (target.flags & 1 /* Any */ || source.flags & 8192 /* Never */) return true; if (source.flags & 262178 /* StringLike */ && target.flags & 2 /* String */) return true; if (source.flags & 340 /* NumberLike */ && target.flags & 4 /* Number */) return true; if (source.flags & 136 /* BooleanLike */ && target.flags & 8 /* Boolean */) return true; if (source.flags & 256 /* EnumLiteral */ && target.flags & 16 /* Enum */ && source.baseType === target) return true; if (source.flags & 16 /* Enum */ && target.flags & 16 /* Enum */ && isEnumTypeRelatedTo(source, target, errorReporter)) return true; if (source.flags & 2048 /* Undefined */ && (!strictNullChecks || target.flags & (2048 /* Undefined */ | 1024 /* Void */))) return true; if (source.flags & 4096 /* Null */ && (!strictNullChecks || target.flags & 4096 /* Null */)) return true; if (relation === assignableRelation || relation === comparableRelation) { if (source.flags & 1 /* Any */) return true; if ((source.flags & 4 /* Number */ | source.flags & 64 /* NumberLiteral */) && target.flags & 272 /* EnumLike */) return true; if (source.flags & 256 /* EnumLiteral */ && target.flags & 256 /* EnumLiteral */ && source.text === target.text && isEnumTypeRelatedTo(source.baseType, target.baseType, errorReporter)) { return true; } if (source.flags & 256 /* EnumLiteral */ && target.flags & 16 /* Enum */ && isEnumTypeRelatedTo(target, source.baseType, errorReporter)) { return true; } } return false; }
(source, target, relation, errorReporter) { if (target.flags & 8192 /* Never */) return false; if (target.flags & 1 /* Any */ || source.flags & 8192 /* Never */) return true; if (source.flags & 262178 /* StringLike */ && target.flags & 2 /* String */) return true; if (source.flags & 340 /* NumberLike */ && target.flags & 4 /* Number */) return true; if (source.flags & 136 /* BooleanLike */ && target.flags & 8 /* Boolean */) return true; if (source.flags & 256 /* EnumLiteral */ && target.flags & 16 /* Enum */ && source.baseType === target) return true; if (source.flags & 16 /* Enum */ && target.flags & 16 /* Enum */ && isEnumTypeRelatedTo(source, target, errorReporter)) return true; if (source.flags & 2048 /* Undefined */ && (!strictNullChecks || target.flags & (2048 /* Undefined */ | 1024 /* Void */))) return true; if (source.flags & 4096 /* Null */ && (!strictNullChecks || target.flags & 4096 /* Null */)) return true; if (relation === assignableRelation || relation === comparableRelation) { if (source.flags & 1 /* Any */) return true; if ((source.flags & 4 /* Number */ | source.flags & 64 /* NumberLiteral */) && target.flags & 272 /* EnumLike */) return true; if (source.flags & 256 /* EnumLiteral */ && target.flags & 256 /* EnumLiteral */ && source.text === target.text && isEnumTypeRelatedTo(source.baseType, target.baseType, errorReporter)) { return true; } if (source.flags & 256 /* EnumLiteral */ && target.flags & 16 /* Enum */ && isEnumTypeRelatedTo(target, source.baseType, errorReporter)) { return true; } } return false; }
Deopt: <JS Function isRelatedTo (SharedFunctionInfo 0x298f55ec1c31)> (opt #601) @79, FP to SP delta: 312, caller sp: 0x7fff5fbfd3f0
(source, target, relation, errorReporter) { if (target.flags & 8192 /* Never */) return false; if (target.flags & 1 /* Any */ || source.flags & 8192 /* Never */) return true; if (source.flags & 262178 /* StringLike */ && target.flags & 2 /* String */) return true; if (source.flags & 340 /* NumberLike */ && target.flags & 4 /* Number */) return true; if (source.flags & 136 /* BooleanLike */ && target.flags & 8 /* Boolean */) return true; if (source.flags & 256 /* EnumLiteral */ && target.flags & 16 /* Enum */ && source.baseType === target) return true; if (source.flags & 16 /* Enum */ && target.flags & 16 /* Enum */ && isEnumTypeRelatedTo(source, target, errorReporter)) return true; if (source.flags & 2048 /* Undefined */ && (!strictNullChecks || target.flags & (2048 /* Undefined */ | 1024 /* Void */))) return true; if (source.flags & 4096 /* Null */ && (!strictNullChecks || target.flags & 4096 /* Null */)) return true; if (relation === assignableRelation || relation === comparableRelation) { if (source.flags & 1 /* Any */) return true; if ((source.flags & 4 /* Number */ | source.flags & 64 /* NumberLiteral */) && target.flags & 272 /* EnumLike */) return true; if (source.flags & 256 /* EnumLiteral */ && target.flags & 256 /* EnumLiteral */ && source.text === target.text && isEnumTypeRelatedTo(source.baseType, target.baseType, errorReporter)) { return true; } if (source.flags & 256 /* EnumLiteral */ && target.flags & 16 /* Enum */ && isEnumTypeRelatedTo(target, source.baseType, errorReporter)) { return true; } } return false; }
Deopt: <JS Function getTypeFromTypeNode (SharedFunctionInfo 0x3fa1587fac81)> (opt #568) @39, FP to SP delta: 264, caller sp: 0x7fff5fbfd280
isRelatedTo:
(source, target, reportErrors, headMessage) { var result; if (source.flags & 96 /* StringOrNumberLiteral */ && source.flags & 1048576 /* FreshLiteral */) { source = source.regularType; } if (target.flags & 96 /* StringOrNumberLiteral */ && target.flags & 1048576 /* FreshLiteral */) { target = target.regularType; } // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases if (source === target) return -1 /* True */; if (relation === identityRelation) { return isIdenticalTo(source, target); } if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return -1 /* True */; if (getObjectFlags(source) & 128 /* ObjectLiteral */ && source.flags & 1048576 /* FreshLiteral */) { if (hasExcessProperties(source, target, reportErrors)) { if (reportErrors) { reportRelationError(headMessage, source, target); } return 0 /* False */; } // Above we check for excess properties with respect to the entire target type. When union // and intersection types are further deconstructed on the target side, we don't want to // make the check again (as it might fail for a partial target type). Therefore we obtain // the regular source type and proceed with that. if (isUnionOrIntersectionTypeWithoutNullableConstituents(target)) { source = getRegularTypeOfObjectLiteral(source); } } var saveErrorInfo = errorInfo; // Note that these checks are specifically ordered to produce correct results. In particular, // we need to deconstruct unions before intersections (because unions are always at the top), // and we need to handle "each" relations before "some" relations for the same kind of type. if (source.flags & 65536 /* Union */) { if (relation === comparableRelation) { result = someTypeRelatedToType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */)); } else { result = eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */)); } if (result) { return result; } } else if (target.flags & 65536 /* Union */) { if (result = typeRelatedToSomeType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */) && !(target.flags & 8190 /* Primitive */))) { return result; } } else if (target.flags & 131072 /* Intersection */) { if (result = typeRelatedToEachType(source, target, reportErrors)) { return result; } } else if (source.flags & 131072 /* Intersection */) { // Check to see if any constituents of the intersection are immediately related to the target. // // Don't report errors though. Checking whether a constituent is related to the source is not actually // useful and leads to some confusing error messages. Instead it is better to let the below checks // take care of this, or to not elaborate at all. For instance, // // - For an object type (such as 'C = A & B'), users are usually more interested in structural errors. // // - For a union type (such as '(A | B) = (C & D)'), it's better to hold onto the whole intersection // than to report that 'D' is not assignable to 'A' or 'B'. // // - For a primitive type or type parameter (such as 'number = A & B') there is no point in // breaking the intersection apart. if (result = someTypeRelatedToType(source, target, /*reportErrors*/ false)) { return result; } } else if (target.flags & 16384 /* TypeParameter */) { // A source type { [P in keyof T]: X } is related to a target type T if X is related to T[P]. if (getObjectFlags(source) & 32 /* Mapped */ && getConstraintTypeFromMappedType(source) === getIndexType(target)) { if (!source.declaration.questionToken) { var templateType = getTemplateTypeFromMappedType(source); var indexedAccessType = getIndexedAccessType(target, getTypeParameterFromMappedType(source)); if (result = isRelatedTo(templateType, indexedAccessType, reportErrors)) { return result; } } } else { // Given a type parameter K with a constraint keyof T, a type S is // assignable to K if S is assignable to keyof T. var constraint = getConstraintOfTypeParameter(target); if (constraint && constraint.flags & 262144 /* Index */) { if (result = isRelatedTo(source, constraint, reportErrors)) { return result; } } } } else if (target.flags & 262144 /* Index */) { // A keyof S is related to a keyof T if T is related to S. if (source.flags & 262144 /* Index */) { if (result = isRelatedTo(target.type, source.type, /*reportErrors*/ false)) { return result; } } // Given a type variable T with a constraint C, a type S is assignable to // keyof T if S is assignable to keyof C. if (target.type.flags & 540672 /* TypeVariable */) { var constraint = getConstraintOfTypeVariable(target.type); if (constraint) { if (result = isRelatedTo(source, getIndexType(constraint), reportErrors)) { return result; } } } } else if (target.flags & 524288 /* IndexedAccess */) { // if we have indexed access types with identical index types, see if relationship holds for // the two object types. if (source.flags & 524288 /* IndexedAccess */ && source.indexType === target.indexType) { if (result = isRelatedTo(source.objectType, target.objectType, reportErrors)) { return result; } } // A type S is related to a type T[K] if S is related to A[K], where K is string-like and // A is the apparent type of S. if (target.constraint) { if (result = isRelatedTo(source, target.constraint, reportErrors)) { errorInfo = saveErrorInfo; return result; } } } if (source.flags & 16384 /* TypeParameter */) { // A source type T is related to a target type { [P in keyof T]: X } if T[P] is related to X. if (getObjectFlags(target) & 32 /* Mapped */ && getConstraintTypeFromMappedType(target) === getIndexType(source)) { var indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(target)); var templateType = getTemplateTypeFromMappedType(target); if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) { errorInfo = saveErrorInfo; return result; } } else { var constraint = getConstraintOfTypeParameter(source); if (!constraint || constraint.flags & 1 /* Any */) { constraint = emptyObjectType; } // The constraint may need to be further instantiated with its 'this' type. constraint = getTypeWithThisArgument(constraint, source); // Report constraint errors only if the constraint is not the empty object type var reportConstraintErrors = reportErrors && constraint !== emptyObjectType; if (result = isRelatedTo(constraint, target, reportConstraintErrors)) { errorInfo = saveErrorInfo; return result; } } } else if (source.flags & 524288 /* IndexedAccess */) { // A type S[K] is related to a type T if A[K] is related to T, where K is string-like and // A is the apparent type of S. if (source.constraint) { if (result = isRelatedTo(source.constraint, target, reportErrors)) { errorInfo = saveErrorInfo; return result; } } } else { if (getObjectFlags(source) & 4 /* Reference */ && getObjectFlags(target) & 4 /* Reference */ && source.target === target.target) { // We have type references to same target type, see if relationship holds for all type arguments if (result = typeArgumentsRelatedTo(source, target, reportErrors)) { return result; } } // Even if relationship doesn't hold for unions, intersections, or generic type references, // it may hold in a structural comparison. var apparentSource = getApparentType(source); // In a check of the form X = A & B, we will have previously checked if A relates to X or B relates // to X. Failing both of those we want to check if the aggregation of A and B's members structurally // relates to X. Thus, we include intersection types on the source side here. if (apparentSource.flags & (32768 /* Object */ | 131072 /* Intersection */) && target.flags & 32768 /* Object */) { // Report structural errors only if we haven't reported any errors yet var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo && !(source.flags & 8190 /* Primitive */); if (result = objectTypeRelatedTo(apparentSource, source, target, reportStructuralErrors)) { errorInfo = saveErrorInfo; return result; } } } if (reportErrors) { if (source.flags & 32768 /* Object */ && target.flags & 8190 /* Primitive */) { tryElaborateErrorsForPrimitivesAndObjects(source, target); } else if (source.symbol && source.flags & 32768 /* Object */ && globalObjectType === source) { reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead); } reportRelationError(headMessage, source, target); } return 0 /* False */; }
(source, target, reportErrors, headMessage) { var result; if (source.flags & 96 /* StringOrNumberLiteral */ && source.flags & 1048576 /* FreshLiteral */) { source = source.regularType; } if (target.flags & 96 /* StringOrNumberLiteral */ && target.flags & 1048576 /* FreshLiteral */) { target = target.regularType; } // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases if (source === target) return -1 /* True */; if (relation === identityRelation) { return isIdenticalTo(source, target); } if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return -1 /* True */; if (getObjectFlags(source) & 128 /* ObjectLiteral */ && source.flags & 1048576 /* FreshLiteral */) { if (hasExcessProperties(source, target, reportErrors)) { if (reportErrors) { reportRelationError(headMessage, source, target); } return 0 /* False */; } // Above we check for excess properties with respect to the entire target type. When union // and intersection types are further deconstructed on the target side, we don't want to // make the check again (as it might fail for a partial target type). Therefore we obtain // the regular source type and proceed with that. if (isUnionOrIntersectionTypeWithoutNullableConstituents(target)) { source = getRegularTypeOfObjectLiteral(source); } } var saveErrorInfo = errorInfo; // Note that these checks are specifically ordered to produce correct results. In particular, // we need to deconstruct unions before intersections (because unions are always at the top), // and we need to handle "each" relations before "some" relations for the same kind of type. if (source.flags & 65536 /* Union */) { if (relation === comparableRelation) { result = someTypeRelatedToType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */)); } else { result = eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */)); } if (result) { return result; } } else if (target.flags & 65536 /* Union */) { if (result = typeRelatedToSomeType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */) && !(target.flags & 8190 /* Primitive */))) { return result; } } else if (target.flags & 131072 /* Intersection */) { if (result = typeRelatedToEachType(source, target, reportErrors)) { return result; } } else if (source.flags & 131072 /* Intersection */) { // Check to see if any constituents of the intersection are immediately related to the target. // // Don't report errors though. Checking whether a constituent is related to the source is not actually // useful and leads to some confusing error messages. Instead it is better to let the below checks // take care of this, or to not elaborate at all. For instance, // // - For an object type (such as 'C = A & B'), users are usually more interested in structural errors. // // - For a union type (such as '(A | B) = (C & D)'), it's better to hold onto the whole intersection // than to report that 'D' is not assignable to 'A' or 'B'. // // - For a primitive type or type parameter (such as 'number = A & B') there is no point in // breaking the intersection apart. if (result = someTypeRelatedToType(source, target, /*reportErrors*/ false)) { return result; } } else if (target.flags & 16384 /* TypeParameter */) { // A source type { [P in keyof T]: X } is related to a target type T if X is related to T[P]. if (getObjectFlags(source) & 32 /* Mapped */ && getConstraintTypeFromMappedType(source) === getIndexType(target)) { if (!source.declaration.questionToken) { var templateType = getTemplateTypeFromMappedType(source); var indexedAccessType = getIndexedAccessType(target, getTypeParameterFromMappedType(source)); if (result = isRelatedTo(templateType, indexedAccessType, reportErrors)) { return result; } } } else { // Given a type parameter K with a constraint keyof T, a type S is // assignable to K if S is assignable to keyof T. var constraint = getConstraintOfTypeParameter(target); if (constraint && constraint.flags & 262144 /* Index */) { if (result = isRelatedTo(source, constraint, reportErrors)) { return result; } } } } else if (target.flags & 262144 /* Index */) { // A keyof S is related to a keyof T if T is related to S. if (source.flags & 262144 /* Index */) { if (result = isRelatedTo(target.type, source.type, /*reportErrors*/ false)) { return result; } } // Given a type variable T with a constraint C, a type S is assignable to // keyof T if S is assignable to keyof C. if (target.type.flags & 540672 /* TypeVariable */) { var constraint = getConstraintOfTypeVariable(target.type); if (constraint) { if (result = isRelatedTo(source, getIndexType(constraint), reportErrors)) { return result; } } } } else if (target.flags & 524288 /* IndexedAccess */) { // if we have indexed access types with identical index types, see if relationship holds for // the two object types. if (source.flags & 524288 /* IndexedAccess */ && source.indexType === target.indexType) { if (result = isRelatedTo(source.objectType, target.objectType, reportErrors)) { return result; } } // A type S is related to a type T[K] if S is related to A[K], where K is string-like and // A is the apparent type of S. if (target.constraint) { if (result = isRelatedTo(source, target.constraint, reportErrors)) { errorInfo = saveErrorInfo; return result; } } } if (source.flags & 16384 /* TypeParameter */) { // A source type T is related to a target type { [P in keyof T]: X } if T[P] is related to X. if (getObjectFlags(target) & 32 /* Mapped */ && getConstraintTypeFromMappedType(target) === getIndexType(source)) { var indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(target)); var templateType = getTemplateTypeFromMappedType(target); if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) { errorInfo = saveErrorInfo; return result; } } else { var constraint = getConstraintOfTypeParameter(source); if (!constraint || constraint.flags & 1 /* Any */) { constraint = emptyObjectType; } // The constraint may need to be further instantiated with its 'this' type. constraint = getTypeWithThisArgument(constraint, source); // Report constraint errors only if the constraint is not the empty object type var reportConstraintErrors = reportErrors && constraint !== emptyObjectType; if (result = isRelatedTo(constraint, target, reportConstraintErrors)) { errorInfo = saveErrorInfo; return result; } } } else if (source.flags & 524288 /* IndexedAccess */) { // A type S[K] is related to a type T if A[K] is related to T, where K is string-like and // A is the apparent type of S. if (source.constraint) { if (result = isRelatedTo(source.constraint, target, reportErrors)) { errorInfo = saveErrorInfo; return result; } } } else { if (getObjectFlags(source) & 4 /* Reference */ && getObjectFlags(target) & 4 /* Reference */ && source.target === target.target) { // We have type references to same target type, see if relationship holds for all type arguments if (result = typeArgumentsRelatedTo(source, target, reportErrors)) { return result; } } // Even if relationship doesn't hold for unions, intersections, or generic type references, // it may hold in a structural comparison. var apparentSource = getApparentType(source); // In a check of the form X = A & B, we will have previously checked if A relates to X or B relates // to X. Failing both of those we want to check if the aggregation of A and B's members structurally // relates to X. Thus, we include intersection types on the source side here. if (apparentSource.flags & (32768 /* Object */ | 131072 /* Intersection */) && target.flags & 32768 /* Object */) { // Report structural errors only if we haven't reported any errors yet var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo && !(source.flags & 8190 /* Primitive */); if (result = objectTypeRelatedTo(apparentSource, source, target, reportStructuralErrors)) { errorInfo = saveErrorInfo; return result; } } } if (reportErrors) { if (source.flags & 32768 /* Object */ && target.flags & 8190 /* Primitive */) { tryElaborateErrorsForPrimitivesAndObjects(source, target); } else if (source.symbol && source.flags & 32768 /* Object */ && globalObjectType === source) { reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead); } reportRelationError(headMessage, source, target); } return 0 /* False */; }
(source, target, reportErrors, headMessage) { var result; if (source.flags & 96 /* StringOrNumberLiteral */ && source.flags & 1048576 /* FreshLiteral */) { source = source.regularType; } if (target.flags & 96 /* StringOrNumberLiteral */ && target.flags & 1048576 /* FreshLiteral */) { target = target.regularType; } // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases if (source === target) return -1 /* True */; if (relation === identityRelation) { return isIdenticalTo(source, target); } if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return -1 /* True */; if (getObjectFlags(source) & 128 /* ObjectLiteral */ && source.flags & 1048576 /* FreshLiteral */) { if (hasExcessProperties(source, target, reportErrors)) { if (reportErrors) { reportRelationError(headMessage, source, target); } return 0 /* False */; } // Above we check for excess properties with respect to the entire target type. When union // and intersection types are further deconstructed on the target side, we don't want to // make the check again (as it might fail for a partial target type). Therefore we obtain // the regular source type and proceed with that. if (isUnionOrIntersectionTypeWithoutNullableConstituents(target)) { source = getRegularTypeOfObjectLiteral(source); } } var saveErrorInfo = errorInfo; // Note that these checks are specifically ordered to produce correct results. In particular, // we need to deconstruct unions before intersections (because unions are always at the top), // and we need to handle "each" relations before "some" relations for the same kind of type. if (source.flags & 65536 /* Union */) { if (relation === comparableRelation) { result = someTypeRelatedToType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */)); } else { result = eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */)); } if (result) { return result; } } else if (target.flags & 65536 /* Union */) { if (result = typeRelatedToSomeType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */) && !(target.flags & 8190 /* Primitive */))) { return result; } } else if (target.flags & 131072 /* Intersection */) { if (result = typeRelatedToEachType(source, target, reportErrors)) { return result; } } else if (source.flags & 131072 /* Intersection */) { // Check to see if any constituents of the intersection are immediately related to the target. // // Don't report errors though. Checking whether a constituent is related to the source is not actually // useful and leads to some confusing error messages. Instead it is better to let the below checks // take care of this, or to not elaborate at all. For instance, // // - For an object type (such as 'C = A & B'), users are usually more interested in structural errors. // // - For a union type (such as '(A | B) = (C & D)'), it's better to hold onto the whole intersection // than to report that 'D' is not assignable to 'A' or 'B'. // // - For a primitive type or type parameter (such as 'number = A & B') there is no point in // breaking the intersection apart. if (result = someTypeRelatedToType(source, target, /*reportErrors*/ false)) { return result; } } else if (target.flags & 16384 /* TypeParameter */) { // A source type { [P in keyof T]: X } is related to a target type T if X is related to T[P]. if (getObjectFlags(source) & 32 /* Mapped */ && getConstraintTypeFromMappedType(source) === getIndexType(target)) { if (!source.declaration.questionToken) { var templateType = getTemplateTypeFromMappedType(source); var indexedAccessType = getIndexedAccessType(target, getTypeParameterFromMappedType(source)); if (result = isRelatedTo(templateType, indexedAccessType, reportErrors)) { return result; } } } else { // Given a type parameter K with a constraint keyof T, a type S is // assignable to K if S is assignable to keyof T. var constraint = getConstraintOfTypeParameter(target); if (constraint && constraint.flags & 262144 /* Index */) { if (result = isRelatedTo(source, constraint, reportErrors)) { return result; } } } } else if (target.flags & 262144 /* Index */) { // A keyof S is related to a keyof T if T is related to S. if (source.flags & 262144 /* Index */) { if (result = isRelatedTo(target.type, source.type, /*reportErrors*/ false)) { return result; } } // Given a type variable T with a constraint C, a type S is assignable to // keyof T if S is assignable to keyof C. if (target.type.flags & 540672 /* TypeVariable */) { var constraint = getConstraintOfTypeVariable(target.type); if (constraint) { if (result = isRelatedTo(source, getIndexType(constraint), reportErrors)) { return result; } } } } else if (target.flags & 524288 /* IndexedAccess */) { // if we have indexed access types with identical index types, see if relationship holds for // the two object types. if (source.flags & 524288 /* IndexedAccess */ && source.indexType === target.indexType) { if (result = isRelatedTo(source.objectType, target.objectType, reportErrors)) { return result; } } // A type S is related to a type T[K] if S is related to A[K], where K is string-like and // A is the apparent type of S. if (target.constraint) { if (result = isRelatedTo(source, target.constraint, reportErrors)) { errorInfo = saveErrorInfo; return result; } } } if (source.flags & 16384 /* TypeParameter */) { // A source type T is related to a target type { [P in keyof T]: X } if T[P] is related to X. if (getObjectFlags(target) & 32 /* Mapped */ && getConstraintTypeFromMappedType(target) === getIndexType(source)) { var indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(target)); var templateType = getTemplateTypeFromMappedType(target); if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) { errorInfo = saveErrorInfo; return result; } } else { var constraint = getConstraintOfTypeParameter(source); if (!constraint || constraint.flags & 1 /* Any */) { constraint = emptyObjectType; } // The constraint may need to be further instantiated with its 'this' type. constraint = getTypeWithThisArgument(constraint, source); // Report constraint errors only if the constraint is not the empty object type var reportConstraintErrors = reportErrors && constraint !== emptyObjectType; if (result = isRelatedTo(constraint, target, reportConstraintErrors)) { errorInfo = saveErrorInfo; return result; } } } else if (source.flags & 524288 /* IndexedAccess */) { // A type S[K] is related to a type T if A[K] is related to T, where K is string-like and // A is the apparent type of S. if (source.constraint) { if (result = isRelatedTo(source.constraint, target, reportErrors)) { errorInfo = saveErrorInfo; return result; } } } else { if (getObjectFlags(source) & 4 /* Reference */ && getObjectFlags(target) & 4 /* Reference */ && source.target === target.target) { // We have type references to same target type, see if relationship holds for all type arguments if (result = typeArgumentsRelatedTo(source, target, reportErrors)) { return result; } } // Even if relationship doesn't hold for unions, intersections, or generic type references, // it may hold in a structural comparison. var apparentSource = getApparentType(source); // In a check of the form X = A & B, we will have previously checked if A relates to X or B relates // to X. Failing both of those we want to check if the aggregation of A and B's members structurally // relates to X. Thus, we include intersection types on the source side here. if (apparentSource.flags & (32768 /* Object */ | 131072 /* Intersection */) && target.flags & 32768 /* Object */) { // Report structural errors only if we haven't reported any errors yet var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo && !(source.flags & 8190 /* Primitive */); if (result = objectTypeRelatedTo(apparentSource, source, target, reportStructuralErrors)) { errorInfo = saveErrorInfo; return result; } } } if (reportErrors) { if (source.flags & 32768 /* Object */ && target.flags & 8190 /* Primitive */) { tryElaborateErrorsForPrimitivesAndObjects(source, target); } else if (source.symbol && source.flags & 32768 /* Object */ && globalObjectType === source) { reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead); } reportRelationError(headMessage, source, target); } return 0 /* False */; }
(source, target, reportErrors, headMessage) { var result; if (source.flags & 96 /* StringOrNumberLiteral */ && source.flags & 1048576 /* FreshLiteral */) { source = source.regularType; } if (target.flags & 96 /* StringOrNumberLiteral */ && target.flags & 1048576 /* FreshLiteral */) { target = target.regularType; } // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases if (source === target) return -1 /* True */; if (relation === identityRelation) { return isIdenticalTo(source, target); } if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return -1 /* True */; if (getObjectFlags(source) & 128 /* ObjectLiteral */ && source.flags & 1048576 /* FreshLiteral */) { if (hasExcessProperties(source, target, reportErrors)) { if (reportErrors) { reportRelationError(headMessage, source, target); } return 0 /* False */; } // Above we check for excess properties with respect to the entire target type. When union // and intersection types are further deconstructed on the target side, we don't want to // make the check again (as it might fail for a partial target type). Therefore we obtain // the regular source type and proceed with that. if (isUnionOrIntersectionTypeWithoutNullableConstituents(target)) { source = getRegularTypeOfObjectLiteral(source); } } var saveErrorInfo = errorInfo; // Note that these checks are specifically ordered to produce correct results. In particular, // we need to deconstruct unions before intersections (because unions are always at the top), // and we need to handle "each" relations before "some" relations for the same kind of type. if (source.flags & 65536 /* Union */) { if (relation === comparableRelation) { result = someTypeRelatedToType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */)); } else { result = eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */)); } if (result) { return result; } } else if (target.flags & 65536 /* Union */) { if (result = typeRelatedToSomeType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */) && !(target.flags & 8190 /* Primitive */))) { return result; } } else if (target.flags & 131072 /* Intersection */) { if (result = typeRelatedToEachType(source, target, reportErrors)) { return result; } } else if (source.flags & 131072 /* Intersection */) { // Check to see if any constituents of the intersection are immediately related to the target. // // Don't report errors though. Checking whether a constituent is related to the source is not actually // useful and leads to some confusing error messages. Instead it is better to let the below checks // take care of this, or to not elaborate at all. For instance, // // - For an object type (such as 'C = A & B'), users are usually more interested in structural errors. // // - For a union type (such as '(A | B) = (C & D)'), it's better to hold onto the whole intersection // than to report that 'D' is not assignable to 'A' or 'B'. // // - For a primitive type or type parameter (such as 'number = A & B') there is no point in // breaking the intersection apart. if (result = someTypeRelatedToType(source, target, /*reportErrors*/ false)) { return result; } } else if (target.flags & 16384 /* TypeParameter */) { // A source type { [P in keyof T]: X } is related to a target type T if X is related to T[P]. if (getObjectFlags(source) & 32 /* Mapped */ && getConstraintTypeFromMappedType(source) === getIndexType(target)) { if (!source.declaration.questionToken) { var templateType = getTemplateTypeFromMappedType(source); var indexedAccessType = getIndexedAccessType(target, getTypeParameterFromMappedType(source)); if (result = isRelatedTo(templateType, indexedAccessType, reportErrors)) { return result; } } } else { // Given a type parameter K with a constraint keyof T, a type S is // assignable to K if S is assignable to keyof T. var constraint = getConstraintOfTypeParameter(target); if (constraint && constraint.flags & 262144 /* Index */) { if (result = isRelatedTo(source, constraint, reportErrors)) { return result; } } } } else if (target.flags & 262144 /* Index */) { // A keyof S is related to a keyof T if T is related to S. if (source.flags & 262144 /* Index */) { if (result = isRelatedTo(target.type, source.type, /*reportErrors*/ false)) { return result; } } // Given a type variable T with a constraint C, a type S is assignable to // keyof T if S is assignable to keyof C. if (target.type.flags & 540672 /* TypeVariable */) { var constraint = getConstraintOfTypeVariable(target.type); if (constraint) { if (result = isRelatedTo(source, getIndexType(constraint), reportErrors)) { return result; } } } } else if (target.flags & 524288 /* IndexedAccess */) { // if we have indexed access types with identical index types, see if relationship holds for // the two object types. if (source.flags & 524288 /* IndexedAccess */ && source.indexType === target.indexType) { if (result = isRelatedTo(source.objectType, target.objectType, reportErrors)) { return result; } } // A type S is related to a type T[K] if S is related to A[K], where K is string-like and // A is the apparent type of S. if (target.constraint) { if (result = isRelatedTo(source, target.constraint, reportErrors)) { errorInfo = saveErrorInfo; return result; } } } if (source.flags & 16384 /* TypeParameter */) { // A source type T is related to a target type { [P in keyof T]: X } if T[P] is related to X. if (getObjectFlags(target) & 32 /* Mapped */ && getConstraintTypeFromMappedType(target) === getIndexType(source)) { var indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(target)); var templateType = getTemplateTypeFromMappedType(target); if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) { errorInfo = saveErrorInfo; return result; } } else { var constraint = getConstraintOfTypeParameter(source); if (!constraint || constraint.flags & 1 /* Any */) { constraint = emptyObjectType; } // The constraint may need to be further instantiated with its 'this' type. constraint = getTypeWithThisArgument(constraint, source); // Report constraint errors only if the constraint is not the empty object type var reportConstraintErrors = reportErrors && constraint !== emptyObjectType; if (result = isRelatedTo(constraint, target, reportConstraintErrors)) { errorInfo = saveErrorInfo; return result; } } } else if (source.flags & 524288 /* IndexedAccess */) { // A type S[K] is related to a type T if A[K] is related to T, where K is string-like and // A is the apparent type of S. if (source.constraint) { if (result = isRelatedTo(source.constraint, target, reportErrors)) { errorInfo = saveErrorInfo; return result; } } } else { if (getObjectFlags(source) & 4 /* Reference */ && getObjectFlags(target) & 4 /* Reference */ && source.target === target.target) { // We have type references to same target type, see if relationship holds for all type arguments if (result = typeArgumentsRelatedTo(source, target, reportErrors)) { return result; } } // Even if relationship doesn't hold for unions, intersections, or generic type references, // it may hold in a structural comparison. var apparentSource = getApparentType(source); // In a check of the form X = A & B, we will have previously checked if A relates to X or B relates // to X. Failing both of those we want to check if the aggregation of A and B's members structurally // relates to X. Thus, we include intersection types on the source side here. if (apparentSource.flags & (32768 /* Object */ | 131072 /* Intersection */) && target.flags & 32768 /* Object */) { // Report structural errors only if we haven't reported any errors yet var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo && !(source.flags & 8190 /* Primitive */); if (result = objectTypeRelatedTo(apparentSource, source, target, reportStructuralErrors)) { errorInfo = saveErrorInfo; return result; } } } if (reportErrors) { if (source.flags & 32768 /* Object */ && target.flags & 8190 /* Primitive */) { tryElaborateErrorsForPrimitivesAndObjects(source, target); } else if (source.symbol && source.flags & 32768 /* Object */ && globalObjectType === source) { reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead); } reportRelationError(headMessage, source, target); } return 0 /* False */; }
(source, target, reportErrors, headMessage) { var result; if (source.flags & 96 /* StringOrNumberLiteral */ && source.flags & 1048576 /* FreshLiteral */) { source = source.regularType; } if (target.flags & 96 /* StringOrNumberLiteral */ && target.flags & 1048576 /* FreshLiteral */) { target = target.regularType; } // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases if (source === target) return -1 /* True */; if (relation === identityRelation) { return isIdenticalTo(source, target); } if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return -1 /* True */; if (getObjectFlags(source) & 128 /* ObjectLiteral */ && source.flags & 1048576 /* FreshLiteral */) { if (hasExcessProperties(source, target, reportErrors)) { if (reportErrors) { reportRelationError(headMessage, source, target); } return 0 /* False */; } // Above we check for excess properties with respect to the entire target type. When union // and intersection types are further deconstructed on the target side, we don't want to // make the check again (as it might fail for a partial target type). Therefore we obtain // the regular source type and proceed with that. if (isUnionOrIntersectionTypeWithoutNullableConstituents(target)) { source = getRegularTypeOfObjectLiteral(source); } } var saveErrorInfo = errorInfo; // Note that these checks are specifically ordered to produce correct results. In particular, // we need to deconstruct unions before intersections (because unions are always at the top), // and we need to handle "each" relations before "some" relations for the same kind of type. if (source.flags & 65536 /* Union */) { if (relation === comparableRelation) { result = someTypeRelatedToType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */)); } else { result = eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */)); } if (result) { return result; } } else if (target.flags & 65536 /* Union */) { if (result = typeRelatedToSomeType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */) && !(target.flags & 8190 /* Primitive */))) { return result; } } else if (target.flags & 131072 /* Intersection */) { if (result = typeRelatedToEachType(source, target, reportErrors)) { return result; } } else if (source.flags & 131072 /* Intersection */) { // Check to see if any constituents of the intersection are immediately related to the target. // // Don't report errors though. Checking whether a constituent is related to the source is not actually // useful and leads to some confusing error messages. Instead it is better to let the below checks // take care of this, or to not elaborate at all. For instance, // // - For an object type (such as 'C = A & B'), users are usually more interested in structural errors. // // - For a union type (such as '(A | B) = (C & D)'), it's better to hold onto the whole intersection // than to report that 'D' is not assignable to 'A' or 'B'. // // - For a primitive type or type parameter (such as 'number = A & B') there is no point in // breaking the intersection apart. if (result = someTypeRelatedToType(source, target, /*reportErrors*/ false)) { return result; } } else if (target.flags & 16384 /* TypeParameter */) { // A source type { [P in keyof T]: X } is related to a target type T if X is related to T[P]. if (getObjectFlags(source) & 32 /* Mapped */ && getConstraintTypeFromMappedType(source) === getIndexType(target)) { if (!source.declaration.questionToken) { var templateType = getTemplateTypeFromMappedType(source); var indexedAccessType = getIndexedAccessType(target, getTypeParameterFromMappedType(source)); if (result = isRelatedTo(templateType, indexedAccessType, reportErrors)) { return result; } } } else { // Given a type parameter K with a constraint keyof T, a type S is // assignable to K if S is assignable to keyof T. var constraint = getConstraintOfTypeParameter(target); if (constraint && constraint.flags & 262144 /* Index */) { if (result = isRelatedTo(source, constraint, reportErrors)) { return result; } } } } else if (target.flags & 262144 /* Index */) { // A keyof S is related to a keyof T if T is related to S. if (source.flags & 262144 /* Index */) { if (result = isRelatedTo(target.type, source.type, /*reportErrors*/ false)) { return result; } } // Given a type variable T with a constraint C, a type S is assignable to // keyof T if S is assignable to keyof C. if (target.type.flags & 540672 /* TypeVariable */) { var constraint = getConstraintOfTypeVariable(target.type); if (constraint) { if (result = isRelatedTo(source, getIndexType(constraint), reportErrors)) { return result; } } } } else if (target.flags & 524288 /* IndexedAccess */) { // if we have indexed access types with identical index types, see if relationship holds for // the two object types. if (source.flags & 524288 /* IndexedAccess */ && source.indexType === target.indexType) { if (result = isRelatedTo(source.objectType, target.objectType, reportErrors)) { return result; } } // A type S is related to a type T[K] if S is related to A[K], where K is string-like and // A is the apparent type of S. if (target.constraint) { if (result = isRelatedTo(source, target.constraint, reportErrors)) { errorInfo = saveErrorInfo; return result; } } } if (source.flags & 16384 /* TypeParameter */) { // A source type T is related to a target type { [P in keyof T]: X } if T[P] is related to X. if (getObjectFlags(target) & 32 /* Mapped */ && getConstraintTypeFromMappedType(target) === getIndexType(source)) { var indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(target)); var templateType = getTemplateTypeFromMappedType(target); if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) { errorInfo = saveErrorInfo; return result; } } else { var constraint = getConstraintOfTypeParameter(source); if (!constraint || constraint.flags & 1 /* Any */) { constraint = emptyObjectType; } // The constraint may need to be further instantiated with its 'this' type. constraint = getTypeWithThisArgument(constraint, source); // Report constraint errors only if the constraint is not the empty object type var reportConstraintErrors = reportErrors && constraint !== emptyObjectType; if (result = isRelatedTo(constraint, target, reportConstraintErrors)) { errorInfo = saveErrorInfo; return result; } } } else if (source.flags & 524288 /* IndexedAccess */) { // A type S[K] is related to a type T if A[K] is related to T, where K is string-like and // A is the apparent type of S. if (source.constraint) { if (result = isRelatedTo(source.constraint, target, reportErrors)) { errorInfo = saveErrorInfo; return result; } } } else { if (getObjectFlags(source) & 4 /* Reference */ && getObjectFlags(target) & 4 /* Reference */ && source.target === target.target) { // We have type references to same target type, see if relationship holds for all type arguments if (result = typeArgumentsRelatedTo(source, target, reportErrors)) { return result; } } // Even if relationship doesn't hold for unions, intersections, or generic type references, // it may hold in a structural comparison. var apparentSource = getApparentType(source); // In a check of the form X = A & B, we will have previously checked if A relates to X or B relates // to X. Failing both of those we want to check if the aggregation of A and B's members structurally // relates to X. Thus, we include intersection types on the source side here. if (apparentSource.flags & (32768 /* Object */ | 131072 /* Intersection */) && target.flags & 32768 /* Object */) { // Report structural errors only if we haven't reported any errors yet var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo && !(source.flags & 8190 /* Primitive */); if (result = objectTypeRelatedTo(apparentSource, source, target, reportStructuralErrors)) { errorInfo = saveErrorInfo; return result; } } } if (reportErrors) { if (source.flags & 32768 /* Object */ && target.flags & 8190 /* Primitive */) { tryElaborateErrorsForPrimitivesAndObjects(source, target); } else if (source.symbol && source.flags & 32768 /* Object */ && globalObjectType === source) { reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead); } reportRelationError(headMessage, source, target); } return 0 /* False */; }
(source, target, reportErrors, headMessage) { var result; if (source.flags & 96 /* StringOrNumberLiteral */ && source.flags & 1048576 /* FreshLiteral */) { source = source.regularType; } if (target.flags & 96 /* StringOrNumberLiteral */ && target.flags & 1048576 /* FreshLiteral */) { target = target.regularType; } // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases if (source === target) return -1 /* True */; if (relation === identityRelation) { return isIdenticalTo(source, target); } if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return -1 /* True */; if (getObjectFlags(source) & 128 /* ObjectLiteral */ && source.flags & 1048576 /* FreshLiteral */) { if (hasExcessProperties(source, target, reportErrors)) { if (reportErrors) { reportRelationError(headMessage, source, target); } return 0 /* False */; } // Above we check for excess properties with respect to the entire target type. When union // and intersection types are further deconstructed on the target side, we don't want to // make the check again (as it might fail for a partial target type). Therefore we obtain // the regular source type and proceed with that. if (isUnionOrIntersectionTypeWithoutNullableConstituents(target)) { source = getRegularTypeOfObjectLiteral(source); } } var saveErrorInfo = errorInfo; // Note that these checks are specifically ordered to produce correct results. In particular, // we need to deconstruct unions before intersections (because unions are always at the top), // and we need to handle "each" relations before "some" relations for the same kind of type. if (source.flags & 65536 /* Union */) { if (relation === comparableRelation) { result = someTypeRelatedToType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */)); } else { result = eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */)); } if (result) { return result; } } else if (target.flags & 65536 /* Union */) { if (result = typeRelatedToSomeType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */) && !(target.flags & 8190 /* Primitive */))) { return result; } } else if (target.flags & 131072 /* Intersection */) { if (result = typeRelatedToEachType(source, target, reportErrors)) { return result; } } else if (source.flags & 131072 /* Intersection */) { // Check to see if any constituents of the intersection are immediately related to the target. // // Don't report errors though. Checking whether a constituent is related to the source is not actually // useful and leads to some confusing error messages. Instead it is better to let the below checks // take care of this, or to not elaborate at all. For instance, // // - For an object type (such as 'C = A & B'), users are usually more interested in structural errors. // // - For a union type (such as '(A | B) = (C & D)'), it's better to hold onto the whole intersection // than to report that 'D' is not assignable to 'A' or 'B'. // // - For a primitive type or type parameter (such as 'number = A & B') there is no point in // breaking the intersection apart. if (result = someTypeRelatedToType(source, target, /*reportErrors*/ false)) { return result; } } else if (target.flags & 16384 /* TypeParameter */) { // A source type { [P in keyof T]: X } is related to a target type T if X is related to T[P]. if (getObjectFlags(source) & 32 /* Mapped */ && getConstraintTypeFromMappedType(source) === getIndexType(target)) { if (!source.declaration.questionToken) { var templateType = getTemplateTypeFromMappedType(source); var indexedAccessType = getIndexedAccessType(target, getTypeParameterFromMappedType(source)); if (result = isRelatedTo(templateType, indexedAccessType, reportErrors)) { return result; } } } else { // Given a type parameter K with a constraint keyof T, a type S is // assignable to K if S is assignable to keyof T. var constraint = getConstraintOfTypeParameter(target); if (constraint && constraint.flags & 262144 /* Index */) { if (result = isRelatedTo(source, constraint, reportErrors)) { return result; } } } } else if (target.flags & 262144 /* Index */) { // A keyof S is related to a keyof T if T is related to S. if (source.flags & 262144 /* Index */) { if (result = isRelatedTo(target.type, source.type, /*reportErrors*/ false)) { return result; } } // Given a type variable T with a constraint C, a type S is assignable to // keyof T if S is assignable to keyof C. if (target.type.flags & 540672 /* TypeVariable */) { var constraint = getConstraintOfTypeVariable(target.type); if (constraint) { if (result = isRelatedTo(source, getIndexType(constraint), reportErrors)) { return result; } } } } else if (target.flags & 524288 /* IndexedAccess */) { // if we have indexed access types with identical index types, see if relationship holds for // the two object types. if (source.flags & 524288 /* IndexedAccess */ && source.indexType === target.indexType) { if (result = isRelatedTo(source.objectType, target.objectType, reportErrors)) { return result; } } // A type S is related to a type T[K] if S is related to A[K], where K is string-like and // A is the apparent type of S. if (target.constraint) { if (result = isRelatedTo(source, target.constraint, reportErrors)) { errorInfo = saveErrorInfo; return result; } } } if (source.flags & 16384 /* TypeParameter */) { // A source type T is related to a target type { [P in keyof T]: X } if T[P] is related to X. if (getObjectFlags(target) & 32 /* Mapped */ && getConstraintTypeFromMappedType(target) === getIndexType(source)) { var indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(target)); var templateType = getTemplateTypeFromMappedType(target); if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) { errorInfo = saveErrorInfo; return result; } } else { var constraint = getConstraintOfTypeParameter(source); if (!constraint || constraint.flags & 1 /* Any */) { constraint = emptyObjectType; } // The constraint may need to be further instantiated with its 'this' type. constraint = getTypeWithThisArgument(constraint, source); // Report constraint errors only if the constraint is not the empty object type var reportConstraintErrors = reportErrors && constraint !== emptyObjectType; if (result = isRelatedTo(constraint, target, reportConstraintErrors)) { errorInfo = saveErrorInfo; return result; } } } else if (source.flags & 524288 /* IndexedAccess */) { // A type S[K] is related to a type T if A[K] is related to T, where K is string-like and // A is the apparent type of S. if (source.constraint) { if (result = isRelatedTo(source.constraint, target, reportErrors)) { errorInfo = saveErrorInfo; return result; } } } else { if (getObjectFlags(source) & 4 /* Reference */ && getObjectFlags(target) & 4 /* Reference */ && source.target === target.target) { // We have type references to same target type, see if relationship holds for all type arguments if (result = typeArgumentsRelatedTo(source, target, reportErrors)) { return result; } } // Even if relationship doesn't hold for unions, intersections, or generic type references, // it may hold in a structural comparison. var apparentSource = getApparentType(source); // In a check of the form X = A & B, we will have previously checked if A relates to X or B relates // to X. Failing both of those we want to check if the aggregation of A and B's members structurally // relates to X. Thus, we include intersection types on the source side here. if (apparentSource.flags & (32768 /* Object */ | 131072 /* Intersection */) && target.flags & 32768 /* Object */) { // Report structural errors only if we haven't reported any errors yet var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo && !(source.flags & 8190 /* Primitive */); if (result = objectTypeRelatedTo(apparentSource, source, target, reportStructuralErrors)) { errorInfo = saveErrorInfo; return result; } } } if (reportErrors) { if (source.flags & 32768 /* Object */ && target.flags & 8190 /* Primitive */) { tryElaborateErrorsForPrimitivesAndObjects(source, target); } else if (source.symbol && source.flags & 32768 /* Object */ && globalObjectType === source) { reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead); } reportRelationError(headMessage, source, target); } return 0 /* False */; }
(source, target, reportErrors, headMessage) { var result; if (source.flags & 96 /* StringOrNumberLiteral */ && source.flags & 1048576 /* FreshLiteral */) { source = source.regularType; } if (target.flags & 96 /* StringOrNumberLiteral */ && target.flags & 1048576 /* FreshLiteral */) { target = target.regularType; } // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases if (source === target) return -1 /* True */; if (relation === identityRelation) { return isIdenticalTo(source, target); } if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return -1 /* True */; if (getObjectFlags(source) & 128 /* ObjectLiteral */ && source.flags & 1048576 /* FreshLiteral */) { if (hasExcessProperties(source, target, reportErrors)) { if (reportErrors) { reportRelationError(headMessage, source, target); } return 0 /* False */; } // Above we check for excess properties with respect to the entire target type. When union // and intersection types are further deconstructed on the target side, we don't want to // make the check again (as it might fail for a partial target type). Therefore we obtain // the regular source type and proceed with that. if (isUnionOrIntersectionTypeWithoutNullableConstituents(target)) { source = getRegularTypeOfObjectLiteral(source); } } var saveErrorInfo = errorInfo; // Note that these checks are specifically ordered to produce correct results. In particular, // we need to deconstruct unions before intersections (because unions are always at the top), // and we need to handle "each" relations before "some" relations for the same kind of type. if (source.flags & 65536 /* Union */) { if (relation === comparableRelation) { result = someTypeRelatedToType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */)); } else { result = eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */)); } if (result) { return result; } } else if (target.flags & 65536 /* Union */) { if (result = typeRelatedToSomeType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */) && !(target.flags & 8190 /* Primitive */))) { return result; } } else if (target.flags & 131072 /* Intersection */) { if (result = typeRelatedToEachType(source, target, reportErrors)) { return result; } } else if (source.flags & 131072 /* Intersection */) { // Check to see if any constituents of the intersection are immediately related to the target. // // Don't report errors though. Checking whether a constituent is related to the source is not actually // useful and leads to some confusing error messages. Instead it is better to let the below checks // take care of this, or to not elaborate at all. For instance, // // - For an object type (such as 'C = A & B'), users are usually more interested in structural errors. // // - For a union type (such as '(A | B) = (C & D)'), it's better to hold onto the whole intersection // than to report that 'D' is not assignable to 'A' or 'B'. // // - For a primitive type or type parameter (such as 'number = A & B') there is no point in // breaking the intersection apart. if (result = someTypeRelatedToType(source, target, /*reportErrors*/ false)) { return result; } } else if (target.flags & 16384 /* TypeParameter */) { // A source type { [P in keyof T]: X } is related to a target type T if X is related to T[P]. if (getObjectFlags(source) & 32 /* Mapped */ && getConstraintTypeFromMappedType(source) === getIndexType(target)) { if (!source.declaration.questionToken) { var templateType = getTemplateTypeFromMappedType(source); var indexedAccessType = getIndexedAccessType(target, getTypeParameterFromMappedType(source)); if (result = isRelatedTo(templateType, indexedAccessType, reportErrors)) { return result; } } } else { // Given a type parameter K with a constraint keyof T, a type S is // assignable to K if S is assignable to keyof T. var constraint = getConstraintOfTypeParameter(target); if (constraint && constraint.flags & 262144 /* Index */) { if (result = isRelatedTo(source, constraint, reportErrors)) { return result; } } } } else if (target.flags & 262144 /* Index */) { // A keyof S is related to a keyof T if T is related to S. if (source.flags & 262144 /* Index */) { if (result = isRelatedTo(target.type, source.type, /*reportErrors*/ false)) { return result; } } // Given a type variable T with a constraint C, a type S is assignable to // keyof T if S is assignable to keyof C. if (target.type.flags & 540672 /* TypeVariable */) { var constraint = getConstraintOfTypeVariable(target.type); if (constraint) { if (result = isRelatedTo(source, getIndexType(constraint), reportErrors)) { return result; } } } } else if (target.flags & 524288 /* IndexedAccess */) { // if we have indexed access types with identical index types, see if relationship holds for // the two object types. if (source.flags & 524288 /* IndexedAccess */ && source.indexType === target.indexType) { if (result = isRelatedTo(source.objectType, target.objectType, reportErrors)) { return result; } } // A type S is related to a type T[K] if S is related to A[K], where K is string-like and // A is the apparent type of S. if (target.constraint) { if (result = isRelatedTo(source, target.constraint, reportErrors)) { errorInfo = saveErrorInfo; return result; } } } if (source.flags & 16384 /* TypeParameter */) { // A source type T is related to a target type { [P in keyof T]: X } if T[P] is related to X. if (getObjectFlags(target) & 32 /* Mapped */ && getConstraintTypeFromMappedType(target) === getIndexType(source)) { var indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(target)); var templateType = getTemplateTypeFromMappedType(target); if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) { errorInfo = saveErrorInfo; return result; } } else { var constraint = getConstraintOfTypeParameter(source); if (!constraint || constraint.flags & 1 /* Any */) { constraint = emptyObjectType; } // The constraint may need to be further instantiated with its 'this' type. constraint = getTypeWithThisArgument(constraint, source); // Report constraint errors only if the constraint is not the empty object type var reportConstraintErrors = reportErrors && constraint !== emptyObjectType; if (result = isRelatedTo(constraint, target, reportConstraintErrors)) { errorInfo = saveErrorInfo; return result; } } } else if (source.flags & 524288 /* IndexedAccess */) { // A type S[K] is related to a type T if A[K] is related to T, where K is string-like and // A is the apparent type of S. if (source.constraint) { if (result = isRelatedTo(source.constraint, target, reportErrors)) { errorInfo = saveErrorInfo; return result; } } } else { if (getObjectFlags(source) & 4 /* Reference */ && getObjectFlags(target) & 4 /* Reference */ && source.target === target.target) { // We have type references to same target type, see if relationship holds for all type arguments if (result = typeArgumentsRelatedTo(source, target, reportErrors)) { return result; } } // Even if relationship doesn't hold for unions, intersections, or generic type references, // it may hold in a structural comparison. var apparentSource = getApparentType(source); // In a check of the form X = A & B, we will have previously checked if A relates to X or B relates // to X. Failing both of those we want to check if the aggregation of A and B's members structurally // relates to X. Thus, we include intersection types on the source side here. if (apparentSource.flags & (32768 /* Object */ | 131072 /* Intersection */) && target.flags & 32768 /* Object */) { // Report structural errors only if we haven't reported any errors yet var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo && !(source.flags & 8190 /* Primitive */); if (result = objectTypeRelatedTo(apparentSource, source, target, reportStructuralErrors)) { errorInfo = saveErrorInfo; return result; } } } if (reportErrors) { if (source.flags & 32768 /* Object */ && target.flags & 8190 /* Primitive */) { tryElaborateErrorsForPrimitivesAndObjects(source, target); } else if (source.symbol && source.flags & 32768 /* Object */ && globalObjectType === source) { reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead); } reportRelationError(headMessage, source, target); } return 0 /* False */; }
(source, target, reportErrors, headMessage) { var result; if (source.flags & 96 /* StringOrNumberLiteral */ && source.flags & 1048576 /* FreshLiteral */) { source = source.regularType; } if (target.flags & 96 /* StringOrNumberLiteral */ && target.flags & 1048576 /* FreshLiteral */) { target = target.regularType; } // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases if (source === target) return -1 /* True */; if (relation === identityRelation) { return isIdenticalTo(source, target); } if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return -1 /* True */; if (getObjectFlags(source) & 128 /* ObjectLiteral */ && source.flags & 1048576 /* FreshLiteral */) { if (hasExcessProperties(source, target, reportErrors)) { if (reportErrors) { reportRelationError(headMessage, source, target); } return 0 /* False */; } // Above we check for excess properties with respect to the entire target type. When union // and intersection types are further deconstructed on the target side, we don't want to // make the check again (as it might fail for a partial target type). Therefore we obtain // the regular source type and proceed with that. if (isUnionOrIntersectionTypeWithoutNullableConstituents(target)) { source = getRegularTypeOfObjectLiteral(source); } } var saveErrorInfo = errorInfo; // Note that these checks are specifically ordered to produce correct results. In particular, // we need to deconstruct unions before intersections (because unions are always at the top), // and we need to handle "each" relations before "some" relations for the same kind of type. if (source.flags & 65536 /* Union */) { if (relation === comparableRelation) { result = someTypeRelatedToType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */)); } else { result = eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */)); } if (result) { return result; } } else if (target.flags & 65536 /* Union */) { if (result = typeRelatedToSomeType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */) && !(target.flags & 8190 /* Primitive */))) { return result; } } else if (target.flags & 131072 /* Intersection */) { if (result = typeRelatedToEachType(source, target, reportErrors)) { return result; } } else if (source.flags & 131072 /* Intersection */) { // Check to see if any constituents of the intersection are immediately related to the target. // // Don't report errors though. Checking whether a constituent is related to the source is not actually // useful and leads to some confusing error messages. Instead it is better to let the below checks // take care of this, or to not elaborate at all. For instance, // // - For an object type (such as 'C = A & B'), users are usually more interested in structural errors. // // - For a union type (such as '(A | B) = (C & D)'), it's better to hold onto the whole intersection // than to report that 'D' is not assignable to 'A' or 'B'. // // - For a primitive type or type parameter (such as 'number = A & B') there is no point in // breaking the intersection apart. if (result = someTypeRelatedToType(source, target, /*reportErrors*/ false)) { return result; } } else if (target.flags & 16384 /* TypeParameter */) { // A source type { [P in keyof T]: X } is related to a target type T if X is related to T[P]. if (getObjectFlags(source) & 32 /* Mapped */ && getConstraintTypeFromMappedType(source) === getIndexType(target)) { if (!source.declaration.questionToken) { var templateType = getTemplateTypeFromMappedType(source); var indexedAccessType = getIndexedAccessType(target, getTypeParameterFromMappedType(source)); if (result = isRelatedTo(templateType, indexedAccessType, reportErrors)) { return result; } } } else { // Given a type parameter K with a constraint keyof T, a type S is // assignable to K if S is assignable to keyof T. var constraint = getConstraintOfTypeParameter(target); if (constraint && constraint.flags & 262144 /* Index */) { if (result = isRelatedTo(source, constraint, reportErrors)) { return result; } } } } else if (target.flags & 262144 /* Index */) { // A keyof S is related to a keyof T if T is related to S. if (source.flags & 262144 /* Index */) { if (result = isRelatedTo(target.type, source.type, /*reportErrors*/ false)) { return result; } } // Given a type variable T with a constraint C, a type S is assignable to // keyof T if S is assignable to keyof C. if (target.type.flags & 540672 /* TypeVariable */) { var constraint = getConstraintOfTypeVariable(target.type); if (constraint) { if (result = isRelatedTo(source, getIndexType(constraint), reportErrors)) { return result; } } } } else if (target.flags & 524288 /* IndexedAccess */) { // if we have indexed access types with identical index types, see if relationship holds for // the two object types. if (source.flags & 524288 /* IndexedAccess */ && source.indexType === target.indexType) { if (result = isRelatedTo(source.objectType, target.objectType, reportErrors)) { return result; } } // A type S is related to a type T[K] if S is related to A[K], where K is string-like and // A is the apparent type of S. if (target.constraint) { if (result = isRelatedTo(source, target.constraint, reportErrors)) { errorInfo = saveErrorInfo; return result; } } } if (source.flags & 16384 /* TypeParameter */) { // A source type T is related to a target type { [P in keyof T]: X } if T[P] is related to X. if (getObjectFlags(target) & 32 /* Mapped */ && getConstraintTypeFromMappedType(target) === getIndexType(source)) { var indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(target)); var templateType = getTemplateTypeFromMappedType(target); if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) { errorInfo = saveErrorInfo; return result; } } else { var constraint = getConstraintOfTypeParameter(source); if (!constraint || constraint.flags & 1 /* Any */) { constraint = emptyObjectType; } // The constraint may need to be further instantiated with its 'this' type. constraint = getTypeWithThisArgument(constraint, source); // Report constraint errors only if the constraint is not the empty object type var reportConstraintErrors = reportErrors && constraint !== emptyObjectType; if (result = isRelatedTo(constraint, target, reportConstraintErrors)) { errorInfo = saveErrorInfo; return result; } } } else if (source.flags & 524288 /* IndexedAccess */) { // A type S[K] is related to a type T if A[K] is related to T, where K is string-like and // A is the apparent type of S. if (source.constraint) { if (result = isRelatedTo(source.constraint, target, reportErrors)) { errorInfo = saveErrorInfo; return result; } } } else { if (getObjectFlags(source) & 4 /* Reference */ && getObjectFlags(target) & 4 /* Reference */ && source.target === target.target) { // We have type references to same target type, see if relationship holds for all type arguments if (result = typeArgumentsRelatedTo(source, target, reportErrors)) { return result; } } // Even if relationship doesn't hold for unions, intersections, or generic type references, // it may hold in a structural comparison. var apparentSource = getApparentType(source); // In a check of the form X = A & B, we will have previously checked if A relates to X or B relates // to X. Failing both of those we want to check if the aggregation of A and B's members structurally // relates to X. Thus, we include intersection types on the source side here. if (apparentSource.flags & (32768 /* Object */ | 131072 /* Intersection */) && target.flags & 32768 /* Object */) { // Report structural errors only if we haven't reported any errors yet var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo && !(source.flags & 8190 /* Primitive */); if (result = objectTypeRelatedTo(apparentSource, source, target, reportStructuralErrors)) { errorInfo = saveErrorInfo; return result; } } } if (reportErrors) { if (source.flags & 32768 /* Object */ && target.flags & 8190 /* Primitive */) { tryElaborateErrorsForPrimitivesAndObjects(source, target); } else if (source.symbol && source.flags & 32768 /* Object */ && globalObjectType === source) { reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead); } reportRelationError(headMessage, source, target); } return 0 /* False */; }
propertiesRelatedTo:
(source, target, reportErrors) { if (relation === identityRelation) { return propertiesIdenticalTo(source, target); } var result = -1 /* True */; var properties = getPropertiesOfObjectType(target); var requireOptionalProperties = relation === subtypeRelation && !(getObjectFlags(source) & 128 /* ObjectLiteral */); for (var _i = 0, properties_3 = properties; _i < properties_3.length; _i++) { var targetProp = properties_3[_i]; var sourceProp = getPropertyOfType(source, targetProp.name); if (sourceProp !== targetProp) { if (!sourceProp) { if (!(targetProp.flags & 536870912 /* Optional */) || requireOptionalProperties) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source)); } return 0 /* False */; } } else if (!(targetProp.flags & 134217728 /* Prototype */)) { var sourcePropFlags = getDeclarationModifierFlagsFromSymbol(sourceProp); var targetPropFlags = getDeclarationModifierFlagsFromSymbol(targetProp); if (sourcePropFlags & 8 /* Private */ || targetPropFlags & 8 /* Private */) { if (sourceProp.valueDeclaration !== targetProp.valueDeclaration) { if (reportErrors) { if (sourcePropFlags & 8 /* Private */ && targetPropFlags & 8 /* Private */) { reportError(ts.Diagnostics.Types_have_separate_declarations_of_a_private_property_0, symbolToString(targetProp)); } else { reportError(ts.Diagnostics.Property_0_is_private_in_type_1_but_not_in_type_2, symbolToString(targetProp), typeToString(sourcePropFlags & 8 /* Private */ ? source : target), typeToString(sourcePropFlags & 8 /* Private */ ? target : source)); } } return 0 /* False */; } } else if (targetPropFlags & 16 /* Protected */) { var sourceDeclaredInClass = sourceProp.parent && sourceProp.parent.flags & 32 /* Class */; var sourceClass = sourceDeclaredInClass ? getDeclaredTypeOfSymbol(getParentOfSymbol(sourceProp)) : undefined; var targetClass = getDeclaredTypeOfSymbol(getParentOfSymbol(targetProp)); if (!sourceClass || !hasBaseType(sourceClass, targetClass)) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2, symbolToString(targetProp), typeToString(sourceClass || source), typeToString(targetClass)); } return 0 /* False */; } } else if (sourcePropFlags & 16 /* Protected */) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_protected_in_type_1_but_public_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target)); } return 0 /* False */; } var related = isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors); if (!related) { if (reportErrors) { reportError(ts.Diagnostics.Types_of_property_0_are_incompatible, symbolToString(targetProp)); } return 0 /* False */; } result &= related; // When checking for comparability, be more lenient with optional properties. if (relation !== comparableRelation && sourceProp.flags & 536870912 /* Optional */ && !(targetProp.flags & 536870912 /* Optional */)) { // TypeScript 1.0 spec (April 2014): 3.8.3 // S is a subtype of a type T, and T is a supertype of S if ... // S' and T are object types and, for each member M in T.. // M is a property and S' contains a property N where // if M is a required property, N is also a required property // (M - property in T) // (N - property in S) if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_optional_in_type_1_but_required_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target)); } return 0 /* False */; } } } } return result; }
(source, target, reportErrors) { if (relation === identityRelation) { return propertiesIdenticalTo(source, target); } var result = -1 /* True */; var properties = getPropertiesOfObjectType(target); var requireOptionalProperties = relation === subtypeRelation && !(getObjectFlags(source) & 128 /* ObjectLiteral */); for (var _i = 0, properties_3 = properties; _i < properties_3.length; _i++) { var targetProp = properties_3[_i]; var sourceProp = getPropertyOfType(source, targetProp.name); if (sourceProp !== targetProp) { if (!sourceProp) { if (!(targetProp.flags & 536870912 /* Optional */) || requireOptionalProperties) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source)); } return 0 /* False */; } } else if (!(targetProp.flags & 134217728 /* Prototype */)) { var sourcePropFlags = getDeclarationModifierFlagsFromSymbol(sourceProp); var targetPropFlags = getDeclarationModifierFlagsFromSymbol(targetProp); if (sourcePropFlags & 8 /* Private */ || targetPropFlags & 8 /* Private */) { if (sourceProp.valueDeclaration !== targetProp.valueDeclaration) { if (reportErrors) { if (sourcePropFlags & 8 /* Private */ && targetPropFlags & 8 /* Private */) { reportError(ts.Diagnostics.Types_have_separate_declarations_of_a_private_property_0, symbolToString(targetProp)); } else { reportError(ts.Diagnostics.Property_0_is_private_in_type_1_but_not_in_type_2, symbolToString(targetProp), typeToString(sourcePropFlags & 8 /* Private */ ? source : target), typeToString(sourcePropFlags & 8 /* Private */ ? target : source)); } } return 0 /* False */; } } else if (targetPropFlags & 16 /* Protected */) { var sourceDeclaredInClass = sourceProp.parent && sourceProp.parent.flags & 32 /* Class */; var sourceClass = sourceDeclaredInClass ? getDeclaredTypeOfSymbol(getParentOfSymbol(sourceProp)) : undefined; var targetClass = getDeclaredTypeOfSymbol(getParentOfSymbol(targetProp)); if (!sourceClass || !hasBaseType(sourceClass, targetClass)) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2, symbolToString(targetProp), typeToString(sourceClass || source), typeToString(targetClass)); } return 0 /* False */; } } else if (sourcePropFlags & 16 /* Protected */) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_protected_in_type_1_but_public_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target)); } return 0 /* False */; } var related = isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors); if (!related) { if (reportErrors) { reportError(ts.Diagnostics.Types_of_property_0_are_incompatible, symbolToString(targetProp)); } return 0 /* False */; } result &= related; // When checking for comparability, be more lenient with optional properties. if (relation !== comparableRelation && sourceProp.flags & 536870912 /* Optional */ && !(targetProp.flags & 536870912 /* Optional */)) { // TypeScript 1.0 spec (April 2014): 3.8.3 // S is a subtype of a type T, and T is a supertype of S if ... // S' and T are object types and, for each member M in T.. // M is a property and S' contains a property N where // if M is a required property, N is also a required property // (M - property in T) // (N - property in S) if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_optional_in_type_1_but_required_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target)); } return 0 /* False */; } } } } return result; }
(source, target, reportErrors) { if (relation === identityRelation) { return propertiesIdenticalTo(source, target); } var result = -1 /* True */; var properties = getPropertiesOfObjectType(target); var requireOptionalProperties = relation === subtypeRelation && !(getObjectFlags(source) & 128 /* ObjectLiteral */); for (var _i = 0, properties_3 = properties; _i < properties_3.length; _i++) { var targetProp = properties_3[_i]; var sourceProp = getPropertyOfType(source, targetProp.name); if (sourceProp !== targetProp) { if (!sourceProp) { if (!(targetProp.flags & 536870912 /* Optional */) || requireOptionalProperties) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source)); } return 0 /* False */; } } else if (!(targetProp.flags & 134217728 /* Prototype */)) { var sourcePropFlags = getDeclarationModifierFlagsFromSymbol(sourceProp); var targetPropFlags = getDeclarationModifierFlagsFromSymbol(targetProp); if (sourcePropFlags & 8 /* Private */ || targetPropFlags & 8 /* Private */) { if (sourceProp.valueDeclaration !== targetProp.valueDeclaration) { if (reportErrors) { if (sourcePropFlags & 8 /* Private */ && targetPropFlags & 8 /* Private */) { reportError(ts.Diagnostics.Types_have_separate_declarations_of_a_private_property_0, symbolToString(targetProp)); } else { reportError(ts.Diagnostics.Property_0_is_private_in_type_1_but_not_in_type_2, symbolToString(targetProp), typeToString(sourcePropFlags & 8 /* Private */ ? source : target), typeToString(sourcePropFlags & 8 /* Private */ ? target : source)); } } return 0 /* False */; } } else if (targetPropFlags & 16 /* Protected */) { var sourceDeclaredInClass = sourceProp.parent && sourceProp.parent.flags & 32 /* Class */; var sourceClass = sourceDeclaredInClass ? getDeclaredTypeOfSymbol(getParentOfSymbol(sourceProp)) : undefined; var targetClass = getDeclaredTypeOfSymbol(getParentOfSymbol(targetProp)); if (!sourceClass || !hasBaseType(sourceClass, targetClass)) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2, symbolToString(targetProp), typeToString(sourceClass || source), typeToString(targetClass)); } return 0 /* False */; } } else if (sourcePropFlags & 16 /* Protected */) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_protected_in_type_1_but_public_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target)); } return 0 /* False */; } var related = isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors); if (!related) { if (reportErrors) { reportError(ts.Diagnostics.Types_of_property_0_are_incompatible, symbolToString(targetProp)); } return 0 /* False */; } result &= related; // When checking for comparability, be more lenient with optional properties. if (relation !== comparableRelation && sourceProp.flags & 536870912 /* Optional */ && !(targetProp.flags & 536870912 /* Optional */)) { // TypeScript 1.0 spec (April 2014): 3.8.3 // S is a subtype of a type T, and T is a supertype of S if ... // S' and T are object types and, for each member M in T.. // M is a property and S' contains a property N where // if M is a required property, N is also a required property // (M - property in T) // (N - property in S) if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_optional_in_type_1_but_required_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target)); } return 0 /* False */; } } } } return result; }
getConstraintOfTypeParameter:
(typeParameter) { if (!typeParameter.constraint) { if (typeParameter.target) { var targetConstraint = getConstraintOfTypeParameter(typeParameter.target); typeParameter.constraint = targetConstraint ? instantiateType(targetConstraint, typeParameter.mapper) : noConstraintType; } else { var constraintDeclaration = getConstraintDeclaration(typeParameter); var constraint = getTypeFromTypeNode(constraintDeclaration); if (hasConstraintReferenceTo(constraint, typeParameter)) { error(constraintDeclaration, ts.Diagnostics.Type_parameter_0_has_a_circular_constraint, typeToString(typeParameter)); constraint = unknownType; } typeParameter.constraint = constraint; } } return typeParameter.constraint === noConstraintType ? undefined : typeParameter.constraint; }
binarySearchTypes:
(types, type) { var low = 0; var high = types.length - 1; var typeId = type.id; while (low <= high) { var middle = low + ((high - low) >> 1); var id = types[middle].id; if (id === typeId) { return middle; } else if (id > typeId) { high = middle - 1; } else { low = middle + 1; } } return ~low; }
(types, type) { var low = 0; var high = types.length - 1; var typeId = type.id; while (low <= high) { var middle = low + ((high - low) >> 1); var id = types[middle].id; if (id === typeId) { return middle; } else if (id > typeId) { high = middle - 1; } else { low = middle + 1; } } return ~low; }
createLiteralType:
(flags, text) { var type = createType(flags); type.text = text; return type; }
getNamedMembers:
(members) { var result; for (var id in members) { if (!isReservedMemberName(id)) { if (!result) result = []; var symbol = members[id]; if (symbolIsValue(symbol)) { result.push(symbol); } } } return result || emptyArray; }
checkTypeAssignableTo:
(source, target, errorNode, headMessage, containingMessageChain) { return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage, containingMessageChain); }
Deopt: <JS Function (SharedFunctionInfo 0x298f55ea01d9)> (opt #426) @2, FP to SP delta: 24, caller sp: 0x7fff5fbfde30
isGenericMappedType:
(type) { if (getObjectFlags(type) & 32 /* Mapped */) { var constraintType = getConstraintTypeFromMappedType(type); return maybeTypeOfKind(constraintType, 540672 /* TypeVariable */ | 262144 /* Index */); } return false; }
isConst:
(node) { return !!(ts.getCombinedNodeFlags(node) & 2 /* Const */) || !!(ts.getCombinedModifierFlags(node) & 2048 /* Const */); }
isLet:
(node) { return !!(ts.getCombinedNodeFlags(node) & 1 /* Let */); }
getNumNonRestParameters:
(signature) { var numParams = signature.parameters.length; return signature.hasRestParameter ? numParams - 1 : numParams; }
(signature) { var numParams = signature.parameters.length; return signature.hasRestParameter ? numParams - 1 : numParams; }
getTypeOfParameter:
(symbol) { var type = getTypeOfSymbol(symbol); if (strictNullChecks) { var declaration = symbol.valueDeclaration; if (declaration && declaration.initializer) { return includeFalsyTypes(type, 2048 /* Undefined */); } } return type; }
map:
(array, f) { var result; if (array) { result = []; for (var i = 0; i < array.length; i++) { result.push(f(array[i], i)); } } return result; }
addInheritedMembers:
(symbols, baseSymbols) { for (var _i = 0, baseSymbols_1 = baseSymbols; _i < baseSymbols_1.length; _i++) { var s = baseSymbols_1[_i]; if (!symbols[s.name]) { symbols[s.name] = s; } } }
Deopt: <JS Function getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode (SharedFunctionInfo 0x3fa1587fa2c1)> (opt #421) @36, FP to SP delta: 168, caller sp: 0x7fff5fbfda58
(symbols, baseSymbols) { for (var _i = 0, baseSymbols_1 = baseSymbols; _i < baseSymbols_1.length; _i++) { var s = baseSymbols_1[_i]; if (!symbols[s.name]) { symbols[s.name] = s; } } }
checkVariableStatement:
(node) { // Grammar checking checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); ts.forEach(node.declarationList.declarations, checkSourceElement); }
(node) { // Grammar checking checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); ts.forEach(node.declarationList.declarations, checkSourceElement); }
checkVariableDeclaration:
(node) { checkGrammarVariableDeclaration(node); return checkVariableLikeDeclaration(node); }
check:
(type) { var target = getTargetType(type); return target === checkBase || ts.forEach(getBaseTypes(target), check); }
getTypeListId:
(types) { var result = ""; if (types) { var length_3 = types.length; var i = 0; while (i < length_3) { var startId = types[i].id; var count = 1; while (i + count < length_3 && types[i + count].id === startId + count) { count++; } if (result.length) { result += ","; } result += startId; if (count > 1) { result += ":" + count; } i += count; } } return result; }
checkGrammarHeritageClause:
(node) { var types = node.types; if (checkGrammarForDisallowedTrailingComma(types)) { return true; } if (types && types.length === 0) { var listType = ts.tokenToString(node.token); var sourceFile = ts.getSourceFileOfNode(node); return grammarErrorAtPos(sourceFile, types.pos, 0, ts.Diagnostics._0_list_cannot_be_empty, listType); } }
needCollisionCheckForIdentifier:
(node, identifier, name) { if (!(identifier && identifier.text === name)) { return false; } if (node.kind === 147 /* PropertyDeclaration */ || node.kind === 146 /* PropertySignature */ || node.kind === 149 /* MethodDeclaration */ || node.kind === 148 /* MethodSignature */ || node.kind === 151 /* GetAccessor */ || node.kind === 152 /* SetAccessor */) { // it is ok to have member named '_super' or '_this' - member access is always qualified return false; } if (ts.isInAmbientContext(node)) { // ambient context - no codegen impact return false; } var root = ts.getRootDeclaration(node); if (root.kind === 144 /* Parameter */ && ts.nodeIsMissing(root.parent.body)) { // just an overload - no codegen impact return false; } return true; }
(node, identifier, name) { if (!(identifier && identifier.text === name)) { return false; } if (node.kind === 147 /* PropertyDeclaration */ || node.kind === 146 /* PropertySignature */ || node.kind === 149 /* MethodDeclaration */ || node.kind === 148 /* MethodSignature */ || node.kind === 151 /* GetAccessor */ || node.kind === 152 /* SetAccessor */) { // it is ok to have member named '_super' or '_this' - member access is always qualified return false; } if (ts.isInAmbientContext(node)) { // ambient context - no codegen impact return false; } var root = ts.getRootDeclaration(node); if (root.kind === 144 /* Parameter */ && ts.nodeIsMissing(root.parent.body)) { // just an overload - no codegen impact return false; } return true; }
(node, identifier, name) { if (!(identifier && identifier.text === name)) { return false; } if (node.kind === 147 /* PropertyDeclaration */ || node.kind === 146 /* PropertySignature */ || node.kind === 149 /* MethodDeclaration */ || node.kind === 148 /* MethodSignature */ || node.kind === 151 /* GetAccessor */ || node.kind === 152 /* SetAccessor */) { // it is ok to have member named '_super' or '_this' - member access is always qualified return false; } if (ts.isInAmbientContext(node)) { // ambient context - no codegen impact return false; } var root = ts.getRootDeclaration(node); if (root.kind === 144 /* Parameter */ && ts.nodeIsMissing(root.parent.body)) { // just an overload - no codegen impact return false; } return true; }
getErasedSignature:
(signature) { if (!signature.typeParameters) return signature; if (!signature.erasedSignatureCache) { signature.erasedSignatureCache = instantiateSignature(signature, createTypeEraser(signature.typeParameters), /*eraseTypeParameters*/ true); } return signature.erasedSignatureCache; }
(signature) { if (!signature.typeParameters) return signature; if (!signature.erasedSignatureCache) { signature.erasedSignatureCache = instantiateSignature(signature, createTypeEraser(signature.typeParameters), /*eraseTypeParameters*/ true); } return signature.erasedSignatureCache; }
(signature) { if (!signature.typeParameters) return signature; if (!signature.erasedSignatureCache) { signature.erasedSignatureCache = instantiateSignature(signature, createTypeEraser(signature.typeParameters), /*eraseTypeParameters*/ true); } return signature.erasedSignatureCache; }
getNumParametersToCheckForSignatureRelatability:
(source, sourceNonRestParamCount, target, targetNonRestParamCount) { if (source.hasRestParameter === target.hasRestParameter) { if (source.hasRestParameter) { // If both have rest parameters, get the max and add 1 to // compensate for the rest parameter. return Math.max(sourceNonRestParamCount, targetNonRestParamCount) + 1; } else { return Math.min(sourceNonRestParamCount, targetNonRestParamCount); } } else { // Return the count for whichever signature doesn't have rest parameters. return source.hasRestParameter ? targetNonRestParamCount : sourceNonRestParamCount; } }
(source, sourceNonRestParamCount, target, targetNonRestParamCount) { if (source.hasRestParameter === target.hasRestParameter) { if (source.hasRestParameter) { // If both have rest parameters, get the max and add 1 to // compensate for the rest parameter. return Math.max(sourceNonRestParamCount, targetNonRestParamCount) + 1; } else { return Math.min(sourceNonRestParamCount, targetNonRestParamCount); } } else { // Return the count for whichever signature doesn't have rest parameters. return source.hasRestParameter ? targetNonRestParamCount : sourceNonRestParamCount; } }
(source, sourceNonRestParamCount, target, targetNonRestParamCount) { if (source.hasRestParameter === target.hasRestParameter) { if (source.hasRestParameter) { // If both have rest parameters, get the max and add 1 to // compensate for the rest parameter. return Math.max(sourceNonRestParamCount, targetNonRestParamCount) + 1; } else { return Math.min(sourceNonRestParamCount, targetNonRestParamCount); } } else { // Return the count for whichever signature doesn't have rest parameters. return source.hasRestParameter ? targetNonRestParamCount : sourceNonRestParamCount; } }
(source, sourceNonRestParamCount, target, targetNonRestParamCount) { if (source.hasRestParameter === target.hasRestParameter) { if (source.hasRestParameter) { // If both have rest parameters, get the max and add 1 to // compensate for the rest parameter. return Math.max(sourceNonRestParamCount, targetNonRestParamCount) + 1; } else { return Math.min(sourceNonRestParamCount, targetNonRestParamCount); } } else { // Return the count for whichever signature doesn't have rest parameters. return source.hasRestParameter ? targetNonRestParamCount : sourceNonRestParamCount; } }
removeRedundantLiteralTypes:
(types) { var i = types.length; while (i > 0) { i--; var t = types[i]; var remove = t.flags & 32 /* StringLiteral */ && types.containsString || t.flags & 64 /* NumberLiteral */ && types.containsNumber || t.flags & 96 /* StringOrNumberLiteral */ && t.flags & 1048576 /* FreshLiteral */ && containsType(types, t.regularType); if (remove) { ts.orderedRemoveItemAt(types, i); } } }
isTypeAssignableTo:
(source, target) { return isTypeRelatedTo(source, target, assignableRelation); }
addTypesToUnion:
(typeSet, types) { for (var _i = 0, types_4 = types; _i < types_4.length; _i++) { var type = types_4[_i]; addTypeToUnion(typeSet, type); } }
(typeSet, types) { for (var _i = 0, types_4 = types; _i < types_4.length; _i++) { var type = types_4[_i]; addTypeToUnion(typeSet, type); } }
Deopt: <JS Function isAmbientModule (SharedFunctionInfo 0x2c75c4acd741)> (opt #559) @4, FP to SP delta: 24, caller sp: 0x7fff5fbfdc20
Deopt: <JS Function checkGrammarVariableDeclaration (SharedFunctionInfo 0x3fca5861a411)> (opt #524) @30, FP to SP delta: 120, caller sp: 0x7fff5fbfd7a0
instantiateSignatures:
(signatures, mapper) { return instantiateList(signatures, mapper, instantiateSignature); }
(signatures, mapper) { return instantiateList(signatures, mapper, instantiateSignature); }
instantiateIndexInfo:
(info, mapper) { return info && createIndexInfo(instantiateType(info.type, mapper), info.isReadonly, info.declaration); }
getThisTypeOfSignature:
(signature) { if (signature.thisParameter) { return getTypeOfSymbol(signature.thisParameter); } }
instantiateTypeNoAlias:
(type, mapper) { if (type.flags & 16384 /* TypeParameter */) { return mapper(type); } if (type.flags & 32768 /* Object */) { if (type.objectFlags & 16 /* Anonymous */) { // If the anonymous type originates in a declaration of a function, method, class, or // interface, in an object type literal, or in an object literal expression, we may need // to instantiate the type because it might reference a type parameter. We skip instantiation // if none of the type parameters that are in scope in the type's declaration are mapped by // the given mapper, however we can only do that analysis if the type isn't itself an // instantiation. return type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */) && (type.objectFlags & 64 /* Instantiated */ || isSymbolInScopeOfMappedTypeParameter(type.symbol, mapper)) ? instantiateCached(type, mapper, instantiateAnonymousType) : type; } if (type.objectFlags & 32 /* Mapped */) { return instantiateCached(type, mapper, instantiateMappedType); } if (type.objectFlags & 4 /* Reference */) { return createTypeReference(type.target, instantiateTypes(type.typeArguments, mapper)); } } if (type.flags & 65536 /* Union */ && !(type.flags & 8190 /* Primitive */)) { return getUnionType(instantiateTypes(type.types, mapper), /*subtypeReduction*/ false, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper)); } if (type.flags & 131072 /* Intersection */) { return getIntersectionType(instantiateTypes(type.types, mapper), type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper)); } if (type.flags & 262144 /* Index */) { return getIndexType(instantiateType(type.type, mapper)); } if (type.flags & 524288 /* IndexedAccess */) { return getIndexedAccessType(instantiateType(type.objectType, mapper), instantiateType(type.indexType, mapper)); } return type; }
(type, mapper) { if (type.flags & 16384 /* TypeParameter */) { return mapper(type); } if (type.flags & 32768 /* Object */) { if (type.objectFlags & 16 /* Anonymous */) { // If the anonymous type originates in a declaration of a function, method, class, or // interface, in an object type literal, or in an object literal expression, we may need // to instantiate the type because it might reference a type parameter. We skip instantiation // if none of the type parameters that are in scope in the type's declaration are mapped by // the given mapper, however we can only do that analysis if the type isn't itself an // instantiation. return type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */) && (type.objectFlags & 64 /* Instantiated */ || isSymbolInScopeOfMappedTypeParameter(type.symbol, mapper)) ? instantiateCached(type, mapper, instantiateAnonymousType) : type; } if (type.objectFlags & 32 /* Mapped */) { return instantiateCached(type, mapper, instantiateMappedType); } if (type.objectFlags & 4 /* Reference */) { return createTypeReference(type.target, instantiateTypes(type.typeArguments, mapper)); } } if (type.flags & 65536 /* Union */ && !(type.flags & 8190 /* Primitive */)) { return getUnionType(instantiateTypes(type.types, mapper), /*subtypeReduction*/ false, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper)); } if (type.flags & 131072 /* Intersection */) { return getIntersectionType(instantiateTypes(type.types, mapper), type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper)); } if (type.flags & 262144 /* Index */) { return getIndexType(instantiateType(type.type, mapper)); } if (type.flags & 524288 /* IndexedAccess */) { return getIndexedAccessType(instantiateType(type.objectType, mapper), instantiateType(type.indexType, mapper)); } return type; }
isTypeAny:
(type) { return type && (type.flags & 1 /* Any */) !== 0; }
indexTypesRelatedTo:
(source, originalSource, target, kind, reportErrors) { if (relation === identityRelation) { return indexTypesIdenticalTo(source, target, kind); } var targetInfo = getIndexInfoOfType(target, kind); if (!targetInfo || ((targetInfo.type.flags & 1 /* Any */) && !(originalSource.flags & 8190 /* Primitive */))) { // Index signature of type any permits assignment from everything but primitives return -1 /* True */; } var sourceInfo = getIndexInfoOfType(source, kind) || kind === 1 /* Number */ && getIndexInfoOfType(source, 0 /* String */); if (sourceInfo) { return indexInfoRelatedTo(sourceInfo, targetInfo, reportErrors); } if (isObjectLiteralType(source)) { var related = -1 /* True */; if (kind === 0 /* String */) { var sourceNumberInfo = getIndexInfoOfType(source, 1 /* Number */); if (sourceNumberInfo) { related = indexInfoRelatedTo(sourceNumberInfo, targetInfo, reportErrors); } } if (related) { related &= eachPropertyRelatedTo(source, targetInfo.type, kind, reportErrors); } return related; } if (reportErrors) { reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } return 0 /* False */; }
(source, originalSource, target, kind, reportErrors) { if (relation === identityRelation) { return indexTypesIdenticalTo(source, target, kind); } var targetInfo = getIndexInfoOfType(target, kind); if (!targetInfo || ((targetInfo.type.flags & 1 /* Any */) && !(originalSource.flags & 8190 /* Primitive */))) { // Index signature of type any permits assignment from everything but primitives return -1 /* True */; } var sourceInfo = getIndexInfoOfType(source, kind) || kind === 1 /* Number */ && getIndexInfoOfType(source, 0 /* String */); if (sourceInfo) { return indexInfoRelatedTo(sourceInfo, targetInfo, reportErrors); } if (isObjectLiteralType(source)) { var related = -1 /* True */; if (kind === 0 /* String */) { var sourceNumberInfo = getIndexInfoOfType(source, 1 /* Number */); if (sourceNumberInfo) { related = indexInfoRelatedTo(sourceNumberInfo, targetInfo, reportErrors); } } if (related) { related &= eachPropertyRelatedTo(source, targetInfo.type, kind, reportErrors); } return related; } if (reportErrors) { reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } return 0 /* False */; }
checkInheritedPropertiesAreIdentical:
(type, typeNode) { var baseTypes = getBaseTypes(type); if (baseTypes.length < 2) { return true; } var seen = ts.createMap(); ts.forEach(resolveDeclaredMembers(type).declaredProperties, function (p) { seen[p.name] = { prop: p, containingType: type }; }); var ok = true; for (var _i = 0, baseTypes_2 = baseTypes; _i < baseTypes_2.length; _i++) { var base = baseTypes_2[_i]; var properties = getPropertiesOfObjectType(getTypeWithThisArgument(base, type.thisType)); for (var _a = 0, properties_7 = properties; _a < properties_7.length; _a++) { var prop = properties_7[_a]; var existing = seen[prop.name]; if (!existing) { seen[prop.name] = { prop: prop, containingType: base }; } else { var isInheritedProperty = existing.containingType !== type; if (isInheritedProperty && !isPropertyIdenticalTo(existing.prop, prop)) { ok = false; var typeName1 = typeToString(existing.containingType); var typeName2 = typeToString(base); var errorInfo = ts.chainDiagnosticMessages(undefined, ts.Diagnostics.Named_property_0_of_types_1_and_2_are_not_identical, symbolToString(prop), typeName1, typeName2); errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.Interface_0_cannot_simultaneously_extend_types_1_and_2, typeToString(type), typeName1, typeName2); diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(typeNode, errorInfo)); } } } } return ok; }
(type, typeNode) { var baseTypes = getBaseTypes(type); if (baseTypes.length < 2) { return true; } var seen = ts.createMap(); ts.forEach(resolveDeclaredMembers(type).declaredProperties, function (p) { seen[p.name] = { prop: p, containingType: type }; }); var ok = true; for (var _i = 0, baseTypes_2 = baseTypes; _i < baseTypes_2.length; _i++) { var base = baseTypes_2[_i]; var properties = getPropertiesOfObjectType(getTypeWithThisArgument(base, type.thisType)); for (var _a = 0, properties_7 = properties; _a < properties_7.length; _a++) { var prop = properties_7[_a]; var existing = seen[prop.name]; if (!existing) { seen[prop.name] = { prop: prop, containingType: base }; } else { var isInheritedProperty = existing.containingType !== type; if (isInheritedProperty && !isPropertyIdenticalTo(existing.prop, prop)) { ok = false; var typeName1 = typeToString(existing.containingType); var typeName2 = typeToString(base); var errorInfo = ts.chainDiagnosticMessages(undefined, ts.Diagnostics.Named_property_0_of_types_1_and_2_are_not_identical, symbolToString(prop), typeName1, typeName2); errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.Interface_0_cannot_simultaneously_extend_types_1_and_2, typeToString(type), typeName1, typeName2); diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(typeNode, errorInfo)); } } } } return ok; }
getIndexType:
(type) { return maybeTypeOfKind(type, 540672 /* TypeVariable */) ? getIndexTypeForGenericType(type) : getObjectFlags(type) & 32 /* Mapped */ ? getConstraintTypeFromMappedType(type) : type.flags & 1 /* Any */ || getIndexInfoOfType(type, 0 /* String */) ? stringType : getLiteralTypeFromPropertyNames(type); }
signatureRelatedTo:
(source, target, reportErrors) { return compareSignaturesRelated(source, target, /*ignoreReturnTypes*/ false, reportErrors, reportError, isRelatedTo); }
containsType:
(types, type) { return binarySearchTypes(types, type) >= 0; }
isTypeRelatedTo:
(source, target, relation) { if (source.flags & 96 /* StringOrNumberLiteral */ && source.flags & 1048576 /* FreshLiteral */) { source = source.regularType; } if (target.flags & 96 /* StringOrNumberLiteral */ && target.flags & 1048576 /* FreshLiteral */) { target = target.regularType; } if (source === target || relation !== identityRelation && isSimpleTypeRelatedTo(source, target, relation)) { return true; } if (source.flags & 32768 /* Object */ && target.flags & 32768 /* Object */) { var id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id; var related = relation[id]; if (related !== undefined) { return related === 1 /* Succeeded */; } } if (source.flags & 507904 /* StructuredOrTypeParameter */ || target.flags & 507904 /* StructuredOrTypeParameter */) { return checkTypeRelatedTo(source, target, relation, undefined, undefined, undefined); } return false; }
checkIndexConstraintForProperty:
(prop, propertyType, containingType, indexDeclaration, indexType, indexKind) { if (!indexType) { return; } // index is numeric and property name is not valid numeric literal if (indexKind === 1 /* Number */ && !isNumericName(prop.valueDeclaration.name)) { return; } // perform property check if property or indexer is declared in 'type' // this allows to rule out cases when both property and indexer are inherited from the base class var errorNode; if (prop.valueDeclaration.name.kind === 142 /* ComputedPropertyName */ || prop.parent === containingType.symbol) { errorNode = prop.valueDeclaration; } else if (indexDeclaration) { errorNode = indexDeclaration; } else if (getObjectFlags(containingType) & 2 /* Interface */) { // for interfaces property and indexer might be inherited from different bases // check if any base class already has both property and indexer. // check should be performed only if 'type' is the first type that brings property\x5cindexer together var someBaseClassHasBothPropertyAndIndexer = ts.forEach(getBaseTypes(containingType), function (base) { return getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind); }); errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : containingType.symbol.declarations[0]; } if (errorNode && !isTypeAssignableTo(propertyType, indexType)) { var errorMessage = indexKind === 0 /* String */ ? ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2 : ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2; error(errorNode, errorMessage, symbolToString(prop), typeToString(propertyType), typeToString(indexType)); } }
(prop, propertyType, containingType, indexDeclaration, indexType, indexKind) { if (!indexType) { return; } // index is numeric and property name is not valid numeric literal if (indexKind === 1 /* Number */ && !isNumericName(prop.valueDeclaration.name)) { return; } // perform property check if property or indexer is declared in 'type' // this allows to rule out cases when both property and indexer are inherited from the base class var errorNode; if (prop.valueDeclaration.name.kind === 142 /* ComputedPropertyName */ || prop.parent === containingType.symbol) { errorNode = prop.valueDeclaration; } else if (indexDeclaration) { errorNode = indexDeclaration; } else if (getObjectFlags(containingType) & 2 /* Interface */) { // for interfaces property and indexer might be inherited from different bases // check if any base class already has both property and indexer. // check should be performed only if 'type' is the first type that brings property\x5cindexer together var someBaseClassHasBothPropertyAndIndexer = ts.forEach(getBaseTypes(containingType), function (base) { return getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind); }); errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : containingType.symbol.declarations[0]; } if (errorNode && !isTypeAssignableTo(propertyType, indexType)) { var errorMessage = indexKind === 0 /* String */ ? ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2 : ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2; error(errorNode, errorMessage, symbolToString(prop), typeToString(propertyType), typeToString(indexType)); } }
getTypeFromIndexedAccessTypeNode:
(node) { var links = getNodeLinks(node); if (!links.resolvedType) { links.resolvedType = getIndexedAccessType(getTypeFromTypeNode(node.objectType), getTypeFromTypeNode(node.indexType), node); } return links.resolvedType; }
eachTypeRelatedToType:
(source, target, reportErrors) { var result = -1 /* True */; var sourceTypes = source.types; for (var _i = 0, sourceTypes_2 = sourceTypes; _i < sourceTypes_2.length; _i++) { var sourceType = sourceTypes_2[_i]; var related = isRelatedTo(sourceType, target, reportErrors); if (!related) { return 0 /* False */; } result &= related; } return result; }
isTypeAnyOrAllConstituentTypesHaveKind:
(type, kind) { return isTypeAny(type) || isTypeOfKind(type, kind); }
resolveAnonymousTypeMembers:
(type) { var symbol = type.symbol; if (type.target) { var members = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, /*mappingThisOnly*/ false); var callSignatures = instantiateSignatures(getSignaturesOfType(type.target, 0 /* Call */), type.mapper); var constructSignatures = instantiateSignatures(getSignaturesOfType(type.target, 1 /* Construct */), type.mapper); var stringIndexInfo = instantiateIndexInfo(getIndexInfoOfType(type.target, 0 /* String */), type.mapper); var numberIndexInfo = instantiateIndexInfo(getIndexInfoOfType(type.target, 1 /* Number */), type.mapper); setStructuredTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); } else if (symbol.flags & 2048 /* TypeLiteral */) { var members = symbol.members; var callSignatures = getSignaturesOfSymbol(members["__call"]); var constructSignatures = getSignaturesOfSymbol(members["__new"]); var stringIndexInfo = getIndexInfoOfSymbol(symbol, 0 /* String */); var numberIndexInfo = getIndexInfoOfSymbol(symbol, 1 /* Number */); setStructuredTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); } else { // Combinations of function, class, enum and module var members = emptySymbols; var constructSignatures = emptyArray; if (symbol.flags & 1952 /* HasExports */) { members = getExportsOfSymbol(symbol); } if (symbol.flags & 32 /* Class */) { var classType = getDeclaredTypeOfClassOrInterface(symbol); constructSignatures = getSignaturesOfSymbol(symbol.members["__constructor"]); if (!constructSignatures.length) { constructSignatures = getDefaultConstructSignatures(classType); } var baseConstructorType = getBaseConstructorTypeOfClass(classType); if (baseConstructorType.flags & 32768 /* Object */) { members = createSymbolTable(getNamedMembers(members)); addInheritedMembers(members, getPropertiesOfObjectType(baseConstructorType)); } } var numberIndexInfo = symbol.flags & 384 /* Enum */ ? enumNumberIndexInfo : undefined; setStructuredTypeMembers(type, members, emptyArray, constructSignatures, undefined, numberIndexInfo); // We resolve the members before computing the signatures because a signature may use // typeof with a qualified name expression that circularly references the type we are // in the process of resolving (see issue #6072). The temporarily empty signature list // will never be observed because a qualified name can't reference signatures. if (symbol.flags & (16 /* Function */ | 8192 /* Method */)) { type.callSignatures = getSignaturesOfSymbol(symbol); } } }
(type) { var symbol = type.symbol; if (type.target) { var members = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, /*mappingThisOnly*/ false); var callSignatures = instantiateSignatures(getSignaturesOfType(type.target, 0 /* Call */), type.mapper); var constructSignatures = instantiateSignatures(getSignaturesOfType(type.target, 1 /* Construct */), type.mapper); var stringIndexInfo = instantiateIndexInfo(getIndexInfoOfType(type.target, 0 /* String */), type.mapper); var numberIndexInfo = instantiateIndexInfo(getIndexInfoOfType(type.target, 1 /* Number */), type.mapper); setStructuredTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); } else if (symbol.flags & 2048 /* TypeLiteral */) { var members = symbol.members; var callSignatures = getSignaturesOfSymbol(members["__call"]); var constructSignatures = getSignaturesOfSymbol(members["__new"]); var stringIndexInfo = getIndexInfoOfSymbol(symbol, 0 /* String */); var numberIndexInfo = getIndexInfoOfSymbol(symbol, 1 /* Number */); setStructuredTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); } else { // Combinations of function, class, enum and module var members = emptySymbols; var constructSignatures = emptyArray; if (symbol.flags & 1952 /* HasExports */) { members = getExportsOfSymbol(symbol); } if (symbol.flags & 32 /* Class */) { var classType = getDeclaredTypeOfClassOrInterface(symbol); constructSignatures = getSignaturesOfSymbol(symbol.members["__constructor"]); if (!constructSignatures.length) { constructSignatures = getDefaultConstructSignatures(classType); } var baseConstructorType = getBaseConstructorTypeOfClass(classType); if (baseConstructorType.flags & 32768 /* Object */) { members = createSymbolTable(getNamedMembers(members)); addInheritedMembers(members, getPropertiesOfObjectType(baseConstructorType)); } } var numberIndexInfo = symbol.flags & 384 /* Enum */ ? enumNumberIndexInfo : undefined; setStructuredTypeMembers(type, members, emptyArray, constructSignatures, undefined, numberIndexInfo); // We resolve the members before computing the signatures because a signature may use // typeof with a qualified name expression that circularly references the type we are // in the process of resolving (see issue #6072). The temporarily empty signature list // will never be observed because a qualified name can't reference signatures. if (symbol.flags & (16 /* Function */ | 8192 /* Method */)) { type.callSignatures = getSignaturesOfSymbol(symbol); } } }
(type) { var symbol = type.symbol; if (type.target) { var members = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, /*mappingThisOnly*/ false); var callSignatures = instantiateSignatures(getSignaturesOfType(type.target, 0 /* Call */), type.mapper); var constructSignatures = instantiateSignatures(getSignaturesOfType(type.target, 1 /* Construct */), type.mapper); var stringIndexInfo = instantiateIndexInfo(getIndexInfoOfType(type.target, 0 /* String */), type.mapper); var numberIndexInfo = instantiateIndexInfo(getIndexInfoOfType(type.target, 1 /* Number */), type.mapper); setStructuredTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); } else if (symbol.flags & 2048 /* TypeLiteral */) { var members = symbol.members; var callSignatures = getSignaturesOfSymbol(members["__call"]); var constructSignatures = getSignaturesOfSymbol(members["__new"]); var stringIndexInfo = getIndexInfoOfSymbol(symbol, 0 /* String */); var numberIndexInfo = getIndexInfoOfSymbol(symbol, 1 /* Number */); setStructuredTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); } else { // Combinations of function, class, enum and module var members = emptySymbols; var constructSignatures = emptyArray; if (symbol.flags & 1952 /* HasExports */) { members = getExportsOfSymbol(symbol); } if (symbol.flags & 32 /* Class */) { var classType = getDeclaredTypeOfClassOrInterface(symbol); constructSignatures = getSignaturesOfSymbol(symbol.members["__constructor"]); if (!constructSignatures.length) { constructSignatures = getDefaultConstructSignatures(classType); } var baseConstructorType = getBaseConstructorTypeOfClass(classType); if (baseConstructorType.flags & 32768 /* Object */) { members = createSymbolTable(getNamedMembers(members)); addInheritedMembers(members, getPropertiesOfObjectType(baseConstructorType)); } } var numberIndexInfo = symbol.flags & 384 /* Enum */ ? enumNumberIndexInfo : undefined; setStructuredTypeMembers(type, members, emptyArray, constructSignatures, undefined, numberIndexInfo); // We resolve the members before computing the signatures because a signature may use // typeof with a qualified name expression that circularly references the type we are // in the process of resolving (see issue #6072). The temporarily empty signature list // will never be observed because a qualified name can't reference signatures. if (symbol.flags & (16 /* Function */ | 8192 /* Method */)) { type.callSignatures = getSignaturesOfSymbol(symbol); } } }
checkTypeParameter:
(node) { // Grammar Checking if (node.expression) { grammarErrorOnFirstToken(node.expression, ts.Diagnostics.Type_expected); } checkSourceElement(node.constraint); getConstraintOfTypeParameter(getDeclaredTypeOfTypeParameter(getSymbolOfNode(node))); if (produceDiagnostics) { checkTypeNameIsReserved(node.name, ts.Diagnostics.Type_parameter_name_cannot_be_0); } }
getTypeFromLiteralTypeNode:
(node) { var links = getNodeLinks(node); if (!links.resolvedType) { links.resolvedType = getRegularTypeOfLiteralType(checkExpression(node.literal)); } return links.resolvedType; }
checkLiteralExpression:
(node) { if (node.kind === 8 /* NumericLiteral */) { checkGrammarNumericLiteral(node); } switch (node.kind) { case 9 /* StringLiteral */: return getFreshTypeOfLiteralType(getLiteralTypeForText(32 /* StringLiteral */, node.text)); case 8 /* NumericLiteral */: return getFreshTypeOfLiteralType(getLiteralTypeForText(64 /* NumberLiteral */, node.text)); case 100 /* TrueKeyword */: return trueType; case 85 /* FalseKeyword */: return falseType; } }
isInferentialContext:
(mapper) { return mapper && mapper.context; }
isConstEnumObjectType:
(type) { return getObjectFlags(type) & 16 /* Anonymous */ && type.symbol && isConstEnumSymbol(type.symbol); }
(type) { return getObjectFlags(type) & 16 /* Anonymous */ && type.symbol && isConstEnumSymbol(type.symbol); }
getSignatureFromDeclaration:
(declaration) { var links = getNodeLinks(declaration); if (!links.resolvedSignature) { var parameters = []; var hasLiteralTypes = false; var minArgumentCount = -1; var thisParameter = undefined; var hasThisParameter = void 0; var isJSConstructSignature = ts.isJSDocConstructSignature(declaration); // If this is a JSDoc construct signature, then skip the first parameter in the // parameter list. The first parameter represents the return type of the construct // signature. for (var i = isJSConstructSignature ? 1 : 0, n = declaration.parameters.length; i < n; i++) { var param = declaration.parameters[i]; var paramSymbol = param.symbol; // Include parameter symbol instead of property symbol in the signature if (paramSymbol && !!(paramSymbol.flags & 4 /* Property */) && !ts.isBindingPattern(param.name)) { var resolvedSymbol = resolveName(param, paramSymbol.name, 107455 /* Value */, undefined, undefined); paramSymbol = resolvedSymbol; } if (i === 0 && paramSymbol.name === "this") { hasThisParameter = true; thisParameter = param.symbol; } else { parameters.push(paramSymbol); } if (param.type && param.type.kind === 171 /* LiteralType */) { hasLiteralTypes = true; } if (param.initializer || param.questionToken || param.dotDotDotToken || isJSDocOptionalParameter(param)) { if (minArgumentCount < 0) { minArgumentCount = i - (hasThisParameter ? 1 : 0); } } else { // If we see any required parameters, it means the prior ones were not in fact optional. minArgumentCount = -1; } } // If only one accessor includes a this-type annotation, the other behaves as if it had the same type annotation if ((declaration.kind === 151 /* GetAccessor */ || declaration.kind === 152 /* SetAccessor */) && !ts.hasDynamicName(declaration) && (!hasThisParameter || !thisParameter)) { var otherKind = declaration.kind === 151 /* GetAccessor */ ? 152 /* SetAccessor */ : 151 /* GetAccessor */; var other = ts.getDeclarationOfKind(declaration.symbol, otherKind); if (other) { thisParameter = getAnnotatedAccessorThisParameter(other); } } if (minArgumentCount < 0) { minArgumentCount = declaration.parameters.length - (hasThisParameter ? 1 : 0); } if (isJSConstructSignature) { minArgumentCount--; } var classType = declaration.kind === 150 /* Constructor */ ? getDeclaredTypeOfClassOrInterface(getMergedSymbol(declaration.parent.symbol)) : undefined; var typeParameters = classType ? classType.localTypeParameters : declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : getTypeParametersFromJSDocTemplate(declaration); var returnType = getSignatureReturnTypeFromDeclaration(declaration, isJSConstructSignature, classType); var typePredicate = declaration.type && declaration.type.kind === 156 /* TypePredicate */ ? createTypePredicateFromTypePredicateNode(declaration.type) : undefined; links.resolvedSignature = createSignature(declaration, typeParameters, thisParameter, parameters, returnType, typePredicate, minArgumentCount, ts.hasRestParameter(declaration), hasLiteralTypes); } return links.resolvedSignature; }
getSymbolOfNode:
(node) { return getMergedSymbol(node.symbol); }
createUnaryTypeMapper:
(source, target) { return function (t) { return t === source ? target : t; }; }
checkTypeRelatedTo:
(source, target, relation, errorNode, headMessage, containingMessageChain) { var errorInfo; var sourceStack; var targetStack; var maybeStack; var expandingFlags; var depth = 0; var overflow = false; ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking"); var result = isRelatedTo(source, target, /*reportErrors*/ !!errorNode, headMessage); if (overflow) { error(errorNode, ts.Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target)); } else if (errorInfo) { if (containingMessageChain) { errorInfo = ts.concatenateDiagnosticMessageChains(containingMessageChain, errorInfo); } diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(errorNode, errorInfo)); } return result !== 0 /* False */; function reportError(message, arg0, arg1, arg2) { ts.Debug.assert(!!errorNode); errorInfo = ts.chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); } function reportRelationError(message, source, target) { var sourceType = typeToString(source); var targetType = typeToString(target); if (sourceType === targetType) { sourceType = typeToString(source, /*enclosingDeclaration*/ undefined, 128 /* UseFullyQualifiedType */); targetType = typeToString(target, /*enclosingDeclaration*/ undefined, 128 /* UseFullyQualifiedType */); } if (!message) { if (relation === comparableRelation) { message = ts.Diagnostics.Type_0_is_not_comparable_to_type_1; } else if (sourceType === targetType) { message = ts.Diagnostics.Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated; } else { message = ts.Diagnostics.Type_0_is_not_assignable_to_type_1; } } reportError(message, sourceType, targetType); } function tryElaborateErrorsForPrimitivesAndObjects(source, target) { var sourceType = typeToString(source); var targetType = typeToString(target); if ((globalStringType === source && stringType === target) || (globalNumberType === source && numberType === target) || (globalBooleanType === source && booleanType === target) || (getGlobalESSymbolType() === source && esSymbolType === target)) { reportError(ts.Diagnostics._0_is_a_primitive_but_1_is_a_wrapper_object_Prefer_using_0_when_possible, targetType, sourceType); } } function isUnionOrIntersectionTypeWithoutNullableConstituents(type) { if (!(type.flags & 196608 /* UnionOrIntersection */)) { return false; } // at this point we know that this is union or intersection type possibly with nullable constituents. // check if we still will have compound type if we ignore nullable components. var seenNonNullable = false; for (var _i = 0, _a = type.types; _i < _a.length; _i++) { var t = _a[_i]; if (t.flags & 6144 /* Nullable */) { continue; } if (seenNonNullable) { return true; } seenNonNullable = true; } return false; } // Compare two types and return // Ternary.True if they are related with no assumptions, // Ternary.Maybe if they are related with assumptions of other relationships, or // Ternary.False if they are not related. function isRelatedTo(source, target, reportErrors, headMessage) { var result; if (source.flags & 96 /* StringOrNumberLiteral */ && source.flags & 1048576 /* FreshLiteral */) { source = source.regularType; } if (target.flags & 96 /* StringOrNumberLiteral */ && target.flags & 1048576 /* FreshLiteral */) { target = target.regularType; } // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases if (source === target) return -1 /* True */; if (relation === identityRelation) { return isIdenticalTo(source, target); } if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return -1 /* True */; if (getObjectFlags(source) & 128 /* ObjectLiteral */ && source.flags & 1048576 /* FreshLiteral */) { if (hasExcessProperties(source, target, reportErrors)) { if (reportErrors) { reportRelationError(headMessage, source, target); } return 0 /* False */; } // Above we check for excess properties with respect to the entire target type. When union // and intersection types are further deconstructed on the target side, we don't want to // make the check again (as it might fail for a partial target type). Therefore we obtain // the regular source type and proceed with that. if (isUnionOrIntersectionTypeWithoutNullableConstituents(target)) { source = getRegularTypeOfObjectLiteral(source); } } var saveErrorInfo = errorInfo; // Note that these checks are specifically ordered to produce correct results. In particular, // we need to deconstruct unions before intersections (because unions are always at the top), // and we need to handle "each" relations before "some" relations for the same kind of type. if (source.flags & 65536 /* Union */) { if (relation === comparableRelation) { result = someTypeRelatedToType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */)); } else { result = eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */)); } if (result) { return result; } } else if (target.flags & 65536 /* Union */) { if (result = typeRelatedToSomeType(source, target, reportErrors && !(source.flags & 8190 /* Primitive */) && !(target.flags & 8190 /* Primitive */))) { return result; } } else if (target.flags & 131072 /* Intersection */) { if (result = typeRelatedToEachType(source, target, reportErrors)) { return result; } } else if (source.flags & 131072 /* Intersection */) { // Check to see if any constituents of the intersection are immediately related to the target. // // Don't report errors though. Checking whether a constituent is related to the source is not actually // useful and leads to some confusing error messages. Instead it is better to let the below checks // take care of this, or to not elaborate at all. For instance, // // - For an object type (such as 'C = A & B'), users are usually more interested in structural errors. // // - For a union type (such as '(A | B) = (C & D)'), it's better to hold onto the whole intersection // than to report that 'D' is not assignable to 'A' or 'B'. // // - For a primitive type or type parameter (such as 'number = A & B') there is no point in // breaking the intersection apart. if (result = someTypeRelatedToType(source, target, /*reportErrors*/ false)) { return result; } } else if (target.flags & 16384 /* TypeParameter */) { // A source type { [P in keyof T]: X } is related to a target type T if X is related to T[P]. if (getObjectFlags(source) & 32 /* Mapped */ && getConstraintTypeFromMappedType(source) === getIndexType(target)) { if (!source.declaration.questionToken) { var templateType = getTemplateTypeFromMappedType(source); var indexedAccessType = getIndexedAccessType(target, getTypeParameterFromMappedType(source)); if (result = isRelatedTo(templateType, indexedAccessType, reportErrors)) { return result; } } } else { // Given a type parameter K with a constraint keyof T, a type S is // assignable to K if S is assignable to keyof T. var constraint = getConstraintOfTypeParameter(target); if (constraint && constraint.flags & 262144 /* Index */) { if (result = isRelatedTo(source, constraint, reportErrors)) { return result; } } } } else if (target.flags & 262144 /* Index */) { // A keyof S is related to a keyof T if T is related to S. if (source.flags & 262144 /* Index */) { if (result = isRelatedTo(target.type, source.type, /*reportErrors*/ false)) { return result; } } // Given a type variable T with a constraint C, a type S is assignable to // keyof T if S is assignable to keyof C. if (target.type.flags & 540672 /* TypeVariable */) { var constraint = getConstraintOfTypeVariable(target.type); if (constraint) { if (result = isRelatedTo(source, getIndexType(constraint), reportErrors)) { return result; } } } } else if (target.flags & 524288 /* IndexedAccess */) { // if we have indexed access types with identical index types, see if relationship holds for // the two object types. if (source.flags & 524288 /* IndexedAccess */ && source.indexType === target.indexType) { if (result = isRelatedTo(source.objectType, target.objectType, reportErrors)) { return result; } } // A type S is related to a type T[K] if S is related to A[K], where K is string-like and // A is the apparent type of S. if (target.constraint) { if (result = isRelatedTo(source, target.constraint, reportErrors)) { errorInfo = saveErrorInfo; return result; } } } if (source.flags & 16384 /* TypeParameter */) { // A source type T is related to a target type { [P in keyof T]: X } if T[P] is related to X. if (getObjectFlags(target) & 32 /* Mapped */ && getConstraintTypeFromMappedType(target) === getIndexType(source)) { var indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(target)); var templateType = getTemplateTypeFromMappedType(target); if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) { errorInfo = saveErrorInfo; return result; } } else { var constraint = getConstraintOfTypeParameter(source); if (!constraint || constraint.flags & 1 /* Any */) { constraint = emptyObjectType; } // The constraint may need to be further instantiated with its 'this' type. constraint = getTypeWithThisArgument(constraint, source); // Report constraint errors only if the constraint is not the empty object type var reportConstraintErrors = reportErrors && constraint !== emptyObjectType; if (result = isRelatedTo(constraint, target, reportConstraintErrors)) { errorInfo = saveErrorInfo; return result; } } } else if (source.flags & 524288 /* IndexedAccess */) { // A type S[K] is related to a type T if A[K] is related to T, where K is string-like and // A is the apparent type of S. if (source.constraint) { if (result = isRelatedTo(source.constraint, target, reportErrors)) { errorInfo = saveErrorInfo; return result; } } } else { if (getObjectFlags(source) & 4 /* Reference */ && getObjectFlags(target) & 4 /* Reference */ && source.target === target.target) { // We have type references to same target type, see if relationship holds for all type arguments if (result = typeArgumentsRelatedTo(source, target, reportErrors)) { return result; } } // Even if relationship doesn't hold for unions, intersections, or generic type references, // it may hold in a structural comparison. var apparentSource = getApparentType(source); // In a check of the form X = A & B, we will have previously checked if A relates to X or B relates // to X. Failing both of those we want to check if the aggregation of A and B's members structurally // relates to X. Thus, we include intersection types on the source side here. if (apparentSource.flags & (32768 /* Object */ | 131072 /* Intersection */) && target.flags & 32768 /* Object */) { // Report structural errors only if we haven't reported any errors yet var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo && !(source.flags & 8190 /* Primitive */); if (result = objectTypeRelatedTo(apparentSource, source, target, reportStructuralErrors)) { errorInfo = saveErrorInfo; return result; } } } if (reportErrors) { if (source.flags & 32768 /* Object */ && target.flags & 8190 /* Primitive */) { tryElaborateErrorsForPrimitivesAndObjects(source, target); } else if (source.symbol && source.flags & 32768 /* Object */ && globalObjectType === source) { reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead); } reportRelationError(headMessage, source, target); } return 0 /* False */; } function isIdenticalTo(source, target) { var result; if (source.flags & 32768 /* Object */ && target.flags & 32768 /* Object */) { if (getObjectFlags(source) & 4 /* Reference */ && getObjectFlags(target) & 4 /* Reference */ && source.target === target.target) { // We have type references to same target type, see if all type arguments are identical if (result = typeArgumentsRelatedTo(source, target, /*reportErrors*/ false)) { return result; } } return objectTypeRelatedTo(source, source, target, /*reportErrors*/ false); } if (source.flags & 65536 /* Union */ && target.flags & 65536 /* Union */ || source.flags & 131072 /* Intersection */ && target.flags & 131072 /* Intersection */) { if (result = eachTypeRelatedToSomeType(source, target)) { if (result &= eachTypeRelatedToSomeType(target, source)) { return result; } } } return 0 /* False */; } // Check if a property with the given name is known anywhere in the given type. In an object type, a property // is considered known if the object type is empty and the check is for assignability, if the object type has // index signatures, or if the property is actually declared in the object type. In a union or intersection // type, a property is considered known if it is known in any constituent type. function isKnownProperty(type, name) { if (type.flags & 32768 /* Object */) { var resolved = resolveStructuredTypeMembers(type); if ((relation === assignableRelation || relation === comparableRelation) && (type === globalObjectType || isEmptyObjectType(resolved)) || resolved.stringIndexInfo || (resolved.numberIndexInfo && isNumericLiteralName(name)) || getPropertyOfType(type, name)) { return true; } } else if (type.flags & 196608 /* UnionOrIntersection */) { for (var _i = 0, _a = type.types; _i < _a.length; _i++) { var t = _a[_i]; if (isKnownProperty(t, name)) { return true; } } } return false; } function isEmptyObjectType(t) { return t.properties.length === 0 && t.callSignatures.length === 0 && t.constructSignatures.length === 0 && !t.stringIndexInfo && !t.numberIndexInfo; } function hasExcessProperties(source, target, reportErrors) { if (maybeTypeOfKind(target, 32768 /* Object */) && !(getObjectFlags(target) & 512 /* ObjectLiteralPatternWithComputedProperties */)) { for (var _i = 0, _a = getPropertiesOfObjectType(source); _i < _a.length; _i++) { var prop = _a[_i]; if (!isKnownProperty(target, prop.name)) { if (reportErrors) { // We know *exactly* where things went wrong when comparing the types. // Use this property as the error node as this will be more helpful in // reasoning about what went wrong. ts.Debug.assert(!!errorNode); errorNode = prop.valueDeclaration; reportError(ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target)); } return true; } } } return false; } function eachTypeRelatedToSomeType(source, target) { var result = -1 /* True */; var sourceTypes = source.types; for (var _i = 0, sourceTypes_1 = sourceTypes; _i < sourceTypes_1.length; _i++) { var sourceType = sourceTypes_1[_i]; var related = typeRelatedToSomeType(sourceType, target, /*reportErrors*/ false); if (!related) { return 0 /* False */; } result &= related; } return result; } function typeRelatedToSomeType(source, target, reportErrors) { var targetTypes = target.types; if (target.flags & 65536 /* Union */ && containsType(targetTypes, source)) { return -1 /* True */; } var len = targetTypes.length; for (var i = 0; i < len; i++) { var related = isRelatedTo(source, targetTypes[i], reportErrors && i === len - 1); if (related) { return related; } } return 0 /* False */; } function typeRelatedToEachType(source, target, reportErrors) { var result = -1 /* True */; var targetTypes = target.types; for (var _i = 0, targetTypes_1 = targetTypes; _i < targetTypes_1.length; _i++) { var targetType = targetTypes_1[_i]; var related = isRelatedTo(source, targetType, reportErrors); if (!related) { return 0 /* False */; } result &= related; } return result; } function someTypeRelatedToType(source, target, reportErrors) { var sourceTypes = source.types; if (source.flags & 65536 /* Union */ && containsType(sourceTypes, target)) { return -1 /* True */; } var len = sourceTypes.length; for (var i = 0; i < len; i++) { var related = isRelatedTo(sourceTypes[i], target, reportErrors && i === len - 1); if (related) { return related; } } return 0 /* False */; } function eachTypeRelatedToType(source, target, reportErrors) { var result = -1 /* True */; var sourceTypes = source.types; for (var _i = 0, sourceTypes_2 = sourceTypes; _i < sourceTypes_2.length; _i++) { var sourceType = sourceTypes_2[_i]; var related = isRelatedTo(sourceType, target, reportErrors); if (!related) { return 0 /* False */; } result &= related; } return result; } function typeArgumentsRelatedTo(source, target, reportErrors) { var sources = source.typeArguments || emptyArray; var targets = target.typeArguments || emptyArray; if (sources.length !== targets.length && relation === identityRelation) { return 0 /* False */; } var length = sources.length <= targets.length ? sources.length : targets.length; var result = -1 /* True */; for (var i = 0; i < length; i++) { var related = isRelatedTo(sources[i], targets[i], reportErrors); if (!related) { return 0 /* False */; } result &= related; } 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. function objectTypeRelatedTo(source, originalSource, 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 (reportErrors && related === 2 /* Failed */) { // We are elaborating errors and the cached result is an unreported failure. Record the result as a reported // failure and continue computing the relation such that errors get reported. relation[id] = 3 /* FailedAndReported */; } else { 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] = ts.createMap(); 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 if (isGenericMappedType(source) || isGenericMappedType(target)) { result = mappedTypeRelatedTo(source, target, reportErrors); } 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 &= indexTypesRelatedTo(source, originalSource, target, 0 /* String */, reportErrors); if (result) { result &= indexTypesRelatedTo(source, originalSource, target, 1 /* Number */, 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.copyProperties(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; } // A type [P in S]: X is related to a type [P in T]: Y if T is related to S and X is related to Y. function mappedTypeRelatedTo(source, target, reportErrors) { if (isGenericMappedType(target)) { if (isGenericMappedType(source)) { var result_2; if (relation === identityRelation) { var readonlyMatches = !source.declaration.readonlyToken === !target.declaration.readonlyToken; var optionalMatches = !source.declaration.questionToken === !target.declaration.questionToken; if (readonlyMatches && optionalMatches) { if (result_2 = isRelatedTo(getConstraintTypeFromMappedType(target), getConstraintTypeFromMappedType(source), reportErrors)) { return result_2 & isRelatedTo(getErasedTemplateTypeFromMappedType(source), getErasedTemplateTypeFromMappedType(target), reportErrors); } } } else { if (relation === comparableRelation || !source.declaration.questionToken || target.declaration.questionToken) { if (result_2 = isRelatedTo(getConstraintTypeFromMappedType(target), getConstraintTypeFromMappedType(source), reportErrors)) { return result_2 & isRelatedTo(getTemplateTypeFromMappedType(source), getTemplateTypeFromMappedType(target), reportErrors); } } } } } else if (relation !== identityRelation) { var resolved = resolveStructuredTypeMembers(target); if (isEmptyObjectType(resolved) || resolved.stringIndexInfo && resolved.stringIndexInfo.type.flags & 1 /* Any */) { return -1 /* True */; } } return 0 /* False */; } function propertiesRelatedTo(source, target, reportErrors) { if (relation === identityRelation) { return propertiesIdenticalTo(source, target); } var result = -1 /* True */; var properties = getPropertiesOfObjectType(target); var requireOptionalProperties = relation === subtypeRelation && !(getObjectFlags(source) & 128 /* ObjectLiteral */); for (var _i = 0, properties_3 = properties; _i < properties_3.length; _i++) { var targetProp = properties_3[_i]; var sourceProp = getPropertyOfType(source, targetProp.name); if (sourceProp !== targetProp) { if (!sourceProp) { if (!(targetProp.flags & 536870912 /* Optional */) || requireOptionalProperties) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source)); } return 0 /* False */; } } else if (!(targetProp.flags & 134217728 /* Prototype */)) { var sourcePropFlags = getDeclarationModifierFlagsFromSymbol(sourceProp); var targetPropFlags = getDeclarationModifierFlagsFromSymbol(targetProp); if (sourcePropFlags & 8 /* Private */ || targetPropFlags & 8 /* Private */) { if (sourceProp.valueDeclaration !== targetProp.valueDeclaration) { if (reportErrors) { if (sourcePropFlags & 8 /* Private */ && targetPropFlags & 8 /* Private */) { reportError(ts.Diagnostics.Types_have_separate_declarations_of_a_private_property_0, symbolToString(targetProp)); } else { reportError(ts.Diagnostics.Property_0_is_private_in_type_1_but_not_in_type_2, symbolToString(targetProp), typeToString(sourcePropFlags & 8 /* Private */ ? source : target), typeToString(sourcePropFlags & 8 /* Private */ ? target : source)); } } return 0 /* False */; } } else if (targetPropFlags & 16 /* Protected */) { var sourceDeclaredInClass = sourceProp.parent && sourceProp.parent.flags & 32 /* Class */; var sourceClass = sourceDeclaredInClass ? getDeclaredTypeOfSymbol(getParentOfSymbol(sourceProp)) : undefined; var targetClass = getDeclaredTypeOfSymbol(getParentOfSymbol(targetProp)); if (!sourceClass || !hasBaseType(sourceClass, targetClass)) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2, symbolToString(targetProp), typeToString(sourceClass || source), typeToString(targetClass)); } return 0 /* False */; } } else if (sourcePropFlags & 16 /* Protected */) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_protected_in_type_1_but_public_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target)); } return 0 /* False */; } var related = isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors); if (!related) { if (reportErrors) { reportError(ts.Diagnostics.Types_of_property_0_are_incompatible, symbolToString(targetProp)); } return 0 /* False */; } result &= related; // When checking for comparability, be more lenient with optional properties. if (relation !== comparableRelation && sourceProp.flags & 536870912 /* Optional */ && !(targetProp.flags & 536870912 /* Optional */)) { // TypeScript 1.0 spec (April 2014): 3.8.3 // S is a subtype of a type T, and T is a supertype of S if ... // S' and T are object types and, for each member M in T.. // M is a property and S' contains a property N where // if M is a required property, N is also a required property // (M - property in T) // (N - property in S) if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_optional_in_type_1_but_required_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target)); } return 0 /* False */; } } } } return result; } function propertiesIdenticalTo(source, target) { if (!(source.flags & 32768 /* Object */ && target.flags & 32768 /* Object */)) { return 0 /* False */; } var sourceProperties = getPropertiesOfObjectType(source); var targetProperties = getPropertiesOfObjectType(target); if (sourceProperties.length !== targetProperties.length) { return 0 /* False */; } var result = -1 /* True */; for (var _i = 0, sourceProperties_1 = sourceProperties; _i < sourceProperties_1.length; _i++) { var sourceProp = sourceProperties_1[_i]; var targetProp = getPropertyOfObjectType(target, sourceProp.name); if (!targetProp) { return 0 /* False */; } var related = compareProperties(sourceProp, targetProp, isRelatedTo); if (!related) { return 0 /* False */; } result &= related; } return result; } function signaturesRelatedTo(source, target, kind, reportErrors) { if (relation === identityRelation) { return signaturesIdenticalTo(source, target, kind); } if (target === anyFunctionType || source === anyFunctionType) { return -1 /* True */; } var sourceSignatures = getSignaturesOfType(source, kind); var targetSignatures = getSignaturesOfType(target, kind); if (kind === 1 /* Construct */ && sourceSignatures.length && targetSignatures.length) { if (isAbstractConstructorType(source) && !isAbstractConstructorType(target)) { // An abstract constructor type is not assignable to a non-abstract constructor type // as it would otherwise be possible to new an abstract class. Note that the assignability // check we perform for an extends clause excludes construct signatures from the target, // so this check never proceeds. if (reportErrors) { reportError(ts.Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type); } return 0 /* False */; } if (!constructorVisibilitiesAreCompatible(sourceSignatures[0], targetSignatures[0], reportErrors)) { return 0 /* False */; } } var result = -1 /* True */; var saveErrorInfo = errorInfo; outer: for (var _i = 0, targetSignatures_1 = targetSignatures; _i < targetSignatures_1.length; _i++) { var t = targetSignatures_1[_i]; // Only elaborate errors from the first failure var shouldElaborateErrors = reportErrors; for (var _a = 0, sourceSignatures_1 = sourceSignatures; _a < sourceSignatures_1.length; _a++) { var s = sourceSignatures_1[_a]; var related = signatureRelatedTo(s, t, shouldElaborateErrors); if (related) { result &= related; errorInfo = saveErrorInfo; continue outer; } shouldElaborateErrors = false; } if (shouldElaborateErrors) { reportError(ts.Diagnostics.Type_0_provides_no_match_for_the_signature_1, typeToString(source), signatureToString(t, /*enclosingDeclaration*/ undefined, /*flags*/ undefined, kind)); } return 0 /* False */; } return result; } /** * See signatureAssignableTo, compareSignaturesIdentical */ function signatureRelatedTo(source, target, reportErrors) { return compareSignaturesRelated(source, target, /*ignoreReturnTypes*/ false, reportErrors, reportError, isRelatedTo); } function signaturesIdenticalTo(source, target, kind) { var sourceSignatures = getSignaturesOfType(source, kind); var targetSignatures = getSignaturesOfType(target, kind); if (sourceSignatures.length !== targetSignatures.length) { return 0 /* False */; } var result = -1 /* True */; for (var i = 0, len = sourceSignatures.length; i < len; i++) { var related = compareSignaturesIdentical(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreThisTypes*/ false, /*ignoreReturnTypes*/ false, isRelatedTo); if (!related) { return 0 /* False */; } result &= related; } return result; } function eachPropertyRelatedTo(source, target, kind, reportErrors) { var result = -1 /* True */; for (var _i = 0, _a = getPropertiesOfObjectType(source); _i < _a.length; _i++) { var prop = _a[_i]; if (kind === 0 /* String */ || isNumericLiteralName(prop.name)) { var related = isRelatedTo(getTypeOfSymbol(prop), target, reportErrors); if (!related) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_incompatible_with_index_signature, symbolToString(prop)); } return 0 /* False */; } result &= related; } } return result; } function indexInfoRelatedTo(sourceInfo, targetInfo, reportErrors) { var related = isRelatedTo(sourceInfo.type, targetInfo.type, reportErrors); if (!related && reportErrors) { reportError(ts.Diagnostics.Index_signatures_are_incompatible); } return related; } function indexTypesRelatedTo(source, originalSource, target, kind, reportErrors) { if (relation === identityRelation) { return indexTypesIdenticalTo(source, target, kind); } var targetInfo = getIndexInfoOfType(target, kind); if (!targetInfo || ((targetInfo.type.flags & 1 /* Any */) && !(originalSource.flags & 8190 /* Primitive */))) { // Index signature of type any permits assignment from everything but primitives return -1 /* True */; } var sourceInfo = getIndexInfoOfType(source, kind) || kind === 1 /* Number */ && getIndexInfoOfType(source, 0 /* String */); if (sourceInfo) { return indexInfoRelatedTo(sourceInfo, targetInfo, reportErrors); } if (isObjectLiteralType(source)) { var related = -1 /* True */; if (kind === 0 /* String */) { var sourceNumberInfo = getIndexInfoOfType(source, 1 /* Number */); if (sourceNumberInfo) { related = indexInfoRelatedTo(sourceNumberInfo, targetInfo, reportErrors); } } if (related) { related &= eachPropertyRelatedTo(source, targetInfo.type, kind, reportErrors); } return related; } if (reportErrors) { reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } return 0 /* False */; } function indexTypesIdenticalTo(source, target, indexKind) { var targetInfo = getIndexInfoOfType(target, indexKind); var sourceInfo = getIndexInfoOfType(source, indexKind); if (!sourceInfo && !targetInfo) { return -1 /* True */; } if (sourceInfo && targetInfo && sourceInfo.isReadonly === targetInfo.isReadonly) { return isRelatedTo(sourceInfo.type, targetInfo.type); } return 0 /* False */; } function constructorVisibilitiesAreCompatible(sourceSignature, targetSignature, reportErrors) { if (!sourceSignature.declaration || !targetSignature.declaration) { return true; } var sourceAccessibility = ts.getModifierFlags(sourceSignature.declaration) & 24 /* NonPublicAccessibilityModifier */; var targetAccessibility = ts.getModifierFlags(targetSignature.declaration) & 24 /* NonPublicAccessibilityModifier */; // A public, protected and private signature is assignable to a private signature. if (targetAccessibility === 8 /* Private */) { return true; } // A public and protected signature is assignable to a protected signature. if (targetAccessibility === 16 /* Protected */ && sourceAccessibility !== 8 /* Private */) { return true; } // Only a public signature is assignable to public signature. if (targetAccessibility !== 16 /* Protected */ && !sourceAccessibility) { return true; } if (reportErrors) { reportError(ts.Diagnostics.Cannot_assign_a_0_constructor_type_to_a_1_constructor_type, visibilityToString(sourceAccessibility), visibilityToString(targetAccessibility)); } return false; } }
checkObjectTypeForDuplicateDeclarations:
(node) { var names = ts.createMap(); for (var _i = 0, _a = node.members; _i < _a.length; _i++) { var member = _a[_i]; if (member.kind == 146 /* PropertySignature */) { var memberName = void 0; switch (member.name.kind) { case 9 /* StringLiteral */: case 8 /* NumericLiteral */: case 70 /* Identifier */: memberName = member.name.text; break; default: continue; } if (names[memberName]) { error(member.symbol.valueDeclaration.name, ts.Diagnostics.Duplicate_identifier_0, memberName); error(member.name, ts.Diagnostics.Duplicate_identifier_0, memberName); } else { names[memberName] = true; } } } }
checkFunctionOrConstructorSymbol:
(symbol) { if (!produceDiagnostics) { return; } function getCanonicalOverload(overloads, implementation) { // Consider the canonical set of flags to be the flags of the bodyDeclaration or the first declaration // Error on all deviations from this canonical set of flags // The caveat is that if some overloads are defined in lib.d.ts, we don't want to // report the errors on those. To achieve this, we will say that the implementation is // the canonical signature only if it is in the same container as the first overload var implementationSharesContainerWithFirstOverload = implementation !== undefined && implementation.parent === overloads[0].parent; return implementationSharesContainerWithFirstOverload ? implementation : overloads[0]; } function checkFlagAgreementBetweenOverloads(overloads, implementation, flagsToCheck, someOverloadFlags, allOverloadFlags) { // Error if some overloads have a flag that is not shared by all overloads. To find the // deviations, we XOR someOverloadFlags with allOverloadFlags var someButNotAllOverloadFlags = someOverloadFlags ^ allOverloadFlags; if (someButNotAllOverloadFlags !== 0) { var canonicalFlags_1 = getEffectiveDeclarationFlags(getCanonicalOverload(overloads, implementation), flagsToCheck); ts.forEach(overloads, function (o) { var deviation = getEffectiveDeclarationFlags(o, flagsToCheck) ^ canonicalFlags_1; if (deviation & 1 /* Export */) { error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_exported_or_non_exported); } else if (deviation & 2 /* Ambient */) { error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_ambient_or_non_ambient); } else if (deviation & (8 /* Private */ | 16 /* Protected */)) { error(o.name || o, ts.Diagnostics.Overload_signatures_must_all_be_public_private_or_protected); } else if (deviation & 128 /* Abstract */) { error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_abstract_or_non_abstract); } }); } } function checkQuestionTokenAgreementBetweenOverloads(overloads, implementation, someHaveQuestionToken, allHaveQuestionToken) { if (someHaveQuestionToken !== allHaveQuestionToken) { var canonicalHasQuestionToken_1 = ts.hasQuestionToken(getCanonicalOverload(overloads, implementation)); ts.forEach(overloads, function (o) { var deviation = ts.hasQuestionToken(o) !== canonicalHasQuestionToken_1; if (deviation) { error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_optional_or_required); } }); } } var flagsToCheck = 1 /* Export */ | 2 /* Ambient */ | 8 /* Private */ | 16 /* Protected */ | 128 /* Abstract */; var someNodeFlags = 0 /* None */; var allNodeFlags = flagsToCheck; var someHaveQuestionToken = false; var allHaveQuestionToken = true; var hasOverloads = false; var bodyDeclaration; var lastSeenNonAmbientDeclaration; var previousDeclaration; var declarations = symbol.declarations; var isConstructor = (symbol.flags & 16384 /* Constructor */) !== 0; function reportImplementationExpectedError(node) { if (node.name && ts.nodeIsMissing(node.name)) { return; } var seen = false; var subsequentNode = ts.forEachChild(node.parent, function (c) { if (seen) { return c; } else { seen = c === node; } }); // We may be here because of some extra nodes between overloads that could not be parsed into a valid node. // In this case the subsequent node is not really consecutive (.pos !== node.end), and we must ignore it here. if (subsequentNode && subsequentNode.pos === node.end) { if (subsequentNode.kind === node.kind) { var errorNode_1 = subsequentNode.name || subsequentNode; // TODO(jfreeman): These are methods, so handle computed name case if (node.name && subsequentNode.name && node.name.text === subsequentNode.name.text) { var reportError = (node.kind === 149 /* MethodDeclaration */ || node.kind === 148 /* MethodSignature */) && (ts.getModifierFlags(node) & 32 /* Static */) !== (ts.getModifierFlags(subsequentNode) & 32 /* Static */); // we can get here in two cases // 1. mixed static and instance class members // 2. something with the same name was defined before the set of overloads that prevents them from merging // here we'll report error only for the first case since for second we should already report error in binder if (reportError) { var diagnostic = ts.getModifierFlags(node) & 32 /* Static */ ? ts.Diagnostics.Function_overload_must_be_static : ts.Diagnostics.Function_overload_must_not_be_static; error(errorNode_1, diagnostic); } return; } else if (ts.nodeIsPresent(subsequentNode.body)) { error(errorNode_1, ts.Diagnostics.Function_implementation_name_must_be_0, ts.declarationNameToString(node.name)); return; } } } var errorNode = node.name || node; if (isConstructor) { error(errorNode, ts.Diagnostics.Constructor_implementation_is_missing); } else { // Report different errors regarding non-consecutive blocks of declarations depending on whether // the node in question is abstract. if (ts.getModifierFlags(node) & 128 /* Abstract */) { error(errorNode, ts.Diagnostics.All_declarations_of_an_abstract_method_must_be_consecutive); } else { error(errorNode, ts.Diagnostics.Function_implementation_is_missing_or_not_immediately_following_the_declaration); } } } var duplicateFunctionDeclaration = false; var multipleConstructorImplementation = false; for (var _i = 0, declarations_4 = declarations; _i < declarations_4.length; _i++) { var current = declarations_4[_i]; var node = current; var inAmbientContext = ts.isInAmbientContext(node); var inAmbientContextOrInterface = node.parent.kind === 227 /* InterfaceDeclaration */ || node.parent.kind === 161 /* TypeLiteral */ || inAmbientContext; if (inAmbientContextOrInterface) { // check if declarations are consecutive only if they are non-ambient // 1. ambient declarations can be interleaved // i.e. this is legal // declare function foo(); // declare function bar(); // declare function foo(); // 2. mixing ambient and non-ambient declarations is a separate error that will be reported - do not want to report an extra one previousDeclaration = undefined; } if (node.kind === 225 /* FunctionDeclaration */ || node.kind === 149 /* MethodDeclaration */ || node.kind === 148 /* MethodSignature */ || node.kind === 150 /* Constructor */) { var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck); someNodeFlags |= currentNodeFlags; allNodeFlags &= currentNodeFlags; someHaveQuestionToken = someHaveQuestionToken || ts.hasQuestionToken(node); allHaveQuestionToken = allHaveQuestionToken && ts.hasQuestionToken(node); if (ts.nodeIsPresent(node.body) && bodyDeclaration) { if (isConstructor) { multipleConstructorImplementation = true; } else { duplicateFunctionDeclaration = true; } } else if (previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) { reportImplementationExpectedError(previousDeclaration); } if (ts.nodeIsPresent(node.body)) { if (!bodyDeclaration) { bodyDeclaration = node; } } else { hasOverloads = true; } previousDeclaration = node; if (!inAmbientContextOrInterface) { lastSeenNonAmbientDeclaration = node; } } } if (multipleConstructorImplementation) { ts.forEach(declarations, function (declaration) { error(declaration, ts.Diagnostics.Multiple_constructor_implementations_are_not_allowed); }); } if (duplicateFunctionDeclaration) { ts.forEach(declarations, function (declaration) { error(declaration.name, ts.Diagnostics.Duplicate_function_implementation); }); } // Abstract methods can't have an implementation -- in particular, they don't need one. if (lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body && !(ts.getModifierFlags(lastSeenNonAmbientDeclaration) & 128 /* Abstract */) && !lastSeenNonAmbientDeclaration.questionToken) { reportImplementationExpectedError(lastSeenNonAmbientDeclaration); } if (hasOverloads) { checkFlagAgreementBetweenOverloads(declarations, bodyDeclaration, flagsToCheck, someNodeFlags, allNodeFlags); checkQuestionTokenAgreementBetweenOverloads(declarations, bodyDeclaration, someHaveQuestionToken, allHaveQuestionToken); if (bodyDeclaration) { var signatures = getSignaturesOfSymbol(symbol); var bodySignature = getSignatureFromDeclaration(bodyDeclaration); for (var _a = 0, signatures_3 = signatures; _a < signatures_3.length; _a++) { var signature = signatures_3[_a]; if (!isImplementationCompatibleWithOverload(bodySignature, signature)) { error(signature.declaration, ts.Diagnostics.Overload_signature_is_not_compatible_with_function_implementation); break; } } } } }
getTypeFromTypeOperatorNode:
(node) { var links = getNodeLinks(node); if (!links.resolvedType) { links.resolvedType = getIndexType(getTypeFromTypeNode(node.type)); } return links.resolvedType; }
getTypeParametersFromDeclaration:
(typeParameterDeclarations) { var result = []; ts.forEach(typeParameterDeclarations, function (node) { var tp = getDeclaredTypeOfTypeParameter(node.symbol); if (!ts.contains(result, tp)) { result.push(tp); } }); return result; }
getDeclarationModifierFlagsFromSymbol:
(s) { return s.valueDeclaration ? ts.getCombinedModifierFlags(s.valueDeclaration) : s.flags & 134217728 /* Prototype */ ? 4 /* Public */ | 32 /* Static */ : 0; }
(s) { return s.valueDeclaration ? ts.getCombinedModifierFlags(s.valueDeclaration) : s.flags & 134217728 /* Prototype */ ? 4 /* Public */ | 32 /* Static */ : 0; }
checkIndexedAccessType:
(node) { getTypeFromIndexedAccessTypeNode(node); }
checkGrammarVariableDeclaration:
(node) { if (node.parent.parent.kind !== 212 /* ForInStatement */ && node.parent.parent.kind !== 213 /* ForOfStatement */) { if (ts.isInAmbientContext(node)) { if (node.initializer) { if (ts.isConst(node) && !node.type) { if (!isStringOrNumberLiteralExpression(node.initializer)) { return grammarErrorOnNode(node.initializer, ts.Diagnostics.A_const_initializer_in_an_ambient_context_must_be_a_string_or_numeric_literal); } } else { // Error on equals token which immediate precedes the initializer var equalsTokenLength = "=".length; return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - equalsTokenLength, equalsTokenLength, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); } } if (node.initializer && !(ts.isConst(node) && isStringOrNumberLiteralExpression(node.initializer))) { // Error on equals token which immediate precedes the initializer var equalsTokenLength = "=".length; return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - equalsTokenLength, equalsTokenLength, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); } } else if (!node.initializer) { if (ts.isBindingPattern(node.name) && !ts.isBindingPattern(node.parent)) { return grammarErrorOnNode(node, ts.Diagnostics.A_destructuring_declaration_must_have_an_initializer); } if (ts.isConst(node)) { return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_must_be_initialized); } } } var checkLetConstNames = (ts.isLet(node) || ts.isConst(node)); // 1. LexicalDeclaration : LetOrConst BindingList ; // It is a Syntax Error if the BoundNames of BindingList contains "let". // 2. ForDeclaration: ForDeclaration : LetOrConst ForBinding // It is a Syntax Error if the BoundNames of ForDeclaration contains "let". // It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code // and its Identifier is eval or arguments return checkLetConstNames && checkGrammarNameInLetOrConstDeclarations(node.name); }
getIndexDeclarationOfSymbol:
(symbol, kind) { var syntaxKind = kind === 1 /* Number */ ? 132 /* NumberKeyword */ : 134 /* StringKeyword */; var indexSymbol = getIndexSymbol(symbol); if (indexSymbol) { for (var _i = 0, _a = indexSymbol.declarations; _i < _a.length; _i++) { var decl = _a[_i]; var node = decl; if (node.parameters.length === 1) { var parameter = node.parameters[0]; if (parameter && parameter.type && parameter.type.kind === syntaxKind) { return node; } } } } return undefined; }
checkTypeParameters:
(typeParameterDeclarations) { if (typeParameterDeclarations) { for (var i = 0, n = typeParameterDeclarations.length; i < n; i++) { var node = typeParameterDeclarations[i]; checkTypeParameter(node); if (produceDiagnostics) { for (var j = 0; j < i; j++) { if (typeParameterDeclarations[j].symbol === node.symbol) { error(node.name, ts.Diagnostics.Duplicate_identifier_0, ts.declarationNameToString(node.name)); } } } } } }
checkGrammarDecorators:
(node) { if (!node.decorators) { return false; } if (!ts.nodeCanBeDecorated(node)) { if (node.kind === 149 /* MethodDeclaration */ && !ts.nodeIsPresent(node.body)) { return grammarErrorOnFirstToken(node, ts.Diagnostics.A_decorator_can_only_decorate_a_method_implementation_not_an_overload); } else { return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_are_not_valid_here); } } else if (node.kind === 151 /* GetAccessor */ || node.kind === 152 /* SetAccessor */) { var accessors = ts.getAllAccessorDeclarations(node.parent.members, node); if (accessors.firstAccessor.decorators && node === accessors.secondAccessor) { return grammarErrorOnFirstToken(node, ts.Diagnostics.Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name); } } return false; }
Deopt: <JS Function nodeIsMissing (SharedFunctionInfo 0x2c75c4acca81)> (opt #386) @2, FP to SP delta: 24, caller sp: 0x7fff5fbfda60
Deopt: <JS Function getSymbol (SharedFunctionInfo 0x3fa1587ed239)> (opt #374) @13, FP to SP delta: 40, caller sp: 0x7fff5fbfd8e0
Deopt: <JS Function resolveName (SharedFunctionInfo 0x3fa1587ed479)> (opt #453) @114, FP to SP delta: 320, caller sp: 0x7fff5fbfda60
Deopt: <JS Function needCollisionCheckForIdentifier (SharedFunctionInfo 0x3fca58612181)> (opt #471) @3, FP to SP delta: 32, caller sp: 0x7fff5fbfda58
Deopt: <JS Function getTypeOfSymbol (SharedFunctionInfo 0x3fa1587f2939)> (opt #454) @2, FP to SP delta: 128, caller sp: 0x7fff5fbfdaa8
Deopt: <JS Function getTypeOfVariableOrParameterOrProperty (SharedFunctionInfo 0x3fa1587f21b9)> (opt #390) @16, FP to SP delta: 80, caller sp: 0x7fff5fbfda70
Deopt: <JS Function isConstEnumObjectType (SharedFunctionInfo 0x3fca5860e041)> (opt #502) @4, FP to SP delta: 32, caller sp: 0x7fff5fbfdb90
resolveBaseTypesOfInterface:
(type) { type.resolvedBaseTypes = type.resolvedBaseTypes || emptyArray; for (var _i = 0, _a = type.symbol.declarations; _i < _a.length; _i++) { var declaration = _a[_i]; if (declaration.kind === 227 /* InterfaceDeclaration */ && ts.getInterfaceBaseTypeNodes(declaration)) { for (var _b = 0, _c = ts.getInterfaceBaseTypeNodes(declaration); _b < _c.length; _b++) { var node = _c[_b]; var baseType = getTypeFromTypeNode(node); if (baseType !== unknownType) { if (getObjectFlags(getTargetType(baseType)) & 3 /* ClassOrInterface */) { if (type !== baseType && !hasBaseType(baseType, type)) { if (type.resolvedBaseTypes === emptyArray) { type.resolvedBaseTypes = [baseType]; } else { type.resolvedBaseTypes.push(baseType); } } else { error(declaration, ts.Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, /*enclosingDeclaration*/ undefined, 1 /* WriteArrayAsGenericType */)); } } else { error(node, ts.Diagnostics.An_interface_may_only_extend_a_class_or_another_interface); } } } } } }
createTypeMapper:
(sources, targets) { var count = sources.length; var mapper = count == 1 ? createUnaryTypeMapper(sources[0], targets ? targets[0] : anyType) : count == 2 ? createBinaryTypeMapper(sources[0], targets ? targets[0] : anyType, sources[1], targets ? targets[1] : anyType) : createArrayTypeMapper(sources, targets); mapper.mappedTypes = sources; return mapper; }
reportErrorsFromWidening:
(declaration, type) { if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 2097152 /* ContainsWideningType */) { // Report implicit any error within type if possible, otherwise report error on declaration if (!reportWideningErrorsInType(type)) { reportImplicitAnyError(declaration, type); } } }
Deopt: <JS Function checkVariableStatement (SharedFunctionInfo 0x3fca58612b41)> (opt #465) @18, FP to SP delta: 88, caller sp: 0x7fff5fbfdfe0
Deopt: <JS Function resolveEntityName (SharedFunctionInfo 0x3fa1587ee979)> (opt #402) @37, FP to SP delta: 128, caller sp: 0x7fff5fbfdb50
allowLetAndConstDeclarations:
(parent) { switch (parent.kind) { case 208 /* IfStatement */: case 209 /* DoStatement */: case 210 /* WhileStatement */: case 217 /* WithStatement */: case 211 /* ForStatement */: case 212 /* ForInStatement */: case 213 /* ForOfStatement */: return false; case 219 /* LabeledStatement */: return allowLetAndConstDeclarations(parent.parent); } return true; }
Deopt: <JS Function resolveBaseTypesOfInterface (SharedFunctionInfo 0x3fa1587f3539)> (opt #533) @29, FP to SP delta: 128, caller sp: 0x7fff5fbfddb0
Deopt: <JS Function check (SharedFunctionInfo 0x298f55ec11c1)> (opt #468) @6, FP to SP delta: 64, caller sp: 0x7fff5fbfdd00
Deopt: <JS Function getTargetType (SharedFunctionInfo 0x3fa1587f29f9)> (opt #391) @5, FP to SP delta: 32, caller sp: 0x7fff5fbfdbf8
Deopt: <JS Function getTypeWithThisArgument (SharedFunctionInfo 0x3fa1587f44f9)> (opt #373) @5, FP to SP delta: 144, caller sp: 0x7fff5fbfdf58
isIndependentType:
(node) { switch (node.kind) { case 118 /* AnyKeyword */: case 134 /* StringKeyword */: case 132 /* NumberKeyword */: case 121 /* BooleanKeyword */: case 135 /* SymbolKeyword */: case 104 /* VoidKeyword */: case 137 /* UndefinedKeyword */: case 94 /* NullKeyword */: case 129 /* NeverKeyword */: case 171 /* LiteralType */: return true; case 162 /* ArrayType */: return isIndependentType(node.elementType); case 157 /* TypeReference */: return isIndependentTypeReference(node); } return false; }
(node) { switch (node.kind) { case 118 /* AnyKeyword */: case 134 /* StringKeyword */: case 132 /* NumberKeyword */: case 121 /* BooleanKeyword */: case 135 /* SymbolKeyword */: case 104 /* VoidKeyword */: case 137 /* UndefinedKeyword */: case 94 /* NullKeyword */: case 129 /* NeverKeyword */: case 171 /* LiteralType */: return true; case 162 /* ArrayType */: return isIndependentType(node.elementType); case 157 /* TypeReference */: return isIndependentTypeReference(node); } return false; }
isIndependentVariableLikeDeclaration:
(node) { return node.type && isIndependentType(node.type) || !node.type && !node.initializer; }
Deopt: <JS Function isIndependentType (SharedFunctionInfo 0x3fa1587f3ef9)> (opt #542) @4, FP to SP delta: 24, caller sp: 0x7fff5fbfd8c0
getTypeOfFuncClassEnumModule:
(symbol) { var links = getSymbolLinks(symbol); if (!links.type) { if (symbol.flags & 1536 /* Module */ && ts.isShorthandAmbientModuleSymbol(symbol)) { links.type = anyType; } else { var type = createObjectType(16 /* Anonymous */, symbol); links.type = strictNullChecks && symbol.flags & 536870912 /* Optional */ ? includeFalsyTypes(type, 2048 /* Undefined */) : type; } } return links.type; }
(symbol) { var links = getSymbolLinks(symbol); if (!links.type) { if (symbol.flags & 1536 /* Module */ && ts.isShorthandAmbientModuleSymbol(symbol)) { links.type = anyType; } else { var type = createObjectType(16 /* Anonymous */, symbol); links.type = strictNullChecks && symbol.flags & 536870912 /* Optional */ ? includeFalsyTypes(type, 2048 /* Undefined */) : type; } } return links.type; }
checkVariableLikeDeclaration:
(node) { checkDecorators(node); checkSourceElement(node.type); // For a computed property, just check the initializer and exit // Do not use hasDynamicName here, because that returns false for well known symbols. // We want to perform checkComputedPropertyName for all computed properties, including // well known symbols. if (node.name.kind === 142 /* ComputedPropertyName */) { checkComputedPropertyName(node.name); if (node.initializer) { checkExpressionCached(node.initializer); } } if (node.kind === 174 /* BindingElement */) { if (node.parent.kind === 172 /* ObjectBindingPattern */ && languageVersion < 5 /* ESNext */ && !ts.isInAmbientContext(node)) { checkExternalEmitHelpers(node, 4 /* Rest */); } // check computed properties inside property names of binding elements if (node.propertyName && node.propertyName.kind === 142 /* ComputedPropertyName */) { checkComputedPropertyName(node.propertyName); } // check private/protected variable access var parent_11 = node.parent.parent; var parentType = getTypeForBindingElementParent(parent_11); var name_24 = node.propertyName || node.name; var property = getPropertyOfType(parentType, ts.getTextOfPropertyName(name_24)); markPropertyAsReferenced(property); if (parent_11.initializer && property && getParentOfSymbol(property)) { checkClassPropertyAccess(parent_11, parent_11.initializer, parentType, property); } } // For a binding pattern, check contained binding elements if (ts.isBindingPattern(node.name)) { ts.forEach(node.name.elements, checkSourceElement); } // For a parameter declaration with an initializer, error and exit if the containing function doesn't have a body if (node.initializer && ts.getRootDeclaration(node).kind === 144 /* Parameter */ && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation); return; } // For a binding pattern, validate the initializer and exit if (ts.isBindingPattern(node.name)) { // Don't validate for-in initializer as it is already an error if (node.initializer && node.parent.parent.kind !== 212 /* ForInStatement */) { checkTypeAssignableTo(checkExpressionCached(node.initializer), getWidenedTypeForVariableLikeDeclaration(node), node, /*headMessage*/ undefined); checkParameterInitializer(node); } return; } var symbol = getSymbolOfNode(node); var type = convertAutoToAny(getTypeOfVariableOrParameterOrProperty(symbol)); if (node === symbol.valueDeclaration) { // Node is the primary declaration of the symbol, just validate the initializer // Don't validate for-in initializer as it is already an error if (node.initializer && node.parent.parent.kind !== 212 /* ForInStatement */) { checkTypeAssignableTo(checkExpressionCached(node.initializer), type, node, /*headMessage*/ undefined); checkParameterInitializer(node); } } else { // Node is a secondary declaration, check that type is identical to primary declaration and check that // initializer is consistent with type associated with the node var declarationType = convertAutoToAny(getWidenedTypeForVariableLikeDeclaration(node)); if (type !== unknownType && declarationType !== unknownType && !isTypeIdenticalTo(type, declarationType)) { error(node.name, ts.Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2, ts.declarationNameToString(node.name), typeToString(type), typeToString(declarationType)); } if (node.initializer) { checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, /*headMessage*/ undefined); } if (!areDeclarationFlagsIdentical(node, symbol.valueDeclaration)) { error(symbol.valueDeclaration.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); error(node.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); } } if (node.kind !== 147 /* PropertyDeclaration */ && node.kind !== 146 /* PropertySignature */) { // We know we don't have a binding pattern or computed name here checkExportsOnMergedDeclarations(node); if (node.kind === 223 /* VariableDeclaration */ || node.kind === 174 /* BindingElement */) { checkVarDeclaredNamesNotShadowed(node); } checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } }
(node) { checkDecorators(node); checkSourceElement(node.type); // For a computed property, just check the initializer and exit // Do not use hasDynamicName here, because that returns false for well known symbols. // We want to perform checkComputedPropertyName for all computed properties, including // well known symbols. if (node.name.kind === 142 /* ComputedPropertyName */) { checkComputedPropertyName(node.name); if (node.initializer) { checkExpressionCached(node.initializer); } } if (node.kind === 174 /* BindingElement */) { if (node.parent.kind === 172 /* ObjectBindingPattern */ && languageVersion < 5 /* ESNext */ && !ts.isInAmbientContext(node)) { checkExternalEmitHelpers(node, 4 /* Rest */); } // check computed properties inside property names of binding elements if (node.propertyName && node.propertyName.kind === 142 /* ComputedPropertyName */) { checkComputedPropertyName(node.propertyName); } // check private/protected variable access var parent_11 = node.parent.parent; var parentType = getTypeForBindingElementParent(parent_11); var name_24 = node.propertyName || node.name; var property = getPropertyOfType(parentType, ts.getTextOfPropertyName(name_24)); markPropertyAsReferenced(property); if (parent_11.initializer && property && getParentOfSymbol(property)) { checkClassPropertyAccess(parent_11, parent_11.initializer, parentType, property); } } // For a binding pattern, check contained binding elements if (ts.isBindingPattern(node.name)) { ts.forEach(node.name.elements, checkSourceElement); } // For a parameter declaration with an initializer, error and exit if the containing function doesn't have a body if (node.initializer && ts.getRootDeclaration(node).kind === 144 /* Parameter */ && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation); return; } // For a binding pattern, validate the initializer and exit if (ts.isBindingPattern(node.name)) { // Don't validate for-in initializer as it is already an error if (node.initializer && node.parent.parent.kind !== 212 /* ForInStatement */) { checkTypeAssignableTo(checkExpressionCached(node.initializer), getWidenedTypeForVariableLikeDeclaration(node), node, /*headMessage*/ undefined); checkParameterInitializer(node); } return; } var symbol = getSymbolOfNode(node); var type = convertAutoToAny(getTypeOfVariableOrParameterOrProperty(symbol)); if (node === symbol.valueDeclaration) { // Node is the primary declaration of the symbol, just validate the initializer // Don't validate for-in initializer as it is already an error if (node.initializer && node.parent.parent.kind !== 212 /* ForInStatement */) { checkTypeAssignableTo(checkExpressionCached(node.initializer), type, node, /*headMessage*/ undefined); checkParameterInitializer(node); } } else { // Node is a secondary declaration, check that type is identical to primary declaration and check that // initializer is consistent with type associated with the node var declarationType = convertAutoToAny(getWidenedTypeForVariableLikeDeclaration(node)); if (type !== unknownType && declarationType !== unknownType && !isTypeIdenticalTo(type, declarationType)) { error(node.name, ts.Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2, ts.declarationNameToString(node.name), typeToString(type), typeToString(declarationType)); } if (node.initializer) { checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, /*headMessage*/ undefined); } if (!areDeclarationFlagsIdentical(node, symbol.valueDeclaration)) { error(symbol.valueDeclaration.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); error(node.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); } } if (node.kind !== 147 /* PropertyDeclaration */ && node.kind !== 146 /* PropertySignature */) { // We know we don't have a binding pattern or computed name here checkExportsOnMergedDeclarations(node); if (node.kind === 223 /* VariableDeclaration */ || node.kind === 174 /* BindingElement */) { checkVarDeclaredNamesNotShadowed(node); } checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } }
getContainingFunction:
(node) { while (true) { node = node.parent; if (!node || isFunctionLike(node)) { return node; } } }
getTypeForVariableLikeDeclaration:
(declaration, includeOptionality) { if (declaration.flags & 65536 /* JavaScriptFile */) { // If this is a variable in a JavaScript file, then use the JSDoc type (if it has // one as its type), otherwise fallback to the below standard TS codepaths to // try to figure it out. var type = getTypeForVariableLikeDeclarationFromJSDocComment(declaration); if (type && type !== unknownType) { return type; } } // A variable declared in a for..in statement is of type string, or of type keyof T when the // right hand expression is of a type parameter type. if (declaration.parent.parent.kind === 212 /* ForInStatement */) { var indexType = getIndexType(checkNonNullExpression(declaration.parent.parent.expression)); return indexType.flags & (16384 /* TypeParameter */ | 262144 /* Index */) ? indexType : stringType; } if (declaration.parent.parent.kind === 213 /* 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 addOptionality(getTypeFromTypeNode(declaration.type), /*optional*/ declaration.questionToken && includeOptionality); } if ((compilerOptions.noImplicitAny || declaration.flags & 65536 /* JavaScriptFile */) && declaration.kind === 223 /* VariableDeclaration */ && !ts.isBindingPattern(declaration.name) && !(ts.getCombinedModifierFlags(declaration) & 1 /* Export */) && !ts.isInAmbientContext(declaration)) { // If --noImplicitAny is on or the declaration is in a Javascript file, // use control flow tracked 'any' type for non-ambient, non-exported var or let variables with no // initializer or a 'null' or 'undefined' initializer. if (!(ts.getCombinedNodeFlags(declaration) & 2 /* Const */) && (!declaration.initializer || isNullOrUndefined(declaration.initializer))) { return autoType; } // Use control flow tracked 'any[]' type for non-ambient, non-exported variables with an empty array // literal initializer. if (declaration.initializer && isEmptyArrayLiteral(declaration.initializer)) { return autoArrayType; } } if (declaration.kind === 144 /* 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 === 152 /* SetAccessor */ && !ts.hasDynamicName(func)) { var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 151 /* GetAccessor */); if (getter) { var getterSignature = getSignatureFromDeclaration(getter); var thisParameter = getAccessorThisParameter(func); if (thisParameter && declaration === thisParameter) { // Use the type from the *getter* ts.Debug.assert(!thisParameter.type); return getTypeOfSymbol(getterSignature.thisParameter); } return getReturnTypeOfSignature(getterSignature); } } // Use contextual parameter type if one is available var type = void 0; if (declaration.symbol.name === "this") { type = getContextualThisParameterType(func); } else { type = getContextuallyTypedParameterType(declaration); } if (type) { return addOptionality(type, /*optional*/ declaration.questionToken && includeOptionality); } } // Use the type of the initializer expression if one is present if (declaration.initializer) { var type = checkDeclarationInitializer(declaration); return addOptionality(type, /*optional*/ declaration.questionToken && includeOptionality); } // If it is a short-hand property assignment, use the type of the identifier if (declaration.kind === 258 /* 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, /*reportErrors*/ true); } // No type specified and nothing can be inferred return undefined; }
checkFunctionDeclaration:
(node) { if (produceDiagnostics) { checkFunctionOrMethodDeclaration(node) || checkGrammarForGenerator(node); checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } }
getPropertyOfObjectType:
(type, name) { if (type.flags & 32768 /* Object */) { var resolved = resolveStructuredTypeMembers(type); var symbol = resolved.members[name]; if (symbol && symbolIsValue(symbol)) { return symbol; } } }
(type, name) { if (type.flags & 32768 /* Object */) { var resolved = resolveStructuredTypeMembers(type); var symbol = resolved.members[name]; if (symbol && symbolIsValue(symbol)) { return symbol; } } }
checkArrayType:
(node) { checkSourceElement(node.elementType); }
instantiateList:
(items, mapper, instantiator) { if (items && items.length) { var result = []; for (var _i = 0, items_1 = items; _i < items_1.length; _i++) { var v = items_1[_i]; result.push(instantiator(v, mapper)); } return result; } return items; }
isSymbolInScopeOfMappedTypeParameter:
(symbol, mapper) { if (!(symbol.declarations && symbol.declarations.length)) { return false; } var mappedTypes = mapper.mappedTypes; // Starting with the parent of the symbol's declaration, check if the mapper maps any of // the type parameters introduced by enclosing declarations. We just pick the first // declaration since multiple declarations will all have the same parent anyway. var node = symbol.declarations[0]; while (node) { switch (node.kind) { case 158 /* FunctionType */: case 159 /* ConstructorType */: case 225 /* FunctionDeclaration */: case 149 /* MethodDeclaration */: case 148 /* MethodSignature */: case 150 /* Constructor */: case 153 /* CallSignature */: case 154 /* ConstructSignature */: case 155 /* IndexSignature */: case 151 /* GetAccessor */: case 152 /* SetAccessor */: case 184 /* FunctionExpression */: case 185 /* ArrowFunction */: case 226 /* ClassDeclaration */: case 197 /* ClassExpression */: case 227 /* InterfaceDeclaration */: case 228 /* TypeAliasDeclaration */: var declaration = node; if (declaration.typeParameters) { for (var _i = 0, _a = declaration.typeParameters; _i < _a.length; _i++) { var d = _a[_i]; if (ts.contains(mappedTypes, getDeclaredTypeOfTypeParameter(getSymbolOfNode(d)))) { return true; } } } if (ts.isClassLike(node) || node.kind === 227 /* InterfaceDeclaration */) { var thisType = getDeclaredTypeOfClassOrInterface(getSymbolOfNode(node)).thisType; if (thisType && ts.contains(mappedTypes, thisType)) { return true; } } break; case 274 /* JSDocFunctionType */: var func = node; for (var _b = 0, _c = func.parameters; _b &lt; _c.length; _b++) { var p = _c[_b]; if (ts.contains(mappedTypes, getTypeOfNode(p))) { return true; } } break; case 230 /* ModuleDeclaration */: case 261 /* SourceFile */: return false; } node = node.parent; } return false; }
createInstantiatedSymbolTable:
(symbols, mapper, mappingThisOnly) { var result = ts.createMap(); for (var _i = 0, symbols_2 = symbols; _i < symbols_2.length; _i++) { var symbol = symbols_2[_i]; result[symbol.name] = mappingThisOnly && isIndependentMember(symbol) ? symbol : instantiateSymbol(symbol, mapper); } return result; }
Deopt: <JS Function checkSourceElement (SharedFunctionInfo 0x3fca58615911)> (opt #585) @44, FP to SP delta: 200, caller sp: 0x7fff5fbfdf48
Deopt: <JS Function checkSourceElement (SharedFunctionInfo 0x3fca58615911)> (opt #585) @16, FP to SP delta: 200, caller sp: 0x7fff5fbfe0c0
getTargetSymbol:
(s) { // if symbol is instantiated its flags are not copied from the 'target' // so we'll need to get back original 'target' symbol to work with correct set of flags return s.flags & 16777216 /* Instantiated */ ? getSymbolLinks(s).target : s; }
getObjectFlags:
(type) { return type.flags & 32768 /* Object */ ? type.objectFlags : 0; }
getClassLikeDeclarationOfSymbol:
(symbol) { return ts.forEach(symbol.declarations, function (d) { return ts.isClassLike(d) ? d : undefined; }); }
Deopt: <JS Function checkFunctionOrMethodDeclaration (SharedFunctionInfo 0x3fca586117c1)> (opt #602) @33, FP to SP delta: 160, caller sp: 0x7fff5fbfdc60
Deopt: <JS Function propertiesRelatedTo (SharedFunctionInfo 0x298f55ec25f1)> (opt #636) @22, FP to SP delta: 152, caller sp: 0x7fff5fbfd568
getDeclarationOfKind:
(symbol, kind) { var declarations = symbol.declarations; if (declarations) { for (var _i = 0, declarations_1 = declarations; _i < declarations_1.length; _i++) { var declaration = declarations_1[_i]; if (declaration.kind === kind) { return declaration; } } } return undefined; }
checkGrammarModifiers:
(node) { var quickResult = reportObviousModifierErrors(node); if (quickResult !== undefined) { return quickResult; } var lastStatic, lastPrivate, lastProtected, lastDeclare, lastAsync, lastReadonly; var flags = 0 /* None */; for (var _i = 0, _a = node.modifiers; _i < _a.length; _i++) { var modifier = _a[_i]; if (modifier.kind !== 130 /* ReadonlyKeyword */) { if (node.kind === 146 /* PropertySignature */ || node.kind === 148 /* MethodSignature */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_type_member, ts.tokenToString(modifier.kind)); } if (node.kind === 155 /* IndexSignature */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_an_index_signature, ts.tokenToString(modifier.kind)); } } switch (modifier.kind) { case 75 /* ConstKeyword */: if (node.kind !== 229 /* EnumDeclaration */ && node.parent.kind === 226 /* ClassDeclaration */) { return grammarErrorOnNode(node, ts.Diagnostics.A_class_member_cannot_have_the_0_keyword, ts.tokenToString(75 /* ConstKeyword */)); } break; case 113 /* PublicKeyword */: case 112 /* ProtectedKeyword */: case 111 /* PrivateKeyword */: var text = visibilityToString(ts.modifierToFlag(modifier.kind)); if (modifier.kind === 112 /* ProtectedKeyword */) { lastProtected = modifier; } else if (modifier.kind === 111 /* PrivateKeyword */) { lastPrivate = modifier; } if (flags & 28 /* AccessibilityModifier */) { return grammarErrorOnNode(modifier, ts.Diagnostics.Accessibility_modifier_already_seen); } else if (flags & 32 /* Static */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "static"); } else if (flags & 64 /* Readonly */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "readonly"); } else if (flags & 256 /* Async */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "async"); } else if (node.parent.kind === 231 /* ModuleBlock */ || node.parent.kind === 261 /* SourceFile */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_or_namespace_element, text); } else if (flags & 128 /* Abstract */) { if (modifier.kind === 111 /* PrivateKeyword */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, text, "abstract"); } else { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "abstract"); } } flags |= ts.modifierToFlag(modifier.kind); break; case 114 /* StaticKeyword */: if (flags & 32 /* Static */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static"); } else if (flags & 64 /* Readonly */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "static", "readonly"); } else if (flags & 256 /* Async */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "static", "async"); } else if (node.parent.kind === 231 /* ModuleBlock */ || node.parent.kind === 261 /* SourceFile */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_or_namespace_element, "static"); } else if (node.kind === 144 /* Parameter */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static"); } else if (flags & 128 /* Abstract */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "static", "abstract"); } flags |= 32 /* Static */; lastStatic = modifier; break; case 130 /* ReadonlyKeyword */: if (flags & 64 /* Readonly */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "readonly"); } else if (node.kind !== 147 /* PropertyDeclaration */ && node.kind !== 146 /* PropertySignature */ && node.kind !== 155 /* IndexSignature */ && node.kind !== 144 /* Parameter */) { // If node.kind === SyntaxKind.Parameter, checkParameter report an error if it's not a parameter property. return grammarErrorOnNode(modifier, ts.Diagnostics.readonly_modifier_can_only_appear_on_a_property_declaration_or_index_signature); } flags |= 64 /* Readonly */; lastReadonly = modifier; break; case 83 /* ExportKeyword */: if (flags & 1 /* Export */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "export"); } else if (flags & 2 /* Ambient */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "declare"); } else if (flags & 128 /* Abstract */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "abstract"); } else if (flags & 256 /* Async */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "async"); } else if (node.parent.kind === 226 /* ClassDeclaration */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export"); } else if (node.kind === 144 /* Parameter */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export"); } flags |= 1 /* Export */; break; case 123 /* DeclareKeyword */: if (flags & 2 /* Ambient */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare"); } else if (flags & 256 /* Async */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async"); } else if (node.parent.kind === 226 /* ClassDeclaration */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare"); } else if (node.kind === 144 /* Parameter */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare"); } else if (ts.isInAmbientContext(node.parent) && node.parent.kind === 231 /* ModuleBlock */) { return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context); } flags |= 2 /* Ambient */; lastDeclare = modifier; break; case 116 /* AbstractKeyword */: if (flags & 128 /* Abstract */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "abstract"); } if (node.kind !== 226 /* ClassDeclaration */) { if (node.kind !== 149 /* MethodDeclaration */ && node.kind !== 147 /* PropertyDeclaration */ && node.kind !== 151 /* GetAccessor */ && node.kind !== 152 /* SetAccessor */) { return grammarErrorOnNode(modifier, ts.Diagnostics.abstract_modifier_can_only_appear_on_a_class_method_or_property_declaration); } if (!(node.parent.kind === 226 /* ClassDeclaration */ && ts.getModifierFlags(node.parent) & 128 /* Abstract */)) { return grammarErrorOnNode(modifier, ts.Diagnostics.Abstract_methods_can_only_appear_within_an_abstract_class); } if (flags & 32 /* Static */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "static", "abstract"); } if (flags & 8 /* Private */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "private", "abstract"); } } flags |= 128 /* Abstract */; break; case 119 /* AsyncKeyword */: if (flags & 256 /* Async */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "async"); } else if (flags & 2 /* Ambient */ || ts.isInAmbientContext(node.parent)) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async"); } else if (node.kind === 144 /* Parameter */) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "async"); } flags |= 256 /* Async */; lastAsync = modifier; break; } } if (node.kind === 150 /* Constructor */) { if (flags & 32 /* Static */) { return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static"); } if (flags & 128 /* Abstract */) { return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "abstract"); } else if (flags & 256 /* Async */) { return grammarErrorOnNode(lastAsync, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "async"); } else if (flags & 64 /* Readonly */) { return grammarErrorOnNode(lastReadonly, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "readonly"); } return; } else if ((node.kind === 235 /* ImportDeclaration */ || node.kind === 234 /* ImportEqualsDeclaration */) && flags & 2 /* Ambient */) { return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_0_modifier_cannot_be_used_with_an_import_declaration, "declare"); } else if (node.kind === 144 /* Parameter */ && (flags & 92 /* ParameterPropertyModifier */) && ts.isBindingPattern(node.name)) { return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_may_not_be_declared_using_a_binding_pattern); } else if (node.kind === 144 /* Parameter */ && (flags & 92 /* ParameterPropertyModifier */) && node.dotDotDotToken) { return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_cannot_be_declared_using_a_rest_parameter); } if (flags & 256 /* Async */) { return checkGrammarAsyncModifier(node, lastAsync); } }
native string.js
substring:
(L,M){ if((%IS_VAR(this)===null)||(this===(void 0)))throw %make_type_error(17,"String.prototype.subString"); var p=(%_ToString(this)); var Z=p.length; var aa=(%_ToInteger(L)); if(aa<0){ aa=0; }else if(aa>Z){ aa=Z; } var ab=Z; if(!(M===(void 0))){ ab=(%_ToInteger(M)); if(ab>Z){ ab=Z; }else{ if(ab<0)ab=0; if(aa>ab){ var ah=ab; ab=aa; aa=ah; } } } return %_SubString(p,aa,ab); }
slice:
(L,M){ if((%IS_VAR(this)===null)||(this===(void 0)))throw %make_type_error(17,"String.prototype.slice"); var p=(%_ToString(this)); var Z=p.length; var aa=(%_ToInteger(L)); var ab=Z; if(!(M===(void 0))){ ab=(%_ToInteger(M)); } if(aa<0){ aa+=Z; if(aa&lt;0){ aa=0; } }else{ if(aa>Z){ return''; } } if(ab<0){ ab+=Z; if(ab<0){ return''; } }else{ if(ab>Z){ ab=Z; } } if(ab<=aa){ return''; } return %_SubString(p,aa,ab); }
lastIndexOf:
(w,x){ if((%IS_VAR(this)===null)||(this===(void 0)))throw %make_type_error(17,"String.prototype.lastIndexOf"); var y=(%_ToString(this)); var z=y.length; var w=(%_ToString(w)); var A=w.length; var v=z-A; var t=(%_ToNumber(x)); if(!(!%_IsSmi(%IS_VAR(t))&&!(t==t))){ t=(%_ToInteger(t)); if(t<0){ t=0; } if(t+A<z){ v=t; } } if(v<0){ return-1; } return %StringLastIndexOf(y,w,v); }
native array.js
ConvertToString:
(A,O){ if((O==null))return''; return(%_ToString(A?O.toLocaleString():O)); }
join:
(B){ if((%IS_VAR(this)===null)||(this===(void 0)))throw %make_type_error(17,"Array.prototype.join"); var q=(%_ToObject(this)); var r=(%_ToLength(q.length)); return InnerArrayJoin(B,q,r); }
InnerArrayJoin:
(B,q,r){ if((B===(void 0))){ B=','; }else{ B=(%_ToString(B)); } if(r===1){ var z=q[0]; if((z==null))return''; return(%_ToString(z)); } return Join(q,r,B,false); }
StackPush:
(J,K){ J.values[J.length++]=K; }
UseSparseVariant:
(q,r,F,G){ if(!F||r<1000||%HasComplexElements(q)){ return false; } if(!%_IsSmi(r)){ return true; } var H=r>>2; var I=%EstimateNumberOfElements(q); return(I&lt;H)&& (G>I*4); }
StackPop:
(J){ J.values[--J.length]=null }
DoJoin:
(q,r,F,B,A){ if(UseSparseVariant(q,r,F,r)){ %NormalizeElements(q); var x=GetSortedArrayKeys(q,%GetArrayKeys(q,r)); if(B===''){ if(x.length===0)return''; return SparseJoin(q,x,A); }else{ return SparseJoinWithSeparatorJS( q,x,r,A,B); } } if(r===1){ return ConvertToString(A,q[0]); } var D=new g(r); for(var y=0;y<r;y++){ D[y]=ConvertToString(A,q[y]); } if(B===''){ return %StringBuilderConcat(D,r,''); }else{ return %StringBuilderJoin(D,r,B); } }
Deopt: <JS Function parseTypeWorker (SharedFunctionInfo 0x2c75c4af81d9)> (opt #141) @18, FP to SP delta: 224, caller sp: 0x7fff5fbfdab8
Deopt: <JS Function parseTypeWorker (SharedFunctionInfo 0x2c75c4af81d9)> (opt #141) @90, FP to SP delta: 224, caller sp: 0x7fff5fbfdd58
Deopt: <JS Function skipParameterStart (SharedFunctionInfo 0x2c75c4af7e19)> (opt #105) @10, FP to SP delta: 40, caller sp: 0x7fff5fbfd648
native regexp.js
RegExpSubclassExec:
(B,C,Q){ if((Q===(void 0))){ Q=B.exec; } if((typeof(Q)==='function')){ var J=%_Call(Q,B,C); if(!(%_IsJSReceiver(J))&&!(J===null)){ throw %make_type_error(48); } return J; } return %_Call(RegExpExecJS,B,C); }