Skip to content

Instantly share code, notes, and snippets.

@robwormald
Created September 14, 2015 21:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save robwormald/8bae937e25146b4ee36a to your computer and use it in GitHub Desktop.
Save robwormald/8bae937e25146b4ee36a to your computer and use it in GitHub Desktop.
This file has been truncated, but you can view the full file.
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
var ts;
(function (ts) {
// token > SyntaxKind.Identifer => token is a keyword
// Also, If you add a new SyntaxKind be sure to keep the `Markers` section at the bottom in sync
(function (SyntaxKind) {
SyntaxKind[SyntaxKind["Unknown"] = 0] = "Unknown";
SyntaxKind[SyntaxKind["EndOfFileToken"] = 1] = "EndOfFileToken";
SyntaxKind[SyntaxKind["SingleLineCommentTrivia"] = 2] = "SingleLineCommentTrivia";
SyntaxKind[SyntaxKind["MultiLineCommentTrivia"] = 3] = "MultiLineCommentTrivia";
SyntaxKind[SyntaxKind["NewLineTrivia"] = 4] = "NewLineTrivia";
SyntaxKind[SyntaxKind["WhitespaceTrivia"] = 5] = "WhitespaceTrivia";
// We detect and preserve #! on the first line
SyntaxKind[SyntaxKind["ShebangTrivia"] = 6] = "ShebangTrivia";
// We detect and provide better error recovery when we encounter a git merge marker. This
// allows us to edit files with git-conflict markers in them in a much more pleasant manner.
SyntaxKind[SyntaxKind["ConflictMarkerTrivia"] = 7] = "ConflictMarkerTrivia";
// Literals
SyntaxKind[SyntaxKind["NumericLiteral"] = 8] = "NumericLiteral";
SyntaxKind[SyntaxKind["StringLiteral"] = 9] = "StringLiteral";
SyntaxKind[SyntaxKind["RegularExpressionLiteral"] = 10] = "RegularExpressionLiteral";
SyntaxKind[SyntaxKind["NoSubstitutionTemplateLiteral"] = 11] = "NoSubstitutionTemplateLiteral";
// Pseudo-literals
SyntaxKind[SyntaxKind["TemplateHead"] = 12] = "TemplateHead";
SyntaxKind[SyntaxKind["TemplateMiddle"] = 13] = "TemplateMiddle";
SyntaxKind[SyntaxKind["TemplateTail"] = 14] = "TemplateTail";
// Punctuation
SyntaxKind[SyntaxKind["OpenBraceToken"] = 15] = "OpenBraceToken";
SyntaxKind[SyntaxKind["CloseBraceToken"] = 16] = "CloseBraceToken";
SyntaxKind[SyntaxKind["OpenParenToken"] = 17] = "OpenParenToken";
SyntaxKind[SyntaxKind["CloseParenToken"] = 18] = "CloseParenToken";
SyntaxKind[SyntaxKind["OpenBracketToken"] = 19] = "OpenBracketToken";
SyntaxKind[SyntaxKind["CloseBracketToken"] = 20] = "CloseBracketToken";
SyntaxKind[SyntaxKind["DotToken"] = 21] = "DotToken";
SyntaxKind[SyntaxKind["DotDotDotToken"] = 22] = "DotDotDotToken";
SyntaxKind[SyntaxKind["SemicolonToken"] = 23] = "SemicolonToken";
SyntaxKind[SyntaxKind["CommaToken"] = 24] = "CommaToken";
SyntaxKind[SyntaxKind["LessThanToken"] = 25] = "LessThanToken";
SyntaxKind[SyntaxKind["LessThanSlashToken"] = 26] = "LessThanSlashToken";
SyntaxKind[SyntaxKind["GreaterThanToken"] = 27] = "GreaterThanToken";
SyntaxKind[SyntaxKind["LessThanEqualsToken"] = 28] = "LessThanEqualsToken";
SyntaxKind[SyntaxKind["GreaterThanEqualsToken"] = 29] = "GreaterThanEqualsToken";
SyntaxKind[SyntaxKind["EqualsEqualsToken"] = 30] = "EqualsEqualsToken";
SyntaxKind[SyntaxKind["ExclamationEqualsToken"] = 31] = "ExclamationEqualsToken";
SyntaxKind[SyntaxKind["EqualsEqualsEqualsToken"] = 32] = "EqualsEqualsEqualsToken";
SyntaxKind[SyntaxKind["ExclamationEqualsEqualsToken"] = 33] = "ExclamationEqualsEqualsToken";
SyntaxKind[SyntaxKind["EqualsGreaterThanToken"] = 34] = "EqualsGreaterThanToken";
SyntaxKind[SyntaxKind["PlusToken"] = 35] = "PlusToken";
SyntaxKind[SyntaxKind["MinusToken"] = 36] = "MinusToken";
SyntaxKind[SyntaxKind["AsteriskToken"] = 37] = "AsteriskToken";
SyntaxKind[SyntaxKind["SlashToken"] = 38] = "SlashToken";
SyntaxKind[SyntaxKind["PercentToken"] = 39] = "PercentToken";
SyntaxKind[SyntaxKind["PlusPlusToken"] = 40] = "PlusPlusToken";
SyntaxKind[SyntaxKind["MinusMinusToken"] = 41] = "MinusMinusToken";
SyntaxKind[SyntaxKind["LessThanLessThanToken"] = 42] = "LessThanLessThanToken";
SyntaxKind[SyntaxKind["GreaterThanGreaterThanToken"] = 43] = "GreaterThanGreaterThanToken";
SyntaxKind[SyntaxKind["GreaterThanGreaterThanGreaterThanToken"] = 44] = "GreaterThanGreaterThanGreaterThanToken";
SyntaxKind[SyntaxKind["AmpersandToken"] = 45] = "AmpersandToken";
SyntaxKind[SyntaxKind["BarToken"] = 46] = "BarToken";
SyntaxKind[SyntaxKind["CaretToken"] = 47] = "CaretToken";
SyntaxKind[SyntaxKind["ExclamationToken"] = 48] = "ExclamationToken";
SyntaxKind[SyntaxKind["TildeToken"] = 49] = "TildeToken";
SyntaxKind[SyntaxKind["AmpersandAmpersandToken"] = 50] = "AmpersandAmpersandToken";
SyntaxKind[SyntaxKind["BarBarToken"] = 51] = "BarBarToken";
SyntaxKind[SyntaxKind["QuestionToken"] = 52] = "QuestionToken";
SyntaxKind[SyntaxKind["ColonToken"] = 53] = "ColonToken";
SyntaxKind[SyntaxKind["AtToken"] = 54] = "AtToken";
// Assignments
SyntaxKind[SyntaxKind["EqualsToken"] = 55] = "EqualsToken";
SyntaxKind[SyntaxKind["PlusEqualsToken"] = 56] = "PlusEqualsToken";
SyntaxKind[SyntaxKind["MinusEqualsToken"] = 57] = "MinusEqualsToken";
SyntaxKind[SyntaxKind["AsteriskEqualsToken"] = 58] = "AsteriskEqualsToken";
SyntaxKind[SyntaxKind["SlashEqualsToken"] = 59] = "SlashEqualsToken";
SyntaxKind[SyntaxKind["PercentEqualsToken"] = 60] = "PercentEqualsToken";
SyntaxKind[SyntaxKind["LessThanLessThanEqualsToken"] = 61] = "LessThanLessThanEqualsToken";
SyntaxKind[SyntaxKind["GreaterThanGreaterThanEqualsToken"] = 62] = "GreaterThanGreaterThanEqualsToken";
SyntaxKind[SyntaxKind["GreaterThanGreaterThanGreaterThanEqualsToken"] = 63] = "GreaterThanGreaterThanGreaterThanEqualsToken";
SyntaxKind[SyntaxKind["AmpersandEqualsToken"] = 64] = "AmpersandEqualsToken";
SyntaxKind[SyntaxKind["BarEqualsToken"] = 65] = "BarEqualsToken";
SyntaxKind[SyntaxKind["CaretEqualsToken"] = 66] = "CaretEqualsToken";
// Identifiers
SyntaxKind[SyntaxKind["Identifier"] = 67] = "Identifier";
// Reserved words
SyntaxKind[SyntaxKind["BreakKeyword"] = 68] = "BreakKeyword";
SyntaxKind[SyntaxKind["CaseKeyword"] = 69] = "CaseKeyword";
SyntaxKind[SyntaxKind["CatchKeyword"] = 70] = "CatchKeyword";
SyntaxKind[SyntaxKind["ClassKeyword"] = 71] = "ClassKeyword";
SyntaxKind[SyntaxKind["ConstKeyword"] = 72] = "ConstKeyword";
SyntaxKind[SyntaxKind["ContinueKeyword"] = 73] = "ContinueKeyword";
SyntaxKind[SyntaxKind["DebuggerKeyword"] = 74] = "DebuggerKeyword";
SyntaxKind[SyntaxKind["DefaultKeyword"] = 75] = "DefaultKeyword";
SyntaxKind[SyntaxKind["DeleteKeyword"] = 76] = "DeleteKeyword";
SyntaxKind[SyntaxKind["DoKeyword"] = 77] = "DoKeyword";
SyntaxKind[SyntaxKind["ElseKeyword"] = 78] = "ElseKeyword";
SyntaxKind[SyntaxKind["EnumKeyword"] = 79] = "EnumKeyword";
SyntaxKind[SyntaxKind["ExportKeyword"] = 80] = "ExportKeyword";
SyntaxKind[SyntaxKind["ExtendsKeyword"] = 81] = "ExtendsKeyword";
SyntaxKind[SyntaxKind["FalseKeyword"] = 82] = "FalseKeyword";
SyntaxKind[SyntaxKind["FinallyKeyword"] = 83] = "FinallyKeyword";
SyntaxKind[SyntaxKind["ForKeyword"] = 84] = "ForKeyword";
SyntaxKind[SyntaxKind["FunctionKeyword"] = 85] = "FunctionKeyword";
SyntaxKind[SyntaxKind["IfKeyword"] = 86] = "IfKeyword";
SyntaxKind[SyntaxKind["ImportKeyword"] = 87] = "ImportKeyword";
SyntaxKind[SyntaxKind["InKeyword"] = 88] = "InKeyword";
SyntaxKind[SyntaxKind["InstanceOfKeyword"] = 89] = "InstanceOfKeyword";
SyntaxKind[SyntaxKind["NewKeyword"] = 90] = "NewKeyword";
SyntaxKind[SyntaxKind["NullKeyword"] = 91] = "NullKeyword";
SyntaxKind[SyntaxKind["ReturnKeyword"] = 92] = "ReturnKeyword";
SyntaxKind[SyntaxKind["SuperKeyword"] = 93] = "SuperKeyword";
SyntaxKind[SyntaxKind["SwitchKeyword"] = 94] = "SwitchKeyword";
SyntaxKind[SyntaxKind["ThisKeyword"] = 95] = "ThisKeyword";
SyntaxKind[SyntaxKind["ThrowKeyword"] = 96] = "ThrowKeyword";
SyntaxKind[SyntaxKind["TrueKeyword"] = 97] = "TrueKeyword";
SyntaxKind[SyntaxKind["TryKeyword"] = 98] = "TryKeyword";
SyntaxKind[SyntaxKind["TypeOfKeyword"] = 99] = "TypeOfKeyword";
SyntaxKind[SyntaxKind["VarKeyword"] = 100] = "VarKeyword";
SyntaxKind[SyntaxKind["VoidKeyword"] = 101] = "VoidKeyword";
SyntaxKind[SyntaxKind["WhileKeyword"] = 102] = "WhileKeyword";
SyntaxKind[SyntaxKind["WithKeyword"] = 103] = "WithKeyword";
// Strict mode reserved words
SyntaxKind[SyntaxKind["ImplementsKeyword"] = 104] = "ImplementsKeyword";
SyntaxKind[SyntaxKind["InterfaceKeyword"] = 105] = "InterfaceKeyword";
SyntaxKind[SyntaxKind["LetKeyword"] = 106] = "LetKeyword";
SyntaxKind[SyntaxKind["PackageKeyword"] = 107] = "PackageKeyword";
SyntaxKind[SyntaxKind["PrivateKeyword"] = 108] = "PrivateKeyword";
SyntaxKind[SyntaxKind["ProtectedKeyword"] = 109] = "ProtectedKeyword";
SyntaxKind[SyntaxKind["PublicKeyword"] = 110] = "PublicKeyword";
SyntaxKind[SyntaxKind["StaticKeyword"] = 111] = "StaticKeyword";
SyntaxKind[SyntaxKind["YieldKeyword"] = 112] = "YieldKeyword";
// Contextual keywords
SyntaxKind[SyntaxKind["AbstractKeyword"] = 113] = "AbstractKeyword";
SyntaxKind[SyntaxKind["AsKeyword"] = 114] = "AsKeyword";
SyntaxKind[SyntaxKind["AnyKeyword"] = 115] = "AnyKeyword";
SyntaxKind[SyntaxKind["AsyncKeyword"] = 116] = "AsyncKeyword";
SyntaxKind[SyntaxKind["AwaitKeyword"] = 117] = "AwaitKeyword";
SyntaxKind[SyntaxKind["BooleanKeyword"] = 118] = "BooleanKeyword";
SyntaxKind[SyntaxKind["ConstructorKeyword"] = 119] = "ConstructorKeyword";
SyntaxKind[SyntaxKind["DeclareKeyword"] = 120] = "DeclareKeyword";
SyntaxKind[SyntaxKind["GetKeyword"] = 121] = "GetKeyword";
SyntaxKind[SyntaxKind["IsKeyword"] = 122] = "IsKeyword";
SyntaxKind[SyntaxKind["ModuleKeyword"] = 123] = "ModuleKeyword";
SyntaxKind[SyntaxKind["NamespaceKeyword"] = 124] = "NamespaceKeyword";
SyntaxKind[SyntaxKind["RequireKeyword"] = 125] = "RequireKeyword";
SyntaxKind[SyntaxKind["NumberKeyword"] = 126] = "NumberKeyword";
SyntaxKind[SyntaxKind["SetKeyword"] = 127] = "SetKeyword";
SyntaxKind[SyntaxKind["StringKeyword"] = 128] = "StringKeyword";
SyntaxKind[SyntaxKind["SymbolKeyword"] = 129] = "SymbolKeyword";
SyntaxKind[SyntaxKind["TypeKeyword"] = 130] = "TypeKeyword";
SyntaxKind[SyntaxKind["FromKeyword"] = 131] = "FromKeyword";
SyntaxKind[SyntaxKind["OfKeyword"] = 132] = "OfKeyword";
// Parse tree nodes
// Names
SyntaxKind[SyntaxKind["QualifiedName"] = 133] = "QualifiedName";
SyntaxKind[SyntaxKind["ComputedPropertyName"] = 134] = "ComputedPropertyName";
// Signature elements
SyntaxKind[SyntaxKind["TypeParameter"] = 135] = "TypeParameter";
SyntaxKind[SyntaxKind["Parameter"] = 136] = "Parameter";
SyntaxKind[SyntaxKind["Decorator"] = 137] = "Decorator";
// TypeMember
SyntaxKind[SyntaxKind["PropertySignature"] = 138] = "PropertySignature";
SyntaxKind[SyntaxKind["PropertyDeclaration"] = 139] = "PropertyDeclaration";
SyntaxKind[SyntaxKind["MethodSignature"] = 140] = "MethodSignature";
SyntaxKind[SyntaxKind["MethodDeclaration"] = 141] = "MethodDeclaration";
SyntaxKind[SyntaxKind["Constructor"] = 142] = "Constructor";
SyntaxKind[SyntaxKind["GetAccessor"] = 143] = "GetAccessor";
SyntaxKind[SyntaxKind["SetAccessor"] = 144] = "SetAccessor";
SyntaxKind[SyntaxKind["CallSignature"] = 145] = "CallSignature";
SyntaxKind[SyntaxKind["ConstructSignature"] = 146] = "ConstructSignature";
SyntaxKind[SyntaxKind["IndexSignature"] = 147] = "IndexSignature";
// Type
SyntaxKind[SyntaxKind["TypePredicate"] = 148] = "TypePredicate";
SyntaxKind[SyntaxKind["TypeReference"] = 149] = "TypeReference";
SyntaxKind[SyntaxKind["FunctionType"] = 150] = "FunctionType";
SyntaxKind[SyntaxKind["ConstructorType"] = 151] = "ConstructorType";
SyntaxKind[SyntaxKind["TypeQuery"] = 152] = "TypeQuery";
SyntaxKind[SyntaxKind["TypeLiteral"] = 153] = "TypeLiteral";
SyntaxKind[SyntaxKind["ArrayType"] = 154] = "ArrayType";
SyntaxKind[SyntaxKind["TupleType"] = 155] = "TupleType";
SyntaxKind[SyntaxKind["UnionType"] = 156] = "UnionType";
SyntaxKind[SyntaxKind["IntersectionType"] = 157] = "IntersectionType";
SyntaxKind[SyntaxKind["ParenthesizedType"] = 158] = "ParenthesizedType";
// Binding patterns
SyntaxKind[SyntaxKind["ObjectBindingPattern"] = 159] = "ObjectBindingPattern";
SyntaxKind[SyntaxKind["ArrayBindingPattern"] = 160] = "ArrayBindingPattern";
SyntaxKind[SyntaxKind["BindingElement"] = 161] = "BindingElement";
// Expression
SyntaxKind[SyntaxKind["ArrayLiteralExpression"] = 162] = "ArrayLiteralExpression";
SyntaxKind[SyntaxKind["ObjectLiteralExpression"] = 163] = "ObjectLiteralExpression";
SyntaxKind[SyntaxKind["PropertyAccessExpression"] = 164] = "PropertyAccessExpression";
SyntaxKind[SyntaxKind["ElementAccessExpression"] = 165] = "ElementAccessExpression";
SyntaxKind[SyntaxKind["CallExpression"] = 166] = "CallExpression";
SyntaxKind[SyntaxKind["NewExpression"] = 167] = "NewExpression";
SyntaxKind[SyntaxKind["TaggedTemplateExpression"] = 168] = "TaggedTemplateExpression";
SyntaxKind[SyntaxKind["TypeAssertionExpression"] = 169] = "TypeAssertionExpression";
SyntaxKind[SyntaxKind["ParenthesizedExpression"] = 170] = "ParenthesizedExpression";
SyntaxKind[SyntaxKind["FunctionExpression"] = 171] = "FunctionExpression";
SyntaxKind[SyntaxKind["ArrowFunction"] = 172] = "ArrowFunction";
SyntaxKind[SyntaxKind["DeleteExpression"] = 173] = "DeleteExpression";
SyntaxKind[SyntaxKind["TypeOfExpression"] = 174] = "TypeOfExpression";
SyntaxKind[SyntaxKind["VoidExpression"] = 175] = "VoidExpression";
SyntaxKind[SyntaxKind["AwaitExpression"] = 176] = "AwaitExpression";
SyntaxKind[SyntaxKind["PrefixUnaryExpression"] = 177] = "PrefixUnaryExpression";
SyntaxKind[SyntaxKind["PostfixUnaryExpression"] = 178] = "PostfixUnaryExpression";
SyntaxKind[SyntaxKind["BinaryExpression"] = 179] = "BinaryExpression";
SyntaxKind[SyntaxKind["ConditionalExpression"] = 180] = "ConditionalExpression";
SyntaxKind[SyntaxKind["TemplateExpression"] = 181] = "TemplateExpression";
SyntaxKind[SyntaxKind["YieldExpression"] = 182] = "YieldExpression";
SyntaxKind[SyntaxKind["SpreadElementExpression"] = 183] = "SpreadElementExpression";
SyntaxKind[SyntaxKind["ClassExpression"] = 184] = "ClassExpression";
SyntaxKind[SyntaxKind["OmittedExpression"] = 185] = "OmittedExpression";
SyntaxKind[SyntaxKind["ExpressionWithTypeArguments"] = 186] = "ExpressionWithTypeArguments";
SyntaxKind[SyntaxKind["AsExpression"] = 187] = "AsExpression";
// Misc
SyntaxKind[SyntaxKind["TemplateSpan"] = 188] = "TemplateSpan";
SyntaxKind[SyntaxKind["SemicolonClassElement"] = 189] = "SemicolonClassElement";
// Element
SyntaxKind[SyntaxKind["Block"] = 190] = "Block";
SyntaxKind[SyntaxKind["VariableStatement"] = 191] = "VariableStatement";
SyntaxKind[SyntaxKind["EmptyStatement"] = 192] = "EmptyStatement";
SyntaxKind[SyntaxKind["ExpressionStatement"] = 193] = "ExpressionStatement";
SyntaxKind[SyntaxKind["IfStatement"] = 194] = "IfStatement";
SyntaxKind[SyntaxKind["DoStatement"] = 195] = "DoStatement";
SyntaxKind[SyntaxKind["WhileStatement"] = 196] = "WhileStatement";
SyntaxKind[SyntaxKind["ForStatement"] = 197] = "ForStatement";
SyntaxKind[SyntaxKind["ForInStatement"] = 198] = "ForInStatement";
SyntaxKind[SyntaxKind["ForOfStatement"] = 199] = "ForOfStatement";
SyntaxKind[SyntaxKind["ContinueStatement"] = 200] = "ContinueStatement";
SyntaxKind[SyntaxKind["BreakStatement"] = 201] = "BreakStatement";
SyntaxKind[SyntaxKind["ReturnStatement"] = 202] = "ReturnStatement";
SyntaxKind[SyntaxKind["WithStatement"] = 203] = "WithStatement";
SyntaxKind[SyntaxKind["SwitchStatement"] = 204] = "SwitchStatement";
SyntaxKind[SyntaxKind["LabeledStatement"] = 205] = "LabeledStatement";
SyntaxKind[SyntaxKind["ThrowStatement"] = 206] = "ThrowStatement";
SyntaxKind[SyntaxKind["TryStatement"] = 207] = "TryStatement";
SyntaxKind[SyntaxKind["DebuggerStatement"] = 208] = "DebuggerStatement";
SyntaxKind[SyntaxKind["VariableDeclaration"] = 209] = "VariableDeclaration";
SyntaxKind[SyntaxKind["VariableDeclarationList"] = 210] = "VariableDeclarationList";
SyntaxKind[SyntaxKind["FunctionDeclaration"] = 211] = "FunctionDeclaration";
SyntaxKind[SyntaxKind["ClassDeclaration"] = 212] = "ClassDeclaration";
SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 213] = "InterfaceDeclaration";
SyntaxKind[SyntaxKind["TypeAliasDeclaration"] = 214] = "TypeAliasDeclaration";
SyntaxKind[SyntaxKind["EnumDeclaration"] = 215] = "EnumDeclaration";
SyntaxKind[SyntaxKind["ModuleDeclaration"] = 216] = "ModuleDeclaration";
SyntaxKind[SyntaxKind["ModuleBlock"] = 217] = "ModuleBlock";
SyntaxKind[SyntaxKind["CaseBlock"] = 218] = "CaseBlock";
SyntaxKind[SyntaxKind["ImportEqualsDeclaration"] = 219] = "ImportEqualsDeclaration";
SyntaxKind[SyntaxKind["ImportDeclaration"] = 220] = "ImportDeclaration";
SyntaxKind[SyntaxKind["ImportClause"] = 221] = "ImportClause";
SyntaxKind[SyntaxKind["NamespaceImport"] = 222] = "NamespaceImport";
SyntaxKind[SyntaxKind["NamedImports"] = 223] = "NamedImports";
SyntaxKind[SyntaxKind["ImportSpecifier"] = 224] = "ImportSpecifier";
SyntaxKind[SyntaxKind["ExportAssignment"] = 225] = "ExportAssignment";
SyntaxKind[SyntaxKind["ExportDeclaration"] = 226] = "ExportDeclaration";
SyntaxKind[SyntaxKind["NamedExports"] = 227] = "NamedExports";
SyntaxKind[SyntaxKind["ExportSpecifier"] = 228] = "ExportSpecifier";
SyntaxKind[SyntaxKind["MissingDeclaration"] = 229] = "MissingDeclaration";
// Module references
SyntaxKind[SyntaxKind["ExternalModuleReference"] = 230] = "ExternalModuleReference";
// JSX
SyntaxKind[SyntaxKind["JsxElement"] = 231] = "JsxElement";
SyntaxKind[SyntaxKind["JsxSelfClosingElement"] = 232] = "JsxSelfClosingElement";
SyntaxKind[SyntaxKind["JsxOpeningElement"] = 233] = "JsxOpeningElement";
SyntaxKind[SyntaxKind["JsxText"] = 234] = "JsxText";
SyntaxKind[SyntaxKind["JsxClosingElement"] = 235] = "JsxClosingElement";
SyntaxKind[SyntaxKind["JsxAttribute"] = 236] = "JsxAttribute";
SyntaxKind[SyntaxKind["JsxSpreadAttribute"] = 237] = "JsxSpreadAttribute";
SyntaxKind[SyntaxKind["JsxExpression"] = 238] = "JsxExpression";
// Clauses
SyntaxKind[SyntaxKind["CaseClause"] = 239] = "CaseClause";
SyntaxKind[SyntaxKind["DefaultClause"] = 240] = "DefaultClause";
SyntaxKind[SyntaxKind["HeritageClause"] = 241] = "HeritageClause";
SyntaxKind[SyntaxKind["CatchClause"] = 242] = "CatchClause";
// Property assignments
SyntaxKind[SyntaxKind["PropertyAssignment"] = 243] = "PropertyAssignment";
SyntaxKind[SyntaxKind["ShorthandPropertyAssignment"] = 244] = "ShorthandPropertyAssignment";
// Enum
SyntaxKind[SyntaxKind["EnumMember"] = 245] = "EnumMember";
// Top-level nodes
SyntaxKind[SyntaxKind["SourceFile"] = 246] = "SourceFile";
// JSDoc nodes.
SyntaxKind[SyntaxKind["JSDocTypeExpression"] = 247] = "JSDocTypeExpression";
// The * type.
SyntaxKind[SyntaxKind["JSDocAllType"] = 248] = "JSDocAllType";
// The ? type.
SyntaxKind[SyntaxKind["JSDocUnknownType"] = 249] = "JSDocUnknownType";
SyntaxKind[SyntaxKind["JSDocArrayType"] = 250] = "JSDocArrayType";
SyntaxKind[SyntaxKind["JSDocUnionType"] = 251] = "JSDocUnionType";
SyntaxKind[SyntaxKind["JSDocTupleType"] = 252] = "JSDocTupleType";
SyntaxKind[SyntaxKind["JSDocNullableType"] = 253] = "JSDocNullableType";
SyntaxKind[SyntaxKind["JSDocNonNullableType"] = 254] = "JSDocNonNullableType";
SyntaxKind[SyntaxKind["JSDocRecordType"] = 255] = "JSDocRecordType";
SyntaxKind[SyntaxKind["JSDocRecordMember"] = 256] = "JSDocRecordMember";
SyntaxKind[SyntaxKind["JSDocTypeReference"] = 257] = "JSDocTypeReference";
SyntaxKind[SyntaxKind["JSDocOptionalType"] = 258] = "JSDocOptionalType";
SyntaxKind[SyntaxKind["JSDocFunctionType"] = 259] = "JSDocFunctionType";
SyntaxKind[SyntaxKind["JSDocVariadicType"] = 260] = "JSDocVariadicType";
SyntaxKind[SyntaxKind["JSDocConstructorType"] = 261] = "JSDocConstructorType";
SyntaxKind[SyntaxKind["JSDocThisType"] = 262] = "JSDocThisType";
SyntaxKind[SyntaxKind["JSDocComment"] = 263] = "JSDocComment";
SyntaxKind[SyntaxKind["JSDocTag"] = 264] = "JSDocTag";
SyntaxKind[SyntaxKind["JSDocParameterTag"] = 265] = "JSDocParameterTag";
SyntaxKind[SyntaxKind["JSDocReturnTag"] = 266] = "JSDocReturnTag";
SyntaxKind[SyntaxKind["JSDocTypeTag"] = 267] = "JSDocTypeTag";
SyntaxKind[SyntaxKind["JSDocTemplateTag"] = 268] = "JSDocTemplateTag";
// Synthesized list
SyntaxKind[SyntaxKind["SyntaxList"] = 269] = "SyntaxList";
// Enum value count
SyntaxKind[SyntaxKind["Count"] = 270] = "Count";
// Markers
SyntaxKind[SyntaxKind["FirstAssignment"] = 55] = "FirstAssignment";
SyntaxKind[SyntaxKind["LastAssignment"] = 66] = "LastAssignment";
SyntaxKind[SyntaxKind["FirstReservedWord"] = 68] = "FirstReservedWord";
SyntaxKind[SyntaxKind["LastReservedWord"] = 103] = "LastReservedWord";
SyntaxKind[SyntaxKind["FirstKeyword"] = 68] = "FirstKeyword";
SyntaxKind[SyntaxKind["LastKeyword"] = 132] = "LastKeyword";
SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = 104] = "FirstFutureReservedWord";
SyntaxKind[SyntaxKind["LastFutureReservedWord"] = 112] = "LastFutureReservedWord";
SyntaxKind[SyntaxKind["FirstTypeNode"] = 149] = "FirstTypeNode";
SyntaxKind[SyntaxKind["LastTypeNode"] = 158] = "LastTypeNode";
SyntaxKind[SyntaxKind["FirstPunctuation"] = 15] = "FirstPunctuation";
SyntaxKind[SyntaxKind["LastPunctuation"] = 66] = "LastPunctuation";
SyntaxKind[SyntaxKind["FirstToken"] = 0] = "FirstToken";
SyntaxKind[SyntaxKind["LastToken"] = 132] = "LastToken";
SyntaxKind[SyntaxKind["FirstTriviaToken"] = 2] = "FirstTriviaToken";
SyntaxKind[SyntaxKind["LastTriviaToken"] = 7] = "LastTriviaToken";
SyntaxKind[SyntaxKind["FirstLiteralToken"] = 8] = "FirstLiteralToken";
SyntaxKind[SyntaxKind["LastLiteralToken"] = 11] = "LastLiteralToken";
SyntaxKind[SyntaxKind["FirstTemplateToken"] = 11] = "FirstTemplateToken";
SyntaxKind[SyntaxKind["LastTemplateToken"] = 14] = "LastTemplateToken";
SyntaxKind[SyntaxKind["FirstBinaryOperator"] = 25] = "FirstBinaryOperator";
SyntaxKind[SyntaxKind["LastBinaryOperator"] = 66] = "LastBinaryOperator";
SyntaxKind[SyntaxKind["FirstNode"] = 133] = "FirstNode";
})(ts.SyntaxKind || (ts.SyntaxKind = {}));
var SyntaxKind = ts.SyntaxKind;
(function (NodeFlags) {
NodeFlags[NodeFlags["Export"] = 1] = "Export";
NodeFlags[NodeFlags["Ambient"] = 2] = "Ambient";
NodeFlags[NodeFlags["Public"] = 16] = "Public";
NodeFlags[NodeFlags["Private"] = 32] = "Private";
NodeFlags[NodeFlags["Protected"] = 64] = "Protected";
NodeFlags[NodeFlags["Static"] = 128] = "Static";
NodeFlags[NodeFlags["Abstract"] = 256] = "Abstract";
NodeFlags[NodeFlags["Async"] = 512] = "Async";
NodeFlags[NodeFlags["Default"] = 1024] = "Default";
NodeFlags[NodeFlags["MultiLine"] = 2048] = "MultiLine";
NodeFlags[NodeFlags["Synthetic"] = 4096] = "Synthetic";
NodeFlags[NodeFlags["DeclarationFile"] = 8192] = "DeclarationFile";
NodeFlags[NodeFlags["Let"] = 16384] = "Let";
NodeFlags[NodeFlags["Const"] = 32768] = "Const";
NodeFlags[NodeFlags["OctalLiteral"] = 65536] = "OctalLiteral";
NodeFlags[NodeFlags["Namespace"] = 131072] = "Namespace";
NodeFlags[NodeFlags["ExportContext"] = 262144] = "ExportContext";
NodeFlags[NodeFlags["Modifier"] = 2035] = "Modifier";
NodeFlags[NodeFlags["AccessibilityModifier"] = 112] = "AccessibilityModifier";
NodeFlags[NodeFlags["BlockScoped"] = 49152] = "BlockScoped";
})(ts.NodeFlags || (ts.NodeFlags = {}));
var NodeFlags = ts.NodeFlags;
/* @internal */
(function (ParserContextFlags) {
ParserContextFlags[ParserContextFlags["None"] = 0] = "None";
// If this node was parsed in a context where 'in-expressions' are not allowed.
ParserContextFlags[ParserContextFlags["DisallowIn"] = 1] = "DisallowIn";
// If this node was parsed in the 'yield' context created when parsing a generator.
ParserContextFlags[ParserContextFlags["Yield"] = 2] = "Yield";
// If this node was parsed as part of a decorator
ParserContextFlags[ParserContextFlags["Decorator"] = 4] = "Decorator";
// If this node was parsed in the 'await' context created when parsing an async function.
ParserContextFlags[ParserContextFlags["Await"] = 8] = "Await";
// If the parser encountered an error when parsing the code that created this node. Note
// the parser only sets this directly on the node it creates right after encountering the
// error.
ParserContextFlags[ParserContextFlags["ThisNodeHasError"] = 16] = "ThisNodeHasError";
// This node was parsed in a JavaScript file and can be processed differently. For example
// its type can be specified usign a JSDoc comment.
ParserContextFlags[ParserContextFlags["JavaScriptFile"] = 32] = "JavaScriptFile";
// Context flags set directly by the parser.
ParserContextFlags[ParserContextFlags["ParserGeneratedFlags"] = 31] = "ParserGeneratedFlags";
// Exclude these flags when parsing a Type
ParserContextFlags[ParserContextFlags["TypeExcludesFlags"] = 10] = "TypeExcludesFlags";
// Context flags computed by aggregating child flags upwards.
// Used during incremental parsing to determine if this node or any of its children had an
// error. Computed only once and then cached.
ParserContextFlags[ParserContextFlags["ThisNodeOrAnySubNodesHasError"] = 64] = "ThisNodeOrAnySubNodesHasError";
// Used to know if we've computed data from children and cached it in this node.
ParserContextFlags[ParserContextFlags["HasAggregatedChildData"] = 128] = "HasAggregatedChildData";
})(ts.ParserContextFlags || (ts.ParserContextFlags = {}));
var ParserContextFlags = ts.ParserContextFlags;
(function (JsxFlags) {
JsxFlags[JsxFlags["None"] = 0] = "None";
JsxFlags[JsxFlags["IntrinsicNamedElement"] = 1] = "IntrinsicNamedElement";
JsxFlags[JsxFlags["IntrinsicIndexedElement"] = 2] = "IntrinsicIndexedElement";
JsxFlags[JsxFlags["ClassElement"] = 4] = "ClassElement";
JsxFlags[JsxFlags["UnknownElement"] = 8] = "UnknownElement";
JsxFlags[JsxFlags["IntrinsicElement"] = 3] = "IntrinsicElement";
})(ts.JsxFlags || (ts.JsxFlags = {}));
var JsxFlags = ts.JsxFlags;
/* @internal */
(function (RelationComparisonResult) {
RelationComparisonResult[RelationComparisonResult["Succeeded"] = 1] = "Succeeded";
RelationComparisonResult[RelationComparisonResult["Failed"] = 2] = "Failed";
RelationComparisonResult[RelationComparisonResult["FailedAndReported"] = 3] = "FailedAndReported";
})(ts.RelationComparisonResult || (ts.RelationComparisonResult = {}));
var RelationComparisonResult = ts.RelationComparisonResult;
var OperationCanceledException = (function () {
function OperationCanceledException() {
}
return OperationCanceledException;
})();
ts.OperationCanceledException = OperationCanceledException;
/** Return code used by getEmitOutput function to indicate status of the function */
(function (ExitStatus) {
// Compiler ran successfully. Either this was a simple do-nothing compilation (for example,
// when -version or -help was provided, or this was a normal compilation, no diagnostics
// were produced, and all outputs were generated successfully.
ExitStatus[ExitStatus["Success"] = 0] = "Success";
// Diagnostics were produced and because of them no code was generated.
ExitStatus[ExitStatus["DiagnosticsPresent_OutputsSkipped"] = 1] = "DiagnosticsPresent_OutputsSkipped";
// Diagnostics were produced and outputs were generated in spite of them.
ExitStatus[ExitStatus["DiagnosticsPresent_OutputsGenerated"] = 2] = "DiagnosticsPresent_OutputsGenerated";
})(ts.ExitStatus || (ts.ExitStatus = {}));
var ExitStatus = ts.ExitStatus;
(function (TypeFormatFlags) {
TypeFormatFlags[TypeFormatFlags["None"] = 0] = "None";
TypeFormatFlags[TypeFormatFlags["WriteArrayAsGenericType"] = 1] = "WriteArrayAsGenericType";
TypeFormatFlags[TypeFormatFlags["UseTypeOfFunction"] = 2] = "UseTypeOfFunction";
TypeFormatFlags[TypeFormatFlags["NoTruncation"] = 4] = "NoTruncation";
TypeFormatFlags[TypeFormatFlags["WriteArrowStyleSignature"] = 8] = "WriteArrowStyleSignature";
TypeFormatFlags[TypeFormatFlags["WriteOwnNameForAnyLike"] = 16] = "WriteOwnNameForAnyLike";
TypeFormatFlags[TypeFormatFlags["WriteTypeArgumentsOfSignature"] = 32] = "WriteTypeArgumentsOfSignature";
TypeFormatFlags[TypeFormatFlags["InElementType"] = 64] = "InElementType";
TypeFormatFlags[TypeFormatFlags["UseFullyQualifiedType"] = 128] = "UseFullyQualifiedType";
})(ts.TypeFormatFlags || (ts.TypeFormatFlags = {}));
var TypeFormatFlags = ts.TypeFormatFlags;
(function (SymbolFormatFlags) {
SymbolFormatFlags[SymbolFormatFlags["None"] = 0] = "None";
// Write symbols's type argument if it is instantiated symbol
// eg. class C<T> { p: T } <-- Show p as C<T>.p here
// var a: C<number>;
// var p = a.p; <--- Here p is property of C<number> so show it as C<number>.p instead of just C.p
SymbolFormatFlags[SymbolFormatFlags["WriteTypeParametersOrArguments"] = 1] = "WriteTypeParametersOrArguments";
// Use only external alias information to get the symbol name in the given context
// eg. module m { export class c { } } import x = m.c;
// When this flag is specified m.c will be used to refer to the class instead of alias symbol x
SymbolFormatFlags[SymbolFormatFlags["UseOnlyExternalAliasing"] = 2] = "UseOnlyExternalAliasing";
})(ts.SymbolFormatFlags || (ts.SymbolFormatFlags = {}));
var SymbolFormatFlags = ts.SymbolFormatFlags;
/* @internal */
(function (SymbolAccessibility) {
SymbolAccessibility[SymbolAccessibility["Accessible"] = 0] = "Accessible";
SymbolAccessibility[SymbolAccessibility["NotAccessible"] = 1] = "NotAccessible";
SymbolAccessibility[SymbolAccessibility["CannotBeNamed"] = 2] = "CannotBeNamed";
})(ts.SymbolAccessibility || (ts.SymbolAccessibility = {}));
var SymbolAccessibility = ts.SymbolAccessibility;
/** Indicates how to serialize the name for a TypeReferenceNode when emitting decorator
* metadata */
/* @internal */
(function (TypeReferenceSerializationKind) {
TypeReferenceSerializationKind[TypeReferenceSerializationKind["Unknown"] = 0] = "Unknown";
// should be emitted using a safe fallback.
TypeReferenceSerializationKind[TypeReferenceSerializationKind["TypeWithConstructSignatureAndValue"] = 1] = "TypeWithConstructSignatureAndValue";
// function that can be reached at runtime (e.g. a `class`
// declaration or a `var` declaration for the static side
// of a type, such as the global `Promise` type in lib.d.ts).
TypeReferenceSerializationKind[TypeReferenceSerializationKind["VoidType"] = 2] = "VoidType";
TypeReferenceSerializationKind[TypeReferenceSerializationKind["NumberLikeType"] = 3] = "NumberLikeType";
TypeReferenceSerializationKind[TypeReferenceSerializationKind["StringLikeType"] = 4] = "StringLikeType";
TypeReferenceSerializationKind[TypeReferenceSerializationKind["BooleanType"] = 5] = "BooleanType";
TypeReferenceSerializationKind[TypeReferenceSerializationKind["ArrayLikeType"] = 6] = "ArrayLikeType";
TypeReferenceSerializationKind[TypeReferenceSerializationKind["ESSymbolType"] = 7] = "ESSymbolType";
TypeReferenceSerializationKind[TypeReferenceSerializationKind["TypeWithCallSignature"] = 8] = "TypeWithCallSignature";
// with call signatures.
TypeReferenceSerializationKind[TypeReferenceSerializationKind["ObjectType"] = 9] = "ObjectType";
})(ts.TypeReferenceSerializationKind || (ts.TypeReferenceSerializationKind = {}));
var TypeReferenceSerializationKind = ts.TypeReferenceSerializationKind;
(function (SymbolFlags) {
SymbolFlags[SymbolFlags["None"] = 0] = "None";
SymbolFlags[SymbolFlags["FunctionScopedVariable"] = 1] = "FunctionScopedVariable";
SymbolFlags[SymbolFlags["BlockScopedVariable"] = 2] = "BlockScopedVariable";
SymbolFlags[SymbolFlags["Property"] = 4] = "Property";
SymbolFlags[SymbolFlags["EnumMember"] = 8] = "EnumMember";
SymbolFlags[SymbolFlags["Function"] = 16] = "Function";
SymbolFlags[SymbolFlags["Class"] = 32] = "Class";
SymbolFlags[SymbolFlags["Interface"] = 64] = "Interface";
SymbolFlags[SymbolFlags["ConstEnum"] = 128] = "ConstEnum";
SymbolFlags[SymbolFlags["RegularEnum"] = 256] = "RegularEnum";
SymbolFlags[SymbolFlags["ValueModule"] = 512] = "ValueModule";
SymbolFlags[SymbolFlags["NamespaceModule"] = 1024] = "NamespaceModule";
SymbolFlags[SymbolFlags["TypeLiteral"] = 2048] = "TypeLiteral";
SymbolFlags[SymbolFlags["ObjectLiteral"] = 4096] = "ObjectLiteral";
SymbolFlags[SymbolFlags["Method"] = 8192] = "Method";
SymbolFlags[SymbolFlags["Constructor"] = 16384] = "Constructor";
SymbolFlags[SymbolFlags["GetAccessor"] = 32768] = "GetAccessor";
SymbolFlags[SymbolFlags["SetAccessor"] = 65536] = "SetAccessor";
SymbolFlags[SymbolFlags["Signature"] = 131072] = "Signature";
SymbolFlags[SymbolFlags["TypeParameter"] = 262144] = "TypeParameter";
SymbolFlags[SymbolFlags["TypeAlias"] = 524288] = "TypeAlias";
SymbolFlags[SymbolFlags["ExportValue"] = 1048576] = "ExportValue";
SymbolFlags[SymbolFlags["ExportType"] = 2097152] = "ExportType";
SymbolFlags[SymbolFlags["ExportNamespace"] = 4194304] = "ExportNamespace";
SymbolFlags[SymbolFlags["Alias"] = 8388608] = "Alias";
SymbolFlags[SymbolFlags["Instantiated"] = 16777216] = "Instantiated";
SymbolFlags[SymbolFlags["Merged"] = 33554432] = "Merged";
SymbolFlags[SymbolFlags["Transient"] = 67108864] = "Transient";
SymbolFlags[SymbolFlags["Prototype"] = 134217728] = "Prototype";
SymbolFlags[SymbolFlags["SyntheticProperty"] = 268435456] = "SyntheticProperty";
SymbolFlags[SymbolFlags["Optional"] = 536870912] = "Optional";
SymbolFlags[SymbolFlags["ExportStar"] = 1073741824] = "ExportStar";
SymbolFlags[SymbolFlags["Enum"] = 384] = "Enum";
SymbolFlags[SymbolFlags["Variable"] = 3] = "Variable";
SymbolFlags[SymbolFlags["Value"] = 107455] = "Value";
SymbolFlags[SymbolFlags["Type"] = 793056] = "Type";
SymbolFlags[SymbolFlags["Namespace"] = 1536] = "Namespace";
SymbolFlags[SymbolFlags["Module"] = 1536] = "Module";
SymbolFlags[SymbolFlags["Accessor"] = 98304] = "Accessor";
// Variables can be redeclared, but can not redeclare a block-scoped declaration with the
// same name, or any other value that is not a variable, e.g. ValueModule or Class
SymbolFlags[SymbolFlags["FunctionScopedVariableExcludes"] = 107454] = "FunctionScopedVariableExcludes";
// Block-scoped declarations are not allowed to be re-declared
// they can not merge with anything in the value space
SymbolFlags[SymbolFlags["BlockScopedVariableExcludes"] = 107455] = "BlockScopedVariableExcludes";
SymbolFlags[SymbolFlags["ParameterExcludes"] = 107455] = "ParameterExcludes";
SymbolFlags[SymbolFlags["PropertyExcludes"] = 107455] = "PropertyExcludes";
SymbolFlags[SymbolFlags["EnumMemberExcludes"] = 107455] = "EnumMemberExcludes";
SymbolFlags[SymbolFlags["FunctionExcludes"] = 106927] = "FunctionExcludes";
SymbolFlags[SymbolFlags["ClassExcludes"] = 899519] = "ClassExcludes";
SymbolFlags[SymbolFlags["InterfaceExcludes"] = 792960] = "InterfaceExcludes";
SymbolFlags[SymbolFlags["RegularEnumExcludes"] = 899327] = "RegularEnumExcludes";
SymbolFlags[SymbolFlags["ConstEnumExcludes"] = 899967] = "ConstEnumExcludes";
SymbolFlags[SymbolFlags["ValueModuleExcludes"] = 106639] = "ValueModuleExcludes";
SymbolFlags[SymbolFlags["NamespaceModuleExcludes"] = 0] = "NamespaceModuleExcludes";
SymbolFlags[SymbolFlags["MethodExcludes"] = 99263] = "MethodExcludes";
SymbolFlags[SymbolFlags["GetAccessorExcludes"] = 41919] = "GetAccessorExcludes";
SymbolFlags[SymbolFlags["SetAccessorExcludes"] = 74687] = "SetAccessorExcludes";
SymbolFlags[SymbolFlags["TypeParameterExcludes"] = 530912] = "TypeParameterExcludes";
SymbolFlags[SymbolFlags["TypeAliasExcludes"] = 793056] = "TypeAliasExcludes";
SymbolFlags[SymbolFlags["AliasExcludes"] = 8388608] = "AliasExcludes";
SymbolFlags[SymbolFlags["ModuleMember"] = 8914931] = "ModuleMember";
SymbolFlags[SymbolFlags["ExportHasLocal"] = 944] = "ExportHasLocal";
SymbolFlags[SymbolFlags["HasExports"] = 1952] = "HasExports";
SymbolFlags[SymbolFlags["HasMembers"] = 6240] = "HasMembers";
SymbolFlags[SymbolFlags["BlockScoped"] = 418] = "BlockScoped";
SymbolFlags[SymbolFlags["PropertyOrAccessor"] = 98308] = "PropertyOrAccessor";
SymbolFlags[SymbolFlags["Export"] = 7340032] = "Export";
/* @internal */
// The set of things we consider semantically classifiable. Used to speed up the LS during
// classification.
SymbolFlags[SymbolFlags["Classifiable"] = 788448] = "Classifiable";
})(ts.SymbolFlags || (ts.SymbolFlags = {}));
var SymbolFlags = ts.SymbolFlags;
/* @internal */
(function (NodeCheckFlags) {
NodeCheckFlags[NodeCheckFlags["TypeChecked"] = 1] = "TypeChecked";
NodeCheckFlags[NodeCheckFlags["LexicalThis"] = 2] = "LexicalThis";
NodeCheckFlags[NodeCheckFlags["CaptureThis"] = 4] = "CaptureThis";
NodeCheckFlags[NodeCheckFlags["EmitExtends"] = 8] = "EmitExtends";
NodeCheckFlags[NodeCheckFlags["EmitDecorate"] = 16] = "EmitDecorate";
NodeCheckFlags[NodeCheckFlags["EmitParam"] = 32] = "EmitParam";
NodeCheckFlags[NodeCheckFlags["EmitAwaiter"] = 64] = "EmitAwaiter";
NodeCheckFlags[NodeCheckFlags["EmitGenerator"] = 128] = "EmitGenerator";
NodeCheckFlags[NodeCheckFlags["SuperInstance"] = 256] = "SuperInstance";
NodeCheckFlags[NodeCheckFlags["SuperStatic"] = 512] = "SuperStatic";
NodeCheckFlags[NodeCheckFlags["ContextChecked"] = 1024] = "ContextChecked";
NodeCheckFlags[NodeCheckFlags["LexicalArguments"] = 2048] = "LexicalArguments";
NodeCheckFlags[NodeCheckFlags["CaptureArguments"] = 4096] = "CaptureArguments";
// Values for enum members have been computed, and any errors have been reported for them.
NodeCheckFlags[NodeCheckFlags["EnumValuesComputed"] = 8192] = "EnumValuesComputed";
NodeCheckFlags[NodeCheckFlags["BlockScopedBindingInLoop"] = 16384] = "BlockScopedBindingInLoop";
NodeCheckFlags[NodeCheckFlags["LexicalModuleMergesWithClass"] = 32768] = "LexicalModuleMergesWithClass";
})(ts.NodeCheckFlags || (ts.NodeCheckFlags = {}));
var NodeCheckFlags = ts.NodeCheckFlags;
(function (TypeFlags) {
TypeFlags[TypeFlags["Any"] = 1] = "Any";
TypeFlags[TypeFlags["String"] = 2] = "String";
TypeFlags[TypeFlags["Number"] = 4] = "Number";
TypeFlags[TypeFlags["Boolean"] = 8] = "Boolean";
TypeFlags[TypeFlags["Void"] = 16] = "Void";
TypeFlags[TypeFlags["Undefined"] = 32] = "Undefined";
TypeFlags[TypeFlags["Null"] = 64] = "Null";
TypeFlags[TypeFlags["Enum"] = 128] = "Enum";
TypeFlags[TypeFlags["StringLiteral"] = 256] = "StringLiteral";
TypeFlags[TypeFlags["TypeParameter"] = 512] = "TypeParameter";
TypeFlags[TypeFlags["Class"] = 1024] = "Class";
TypeFlags[TypeFlags["Interface"] = 2048] = "Interface";
TypeFlags[TypeFlags["Reference"] = 4096] = "Reference";
TypeFlags[TypeFlags["Tuple"] = 8192] = "Tuple";
TypeFlags[TypeFlags["Union"] = 16384] = "Union";
TypeFlags[TypeFlags["Intersection"] = 32768] = "Intersection";
TypeFlags[TypeFlags["Anonymous"] = 65536] = "Anonymous";
TypeFlags[TypeFlags["Instantiated"] = 131072] = "Instantiated";
/* @internal */
TypeFlags[TypeFlags["FromSignature"] = 262144] = "FromSignature";
TypeFlags[TypeFlags["ObjectLiteral"] = 524288] = "ObjectLiteral";
/* @internal */
TypeFlags[TypeFlags["FreshObjectLiteral"] = 1048576] = "FreshObjectLiteral";
/* @internal */
TypeFlags[TypeFlags["ContainsUndefinedOrNull"] = 2097152] = "ContainsUndefinedOrNull";
/* @internal */
TypeFlags[TypeFlags["ContainsObjectLiteral"] = 4194304] = "ContainsObjectLiteral";
/* @internal */
TypeFlags[TypeFlags["ContainsAnyFunctionType"] = 8388608] = "ContainsAnyFunctionType";
TypeFlags[TypeFlags["ESSymbol"] = 16777216] = "ESSymbol";
/* @internal */
TypeFlags[TypeFlags["Intrinsic"] = 16777343] = "Intrinsic";
/* @internal */
TypeFlags[TypeFlags["Primitive"] = 16777726] = "Primitive";
TypeFlags[TypeFlags["StringLike"] = 258] = "StringLike";
TypeFlags[TypeFlags["NumberLike"] = 132] = "NumberLike";
TypeFlags[TypeFlags["ObjectType"] = 80896] = "ObjectType";
TypeFlags[TypeFlags["UnionOrIntersection"] = 49152] = "UnionOrIntersection";
TypeFlags[TypeFlags["StructuredType"] = 130048] = "StructuredType";
/* @internal */
TypeFlags[TypeFlags["RequiresWidening"] = 6291456] = "RequiresWidening";
/* @internal */
TypeFlags[TypeFlags["PropagatingFlags"] = 14680064] = "PropagatingFlags";
})(ts.TypeFlags || (ts.TypeFlags = {}));
var TypeFlags = ts.TypeFlags;
(function (SignatureKind) {
SignatureKind[SignatureKind["Call"] = 0] = "Call";
SignatureKind[SignatureKind["Construct"] = 1] = "Construct";
})(ts.SignatureKind || (ts.SignatureKind = {}));
var SignatureKind = ts.SignatureKind;
(function (IndexKind) {
IndexKind[IndexKind["String"] = 0] = "String";
IndexKind[IndexKind["Number"] = 1] = "Number";
})(ts.IndexKind || (ts.IndexKind = {}));
var IndexKind = ts.IndexKind;
(function (DiagnosticCategory) {
DiagnosticCategory[DiagnosticCategory["Warning"] = 0] = "Warning";
DiagnosticCategory[DiagnosticCategory["Error"] = 1] = "Error";
DiagnosticCategory[DiagnosticCategory["Message"] = 2] = "Message";
})(ts.DiagnosticCategory || (ts.DiagnosticCategory = {}));
var DiagnosticCategory = ts.DiagnosticCategory;
(function (ModuleResolutionKind) {
ModuleResolutionKind[ModuleResolutionKind["Classic"] = 1] = "Classic";
ModuleResolutionKind[ModuleResolutionKind["NodeJs"] = 2] = "NodeJs";
})(ts.ModuleResolutionKind || (ts.ModuleResolutionKind = {}));
var ModuleResolutionKind = ts.ModuleResolutionKind;
(function (ModuleKind) {
ModuleKind[ModuleKind["None"] = 0] = "None";
ModuleKind[ModuleKind["CommonJS"] = 1] = "CommonJS";
ModuleKind[ModuleKind["AMD"] = 2] = "AMD";
ModuleKind[ModuleKind["UMD"] = 3] = "UMD";
ModuleKind[ModuleKind["System"] = 4] = "System";
})(ts.ModuleKind || (ts.ModuleKind = {}));
var ModuleKind = ts.ModuleKind;
(function (JsxEmit) {
JsxEmit[JsxEmit["None"] = 0] = "None";
JsxEmit[JsxEmit["Preserve"] = 1] = "Preserve";
JsxEmit[JsxEmit["React"] = 2] = "React";
})(ts.JsxEmit || (ts.JsxEmit = {}));
var JsxEmit = ts.JsxEmit;
(function (NewLineKind) {
NewLineKind[NewLineKind["CarriageReturnLineFeed"] = 0] = "CarriageReturnLineFeed";
NewLineKind[NewLineKind["LineFeed"] = 1] = "LineFeed";
})(ts.NewLineKind || (ts.NewLineKind = {}));
var NewLineKind = ts.NewLineKind;
(function (ScriptTarget) {
ScriptTarget[ScriptTarget["ES3"] = 0] = "ES3";
ScriptTarget[ScriptTarget["ES5"] = 1] = "ES5";
ScriptTarget[ScriptTarget["ES6"] = 2] = "ES6";
ScriptTarget[ScriptTarget["Latest"] = 2] = "Latest";
})(ts.ScriptTarget || (ts.ScriptTarget = {}));
var ScriptTarget = ts.ScriptTarget;
(function (LanguageVariant) {
LanguageVariant[LanguageVariant["Standard"] = 0] = "Standard";
LanguageVariant[LanguageVariant["JSX"] = 1] = "JSX";
})(ts.LanguageVariant || (ts.LanguageVariant = {}));
var LanguageVariant = ts.LanguageVariant;
/* @internal */
(function (CharacterCodes) {
CharacterCodes[CharacterCodes["nullCharacter"] = 0] = "nullCharacter";
CharacterCodes[CharacterCodes["maxAsciiCharacter"] = 127] = "maxAsciiCharacter";
CharacterCodes[CharacterCodes["lineFeed"] = 10] = "lineFeed";
CharacterCodes[CharacterCodes["carriageReturn"] = 13] = "carriageReturn";
CharacterCodes[CharacterCodes["lineSeparator"] = 8232] = "lineSeparator";
CharacterCodes[CharacterCodes["paragraphSeparator"] = 8233] = "paragraphSeparator";
CharacterCodes[CharacterCodes["nextLine"] = 133] = "nextLine";
// Unicode 3.0 space characters
CharacterCodes[CharacterCodes["space"] = 32] = "space";
CharacterCodes[CharacterCodes["nonBreakingSpace"] = 160] = "nonBreakingSpace";
CharacterCodes[CharacterCodes["enQuad"] = 8192] = "enQuad";
CharacterCodes[CharacterCodes["emQuad"] = 8193] = "emQuad";
CharacterCodes[CharacterCodes["enSpace"] = 8194] = "enSpace";
CharacterCodes[CharacterCodes["emSpace"] = 8195] = "emSpace";
CharacterCodes[CharacterCodes["threePerEmSpace"] = 8196] = "threePerEmSpace";
CharacterCodes[CharacterCodes["fourPerEmSpace"] = 8197] = "fourPerEmSpace";
CharacterCodes[CharacterCodes["sixPerEmSpace"] = 8198] = "sixPerEmSpace";
CharacterCodes[CharacterCodes["figureSpace"] = 8199] = "figureSpace";
CharacterCodes[CharacterCodes["punctuationSpace"] = 8200] = "punctuationSpace";
CharacterCodes[CharacterCodes["thinSpace"] = 8201] = "thinSpace";
CharacterCodes[CharacterCodes["hairSpace"] = 8202] = "hairSpace";
CharacterCodes[CharacterCodes["zeroWidthSpace"] = 8203] = "zeroWidthSpace";
CharacterCodes[CharacterCodes["narrowNoBreakSpace"] = 8239] = "narrowNoBreakSpace";
CharacterCodes[CharacterCodes["ideographicSpace"] = 12288] = "ideographicSpace";
CharacterCodes[CharacterCodes["mathematicalSpace"] = 8287] = "mathematicalSpace";
CharacterCodes[CharacterCodes["ogham"] = 5760] = "ogham";
CharacterCodes[CharacterCodes["_"] = 95] = "_";
CharacterCodes[CharacterCodes["$"] = 36] = "$";
CharacterCodes[CharacterCodes["_0"] = 48] = "_0";
CharacterCodes[CharacterCodes["_1"] = 49] = "_1";
CharacterCodes[CharacterCodes["_2"] = 50] = "_2";
CharacterCodes[CharacterCodes["_3"] = 51] = "_3";
CharacterCodes[CharacterCodes["_4"] = 52] = "_4";
CharacterCodes[CharacterCodes["_5"] = 53] = "_5";
CharacterCodes[CharacterCodes["_6"] = 54] = "_6";
CharacterCodes[CharacterCodes["_7"] = 55] = "_7";
CharacterCodes[CharacterCodes["_8"] = 56] = "_8";
CharacterCodes[CharacterCodes["_9"] = 57] = "_9";
CharacterCodes[CharacterCodes["a"] = 97] = "a";
CharacterCodes[CharacterCodes["b"] = 98] = "b";
CharacterCodes[CharacterCodes["c"] = 99] = "c";
CharacterCodes[CharacterCodes["d"] = 100] = "d";
CharacterCodes[CharacterCodes["e"] = 101] = "e";
CharacterCodes[CharacterCodes["f"] = 102] = "f";
CharacterCodes[CharacterCodes["g"] = 103] = "g";
CharacterCodes[CharacterCodes["h"] = 104] = "h";
CharacterCodes[CharacterCodes["i"] = 105] = "i";
CharacterCodes[CharacterCodes["j"] = 106] = "j";
CharacterCodes[CharacterCodes["k"] = 107] = "k";
CharacterCodes[CharacterCodes["l"] = 108] = "l";
CharacterCodes[CharacterCodes["m"] = 109] = "m";
CharacterCodes[CharacterCodes["n"] = 110] = "n";
CharacterCodes[CharacterCodes["o"] = 111] = "o";
CharacterCodes[CharacterCodes["p"] = 112] = "p";
CharacterCodes[CharacterCodes["q"] = 113] = "q";
CharacterCodes[CharacterCodes["r"] = 114] = "r";
CharacterCodes[CharacterCodes["s"] = 115] = "s";
CharacterCodes[CharacterCodes["t"] = 116] = "t";
CharacterCodes[CharacterCodes["u"] = 117] = "u";
CharacterCodes[CharacterCodes["v"] = 118] = "v";
CharacterCodes[CharacterCodes["w"] = 119] = "w";
CharacterCodes[CharacterCodes["x"] = 120] = "x";
CharacterCodes[CharacterCodes["y"] = 121] = "y";
CharacterCodes[CharacterCodes["z"] = 122] = "z";
CharacterCodes[CharacterCodes["A"] = 65] = "A";
CharacterCodes[CharacterCodes["B"] = 66] = "B";
CharacterCodes[CharacterCodes["C"] = 67] = "C";
CharacterCodes[CharacterCodes["D"] = 68] = "D";
CharacterCodes[CharacterCodes["E"] = 69] = "E";
CharacterCodes[CharacterCodes["F"] = 70] = "F";
CharacterCodes[CharacterCodes["G"] = 71] = "G";
CharacterCodes[CharacterCodes["H"] = 72] = "H";
CharacterCodes[CharacterCodes["I"] = 73] = "I";
CharacterCodes[CharacterCodes["J"] = 74] = "J";
CharacterCodes[CharacterCodes["K"] = 75] = "K";
CharacterCodes[CharacterCodes["L"] = 76] = "L";
CharacterCodes[CharacterCodes["M"] = 77] = "M";
CharacterCodes[CharacterCodes["N"] = 78] = "N";
CharacterCodes[CharacterCodes["O"] = 79] = "O";
CharacterCodes[CharacterCodes["P"] = 80] = "P";
CharacterCodes[CharacterCodes["Q"] = 81] = "Q";
CharacterCodes[CharacterCodes["R"] = 82] = "R";
CharacterCodes[CharacterCodes["S"] = 83] = "S";
CharacterCodes[CharacterCodes["T"] = 84] = "T";
CharacterCodes[CharacterCodes["U"] = 85] = "U";
CharacterCodes[CharacterCodes["V"] = 86] = "V";
CharacterCodes[CharacterCodes["W"] = 87] = "W";
CharacterCodes[CharacterCodes["X"] = 88] = "X";
CharacterCodes[CharacterCodes["Y"] = 89] = "Y";
CharacterCodes[CharacterCodes["Z"] = 90] = "Z";
CharacterCodes[CharacterCodes["ampersand"] = 38] = "ampersand";
CharacterCodes[CharacterCodes["asterisk"] = 42] = "asterisk";
CharacterCodes[CharacterCodes["at"] = 64] = "at";
CharacterCodes[CharacterCodes["backslash"] = 92] = "backslash";
CharacterCodes[CharacterCodes["backtick"] = 96] = "backtick";
CharacterCodes[CharacterCodes["bar"] = 124] = "bar";
CharacterCodes[CharacterCodes["caret"] = 94] = "caret";
CharacterCodes[CharacterCodes["closeBrace"] = 125] = "closeBrace";
CharacterCodes[CharacterCodes["closeBracket"] = 93] = "closeBracket";
CharacterCodes[CharacterCodes["closeParen"] = 41] = "closeParen";
CharacterCodes[CharacterCodes["colon"] = 58] = "colon";
CharacterCodes[CharacterCodes["comma"] = 44] = "comma";
CharacterCodes[CharacterCodes["dot"] = 46] = "dot";
CharacterCodes[CharacterCodes["doubleQuote"] = 34] = "doubleQuote";
CharacterCodes[CharacterCodes["equals"] = 61] = "equals";
CharacterCodes[CharacterCodes["exclamation"] = 33] = "exclamation";
CharacterCodes[CharacterCodes["greaterThan"] = 62] = "greaterThan";
CharacterCodes[CharacterCodes["hash"] = 35] = "hash";
CharacterCodes[CharacterCodes["lessThan"] = 60] = "lessThan";
CharacterCodes[CharacterCodes["minus"] = 45] = "minus";
CharacterCodes[CharacterCodes["openBrace"] = 123] = "openBrace";
CharacterCodes[CharacterCodes["openBracket"] = 91] = "openBracket";
CharacterCodes[CharacterCodes["openParen"] = 40] = "openParen";
CharacterCodes[CharacterCodes["percent"] = 37] = "percent";
CharacterCodes[CharacterCodes["plus"] = 43] = "plus";
CharacterCodes[CharacterCodes["question"] = 63] = "question";
CharacterCodes[CharacterCodes["semicolon"] = 59] = "semicolon";
CharacterCodes[CharacterCodes["singleQuote"] = 39] = "singleQuote";
CharacterCodes[CharacterCodes["slash"] = 47] = "slash";
CharacterCodes[CharacterCodes["tilde"] = 126] = "tilde";
CharacterCodes[CharacterCodes["backspace"] = 8] = "backspace";
CharacterCodes[CharacterCodes["formFeed"] = 12] = "formFeed";
CharacterCodes[CharacterCodes["byteOrderMark"] = 65279] = "byteOrderMark";
CharacterCodes[CharacterCodes["tab"] = 9] = "tab";
CharacterCodes[CharacterCodes["verticalTab"] = 11] = "verticalTab";
})(ts.CharacterCodes || (ts.CharacterCodes = {}));
var CharacterCodes = ts.CharacterCodes;
})(ts || (ts = {}));
/// <reference path="types.ts"/>
/* @internal */
var ts;
(function (ts) {
/**
* Ternary values are defined such that
* x & y is False if either x or y is False.
* x & y is Maybe if either x or y is Maybe, but neither x or y is False.
* x & y is True if both x and y are True.
* x | y is False if both x and y are False.
* x | y is Maybe if either x or y is Maybe, but neither x or y is True.
* x | y is True if either x or y is True.
*/
(function (Ternary) {
Ternary[Ternary["False"] = 0] = "False";
Ternary[Ternary["Maybe"] = 1] = "Maybe";
Ternary[Ternary["True"] = -1] = "True";
})(ts.Ternary || (ts.Ternary = {}));
var Ternary = ts.Ternary;
function createFileMap(getCanonicalFileName) {
var files = {};
return {
get: get,
set: set,
contains: contains,
remove: remove,
clear: clear,
forEachValue: forEachValueInMap
};
function set(fileName, value) {
files[normalizeKey(fileName)] = value;
}
function get(fileName) {
return files[normalizeKey(fileName)];
}
function contains(fileName) {
return hasProperty(files, normalizeKey(fileName));
}
function remove(fileName) {
var key = normalizeKey(fileName);
delete files[key];
}
function forEachValueInMap(f) {
forEachValue(files, f);
}
function normalizeKey(key) {
return getCanonicalFileName(normalizeSlashes(key));
}
function clear() {
files = {};
}
}
ts.createFileMap = createFileMap;
(function (Comparison) {
Comparison[Comparison["LessThan"] = -1] = "LessThan";
Comparison[Comparison["EqualTo"] = 0] = "EqualTo";
Comparison[Comparison["GreaterThan"] = 1] = "GreaterThan";
})(ts.Comparison || (ts.Comparison = {}));
var Comparison = ts.Comparison;
/**
* Iterates through 'array' by index and performs the callback on each element of array until the callback
* returns a truthy value, then returns that value.
* If no such value is found, the callback is applied to each element of array and undefined is returned.
*/
function 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;
}
ts.forEach = forEach;
function contains(array, value) {
if (array) {
for (var _i = 0; _i < array.length; _i++) {
var v = array[_i];
if (v === value) {
return true;
}
}
}
return false;
}
ts.contains = contains;
function indexOf(array, value) {
if (array) {
for (var i = 0, len = array.length; i < len; i++) {
if (array[i] === value) {
return i;
}
}
}
return -1;
}
ts.indexOf = indexOf;
function countWhere(array, predicate) {
var count = 0;
if (array) {
for (var _i = 0; _i < array.length; _i++) {
var v = array[_i];
if (predicate(v)) {
count++;
}
}
}
return count;
}
ts.countWhere = countWhere;
function filter(array, f) {
var result;
if (array) {
result = [];
for (var _i = 0; _i < array.length; _i++) {
var item = array[_i];
if (f(item)) {
result.push(item);
}
}
}
return result;
}
ts.filter = filter;
function map(array, f) {
var result;
if (array) {
result = [];
for (var _i = 0; _i < array.length; _i++) {
var v = array[_i];
result.push(f(v));
}
}
return result;
}
ts.map = map;
function concatenate(array1, array2) {
if (!array2 || !array2.length)
return array1;
if (!array1 || !array1.length)
return array2;
return array1.concat(array2);
}
ts.concatenate = concatenate;
function deduplicate(array) {
var result;
if (array) {
result = [];
for (var _i = 0; _i < array.length; _i++) {
var item = array[_i];
if (!contains(result, item)) {
result.push(item);
}
}
}
return result;
}
ts.deduplicate = deduplicate;
function sum(array, prop) {
var result = 0;
for (var _i = 0; _i < array.length; _i++) {
var v = array[_i];
result += v[prop];
}
return result;
}
ts.sum = sum;
function addRange(to, from) {
if (to && from) {
for (var _i = 0; _i < from.length; _i++) {
var v = from[_i];
to.push(v);
}
}
}
ts.addRange = addRange;
function rangeEquals(array1, array2, pos, end) {
while (pos < end) {
if (array1[pos] !== array2[pos]) {
return false;
}
pos++;
}
return true;
}
ts.rangeEquals = rangeEquals;
/**
* Returns the last element of an array if non-empty, undefined otherwise.
*/
function lastOrUndefined(array) {
if (array.length === 0) {
return undefined;
}
return array[array.length - 1];
}
ts.lastOrUndefined = lastOrUndefined;
/**
* Performs a binary search, finding the index at which 'value' occurs in 'array'.
* If no such index is found, returns the 2's-complement of first index at which
* number[index] exceeds number.
* @param array A sorted array whose first element must be no larger than number
* @param number The value to be searched for in the array.
*/
function binarySearch(array, value) {
var low = 0;
var high = array.length - 1;
while (low <= high) {
var middle = low + ((high - low) >> 1);
var midValue = array[middle];
if (midValue === value) {
return middle;
}
else if (midValue > value) {
high = middle - 1;
}
else {
low = middle + 1;
}
}
return ~low;
}
ts.binarySearch = binarySearch;
function reduceLeft(array, f, initial) {
if (array) {
var count = array.length;
if (count > 0) {
var pos = 0;
var result = arguments.length <= 2 ? array[pos++] : initial;
while (pos < count) {
result = f(result, array[pos++]);
}
return result;
}
}
return initial;
}
ts.reduceLeft = reduceLeft;
function reduceRight(array, f, initial) {
if (array) {
var pos = array.length - 1;
if (pos >= 0) {
var result = arguments.length <= 2 ? array[pos--] : initial;
while (pos >= 0) {
result = f(result, array[pos--]);
}
return result;
}
}
return initial;
}
ts.reduceRight = reduceRight;
var hasOwnProperty = Object.prototype.hasOwnProperty;
function hasProperty(map, key) {
return hasOwnProperty.call(map, key);
}
ts.hasProperty = hasProperty;
function getProperty(map, key) {
return hasOwnProperty.call(map, key) ? map[key] : undefined;
}
ts.getProperty = getProperty;
function isEmpty(map) {
for (var id in map) {
if (hasProperty(map, id)) {
return false;
}
}
return true;
}
ts.isEmpty = isEmpty;
function clone(object) {
var result = {};
for (var id in object) {
result[id] = object[id];
}
return result;
}
ts.clone = clone;
function extend(first, second) {
var result = {};
for (var id in first) {
result[id] = first[id];
}
for (var id in second) {
if (!hasProperty(result, id)) {
result[id] = second[id];
}
}
return result;
}
ts.extend = extend;
function forEachValue(map, callback) {
var result;
for (var id in map) {
if (result = callback(map[id]))
break;
}
return result;
}
ts.forEachValue = forEachValue;
function forEachKey(map, callback) {
var result;
for (var id in map) {
if (result = callback(id))
break;
}
return result;
}
ts.forEachKey = forEachKey;
function lookUp(map, key) {
return hasProperty(map, key) ? map[key] : undefined;
}
ts.lookUp = lookUp;
function copyMap(source, target) {
for (var p in source) {
target[p] = source[p];
}
}
ts.copyMap = copyMap;
/**
* Creates a map from the elements of an array.
*
* @param array the array of input elements.
* @param makeKey a function that produces a key for a given element.
*
* This function makes no effort to avoid collisions; if any two elements produce
* the same key with the given 'makeKey' function, then the element with the higher
* index in the array will be the one associated with the produced key.
*/
function arrayToMap(array, makeKey) {
var result = {};
forEach(array, function (value) {
result[makeKey(value)] = value;
});
return result;
}
ts.arrayToMap = arrayToMap;
function memoize(callback) {
var value;
return function () {
if (callback) {
value = callback();
callback = undefined;
}
return value;
};
}
ts.memoize = memoize;
function formatStringFromArgs(text, args, baseIndex) {
baseIndex = baseIndex || 0;
return text.replace(/{(\d+)}/g, function (match, index) { return args[+index + baseIndex]; });
}
ts.localizedDiagnosticMessages = undefined;
function getLocaleSpecificMessage(message) {
return ts.localizedDiagnosticMessages && ts.localizedDiagnosticMessages[message]
? ts.localizedDiagnosticMessages[message]
: message;
}
ts.getLocaleSpecificMessage = getLocaleSpecificMessage;
function createFileDiagnostic(file, start, length, message) {
var end = start + length;
Debug.assert(start >= 0, "start must be non-negative, is " + start);
Debug.assert(length >= 0, "length must be non-negative, is " + length);
if (file) {
Debug.assert(start <= file.text.length, "start must be within the bounds of the file. " + start + " > " + file.text.length);
Debug.assert(end <= file.text.length, "end must be the bounds of the file. " + end + " > " + file.text.length);
}
var text = getLocaleSpecificMessage(message.key);
if (arguments.length > 4) {
text = formatStringFromArgs(text, arguments, 4);
}
return {
file: file,
start: start,
length: length,
messageText: text,
category: message.category,
code: message.code
};
}
ts.createFileDiagnostic = createFileDiagnostic;
function createCompilerDiagnostic(message) {
var text = getLocaleSpecificMessage(message.key);
if (arguments.length > 1) {
text = formatStringFromArgs(text, arguments, 1);
}
return {
file: undefined,
start: undefined,
length: undefined,
messageText: text,
category: message.category,
code: message.code
};
}
ts.createCompilerDiagnostic = createCompilerDiagnostic;
function chainDiagnosticMessages(details, message) {
var text = getLocaleSpecificMessage(message.key);
if (arguments.length > 2) {
text = formatStringFromArgs(text, arguments, 2);
}
return {
messageText: text,
category: message.category,
code: message.code,
next: details
};
}
ts.chainDiagnosticMessages = chainDiagnosticMessages;
function concatenateDiagnosticMessageChains(headChain, tailChain) {
Debug.assert(!headChain.next);
headChain.next = tailChain;
return headChain;
}
ts.concatenateDiagnosticMessageChains = concatenateDiagnosticMessageChains;
function compareValues(a, b) {
if (a === b)
return 0 /* EqualTo */;
if (a === undefined)
return -1 /* LessThan */;
if (b === undefined)
return 1 /* GreaterThan */;
return a < b ? -1 /* LessThan */ : 1 /* GreaterThan */;
}
ts.compareValues = compareValues;
function getDiagnosticFileName(diagnostic) {
return diagnostic.file ? diagnostic.file.fileName : undefined;
}
function compareDiagnostics(d1, d2) {
return compareValues(getDiagnosticFileName(d1), getDiagnosticFileName(d2)) ||
compareValues(d1.start, d2.start) ||
compareValues(d1.length, d2.length) ||
compareValues(d1.code, d2.code) ||
compareMessageText(d1.messageText, d2.messageText) ||
0 /* EqualTo */;
}
ts.compareDiagnostics = compareDiagnostics;
function compareMessageText(text1, text2) {
while (text1 && text2) {
// We still have both chains.
var string1 = typeof text1 === "string" ? text1 : text1.messageText;
var string2 = typeof text2 === "string" ? text2 : text2.messageText;
var res = compareValues(string1, string2);
if (res) {
return res;
}
text1 = typeof text1 === "string" ? undefined : text1.next;
text2 = typeof text2 === "string" ? undefined : text2.next;
}
if (!text1 && !text2) {
// if the chains are done, then these messages are the same.
return 0 /* EqualTo */;
}
// We still have one chain remaining. The shorter chain should come first.
return text1 ? 1 /* GreaterThan */ : -1 /* LessThan */;
}
function sortAndDeduplicateDiagnostics(diagnostics) {
return deduplicateSortedDiagnostics(diagnostics.sort(compareDiagnostics));
}
ts.sortAndDeduplicateDiagnostics = sortAndDeduplicateDiagnostics;
function deduplicateSortedDiagnostics(diagnostics) {
if (diagnostics.length < 2) {
return diagnostics;
}
var newDiagnostics = [diagnostics[0]];
var previousDiagnostic = diagnostics[0];
for (var i = 1; i < diagnostics.length; i++) {
var currentDiagnostic = diagnostics[i];
var isDupe = compareDiagnostics(currentDiagnostic, previousDiagnostic) === 0 /* EqualTo */;
if (!isDupe) {
newDiagnostics.push(currentDiagnostic);
previousDiagnostic = currentDiagnostic;
}
}
return newDiagnostics;
}
ts.deduplicateSortedDiagnostics = deduplicateSortedDiagnostics;
function normalizeSlashes(path) {
return path.replace(/\\/g, "/");
}
ts.normalizeSlashes = normalizeSlashes;
// Returns length of path root (i.e. length of "/", "x:/", "//server/share/, file:///user/files")
function getRootLength(path) {
if (path.charCodeAt(0) === 47 /* slash */) {
if (path.charCodeAt(1) !== 47 /* slash */)
return 1;
var p1 = path.indexOf("/", 2);
if (p1 < 0)
return 2;
var p2 = path.indexOf("/", p1 + 1);
if (p2 < 0)
return p1 + 1;
return p2 + 1;
}
if (path.charCodeAt(1) === 58 /* colon */) {
if (path.charCodeAt(2) === 47 /* slash */)
return 3;
return 2;
}
// Per RFC 1738 'file' URI schema has the shape file://<host>/<path>
// if <host> is omitted then it is assumed that host value is 'localhost',
// however slash after the omitted <host> is not removed.
// file:///folder1/file1 - this is a correct URI
// file://folder2/file2 - this is an incorrect URI
if (path.lastIndexOf("file:///", 0) === 0) {
return "file:///".length;
}
var idx = path.indexOf("://");
if (idx !== -1) {
return idx + "://".length;
}
return 0;
}
ts.getRootLength = getRootLength;
ts.directorySeparator = "/";
function getNormalizedParts(normalizedSlashedPath, rootLength) {
var parts = normalizedSlashedPath.substr(rootLength).split(ts.directorySeparator);
var normalized = [];
for (var _i = 0; _i < parts.length; _i++) {
var part = parts[_i];
if (part !== ".") {
if (part === ".." && normalized.length > 0 && lastOrUndefined(normalized) !== "..") {
normalized.pop();
}
else {
// A part may be an empty string (which is 'falsy') if the path had consecutive slashes,
// e.g. "path//file.ts". Drop these before re-joining the parts.
if (part) {
normalized.push(part);
}
}
}
}
return normalized;
}
function normalizePath(path) {
path = normalizeSlashes(path);
var rootLength = getRootLength(path);
var normalized = getNormalizedParts(path, rootLength);
return path.substr(0, rootLength) + normalized.join(ts.directorySeparator);
}
ts.normalizePath = normalizePath;
function getDirectoryPath(path) {
return path.substr(0, Math.max(getRootLength(path), path.lastIndexOf(ts.directorySeparator)));
}
ts.getDirectoryPath = getDirectoryPath;
function isUrl(path) {
return path && !isRootedDiskPath(path) && path.indexOf("://") !== -1;
}
ts.isUrl = isUrl;
function isRootedDiskPath(path) {
return getRootLength(path) !== 0;
}
ts.isRootedDiskPath = isRootedDiskPath;
function normalizedPathComponents(path, rootLength) {
var normalizedParts = getNormalizedParts(path, rootLength);
return [path.substr(0, rootLength)].concat(normalizedParts);
}
function getNormalizedPathComponents(path, currentDirectory) {
path = normalizeSlashes(path);
var rootLength = getRootLength(path);
if (rootLength === 0) {
// If the path is not rooted it is relative to current directory
path = combinePaths(normalizeSlashes(currentDirectory), path);
rootLength = getRootLength(path);
}
return normalizedPathComponents(path, rootLength);
}
ts.getNormalizedPathComponents = getNormalizedPathComponents;
function getNormalizedAbsolutePath(fileName, currentDirectory) {
return getNormalizedPathFromPathComponents(getNormalizedPathComponents(fileName, currentDirectory));
}
ts.getNormalizedAbsolutePath = getNormalizedAbsolutePath;
function getNormalizedPathFromPathComponents(pathComponents) {
if (pathComponents && pathComponents.length) {
return pathComponents[0] + pathComponents.slice(1).join(ts.directorySeparator);
}
}
ts.getNormalizedPathFromPathComponents = getNormalizedPathFromPathComponents;
function getNormalizedPathComponentsOfUrl(url) {
// Get root length of http://www.website.com/folder1/foler2/
// In this example the root is: http://www.website.com/
// normalized path components should be ["http://www.website.com/", "folder1", "folder2"]
var urlLength = url.length;
// Initial root length is http:// part
var rootLength = url.indexOf("://") + "://".length;
while (rootLength < urlLength) {
// Consume all immediate slashes in the protocol
// eg.initial rootlength is just file:// but it needs to consume another "/" in file:///
if (url.charCodeAt(rootLength) === 47 /* slash */) {
rootLength++;
}
else {
// non slash character means we continue proceeding to next component of root search
break;
}
}
// there are no parts after http:// just return current string as the pathComponent
if (rootLength === urlLength) {
return [url];
}
// Find the index of "/" after website.com so the root can be http://www.website.com/ (from existing http://)
var indexOfNextSlash = url.indexOf(ts.directorySeparator, rootLength);
if (indexOfNextSlash !== -1) {
// Found the "/" after the website.com so the root is length of http://www.website.com/
// and get components afetr the root normally like any other folder components
rootLength = indexOfNextSlash + 1;
return normalizedPathComponents(url, rootLength);
}
else {
// Can't find the host assume the rest of the string as component
// but make sure we append "/" to it as root is not joined using "/"
// eg. if url passed in was http://website.com we want to use root as [http://website.com/]
// so that other path manipulations will be correct and it can be merged with relative paths correctly
return [url + ts.directorySeparator];
}
}
function getNormalizedPathOrUrlComponents(pathOrUrl, currentDirectory) {
if (isUrl(pathOrUrl)) {
return getNormalizedPathComponentsOfUrl(pathOrUrl);
}
else {
return getNormalizedPathComponents(pathOrUrl, currentDirectory);
}
}
function getRelativePathToDirectoryOrUrl(directoryPathOrUrl, relativeOrAbsolutePath, currentDirectory, getCanonicalFileName, isAbsolutePathAnUrl) {
var pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, currentDirectory);
var directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, currentDirectory);
if (directoryComponents.length > 1 && lastOrUndefined(directoryComponents) === "") {
// If the directory path given was of type test/cases/ then we really need components of directory to be only till its name
// that is ["test", "cases", ""] needs to be actually ["test", "cases"]
directoryComponents.length--;
}
// Find the component that differs
for (var joinStartIndex = 0; joinStartIndex < pathComponents.length && joinStartIndex < directoryComponents.length; joinStartIndex++) {
if (getCanonicalFileName(directoryComponents[joinStartIndex]) !== getCanonicalFileName(pathComponents[joinStartIndex])) {
break;
}
}
// Get the relative path
if (joinStartIndex) {
var relativePath = "";
var relativePathComponents = pathComponents.slice(joinStartIndex, pathComponents.length);
for (; joinStartIndex < directoryComponents.length; joinStartIndex++) {
if (directoryComponents[joinStartIndex] !== "") {
relativePath = relativePath + ".." + ts.directorySeparator;
}
}
return relativePath + relativePathComponents.join(ts.directorySeparator);
}
// Cant find the relative path, get the absolute path
var absolutePath = getNormalizedPathFromPathComponents(pathComponents);
if (isAbsolutePathAnUrl && isRootedDiskPath(absolutePath)) {
absolutePath = "file:///" + absolutePath;
}
return absolutePath;
}
ts.getRelativePathToDirectoryOrUrl = getRelativePathToDirectoryOrUrl;
function getBaseFileName(path) {
var i = path.lastIndexOf(ts.directorySeparator);
return i < 0 ? path : path.substring(i + 1);
}
ts.getBaseFileName = getBaseFileName;
function combinePaths(path1, path2) {
if (!(path1 && path1.length))
return path2;
if (!(path2 && path2.length))
return path1;
if (getRootLength(path2) !== 0)
return path2;
if (path1.charAt(path1.length - 1) === ts.directorySeparator)
return path1 + path2;
return path1 + ts.directorySeparator + path2;
}
ts.combinePaths = combinePaths;
function fileExtensionIs(path, extension) {
var pathLen = path.length;
var extLen = extension.length;
return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension;
}
ts.fileExtensionIs = fileExtensionIs;
/**
* List of supported extensions in order of file resolution precedence.
*/
ts.supportedExtensions = [".ts", ".tsx", ".d.ts"];
var extensionsToRemove = [".d.ts", ".ts", ".js", ".tsx", ".jsx"];
function removeFileExtension(path) {
for (var _i = 0; _i < extensionsToRemove.length; _i++) {
var ext = extensionsToRemove[_i];
if (fileExtensionIs(path, ext)) {
return path.substr(0, path.length - ext.length);
}
}
return path;
}
ts.removeFileExtension = removeFileExtension;
var backslashOrDoubleQuote = /[\"\\]/g;
var escapedCharsRegExp = /[\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
var escapedCharsMap = {
"\0": "\\0",
"\t": "\\t",
"\v": "\\v",
"\f": "\\f",
"\b": "\\b",
"\r": "\\r",
"\n": "\\n",
"\\": "\\\\",
"\"": "\\\"",
"\u2028": "\\u2028",
"\u2029": "\\u2029",
"\u0085": "\\u0085" // nextLine
};
function Symbol(flags, name) {
this.flags = flags;
this.name = name;
this.declarations = undefined;
}
function Type(checker, flags) {
this.flags = flags;
}
function Signature(checker) {
}
ts.objectAllocator = {
getNodeConstructor: function (kind) {
function Node() {
}
Node.prototype = {
kind: kind,
pos: -1,
end: -1,
flags: 0,
parent: undefined
};
return Node;
},
getSymbolConstructor: function () { return Symbol; },
getTypeConstructor: function () { return Type; },
getSignatureConstructor: function () { return Signature; }
};
(function (AssertionLevel) {
AssertionLevel[AssertionLevel["None"] = 0] = "None";
AssertionLevel[AssertionLevel["Normal"] = 1] = "Normal";
AssertionLevel[AssertionLevel["Aggressive"] = 2] = "Aggressive";
AssertionLevel[AssertionLevel["VeryAggressive"] = 3] = "VeryAggressive";
})(ts.AssertionLevel || (ts.AssertionLevel = {}));
var AssertionLevel = ts.AssertionLevel;
var Debug;
(function (Debug) {
var currentAssertionLevel = 0 /* None */;
function shouldAssert(level) {
return currentAssertionLevel >= level;
}
Debug.shouldAssert = shouldAssert;
function assert(expression, message, verboseDebugInfo) {
if (!expression) {
var verboseDebugString = "";
if (verboseDebugInfo) {
verboseDebugString = "\r\nVerbose Debug Information: " + verboseDebugInfo();
}
throw new Error("Debug Failure. False expression: " + (message || "") + verboseDebugString);
}
}
Debug.assert = assert;
function fail(message) {
Debug.assert(false, message);
}
Debug.fail = fail;
})(Debug = ts.Debug || (ts.Debug = {}));
})(ts || (ts = {}));
/// <reference path="core.ts"/>
var ts;
(function (ts) {
ts.sys = (function () {
function getWScriptSystem() {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fileStream = new ActiveXObject("ADODB.Stream");
fileStream.Type = 2 /*text*/;
var binaryStream = new ActiveXObject("ADODB.Stream");
binaryStream.Type = 1 /*binary*/;
var args = [];
for (var i = 0; i < WScript.Arguments.length; i++) {
args[i] = WScript.Arguments.Item(i);
}
function readFile(fileName, encoding) {
if (!fso.FileExists(fileName)) {
return undefined;
}
fileStream.Open();
try {
if (encoding) {
fileStream.Charset = encoding;
fileStream.LoadFromFile(fileName);
}
else {
// Load file and read the first two bytes into a string with no interpretation
fileStream.Charset = "x-ansi";
fileStream.LoadFromFile(fileName);
var bom = fileStream.ReadText(2) || "";
// Position must be at 0 before encoding can be changed
fileStream.Position = 0;
// [0xFF,0xFE] and [0xFE,0xFF] mean utf-16 (little or big endian), otherwise default to utf-8
fileStream.Charset = bom.length >= 2 && (bom.charCodeAt(0) === 0xFF && bom.charCodeAt(1) === 0xFE || bom.charCodeAt(0) === 0xFE && bom.charCodeAt(1) === 0xFF) ? "unicode" : "utf-8";
}
// ReadText method always strips byte order mark from resulting string
return fileStream.ReadText();
}
catch (e) {
throw e;
}
finally {
fileStream.Close();
}
}
function writeFile(fileName, data, writeByteOrderMark) {
fileStream.Open();
binaryStream.Open();
try {
// Write characters in UTF-8 encoding
fileStream.Charset = "utf-8";
fileStream.WriteText(data);
// If we don't want the BOM, then skip it by setting the starting location to 3 (size of BOM).
// If not, start from position 0, as the BOM will be added automatically when charset==utf8.
if (writeByteOrderMark) {
fileStream.Position = 0;
}
else {
fileStream.Position = 3;
}
fileStream.CopyTo(binaryStream);
binaryStream.SaveToFile(fileName, 2 /*overwrite*/);
}
finally {
binaryStream.Close();
fileStream.Close();
}
}
function getCanonicalPath(path) {
return path.toLowerCase();
}
function getNames(collection) {
var result = [];
for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) {
result.push(e.item().Name);
}
return result.sort();
}
function readDirectory(path, extension, exclude) {
var result = [];
exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); });
visitDirectory(path);
return result;
function visitDirectory(path) {
var folder = fso.GetFolder(path || ".");
var files = getNames(folder.files);
for (var _i = 0; _i < files.length; _i++) {
var current = files[_i];
var name_1 = ts.combinePaths(path, current);
if ((!extension || ts.fileExtensionIs(name_1, extension)) && !ts.contains(exclude, getCanonicalPath(name_1))) {
result.push(name_1);
}
}
var subfolders = getNames(folder.subfolders);
for (var _a = 0; _a < subfolders.length; _a++) {
var current = subfolders[_a];
var name_2 = ts.combinePaths(path, current);
if (!ts.contains(exclude, getCanonicalPath(name_2))) {
visitDirectory(name_2);
}
}
}
}
return {
args: args,
newLine: "\r\n",
useCaseSensitiveFileNames: false,
write: function (s) {
WScript.StdOut.Write(s);
},
readFile: readFile,
writeFile: writeFile,
resolvePath: function (path) {
return fso.GetAbsolutePathName(path);
},
fileExists: function (path) {
return fso.FileExists(path);
},
directoryExists: function (path) {
return fso.FolderExists(path);
},
createDirectory: function (directoryName) {
if (!this.directoryExists(directoryName)) {
fso.CreateFolder(directoryName);
}
},
getExecutingFilePath: function () {
return WScript.ScriptFullName;
},
getCurrentDirectory: function () {
return new ActiveXObject("WScript.Shell").CurrentDirectory;
},
readDirectory: readDirectory,
exit: function (exitCode) {
try {
WScript.Quit(exitCode);
}
catch (e) {
}
}
};
}
function getNodeSystem() {
var _fs = require("fs");
var _path = require("path");
var _os = require("os");
var platform = _os.platform();
// win32\win64 are case insensitive platforms, MacOS (darwin) by default is also case insensitive
var useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin";
function readFile(fileName, encoding) {
if (!_fs.existsSync(fileName)) {
return undefined;
}
var buffer = _fs.readFileSync(fileName);
var len = buffer.length;
if (len >= 2 && buffer[0] === 0xFE && buffer[1] === 0xFF) {
// Big endian UTF-16 byte order mark detected. Since big endian is not supported by node.js,
// flip all byte pairs and treat as little endian.
len &= ~1;
for (var i = 0; i < len; i += 2) {
var temp = buffer[i];
buffer[i] = buffer[i + 1];
buffer[i + 1] = temp;
}
return buffer.toString("utf16le", 2);
}
if (len >= 2 && buffer[0] === 0xFF && buffer[1] === 0xFE) {
// Little endian UTF-16 byte order mark detected
return buffer.toString("utf16le", 2);
}
if (len >= 3 && buffer[0] === 0xEF && buffer[1] === 0xBB && buffer[2] === 0xBF) {
// UTF-8 byte order mark detected
return buffer.toString("utf8", 3);
}
// Default is UTF-8 with no byte order mark
return buffer.toString("utf8");
}
function writeFile(fileName, data, writeByteOrderMark) {
// If a BOM is required, emit one
if (writeByteOrderMark) {
data = "\uFEFF" + data;
}
_fs.writeFileSync(fileName, data, "utf8");
}
function getCanonicalPath(path) {
return useCaseSensitiveFileNames ? path.toLowerCase() : path;
}
function readDirectory(path, extension, exclude) {
var result = [];
exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); });
visitDirectory(path);
return result;
function visitDirectory(path) {
var files = _fs.readdirSync(path || ".").sort();
var directories = [];
for (var _i = 0; _i < files.length; _i++) {
var current = files[_i];
var name_3 = ts.combinePaths(path, current);
if (!ts.contains(exclude, getCanonicalPath(name_3))) {
var stat = _fs.statSync(name_3);
if (stat.isFile()) {
if (!extension || ts.fileExtensionIs(name_3, extension)) {
result.push(name_3);
}
}
else if (stat.isDirectory()) {
directories.push(name_3);
}
}
}
for (var _a = 0; _a < directories.length; _a++) {
var current = directories[_a];
visitDirectory(current);
}
}
}
return {
args: process.argv.slice(2),
newLine: _os.EOL,
useCaseSensitiveFileNames: useCaseSensitiveFileNames,
write: function (s) {
var buffer = new Buffer(s, "utf8");
var offset = 0;
var toWrite = buffer.length;
var written = 0;
// 1 is a standard descriptor for stdout
while ((written = _fs.writeSync(1, buffer, offset, toWrite)) < toWrite) {
offset += written;
toWrite -= written;
}
},
readFile: readFile,
writeFile: writeFile,
watchFile: function (fileName, callback) {
// watchFile polls a file every 250ms, picking up file notifications.
_fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged);
return {
close: function () { _fs.unwatchFile(fileName, fileChanged); }
};
function fileChanged(curr, prev) {
if (+curr.mtime <= +prev.mtime) {
return;
}
callback(fileName);
}
},
resolvePath: function (path) {
return _path.resolve(path);
},
fileExists: function (path) {
return _fs.existsSync(path);
},
directoryExists: function (path) {
return _fs.existsSync(path) && _fs.statSync(path).isDirectory();
},
createDirectory: function (directoryName) {
if (!this.directoryExists(directoryName)) {
_fs.mkdirSync(directoryName);
}
},
getExecutingFilePath: function () {
return __filename;
},
getCurrentDirectory: function () {
return process.cwd();
},
readDirectory: readDirectory,
getMemoryUsage: function () {
if (global.gc) {
global.gc();
}
return process.memoryUsage().heapUsed;
},
exit: function (exitCode) {
process.exit(exitCode);
}
};
}
if (typeof WScript !== "undefined" && typeof ActiveXObject === "function") {
return getWScriptSystem();
}
else if (typeof process !== "undefined" && process.nextTick && !process.browser && typeof require !== "undefined") {
// process and process.nextTick checks if current environment is node-like
// process.browser check excludes webpack and browserify
return getNodeSystem();
}
else {
return undefined; // Unsupported host
}
})();
})(ts || (ts = {}));
// <auto-generated />
/// <reference path="types.ts" />
/* @internal */
var ts;
(function (ts) {
ts.Diagnostics = {
Unterminated_string_literal: { code: 1002, category: ts.DiagnosticCategory.Error, key: "Unterminated string literal." },
Identifier_expected: { code: 1003, category: ts.DiagnosticCategory.Error, key: "Identifier expected." },
_0_expected: { code: 1005, category: ts.DiagnosticCategory.Error, key: "'{0}' expected." },
A_file_cannot_have_a_reference_to_itself: { code: 1006, category: ts.DiagnosticCategory.Error, key: "A file cannot have a reference to itself." },
Trailing_comma_not_allowed: { code: 1009, category: ts.DiagnosticCategory.Error, key: "Trailing comma not allowed." },
Asterisk_Slash_expected: { code: 1010, category: ts.DiagnosticCategory.Error, key: "'*/' expected." },
Unexpected_token: { code: 1012, category: ts.DiagnosticCategory.Error, key: "Unexpected token." },
A_rest_parameter_must_be_last_in_a_parameter_list: { code: 1014, category: ts.DiagnosticCategory.Error, key: "A rest parameter must be last in a parameter list." },
Parameter_cannot_have_question_mark_and_initializer: { code: 1015, category: ts.DiagnosticCategory.Error, key: "Parameter cannot have question mark and initializer." },
A_required_parameter_cannot_follow_an_optional_parameter: { code: 1016, category: ts.DiagnosticCategory.Error, key: "A required parameter cannot follow an optional parameter." },
An_index_signature_cannot_have_a_rest_parameter: { code: 1017, category: ts.DiagnosticCategory.Error, key: "An index signature cannot have a rest parameter." },
An_index_signature_parameter_cannot_have_an_accessibility_modifier: { code: 1018, category: ts.DiagnosticCategory.Error, key: "An index signature parameter cannot have an accessibility modifier." },
An_index_signature_parameter_cannot_have_a_question_mark: { code: 1019, category: ts.DiagnosticCategory.Error, key: "An index signature parameter cannot have a question mark." },
An_index_signature_parameter_cannot_have_an_initializer: { code: 1020, category: ts.DiagnosticCategory.Error, key: "An index signature parameter cannot have an initializer." },
An_index_signature_must_have_a_type_annotation: { code: 1021, category: ts.DiagnosticCategory.Error, key: "An index signature must have a type annotation." },
An_index_signature_parameter_must_have_a_type_annotation: { code: 1022, category: ts.DiagnosticCategory.Error, key: "An index signature parameter must have a type annotation." },
An_index_signature_parameter_type_must_be_string_or_number: { code: 1023, category: ts.DiagnosticCategory.Error, key: "An index signature parameter type must be 'string' or 'number'." },
Accessibility_modifier_already_seen: { code: 1028, category: ts.DiagnosticCategory.Error, key: "Accessibility modifier already seen." },
_0_modifier_must_precede_1_modifier: { code: 1029, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier must precede '{1}' modifier." },
_0_modifier_already_seen: { code: 1030, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier already seen." },
_0_modifier_cannot_appear_on_a_class_element: { code: 1031, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a class element." },
super_must_be_followed_by_an_argument_list_or_member_access: { code: 1034, category: ts.DiagnosticCategory.Error, key: "'super' must be followed by an argument list or member access." },
Only_ambient_modules_can_use_quoted_names: { code: 1035, category: ts.DiagnosticCategory.Error, key: "Only ambient modules can use quoted names." },
Statements_are_not_allowed_in_ambient_contexts: { code: 1036, category: ts.DiagnosticCategory.Error, key: "Statements are not allowed in ambient contexts." },
A_declare_modifier_cannot_be_used_in_an_already_ambient_context: { code: 1038, category: ts.DiagnosticCategory.Error, key: "A 'declare' modifier cannot be used in an already ambient context." },
Initializers_are_not_allowed_in_ambient_contexts: { code: 1039, category: ts.DiagnosticCategory.Error, key: "Initializers are not allowed in ambient contexts." },
_0_modifier_cannot_be_used_in_an_ambient_context: { code: 1040, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot be used in an ambient context." },
_0_modifier_cannot_be_used_with_a_class_declaration: { code: 1041, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot be used with a class declaration." },
_0_modifier_cannot_be_used_here: { code: 1042, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot be used here." },
_0_modifier_cannot_appear_on_a_data_property: { code: 1043, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a data property." },
_0_modifier_cannot_appear_on_a_module_element: { code: 1044, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a module element." },
A_0_modifier_cannot_be_used_with_an_interface_declaration: { code: 1045, category: ts.DiagnosticCategory.Error, key: "A '{0}' modifier cannot be used with an interface declaration." },
A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file: { code: 1046, category: ts.DiagnosticCategory.Error, key: "A 'declare' modifier is required for a top level declaration in a .d.ts file." },
A_rest_parameter_cannot_be_optional: { code: 1047, category: ts.DiagnosticCategory.Error, key: "A rest parameter cannot be optional." },
A_rest_parameter_cannot_have_an_initializer: { code: 1048, category: ts.DiagnosticCategory.Error, key: "A rest parameter cannot have an initializer." },
A_set_accessor_must_have_exactly_one_parameter: { code: 1049, category: ts.DiagnosticCategory.Error, key: "A 'set' accessor must have exactly one parameter." },
A_set_accessor_cannot_have_an_optional_parameter: { code: 1051, category: ts.DiagnosticCategory.Error, key: "A 'set' accessor cannot have an optional parameter." },
A_set_accessor_parameter_cannot_have_an_initializer: { code: 1052, category: ts.DiagnosticCategory.Error, key: "A 'set' accessor parameter cannot have an initializer." },
A_set_accessor_cannot_have_rest_parameter: { code: 1053, category: ts.DiagnosticCategory.Error, key: "A 'set' accessor cannot have rest parameter." },
A_get_accessor_cannot_have_parameters: { code: 1054, category: ts.DiagnosticCategory.Error, key: "A 'get' accessor cannot have parameters." },
Type_0_is_not_a_valid_async_function_return_type: { code: 1055, category: ts.DiagnosticCategory.Error, key: "Type '{0}' is not a valid async function return type." },
Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1056, category: ts.DiagnosticCategory.Error, key: "Accessors are only available when targeting ECMAScript 5 and higher." },
An_async_function_or_method_must_have_a_valid_awaitable_return_type: { code: 1057, category: ts.DiagnosticCategory.Error, key: "An async function or method must have a valid awaitable return type." },
Operand_for_await_does_not_have_a_valid_callable_then_member: { code: 1058, category: ts.DiagnosticCategory.Error, key: "Operand for 'await' does not have a valid callable 'then' member." },
Return_expression_in_async_function_does_not_have_a_valid_callable_then_member: { code: 1059, category: ts.DiagnosticCategory.Error, key: "Return expression in async function does not have a valid callable 'then' member." },
Expression_body_for_async_arrow_function_does_not_have_a_valid_callable_then_member: { code: 1060, category: ts.DiagnosticCategory.Error, key: "Expression body for async arrow function does not have a valid callable 'then' member." },
Enum_member_must_have_initializer: { code: 1061, category: ts.DiagnosticCategory.Error, key: "Enum member must have initializer." },
_0_is_referenced_directly_or_indirectly_in_the_fulfillment_callback_of_its_own_then_method: { code: 1062, category: ts.DiagnosticCategory.Error, key: "{0} is referenced directly or indirectly in the fulfillment callback of its own 'then' method." },
An_export_assignment_cannot_be_used_in_a_namespace: { code: 1063, category: ts.DiagnosticCategory.Error, key: "An export assignment cannot be used in a namespace." },
Ambient_enum_elements_can_only_have_integer_literal_initializers: { code: 1066, category: ts.DiagnosticCategory.Error, key: "Ambient enum elements can only have integer literal initializers." },
Unexpected_token_A_constructor_method_accessor_or_property_was_expected: { code: 1068, category: ts.DiagnosticCategory.Error, key: "Unexpected token. A constructor, method, accessor, or property was expected." },
A_0_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: ts.DiagnosticCategory.Error, key: "A '{0}' modifier cannot be used with an import declaration." },
Invalid_reference_directive_syntax: { code: 1084, category: ts.DiagnosticCategory.Error, key: "Invalid 'reference' directive syntax." },
Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher: { code: 1085, category: ts.DiagnosticCategory.Error, key: "Octal literals are not available when targeting ECMAScript 5 and higher." },
An_accessor_cannot_be_declared_in_an_ambient_context: { code: 1086, category: ts.DiagnosticCategory.Error, key: "An accessor cannot be declared in an ambient context." },
_0_modifier_cannot_appear_on_a_constructor_declaration: { code: 1089, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a constructor declaration." },
_0_modifier_cannot_appear_on_a_parameter: { code: 1090, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a parameter." },
Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement: { code: 1091, category: ts.DiagnosticCategory.Error, key: "Only a single variable declaration is allowed in a 'for...in' statement." },
Type_parameters_cannot_appear_on_a_constructor_declaration: { code: 1092, category: ts.DiagnosticCategory.Error, key: "Type parameters cannot appear on a constructor declaration." },
Type_annotation_cannot_appear_on_a_constructor_declaration: { code: 1093, category: ts.DiagnosticCategory.Error, key: "Type annotation cannot appear on a constructor declaration." },
An_accessor_cannot_have_type_parameters: { code: 1094, category: ts.DiagnosticCategory.Error, key: "An accessor cannot have type parameters." },
A_set_accessor_cannot_have_a_return_type_annotation: { code: 1095, category: ts.DiagnosticCategory.Error, key: "A 'set' accessor cannot have a return type annotation." },
An_index_signature_must_have_exactly_one_parameter: { code: 1096, category: ts.DiagnosticCategory.Error, key: "An index signature must have exactly one parameter." },
_0_list_cannot_be_empty: { code: 1097, category: ts.DiagnosticCategory.Error, key: "'{0}' list cannot be empty." },
Type_parameter_list_cannot_be_empty: { code: 1098, category: ts.DiagnosticCategory.Error, key: "Type parameter list cannot be empty." },
Type_argument_list_cannot_be_empty: { code: 1099, category: ts.DiagnosticCategory.Error, key: "Type argument list cannot be empty." },
Invalid_use_of_0_in_strict_mode: { code: 1100, category: ts.DiagnosticCategory.Error, key: "Invalid use of '{0}' in strict mode." },
with_statements_are_not_allowed_in_strict_mode: { code: 1101, category: ts.DiagnosticCategory.Error, key: "'with' statements are not allowed in strict mode." },
delete_cannot_be_called_on_an_identifier_in_strict_mode: { code: 1102, category: ts.DiagnosticCategory.Error, key: "'delete' cannot be called on an identifier in strict mode." },
A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement: { code: 1104, category: ts.DiagnosticCategory.Error, key: "A 'continue' statement can only be used within an enclosing iteration statement." },
A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement: { code: 1105, category: ts.DiagnosticCategory.Error, key: "A 'break' statement can only be used within an enclosing iteration or switch statement." },
Jump_target_cannot_cross_function_boundary: { code: 1107, category: ts.DiagnosticCategory.Error, key: "Jump target cannot cross function boundary." },
A_return_statement_can_only_be_used_within_a_function_body: { code: 1108, category: ts.DiagnosticCategory.Error, key: "A 'return' statement can only be used within a function body." },
Expression_expected: { code: 1109, category: ts.DiagnosticCategory.Error, key: "Expression expected." },
Type_expected: { code: 1110, category: ts.DiagnosticCategory.Error, key: "Type expected." },
A_class_member_cannot_be_declared_optional: { code: 1112, category: ts.DiagnosticCategory.Error, key: "A class member cannot be declared optional." },
A_default_clause_cannot_appear_more_than_once_in_a_switch_statement: { code: 1113, category: ts.DiagnosticCategory.Error, key: "A 'default' clause cannot appear more than once in a 'switch' statement." },
Duplicate_label_0: { code: 1114, category: ts.DiagnosticCategory.Error, key: "Duplicate label '{0}'" },
A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement: { code: 1115, category: ts.DiagnosticCategory.Error, key: "A 'continue' statement can only jump to a label of an enclosing iteration statement." },
A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement: { code: 1116, category: ts.DiagnosticCategory.Error, key: "A 'break' statement can only jump to a label of an enclosing statement." },
An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode: { code: 1117, category: ts.DiagnosticCategory.Error, key: "An object literal cannot have multiple properties with the same name in strict mode." },
An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name: { code: 1118, category: ts.DiagnosticCategory.Error, key: "An object literal cannot have multiple get/set accessors with the same name." },
An_object_literal_cannot_have_property_and_accessor_with_the_same_name: { code: 1119, category: ts.DiagnosticCategory.Error, key: "An object literal cannot have property and accessor with the same name." },
An_export_assignment_cannot_have_modifiers: { code: 1120, category: ts.DiagnosticCategory.Error, key: "An export assignment cannot have modifiers." },
Octal_literals_are_not_allowed_in_strict_mode: { code: 1121, category: ts.DiagnosticCategory.Error, key: "Octal literals are not allowed in strict mode." },
A_tuple_type_element_list_cannot_be_empty: { code: 1122, category: ts.DiagnosticCategory.Error, key: "A tuple type element list cannot be empty." },
Variable_declaration_list_cannot_be_empty: { code: 1123, category: ts.DiagnosticCategory.Error, key: "Variable declaration list cannot be empty." },
Digit_expected: { code: 1124, category: ts.DiagnosticCategory.Error, key: "Digit expected." },
Hexadecimal_digit_expected: { code: 1125, category: ts.DiagnosticCategory.Error, key: "Hexadecimal digit expected." },
Unexpected_end_of_text: { code: 1126, category: ts.DiagnosticCategory.Error, key: "Unexpected end of text." },
Invalid_character: { code: 1127, category: ts.DiagnosticCategory.Error, key: "Invalid character." },
Declaration_or_statement_expected: { code: 1128, category: ts.DiagnosticCategory.Error, key: "Declaration or statement expected." },
Statement_expected: { code: 1129, category: ts.DiagnosticCategory.Error, key: "Statement expected." },
case_or_default_expected: { code: 1130, category: ts.DiagnosticCategory.Error, key: "'case' or 'default' expected." },
Property_or_signature_expected: { code: 1131, category: ts.DiagnosticCategory.Error, key: "Property or signature expected." },
Enum_member_expected: { code: 1132, category: ts.DiagnosticCategory.Error, key: "Enum member expected." },
Variable_declaration_expected: { code: 1134, category: ts.DiagnosticCategory.Error, key: "Variable declaration expected." },
Argument_expression_expected: { code: 1135, category: ts.DiagnosticCategory.Error, key: "Argument expression expected." },
Property_assignment_expected: { code: 1136, category: ts.DiagnosticCategory.Error, key: "Property assignment expected." },
Expression_or_comma_expected: { code: 1137, category: ts.DiagnosticCategory.Error, key: "Expression or comma expected." },
Parameter_declaration_expected: { code: 1138, category: ts.DiagnosticCategory.Error, key: "Parameter declaration expected." },
Type_parameter_declaration_expected: { code: 1139, category: ts.DiagnosticCategory.Error, key: "Type parameter declaration expected." },
Type_argument_expected: { code: 1140, category: ts.DiagnosticCategory.Error, key: "Type argument expected." },
String_literal_expected: { code: 1141, category: ts.DiagnosticCategory.Error, key: "String literal expected." },
Line_break_not_permitted_here: { code: 1142, category: ts.DiagnosticCategory.Error, key: "Line break not permitted here." },
or_expected: { code: 1144, category: ts.DiagnosticCategory.Error, key: "'{' or ';' expected." },
Modifiers_not_permitted_on_index_signature_members: { code: 1145, category: ts.DiagnosticCategory.Error, key: "Modifiers not permitted on index signature members." },
Declaration_expected: { code: 1146, category: ts.DiagnosticCategory.Error, key: "Declaration expected." },
Import_declarations_in_a_namespace_cannot_reference_a_module: { code: 1147, category: ts.DiagnosticCategory.Error, key: "Import declarations in a namespace cannot reference a module." },
Cannot_compile_modules_unless_the_module_flag_is_provided: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot compile modules unless the '--module' flag is provided." },
File_name_0_differs_from_already_included_file_name_1_only_in_casing: { code: 1149, category: ts.DiagnosticCategory.Error, key: "File name '{0}' differs from already included file name '{1}' only in casing" },
new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: ts.DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead." },
const_declarations_must_be_initialized: { code: 1155, category: ts.DiagnosticCategory.Error, key: "'const' declarations must be initialized" },
const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: ts.DiagnosticCategory.Error, key: "'const' declarations can only be declared inside a block." },
let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: ts.DiagnosticCategory.Error, key: "'let' declarations can only be declared inside a block." },
Unterminated_template_literal: { code: 1160, category: ts.DiagnosticCategory.Error, key: "Unterminated template literal." },
Unterminated_regular_expression_literal: { code: 1161, category: ts.DiagnosticCategory.Error, key: "Unterminated regular expression literal." },
An_object_member_cannot_be_declared_optional: { code: 1162, category: ts.DiagnosticCategory.Error, key: "An object member cannot be declared optional." },
A_yield_expression_is_only_allowed_in_a_generator_body: { code: 1163, category: ts.DiagnosticCategory.Error, key: "A 'yield' expression is only allowed in a generator body." },
Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: ts.DiagnosticCategory.Error, key: "Computed property names are not allowed in enums." },
A_computed_property_name_in_an_ambient_context_must_directly_refer_to_a_built_in_symbol: { code: 1165, category: ts.DiagnosticCategory.Error, key: "A computed property name in an ambient context must directly refer to a built-in symbol." },
A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol: { code: 1166, category: ts.DiagnosticCategory.Error, key: "A computed property name in a class property declaration must directly refer to a built-in symbol." },
A_computed_property_name_in_a_method_overload_must_directly_refer_to_a_built_in_symbol: { code: 1168, category: ts.DiagnosticCategory.Error, key: "A computed property name in a method overload must directly refer to a built-in symbol." },
A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol: { code: 1169, category: ts.DiagnosticCategory.Error, key: "A computed property name in an interface must directly refer to a built-in symbol." },
A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol: { code: 1170, category: ts.DiagnosticCategory.Error, key: "A computed property name in a type literal must directly refer to a built-in symbol." },
A_comma_expression_is_not_allowed_in_a_computed_property_name: { code: 1171, category: ts.DiagnosticCategory.Error, key: "A comma expression is not allowed in a computed property name." },
extends_clause_already_seen: { code: 1172, category: ts.DiagnosticCategory.Error, key: "'extends' clause already seen." },
extends_clause_must_precede_implements_clause: { code: 1173, category: ts.DiagnosticCategory.Error, key: "'extends' clause must precede 'implements' clause." },
Classes_can_only_extend_a_single_class: { code: 1174, category: ts.DiagnosticCategory.Error, key: "Classes can only extend a single class." },
implements_clause_already_seen: { code: 1175, category: ts.DiagnosticCategory.Error, key: "'implements' clause already seen." },
Interface_declaration_cannot_have_implements_clause: { code: 1176, category: ts.DiagnosticCategory.Error, key: "Interface declaration cannot have 'implements' clause." },
Binary_digit_expected: { code: 1177, category: ts.DiagnosticCategory.Error, key: "Binary digit expected." },
Octal_digit_expected: { code: 1178, category: ts.DiagnosticCategory.Error, key: "Octal digit expected." },
Unexpected_token_expected: { code: 1179, category: ts.DiagnosticCategory.Error, key: "Unexpected token. '{' expected." },
Property_destructuring_pattern_expected: { code: 1180, category: ts.DiagnosticCategory.Error, key: "Property destructuring pattern expected." },
Array_element_destructuring_pattern_expected: { code: 1181, category: ts.DiagnosticCategory.Error, key: "Array element destructuring pattern expected." },
A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: ts.DiagnosticCategory.Error, key: "A destructuring declaration must have an initializer." },
An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1184, category: ts.DiagnosticCategory.Error, key: "An implementation cannot be declared in ambient contexts." },
Modifiers_cannot_appear_here: { code: 1184, category: ts.DiagnosticCategory.Error, key: "Modifiers cannot appear here." },
Merge_conflict_marker_encountered: { code: 1185, category: ts.DiagnosticCategory.Error, key: "Merge conflict marker encountered." },
A_rest_element_cannot_have_an_initializer: { code: 1186, category: ts.DiagnosticCategory.Error, key: "A rest element cannot have an initializer." },
A_parameter_property_may_not_be_a_binding_pattern: { code: 1187, category: ts.DiagnosticCategory.Error, key: "A parameter property may not be a binding pattern." },
Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement: { code: 1188, category: ts.DiagnosticCategory.Error, key: "Only a single variable declaration is allowed in a 'for...of' statement." },
The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer: { code: 1189, category: ts.DiagnosticCategory.Error, key: "The variable declaration of a 'for...in' statement cannot have an initializer." },
The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer: { code: 1190, category: ts.DiagnosticCategory.Error, key: "The variable declaration of a 'for...of' statement cannot have an initializer." },
An_import_declaration_cannot_have_modifiers: { code: 1191, category: ts.DiagnosticCategory.Error, key: "An import declaration cannot have modifiers." },
Module_0_has_no_default_export: { code: 1192, category: ts.DiagnosticCategory.Error, key: "Module '{0}' has no default export." },
An_export_declaration_cannot_have_modifiers: { code: 1193, category: ts.DiagnosticCategory.Error, key: "An export declaration cannot have modifiers." },
Export_declarations_are_not_permitted_in_a_namespace: { code: 1194, category: ts.DiagnosticCategory.Error, key: "Export declarations are not permitted in a namespace." },
Catch_clause_variable_name_must_be_an_identifier: { code: 1195, category: ts.DiagnosticCategory.Error, key: "Catch clause variable name must be an identifier." },
Catch_clause_variable_cannot_have_a_type_annotation: { code: 1196, category: ts.DiagnosticCategory.Error, key: "Catch clause variable cannot have a type annotation." },
Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: ts.DiagnosticCategory.Error, key: "Catch clause variable cannot have an initializer." },
An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: ts.DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." },
Unterminated_Unicode_escape_sequence: { code: 1199, category: ts.DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." },
Line_terminator_not_permitted_before_arrow: { code: 1200, category: ts.DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." },
Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1202, category: ts.DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." },
Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1203, category: ts.DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." },
Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher: { code: 1204, category: ts.DiagnosticCategory.Error, key: "Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher." },
Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1205, category: ts.DiagnosticCategory.Error, key: "Decorators are only available when targeting ECMAScript 5 and higher." },
Decorators_are_not_valid_here: { code: 1206, category: ts.DiagnosticCategory.Error, key: "Decorators are not valid here." },
Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: ts.DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." },
Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided: { code: 1208, category: ts.DiagnosticCategory.Error, key: "Cannot compile namespaces when the '--isolatedModules' flag is provided." },
Ambient_const_enums_are_not_allowed_when_the_isolatedModules_flag_is_provided: { code: 1209, category: ts.DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--isolatedModules' flag is provided." },
Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: { code: 1210, category: ts.DiagnosticCategory.Error, key: "Invalid use of '{0}'. Class definitions are automatically in strict mode." },
A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: ts.DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" },
Identifier_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode" },
Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1213, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." },
Identifier_expected_0_is_a_reserved_word_in_strict_mode_Modules_are_automatically_in_strict_mode: { code: 1214, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. Modules are automatically in strict mode." },
Invalid_use_of_0_Modules_are_automatically_in_strict_mode: { code: 1215, category: ts.DiagnosticCategory.Error, key: "Invalid use of '{0}'. Modules are automatically in strict mode." },
Export_assignment_is_not_supported_when_module_flag_is_system: { code: 1218, category: ts.DiagnosticCategory.Error, key: "Export assignment is not supported when '--module' flag is 'system'." },
Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning: { code: 1219, category: ts.DiagnosticCategory.Error, key: "Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning." },
Generators_are_only_available_when_targeting_ECMAScript_6_or_higher: { code: 1220, category: ts.DiagnosticCategory.Error, key: "Generators are only available when targeting ECMAScript 6 or higher." },
Generators_are_not_allowed_in_an_ambient_context: { code: 1221, category: ts.DiagnosticCategory.Error, key: "Generators are not allowed in an ambient context." },
An_overload_signature_cannot_be_declared_as_a_generator: { code: 1222, category: ts.DiagnosticCategory.Error, key: "An overload signature cannot be declared as a generator." },
_0_tag_already_specified: { code: 1223, category: ts.DiagnosticCategory.Error, key: "'{0}' tag already specified." },
Signature_0_must_have_a_type_predicate: { code: 1224, category: ts.DiagnosticCategory.Error, key: "Signature '{0}' must have a type predicate." },
Cannot_find_parameter_0: { code: 1225, category: ts.DiagnosticCategory.Error, key: "Cannot find parameter '{0}'." },
Type_predicate_0_is_not_assignable_to_1: { code: 1226, category: ts.DiagnosticCategory.Error, key: "Type predicate '{0}' is not assignable to '{1}'." },
Parameter_0_is_not_in_the_same_position_as_parameter_1: { code: 1227, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' is not in the same position as parameter '{1}'." },
A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods: { code: 1228, category: ts.DiagnosticCategory.Error, key: "A type predicate is only allowed in return type position for functions and methods." },
A_type_predicate_cannot_reference_a_rest_parameter: { code: 1229, category: ts.DiagnosticCategory.Error, key: "A type predicate cannot reference a rest parameter." },
A_type_predicate_cannot_reference_element_0_in_a_binding_pattern: { code: 1230, category: ts.DiagnosticCategory.Error, key: "A type predicate cannot reference element '{0}' in a binding pattern." },
An_export_assignment_can_only_be_used_in_a_module: { code: 1231, category: ts.DiagnosticCategory.Error, key: "An export assignment can only be used in a module." },
An_import_declaration_can_only_be_used_in_a_namespace_or_module: { code: 1232, category: ts.DiagnosticCategory.Error, key: "An import declaration can only be used in a namespace or module." },
An_export_declaration_can_only_be_used_in_a_module: { code: 1233, category: ts.DiagnosticCategory.Error, key: "An export declaration can only be used in a module." },
An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file: { code: 1234, category: ts.DiagnosticCategory.Error, key: "An ambient module declaration is only allowed at the top level in a file." },
A_namespace_declaration_is_only_allowed_in_a_namespace_or_module: { code: 1235, category: ts.DiagnosticCategory.Error, key: "A namespace declaration is only allowed in a namespace or module." },
Experimental_support_for_async_functions_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalAsyncFunctions_to_remove_this_warning: { code: 1236, category: ts.DiagnosticCategory.Error, key: "Experimental support for async functions is a feature that is subject to change in a future release. Specify '--experimentalAsyncFunctions' to remove this warning." },
with_statements_are_not_allowed_in_an_async_function_block: { code: 1300, category: ts.DiagnosticCategory.Error, key: "'with' statements are not allowed in an async function block." },
await_expression_is_only_allowed_within_an_async_function: { code: 1308, category: ts.DiagnosticCategory.Error, key: "'await' expression is only allowed within an async function." },
Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1311, category: ts.DiagnosticCategory.Error, key: "Async functions are only available when targeting ECMAScript 6 and higher." },
The_return_type_of_a_property_decorator_function_must_be_either_void_or_any: { code: 1236, category: ts.DiagnosticCategory.Error, key: "The return type of a property decorator function must be either 'void' or 'any'." },
The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any: { code: 1237, category: ts.DiagnosticCategory.Error, key: "The return type of a parameter decorator function must be either 'void' or 'any'." },
Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression: { code: 1238, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of class decorator when called as an expression." },
Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression: { code: 1239, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of parameter decorator when called as an expression." },
Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression: { code: 1240, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of property decorator when called as an expression." },
Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression: { code: 1241, category: ts.DiagnosticCategory.Error, key: "Unable to resolve signature of method decorator when called as an expression." },
abstract_modifier_can_only_appear_on_a_class_or_method_declaration: { code: 1242, category: ts.DiagnosticCategory.Error, key: "'abstract' modifier can only appear on a class or method declaration." },
_0_modifier_cannot_be_used_with_1_modifier: { code: 1243, category: ts.DiagnosticCategory.Error, key: "'{0}' modifier cannot be used with '{1}' modifier." },
Abstract_methods_can_only_appear_within_an_abstract_class: { code: 1244, category: ts.DiagnosticCategory.Error, key: "Abstract methods can only appear within an abstract class." },
Method_0_cannot_have_an_implementation_because_it_is_marked_abstract: { code: 1245, category: ts.DiagnosticCategory.Error, key: "Method '{0}' cannot have an implementation because it is marked abstract." },
Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
Circular_definition_of_import_alias_0: { code: 2303, category: ts.DiagnosticCategory.Error, key: "Circular definition of import alias '{0}'." },
Cannot_find_name_0: { code: 2304, category: ts.DiagnosticCategory.Error, key: "Cannot find name '{0}'." },
Module_0_has_no_exported_member_1: { code: 2305, category: ts.DiagnosticCategory.Error, key: "Module '{0}' has no exported member '{1}'." },
File_0_is_not_a_module: { code: 2306, category: ts.DiagnosticCategory.Error, key: "File '{0}' is not a module." },
Cannot_find_module_0: { code: 2307, category: ts.DiagnosticCategory.Error, key: "Cannot find module '{0}'." },
An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements: { code: 2309, category: ts.DiagnosticCategory.Error, key: "An export assignment cannot be used in a module with other exported elements." },
Type_0_recursively_references_itself_as_a_base_type: { code: 2310, category: ts.DiagnosticCategory.Error, key: "Type '{0}' recursively references itself as a base type." },
A_class_may_only_extend_another_class: { code: 2311, category: ts.DiagnosticCategory.Error, key: "A class may only extend another class." },
An_interface_may_only_extend_a_class_or_another_interface: { code: 2312, category: ts.DiagnosticCategory.Error, key: "An interface may only extend a class or another interface." },
Constraint_of_a_type_parameter_cannot_reference_any_type_parameter_from_the_same_type_parameter_list: { code: 2313, category: ts.DiagnosticCategory.Error, key: "Constraint of a type parameter cannot reference any type parameter from the same type parameter list." },
Generic_type_0_requires_1_type_argument_s: { code: 2314, category: ts.DiagnosticCategory.Error, key: "Generic type '{0}' requires {1} type argument(s)." },
Type_0_is_not_generic: { code: 2315, category: ts.DiagnosticCategory.Error, key: "Type '{0}' is not generic." },
Global_type_0_must_be_a_class_or_interface_type: { code: 2316, category: ts.DiagnosticCategory.Error, key: "Global type '{0}' must be a class or interface type." },
Global_type_0_must_have_1_type_parameter_s: { code: 2317, category: ts.DiagnosticCategory.Error, key: "Global type '{0}' must have {1} type parameter(s)." },
Cannot_find_global_type_0: { code: 2318, category: ts.DiagnosticCategory.Error, key: "Cannot find global type '{0}'." },
Named_property_0_of_types_1_and_2_are_not_identical: { code: 2319, category: ts.DiagnosticCategory.Error, key: "Named property '{0}' of types '{1}' and '{2}' are not identical." },
Interface_0_cannot_simultaneously_extend_types_1_and_2: { code: 2320, category: ts.DiagnosticCategory.Error, key: "Interface '{0}' cannot simultaneously extend types '{1}' and '{2}'." },
Excessive_stack_depth_comparing_types_0_and_1: { code: 2321, category: ts.DiagnosticCategory.Error, key: "Excessive stack depth comparing types '{0}' and '{1}'." },
Type_0_is_not_assignable_to_type_1: { code: 2322, category: ts.DiagnosticCategory.Error, key: "Type '{0}' is not assignable to type '{1}'." },
Property_0_is_missing_in_type_1: { code: 2324, category: ts.DiagnosticCategory.Error, key: "Property '{0}' is missing in type '{1}'." },
Property_0_is_private_in_type_1_but_not_in_type_2: { code: 2325, category: ts.DiagnosticCategory.Error, key: "Property '{0}' is private in type '{1}' but not in type '{2}'." },
Types_of_property_0_are_incompatible: { code: 2326, category: ts.DiagnosticCategory.Error, key: "Types of property '{0}' are incompatible." },
Property_0_is_optional_in_type_1_but_required_in_type_2: { code: 2327, category: ts.DiagnosticCategory.Error, key: "Property '{0}' is optional in type '{1}' but required in type '{2}'." },
Types_of_parameters_0_and_1_are_incompatible: { code: 2328, category: ts.DiagnosticCategory.Error, key: "Types of parameters '{0}' and '{1}' are incompatible." },
Index_signature_is_missing_in_type_0: { code: 2329, category: ts.DiagnosticCategory.Error, key: "Index signature is missing in type '{0}'." },
Index_signatures_are_incompatible: { code: 2330, category: ts.DiagnosticCategory.Error, key: "Index signatures are incompatible." },
this_cannot_be_referenced_in_a_module_or_namespace_body: { code: 2331, category: ts.DiagnosticCategory.Error, key: "'this' cannot be referenced in a module or namespace body." },
this_cannot_be_referenced_in_current_location: { code: 2332, category: ts.DiagnosticCategory.Error, key: "'this' cannot be referenced in current location." },
this_cannot_be_referenced_in_constructor_arguments: { code: 2333, category: ts.DiagnosticCategory.Error, key: "'this' cannot be referenced in constructor arguments." },
this_cannot_be_referenced_in_a_static_property_initializer: { code: 2334, category: ts.DiagnosticCategory.Error, key: "'this' cannot be referenced in a static property initializer." },
super_can_only_be_referenced_in_a_derived_class: { code: 2335, category: ts.DiagnosticCategory.Error, key: "'super' can only be referenced in a derived class." },
super_cannot_be_referenced_in_constructor_arguments: { code: 2336, category: ts.DiagnosticCategory.Error, key: "'super' cannot be referenced in constructor arguments." },
Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors: { code: 2337, category: ts.DiagnosticCategory.Error, key: "Super calls are not permitted outside constructors or in nested functions inside constructors." },
super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class: { code: 2338, category: ts.DiagnosticCategory.Error, key: "'super' property access is permitted only in a constructor, member function, or member accessor of a derived class." },
Property_0_does_not_exist_on_type_1: { code: 2339, category: ts.DiagnosticCategory.Error, key: "Property '{0}' does not exist on type '{1}'." },
Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword: { code: 2340, category: ts.DiagnosticCategory.Error, key: "Only public and protected methods of the base class are accessible via the 'super' keyword." },
Property_0_is_private_and_only_accessible_within_class_1: { code: 2341, category: ts.DiagnosticCategory.Error, key: "Property '{0}' is private and only accessible within class '{1}'." },
An_index_expression_argument_must_be_of_type_string_number_symbol_or_any: { code: 2342, category: ts.DiagnosticCategory.Error, key: "An index expression argument must be of type 'string', 'number', 'symbol, or 'any'." },
Type_0_does_not_satisfy_the_constraint_1: { code: 2344, category: ts.DiagnosticCategory.Error, key: "Type '{0}' does not satisfy the constraint '{1}'." },
Argument_of_type_0_is_not_assignable_to_parameter_of_type_1: { code: 2345, category: ts.DiagnosticCategory.Error, key: "Argument of type '{0}' is not assignable to parameter of type '{1}'." },
Supplied_parameters_do_not_match_any_signature_of_call_target: { code: 2346, category: ts.DiagnosticCategory.Error, key: "Supplied parameters do not match any signature of call target." },
Untyped_function_calls_may_not_accept_type_arguments: { code: 2347, category: ts.DiagnosticCategory.Error, key: "Untyped function calls may not accept type arguments." },
Value_of_type_0_is_not_callable_Did_you_mean_to_include_new: { code: 2348, category: ts.DiagnosticCategory.Error, key: "Value of type '{0}' is not callable. Did you mean to include 'new'?" },
Cannot_invoke_an_expression_whose_type_lacks_a_call_signature: { code: 2349, category: ts.DiagnosticCategory.Error, key: "Cannot invoke an expression whose type lacks a call signature." },
Only_a_void_function_can_be_called_with_the_new_keyword: { code: 2350, category: ts.DiagnosticCategory.Error, key: "Only a void function can be called with the 'new' keyword." },
Cannot_use_new_with_an_expression_whose_type_lacks_a_call_or_construct_signature: { code: 2351, category: ts.DiagnosticCategory.Error, key: "Cannot use 'new' with an expression whose type lacks a call or construct signature." },
Neither_type_0_nor_type_1_is_assignable_to_the_other: { code: 2352, category: ts.DiagnosticCategory.Error, key: "Neither type '{0}' nor type '{1}' is assignable to the other." },
Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1: { code: 2353, category: ts.DiagnosticCategory.Error, key: "Object literal may only specify known properties, and '{0}' does not exist in type '{1}'." },
No_best_common_type_exists_among_return_expressions: { code: 2354, category: ts.DiagnosticCategory.Error, key: "No best common type exists among return expressions." },
A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value_or_consist_of_a_single_throw_statement: { code: 2355, category: ts.DiagnosticCategory.Error, key: "A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement." },
An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type: { code: 2356, category: ts.DiagnosticCategory.Error, key: "An arithmetic operand must be of type 'any', 'number' or an enum type." },
The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer: { code: 2357, category: ts.DiagnosticCategory.Error, key: "The operand of an increment or decrement operator must be a variable, property or indexer." },
The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: { code: 2358, category: ts.DiagnosticCategory.Error, key: "The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter." },
The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type: { code: 2359, category: ts.DiagnosticCategory.Error, key: "The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type." },
The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol: { code: 2360, category: ts.DiagnosticCategory.Error, key: "The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'." },
The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: { code: 2361, category: ts.DiagnosticCategory.Error, key: "The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter" },
The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: { code: 2362, category: ts.DiagnosticCategory.Error, key: "The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type." },
The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: { code: 2363, category: ts.DiagnosticCategory.Error, key: "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type." },
Invalid_left_hand_side_of_assignment_expression: { code: 2364, category: ts.DiagnosticCategory.Error, key: "Invalid left-hand side of assignment expression." },
Operator_0_cannot_be_applied_to_types_1_and_2: { code: 2365, category: ts.DiagnosticCategory.Error, key: "Operator '{0}' cannot be applied to types '{1}' and '{2}'." },
Type_parameter_name_cannot_be_0: { code: 2368, category: ts.DiagnosticCategory.Error, key: "Type parameter name cannot be '{0}'" },
A_parameter_property_is_only_allowed_in_a_constructor_implementation: { code: 2369, category: ts.DiagnosticCategory.Error, key: "A parameter property is only allowed in a constructor implementation." },
A_rest_parameter_must_be_of_an_array_type: { code: 2370, category: ts.DiagnosticCategory.Error, key: "A rest parameter must be of an array type." },
A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation: { code: 2371, category: ts.DiagnosticCategory.Error, key: "A parameter initializer is only allowed in a function or constructor implementation." },
Parameter_0_cannot_be_referenced_in_its_initializer: { code: 2372, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' cannot be referenced in its initializer." },
Initializer_of_parameter_0_cannot_reference_identifier_1_declared_after_it: { code: 2373, category: ts.DiagnosticCategory.Error, key: "Initializer of parameter '{0}' cannot reference identifier '{1}' declared after it." },
Duplicate_string_index_signature: { code: 2374, category: ts.DiagnosticCategory.Error, key: "Duplicate string index signature." },
Duplicate_number_index_signature: { code: 2375, category: ts.DiagnosticCategory.Error, key: "Duplicate number index signature." },
A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties: { code: 2376, category: ts.DiagnosticCategory.Error, key: "A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties." },
Constructors_for_derived_classes_must_contain_a_super_call: { code: 2377, category: ts.DiagnosticCategory.Error, key: "Constructors for derived classes must contain a 'super' call." },
A_get_accessor_must_return_a_value_or_consist_of_a_single_throw_statement: { code: 2378, category: ts.DiagnosticCategory.Error, key: "A 'get' accessor must return a value or consist of a single 'throw' statement." },
Getter_and_setter_accessors_do_not_agree_in_visibility: { code: 2379, category: ts.DiagnosticCategory.Error, key: "Getter and setter accessors do not agree in visibility." },
get_and_set_accessor_must_have_the_same_type: { code: 2380, category: ts.DiagnosticCategory.Error, key: "'get' and 'set' accessor must have the same type." },
A_signature_with_an_implementation_cannot_use_a_string_literal_type: { code: 2381, category: ts.DiagnosticCategory.Error, key: "A signature with an implementation cannot use a string literal type." },
Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature: { code: 2382, category: ts.DiagnosticCategory.Error, key: "Specialized overload signature is not assignable to any non-specialized signature." },
Overload_signatures_must_all_be_exported_or_not_exported: { code: 2383, category: ts.DiagnosticCategory.Error, key: "Overload signatures must all be exported or not exported." },
Overload_signatures_must_all_be_ambient_or_non_ambient: { code: 2384, category: ts.DiagnosticCategory.Error, key: "Overload signatures must all be ambient or non-ambient." },
Overload_signatures_must_all_be_public_private_or_protected: { code: 2385, category: ts.DiagnosticCategory.Error, key: "Overload signatures must all be public, private or protected." },
Overload_signatures_must_all_be_optional_or_required: { code: 2386, category: ts.DiagnosticCategory.Error, key: "Overload signatures must all be optional or required." },
Function_overload_must_be_static: { code: 2387, category: ts.DiagnosticCategory.Error, key: "Function overload must be static." },
Function_overload_must_not_be_static: { code: 2388, category: ts.DiagnosticCategory.Error, key: "Function overload must not be static." },
Function_implementation_name_must_be_0: { code: 2389, category: ts.DiagnosticCategory.Error, key: "Function implementation name must be '{0}'." },
Constructor_implementation_is_missing: { code: 2390, category: ts.DiagnosticCategory.Error, key: "Constructor implementation is missing." },
Function_implementation_is_missing_or_not_immediately_following_the_declaration: { code: 2391, category: ts.DiagnosticCategory.Error, key: "Function implementation is missing or not immediately following the declaration." },
Multiple_constructor_implementations_are_not_allowed: { code: 2392, category: ts.DiagnosticCategory.Error, key: "Multiple constructor implementations are not allowed." },
Duplicate_function_implementation: { code: 2393, category: ts.DiagnosticCategory.Error, key: "Duplicate function implementation." },
Overload_signature_is_not_compatible_with_function_implementation: { code: 2394, category: ts.DiagnosticCategory.Error, key: "Overload signature is not compatible with function implementation." },
Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local: { code: 2395, category: ts.DiagnosticCategory.Error, key: "Individual declarations in merged declaration '{0}' must be all exported or all local." },
Duplicate_identifier_arguments_Compiler_uses_arguments_to_initialize_rest_parameters: { code: 2396, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters." },
Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference: { code: 2399, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference." },
Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference: { code: 2400, category: ts.DiagnosticCategory.Error, key: "Expression resolves to variable declaration '_this' that compiler uses to capture 'this' reference." },
Duplicate_identifier_super_Compiler_uses_super_to_capture_base_class_reference: { code: 2401, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference." },
Expression_resolves_to_super_that_compiler_uses_to_capture_base_class_reference: { code: 2402, category: ts.DiagnosticCategory.Error, key: "Expression resolves to '_super' that compiler uses to capture base class reference." },
Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2: { code: 2403, category: ts.DiagnosticCategory.Error, key: "Subsequent variable declarations must have the same type. Variable '{0}' must be of type '{1}', but here has type '{2}'." },
The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation: { code: 2404, category: ts.DiagnosticCategory.Error, key: "The left-hand side of a 'for...in' statement cannot use a type annotation." },
The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any: { code: 2405, category: ts.DiagnosticCategory.Error, key: "The left-hand side of a 'for...in' statement must be of type 'string' or 'any'." },
Invalid_left_hand_side_in_for_in_statement: { code: 2406, category: ts.DiagnosticCategory.Error, key: "Invalid left-hand side in 'for...in' statement." },
The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter: { code: 2407, category: ts.DiagnosticCategory.Error, key: "The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter." },
Setters_cannot_return_a_value: { code: 2408, category: ts.DiagnosticCategory.Error, key: "Setters cannot return a value." },
Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class: { code: 2409, category: ts.DiagnosticCategory.Error, key: "Return type of constructor signature must be assignable to the instance type of the class" },
All_symbols_within_a_with_block_will_be_resolved_to_any: { code: 2410, category: ts.DiagnosticCategory.Error, key: "All symbols within a 'with' block will be resolved to 'any'." },
Property_0_of_type_1_is_not_assignable_to_string_index_type_2: { code: 2411, category: ts.DiagnosticCategory.Error, key: "Property '{0}' of type '{1}' is not assignable to string index type '{2}'." },
Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2: { code: 2412, category: ts.DiagnosticCategory.Error, key: "Property '{0}' of type '{1}' is not assignable to numeric index type '{2}'." },
Numeric_index_type_0_is_not_assignable_to_string_index_type_1: { code: 2413, category: ts.DiagnosticCategory.Error, key: "Numeric index type '{0}' is not assignable to string index type '{1}'." },
Class_name_cannot_be_0: { code: 2414, category: ts.DiagnosticCategory.Error, key: "Class name cannot be '{0}'" },
Class_0_incorrectly_extends_base_class_1: { code: 2415, category: ts.DiagnosticCategory.Error, key: "Class '{0}' incorrectly extends base class '{1}'." },
Class_static_side_0_incorrectly_extends_base_class_static_side_1: { code: 2417, category: ts.DiagnosticCategory.Error, key: "Class static side '{0}' incorrectly extends base class static side '{1}'." },
Type_name_0_in_extends_clause_does_not_reference_constructor_function_for_0: { code: 2419, category: ts.DiagnosticCategory.Error, key: "Type name '{0}' in extends clause does not reference constructor function for '{0}'." },
Class_0_incorrectly_implements_interface_1: { code: 2420, category: ts.DiagnosticCategory.Error, key: "Class '{0}' incorrectly implements interface '{1}'." },
A_class_may_only_implement_another_class_or_interface: { code: 2422, category: ts.DiagnosticCategory.Error, key: "A class may only implement another class or interface." },
Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_accessor: { code: 2423, category: ts.DiagnosticCategory.Error, key: "Class '{0}' defines instance member function '{1}', but extended class '{2}' defines it as instance member accessor." },
Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_property: { code: 2424, category: ts.DiagnosticCategory.Error, key: "Class '{0}' defines instance member function '{1}', but extended class '{2}' defines it as instance member property." },
Class_0_defines_instance_member_property_1_but_extended_class_2_defines_it_as_instance_member_function: { code: 2425, category: ts.DiagnosticCategory.Error, key: "Class '{0}' defines instance member property '{1}', but extended class '{2}' defines it as instance member function." },
Class_0_defines_instance_member_accessor_1_but_extended_class_2_defines_it_as_instance_member_function: { code: 2426, category: ts.DiagnosticCategory.Error, key: "Class '{0}' defines instance member accessor '{1}', but extended class '{2}' defines it as instance member function." },
Interface_name_cannot_be_0: { code: 2427, category: ts.DiagnosticCategory.Error, key: "Interface name cannot be '{0}'" },
All_declarations_of_an_interface_must_have_identical_type_parameters: { code: 2428, category: ts.DiagnosticCategory.Error, key: "All declarations of an interface must have identical type parameters." },
Interface_0_incorrectly_extends_interface_1: { code: 2430, category: ts.DiagnosticCategory.Error, key: "Interface '{0}' incorrectly extends interface '{1}'." },
Enum_name_cannot_be_0: { code: 2431, category: ts.DiagnosticCategory.Error, key: "Enum name cannot be '{0}'" },
In_an_enum_with_multiple_declarations_only_one_declaration_can_omit_an_initializer_for_its_first_enum_element: { code: 2432, category: ts.DiagnosticCategory.Error, key: "In an enum with multiple declarations, only one declaration can omit an initializer for its first enum element." },
A_namespace_declaration_cannot_be_in_a_different_file_from_a_class_or_function_with_which_it_is_merged: { code: 2433, category: ts.DiagnosticCategory.Error, key: "A namespace declaration cannot be in a different file from a class or function with which it is merged" },
A_namespace_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged: { code: 2434, category: ts.DiagnosticCategory.Error, key: "A namespace declaration cannot be located prior to a class or function with which it is merged" },
Ambient_modules_cannot_be_nested_in_other_modules: { code: 2435, category: ts.DiagnosticCategory.Error, key: "Ambient modules cannot be nested in other modules." },
Ambient_module_declaration_cannot_specify_relative_module_name: { code: 2436, category: ts.DiagnosticCategory.Error, key: "Ambient module declaration cannot specify relative module name." },
Module_0_is_hidden_by_a_local_declaration_with_the_same_name: { code: 2437, category: ts.DiagnosticCategory.Error, key: "Module '{0}' is hidden by a local declaration with the same name" },
Import_name_cannot_be_0: { code: 2438, category: ts.DiagnosticCategory.Error, key: "Import name cannot be '{0}'" },
Import_or_export_declaration_in_an_ambient_module_declaration_cannot_reference_module_through_relative_module_name: { code: 2439, category: ts.DiagnosticCategory.Error, key: "Import or export declaration in an ambient module declaration cannot reference module through relative module name." },
Import_declaration_conflicts_with_local_declaration_of_0: { code: 2440, category: ts.DiagnosticCategory.Error, key: "Import declaration conflicts with local declaration of '{0}'" },
Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_a_module: { code: 2441, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'. Compiler reserves name '{1}' in top level scope of a module." },
Types_have_separate_declarations_of_a_private_property_0: { code: 2442, category: ts.DiagnosticCategory.Error, key: "Types have separate declarations of a private property '{0}'." },
Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2: { code: 2443, category: ts.DiagnosticCategory.Error, key: "Property '{0}' is protected but type '{1}' is not a class derived from '{2}'." },
Property_0_is_protected_in_type_1_but_public_in_type_2: { code: 2444, category: ts.DiagnosticCategory.Error, key: "Property '{0}' is protected in type '{1}' but public in type '{2}'." },
Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses: { code: 2445, category: ts.DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible within class '{1}' and its subclasses." },
Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1: { code: 2446, category: ts.DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible through an instance of class '{1}'." },
The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead: { code: 2447, category: ts.DiagnosticCategory.Error, key: "The '{0}' operator is not allowed for boolean types. Consider using '{1}' instead." },
Block_scoped_variable_0_used_before_its_declaration: { code: 2448, category: ts.DiagnosticCategory.Error, key: "Block-scoped variable '{0}' used before its declaration." },
The_operand_of_an_increment_or_decrement_operator_cannot_be_a_constant: { code: 2449, category: ts.DiagnosticCategory.Error, key: "The operand of an increment or decrement operator cannot be a constant." },
Left_hand_side_of_assignment_expression_cannot_be_a_constant: { code: 2450, category: ts.DiagnosticCategory.Error, key: "Left-hand side of assignment expression cannot be a constant." },
Cannot_redeclare_block_scoped_variable_0: { code: 2451, category: ts.DiagnosticCategory.Error, key: "Cannot redeclare block-scoped variable '{0}'." },
An_enum_member_cannot_have_a_numeric_name: { code: 2452, category: ts.DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." },
The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly: { code: 2453, category: ts.DiagnosticCategory.Error, key: "The type argument for type parameter '{0}' cannot be inferred from the usage. Consider specifying the type arguments explicitly." },
Type_argument_candidate_1_is_not_a_valid_type_argument_because_it_is_not_a_supertype_of_candidate_0: { code: 2455, category: ts.DiagnosticCategory.Error, key: "Type argument candidate '{1}' is not a valid type argument because it is not a supertype of candidate '{0}'." },
Type_alias_0_circularly_references_itself: { code: 2456, category: ts.DiagnosticCategory.Error, key: "Type alias '{0}' circularly references itself." },
Type_alias_name_cannot_be_0: { code: 2457, category: ts.DiagnosticCategory.Error, key: "Type alias name cannot be '{0}'" },
An_AMD_module_cannot_have_multiple_name_assignments: { code: 2458, category: ts.DiagnosticCategory.Error, key: "An AMD module cannot have multiple name assignments." },
Type_0_has_no_property_1_and_no_string_index_signature: { code: 2459, category: ts.DiagnosticCategory.Error, key: "Type '{0}' has no property '{1}' and no string index signature." },
Type_0_has_no_property_1: { code: 2460, category: ts.DiagnosticCategory.Error, key: "Type '{0}' has no property '{1}'." },
Type_0_is_not_an_array_type: { code: 2461, category: ts.DiagnosticCategory.Error, key: "Type '{0}' is not an array type." },
A_rest_element_must_be_last_in_an_array_destructuring_pattern: { code: 2462, category: ts.DiagnosticCategory.Error, key: "A rest element must be last in an array destructuring pattern" },
A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature: { code: 2463, category: ts.DiagnosticCategory.Error, key: "A binding pattern parameter cannot be optional in an implementation signature." },
A_computed_property_name_must_be_of_type_string_number_symbol_or_any: { code: 2464, category: ts.DiagnosticCategory.Error, key: "A computed property name must be of type 'string', 'number', 'symbol', or 'any'." },
this_cannot_be_referenced_in_a_computed_property_name: { code: 2465, category: ts.DiagnosticCategory.Error, key: "'this' cannot be referenced in a computed property name." },
super_cannot_be_referenced_in_a_computed_property_name: { code: 2466, category: ts.DiagnosticCategory.Error, key: "'super' cannot be referenced in a computed property name." },
A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type: { code: 2467, category: ts.DiagnosticCategory.Error, key: "A computed property name cannot reference a type parameter from its containing type." },
Cannot_find_global_value_0: { code: 2468, category: ts.DiagnosticCategory.Error, key: "Cannot find global value '{0}'." },
The_0_operator_cannot_be_applied_to_type_symbol: { code: 2469, category: ts.DiagnosticCategory.Error, key: "The '{0}' operator cannot be applied to type 'symbol'." },
Symbol_reference_does_not_refer_to_the_global_Symbol_constructor_object: { code: 2470, category: ts.DiagnosticCategory.Error, key: "'Symbol' reference does not refer to the global Symbol constructor object." },
A_computed_property_name_of_the_form_0_must_be_of_type_symbol: { code: 2471, category: ts.DiagnosticCategory.Error, key: "A computed property name of the form '{0}' must be of type 'symbol'." },
Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher: { code: 2472, category: ts.DiagnosticCategory.Error, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher." },
Enum_declarations_must_all_be_const_or_non_const: { code: 2473, category: ts.DiagnosticCategory.Error, key: "Enum declarations must all be const or non-const." },
In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 2474, category: ts.DiagnosticCategory.Error, key: "In 'const' enum declarations member initializer must be constant expression." },
const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment: { code: 2475, category: ts.DiagnosticCategory.Error, key: "'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment." },
A_const_enum_member_can_only_be_accessed_using_a_string_literal: { code: 2476, category: ts.DiagnosticCategory.Error, key: "A const enum member can only be accessed using a string literal." },
const_enum_member_initializer_was_evaluated_to_a_non_finite_value: { code: 2477, category: ts.DiagnosticCategory.Error, key: "'const' enum member initializer was evaluated to a non-finite value." },
const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN: { code: 2478, category: ts.DiagnosticCategory.Error, key: "'const' enum member initializer was evaluated to disallowed value 'NaN'." },
Property_0_does_not_exist_on_const_enum_1: { code: 2479, category: ts.DiagnosticCategory.Error, key: "Property '{0}' does not exist on 'const' enum '{1}'." },
let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations: { code: 2480, category: ts.DiagnosticCategory.Error, key: "'let' is not allowed to be used as a name in 'let' or 'const' declarations." },
Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1: { code: 2481, category: ts.DiagnosticCategory.Error, key: "Cannot initialize outer scoped variable '{0}' in the same scope as block scoped declaration '{1}'." },
The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation: { code: 2483, category: ts.DiagnosticCategory.Error, key: "The left-hand side of a 'for...of' statement cannot use a type annotation." },
Export_declaration_conflicts_with_exported_declaration_of_0: { code: 2484, category: ts.DiagnosticCategory.Error, key: "Export declaration conflicts with exported declaration of '{0}'" },
The_left_hand_side_of_a_for_of_statement_cannot_be_a_previously_defined_constant: { code: 2485, category: ts.DiagnosticCategory.Error, key: "The left-hand side of a 'for...of' statement cannot be a previously defined constant." },
The_left_hand_side_of_a_for_in_statement_cannot_be_a_previously_defined_constant: { code: 2486, category: ts.DiagnosticCategory.Error, key: "The left-hand side of a 'for...in' statement cannot be a previously defined constant." },
Invalid_left_hand_side_in_for_of_statement: { code: 2487, category: ts.DiagnosticCategory.Error, key: "Invalid left-hand side in 'for...of' statement." },
Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator: { code: 2488, category: ts.DiagnosticCategory.Error, key: "Type must have a '[Symbol.iterator]()' method that returns an iterator." },
An_iterator_must_have_a_next_method: { code: 2489, category: ts.DiagnosticCategory.Error, key: "An iterator must have a 'next()' method." },
The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property: { code: 2490, category: ts.DiagnosticCategory.Error, key: "The type returned by the 'next()' method of an iterator must have a 'value' property." },
The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern: { code: 2491, category: ts.DiagnosticCategory.Error, key: "The left-hand side of a 'for...in' statement cannot be a destructuring pattern." },
Cannot_redeclare_identifier_0_in_catch_clause: { code: 2492, category: ts.DiagnosticCategory.Error, key: "Cannot redeclare identifier '{0}' in catch clause" },
Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2: { code: 2493, category: ts.DiagnosticCategory.Error, key: "Tuple type '{0}' with length '{1}' cannot be assigned to tuple with length '{2}'." },
Using_a_string_in_a_for_of_statement_is_only_supported_in_ECMAScript_5_and_higher: { code: 2494, category: ts.DiagnosticCategory.Error, key: "Using a string in a 'for...of' statement is only supported in ECMAScript 5 and higher." },
Type_0_is_not_an_array_type_or_a_string_type: { code: 2495, category: ts.DiagnosticCategory.Error, key: "Type '{0}' is not an array type or a string type." },
The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression: { code: 2496, category: ts.DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression." },
Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct: { code: 2497, category: ts.DiagnosticCategory.Error, key: "Module '{0}' resolves to a non-module entity and cannot be imported using this construct." },
Module_0_uses_export_and_cannot_be_used_with_export_Asterisk: { code: 2498, category: ts.DiagnosticCategory.Error, key: "Module '{0}' uses 'export =' and cannot be used with 'export *'." },
An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments: { code: 2499, category: ts.DiagnosticCategory.Error, key: "An interface can only extend an identifier/qualified-name with optional type arguments." },
A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments: { code: 2500, category: ts.DiagnosticCategory.Error, key: "A class can only implement an identifier/qualified-name with optional type arguments." },
A_rest_element_cannot_contain_a_binding_pattern: { code: 2501, category: ts.DiagnosticCategory.Error, key: "A rest element cannot contain a binding pattern." },
_0_is_referenced_directly_or_indirectly_in_its_own_type_annotation: { code: 2502, category: ts.DiagnosticCategory.Error, key: "'{0}' is referenced directly or indirectly in its own type annotation." },
Cannot_find_namespace_0: { code: 2503, category: ts.DiagnosticCategory.Error, key: "Cannot find namespace '{0}'." },
No_best_common_type_exists_among_yield_expressions: { code: 2504, category: ts.DiagnosticCategory.Error, key: "No best common type exists among yield expressions." },
A_generator_cannot_have_a_void_type_annotation: { code: 2505, category: ts.DiagnosticCategory.Error, key: "A generator cannot have a 'void' type annotation." },
_0_is_referenced_directly_or_indirectly_in_its_own_base_expression: { code: 2506, category: ts.DiagnosticCategory.Error, key: "'{0}' is referenced directly or indirectly in its own base expression." },
Type_0_is_not_a_constructor_function_type: { code: 2507, category: ts.DiagnosticCategory.Error, key: "Type '{0}' is not a constructor function type." },
No_base_constructor_has_the_specified_number_of_type_arguments: { code: 2508, category: ts.DiagnosticCategory.Error, key: "No base constructor has the specified number of type arguments." },
Base_constructor_return_type_0_is_not_a_class_or_interface_type: { code: 2509, category: ts.DiagnosticCategory.Error, key: "Base constructor return type '{0}' is not a class or interface type." },
Base_constructors_must_all_have_the_same_return_type: { code: 2510, category: ts.DiagnosticCategory.Error, key: "Base constructors must all have the same return type." },
Cannot_create_an_instance_of_the_abstract_class_0: { code: 2511, category: ts.DiagnosticCategory.Error, key: "Cannot create an instance of the abstract class '{0}'." },
Overload_signatures_must_all_be_abstract_or_not_abstract: { code: 2512, category: ts.DiagnosticCategory.Error, key: "Overload signatures must all be abstract or not abstract." },
Abstract_method_0_in_class_1_cannot_be_accessed_via_super_expression: { code: 2513, category: ts.DiagnosticCategory.Error, key: "Abstract method '{0}' in class '{1}' cannot be accessed via super expression." },
Classes_containing_abstract_methods_must_be_marked_abstract: { code: 2514, category: ts.DiagnosticCategory.Error, key: "Classes containing abstract methods must be marked abstract." },
Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2: { code: 2515, category: ts.DiagnosticCategory.Error, key: "Non-abstract class '{0}' does not implement inherited abstract member '{1}' from class '{2}'." },
All_declarations_of_an_abstract_method_must_be_consecutive: { code: 2516, category: ts.DiagnosticCategory.Error, key: "All declarations of an abstract method must be consecutive." },
Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type: { code: 2517, category: ts.DiagnosticCategory.Error, key: "Cannot assign an abstract constructor type to a non-abstract constructor type." },
Only_an_ambient_class_can_be_merged_with_an_interface: { code: 2518, category: ts.DiagnosticCategory.Error, key: "Only an ambient class can be merged with an interface." },
Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions: { code: 2520, category: ts.DiagnosticCategory.Error, key: "Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions." },
Expression_resolves_to_variable_declaration_0_that_compiler_uses_to_support_async_functions: { code: 2521, category: ts.DiagnosticCategory.Error, key: "Expression resolves to variable declaration '{0}' that compiler uses to support async functions." },
The_arguments_object_cannot_be_referenced_in_an_async_arrow_function_Consider_using_a_standard_async_function_expression: { code: 2522, category: ts.DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an async arrow function. Consider using a standard async function expression." },
yield_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2523, category: ts.DiagnosticCategory.Error, key: "'yield' expressions cannot be used in a parameter initializer." },
await_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2524, category: ts.DiagnosticCategory.Error, key: "'await' expressions cannot be used in a parameter initializer." },
JSX_element_attributes_type_0_must_be_an_object_type: { code: 2600, category: ts.DiagnosticCategory.Error, key: "JSX element attributes type '{0}' must be an object type." },
The_return_type_of_a_JSX_element_constructor_must_return_an_object_type: { code: 2601, category: ts.DiagnosticCategory.Error, key: "The return type of a JSX element constructor must return an object type." },
JSX_element_implicitly_has_type_any_because_the_global_type_JSX_Element_does_not_exist: { code: 2602, category: ts.DiagnosticCategory.Error, key: "JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist." },
Property_0_in_type_1_is_not_assignable_to_type_2: { code: 2603, category: ts.DiagnosticCategory.Error, key: "Property '{0}' in type '{1}' is not assignable to type '{2}'" },
JSX_element_type_0_does_not_have_any_construct_or_call_signatures: { code: 2604, category: ts.DiagnosticCategory.Error, key: "JSX element type '{0}' does not have any construct or call signatures." },
JSX_element_type_0_is_not_a_constructor_function_for_JSX_elements: { code: 2605, category: ts.DiagnosticCategory.Error, key: "JSX element type '{0}' is not a constructor function for JSX elements." },
Property_0_of_JSX_spread_attribute_is_not_assignable_to_target_property: { code: 2606, category: ts.DiagnosticCategory.Error, key: "Property '{0}' of JSX spread attribute is not assignable to target property." },
JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property: { code: 2607, category: ts.DiagnosticCategory.Error, key: "JSX element class does not support attributes because it does not have a '{0}' property" },
The_global_type_JSX_0_may_not_have_more_than_one_property: { code: 2608, category: ts.DiagnosticCategory.Error, key: "The global type 'JSX.{0}' may not have more than one property" },
Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: ts.DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" },
A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums: { code: 2651, category: ts.DiagnosticCategory.Error, key: "A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums." },
Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: { code: 2652, category: ts.DiagnosticCategory.Error, key: "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead." },
Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 4006, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'." },
Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 4008, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of call signature from exported interface has or is using private name '{1}'." },
Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1: { code: 4010, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of public static method from exported class has or is using private name '{1}'." },
Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1: { code: 4012, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of public method from exported class has or is using private name '{1}'." },
Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1: { code: 4014, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of method from exported interface has or is using private name '{1}'." },
Type_parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4016, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported function has or is using private name '{1}'." },
Implements_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 4019, category: ts.DiagnosticCategory.Error, key: "Implements clause of exported class '{0}' has or is using private name '{1}'." },
Extends_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 4020, category: ts.DiagnosticCategory.Error, key: "Extends clause of exported class '{0}' has or is using private name '{1}'." },
Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1: { code: 4022, category: ts.DiagnosticCategory.Error, key: "Extends clause of exported interface '{0}' has or is using private name '{1}'." },
Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4023, category: ts.DiagnosticCategory.Error, key: "Exported variable '{0}' has or is using name '{1}' from external module {2} but cannot be named." },
Exported_variable_0_has_or_is_using_name_1_from_private_module_2: { code: 4024, category: ts.DiagnosticCategory.Error, key: "Exported variable '{0}' has or is using name '{1}' from private module '{2}'." },
Exported_variable_0_has_or_is_using_private_name_1: { code: 4025, category: ts.DiagnosticCategory.Error, key: "Exported variable '{0}' has or is using private name '{1}'." },
Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4026, category: ts.DiagnosticCategory.Error, key: "Public static property '{0}' of exported class has or is using name '{1}' from external module {2} but cannot be named." },
Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4027, category: ts.DiagnosticCategory.Error, key: "Public static property '{0}' of exported class has or is using name '{1}' from private module '{2}'." },
Public_static_property_0_of_exported_class_has_or_is_using_private_name_1: { code: 4028, category: ts.DiagnosticCategory.Error, key: "Public static property '{0}' of exported class has or is using private name '{1}'." },
Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4029, category: ts.DiagnosticCategory.Error, key: "Public property '{0}' of exported class has or is using name '{1}' from external module {2} but cannot be named." },
Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4030, category: ts.DiagnosticCategory.Error, key: "Public property '{0}' of exported class has or is using name '{1}' from private module '{2}'." },
Public_property_0_of_exported_class_has_or_is_using_private_name_1: { code: 4031, category: ts.DiagnosticCategory.Error, key: "Public property '{0}' of exported class has or is using private name '{1}'." },
Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4032, category: ts.DiagnosticCategory.Error, key: "Property '{0}' of exported interface has or is using name '{1}' from private module '{2}'." },
Property_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4033, category: ts.DiagnosticCategory.Error, key: "Property '{0}' of exported interface has or is using private name '{1}'." },
Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4034, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public static property setter from exported class has or is using name '{1}' from private module '{2}'." },
Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1: { code: 4035, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public static property setter from exported class has or is using private name '{1}'." },
Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4036, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public property setter from exported class has or is using name '{1}' from private module '{2}'." },
Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1: { code: 4037, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public property setter from exported class has or is using private name '{1}'." },
Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named: { code: 4038, category: ts.DiagnosticCategory.Error, key: "Return type of public static property getter from exported class has or is using name '{0}' from external module {1} but cannot be named." },
Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1: { code: 4039, category: ts.DiagnosticCategory.Error, key: "Return type of public static property getter from exported class has or is using name '{0}' from private module '{1}'." },
Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0: { code: 4040, category: ts.DiagnosticCategory.Error, key: "Return type of public static property getter from exported class has or is using private name '{0}'." },
Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named: { code: 4041, category: ts.DiagnosticCategory.Error, key: "Return type of public property getter from exported class has or is using name '{0}' from external module {1} but cannot be named." },
Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1: { code: 4042, category: ts.DiagnosticCategory.Error, key: "Return type of public property getter from exported class has or is using name '{0}' from private module '{1}'." },
Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0: { code: 4043, category: ts.DiagnosticCategory.Error, key: "Return type of public property getter from exported class has or is using private name '{0}'." },
Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1: { code: 4044, category: ts.DiagnosticCategory.Error, key: "Return type of constructor signature from exported interface has or is using name '{0}' from private module '{1}'." },
Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0: { code: 4045, category: ts.DiagnosticCategory.Error, key: "Return type of constructor signature from exported interface has or is using private name '{0}'." },
Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1: { code: 4046, category: ts.DiagnosticCategory.Error, key: "Return type of call signature from exported interface has or is using name '{0}' from private module '{1}'." },
Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0: { code: 4047, category: ts.DiagnosticCategory.Error, key: "Return type of call signature from exported interface has or is using private name '{0}'." },
Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1: { code: 4048, category: ts.DiagnosticCategory.Error, key: "Return type of index signature from exported interface has or is using name '{0}' from private module '{1}'." },
Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0: { code: 4049, category: ts.DiagnosticCategory.Error, key: "Return type of index signature from exported interface has or is using private name '{0}'." },
Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named: { code: 4050, category: ts.DiagnosticCategory.Error, key: "Return type of public static method from exported class has or is using name '{0}' from external module {1} but cannot be named." },
Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1: { code: 4051, category: ts.DiagnosticCategory.Error, key: "Return type of public static method from exported class has or is using name '{0}' from private module '{1}'." },
Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0: { code: 4052, category: ts.DiagnosticCategory.Error, key: "Return type of public static method from exported class has or is using private name '{0}'." },
Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named: { code: 4053, category: ts.DiagnosticCategory.Error, key: "Return type of public method from exported class has or is using name '{0}' from external module {1} but cannot be named." },
Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1: { code: 4054, category: ts.DiagnosticCategory.Error, key: "Return type of public method from exported class has or is using name '{0}' from private module '{1}'." },
Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0: { code: 4055, category: ts.DiagnosticCategory.Error, key: "Return type of public method from exported class has or is using private name '{0}'." },
Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1: { code: 4056, category: ts.DiagnosticCategory.Error, key: "Return type of method from exported interface has or is using name '{0}' from private module '{1}'." },
Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0: { code: 4057, category: ts.DiagnosticCategory.Error, key: "Return type of method from exported interface has or is using private name '{0}'." },
Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named: { code: 4058, category: ts.DiagnosticCategory.Error, key: "Return type of exported function has or is using name '{0}' from external module {1} but cannot be named." },
Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1: { code: 4059, category: ts.DiagnosticCategory.Error, key: "Return type of exported function has or is using name '{0}' from private module '{1}'." },
Return_type_of_exported_function_has_or_is_using_private_name_0: { code: 4060, category: ts.DiagnosticCategory.Error, key: "Return type of exported function has or is using private name '{0}'." },
Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4061, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of constructor from exported class has or is using name '{1}' from external module {2} but cannot be named." },
Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4062, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of constructor from exported class has or is using name '{1}' from private module '{2}'." },
Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1: { code: 4063, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of constructor from exported class has or is using private name '{1}'." },
Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4064, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'." },
Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 4065, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'." },
Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4066, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'." },
Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 4067, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of call signature from exported interface has or is using private name '{1}'." },
Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4068, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public static method from exported class has or is using name '{1}' from external module {2} but cannot be named." },
Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4069, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'." },
Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1: { code: 4070, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public static method from exported class has or is using private name '{1}'." },
Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4071, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public method from exported class has or is using name '{1}' from external module {2} but cannot be named." },
Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4072, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'." },
Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1: { code: 4073, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of public method from exported class has or is using private name '{1}'." },
Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4074, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'." },
Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1: { code: 4075, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of method from exported interface has or is using private name '{1}'." },
Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4076, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from external module {2} but cannot be named." },
Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." },
Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using private name '{1}'." },
Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: ts.DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using private name '{1}'." },
Default_export_of_the_module_has_or_is_using_private_name_0: { code: 4082, category: ts.DiagnosticCategory.Error, key: "Default export of the module has or is using private name '{0}'." },
Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher: { code: 4091, category: ts.DiagnosticCategory.Error, key: "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher." },
The_current_host_does_not_support_the_0_option: { code: 5001, category: ts.DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." },
Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: ts.DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." },
Cannot_read_file_0_Colon_1: { code: 5012, category: ts.DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" },
Unsupported_file_encoding: { code: 5013, category: ts.DiagnosticCategory.Error, key: "Unsupported file encoding." },
Failed_to_parse_file_0_Colon_1: { code: 5014, category: ts.DiagnosticCategory.Error, key: "Failed to parse file '{0}': {1}." },
Unknown_compiler_option_0: { code: 5023, category: ts.DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." },
Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: ts.DiagnosticCategory.Error, key: "Compiler option '{0}' requires a value of type {1}." },
Could_not_write_file_0_Colon_1: { code: 5033, category: ts.DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" },
Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: ts.DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." },
Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher: { code: 5047, category: ts.DiagnosticCategory.Error, key: "Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." },
Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided: { code: 5051, category: ts.DiagnosticCategory.Error, key: "Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided." },
Option_0_cannot_be_specified_without_specifying_option_1: { code: 5052, category: ts.DiagnosticCategory.Error, key: "Option '{0}' cannot be specified without specifying option '{1}'." },
Option_0_cannot_be_specified_with_option_1: { code: 5053, category: ts.DiagnosticCategory.Error, key: "Option '{0}' cannot be specified with option '{1}'." },
A_tsconfig_json_file_is_already_defined_at_Colon_0: { code: 5053, category: ts.DiagnosticCategory.Error, key: "A 'tsconfig.json' file is already defined at: '{0}'." },
Concatenate_and_emit_output_to_single_file: { code: 6001, category: ts.DiagnosticCategory.Message, key: "Concatenate and emit output to single file." },
Generates_corresponding_d_ts_file: { code: 6002, category: ts.DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." },
Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: ts.DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." },
Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations: { code: 6004, category: ts.DiagnosticCategory.Message, key: "Specifies the location where debugger should locate TypeScript files instead of source locations." },
Watch_input_files: { code: 6005, category: ts.DiagnosticCategory.Message, key: "Watch input files." },
Redirect_output_structure_to_the_directory: { code: 6006, category: ts.DiagnosticCategory.Message, key: "Redirect output structure to the directory." },
Do_not_erase_const_enum_declarations_in_generated_code: { code: 6007, category: ts.DiagnosticCategory.Message, key: "Do not erase const enum declarations in generated code." },
Do_not_emit_outputs_if_any_errors_were_reported: { code: 6008, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs if any errors were reported." },
Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do not emit comments to output." },
Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do not emit outputs." },
Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" },
Specify_module_code_generation_Colon_commonjs_amd_system_or_umd: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', 'system' or 'umd'" },
Print_this_message: { code: 6017, category: ts.DiagnosticCategory.Message, key: "Print this message." },
Print_the_compiler_s_version: { code: 6019, category: ts.DiagnosticCategory.Message, key: "Print the compiler's version." },
Compile_the_project_in_the_given_directory: { code: 6020, category: ts.DiagnosticCategory.Message, key: "Compile the project in the given directory." },
Syntax_Colon_0: { code: 6023, category: ts.DiagnosticCategory.Message, key: "Syntax: {0}" },
options: { code: 6024, category: ts.DiagnosticCategory.Message, key: "options" },
file: { code: 6025, category: ts.DiagnosticCategory.Message, key: "file" },
Examples_Colon_0: { code: 6026, category: ts.DiagnosticCategory.Message, key: "Examples: {0}" },
Options_Colon: { code: 6027, category: ts.DiagnosticCategory.Message, key: "Options:" },
Version_0: { code: 6029, category: ts.DiagnosticCategory.Message, key: "Version {0}" },
Insert_command_line_options_and_files_from_a_file: { code: 6030, category: ts.DiagnosticCategory.Message, key: "Insert command line options and files from a file." },
File_change_detected_Starting_incremental_compilation: { code: 6032, category: ts.DiagnosticCategory.Message, key: "File change detected. Starting incremental compilation..." },
KIND: { code: 6034, category: ts.DiagnosticCategory.Message, key: "KIND" },
FILE: { code: 6035, category: ts.DiagnosticCategory.Message, key: "FILE" },
VERSION: { code: 6036, category: ts.DiagnosticCategory.Message, key: "VERSION" },
LOCATION: { code: 6037, category: ts.DiagnosticCategory.Message, key: "LOCATION" },
DIRECTORY: { code: 6038, category: ts.DiagnosticCategory.Message, key: "DIRECTORY" },
Compilation_complete_Watching_for_file_changes: { code: 6042, category: ts.DiagnosticCategory.Message, key: "Compilation complete. Watching for file changes." },
Generates_corresponding_map_file: { code: 6043, category: ts.DiagnosticCategory.Message, key: "Generates corresponding '.map' file." },
Compiler_option_0_expects_an_argument: { code: 6044, category: ts.DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." },
Unterminated_quoted_string_in_response_file_0: { code: 6045, category: ts.DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." },
Argument_for_module_option_must_be_commonjs_amd_system_or_umd: { code: 6046, category: ts.DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', 'system' or 'umd'." },
Argument_for_target_option_must_be_ES3_ES5_or_ES6: { code: 6047, category: ts.DiagnosticCategory.Error, key: "Argument for '--target' option must be 'ES3', 'ES5', or 'ES6'." },
Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: 6048, category: ts.DiagnosticCategory.Error, key: "Locale must be of the form <language> or <language>-<territory>. For example '{0}' or '{1}'." },
Unsupported_locale_0: { code: 6049, category: ts.DiagnosticCategory.Error, key: "Unsupported locale '{0}'." },
Unable_to_open_file_0: { code: 6050, category: ts.DiagnosticCategory.Error, key: "Unable to open file '{0}'." },
Corrupted_locale_file_0: { code: 6051, category: ts.DiagnosticCategory.Error, key: "Corrupted locale file {0}." },
Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: ts.DiagnosticCategory.Message, key: "Raise error on expressions and declarations with an implied 'any' type." },
File_0_not_found: { code: 6053, category: ts.DiagnosticCategory.Error, key: "File '{0}' not found." },
File_0_has_unsupported_extension_The_only_supported_extensions_are_1: { code: 6054, category: ts.DiagnosticCategory.Error, key: "File '{0}' has unsupported extension. The only supported extensions are {1}." },
Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: ts.DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." },
Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: ts.DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." },
Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir: { code: 6058, category: ts.DiagnosticCategory.Message, key: "Specifies the root directory of input files. Use to control the output directory structure with --outDir." },
File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files: { code: 6059, category: ts.DiagnosticCategory.Error, key: "File '{0}' is not under 'rootDir' '{1}'. 'rootDir' is expected to contain all source files." },
Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: ts.DiagnosticCategory.Message, key: "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix)." },
NEWLINE: { code: 6061, category: ts.DiagnosticCategory.Message, key: "NEWLINE" },
Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, category: ts.DiagnosticCategory.Error, key: "Argument for '--newLine' option must be 'CRLF' or 'LF'." },
Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: ts.DiagnosticCategory.Message, key: "Specify JSX code generation: 'preserve' or 'react'" },
Argument_for_jsx_must_be_preserve_or_react: { code: 6081, category: ts.DiagnosticCategory.Message, key: "Argument for '--jsx' must be 'preserve' or 'react'." },
Enables_experimental_support_for_ES7_decorators: { code: 6065, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." },
Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." },
Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower: { code: 6067, category: ts.DiagnosticCategory.Message, key: "Option 'experimentalAsyncFunctions' cannot be specified when targeting ES5 or lower." },
Enables_experimental_support_for_ES7_async_functions: { code: 6068, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 async functions." },
Specifies_module_resolution_strategy_Colon_node_Node_or_classic_TypeScript_pre_1_6: { code: 6069, category: ts.DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node) or 'classic' (TypeScript pre 1.6) ." },
Initializes_a_TypeScript_project_and_creates_a_tsconfig_json_file: { code: 6070, category: ts.DiagnosticCategory.Message, key: "Initializes a TypeScript project and creates a tsconfig.json file." },
Successfully_created_a_tsconfig_json_file: { code: 6071, category: ts.DiagnosticCategory.Message, key: "Successfully created a tsconfig.json file." },
Suppress_excess_property_checks_for_object_literals: { code: 6072, category: ts.DiagnosticCategory.Message, key: "Suppress excess property checks for object literals." },
Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." },
Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." },
Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." },
new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type: { code: 7009, category: ts.DiagnosticCategory.Error, key: "'new' expression, whose target lacks a construct signature, implicitly has an 'any' type." },
_0_which_lacks_return_type_annotation_implicitly_has_an_1_return_type: { code: 7010, category: ts.DiagnosticCategory.Error, key: "'{0}', which lacks return-type annotation, implicitly has an '{1}' return type." },
Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type: { code: 7011, category: ts.DiagnosticCategory.Error, key: "Function expression, which lacks return-type annotation, implicitly has an '{0}' return type." },
Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: { code: 7013, category: ts.DiagnosticCategory.Error, key: "Construct signature, which lacks return-type annotation, implicitly has an 'any' return type." },
Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_type_annotation: { code: 7016, category: ts.DiagnosticCategory.Error, key: "Property '{0}' implicitly has type 'any', because its 'set' accessor lacks a type annotation." },
Index_signature_of_object_type_implicitly_has_an_any_type: { code: 7017, category: ts.DiagnosticCategory.Error, key: "Index signature of object type implicitly has an 'any' type." },
Object_literal_s_property_0_implicitly_has_an_1_type: { code: 7018, category: ts.DiagnosticCategory.Error, key: "Object literal's property '{0}' implicitly has an '{1}' type." },
Rest_parameter_0_implicitly_has_an_any_type: { code: 7019, category: ts.DiagnosticCategory.Error, key: "Rest parameter '{0}' implicitly has an 'any[]' type." },
Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: { code: 7020, category: ts.DiagnosticCategory.Error, key: "Call signature, which lacks return-type annotation, implicitly has an 'any' return type." },
_0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer." },
_0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: ts.DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type: { code: 7025, category: ts.DiagnosticCategory.Error, key: "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type." },
JSX_element_implicitly_has_type_any_because_no_interface_JSX_0_exists: { code: 7026, category: ts.DiagnosticCategory.Error, key: "JSX element implicitly has type 'any' because no interface 'JSX.{0}' exists" },
You_cannot_rename_this_element: { code: 8000, category: ts.DiagnosticCategory.Error, key: "You cannot rename this element." },
You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: ts.DiagnosticCategory.Error, key: "You cannot rename elements that are defined in the standard TypeScript library." },
import_can_only_be_used_in_a_ts_file: { code: 8002, category: ts.DiagnosticCategory.Error, key: "'import ... =' can only be used in a .ts file." },
export_can_only_be_used_in_a_ts_file: { code: 8003, category: ts.DiagnosticCategory.Error, key: "'export=' can only be used in a .ts file." },
type_parameter_declarations_can_only_be_used_in_a_ts_file: { code: 8004, category: ts.DiagnosticCategory.Error, key: "'type parameter declarations' can only be used in a .ts file." },
implements_clauses_can_only_be_used_in_a_ts_file: { code: 8005, category: ts.DiagnosticCategory.Error, key: "'implements clauses' can only be used in a .ts file." },
interface_declarations_can_only_be_used_in_a_ts_file: { code: 8006, category: ts.DiagnosticCategory.Error, key: "'interface declarations' can only be used in a .ts file." },
module_declarations_can_only_be_used_in_a_ts_file: { code: 8007, category: ts.DiagnosticCategory.Error, key: "'module declarations' can only be used in a .ts file." },
type_aliases_can_only_be_used_in_a_ts_file: { code: 8008, category: ts.DiagnosticCategory.Error, key: "'type aliases' can only be used in a .ts file." },
_0_can_only_be_used_in_a_ts_file: { code: 8009, category: ts.DiagnosticCategory.Error, key: "'{0}' can only be used in a .ts file." },
types_can_only_be_used_in_a_ts_file: { code: 8010, category: ts.DiagnosticCategory.Error, key: "'types' can only be used in a .ts file." },
type_arguments_can_only_be_used_in_a_ts_file: { code: 8011, category: ts.DiagnosticCategory.Error, key: "'type arguments' can only be used in a .ts file." },
parameter_modifiers_can_only_be_used_in_a_ts_file: { code: 8012, category: ts.DiagnosticCategory.Error, key: "'parameter modifiers' can only be used in a .ts file." },
property_declarations_can_only_be_used_in_a_ts_file: { code: 8014, category: ts.DiagnosticCategory.Error, key: "'property declarations' can only be used in a .ts file." },
enum_declarations_can_only_be_used_in_a_ts_file: { code: 8015, category: ts.DiagnosticCategory.Error, key: "'enum declarations' can only be used in a .ts file." },
type_assertion_expressions_can_only_be_used_in_a_ts_file: { code: 8016, category: ts.DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in a .ts file." },
decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: ts.DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." },
Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clauses: { code: 9002, category: ts.DiagnosticCategory.Error, key: "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses." },
class_expressions_are_not_currently_supported: { code: 9003, category: ts.DiagnosticCategory.Error, key: "'class' expressions are not currently supported." },
JSX_attributes_must_only_be_assigned_a_non_empty_expression: { code: 17000, category: ts.DiagnosticCategory.Error, key: "JSX attributes must only be assigned a non-empty 'expression'." },
JSX_elements_cannot_have_multiple_attributes_with_the_same_name: { code: 17001, category: ts.DiagnosticCategory.Error, key: "JSX elements cannot have multiple attributes with the same name." },
Expected_corresponding_JSX_closing_tag_for_0: { code: 17002, category: ts.DiagnosticCategory.Error, key: "Expected corresponding JSX closing tag for '{0}'." },
JSX_attribute_expected: { code: 17003, category: ts.DiagnosticCategory.Error, key: "JSX attribute expected." },
Cannot_use_JSX_unless_the_jsx_flag_is_provided: { code: 17004, category: ts.DiagnosticCategory.Error, key: "Cannot use JSX unless the '--jsx' flag is provided." },
A_constructor_cannot_contain_a_super_call_when_its_class_extends_null: { code: 17005, category: ts.DiagnosticCategory.Error, key: "A constructor cannot contain a 'super' call when its class extends 'null'" }
};
})(ts || (ts = {}));
/// <reference path="core.ts"/>
/// <reference path="diagnosticInformationMap.generated.ts"/>
var ts;
(function (ts) {
var textToToken = {
"abstract": 113 /* AbstractKeyword */,
"any": 115 /* AnyKeyword */,
"as": 114 /* AsKeyword */,
"boolean": 118 /* BooleanKeyword */,
"break": 68 /* BreakKeyword */,
"case": 69 /* CaseKeyword */,
"catch": 70 /* CatchKeyword */,
"class": 71 /* ClassKeyword */,
"continue": 73 /* ContinueKeyword */,
"const": 72 /* ConstKeyword */,
"constructor": 119 /* ConstructorKeyword */,
"debugger": 74 /* DebuggerKeyword */,
"declare": 120 /* DeclareKeyword */,
"default": 75 /* DefaultKeyword */,
"delete": 76 /* DeleteKeyword */,
"do": 77 /* DoKeyword */,
"else": 78 /* ElseKeyword */,
"enum": 79 /* EnumKeyword */,
"export": 80 /* ExportKeyword */,
"extends": 81 /* ExtendsKeyword */,
"false": 82 /* FalseKeyword */,
"finally": 83 /* FinallyKeyword */,
"for": 84 /* ForKeyword */,
"from": 131 /* FromKeyword */,
"function": 85 /* FunctionKeyword */,
"get": 121 /* GetKeyword */,
"if": 86 /* IfKeyword */,
"implements": 104 /* ImplementsKeyword */,
"import": 87 /* ImportKeyword */,
"in": 88 /* InKeyword */,
"instanceof": 89 /* InstanceOfKeyword */,
"interface": 105 /* InterfaceKeyword */,
"is": 122 /* IsKeyword */,
"let": 106 /* LetKeyword */,
"module": 123 /* ModuleKeyword */,
"namespace": 124 /* NamespaceKeyword */,
"new": 90 /* NewKeyword */,
"null": 91 /* NullKeyword */,
"number": 126 /* NumberKeyword */,
"package": 107 /* PackageKeyword */,
"private": 108 /* PrivateKeyword */,
"protected": 109 /* ProtectedKeyword */,
"public": 110 /* PublicKeyword */,
"require": 125 /* RequireKeyword */,
"return": 92 /* ReturnKeyword */,
"set": 127 /* SetKeyword */,
"static": 111 /* StaticKeyword */,
"string": 128 /* StringKeyword */,
"super": 93 /* SuperKeyword */,
"switch": 94 /* SwitchKeyword */,
"symbol": 129 /* SymbolKeyword */,
"this": 95 /* ThisKeyword */,
"throw": 96 /* ThrowKeyword */,
"true": 97 /* TrueKeyword */,
"try": 98 /* TryKeyword */,
"type": 130 /* TypeKeyword */,
"typeof": 99 /* TypeOfKeyword */,
"var": 100 /* VarKeyword */,
"void": 101 /* VoidKeyword */,
"while": 102 /* WhileKeyword */,
"with": 103 /* WithKeyword */,
"yield": 112 /* YieldKeyword */,
"async": 116 /* AsyncKeyword */,
"await": 117 /* AwaitKeyword */,
"of": 132 /* OfKeyword */,
"{": 15 /* OpenBraceToken */,
"}": 16 /* CloseBraceToken */,
"(": 17 /* OpenParenToken */,
")": 18 /* CloseParenToken */,
"[": 19 /* OpenBracketToken */,
"]": 20 /* CloseBracketToken */,
".": 21 /* DotToken */,
"...": 22 /* DotDotDotToken */,
";": 23 /* SemicolonToken */,
",": 24 /* CommaToken */,
"<": 25 /* LessThanToken */,
">": 27 /* GreaterThanToken */,
"<=": 28 /* LessThanEqualsToken */,
">=": 29 /* GreaterThanEqualsToken */,
"==": 30 /* EqualsEqualsToken */,
"!=": 31 /* ExclamationEqualsToken */,
"===": 32 /* EqualsEqualsEqualsToken */,
"!==": 33 /* ExclamationEqualsEqualsToken */,
"=>": 34 /* EqualsGreaterThanToken */,
"+": 35 /* PlusToken */,
"-": 36 /* MinusToken */,
"*": 37 /* AsteriskToken */,
"/": 38 /* SlashToken */,
"%": 39 /* PercentToken */,
"++": 40 /* PlusPlusToken */,
"--": 41 /* MinusMinusToken */,
"<<": 42 /* LessThanLessThanToken */,
"</": 26 /* LessThanSlashToken */,
">>": 43 /* GreaterThanGreaterThanToken */,
">>>": 44 /* GreaterThanGreaterThanGreaterThanToken */,
"&": 45 /* AmpersandToken */,
"|": 46 /* BarToken */,
"^": 47 /* CaretToken */,
"!": 48 /* ExclamationToken */,
"~": 49 /* TildeToken */,
"&&": 50 /* AmpersandAmpersandToken */,
"||": 51 /* BarBarToken */,
"?": 52 /* QuestionToken */,
":": 53 /* ColonToken */,
"=": 55 /* EqualsToken */,
"+=": 56 /* PlusEqualsToken */,
"-=": 57 /* MinusEqualsToken */,
"*=": 58 /* AsteriskEqualsToken */,
"/=": 59 /* SlashEqualsToken */,
"%=": 60 /* PercentEqualsToken */,
"<<=": 61 /* LessThanLessThanEqualsToken */,
">>=": 62 /* GreaterThanGreaterThanEqualsToken */,
">>>=": 63 /* GreaterThanGreaterThanGreaterThanEqualsToken */,
"&=": 64 /* AmpersandEqualsToken */,
"|=": 65 /* BarEqualsToken */,
"^=": 66 /* CaretEqualsToken */,
"@": 54 /* AtToken */
};
/*
As per ECMAScript Language Specification 3th Edition, Section 7.6: Identifiers
IdentifierStart ::
Can contain Unicode 3.0.0 categories:
Uppercase letter (Lu),
Lowercase letter (Ll),
Titlecase letter (Lt),
Modifier letter (Lm),
Other letter (Lo), or
Letter number (Nl).
IdentifierPart :: =
Can contain IdentifierStart + Unicode 3.0.0 categories:
Non-spacing mark (Mn),
Combining spacing mark (Mc),
Decimal number (Nd), or
Connector punctuation (Pc).
Codepoint ranges for ES3 Identifiers are extracted from the Unicode 3.0.0 specification at:
http://www.unicode.org/Public/3.0-Update/UnicodeData-3.0.0.txt
*/
var unicodeES3IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1610, 1649, 1747, 1749, 1749, 1765, 1766, 1786, 1788, 1808, 1808, 1810, 1836, 1920, 1957, 2309, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2784, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3294, 3294, 3296, 3297, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3424, 3425, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3805, 3840, 3840, 3904, 3911, 3913, 3946, 3976, 3979, 4096, 4129, 4131, 4135, 4137, 4138, 4176, 4181, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6067, 6176, 6263, 6272, 6312, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8319, 8319, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12346, 12353, 12436, 12445, 12446, 12449, 12538, 12540, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65138, 65140, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,];
var unicodeES3IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 768, 846, 864, 866, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1155, 1158, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1441, 1443, 1465, 1467, 1469, 1471, 1471, 1473, 1474, 1476, 1476, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1621, 1632, 1641, 1648, 1747, 1749, 1756, 1759, 1768, 1770, 1773, 1776, 1788, 1808, 1836, 1840, 1866, 1920, 1968, 2305, 2307, 2309, 2361, 2364, 2381, 2384, 2388, 2392, 2403, 2406, 2415, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2492, 2494, 2500, 2503, 2504, 2507, 2509, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2562, 2562, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2649, 2652, 2654, 2654, 2662, 2676, 2689, 2691, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2784, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2876, 2883, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2913, 2918, 2927, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3031, 3031, 3047, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3134, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3168, 3169, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3262, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3297, 3302, 3311, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3390, 3395, 3398, 3400, 3402, 3405, 3415, 3415, 3424, 3425, 3430, 3439, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3805, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3946, 3953, 3972, 3974, 3979, 3984, 3991, 3993, 4028, 4038, 4038, 4096, 4129, 4131, 4135, 4137, 4138, 4140, 4146, 4150, 4153, 4160, 4169, 4176, 4185, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 4969, 4977, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6099, 6112, 6121, 6160, 6169, 6176, 6263, 6272, 6313, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8255, 8256, 8319, 8319, 8400, 8412, 8417, 8417, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12346, 12353, 12436, 12441, 12442, 12445, 12446, 12449, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65056, 65059, 65075, 65076, 65101, 65103, 65136, 65138, 65140, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65381, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,];
/*
As per ECMAScript Language Specification 5th Edition, Section 7.6: ISyntaxToken Names and Identifiers
IdentifierStart ::
Can contain Unicode 6.2 categories:
Uppercase letter (Lu),
Lowercase letter (Ll),
Titlecase letter (Lt),
Modifier letter (Lm),
Other letter (Lo), or
Letter number (Nl).
IdentifierPart ::
Can contain IdentifierStart + Unicode 6.2 categories:
Non-spacing mark (Mn),
Combining spacing mark (Mc),
Decimal number (Nd),
Connector punctuation (Pc),
<ZWNJ>, or
<ZWJ>.
Codepoint ranges for ES5 Identifiers are extracted from the Unicode 6.2 specification at:
http://www.unicode.org/Public/6.2.0/ucd/UnicodeData.txt
*/
var unicodeES5IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, 2088, 2112, 2136, 2208, 2208, 2210, 2220, 2308, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2417, 2423, 2425, 2431, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2785, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3133, 3160, 3161, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3424, 3425, 3450, 3455, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000, 6016, 6067, 6103, 6103, 6108, 6108, 6176, 6263, 6272, 6312, 6314, 6314, 6320, 6389, 6400, 6428, 6480, 6509, 6512, 6516, 6528, 6571, 6593, 6599, 6656, 6678, 6688, 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, 7168, 7203, 7245, 7247, 7258, 7293, 7401, 7404, 7406, 7409, 7413, 7414, 7424, 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11823, 11823, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12348, 12353, 12438, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, 42539, 42560, 42606, 42623, 42647, 42656, 42735, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43009, 43011, 43013, 43015, 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43520, 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43648, 43695, 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44002, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,];
var unicodeES5IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1155, 1159, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1520, 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2048, 2093, 2112, 2139, 2208, 2208, 2210, 2220, 2276, 2302, 2304, 2403, 2406, 2415, 2417, 2423, 2425, 2431, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3160, 3161, 3168, 3171, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3396, 3398, 3400, 3402, 3406, 3415, 3415, 3424, 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6000, 6002, 6003, 6016, 6099, 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6263, 6272, 6314, 6320, 6389, 6400, 6428, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6608, 6617, 6656, 6683, 6688, 6750, 6752, 6780, 6783, 6793, 6800, 6809, 6823, 6823, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, 7168, 7223, 7232, 7241, 7245, 7293, 7376, 7378, 7380, 7414, 7424, 7654, 7676, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8204, 8205, 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11744, 11775, 11823, 11823, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12442, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42539, 42560, 42607, 42612, 42621, 42623, 42647, 42655, 42737, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43047, 43072, 43123, 43136, 43204, 43216, 43225, 43232, 43255, 43259, 43259, 43264, 43309, 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43520, 43574, 43584, 43597, 43600, 43609, 43616, 43638, 43642, 43643, 43648, 43714, 43739, 43741, 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44010, 44012, 44013, 44016, 44025, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65024, 65039, 65056, 65062, 65075, 65076, 65101, 65103, 65136, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,];
function lookupInUnicodeMap(code, map) {
// Bail out quickly if it couldn't possibly be in the map.
if (code < map[0]) {
return false;
}
// Perform binary search in one of the Unicode range maps
var lo = 0;
var hi = map.length;
var mid;
while (lo + 1 < hi) {
mid = lo + (hi - lo) / 2;
// mid has to be even to catch a range's beginning
mid -= mid % 2;
if (map[mid] <= code && code <= map[mid + 1]) {
return true;
}
if (code < map[mid]) {
hi = mid;
}
else {
lo = mid + 2;
}
}
return false;
}
/* @internal */ function isUnicodeIdentifierStart(code, languageVersion) {
return languageVersion >= 1 /* ES5 */ ?
lookupInUnicodeMap(code, unicodeES5IdentifierStart) :
lookupInUnicodeMap(code, unicodeES3IdentifierStart);
}
ts.isUnicodeIdentifierStart = isUnicodeIdentifierStart;
function isUnicodeIdentifierPart(code, languageVersion) {
return languageVersion >= 1 /* ES5 */ ?
lookupInUnicodeMap(code, unicodeES5IdentifierPart) :
lookupInUnicodeMap(code, unicodeES3IdentifierPart);
}
function makeReverseMap(source) {
var result = [];
for (var name_4 in source) {
if (source.hasOwnProperty(name_4)) {
result[source[name_4]] = name_4;
}
}
return result;
}
var tokenStrings = makeReverseMap(textToToken);
function tokenToString(t) {
return tokenStrings[t];
}
ts.tokenToString = tokenToString;
/* @internal */
function stringToToken(s) {
return textToToken[s];
}
ts.stringToToken = stringToToken;
/* @internal */
function computeLineStarts(text) {
var result = new Array();
var pos = 0;
var lineStart = 0;
while (pos < text.length) {
var ch = text.charCodeAt(pos++);
switch (ch) {
case 13 /* carriageReturn */:
if (text.charCodeAt(pos) === 10 /* lineFeed */) {
pos++;
}
case 10 /* lineFeed */:
result.push(lineStart);
lineStart = pos;
break;
default:
if (ch > 127 /* maxAsciiCharacter */ && isLineBreak(ch)) {
result.push(lineStart);
lineStart = pos;
}
break;
}
}
result.push(lineStart);
return result;
}
ts.computeLineStarts = computeLineStarts;
function getPositionOfLineAndCharacter(sourceFile, line, character) {
return computePositionOfLineAndCharacter(getLineStarts(sourceFile), line, character);
}
ts.getPositionOfLineAndCharacter = getPositionOfLineAndCharacter;
/* @internal */
function computePositionOfLineAndCharacter(lineStarts, line, character) {
ts.Debug.assert(line >= 0 && line < lineStarts.length);
return lineStarts[line] + character;
}
ts.computePositionOfLineAndCharacter = computePositionOfLineAndCharacter;
/* @internal */
function getLineStarts(sourceFile) {
return sourceFile.lineMap || (sourceFile.lineMap = computeLineStarts(sourceFile.text));
}
ts.getLineStarts = getLineStarts;
/* @internal */
/**
* We assume the first line starts at position 0 and 'position' is non-negative.
*/
function computeLineAndCharacterOfPosition(lineStarts, position) {
var lineNumber = ts.binarySearch(lineStarts, position);
if (lineNumber < 0) {
// If the actual position was not found,
// the binary search returns the 2's-complement of the next line start
// e.g. if the line starts at [5, 10, 23, 80] and the position requested was 20
// then the search will return -2.
//
// We want the index of the previous line start, so we subtract 1.
// Review 2's-complement if this is confusing.
lineNumber = ~lineNumber - 1;
ts.Debug.assert(lineNumber !== -1, "position cannot precede the beginning of the file");
}
return {
line: lineNumber,
character: position - lineStarts[lineNumber]
};
}
ts.computeLineAndCharacterOfPosition = computeLineAndCharacterOfPosition;
function getLineAndCharacterOfPosition(sourceFile, position) {
return computeLineAndCharacterOfPosition(getLineStarts(sourceFile), position);
}
ts.getLineAndCharacterOfPosition = getLineAndCharacterOfPosition;
var hasOwnProperty = Object.prototype.hasOwnProperty;
function isWhiteSpace(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 */;
}
ts.isWhiteSpace = isWhiteSpace;
function 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
// \u000A Line Feed <LF>
// \u000D Carriage Return <CR>
// \u2028 Line separator <LS>
// \u2029 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 */;
}
ts.isLineBreak = isLineBreak;
function isDigit(ch) {
return ch >= 48 /* _0 */ && ch <= 57 /* _9 */;
}
/* @internal */
function isOctalDigit(ch) {
return ch >= 48 /* _0 */ && ch <= 55 /* _7 */;
}
ts.isOctalDigit = isOctalDigit;
function couldStartTrivia(text, pos) {
// Keep in sync with skipTrivia
var ch = text.charCodeAt(pos);
switch (ch) {
case 13 /* carriageReturn */:
case 10 /* lineFeed */:
case 9 /* tab */:
case 11 /* verticalTab */:
case 12 /* formFeed */:
case 32 /* space */:
case 47 /* slash */:
// starts of normal trivia
case 60 /* lessThan */:
case 61 /* equals */:
case 62 /* greaterThan */:
// Starts of conflict marker trivia
return true;
case 35 /* hash */:
// Only if its the beginning can we have #! trivia
return pos === 0;
default:
return ch > 127 /* maxAsciiCharacter */;
}
}
ts.couldStartTrivia = couldStartTrivia;
/* @internal */
function skipTrivia(text, pos, stopAfterLineBreak) {
// Keep in sync with couldStartTrivia
while (true) {
var ch = text.charCodeAt(pos);
switch (ch) {
case 13 /* carriageReturn */:
if (text.charCodeAt(pos + 1) === 10 /* lineFeed */) {
pos++;
}
case 10 /* lineFeed */:
pos++;
if (stopAfterLineBreak) {
return pos;
}
continue;
case 9 /* tab */:
case 11 /* verticalTab */:
case 12 /* formFeed */:
case 32 /* space */:
pos++;
continue;
case 47 /* slash */:
if (text.charCodeAt(pos + 1) === 47 /* slash */) {
pos += 2;
while (pos < text.length) {
if (isLineBreak(text.charCodeAt(pos))) {
break;
}
pos++;
}
continue;
}
if (text.charCodeAt(pos + 1) === 42 /* asterisk */) {
pos += 2;
while (pos < text.length) {
if (text.charCodeAt(pos) === 42 /* asterisk */ && text.charCodeAt(pos + 1) === 47 /* slash */) {
pos += 2;
break;
}
pos++;
}
continue;
}
break;
case 60 /* lessThan */:
case 61 /* equals */:
case 62 /* greaterThan */:
if (isConflictMarkerTrivia(text, pos)) {
pos = scanConflictMarkerTrivia(text, pos);
continue;
}
break;
case 35 /* hash */:
if (pos === 0 && isShebangTrivia(text, pos)) {
pos = scanShebangTrivia(text, pos);
continue;
}
break;
default:
if (ch > 127 /* maxAsciiCharacter */ && (isWhiteSpace(ch) || isLineBreak(ch))) {
pos++;
continue;
}
break;
}
return pos;
}
}
ts.skipTrivia = skipTrivia;
// All conflict markers consist of the same character repeated seven times. If it is
// a <<<<<<< or >>>>>>> marker then it is also followd by a space.
var mergeConflictMarkerLength = "<<<<<<<".length;
function isConflictMarkerTrivia(text, pos) {
ts.Debug.assert(pos >= 0);
// Conflict markers must be at the start of a line.
if (pos === 0 || isLineBreak(text.charCodeAt(pos - 1))) {
var ch = text.charCodeAt(pos);
if ((pos + mergeConflictMarkerLength) < text.length) {
for (var i = 0, n = mergeConflictMarkerLength; i < n; i++) {
if (text.charCodeAt(pos + i) !== ch) {
return false;
}
}
return ch === 61 /* equals */ ||
text.charCodeAt(pos + mergeConflictMarkerLength) === 32 /* space */;
}
}
return false;
}
function scanConflictMarkerTrivia(text, pos, error) {
if (error) {
error(ts.Diagnostics.Merge_conflict_marker_encountered, mergeConflictMarkerLength);
}
var ch = text.charCodeAt(pos);
var len = text.length;
if (ch === 60 /* lessThan */ || ch === 62 /* greaterThan */) {
while (pos < len && !isLineBreak(text.charCodeAt(pos))) {
pos++;
}
}
else {
ts.Debug.assert(ch === 61 /* equals */);
// Consume everything from the start of the mid-conlict marker to the start of the next
// end-conflict marker.
while (pos < len) {
var ch_1 = text.charCodeAt(pos);
if (ch_1 === 62 /* greaterThan */ && isConflictMarkerTrivia(text, pos)) {
break;
}
pos++;
}
}
return pos;
}
var shebangTriviaRegex = /^#!.*/;
function isShebangTrivia(text, pos) {
// Shebangs check must only be done at the start of the file
ts.Debug.assert(pos === 0);
return shebangTriviaRegex.test(text);
}
function scanShebangTrivia(text, pos) {
var shebang = shebangTriviaRegex.exec(text)[0];
pos = pos + shebang.length;
return pos;
}
/**
* Extract comments from text prefixing the token closest following `pos`.
* The return value is an array containing a TextRange for each comment.
* Single-line comment ranges include the beginning '//' characters but not the ending line break.
* Multi - line comment ranges include the beginning '/* and ending '<asterisk>/' characters.
* The return value is undefined if no comments were found.
* @param trailing
* If false, whitespace is skipped until the first line break and comments between that location
* and the next token are returned.
* If true, comments occurring between the given position and the next line break are returned.
*/
function getCommentRanges(text, pos, trailing) {
var result;
var collecting = trailing || pos === 0;
while (true) {
var ch = text.charCodeAt(pos);
switch (ch) {
case 13 /* carriageReturn */:
if (text.charCodeAt(pos + 1) === 10 /* lineFeed */) {
pos++;
}
case 10 /* lineFeed */:
pos++;
if (trailing) {
return result;
}
collecting = true;
if (result && result.length) {
ts.lastOrUndefined(result).hasTrailingNewLine = 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 (!result) {
result = [];
}
result.push({ pos: startPos, end: pos, hasTrailingNewLine: hasTrailingNewLine, kind: kind });
}
continue;
}
break;
default:
if (ch > 127 /* maxAsciiCharacter */ && (isWhiteSpace(ch) || isLineBreak(ch))) {
if (result && result.length && isLineBreak(ch)) {
ts.lastOrUndefined(result).hasTrailingNewLine = true;
}
pos++;
continue;
}
break;
}
return result;
}
}
function getLeadingCommentRanges(text, pos) {
return getCommentRanges(text, pos, /*trailing*/ false);
}
ts.getLeadingCommentRanges = getLeadingCommentRanges;
function getTrailingCommentRanges(text, pos) {
return getCommentRanges(text, pos, /*trailing*/ true);
}
ts.getTrailingCommentRanges = getTrailingCommentRanges;
/** Optionally, get the shebang */
function getShebang(text) {
return shebangTriviaRegex.test(text)
? shebangTriviaRegex.exec(text)[0]
: undefined;
}
ts.getShebang = getShebang;
function 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);
}
ts.isIdentifierStart = isIdentifierStart;
function 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);
}
ts.isIdentifierPart = isIdentifierPart;
// Creates a scanner over a (possibly unspecified) range of a piece of text.
function createScanner(languageVersion, skipTrivia, languageVariant, text, onError, start, length) {
if (languageVariant === void 0) { languageVariant = 0 /* Standard */; }
// Current position (end position of text of current token)
var pos;
// end of text
var end;
// Start position of whitespace before current token
var startPos;
// Start position of text of current token
var tokenPos;
var token;
var tokenValue;
var precedingLineBreak;
var hasExtendedUnicodeEscape;
var tokenIsUnterminated;
setText(text, start, length);
return {
getStartPos: function () { return startPos; },
getTextPos: function () { return pos; },
getToken: function () { return token; },
getTokenPos: function () { return tokenPos; },
getTokenText: function () { return text.substring(tokenPos, pos); },
getTokenValue: function () { return tokenValue; },
hasExtendedUnicodeEscape: function () { return hasExtendedUnicodeEscape; },
hasPrecedingLineBreak: function () { return precedingLineBreak; },
isIdentifier: function () { return token === 67 /* Identifier */ || token > 103 /* LastReservedWord */; },
isReservedWord: function () { return token >= 68 /* FirstReservedWord */ && token <= 103 /* LastReservedWord */; },
isUnterminated: function () { return tokenIsUnterminated; },
reScanGreaterToken: reScanGreaterToken,
reScanSlashToken: reScanSlashToken,
reScanTemplateToken: reScanTemplateToken,
scanJsxIdentifier: scanJsxIdentifier,
reScanJsxToken: reScanJsxToken,
scanJsxToken: scanJsxToken,
scan: scan,
setText: setText,
setScriptTarget: setScriptTarget,
setLanguageVariant: setLanguageVariant,
setOnError: setOnError,
setTextPos: setTextPos,
tryScan: tryScan,
lookAhead: lookAhead
};
function error(message, length) {
if (onError) {
onError(message, length || 0);
}
}
function isIdentifierStart(ch) {
return ch >= 65 /* A */ && ch <= 90 /* Z */ || ch >= 97 /* a */ && ch <= 122 /* z */ ||
ch === 36 /* $ */ || ch === 95 /* _ */ ||
ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierStart(ch, languageVersion);
}
function isIdentifierPart(ch) {
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);
}
function scanNumber() {
var start = pos;
while (isDigit(text.charCodeAt(pos)))
pos++;
if (text.charCodeAt(pos) === 46 /* dot */) {
pos++;
while (isDigit(text.charCodeAt(pos)))
pos++;
}
var end = pos;
if (text.charCodeAt(pos) === 69 /* E */ || text.charCodeAt(pos) === 101 /* e */) {
pos++;
if (text.charCodeAt(pos) === 43 /* plus */ || text.charCodeAt(pos) === 45 /* minus */)
pos++;
if (isDigit(text.charCodeAt(pos))) {
pos++;
while (isDigit(text.charCodeAt(pos)))
pos++;
end = pos;
}
else {
error(ts.Diagnostics.Digit_expected);
}
}
return +(text.substring(start, end));
}
function scanOctalDigits() {
var start = pos;
while (isOctalDigit(text.charCodeAt(pos))) {
pos++;
}
return +(text.substring(start, pos));
}
/**
* Scans the given number of hexadecimal digits in the text,
* returning -1 if the given number is unavailable.
*/
function scanExactNumberOfHexDigits(count) {
return scanHexDigits(/*minCount*/ count, /*scanAsManyAsPossible*/ false);
}
/**
* Scans as many hexadecimal digits as are available in the text,
* returning -1 if the given number of digits was unavailable.
*/
function scanMinimumNumberOfHexDigits(count) {
return scanHexDigits(/*minCount*/ count, /*scanAsManyAsPossible*/ true);
}
function scanHexDigits(minCount, scanAsManyAsPossible) {
var digits = 0;
var value = 0;
while (digits < minCount || scanAsManyAsPossible) {
var ch = text.charCodeAt(pos);
if (ch >= 48 /* _0 */ && ch <= 57 /* _9 */) {
value = value * 16 + ch - 48 /* _0 */;
}
else if (ch >= 65 /* A */ && ch <= 70 /* F */) {
value = value * 16 + ch - 65 /* A */ + 10;
}
else if (ch >= 97 /* a */ && ch <= 102 /* f */) {
value = value * 16 + ch - 97 /* a */ + 10;
}
else {
break;
}
pos++;
digits++;
}
if (digits < minCount) {
value = -1;
}
return value;
}
function scanString() {
var quote = text.charCodeAt(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 */) {
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;
}
/**
* Sets the current 'tokenValue' and returns a NoSubstitutionTemplateLiteral or
* a literal component of a TemplateExpression.
*/
function scanTemplateAndSetTokenValue() {
var startedWithBacktick = text.charCodeAt(pos) === 96 /* backtick */;
pos++;
var start = pos;
var contents = "";
var resultingToken;
while (true) {
if (pos >= end) {
contents += text.substring(start, pos);
tokenIsUnterminated = true;
error(ts.Diagnostics.Unterminated_template_literal);
resultingToken = startedWithBacktick ? 11 /* NoSubstitutionTemplateLiteral */ : 14 /* TemplateTail */;
break;
}
var currChar = text.charCodeAt(pos);
// '`'
if (currChar === 96 /* backtick */) {
contents += text.substring(start, pos);
pos++;
resultingToken = startedWithBacktick ? 11 /* NoSubstitutionTemplateLiteral */ : 14 /* TemplateTail */;
break;
}
// '${'
if (currChar === 36 /* $ */ && pos + 1 < end && text.charCodeAt(pos + 1) === 123 /* openBrace */) {
contents += text.substring(start, pos);
pos += 2;
resultingToken = startedWithBacktick ? 12 /* TemplateHead */ : 13 /* TemplateMiddle */;
break;
}
// Escape character
if (currChar === 92 /* backslash */) {
contents += text.substring(start, pos);
contents += scanEscapeSequence();
start = pos;
continue;
}
// Speculated ECMAScript 6 Spec 11.8.6.1:
// <CR><LF> and <CR> LineTerminatorSequences are normalized to <LF> for Template Values
if (currChar === 13 /* carriageReturn */) {
contents += text.substring(start, pos);
pos++;
if (pos < end && text.charCodeAt(pos) === 10 /* lineFeed */) {
pos++;
}
contents += "\n";
start = pos;
continue;
}
pos++;
}
ts.Debug.assert(resultingToken !== undefined);
tokenValue = contents;
return resultingToken;
}
function scanEscapeSequence() {
pos++;
if (pos >= end) {
error(ts.Diagnostics.Unexpected_end_of_text);
return "";
}
var ch = text.charCodeAt(pos++);
switch (ch) {
case 48 /* _0 */:
return "\0";
case 98 /* b */:
return "\b";
case 116 /* t */:
return "\t";
case 110 /* n */:
return "\n";
case 118 /* v */:
return "\v";
case 102 /* f */:
return "\f";
case 114 /* r */:
return "\r";
case 39 /* singleQuote */:
return "\'";
case 34 /* doubleQuote */:
return "\"";
case 117 /* u */:
// '\u{DDDDDDDD}'
if (pos < end && text.charCodeAt(pos) === 123 /* openBrace */) {
hasExtendedUnicodeEscape = true;
pos++;
return scanExtendedUnicodeEscape();
}
// '\uDDDD'
return scanHexadecimalEscape(/*numDigits*/ 4);
case 120 /* x */:
// '\xDD'
return scanHexadecimalEscape(/*numDigits*/ 2);
// when encountering a LineContinuation (i.e. a backslash and a line terminator sequence),
// the line terminator is interpreted to be "the empty code unit sequence".
case 13 /* carriageReturn */:
if (pos < end && text.charCodeAt(pos) === 10 /* lineFeed */) {
pos++;
}
// fall through
case 10 /* lineFeed */:
case 8232 /* lineSeparator */:
case 8233 /* paragraphSeparator */:
return "";
default:
return String.fromCharCode(ch);
}
}
function scanHexadecimalEscape(numDigits) {
var escapedValue = scanExactNumberOfHexDigits(numDigits);
if (escapedValue >= 0) {
return String.fromCharCode(escapedValue);
}
else {
error(ts.Diagnostics.Hexadecimal_digit_expected);
return "";
}
}
function scanExtendedUnicodeEscape() {
var escapedValue = scanMinimumNumberOfHexDigits(1);
var isInvalidExtendedEscape = false;
// Validate the value of the digit
if (escapedValue < 0) {
error(ts.Diagnostics.Hexadecimal_digit_expected);
isInvalidExtendedEscape = true;
}
else if (escapedValue > 0x10FFFF) {
error(ts.Diagnostics.An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive);
isInvalidExtendedEscape = true;
}
if (pos >= end) {
error(ts.Diagnostics.Unexpected_end_of_text);
isInvalidExtendedEscape = true;
}
else if (text.charCodeAt(pos) === 125 /* closeBrace */) {
// Only swallow the following character up if it's a '}'.
pos++;
}
else {
error(ts.Diagnostics.Unterminated_Unicode_escape_sequence);
isInvalidExtendedEscape = true;
}
if (isInvalidExtendedEscape) {
return "";
}
return utf16EncodeAsString(escapedValue);
}
// Derived from the 10.1.1 UTF16Encoding of the ES6 Spec.
function utf16EncodeAsString(codePoint) {
ts.Debug.assert(0x0 <= codePoint && codePoint <= 0x10FFFF);
if (codePoint <= 65535) {
return String.fromCharCode(codePoint);
}
var codeUnit1 = Math.floor((codePoint - 65536) / 1024) + 0xD800;
var codeUnit2 = ((codePoint - 65536) % 1024) + 0xDC00;
return String.fromCharCode(codeUnit1, codeUnit2);
}
// Current character is known to be a backslash. Check for Unicode escape of the form '\uXXXX'
// and return code point value if valid Unicode escape is found. Otherwise return -1.
function peekUnicodeEscape() {
if (pos + 5 < end && text.charCodeAt(pos + 1) === 117 /* u */) {
var start_1 = pos;
pos += 2;
var value = scanExactNumberOfHexDigits(4);
pos = start_1;
return value;
}
return -1;
}
function scanIdentifierParts() {
var result = "";
var start = pos;
while (pos < end) {
var ch = text.charCodeAt(pos);
if (isIdentifierPart(ch)) {
pos++;
}
else if (ch === 92 /* backslash */) {
ch = peekUnicodeEscape();
if (!(ch >= 0 && isIdentifierPart(ch))) {
break;
}
result += text.substring(start, pos);
result += String.fromCharCode(ch);
// Valid Unicode escape is always six characters
pos += 6;
start = pos;
}
else {
break;
}
}
result += text.substring(start, pos);
return result;
}
function 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 = 67 /* Identifier */;
}
function scanBinaryOrOctalDigits(base) {
ts.Debug.assert(base !== 2 || base !== 8, "Expected either base 2 or base 8");
var value = 0;
// For counting number of digits; Valid binaryIntegerLiteral must have at least one binary digit following B or b.
// Similarly valid octalIntegerLiteral must have at least one octal digit following o or O.
var numberOfDigits = 0;
while (true) {
var ch = text.charCodeAt(pos);
var valueOfCh = ch - 48 /* _0 */;
if (!isDigit(ch) || valueOfCh >= base) {
break;
}
value = value * base + valueOfCh;
pos++;
numberOfDigits++;
}
// Invalid binaryIntegerLiteral or octalIntegerLiteral
if (numberOfDigits === 0) {
return -1;
}
return value;
}
function 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 && isWhiteSpace(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 = 33 /* ExclamationEqualsEqualsToken */;
}
return pos += 2, token = 31 /* ExclamationEqualsToken */;
}
return pos++, token = 48 /* 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 = 60 /* PercentEqualsToken */;
}
return pos++, token = 39 /* PercentToken */;
case 38 /* ampersand */:
if (text.charCodeAt(pos + 1) === 38 /* ampersand */) {
return pos += 2, token = 50 /* AmpersandAmpersandToken */;
}
if (text.charCodeAt(pos + 1) === 61 /* equals */) {
return pos += 2, token = 64 /* AmpersandEqualsToken */;
}
return pos++, token = 45 /* AmpersandToken */;
case 40 /* openParen */:
return pos++, token = 17 /* OpenParenToken */;
case 41 /* closeParen */:
return pos++, token = 18 /* CloseParenToken */;
case 42 /* asterisk */:
if (text.charCodeAt(pos + 1) === 61 /* equals */) {
return pos += 2, token = 58 /* AsteriskEqualsToken */;
}
return pos++, token = 37 /* AsteriskToken */;
case 43 /* plus */:
if (text.charCodeAt(pos + 1) === 43 /* plus */) {
return pos += 2, token = 40 /* PlusPlusToken */;
}
if (text.charCodeAt(pos + 1) === 61 /* equals */) {
return pos += 2, token = 56 /* PlusEqualsToken */;
}
return pos++, token = 35 /* PlusToken */;
case 44 /* comma */:
return pos++, token = 24 /* CommaToken */;
case 45 /* minus */:
if (text.charCodeAt(pos + 1) === 45 /* minus */) {
return pos += 2, token = 41 /* MinusMinusToken */;
}
if (text.charCodeAt(pos + 1) === 61 /* equals */) {
return pos += 2, token = 57 /* MinusEqualsToken */;
}
return pos++, token = 36 /* 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 = 22 /* DotDotDotToken */;
}
return pos++, token = 21 /* 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 = 59 /* SlashEqualsToken */;
}
return pos++, token = 38 /* 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 */:
return pos++, token = 53 /* ColonToken */;
case 59 /* semicolon */:
return pos++, token = 23 /* 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 = 61 /* LessThanLessThanEqualsToken */;
}
return pos += 2, token = 42 /* LessThanLessThanToken */;
}
if (text.charCodeAt(pos + 1) === 61 /* equals */) {
return pos += 2, token = 28 /* LessThanEqualsToken */;
}
if (text.charCodeAt(pos + 1) === 47 /* slash */ && languageVariant === 1 /* JSX */) {
return pos += 2, token = 26 /* LessThanSlashToken */;
}
return pos++, token = 25 /* 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 = 32 /* EqualsEqualsEqualsToken */;
}
return pos += 2, token = 30 /* EqualsEqualsToken */;
}
if (text.charCodeAt(pos + 1) === 62 /* greaterThan */) {
return pos += 2, token = 34 /* EqualsGreaterThanToken */;
}
return pos++, token = 55 /* EqualsToken */;
case 62 /* greaterThan */:
if (isConflictMarkerTrivia(text, pos)) {
pos = scanConflictMarkerTrivia(text, pos, error);
if (skipTrivia) {
continue;
}
else {
return token = 7 /* ConflictMarkerTrivia */;
}
}
return pos++, token = 27 /* GreaterThanToken */;
case 63 /* question */:
return pos++, token = 52 /* QuestionToken */;
case 91 /* openBracket */:
return pos++, token = 19 /* OpenBracketToken */;
case 93 /* closeBracket */:
return pos++, token = 20 /* CloseBracketToken */;
case 94 /* caret */:
if (text.charCodeAt(pos + 1) === 61 /* equals */) {
return pos += 2, token = 66 /* CaretEqualsToken */;
}
return pos++, token = 47 /* CaretToken */;
case 123 /* openBrace */:
return pos++, token = 15 /* OpenBraceToken */;
case 124 /* bar */:
if (text.charCodeAt(pos + 1) === 124 /* bar */) {
return pos += 2, token = 51 /* BarBarToken */;
}
if (text.charCodeAt(pos + 1) === 61 /* equals */) {
return pos += 2, token = 65 /* BarEqualsToken */;
}
return pos++, token = 46 /* BarToken */;
case 125 /* closeBrace */:
return pos++, token = 16 /* CloseBraceToken */;
case 126 /* tilde */:
return pos++, token = 49 /* TildeToken */;
case 64 /* at */:
return pos++, token = 54 /* AtToken */;
case 92 /* backslash */:
var cookedChar = peekUnicodeEscape();
if (cookedChar >= 0 && isIdentifierStart(cookedChar)) {
pos += 6;
tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts();
return token = getIdentifierToken();
}
error(ts.Diagnostics.Invalid_character);
return pos++, token = 0 /* Unknown */;
default:
if (isIdentifierStart(ch)) {
pos++;
while (pos < end && isIdentifierPart(ch = text.charCodeAt(pos)))
pos++;
tokenValue = text.substring(tokenPos, pos);
if (ch === 92 /* backslash */) {
tokenValue += scanIdentifierParts();
}
return token = getIdentifierToken();
}
else if (isWhiteSpace(ch)) {
pos++;
continue;
}
else if (isLineBreak(ch)) {
precedingLineBreak = true;
pos++;
continue;
}
error(ts.Diagnostics.Invalid_character);
return pos++, token = 0 /* Unknown */;
}
}
}
function reScanGreaterToken() {
if (token === 27 /* GreaterThanToken */) {
if (text.charCodeAt(pos) === 62 /* greaterThan */) {
if (text.charCodeAt(pos + 1) === 62 /* greaterThan */) {
if (text.charCodeAt(pos + 2) === 61 /* equals */) {
return pos += 3, token = 63 /* GreaterThanGreaterThanGreaterThanEqualsToken */;
}
return pos += 2, token = 44 /* GreaterThanGreaterThanGreaterThanToken */;
}
if (text.charCodeAt(pos + 1) === 61 /* equals */) {
return pos += 2, token = 62 /* GreaterThanGreaterThanEqualsToken */;
}
return pos++, token = 43 /* GreaterThanGreaterThanToken */;
}
if (text.charCodeAt(pos) === 61 /* equals */) {
return pos++, token = 29 /* GreaterThanEqualsToken */;
}
}
return token;
}
function reScanSlashToken() {
if (token === 38 /* SlashToken */ || token === 59 /* SlashEqualsToken */) {
var p = tokenPos + 1;
var inEscape = false;
var inCharacterClass = false;
while (true) {
// If we reach the end of a file, or hit a newline, then this is an unterminated
// regex. Report error and return what we have so far.
if (p >= end) {
tokenIsUnterminated = true;
error(ts.Diagnostics.Unterminated_regular_expression_literal);
break;
}
var ch = text.charCodeAt(p);
if (isLineBreak(ch)) {
tokenIsUnterminated = true;
error(ts.Diagnostics.Unterminated_regular_expression_literal);
break;
}
if (inEscape) {
// Parsing an escape character;
// reset the flag and just advance to the next char.
inEscape = false;
}
else if (ch === 47 /* slash */ && !inCharacterClass) {
// A slash within a character class is permissible,
// but in general it signals the end of the regexp literal.
p++;
break;
}
else if (ch === 91 /* openBracket */) {
inCharacterClass = true;
}
else if (ch === 92 /* backslash */) {
inEscape = true;
}
else if (ch === 93 /* closeBracket */) {
inCharacterClass = false;
}
p++;
}
while (p < end && isIdentifierPart(text.charCodeAt(p))) {
p++;
}
pos = p;
tokenValue = text.substring(tokenPos, pos);
token = 10 /* RegularExpressionLiteral */;
}
return token;
}
/**
* Unconditionally back up and scan a template expression portion.
*/
function reScanTemplateToken() {
ts.Debug.assert(token === 16 /* CloseBraceToken */, "'reScanTemplateToken' should only be called on a '}'");
pos = tokenPos;
return token = scanTemplateAndSetTokenValue();
}
function reScanJsxToken() {
pos = tokenPos = startPos;
return token = scanJsxToken();
}
function scanJsxToken() {
startPos = tokenPos = pos;
if (pos >= end) {
return token = 1 /* EndOfFileToken */;
}
var char = text.charCodeAt(pos);
if (char === 60 /* lessThan */) {
if (text.charCodeAt(pos + 1) === 47 /* slash */) {
pos += 2;
return token = 26 /* LessThanSlashToken */;
}
pos++;
return token = 25 /* LessThanToken */;
}
if (char === 123 /* openBrace */) {
pos++;
return token = 15 /* OpenBraceToken */;
}
while (pos < end) {
pos++;
char = text.charCodeAt(pos);
if ((char === 123 /* openBrace */) || (char === 60 /* lessThan */)) {
break;
}
}
return token = 234 /* JsxText */;
}
// Scans a JSX identifier; these differ from normal identifiers in that
// they allow dashes
function scanJsxIdentifier() {
if (token === 67 /* Identifier */) {
var firstCharPosition = pos;
while (pos < end) {
var ch = text.charCodeAt(pos);
if (ch === 45 /* minus */ || ((firstCharPosition === pos) ? isIdentifierStart(ch) : isIdentifierPart(ch))) {
pos++;
}
else {
break;
}
}
tokenValue += text.substr(firstCharPosition, pos - firstCharPosition);
}
return token;
}
function speculationHelper(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;
}
function lookAhead(callback) {
return speculationHelper(callback, /*isLookahead:*/ true);
}
function tryScan(callback) {
return speculationHelper(callback, /*isLookahead:*/ false);
}
function setText(newText, start, length) {
text = newText || "";
end = length === undefined ? text.length : start + length;
setTextPos(start || 0);
}
function setOnError(errorCallback) {
onError = errorCallback;
}
function setScriptTarget(scriptTarget) {
languageVersion = scriptTarget;
}
function setLanguageVariant(variant) {
languageVariant = variant;
}
function setTextPos(textPos) {
ts.Debug.assert(textPos >= 0);
pos = textPos;
startPos = textPos;
tokenPos = textPos;
token = 0 /* Unknown */;
precedingLineBreak = false;
tokenValue = undefined;
hasExtendedUnicodeEscape = false;
tokenIsUnterminated = false;
}
}
ts.createScanner = createScanner;
})(ts || (ts = {}));
/// <reference path="parser.ts"/>
/* @internal */
var ts;
(function (ts) {
ts.bindTime = 0;
(function (ModuleInstanceState) {
ModuleInstanceState[ModuleInstanceState["NonInstantiated"] = 0] = "NonInstantiated";
ModuleInstanceState[ModuleInstanceState["Instantiated"] = 1] = "Instantiated";
ModuleInstanceState[ModuleInstanceState["ConstEnumOnly"] = 2] = "ConstEnumOnly";
})(ts.ModuleInstanceState || (ts.ModuleInstanceState = {}));
var ModuleInstanceState = ts.ModuleInstanceState;
function getModuleInstanceState(node) {
// A module is uninstantiated if it contains only
// 1. interface declarations, type alias declarations
if (node.kind === 213 /* InterfaceDeclaration */ || node.kind === 214 /* TypeAliasDeclaration */) {
return 0 /* NonInstantiated */;
}
else if (ts.isConstEnumDeclaration(node)) {
return 2 /* ConstEnumOnly */;
}
else if ((node.kind === 220 /* ImportDeclaration */ || node.kind === 219 /* ImportEqualsDeclaration */) && !(node.flags & 1 /* Export */)) {
return 0 /* NonInstantiated */;
}
else if (node.kind === 217 /* ModuleBlock */) {
var state = 0 /* NonInstantiated */;
ts.forEachChild(node, function (n) {
switch (getModuleInstanceState(n)) {
case 0 /* NonInstantiated */:
// child is non-instantiated - continue searching
return false;
case 2 /* ConstEnumOnly */:
// child is const enum only - record state and continue searching
state = 2 /* ConstEnumOnly */;
return false;
case 1 /* Instantiated */:
// child is instantiated - record state and stop
state = 1 /* Instantiated */;
return true;
}
});
return state;
}
else if (node.kind === 216 /* ModuleDeclaration */) {
return getModuleInstanceState(node.body);
}
else {
return 1 /* Instantiated */;
}
}
ts.getModuleInstanceState = getModuleInstanceState;
var ContainerFlags;
(function (ContainerFlags) {
// The current node is not a container, and no container manipulation should happen before
// recursing into it.
ContainerFlags[ContainerFlags["None"] = 0] = "None";
// The current node is a container. It should be set as the current container (and block-
// container) before recursing into it. The current node does not have locals. Examples:
//
// Classes, ObjectLiterals, TypeLiterals, Interfaces...
ContainerFlags[ContainerFlags["IsContainer"] = 1] = "IsContainer";
// The current node is a block-scoped-container. It should be set as the current block-
// container before recursing into it. Examples:
//
// Blocks (when not parented by functions), Catch clauses, For/For-in/For-of statements...
ContainerFlags[ContainerFlags["IsBlockScopedContainer"] = 2] = "IsBlockScopedContainer";
ContainerFlags[ContainerFlags["HasLocals"] = 4] = "HasLocals";
// If the current node is a container that also container that also contains locals. Examples:
//
// Functions, Methods, Modules, Source-files.
ContainerFlags[ContainerFlags["IsContainerWithLocals"] = 5] = "IsContainerWithLocals";
})(ContainerFlags || (ContainerFlags = {}));
function bindSourceFile(file) {
var start = new Date().getTime();
bindSourceFileWorker(file);
ts.bindTime += new Date().getTime() - start;
}
ts.bindSourceFile = bindSourceFile;
function bindSourceFileWorker(file) {
var parent;
var container;
var blockScopeContainer;
var lastContainer;
// If this file is an external module, then it is automatically in strict-mode according to
// ES6. If it is not an external module, then we'll determine if it is in strict mode or
// not depending on if we see "use strict" in certain places (or if we hit a class/namespace).
var inStrictMode = !!file.externalModuleIndicator;
var symbolCount = 0;
var Symbol = ts.objectAllocator.getSymbolConstructor();
var classifiableNames = {};
if (!file.locals) {
bind(file);
file.symbolCount = symbolCount;
file.classifiableNames = classifiableNames;
}
return;
function createSymbol(flags, name) {
symbolCount++;
return new Symbol(flags, name);
}
function 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 = {};
}
if (symbolFlags & 6240 /* HasMembers */ && !symbol.members) {
symbol.members = {};
}
if (symbolFlags & 107455 /* Value */ && !symbol.valueDeclaration) {
symbol.valueDeclaration = node;
}
}
// Should not be called on a declaration with a computed property name,
// unless it is a well known Symbol.
function getDeclarationName(node) {
if (node.name) {
if (node.kind === 216 /* ModuleDeclaration */ && node.name.kind === 9 /* StringLiteral */) {
return "\"" + node.name.text + "\"";
}
if (node.name.kind === 134 /* ComputedPropertyName */) {
var nameExpression = node.name.expression;
ts.Debug.assert(ts.isWellKnownSymbolSyntactically(nameExpression));
return ts.getPropertyNameForKnownSymbolName(nameExpression.name.text);
}
return node.name.text;
}
switch (node.kind) {
case 142 /* Constructor */:
return "__constructor";
case 150 /* FunctionType */:
case 145 /* CallSignature */:
return "__call";
case 151 /* ConstructorType */:
case 146 /* ConstructSignature */:
return "__new";
case 147 /* IndexSignature */:
return "__index";
case 226 /* ExportDeclaration */:
return "__export";
case 225 /* ExportAssignment */:
return node.isExportEquals ? "export=" : "default";
case 211 /* FunctionDeclaration */:
case 212 /* ClassDeclaration */:
return node.flags & 1024 /* Default */ ? "default" : undefined;
}
}
function getDisplayName(node) {
return node.name ? ts.declarationNameToString(node.name) : getDeclarationName(node);
}
/**
* Declares a Symbol for the node and adds it to symbols. Reports errors for conflicting identifier names.
* @param symbolTable - The symbol table which node will be added to.
* @param parent - node's parent declaration.
* @param node - The declaration to be added to the symbol table
* @param includes - The SymbolFlags that node has in addition to its declaration type (eg: export, ambient, etc.)
* @param excludes - The flags which node cannot be declared alongside in a symbol table. Used to report forbidden declarations.
*/
function declareSymbol(symbolTable, parent, node, includes, excludes) {
ts.Debug.assert(!ts.hasDynamicName(node));
// The exported symbol for an export default function/class node is always named "default"
var name = node.flags & 1024 /* Default */ && parent ? "default" : getDeclarationName(node);
var symbol;
if (name !== undefined) {
// 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.
//
// 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 = ts.hasProperty(symbolTable, name)
? symbolTable[name]
: (symbolTable[name] = createSymbol(0 /* None */, name));
if (name && (includes & 788448 /* Classifiable */)) {
classifiableNames[name] = name;
}
if (symbol.flags & excludes) {
if (node.name) {
node.name.parent = node;
}
// Report errors every position with duplicate declaration
// Report errors on previous encountered declarations
var message = symbol.flags & 2 /* BlockScopedVariable */
? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0
: ts.Diagnostics.Duplicate_identifier_0;
ts.forEach(symbol.declarations, function (declaration) {
file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration)));
});
file.bindDiagnostics.push(ts.createDiagnosticForNode(node.name || node, message, getDisplayName(node)));
symbol = createSymbol(0 /* None */, name);
}
}
else {
symbol = createSymbol(0 /* None */, "__missing");
}
addDeclarationToSymbol(symbol, node, includes);
symbol.parent = parent;
return symbol;
}
function declareModuleMember(node, symbolFlags, symbolExcludes) {
var hasExportModifier = ts.getCombinedNodeFlags(node) & 1 /* Export */;
if (symbolFlags & 8388608 /* Alias */) {
if (node.kind === 228 /* ExportSpecifier */ || (node.kind === 219 /* 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.
if (hasExportModifier || container.flags & 262144 /* ExportContext */) {
var exportKind = (symbolFlags & 107455 /* Value */ ? 1048576 /* ExportValue */ : 0) |
(symbolFlags & 793056 /* Type */ ? 2097152 /* ExportType */ : 0) |
(symbolFlags & 1536 /* 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);
}
}
}
// All container nodes are kept on a linked list in declaration order. This list is used by
// the getLocalNameOfContainer function in the type checker to validate that the local name
// used for a container is unique.
function bindChildren(node) {
// Before we recurse into a node's chilren, we first save the existing parent, container
// and block-container. Then after we pop out of processing the children, we restore
// these saved values.
var saveParent = parent;
var saveContainer = container;
var savedBlockScopeContainer = blockScopeContainer;
// This node will now be set as the parent of all of its children as we recurse into them.
parent = node;
// Depending on what kind of node this is, we may have to adjust the current container
// and block-container. If the current node is a container, then it is automatically
// considered the current block-container as well. Also, for containers that we know
// may contain locals, we proactively initialize the .locals field. We do this because
// it's highly likely that the .locals will be needed to place some child in (for example,
// a parameter, or variable declaration).
//
// However, we do not proactively create the .locals for block-containers because it's
// totally normal and common for block-containers to never actually have a block-scoped
// variable in them. We don't want to end up allocating an object for every 'block' we
// run into when most of them won't be necessary.
//
// Finally, if this is a block-container, then we clear out any existing .locals object
// it may contain within it. This happens in incremental scenarios. Because we can be
// reusing a node from a previous compilation, that node may have had 'locals' created
// for it. We must clear this so we don't accidently move any stale data forward from
// a previous compilation.
var containerFlags = getContainerFlags(node);
if (containerFlags & 1 /* IsContainer */) {
container = blockScopeContainer = node;
if (containerFlags & 4 /* HasLocals */) {
container.locals = {};
}
addToContainerChain(container);
}
else if (containerFlags & 2 /* IsBlockScopedContainer */) {
blockScopeContainer = node;
blockScopeContainer.locals = undefined;
}
ts.forEachChild(node, bind);
container = saveContainer;
parent = saveParent;
blockScopeContainer = savedBlockScopeContainer;
}
function getContainerFlags(node) {
switch (node.kind) {
case 184 /* ClassExpression */:
case 212 /* ClassDeclaration */:
case 213 /* InterfaceDeclaration */:
case 215 /* EnumDeclaration */:
case 153 /* TypeLiteral */:
case 163 /* ObjectLiteralExpression */:
return 1 /* IsContainer */;
case 145 /* CallSignature */:
case 146 /* ConstructSignature */:
case 147 /* IndexSignature */:
case 141 /* MethodDeclaration */:
case 140 /* MethodSignature */:
case 211 /* FunctionDeclaration */:
case 142 /* Constructor */:
case 143 /* GetAccessor */:
case 144 /* SetAccessor */:
case 150 /* FunctionType */:
case 151 /* ConstructorType */:
case 171 /* FunctionExpression */:
case 172 /* ArrowFunction */:
case 216 /* ModuleDeclaration */:
case 246 /* SourceFile */:
case 214 /* TypeAliasDeclaration */:
return 5 /* IsContainerWithLocals */;
case 242 /* CatchClause */:
case 197 /* ForStatement */:
case 198 /* ForInStatement */:
case 199 /* ForOfStatement */:
case 218 /* CaseBlock */:
return 2 /* IsBlockScopedContainer */;
case 190 /* 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. Othewise '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 */;
}
function addToContainerChain(next) {
if (lastContainer) {
lastContainer.nextContainer = next;
}
lastContainer = next;
}
function declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes) {
// Just call this directly so that the return type of this function stays "void".
declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes);
}
function 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 216 /* ModuleDeclaration */:
return declareModuleMember(node, symbolFlags, symbolExcludes);
case 246 /* SourceFile */:
return declareSourceFileMember(node, symbolFlags, symbolExcludes);
case 184 /* ClassExpression */:
case 212 /* ClassDeclaration */:
return declareClassMember(node, symbolFlags, symbolExcludes);
case 215 /* EnumDeclaration */:
return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
case 153 /* TypeLiteral */:
case 163 /* ObjectLiteralExpression */:
case 213 /* InterfaceDeclaration */:
// 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 150 /* FunctionType */:
case 151 /* ConstructorType */:
case 145 /* CallSignature */:
case 146 /* ConstructSignature */:
case 147 /* IndexSignature */:
case 141 /* MethodDeclaration */:
case 140 /* MethodSignature */:
case 142 /* Constructor */:
case 143 /* GetAccessor */:
case 144 /* SetAccessor */:
case 211 /* FunctionDeclaration */:
case 171 /* FunctionExpression */:
case 172 /* ArrowFunction */:
case 214 /* TypeAliasDeclaration */:
// 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, undefined, node, symbolFlags, symbolExcludes);
}
}
function declareClassMember(node, symbolFlags, symbolExcludes) {
return node.flags & 128 /* Static */
? declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes)
: declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes);
}
function declareSourceFileMember(node, symbolFlags, symbolExcludes) {
return ts.isExternalModule(file)
? declareModuleMember(node, symbolFlags, symbolExcludes)
: declareSymbol(file.locals, undefined, node, symbolFlags, symbolExcludes);
}
function isAmbientContext(node) {
while (node) {
if (node.flags & 2 /* Ambient */) {
return true;
}
node = node.parent;
}
return false;
}
function hasExportDeclarations(node) {
var body = node.kind === 246 /* SourceFile */ ? node : node.body;
if (body.kind === 246 /* SourceFile */ || body.kind === 217 /* ModuleBlock */) {
for (var _i = 0, _a = body.statements; _i < _a.length; _i++) {
var stat = _a[_i];
if (stat.kind === 226 /* ExportDeclaration */ || stat.kind === 225 /* ExportAssignment */) {
return true;
}
}
}
return false;
}
function setExportContextFlag(node) {
// A declaration source file or ambient module declaration that contains no export declarations (but possibly regular
// declarations with export modifiers) is an export context in which declarations are implicitly exported.
if (isAmbientContext(node) && !hasExportDeclarations(node)) {
node.flags |= 262144 /* ExportContext */;
}
else {
node.flags &= ~262144 /* ExportContext */;
}
}
function bindModuleDeclaration(node) {
setExportContextFlag(node);
if (node.name.kind === 9 /* StringLiteral */) {
declareSymbolAndAddToSymbolTable(node, 512 /* ValueModule */, 106639 /* ValueModuleExcludes */);
}
else {
var state = getModuleInstanceState(node);
if (state === 0 /* NonInstantiated */) {
declareSymbolAndAddToSymbolTable(node, 1024 /* NamespaceModule */, 0 /* NamespaceModuleExcludes */);
}
else {
declareSymbolAndAddToSymbolTable(node, 512 /* ValueModule */, 106639 /* ValueModuleExcludes */);
if (node.symbol.flags & (16 /* Function */ | 32 /* Class */ | 256 /* RegularEnum */)) {
// if module was already merged with some function, class or non-const enum
// treat is a non-const-enum-only
node.symbol.constEnumOnlyModule = false;
}
else {
var currentModuleIsConstEnumOnly = state === 2 /* ConstEnumOnly */;
if (node.symbol.constEnumOnlyModule === undefined) {
// non-merged case - use the current state
node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly;
}
else {
// merged case: module is const enum only if all its pieces are non-instantiated or const enum
node.symbol.constEnumOnlyModule = node.symbol.constEnumOnlyModule && currentModuleIsConstEnumOnly;
}
}
}
}
}
function 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 = (_a = {}, _a[symbol.name] = symbol, _a);
var _a;
}
function bindObjectLiteralExpression(node) {
var ElementKind;
(function (ElementKind) {
ElementKind[ElementKind["Property"] = 1] = "Property";
ElementKind[ElementKind["Accessor"] = 2] = "Accessor";
})(ElementKind || (ElementKind = {}));
if (inStrictMode) {
var seen = {};
for (var _i = 0, _a = node.properties; _i < _a.length; _i++) {
var prop = _a[_i];
if (prop.name.kind !== 67 /* Identifier */) {
continue;
}
var identifier = prop.name;
// ECMA-262 11.1.5 Object Initialiser
// If previous is not undefined then throw a SyntaxError exception if any of the following conditions are true
// a.This production is contained in strict code and IsDataDescriptor(previous) is true and
// IsDataDescriptor(propId.descriptor) is true.
// b.IsDataDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true.
// c.IsAccessorDescriptor(previous) is true and IsDataDescriptor(propId.descriptor) is true.
// d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true
// and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields
var currentKind = prop.kind === 243 /* PropertyAssignment */ || prop.kind === 244 /* ShorthandPropertyAssignment */ || prop.kind === 141 /* MethodDeclaration */
? 1 /* Property */
: 2 /* Accessor */;
var existingKind = seen[identifier.text];
if (!existingKind) {
seen[identifier.text] = currentKind;
continue;
}
if (currentKind === 1 /* Property */ && existingKind === 1 /* Property */) {
var span = ts.getErrorSpanForNode(file, identifier);
file.bindDiagnostics.push(ts.createFileDiagnostic(file, span.start, span.length, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode));
}
}
}
return bindAnonymousDeclaration(node, 4096 /* ObjectLiteral */, "__object");
}
function bindAnonymousDeclaration(node, symbolFlags, name) {
var symbol = createSymbol(symbolFlags, name);
addDeclarationToSymbol(symbol, node, symbolFlags);
}
function bindBlockScopedDeclaration(node, symbolFlags, symbolExcludes) {
switch (blockScopeContainer.kind) {
case 216 /* ModuleDeclaration */:
declareModuleMember(node, symbolFlags, symbolExcludes);
break;
case 246 /* SourceFile */:
if (ts.isExternalModule(container)) {
declareModuleMember(node, symbolFlags, symbolExcludes);
break;
}
// fall through.
default:
if (!blockScopeContainer.locals) {
blockScopeContainer.locals = {};
addToContainerChain(blockScopeContainer);
}
declareSymbol(blockScopeContainer.locals, undefined, node, symbolFlags, symbolExcludes);
}
}
function bindBlockScopedVariableDeclaration(node) {
bindBlockScopedDeclaration(node, 2 /* BlockScopedVariable */, 107455 /* BlockScopedVariableExcludes */);
}
// The binder visits every node in the syntax tree so it is a convenient place to perform a single localized
// check for reserved words used as identifiers in strict mode code.
function checkStrictModeIdentifier(node) {
if (inStrictMode &&
node.originalKeywordKind >= 104 /* FirstFutureReservedWord */ &&
node.originalKeywordKind <= 112 /* LastFutureReservedWord */ &&
!ts.isIdentifierName(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)));
}
}
}
function getStrictModeIdentifierMessage(node) {
// Provide specialized messages to help the user understand why we think they're in
// strict mode.
if (ts.getContainingClass(node)) {
return ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode;
}
if (file.externalModuleIndicator) {
return ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Modules_are_automatically_in_strict_mode;
}
return ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode;
}
function checkStrictModeBinaryExpression(node) {
if (inStrictMode && ts.isLeftHandSideExpression(node.left) && ts.isAssignmentOperator(node.operatorToken.kind)) {
// ECMA 262 (Annex C) The identifier eval or arguments may not appear as the LeftHandSideExpression of an
// Assignment operator(11.13) or of a PostfixExpression(11.3)
checkStrictModeEvalOrArguments(node, node.left);
}
}
function checkStrictModeCatchClause(node) {
// It is a SyntaxError if a TryStatement with a Catch occurs within strict code and the Identifier of the
// Catch production is eval or arguments
if (inStrictMode && node.variableDeclaration) {
checkStrictModeEvalOrArguments(node, node.variableDeclaration.name);
}
}
function checkStrictModeDeleteExpression(node) {
// Grammar checking
if (inStrictMode && node.expression.kind === 67 /* Identifier */) {
// When a delete operator occurs within strict mode code, a SyntaxError is thrown if its
// UnaryExpression is a direct reference to a variable, function argument, or function name
var span = ts.getErrorSpanForNode(file, node.expression);
file.bindDiagnostics.push(ts.createFileDiagnostic(file, span.start, span.length, ts.Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode));
}
}
function isEvalOrArgumentsIdentifier(node) {
return node.kind === 67 /* Identifier */ &&
(node.text === "eval" || node.text === "arguments");
}
function checkStrictModeEvalOrArguments(contextNode, name) {
if (name && name.kind === 67 /* 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 = ts.getErrorSpanForNode(file, name);
file.bindDiagnostics.push(ts.createFileDiagnostic(file, span.start, span.length, getStrictModeEvalOrArgumentsMessage(contextNode), identifier.text));
}
}
}
function getStrictModeEvalOrArgumentsMessage(node) {
// Provide specialized messages to help the user understand why we think they're in
// strict mode.
if (ts.getContainingClass(node)) {
return ts.Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode;
}
if (file.externalModuleIndicator) {
return ts.Diagnostics.Invalid_use_of_0_Modules_are_automatically_in_strict_mode;
}
return ts.Diagnostics.Invalid_use_of_0_in_strict_mode;
}
function checkStrictModeFunctionName(node) {
if (inStrictMode) {
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a strict mode FunctionDeclaration or FunctionExpression (13.1))
checkStrictModeEvalOrArguments(node, node.name);
}
}
function checkStrictModeNumericLiteral(node) {
if (inStrictMode && node.flags & 65536 /* OctalLiteral */) {
file.bindDiagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.Octal_literals_are_not_allowed_in_strict_mode));
}
}
function checkStrictModePostfixUnaryExpression(node) {
// Grammar checking
// The identifier eval or arguments may not appear as the LeftHandSideExpression of an
// Assignment operator(11.13) or of a PostfixExpression(11.3) or as the UnaryExpression
// operated upon by a Prefix Increment(11.4.4) or a Prefix Decrement(11.4.5) operator.
if (inStrictMode) {
checkStrictModeEvalOrArguments(node, node.operand);
}
}
function checkStrictModePrefixUnaryExpression(node) {
// Grammar checking
if (inStrictMode) {
if (node.operator === 40 /* PlusPlusToken */ || node.operator === 41 /* MinusMinusToken */) {
checkStrictModeEvalOrArguments(node, node.operand);
}
}
}
function checkStrictModeWithStatement(node) {
// Grammar checking for withStatement
if (inStrictMode) {
grammarErrorOnFirstToken(node, ts.Diagnostics.with_statements_are_not_allowed_in_strict_mode);
}
}
function grammarErrorOnFirstToken(node, message, arg0, arg1, arg2) {
var span = ts.getSpanOfTokenAtPosition(file, node.pos);
file.bindDiagnostics.push(ts.createFileDiagnostic(file, span.start, span.length, message, arg0, arg1, arg2));
}
function getDestructuringParameterName(node) {
return "__" + ts.indexOf(node.parent.parameters, node);
}
function bind(node) {
node.parent = parent;
var savedInStrictMode = inStrictMode;
if (!savedInStrictMode) {
updateStrictMode(node);
}
// 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.
bindChildren(node);
inStrictMode = savedInStrictMode;
}
function updateStrictMode(node) {
switch (node.kind) {
case 246 /* SourceFile */:
case 217 /* ModuleBlock */:
updateStrictModeStatementList(node.statements);
return;
case 190 /* Block */:
if (ts.isFunctionLike(node.parent)) {
updateStrictModeStatementList(node.statements);
}
return;
case 212 /* ClassDeclaration */:
case 184 /* ClassExpression */:
// All classes are automatically in strict mode in ES6.
inStrictMode = true;
return;
}
}
function updateStrictModeStatementList(statements) {
for (var _i = 0; _i < statements.length; _i++) {
var statement = statements[_i];
if (!ts.isPrologueDirective(statement)) {
return;
}
if (isUseStrictPrologueDirective(statement)) {
inStrictMode = true;
return;
}
}
}
/// Should be called only on prologue directives (isPrologueDirective(node) should be true)
function isUseStrictPrologueDirective(node) {
var nodeText = ts.getTextOfNodeFromSourceText(file.text, node.expression);
// Note: the node text must be exactly "use strict" or 'use strict'. It is not ok for the
// string to contain unicode escapes (as per ES5).
return nodeText === "\"use strict\"" || nodeText === "'use strict'";
}
function bindWorker(node) {
switch (node.kind) {
case 67 /* Identifier */:
return checkStrictModeIdentifier(node);
case 179 /* BinaryExpression */:
return checkStrictModeBinaryExpression(node);
case 242 /* CatchClause */:
return checkStrictModeCatchClause(node);
case 173 /* DeleteExpression */:
return checkStrictModeDeleteExpression(node);
case 8 /* NumericLiteral */:
return checkStrictModeNumericLiteral(node);
case 178 /* PostfixUnaryExpression */:
return checkStrictModePostfixUnaryExpression(node);
case 177 /* PrefixUnaryExpression */:
return checkStrictModePrefixUnaryExpression(node);
case 203 /* WithStatement */:
return checkStrictModeWithStatement(node);
case 135 /* TypeParameter */:
return declareSymbolAndAddToSymbolTable(node, 262144 /* TypeParameter */, 530912 /* TypeParameterExcludes */);
case 136 /* Parameter */:
return bindParameter(node);
case 209 /* VariableDeclaration */:
case 161 /* BindingElement */:
return bindVariableDeclarationOrBindingElement(node);
case 139 /* PropertyDeclaration */:
case 138 /* PropertySignature */:
return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 107455 /* PropertyExcludes */);
case 243 /* PropertyAssignment */:
case 244 /* ShorthandPropertyAssignment */:
return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 107455 /* PropertyExcludes */);
case 245 /* EnumMember */:
return bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 107455 /* EnumMemberExcludes */);
case 145 /* CallSignature */:
case 146 /* ConstructSignature */:
case 147 /* IndexSignature */:
return declareSymbolAndAddToSymbolTable(node, 131072 /* Signature */, 0 /* None */);
case 141 /* MethodDeclaration */:
case 140 /* 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) ? 107455 /* PropertyExcludes */ : 99263 /* MethodExcludes */);
case 211 /* FunctionDeclaration */:
checkStrictModeFunctionName(node);
return declareSymbolAndAddToSymbolTable(node, 16 /* Function */, 106927 /* FunctionExcludes */);
case 142 /* Constructor */:
return declareSymbolAndAddToSymbolTable(node, 16384 /* Constructor */, /*symbolExcludes:*/ 0 /* None */);
case 143 /* GetAccessor */:
return bindPropertyOrMethodOrAccessor(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */);
case 144 /* SetAccessor */:
return bindPropertyOrMethodOrAccessor(node, 65536 /* SetAccessor */, 74687 /* SetAccessorExcludes */);
case 150 /* FunctionType */:
case 151 /* ConstructorType */:
return bindFunctionOrConstructorType(node);
case 153 /* TypeLiteral */:
return bindAnonymousDeclaration(node, 2048 /* TypeLiteral */, "__type");
case 163 /* ObjectLiteralExpression */:
return bindObjectLiteralExpression(node);
case 171 /* FunctionExpression */:
case 172 /* ArrowFunction */:
checkStrictModeFunctionName(node);
var bindingName = node.name ? node.name.text : "__function";
return bindAnonymousDeclaration(node, 16 /* Function */, bindingName);
case 184 /* ClassExpression */:
case 212 /* ClassDeclaration */:
return bindClassLikeDeclaration(node);
case 213 /* InterfaceDeclaration */:
return bindBlockScopedDeclaration(node, 64 /* Interface */, 792960 /* InterfaceExcludes */);
case 214 /* TypeAliasDeclaration */:
return bindBlockScopedDeclaration(node, 524288 /* TypeAlias */, 793056 /* TypeAliasExcludes */);
case 215 /* EnumDeclaration */:
return bindEnumDeclaration(node);
case 216 /* ModuleDeclaration */:
return bindModuleDeclaration(node);
case 219 /* ImportEqualsDeclaration */:
case 222 /* NamespaceImport */:
case 224 /* ImportSpecifier */:
case 228 /* ExportSpecifier */:
return declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */);
case 221 /* ImportClause */:
return bindImportClause(node);
case 226 /* ExportDeclaration */:
return bindExportDeclaration(node);
case 225 /* ExportAssignment */:
return bindExportAssignment(node);
case 246 /* SourceFile */:
return bindSourceFileIfExternalModule();
}
}
function bindSourceFileIfExternalModule() {
setExportContextFlag(file);
if (ts.isExternalModule(file)) {
bindAnonymousDeclaration(file, 512 /* ValueModule */, "\"" + ts.removeFileExtension(file.fileName) + "\"");
}
}
function bindExportAssignment(node) {
if (!container.symbol || !container.symbol.exports) {
// Export assignment in some sort of block construct
bindAnonymousDeclaration(node, 8388608 /* Alias */, getDeclarationName(node));
}
else if (node.expression.kind === 67 /* Identifier */) {
// An export default clause with an identifier exports all meanings of that identifier
declareSymbol(container.symbol.exports, container.symbol, node, 8388608 /* Alias */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */);
}
else {
// An export default clause with an expression exports a value
declareSymbol(container.symbol.exports, container.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */);
}
}
function bindExportDeclaration(node) {
if (!container.symbol || !container.symbol.exports) {
// Export * in some sort of block construct
bindAnonymousDeclaration(node, 1073741824 /* ExportStar */, getDeclarationName(node));
}
else if (!node.exportClause) {
// All export * declarations are collected in an __export symbol
declareSymbol(container.symbol.exports, container.symbol, node, 1073741824 /* ExportStar */, 0 /* None */);
}
}
function bindImportClause(node) {
if (node.name) {
declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */);
}
}
function bindClassLikeDeclaration(node) {
if (node.kind === 212 /* ClassDeclaration */) {
bindBlockScopedDeclaration(node, 32 /* Class */, 899519 /* ClassExcludes */);
}
else {
var bindingName = node.name ? node.name.text : "__class";
bindAnonymousDeclaration(node, 32 /* Class */, bindingName);
// Add name of class expression into the map for semantic classifier
if (node.name) {
classifiableNames[node.name.text] = node.name.text;
}
}
var symbol = node.symbol;
// TypeScript 1.0 spec (April 2014): 8.4
// Every class automatically contains a static property member named 'prototype', the
// type of which is an instantiation of the class type with type Any supplied as a type
// argument for each type parameter. It is an error to explicitly declare a static
// property member with the name 'prototype'.
//
// Note: we check for this here because this class may be merging into a module. The
// module might have an exported variable called 'prototype'. We can't allow that as
// that would clash with the built-in 'prototype' for the class.
var prototypeSymbol = createSymbol(4 /* Property */ | 134217728 /* Prototype */, "prototype");
if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) {
if (node.name) {
node.name.parent = node;
}
file.bindDiagnostics.push(ts.createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], ts.Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
}
symbol.exports[prototypeSymbol.name] = prototypeSymbol;
prototypeSymbol.parent = symbol;
}
function bindEnumDeclaration(node) {
return ts.isConst(node)
? bindBlockScopedDeclaration(node, 128 /* ConstEnum */, 899967 /* ConstEnumExcludes */)
: bindBlockScopedDeclaration(node, 256 /* RegularEnum */, 899327 /* RegularEnumExcludes */);
}
function 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 */);
}
}
}
function 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 (node.flags & 112 /* AccessibilityModifier */ &&
node.parent.kind === 142 /* Constructor */ &&
ts.isClassLike(node.parent.parent)) {
var classDeclaration = node.parent.parent;
declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */);
}
}
function bindPropertyOrMethodOrAccessor(node, symbolFlags, symbolExcludes) {
return ts.hasDynamicName(node)
? bindAnonymousDeclaration(node, symbolFlags, "__computed")
: declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes);
}
}
})(ts || (ts = {}));
/// <reference path="binder.ts" />
/* @internal */
var ts;
(function (ts) {
function getDeclarationOfKind(symbol, kind) {
var declarations = symbol.declarations;
if (declarations) {
for (var _i = 0; _i < declarations.length; _i++) {
var declaration = declarations[_i];
if (declaration.kind === kind) {
return declaration;
}
}
}
return undefined;
}
ts.getDeclarationOfKind = getDeclarationOfKind;
// Pool writers to avoid needing to allocate them for every symbol we write.
var stringWriters = [];
function getSingleLineStringWriter() {
if (stringWriters.length === 0) {
var str = "";
var writeText = function (text) { return str += text; };
return {
string: function () { return str; },
writeKeyword: writeText,
writeOperator: writeText,
writePunctuation: writeText,
writeSpace: writeText,
writeStringLiteral: writeText,
writeParameter: writeText,
writeSymbol: writeText,
// Completely ignore indentation for string writers. And map newlines to
// a single space.
writeLine: function () { return str += " "; },
increaseIndent: function () { },
decreaseIndent: function () { },
clear: function () { return str = ""; },
trackSymbol: function () { }
};
}
return stringWriters.pop();
}
ts.getSingleLineStringWriter = getSingleLineStringWriter;
function releaseStringWriter(writer) {
writer.clear();
stringWriters.push(writer);
}
ts.releaseStringWriter = releaseStringWriter;
function getFullWidth(node) {
return node.end - node.pos;
}
ts.getFullWidth = getFullWidth;
function arrayIsEqualTo(arr1, arr2, comparer) {
if (!arr1 || !arr2) {
return arr1 === arr2;
}
if (arr1.length !== arr2.length) {
return false;
}
for (var i = 0; i < arr1.length; ++i) {
var equals = comparer ? comparer(arr1[i], arr2[i]) : arr1[i] === arr2[i];
if (!equals) {
return false;
}
}
return true;
}
ts.arrayIsEqualTo = arrayIsEqualTo;
function hasResolvedModuleName(sourceFile, moduleNameText) {
return sourceFile.resolvedModules && ts.hasProperty(sourceFile.resolvedModules, moduleNameText);
}
ts.hasResolvedModuleName = hasResolvedModuleName;
function getResolvedModuleFileName(sourceFile, moduleNameText) {
return hasResolvedModuleName(sourceFile, moduleNameText) ? sourceFile.resolvedModules[moduleNameText] : undefined;
}
ts.getResolvedModuleFileName = getResolvedModuleFileName;
function setResolvedModuleName(sourceFile, moduleNameText, resolvedFileName) {
if (!sourceFile.resolvedModules) {
sourceFile.resolvedModules = {};
}
sourceFile.resolvedModules[moduleNameText] = resolvedFileName;
}
ts.setResolvedModuleName = setResolvedModuleName;
// Returns true if this node contains a parse error anywhere underneath it.
function containsParseError(node) {
aggregateChildData(node);
return (node.parserContextFlags & 64 /* ThisNodeOrAnySubNodesHasError */) !== 0;
}
ts.containsParseError = containsParseError;
function aggregateChildData(node) {
if (!(node.parserContextFlags & 128 /* HasAggregatedChildData */)) {
// A node is considered to contain a parse error if:
// a) the parser explicitly marked that it had an error
// b) any of it's children reported that it had an error.
var thisNodeOrAnySubNodesHasError = ((node.parserContextFlags & 16 /* ThisNodeHasError */) !== 0) ||
ts.forEachChild(node, containsParseError);
// If so, mark ourselves accordingly.
if (thisNodeOrAnySubNodesHasError) {
node.parserContextFlags |= 64 /* ThisNodeOrAnySubNodesHasError */;
}
// Also mark that we've propogated the child information to this node. This way we can
// always consult the bit directly on this node without needing to check its children
// again.
node.parserContextFlags |= 128 /* HasAggregatedChildData */;
}
}
function getSourceFileOfNode(node) {
while (node && node.kind !== 246 /* SourceFile */) {
node = node.parent;
}
return node;
}
ts.getSourceFileOfNode = getSourceFileOfNode;
function getStartPositionOfLine(line, sourceFile) {
ts.Debug.assert(line >= 0);
return ts.getLineStarts(sourceFile)[line];
}
ts.getStartPositionOfLine = getStartPositionOfLine;
// This is a useful function for debugging purposes.
function nodePosToString(node) {
var file = getSourceFileOfNode(node);
var loc = ts.getLineAndCharacterOfPosition(file, node.pos);
return file.fileName + "(" + (loc.line + 1) + "," + (loc.character + 1) + ")";
}
ts.nodePosToString = nodePosToString;
function getStartPosOfNode(node) {
return node.pos;
}
ts.getStartPosOfNode = getStartPosOfNode;
// Returns true if this node is missing from the actual source code. 'missing' is different
// from 'undefined/defined'. When a node is undefined (which can happen for optional nodes
// in the tree), it is definitel missing. HOwever, a node may be defined, but still be
// missing. This happens whenever the parser knows it needs to parse something, but can't
// get anything in the source code that it expects at that location. For example:
//
// let a: ;
//
// Here, the Type in the Type-Annotation is not-optional (as there is a colon in the source
// code). So the parser will attempt to parse out a type, and will create an actual node.
// However, this node will be 'missing' in the sense that no actual source-code/tokens are
// contained within it.
function nodeIsMissing(node) {
if (!node) {
return true;
}
return node.pos === node.end && node.pos >= 0 && node.kind !== 1 /* EndOfFileToken */;
}
ts.nodeIsMissing = nodeIsMissing;
function nodeIsPresent(node) {
return !nodeIsMissing(node);
}
ts.nodeIsPresent = nodeIsPresent;
function getTokenPosOfNode(node, sourceFile) {
// With nodes that have no width (i.e. 'Missing' nodes), we actually *don't*
// want to skip trivia because this will launch us forward to the next token.
if (nodeIsMissing(node)) {
return node.pos;
}
return ts.skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos);
}
ts.getTokenPosOfNode = getTokenPosOfNode;
function getNonDecoratorTokenPosOfNode(node, sourceFile) {
if (nodeIsMissing(node) || !node.decorators) {
return getTokenPosOfNode(node, sourceFile);
}
return ts.skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.decorators.end);
}
ts.getNonDecoratorTokenPosOfNode = getNonDecoratorTokenPosOfNode;
function getSourceTextOfNodeFromSourceFile(sourceFile, node, includeTrivia) {
if (includeTrivia === void 0) { includeTrivia = false; }
if (nodeIsMissing(node)) {
return "";
}
var text = sourceFile.text;
return text.substring(includeTrivia ? node.pos : ts.skipTrivia(text, node.pos), node.end);
}
ts.getSourceTextOfNodeFromSourceFile = getSourceTextOfNodeFromSourceFile;
function getTextOfNodeFromSourceText(sourceText, node) {
if (nodeIsMissing(node)) {
return "";
}
return sourceText.substring(ts.skipTrivia(sourceText, node.pos), node.end);
}
ts.getTextOfNodeFromSourceText = getTextOfNodeFromSourceText;
function getTextOfNode(node, includeTrivia) {
if (includeTrivia === void 0) { includeTrivia = false; }
return getSourceTextOfNodeFromSourceFile(getSourceFileOfNode(node), node, includeTrivia);
}
ts.getTextOfNode = getTextOfNode;
// Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like '__proto__'
function escapeIdentifier(identifier) {
return identifier.length >= 2 && identifier.charCodeAt(0) === 95 /* _ */ && identifier.charCodeAt(1) === 95 /* _ */ ? "_" + identifier : identifier;
}
ts.escapeIdentifier = escapeIdentifier;
// Remove extra underscore from escaped identifier
function unescapeIdentifier(identifier) {
return identifier.length >= 3 && identifier.charCodeAt(0) === 95 /* _ */ && identifier.charCodeAt(1) === 95 /* _ */ && identifier.charCodeAt(2) === 95 /* _ */ ? identifier.substr(1) : identifier;
}
ts.unescapeIdentifier = unescapeIdentifier;
// Make an identifier from an external module name by extracting the string after the last "/" and replacing
// all non-alphanumeric characters with underscores
function makeIdentifierFromModuleName(moduleName) {
return ts.getBaseFileName(moduleName).replace(/^(\d)/, "_$1").replace(/\W/g, "_");
}
ts.makeIdentifierFromModuleName = makeIdentifierFromModuleName;
function isBlockOrCatchScoped(declaration) {
return (getCombinedNodeFlags(declaration) & 49152 /* BlockScoped */) !== 0 ||
isCatchClauseVariableDeclaration(declaration);
}
ts.isBlockOrCatchScoped = isBlockOrCatchScoped;
// Gets the nearest enclosing block scope container that has the provided node
// as a descendant, that is not the provided node.
function getEnclosingBlockScopeContainer(node) {
var current = node.parent;
while (current) {
if (isFunctionLike(current)) {
return current;
}
switch (current.kind) {
case 246 /* SourceFile */:
case 218 /* CaseBlock */:
case 242 /* CatchClause */:
case 216 /* ModuleDeclaration */:
case 197 /* ForStatement */:
case 198 /* ForInStatement */:
case 199 /* ForOfStatement */:
return current;
case 190 /* Block */:
// function block is not considered block-scope container
// see comment in binder.ts: bind(...), case for SyntaxKind.Block
if (!isFunctionLike(current.parent)) {
return current;
}
}
current = current.parent;
}
}
ts.getEnclosingBlockScopeContainer = getEnclosingBlockScopeContainer;
function isCatchClauseVariableDeclaration(declaration) {
return declaration &&
declaration.kind === 209 /* VariableDeclaration */ &&
declaration.parent &&
declaration.parent.kind === 242 /* CatchClause */;
}
ts.isCatchClauseVariableDeclaration = isCatchClauseVariableDeclaration;
// Return display name of an identifier
// Computed property names will just be emitted as "[<expr>]", where <expr> is the source
// text of the expression in the computed property.
function declarationNameToString(name) {
return getFullWidth(name) === 0 ? "(Missing)" : getTextOfNode(name);
}
ts.declarationNameToString = declarationNameToString;
function createDiagnosticForNode(node, message, arg0, arg1, arg2) {
var sourceFile = getSourceFileOfNode(node);
var span = getErrorSpanForNode(sourceFile, node);
return ts.createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2);
}
ts.createDiagnosticForNode = createDiagnosticForNode;
function createDiagnosticForNodeFromMessageChain(node, messageChain) {
var sourceFile = getSourceFileOfNode(node);
var span = getErrorSpanForNode(sourceFile, node);
return {
file: sourceFile,
start: span.start,
length: span.length,
code: messageChain.code,
category: messageChain.category,
messageText: messageChain.next ? messageChain : messageChain.messageText
};
}
ts.createDiagnosticForNodeFromMessageChain = createDiagnosticForNodeFromMessageChain;
function getSpanOfTokenAtPosition(sourceFile, pos) {
var scanner = ts.createScanner(sourceFile.languageVersion, /*skipTrivia*/ true, sourceFile.languageVariant, sourceFile.text, /*onError:*/ undefined, pos);
scanner.scan();
var start = scanner.getTokenPos();
return ts.createTextSpanFromBounds(start, scanner.getTextPos());
}
ts.getSpanOfTokenAtPosition = getSpanOfTokenAtPosition;
function getErrorSpanForNode(sourceFile, node) {
var errorNode = node;
switch (node.kind) {
case 246 /* SourceFile */:
var pos_1 = ts.skipTrivia(sourceFile.text, 0, /*stopAfterLineBreak*/ false);
if (pos_1 === sourceFile.text.length) {
// file is empty - return span for the beginning of the file
return ts.createTextSpan(0, 0);
}
return getSpanOfTokenAtPosition(sourceFile, pos_1);
// This list is a work in progress. Add missing node kinds to improve their error
// spans.
case 209 /* VariableDeclaration */:
case 161 /* BindingElement */:
case 212 /* ClassDeclaration */:
case 184 /* ClassExpression */:
case 213 /* InterfaceDeclaration */:
case 216 /* ModuleDeclaration */:
case 215 /* EnumDeclaration */:
case 245 /* EnumMember */:
case 211 /* FunctionDeclaration */:
case 171 /* FunctionExpression */:
errorNode = node.name;
break;
}
if (errorNode === undefined) {
// If we don't have a better node, then just set the error on the first token of
// construct.
return getSpanOfTokenAtPosition(sourceFile, node.pos);
}
var pos = nodeIsMissing(errorNode)
? errorNode.pos
: ts.skipTrivia(sourceFile.text, errorNode.pos);
return ts.createTextSpanFromBounds(pos, errorNode.end);
}
ts.getErrorSpanForNode = getErrorSpanForNode;
function isExternalModule(file) {
return file.externalModuleIndicator !== undefined;
}
ts.isExternalModule = isExternalModule;
function isDeclarationFile(file) {
return (file.flags & 8192 /* DeclarationFile */) !== 0;
}
ts.isDeclarationFile = isDeclarationFile;
function isConstEnumDeclaration(node) {
return node.kind === 215 /* EnumDeclaration */ && isConst(node);
}
ts.isConstEnumDeclaration = isConstEnumDeclaration;
function walkUpBindingElementsAndPatterns(node) {
while (node && (node.kind === 161 /* BindingElement */ || isBindingPattern(node))) {
node = node.parent;
}
return node;
}
// Returns the node flags for this node and all relevant parent nodes. This is done so that
// nodes like variable declarations and binding elements can returned a view of their flags
// that includes the modifiers from their container. i.e. flags like export/declare aren't
// stored on the variable declaration directly, but on the containing variable statement
// (if it has one). Similarly, flags for let/const are store on the variable declaration
// list. By calling this function, all those flags are combined so that the client can treat
// the node as if it actually had those flags.
function getCombinedNodeFlags(node) {
node = walkUpBindingElementsAndPatterns(node);
var flags = node.flags;
if (node.kind === 209 /* VariableDeclaration */) {
node = node.parent;
}
if (node && node.kind === 210 /* VariableDeclarationList */) {
flags |= node.flags;
node = node.parent;
}
if (node && node.kind === 191 /* VariableStatement */) {
flags |= node.flags;
}
return flags;
}
ts.getCombinedNodeFlags = getCombinedNodeFlags;
function isConst(node) {
return !!(getCombinedNodeFlags(node) & 32768 /* Const */);
}
ts.isConst = isConst;
function isLet(node) {
return !!(getCombinedNodeFlags(node) & 16384 /* Let */);
}
ts.isLet = isLet;
function isPrologueDirective(node) {
return node.kind === 193 /* ExpressionStatement */ && node.expression.kind === 9 /* StringLiteral */;
}
ts.isPrologueDirective = isPrologueDirective;
function getLeadingCommentRangesOfNode(node, sourceFileOfNode) {
return ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos);
}
ts.getLeadingCommentRangesOfNode = getLeadingCommentRangesOfNode;
function getJsDocComments(node, sourceFileOfNode) {
var commentRanges = (node.kind === 136 /* Parameter */ || node.kind === 135 /* TypeParameter */) ?
ts.concatenate(ts.getTrailingCommentRanges(sourceFileOfNode.text, node.pos), ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos)) :
getLeadingCommentRangesOfNode(node, sourceFileOfNode);
return ts.filter(commentRanges, isJsDocComment);
function isJsDocComment(comment) {
// True if the comment starts with '/**' but not if it is '/**/'
return sourceFileOfNode.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */ &&
sourceFileOfNode.text.charCodeAt(comment.pos + 2) === 42 /* asterisk */ &&
sourceFileOfNode.text.charCodeAt(comment.pos + 3) !== 47 /* slash */;
}
}
ts.getJsDocComments = getJsDocComments;
ts.fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
function isTypeNode(node) {
if (149 /* FirstTypeNode */ <= node.kind && node.kind <= 158 /* LastTypeNode */) {
return true;
}
switch (node.kind) {
case 115 /* AnyKeyword */:
case 126 /* NumberKeyword */:
case 128 /* StringKeyword */:
case 118 /* BooleanKeyword */:
case 129 /* SymbolKeyword */:
return true;
case 101 /* VoidKeyword */:
return node.parent.kind !== 175 /* VoidExpression */;
case 9 /* StringLiteral */:
// Specialized signatures can have string literals as their parameters' type names
return node.parent.kind === 136 /* Parameter */;
case 186 /* ExpressionWithTypeArguments */:
return !isExpressionWithTypeArgumentsInClassExtendsClause(node);
// Identifiers and qualified names may be type nodes, depending on their context. Climb
// above them to find the lowest container
case 67 /* Identifier */:
// If the identifier is the RHS of a qualified name, then it's a type iff its parent is.
if (node.parent.kind === 133 /* QualifiedName */ && node.parent.right === node) {
node = node.parent;
}
else if (node.parent.kind === 164 /* PropertyAccessExpression */ && node.parent.name === node) {
node = node.parent;
}
// fall through
case 133 /* QualifiedName */:
case 164 /* PropertyAccessExpression */:
// At this point, node is either a qualified name or an identifier
ts.Debug.assert(node.kind === 67 /* Identifier */ || node.kind === 133 /* QualifiedName */ || node.kind === 164 /* PropertyAccessExpression */, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'.");
var parent_1 = node.parent;
if (parent_1.kind === 152 /* TypeQuery */) {
return false;
}
// Do not recursively call isTypeNode on the parent. In the example:
//
// let a: A.B.C;
//
// Calling isTypeNode would consider the qualified name A.B a type node. Only C or
// A.B.C is a type node.
if (149 /* FirstTypeNode */ <= parent_1.kind && parent_1.kind <= 158 /* LastTypeNode */) {
return true;
}
switch (parent_1.kind) {
case 186 /* ExpressionWithTypeArguments */:
return !isExpressionWithTypeArgumentsInClassExtendsClause(parent_1);
case 135 /* TypeParameter */:
return node === parent_1.constraint;
case 139 /* PropertyDeclaration */:
case 138 /* PropertySignature */:
case 136 /* Parameter */:
case 209 /* VariableDeclaration */:
return node === parent_1.type;
case 211 /* FunctionDeclaration */:
case 171 /* FunctionExpression */:
case 172 /* ArrowFunction */:
case 142 /* Constructor */:
case 141 /* MethodDeclaration */:
case 140 /* MethodSignature */:
case 143 /* GetAccessor */:
case 144 /* SetAccessor */:
return node === parent_1.type;
case 145 /* CallSignature */:
case 146 /* ConstructSignature */:
case 147 /* IndexSignature */:
return node === parent_1.type;
case 169 /* TypeAssertionExpression */:
return node === parent_1.type;
case 166 /* CallExpression */:
case 167 /* NewExpression */:
return parent_1.typeArguments && ts.indexOf(parent_1.typeArguments, node) >= 0;
case 168 /* TaggedTemplateExpression */:
// TODO (drosen): TaggedTemplateExpressions may eventually support type arguments.
return false;
}
}
return false;
}
ts.isTypeNode = isTypeNode;
// Warning: This has the same semantics as the forEach family of functions,
// in that traversal terminates in the event that 'visitor' supplies a truthy value.
function forEachReturnStatement(body, visitor) {
return traverse(body);
function traverse(node) {
switch (node.kind) {
case 202 /* ReturnStatement */:
return visitor(node);
case 218 /* CaseBlock */:
case 190 /* Block */:
case 194 /* IfStatement */:
case 195 /* DoStatement */:
case 196 /* WhileStatement */:
case 197 /* ForStatement */:
case 198 /* ForInStatement */:
case 199 /* ForOfStatement */:
case 203 /* WithStatement */:
case 204 /* SwitchStatement */:
case 239 /* CaseClause */:
case 240 /* DefaultClause */:
case 205 /* LabeledStatement */:
case 207 /* TryStatement */:
case 242 /* CatchClause */:
return ts.forEachChild(node, traverse);
}
}
}
ts.forEachReturnStatement = forEachReturnStatement;
function forEachYieldExpression(body, visitor) {
return traverse(body);
function traverse(node) {
switch (node.kind) {
case 182 /* YieldExpression */:
visitor(node);
var operand = node.expression;
if (operand) {
traverse(operand);
}
case 215 /* EnumDeclaration */:
case 213 /* InterfaceDeclaration */:
case 216 /* ModuleDeclaration */:
case 214 /* TypeAliasDeclaration */:
case 212 /* ClassDeclaration */:
case 184 /* ClassExpression */:
// These are not allowed inside a generator now, but eventually they may be allowed
// as local types. Regardless, any yield statements contained within them should be
// skipped in this traversal.
return;
default:
if (isFunctionLike(node)) {
var name_5 = node.name;
if (name_5 && name_5.kind === 134 /* ComputedPropertyName */) {
// Note that we will not include methods/accessors of a class because they would require
// first descending into the class. This is by design.
traverse(name_5.expression);
return;
}
}
else if (!isTypeNode(node)) {
// This is the general case, which should include mostly expressions and statements.
// Also includes NodeArrays.
ts.forEachChild(node, traverse);
}
}
}
}
ts.forEachYieldExpression = forEachYieldExpression;
function isVariableLike(node) {
if (node) {
switch (node.kind) {
case 161 /* BindingElement */:
case 245 /* EnumMember */:
case 136 /* Parameter */:
case 243 /* PropertyAssignment */:
case 139 /* PropertyDeclaration */:
case 138 /* PropertySignature */:
case 244 /* ShorthandPropertyAssignment */:
case 209 /* VariableDeclaration */:
return true;
}
}
return false;
}
ts.isVariableLike = isVariableLike;
function isAccessor(node) {
return node && (node.kind === 143 /* GetAccessor */ || node.kind === 144 /* SetAccessor */);
}
ts.isAccessor = isAccessor;
function isClassLike(node) {
return node && (node.kind === 212 /* ClassDeclaration */ || node.kind === 184 /* ClassExpression */);
}
ts.isClassLike = isClassLike;
function isFunctionLike(node) {
if (node) {
switch (node.kind) {
case 142 /* Constructor */:
case 171 /* FunctionExpression */:
case 211 /* FunctionDeclaration */:
case 172 /* ArrowFunction */:
case 141 /* MethodDeclaration */:
case 140 /* MethodSignature */:
case 143 /* GetAccessor */:
case 144 /* SetAccessor */:
case 145 /* CallSignature */:
case 146 /* ConstructSignature */:
case 147 /* IndexSignature */:
case 150 /* FunctionType */:
case 151 /* ConstructorType */:
return true;
}
}
return false;
}
ts.isFunctionLike = isFunctionLike;
function introducesArgumentsExoticObject(node) {
switch (node.kind) {
case 141 /* MethodDeclaration */:
case 140 /* MethodSignature */:
case 142 /* Constructor */:
case 143 /* GetAccessor */:
case 144 /* SetAccessor */:
case 211 /* FunctionDeclaration */:
case 171 /* FunctionExpression */:
return true;
}
return false;
}
ts.introducesArgumentsExoticObject = introducesArgumentsExoticObject;
function isFunctionBlock(node) {
return node && node.kind === 190 /* Block */ && isFunctionLike(node.parent);
}
ts.isFunctionBlock = isFunctionBlock;
function isObjectLiteralMethod(node) {
return node && node.kind === 141 /* MethodDeclaration */ && node.parent.kind === 163 /* ObjectLiteralExpression */;
}
ts.isObjectLiteralMethod = isObjectLiteralMethod;
function getContainingFunction(node) {
while (true) {
node = node.parent;
if (!node || isFunctionLike(node)) {
return node;
}
}
}
ts.getContainingFunction = getContainingFunction;
function getContainingClass(node) {
while (true) {
node = node.parent;
if (!node || isClassLike(node)) {
return node;
}
}
}
ts.getContainingClass = getContainingClass;
function getThisContainer(node, includeArrowFunctions) {
while (true) {
node = node.parent;
if (!node) {
return undefined;
}
switch (node.kind) {
case 134 /* ComputedPropertyName */:
// If the grandparent node is an object literal (as opposed to a class),
// then the computed property is not a 'this' container.
// A computed property name in a class needs to be a this container
// so that we can error on it.
if (isClassLike(node.parent.parent)) {
return node;
}
// If this is a computed property, then the parent should not
// make it a this container. The parent might be a property
// in an object literal, like a method or accessor. But in order for
// such a parent to be a this container, the reference must be in
// the *body* of the container.
node = node.parent;
break;
case 137 /* Decorator */:
// Decorators are always applied outside of the body of a class or method.
if (node.parent.kind === 136 /* Parameter */ && isClassElement(node.parent.parent)) {
// If the decorator's parent is a Parameter, we resolve the this container from
// the grandparent class declaration.
node = node.parent.parent;
}
else if (isClassElement(node.parent)) {
// If the decorator's parent is a class element, we resolve the 'this' container
// from the parent class declaration.
node = node.parent;
}
break;
case 172 /* ArrowFunction */:
if (!includeArrowFunctions) {
continue;
}
// Fall through
case 211 /* FunctionDeclaration */:
case 171 /* FunctionExpression */:
case 216 /* ModuleDeclaration */:
case 139 /* PropertyDeclaration */:
case 138 /* PropertySignature */:
case 141 /* MethodDeclaration */:
case 140 /* MethodSignature */:
case 142 /* Constructor */:
case 143 /* GetAccessor */:
case 144 /* SetAccessor */:
case 215 /* EnumDeclaration */:
case 246 /* SourceFile */:
return node;
}
}
}
ts.getThisContainer = getThisContainer;
function getSuperContainer(node, includeFunctions) {
while (true) {
node = node.parent;
if (!node)
return node;
switch (node.kind) {
case 134 /* ComputedPropertyName */:
// If the grandparent node is an object literal (as opposed to a class),
// then the computed property is not a 'super' container.
// A computed property name in a class needs to be a super container
// so that we can error on it.
if (isClassLike(node.parent.parent)) {
return node;
}
// If this is a computed property, then the parent should not
// make it a super container. The parent might be a property
// in an object literal, like a method or accessor. But in order for
// such a parent to be a super container, the reference must be in
// the *body* of the container.
node = node.parent;
break;
case 137 /* Decorator */:
// Decorators are always applied outside of the body of a class or method.
if (node.parent.kind === 136 /* Parameter */ && isClassElement(node.parent.parent)) {
// If the decorator's parent is a Parameter, we resolve the this container from
// the grandparent class declaration.
node = node.parent.parent;
}
else if (isClassElement(node.parent)) {
// If the decorator's parent is a class element, we resolve the 'this' container
// from the parent class declaration.
node = node.parent;
}
break;
case 211 /* FunctionDeclaration */:
case 171 /* FunctionExpression */:
case 172 /* ArrowFunction */:
if (!includeFunctions) {
continue;
}
case 139 /* PropertyDeclaration */:
case 138 /* PropertySignature */:
case 141 /* MethodDeclaration */:
case 140 /* MethodSignature */:
case 142 /* Constructor */:
case 143 /* GetAccessor */:
case 144 /* SetAccessor */:
return node;
}
}
}
ts.getSuperContainer = getSuperContainer;
function getEntityNameFromTypeNode(node) {
if (node) {
switch (node.kind) {
case 149 /* TypeReference */:
return node.typeName;
case 186 /* ExpressionWithTypeArguments */:
return node.expression;
case 67 /* Identifier */:
case 133 /* QualifiedName */:
return node;
}
}
return undefined;
}
ts.getEntityNameFromTypeNode = getEntityNameFromTypeNode;
function getInvokedExpression(node) {
if (node.kind === 168 /* TaggedTemplateExpression */) {
return node.tag;
}
// Will either be a CallExpression, NewExpression, or Decorator.
return node.expression;
}
ts.getInvokedExpression = getInvokedExpression;
function nodeCanBeDecorated(node) {
switch (node.kind) {
case 212 /* ClassDeclaration */:
// classes are valid targets
return true;
case 139 /* PropertyDeclaration */:
// property declarations are valid if their parent is a class declaration.
return node.parent.kind === 212 /* ClassDeclaration */;
case 136 /* Parameter */:
// if the parameter's parent has a body and its grandparent is a class declaration, this is a valid target;
return node.parent.body && node.parent.parent.kind === 212 /* ClassDeclaration */;
case 143 /* GetAccessor */:
case 144 /* SetAccessor */:
case 141 /* MethodDeclaration */:
// if this method has a body and its parent is a class declaration, this is a valid target.
return node.body && node.parent.kind === 212 /* ClassDeclaration */;
}
return false;
}
ts.nodeCanBeDecorated = nodeCanBeDecorated;
function nodeIsDecorated(node) {
switch (node.kind) {
case 212 /* ClassDeclaration */:
if (node.decorators) {
return true;
}
return false;
case 139 /* PropertyDeclaration */:
case 136 /* Parameter */:
if (node.decorators) {
return true;
}
return false;
case 143 /* GetAccessor */:
if (node.body && node.decorators) {
return true;
}
return false;
case 141 /* MethodDeclaration */:
case 144 /* SetAccessor */:
if (node.body && node.decorators) {
return true;
}
return false;
}
return false;
}
ts.nodeIsDecorated = nodeIsDecorated;
function childIsDecorated(node) {
switch (node.kind) {
case 212 /* ClassDeclaration */:
return ts.forEach(node.members, nodeOrChildIsDecorated);
case 141 /* MethodDeclaration */:
case 144 /* SetAccessor */:
return ts.forEach(node.parameters, nodeIsDecorated);
}
return false;
}
ts.childIsDecorated = childIsDecorated;
function nodeOrChildIsDecorated(node) {
return nodeIsDecorated(node) || childIsDecorated(node);
}
ts.nodeOrChildIsDecorated = nodeOrChildIsDecorated;
function isExpression(node) {
switch (node.kind) {
case 95 /* ThisKeyword */:
case 93 /* SuperKeyword */:
case 91 /* NullKeyword */:
case 97 /* TrueKeyword */:
case 82 /* FalseKeyword */:
case 10 /* RegularExpressionLiteral */:
case 162 /* ArrayLiteralExpression */:
case 163 /* ObjectLiteralExpression */:
case 164 /* PropertyAccessExpression */:
case 165 /* ElementAccessExpression */:
case 166 /* CallExpression */:
case 167 /* NewExpression */:
case 168 /* TaggedTemplateExpression */:
case 187 /* AsExpression */:
case 169 /* TypeAssertionExpression */:
case 170 /* ParenthesizedExpression */:
case 171 /* FunctionExpression */:
case 184 /* ClassExpression */:
case 172 /* ArrowFunction */:
case 175 /* VoidExpression */:
case 173 /* DeleteExpression */:
case 174 /* TypeOfExpression */:
case 177 /* PrefixUnaryExpression */:
case 178 /* PostfixUnaryExpression */:
case 179 /* BinaryExpression */:
case 180 /* ConditionalExpression */:
case 183 /* SpreadElementExpression */:
case 181 /* TemplateExpression */:
case 11 /* NoSubstitutionTemplateLiteral */:
case 185 /* OmittedExpression */:
case 231 /* JsxElement */:
case 232 /* JsxSelfClosingElement */:
case 182 /* YieldExpression */:
return true;
case 133 /* QualifiedName */:
while (node.parent.kind === 133 /* QualifiedName */) {
node = node.parent;
}
return node.parent.kind === 152 /* TypeQuery */;
case 67 /* Identifier */:
if (node.parent.kind === 152 /* TypeQuery */) {
return true;
}
// fall through
case 8 /* NumericLiteral */:
case 9 /* StringLiteral */:
var parent_2 = node.parent;
switch (parent_2.kind) {
case 209 /* VariableDeclaration */:
case 136 /* Parameter */:
case 139 /* PropertyDeclaration */:
case 138 /* PropertySignature */:
case 245 /* EnumMember */:
case 243 /* PropertyAssignment */:
case 161 /* BindingElement */:
return parent_2.initializer === node;
case 193 /* ExpressionStatement */:
case 194 /* IfStatement */:
case 195 /* DoStatement */:
case 196 /* WhileStatement */:
case 202 /* ReturnStatement */:
case 203 /* WithStatement */:
case 204 /* SwitchStatement */:
case 239 /* CaseClause */:
case 206 /* ThrowStatement */:
case 204 /* SwitchStatement */:
return parent_2.expression === node;
case 197 /* ForStatement */:
var forStatement = parent_2;
return (forStatement.initializer === node && forStatement.initializer.kind !== 210 /* VariableDeclarationList */) ||
forStatement.condition === node ||
forStatement.incrementor === node;
case 198 /* ForInStatement */:
case 199 /* ForOfStatement */:
var forInStatement = parent_2;
return (forInStatement.initializer === node && forInStatement.initializer.kind !== 210 /* VariableDeclarationList */) ||
forInStatement.expression === node;
case 169 /* TypeAssertionExpression */:
case 187 /* AsExpression */:
return node === parent_2.expression;
case 188 /* TemplateSpan */:
return node === parent_2.expression;
case 134 /* ComputedPropertyName */:
return node === parent_2.expression;
case 137 /* Decorator */:
case 238 /* JsxExpression */:
return true;
case 186 /* ExpressionWithTypeArguments */:
return parent_2.expression === node && isExpressionWithTypeArgumentsInClassExtendsClause(parent_2);
default:
if (isExpression(parent_2)) {
return true;
}
}
}
return false;
}
ts.isExpression = isExpression;
function isInstantiatedModule(node, preserveConstEnums) {
var moduleState = ts.getModuleInstanceState(node);
return moduleState === 1 /* Instantiated */ ||
(preserveConstEnums && moduleState === 2 /* ConstEnumOnly */);
}
ts.isInstantiatedModule = isInstantiatedModule;
function isExternalModuleImportEqualsDeclaration(node) {
return node.kind === 219 /* ImportEqualsDeclaration */ && node.moduleReference.kind === 230 /* ExternalModuleReference */;
}
ts.isExternalModuleImportEqualsDeclaration = isExternalModuleImportEqualsDeclaration;
function getExternalModuleImportEqualsDeclarationExpression(node) {
ts.Debug.assert(isExternalModuleImportEqualsDeclaration(node));
return node.moduleReference.expression;
}
ts.getExternalModuleImportEqualsDeclarationExpression = getExternalModuleImportEqualsDeclarationExpression;
function isInternalModuleImportEqualsDeclaration(node) {
return node.kind === 219 /* ImportEqualsDeclaration */ && node.moduleReference.kind !== 230 /* ExternalModuleReference */;
}
ts.isInternalModuleImportEqualsDeclaration = isInternalModuleImportEqualsDeclaration;
function getExternalModuleName(node) {
if (node.kind === 220 /* ImportDeclaration */) {
return node.moduleSpecifier;
}
if (node.kind === 219 /* ImportEqualsDeclaration */) {
var reference = node.moduleReference;
if (reference.kind === 230 /* ExternalModuleReference */) {
return reference.expression;
}
}
if (node.kind === 226 /* ExportDeclaration */) {
return node.moduleSpecifier;
}
}
ts.getExternalModuleName = getExternalModuleName;
function hasQuestionToken(node) {
if (node) {
switch (node.kind) {
case 136 /* Parameter */:
case 141 /* MethodDeclaration */:
case 140 /* MethodSignature */:
case 244 /* ShorthandPropertyAssignment */:
case 243 /* PropertyAssignment */:
case 139 /* PropertyDeclaration */:
case 138 /* PropertySignature */:
return node.questionToken !== undefined;
}
}
return false;
}
ts.hasQuestionToken = hasQuestionToken;
function isJSDocConstructSignature(node) {
return node.kind === 259 /* JSDocFunctionType */ &&
node.parameters.length > 0 &&
node.parameters[0].type.kind === 261 /* JSDocConstructorType */;
}
ts.isJSDocConstructSignature = isJSDocConstructSignature;
function getJSDocTag(node, kind) {
if (node && node.jsDocComment) {
for (var _i = 0, _a = node.jsDocComment.tags; _i < _a.length; _i++) {
var tag = _a[_i];
if (tag.kind === kind) {
return tag;
}
}
}
}
function getJSDocTypeTag(node) {
return getJSDocTag(node, 267 /* JSDocTypeTag */);
}
ts.getJSDocTypeTag = getJSDocTypeTag;
function getJSDocReturnTag(node) {
return getJSDocTag(node, 266 /* JSDocReturnTag */);
}
ts.getJSDocReturnTag = getJSDocReturnTag;
function getJSDocTemplateTag(node) {
return getJSDocTag(node, 268 /* JSDocTemplateTag */);
}
ts.getJSDocTemplateTag = getJSDocTemplateTag;
function getCorrespondingJSDocParameterTag(parameter) {
if (parameter.name && parameter.name.kind === 67 /* Identifier */) {
// If it's a parameter, see if the parent has a jsdoc comment with an @param
// annotation.
var parameterName = parameter.name.text;
var docComment = parameter.parent.jsDocComment;
if (docComment) {
return ts.forEach(docComment.tags, function (t) {
if (t.kind === 265 /* JSDocParameterTag */) {
var parameterTag = t;
var name_6 = parameterTag.preParameterName || parameterTag.postParameterName;
if (name_6.text === parameterName) {
return t;
}
}
});
}
}
}
ts.getCorrespondingJSDocParameterTag = getCorrespondingJSDocParameterTag;
function hasRestParameter(s) {
return isRestParameter(ts.lastOrUndefined(s.parameters));
}
ts.hasRestParameter = hasRestParameter;
function isRestParameter(node) {
if (node) {
if (node.parserContextFlags & 32 /* JavaScriptFile */) {
if (node.type && node.type.kind === 260 /* JSDocVariadicType */) {
return true;
}
var paramTag = getCorrespondingJSDocParameterTag(node);
if (paramTag && paramTag.typeExpression) {
return paramTag.typeExpression.type.kind === 260 /* JSDocVariadicType */;
}
}
return node.dotDotDotToken !== undefined;
}
return false;
}
ts.isRestParameter = isRestParameter;
function isLiteralKind(kind) {
return 8 /* FirstLiteralToken */ <= kind && kind <= 11 /* LastLiteralToken */;
}
ts.isLiteralKind = isLiteralKind;
function isTextualLiteralKind(kind) {
return kind === 9 /* StringLiteral */ || kind === 11 /* NoSubstitutionTemplateLiteral */;
}
ts.isTextualLiteralKind = isTextualLiteralKind;
function isTemplateLiteralKind(kind) {
return 11 /* FirstTemplateToken */ <= kind && kind <= 14 /* LastTemplateToken */;
}
ts.isTemplateLiteralKind = isTemplateLiteralKind;
function isBindingPattern(node) {
return !!node && (node.kind === 160 /* ArrayBindingPattern */ || node.kind === 159 /* ObjectBindingPattern */);
}
ts.isBindingPattern = isBindingPattern;
function isInAmbientContext(node) {
while (node) {
if (node.flags & (2 /* Ambient */ | 8192 /* DeclarationFile */)) {
return true;
}
node = node.parent;
}
return false;
}
ts.isInAmbientContext = isInAmbientContext;
function isDeclaration(node) {
switch (node.kind) {
case 172 /* ArrowFunction */:
case 161 /* BindingElement */:
case 212 /* ClassDeclaration */:
case 184 /* ClassExpression */:
case 142 /* Constructor */:
case 215 /* EnumDeclaration */:
case 245 /* EnumMember */:
case 228 /* ExportSpecifier */:
case 211 /* FunctionDeclaration */:
case 171 /* FunctionExpression */:
case 143 /* GetAccessor */:
case 221 /* ImportClause */:
case 219 /* ImportEqualsDeclaration */:
case 224 /* ImportSpecifier */:
case 213 /* InterfaceDeclaration */:
case 141 /* MethodDeclaration */:
case 140 /* MethodSignature */:
case 216 /* ModuleDeclaration */:
case 222 /* NamespaceImport */:
case 136 /* Parameter */:
case 243 /* PropertyAssignment */:
case 139 /* PropertyDeclaration */:
case 138 /* PropertySignature */:
case 144 /* SetAccessor */:
case 244 /* ShorthandPropertyAssignment */:
case 214 /* TypeAliasDeclaration */:
case 135 /* TypeParameter */:
case 209 /* VariableDeclaration */:
return true;
}
return false;
}
ts.isDeclaration = isDeclaration;
function isStatement(n) {
switch (n.kind) {
case 201 /* BreakStatement */:
case 200 /* ContinueStatement */:
case 208 /* DebuggerStatement */:
case 195 /* DoStatement */:
case 193 /* ExpressionStatement */:
case 192 /* EmptyStatement */:
case 198 /* ForInStatement */:
case 199 /* ForOfStatement */:
case 197 /* ForStatement */:
case 194 /* IfStatement */:
case 205 /* LabeledStatement */:
case 202 /* ReturnStatement */:
case 204 /* SwitchStatement */:
case 96 /* ThrowKeyword */:
case 207 /* TryStatement */:
case 191 /* VariableStatement */:
case 196 /* WhileStatement */:
case 203 /* WithStatement */:
case 225 /* ExportAssignment */:
return true;
default:
return false;
}
}
ts.isStatement = isStatement;
function isClassElement(n) {
switch (n.kind) {
case 142 /* Constructor */:
case 139 /* PropertyDeclaration */:
case 141 /* MethodDeclaration */:
case 143 /* GetAccessor */:
case 144 /* SetAccessor */:
case 140 /* MethodSignature */:
case 147 /* IndexSignature */:
return true;
default:
return false;
}
}
ts.isClassElement = isClassElement;
// True if the given identifier, string literal, or number literal is the name of a declaration node
function isDeclarationName(name) {
if (name.kind !== 67 /* Identifier */ && name.kind !== 9 /* StringLiteral */ && name.kind !== 8 /* NumericLiteral */) {
return false;
}
var parent = name.parent;
if (parent.kind === 224 /* ImportSpecifier */ || parent.kind === 228 /* ExportSpecifier */) {
if (parent.propertyName) {
return true;
}
}
if (isDeclaration(parent)) {
return parent.name === name;
}
return false;
}
ts.isDeclarationName = isDeclarationName;
// Return true if the given identifier is classified as an IdentifierName
function isIdentifierName(node) {
var parent = node.parent;
switch (parent.kind) {
case 139 /* PropertyDeclaration */:
case 138 /* PropertySignature */:
case 141 /* MethodDeclaration */:
case 140 /* MethodSignature */:
case 143 /* GetAccessor */:
case 144 /* SetAccessor */:
case 245 /* EnumMember */:
case 243 /* PropertyAssignment */:
case 164 /* PropertyAccessExpression */:
// Name in member declaration or property name in property access
return parent.name === node;
case 133 /* QualifiedName */:
// Name on right hand side of dot in a type query
if (parent.right === node) {
while (parent.kind === 133 /* QualifiedName */) {
parent = parent.parent;
}
return parent.kind === 152 /* TypeQuery */;
}
return false;
case 161 /* BindingElement */:
case 224 /* ImportSpecifier */:
// Property name in binding element or import specifier
return parent.propertyName === node;
case 228 /* ExportSpecifier */:
// Any name in an export specifier
return true;
}
return false;
}
ts.isIdentifierName = isIdentifierName;
// An alias symbol is created by one of the following declarations:
// import <symbol> = ...
// import <symbol> from ...
// import * as <symbol> from ...
// import { x as <symbol> } from ...
// export { x as <symbol> } from ...
// export = ...
// export default ...
function isAliasSymbolDeclaration(node) {
return node.kind === 219 /* ImportEqualsDeclaration */ ||
node.kind === 221 /* ImportClause */ && !!node.name ||
node.kind === 222 /* NamespaceImport */ ||
node.kind === 224 /* ImportSpecifier */ ||
node.kind === 228 /* ExportSpecifier */ ||
node.kind === 225 /* ExportAssignment */ && node.expression.kind === 67 /* Identifier */;
}
ts.isAliasSymbolDeclaration = isAliasSymbolDeclaration;
function getClassExtendsHeritageClauseElement(node) {
var heritageClause = getHeritageClause(node.heritageClauses, 81 /* ExtendsKeyword */);
return heritageClause && heritageClause.types.length > 0 ? heritageClause.types[0] : undefined;
}
ts.getClassExtendsHeritageClauseElement = getClassExtendsHeritageClauseElement;
function getClassImplementsHeritageClauseElements(node) {
var heritageClause = getHeritageClause(node.heritageClauses, 104 /* ImplementsKeyword */);
return heritageClause ? heritageClause.types : undefined;
}
ts.getClassImplementsHeritageClauseElements = getClassImplementsHeritageClauseElements;
function getInterfaceBaseTypeNodes(node) {
var heritageClause = getHeritageClause(node.heritageClauses, 81 /* ExtendsKeyword */);
return heritageClause ? heritageClause.types : undefined;
}
ts.getInterfaceBaseTypeNodes = getInterfaceBaseTypeNodes;
function getHeritageClause(clauses, kind) {
if (clauses) {
for (var _i = 0; _i < clauses.length; _i++) {
var clause = clauses[_i];
if (clause.token === kind) {
return clause;
}
}
}
return undefined;
}
ts.getHeritageClause = getHeritageClause;
function tryResolveScriptReference(host, sourceFile, reference) {
if (!host.getCompilerOptions().noResolve) {
var referenceFileName = ts.isRootedDiskPath(reference.fileName) ? reference.fileName : ts.combinePaths(ts.getDirectoryPath(sourceFile.fileName), reference.fileName);
referenceFileName = ts.getNormalizedAbsolutePath(referenceFileName, host.getCurrentDirectory());
return host.getSourceFile(referenceFileName);
}
}
ts.tryResolveScriptReference = tryResolveScriptReference;
function getAncestor(node, kind) {
while (node) {
if (node.kind === kind) {
return node;
}
node = node.parent;
}
return undefined;
}
ts.getAncestor = getAncestor;
function getFileReferenceFromReferencePath(comment, commentRange) {
var simpleReferenceRegEx = /^\/\/\/\s*<reference\s+/gim;
var isNoDefaultLibRegEx = /^(\/\/\/\s*<reference\s+no-default-lib\s*=\s*)('|")(.+?)\2\s*\/>/gim;
if (simpleReferenceRegEx.exec(comment)) {
if (isNoDefaultLibRegEx.exec(comment)) {
return {
isNoDefaultLib: true
};
}
else {
var matchResult = ts.fullTripleSlashReferencePathRegEx.exec(comment);
if (matchResult) {
var start = commentRange.pos;
var end = commentRange.end;
return {
fileReference: {
pos: start,
end: end,
fileName: matchResult[3]
},
isNoDefaultLib: false
};
}
else {
return {
diagnosticMessage: ts.Diagnostics.Invalid_reference_directive_syntax,
isNoDefaultLib: false
};
}
}
}
return undefined;
}
ts.getFileReferenceFromReferencePath = getFileReferenceFromReferencePath;
function isKeyword(token) {
return 68 /* FirstKeyword */ <= token && token <= 132 /* LastKeyword */;
}
ts.isKeyword = isKeyword;
function isTrivia(token) {
return 2 /* FirstTriviaToken */ <= token && token <= 7 /* LastTriviaToken */;
}
ts.isTrivia = isTrivia;
function isAsyncFunctionLike(node) {
return isFunctionLike(node) && (node.flags & 512 /* Async */) !== 0 && !isAccessor(node);
}
ts.isAsyncFunctionLike = isAsyncFunctionLike;
/**
* A declaration has a dynamic name if both of the following are true:
* 1. The declaration has a computed property name
* 2. The computed name is *not* expressed as Symbol.<name>, where name
* is a property of the Symbol constructor that denotes a built in
* Symbol.
*/
function hasDynamicName(declaration) {
return declaration.name &&
declaration.name.kind === 134 /* ComputedPropertyName */ &&
!isWellKnownSymbolSyntactically(declaration.name.expression);
}
ts.hasDynamicName = hasDynamicName;
/**
* Checks if the expression is of the form:
* Symbol.name
* where Symbol is literally the word "Symbol", and name is any identifierName
*/
function isWellKnownSymbolSyntactically(node) {
return node.kind === 164 /* PropertyAccessExpression */ && isESSymbolIdentifier(node.expression);
}
ts.isWellKnownSymbolSyntactically = isWellKnownSymbolSyntactically;
function getPropertyNameForPropertyNameNode(name) {
if (name.kind === 67 /* Identifier */ || name.kind === 9 /* StringLiteral */ || name.kind === 8 /* NumericLiteral */) {
return name.text;
}
if (name.kind === 134 /* ComputedPropertyName */) {
var nameExpression = name.expression;
if (isWellKnownSymbolSyntactically(nameExpression)) {
var rightHandSideName = nameExpression.name.text;
return getPropertyNameForKnownSymbolName(rightHandSideName);
}
}
return undefined;
}
ts.getPropertyNameForPropertyNameNode = getPropertyNameForPropertyNameNode;
function getPropertyNameForKnownSymbolName(symbolName) {
return "__@" + symbolName;
}
ts.getPropertyNameForKnownSymbolName = getPropertyNameForKnownSymbolName;
/**
* Includes the word "Symbol" with unicode escapes
*/
function isESSymbolIdentifier(node) {
return node.kind === 67 /* Identifier */ && node.text === "Symbol";
}
ts.isESSymbolIdentifier = isESSymbolIdentifier;
function isModifier(token) {
switch (token) {
case 113 /* AbstractKeyword */:
case 116 /* AsyncKeyword */:
case 72 /* ConstKeyword */:
case 120 /* DeclareKeyword */:
case 75 /* DefaultKeyword */:
case 80 /* ExportKeyword */:
case 110 /* PublicKeyword */:
case 108 /* PrivateKeyword */:
case 109 /* ProtectedKeyword */:
case 111 /* StaticKeyword */:
return true;
}
return false;
}
ts.isModifier = isModifier;
function isParameterDeclaration(node) {
var root = getRootDeclaration(node);
return root.kind === 136 /* Parameter */;
}
ts.isParameterDeclaration = isParameterDeclaration;
function getRootDeclaration(node) {
while (node.kind === 161 /* BindingElement */) {
node = node.parent.parent;
}
return node;
}
ts.getRootDeclaration = getRootDeclaration;
function nodeStartsNewLexicalEnvironment(n) {
return isFunctionLike(n) || n.kind === 216 /* ModuleDeclaration */ || n.kind === 246 /* SourceFile */;
}
ts.nodeStartsNewLexicalEnvironment = nodeStartsNewLexicalEnvironment;
function cloneEntityName(node) {
if (node.kind === 67 /* Identifier */) {
var clone_1 = createSynthesizedNode(67 /* Identifier */);
clone_1.text = node.text;
return clone_1;
}
else {
var clone_2 = createSynthesizedNode(133 /* QualifiedName */);
clone_2.left = cloneEntityName(node.left);
clone_2.left.parent = clone_2;
clone_2.right = cloneEntityName(node.right);
clone_2.right.parent = clone_2;
return clone_2;
}
}
ts.cloneEntityName = cloneEntityName;
function nodeIsSynthesized(node) {
return node.pos === -1;
}
ts.nodeIsSynthesized = nodeIsSynthesized;
function createSynthesizedNode(kind, startsOnNewLine) {
var node = ts.createNode(kind);
node.startsOnNewLine = startsOnNewLine;
return node;
}
ts.createSynthesizedNode = createSynthesizedNode;
function createSynthesizedNodeArray() {
var array = [];
array.pos = -1;
array.end = -1;
return array;
}
ts.createSynthesizedNodeArray = createSynthesizedNodeArray;
function createDiagnosticCollection() {
var nonFileDiagnostics = [];
var fileDiagnostics = {};
var diagnosticsModified = false;
var modificationCount = 0;
return {
add: add,
getGlobalDiagnostics: getGlobalDiagnostics,
getDiagnostics: getDiagnostics,
getModificationCount: getModificationCount
};
function getModificationCount() {
return modificationCount;
}
function add(diagnostic) {
var diagnostics;
if (diagnostic.file) {
diagnostics = fileDiagnostics[diagnostic.file.fileName];
if (!diagnostics) {
diagnostics = [];
fileDiagnostics[diagnostic.file.fileName] = diagnostics;
}
}
else {
diagnostics = nonFileDiagnostics;
}
diagnostics.push(diagnostic);
diagnosticsModified = true;
modificationCount++;
}
function getGlobalDiagnostics() {
sortAndDeduplicate();
return nonFileDiagnostics;
}
function getDiagnostics(fileName) {
sortAndDeduplicate();
if (fileName) {
return fileDiagnostics[fileName] || [];
}
var allDiagnostics = [];
function pushDiagnostic(d) {
allDiagnostics.push(d);
}
ts.forEach(nonFileDiagnostics, pushDiagnostic);
for (var key in fileDiagnostics) {
if (ts.hasProperty(fileDiagnostics, key)) {
ts.forEach(fileDiagnostics[key], pushDiagnostic);
}
}
return ts.sortAndDeduplicateDiagnostics(allDiagnostics);
}
function sortAndDeduplicate() {
if (!diagnosticsModified) {
return;
}
diagnosticsModified = false;
nonFileDiagnostics = ts.sortAndDeduplicateDiagnostics(nonFileDiagnostics);
for (var key in fileDiagnostics) {
if (ts.hasProperty(fileDiagnostics, key)) {
fileDiagnostics[key] = ts.sortAndDeduplicateDiagnostics(fileDiagnostics[key]);
}
}
}
}
ts.createDiagnosticCollection = createDiagnosticCollection;
// This consists of the first 19 unprintable ASCII characters, canonical escapes, lineSeparator,
// paragraphSeparator, and nextLine. The latter three are just desirable to suppress new lines in
// the language service. These characters should be escaped when printing, and if any characters are added,
// the map below must be updated. Note that this regexp *does not* include the 'delete' character.
// There is no reason for this other than that JSON.stringify does not handle it either.
var escapedCharsRegExp = /[\\\"\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
var escapedCharsMap = {
"\0": "\\0",
"\t": "\\t",
"\v": "\\v",
"\f": "\\f",
"\b": "\\b",
"\r": "\\r",
"\n": "\\n",
"\\": "\\\\",
"\"": "\\\"",
"\u2028": "\\u2028",
"\u2029": "\\u2029",
"\u0085": "\\u0085" // nextLine
};
/**
* Based heavily on the abstract 'Quote'/'QuoteJSONString' operation from ECMA-262 (24.3.2.2),
* but augmented for a few select characters (e.g. lineSeparator, paragraphSeparator, nextLine)
* Note that this doesn't actually wrap the input in double quotes.
*/
function escapeString(s) {
s = escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, getReplacement) : s;
return s;
function getReplacement(c) {
return escapedCharsMap[c] || get16BitUnicodeEscapeSequence(c.charCodeAt(0));
}
}
ts.escapeString = escapeString;
function isIntrinsicJsxName(name) {
var ch = name.substr(0, 1);
return ch.toLowerCase() === ch;
}
ts.isIntrinsicJsxName = isIntrinsicJsxName;
function get16BitUnicodeEscapeSequence(charCode) {
var hexCharCode = charCode.toString(16).toUpperCase();
var paddedHexCode = ("0000" + hexCharCode).slice(-4);
return "\\u" + paddedHexCode;
}
var nonAsciiCharacters = /[^\u0000-\u007F]/g;
function escapeNonAsciiCharacters(s) {
// Replace non-ASCII characters with '\uNNNN' escapes if any exist.
// Otherwise just return the original string.
return nonAsciiCharacters.test(s) ?
s.replace(nonAsciiCharacters, function (c) { return get16BitUnicodeEscapeSequence(c.charCodeAt(0)); }) :
s;
}
ts.escapeNonAsciiCharacters = escapeNonAsciiCharacters;
var indentStrings = ["", " "];
function getIndentString(level) {
if (indentStrings[level] === undefined) {
indentStrings[level] = getIndentString(level - 1) + indentStrings[1];
}
return indentStrings[level];
}
ts.getIndentString = getIndentString;
function getIndentSize() {
return indentStrings[1].length;
}
ts.getIndentSize = getIndentSize;
function createTextWriter(newLine) {
var output = "";
var indent = 0;
var lineStart = true;
var lineCount = 0;
var linePos = 0;
function write(s) {
if (s && s.length) {
if (lineStart) {
output += getIndentString(indent);
lineStart = false;
}
output += s;
}
}
function rawWrite(s) {
if (s !== undefined) {
if (lineStart) {
lineStart = false;
}
output += s;
}
}
function writeLiteral(s) {
if (s && s.length) {
write(s);
var lineStartsOfS = ts.computeLineStarts(s);
if (lineStartsOfS.length > 1) {
lineCount = lineCount + lineStartsOfS.length - 1;
linePos = output.length - s.length + ts.lastOrUndefined(lineStartsOfS);
}
}
}
function writeLine() {
if (!lineStart) {
output += newLine;
lineCount++;
linePos = output.length;
lineStart = true;
}
}
function writeTextOfNode(sourceFile, node) {
write(getSourceTextOfNodeFromSourceFile(sourceFile, node));
}
return {
write: write,
rawWrite: rawWrite,
writeTextOfNode: writeTextOfNode,
writeLiteral: writeLiteral,
writeLine: writeLine,
increaseIndent: function () { return indent++; },
decreaseIndent: function () { return indent--; },
getIndent: function () { return indent; },
getTextPos: function () { return output.length; },
getLine: function () { return lineCount + 1; },
getColumn: function () { return lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1; },
getText: function () { return output; }
};
}
ts.createTextWriter = createTextWriter;
function getOwnEmitOutputFilePath(sourceFile, host, extension) {
var compilerOptions = host.getCompilerOptions();
var emitOutputFilePathWithoutExtension;
if (compilerOptions.outDir) {
emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir));
}
else {
emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.fileName);
}
return emitOutputFilePathWithoutExtension + extension;
}
ts.getOwnEmitOutputFilePath = getOwnEmitOutputFilePath;
function getSourceFilePathInNewDir(sourceFile, host, newDirPath) {
var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory());
sourceFilePath = sourceFilePath.replace(host.getCommonSourceDirectory(), "");
return ts.combinePaths(newDirPath, sourceFilePath);
}
ts.getSourceFilePathInNewDir = getSourceFilePathInNewDir;
function writeFile(host, diagnostics, fileName, data, writeByteOrderMark) {
host.writeFile(fileName, data, writeByteOrderMark, function (hostErrorMessage) {
diagnostics.push(ts.createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage));
});
}
ts.writeFile = writeFile;
function getLineOfLocalPosition(currentSourceFile, pos) {
return ts.getLineAndCharacterOfPosition(currentSourceFile, pos).line;
}
ts.getLineOfLocalPosition = getLineOfLocalPosition;
function getFirstConstructorWithBody(node) {
return ts.forEach(node.members, function (member) {
if (member.kind === 142 /* Constructor */ && nodeIsPresent(member.body)) {
return member;
}
});
}
ts.getFirstConstructorWithBody = getFirstConstructorWithBody;
function getSetAccessorTypeAnnotationNode(accessor) {
return accessor && accessor.parameters.length > 0 && accessor.parameters[0].type;
}
ts.getSetAccessorTypeAnnotationNode = getSetAccessorTypeAnnotationNode;
function shouldEmitToOwnFile(sourceFile, compilerOptions) {
if (!isDeclarationFile(sourceFile)) {
if ((isExternalModule(sourceFile) || !(compilerOptions.outFile || compilerOptions.out))) {
// 1. in-browser single file compilation scenario
// 2. non .js file
return compilerOptions.isolatedModules || !ts.fileExtensionIs(sourceFile.fileName, ".js");
}
return false;
}
return false;
}
ts.shouldEmitToOwnFile = shouldEmitToOwnFile;
function getAllAccessorDeclarations(declarations, accessor) {
var firstAccessor;
var secondAccessor;
var getAccessor;
var setAccessor;
if (hasDynamicName(accessor)) {
firstAccessor = accessor;
if (accessor.kind === 143 /* GetAccessor */) {
getAccessor = accessor;
}
else if (accessor.kind === 144 /* SetAccessor */) {
setAccessor = accessor;
}
else {
ts.Debug.fail("Accessor has wrong kind");
}
}
else {
ts.forEach(declarations, function (member) {
if ((member.kind === 143 /* GetAccessor */ || member.kind === 144 /* SetAccessor */)
&& (member.flags & 128 /* Static */) === (accessor.flags & 128 /* Static */)) {
var memberName = getPropertyNameForPropertyNameNode(member.name);
var accessorName = getPropertyNameForPropertyNameNode(accessor.name);
if (memberName === accessorName) {
if (!firstAccessor) {
firstAccessor = member;
}
else if (!secondAccessor) {
secondAccessor = member;
}
if (member.kind === 143 /* GetAccessor */ && !getAccessor) {
getAccessor = member;
}
if (member.kind === 144 /* SetAccessor */ && !setAccessor) {
setAccessor = member;
}
}
}
});
}
return {
firstAccessor: firstAccessor,
secondAccessor: secondAccessor,
getAccessor: getAccessor,
setAccessor: setAccessor
};
}
ts.getAllAccessorDeclarations = getAllAccessorDeclarations;
function emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments) {
// If the leading comments start on different line than the start of node, write new line
if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos &&
getLineOfLocalPosition(currentSourceFile, node.pos) !== getLineOfLocalPosition(currentSourceFile, leadingComments[0].pos)) {
writer.writeLine();
}
}
ts.emitNewLineBeforeLeadingComments = emitNewLineBeforeLeadingComments;
function emitComments(currentSourceFile, writer, comments, trailingSeparator, newLine, writeComment) {
var emitLeadingSpace = !trailingSeparator;
ts.forEach(comments, function (comment) {
if (emitLeadingSpace) {
writer.write(" ");
emitLeadingSpace = false;
}
writeComment(currentSourceFile, writer, comment, newLine);
if (comment.hasTrailingNewLine) {
writer.writeLine();
}
else if (trailingSeparator) {
writer.write(" ");
}
else {
// Emit leading space to separate comment during next comment emit
emitLeadingSpace = true;
}
});
}
ts.emitComments = emitComments;
function writeCommentRange(currentSourceFile, writer, comment, newLine) {
if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */) {
var firstCommentLineAndCharacter = ts.getLineAndCharacterOfPosition(currentSourceFile, comment.pos);
var lineCount = ts.getLineStarts(currentSourceFile).length;
var firstCommentLineIndent;
for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) {
var nextLineStart = (currentLine + 1) === lineCount
? currentSourceFile.text.length + 1
: getStartPositionOfLine(currentLine + 1, currentSourceFile);
if (pos !== comment.pos) {
// If we are not emitting first line, we need to write the spaces to adjust the alignment
if (firstCommentLineIndent === undefined) {
firstCommentLineIndent = calculateIndent(getStartPositionOfLine(firstCommentLineAndCharacter.line, currentSourceFile), comment.pos);
}
// These are number of spaces writer is going to write at current indent
var currentWriterIndentSpacing = writer.getIndent() * getIndentSize();
// Number of spaces we want to be writing
// eg: Assume writer indent
// module m {
// /* starts at character 9 this is line 1
// * starts at character pos 4 line --1 = 8 - 8 + 3
// More left indented comment */ --2 = 8 - 8 + 2
// class c { }
// }
// module m {
// /* this is line 1 -- Assume current writer indent 8
// * line --3 = 8 - 4 + 5
// More right indented comment */ --4 = 8 - 4 + 11
// class c { }
// }
var spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart);
if (spacesToEmit > 0) {
var numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize();
var indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize());
// Write indent size string ( in eg 1: = "", 2: "" , 3: string with 8 spaces 4: string with 12 spaces
writer.rawWrite(indentSizeSpaceString);
// Emit the single spaces (in eg: 1: 3 spaces, 2: 2 spaces, 3: 1 space, 4: 3 spaces)
while (numberOfSingleSpacesToEmit) {
writer.rawWrite(" ");
numberOfSingleSpacesToEmit--;
}
}
else {
// No spaces to emit write empty string
writer.rawWrite("");
}
}
// Write the comment line text
writeTrimmedCurrentLine(pos, nextLineStart);
pos = nextLineStart;
}
}
else {
// Single line comment of style //....
writer.write(currentSourceFile.text.substring(comment.pos, comment.end));
}
function writeTrimmedCurrentLine(pos, nextLineStart) {
var end = Math.min(comment.end, nextLineStart - 1);
var currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, "");
if (currentLineText) {
// trimmed forward and ending spaces text
writer.write(currentLineText);
if (end !== comment.end) {
writer.writeLine();
}
}
else {
// Empty string - make sure we write empty line
writer.writeLiteral(newLine);
}
}
function calculateIndent(pos, end) {
var currentLineIndent = 0;
for (; pos < end && ts.isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) {
if (currentSourceFile.text.charCodeAt(pos) === 9 /* tab */) {
// Tabs = TabSize = indent size and go to next tabStop
currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize());
}
else {
// Single space
currentLineIndent++;
}
}
return currentLineIndent;
}
}
ts.writeCommentRange = writeCommentRange;
function modifierToFlag(token) {
switch (token) {
case 111 /* StaticKeyword */: return 128 /* Static */;
case 110 /* PublicKeyword */: return 16 /* Public */;
case 109 /* ProtectedKeyword */: return 64 /* Protected */;
case 108 /* PrivateKeyword */: return 32 /* Private */;
case 113 /* AbstractKeyword */: return 256 /* Abstract */;
case 80 /* ExportKeyword */: return 1 /* Export */;
case 120 /* DeclareKeyword */: return 2 /* Ambient */;
case 72 /* ConstKeyword */: return 32768 /* Const */;
case 75 /* DefaultKeyword */: return 1024 /* Default */;
case 116 /* AsyncKeyword */: return 512 /* Async */;
}
return 0;
}
ts.modifierToFlag = modifierToFlag;
function isLeftHandSideExpression(expr) {
if (expr) {
switch (expr.kind) {
case 164 /* PropertyAccessExpression */:
case 165 /* ElementAccessExpression */:
case 167 /* NewExpression */:
case 166 /* CallExpression */:
case 231 /* JsxElement */:
case 232 /* JsxSelfClosingElement */:
case 168 /* TaggedTemplateExpression */:
case 162 /* ArrayLiteralExpression */:
case 170 /* ParenthesizedExpression */:
case 163 /* ObjectLiteralExpression */:
case 184 /* ClassExpression */:
case 171 /* FunctionExpression */:
case 67 /* Identifier */:
case 10 /* RegularExpressionLiteral */:
case 8 /* NumericLiteral */:
case 9 /* StringLiteral */:
case 11 /* NoSubstitutionTemplateLiteral */:
case 181 /* TemplateExpression */:
case 82 /* FalseKeyword */:
case 91 /* NullKeyword */:
case 95 /* ThisKeyword */:
case 97 /* TrueKeyword */:
case 93 /* SuperKeyword */:
return true;
}
}
return false;
}
ts.isLeftHandSideExpression = isLeftHandSideExpression;
function isAssignmentOperator(token) {
return token >= 55 /* FirstAssignment */ && token <= 66 /* LastAssignment */;
}
ts.isAssignmentOperator = isAssignmentOperator;
function isExpressionWithTypeArgumentsInClassExtendsClause(node) {
return node.kind === 186 /* ExpressionWithTypeArguments */ &&
node.parent.token === 81 /* ExtendsKeyword */ &&
isClassLike(node.parent.parent);
}
ts.isExpressionWithTypeArgumentsInClassExtendsClause = isExpressionWithTypeArgumentsInClassExtendsClause;
// Returns false if this heritage clause element's expression contains something unsupported
// (i.e. not a name or dotted name).
function isSupportedExpressionWithTypeArguments(node) {
return isSupportedExpressionWithTypeArgumentsRest(node.expression);
}
ts.isSupportedExpressionWithTypeArguments = isSupportedExpressionWithTypeArguments;
function isSupportedExpressionWithTypeArgumentsRest(node) {
if (node.kind === 67 /* Identifier */) {
return true;
}
else if (node.kind === 164 /* PropertyAccessExpression */) {
return isSupportedExpressionWithTypeArgumentsRest(node.expression);
}
else {
return false;
}
}
function isRightSideOfQualifiedNameOrPropertyAccess(node) {
return (node.parent.kind === 133 /* QualifiedName */ && node.parent.right === node) ||
(node.parent.kind === 164 /* PropertyAccessExpression */ && node.parent.name === node);
}
ts.isRightSideOfQualifiedNameOrPropertyAccess = isRightSideOfQualifiedNameOrPropertyAccess;
function isEmptyObjectLiteralOrArrayLiteral(expression) {
var kind = expression.kind;
if (kind === 163 /* ObjectLiteralExpression */) {
return expression.properties.length === 0;
}
if (kind === 162 /* ArrayLiteralExpression */) {
return expression.elements.length === 0;
}
return false;
}
ts.isEmptyObjectLiteralOrArrayLiteral = isEmptyObjectLiteralOrArrayLiteral;
function getLocalSymbolForExportDefault(symbol) {
return symbol && symbol.valueDeclaration && (symbol.valueDeclaration.flags & 1024 /* Default */) ? symbol.valueDeclaration.localSymbol : undefined;
}
ts.getLocalSymbolForExportDefault = getLocalSymbolForExportDefault;
function isJavaScript(fileName) {
return ts.fileExtensionIs(fileName, ".js");
}
ts.isJavaScript = isJavaScript;
function isTsx(fileName) {
return ts.fileExtensionIs(fileName, ".tsx");
}
ts.isTsx = isTsx;
/**
* Replace each instance of non-ascii characters by one, two, three, or four escape sequences
* representing the UTF-8 encoding of the character, and return the expanded char code list.
*/
function getExpandedCharCodes(input) {
var output = [];
var length = input.length;
for (var i = 0; i < length; i++) {
var charCode = input.charCodeAt(i);
// handel utf8
if (charCode < 0x80) {
output.push(charCode);
}
else if (charCode < 0x800) {
output.push((charCode >> 6) | 192);
output.push((charCode & 63) | 128);
}
else if (charCode < 0x10000) {
output.push((charCode >> 12) | 224);
output.push(((charCode >> 6) & 63) | 128);
output.push((charCode & 63) | 128);
}
else if (charCode < 0x20000) {
output.push((charCode >> 18) | 240);
output.push(((charCode >> 12) & 63) | 128);
output.push(((charCode >> 6) & 63) | 128);
output.push((charCode & 63) | 128);
}
else {
ts.Debug.assert(false, "Unexpected code point");
}
}
return output;
}
var base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
/**
* Converts a string to a base-64 encoded ASCII string.
*/
function convertToBase64(input) {
var result = "";
var charCodes = getExpandedCharCodes(input);
var i = 0;
var length = charCodes.length;
var byte1, byte2, byte3, byte4;
while (i < length) {
// Convert every 6-bits in the input 3 character points
// into a base64 digit
byte1 = charCodes[i] >> 2;
byte2 = (charCodes[i] & 3) << 4 | charCodes[i + 1] >> 4;
byte3 = (charCodes[i + 1] & 15) << 2 | charCodes[i + 2] >> 6;
byte4 = charCodes[i + 2] & 63;
// We are out of characters in the input, set the extra
// digits to 64 (padding character).
if (i + 1 >= length) {
byte3 = byte4 = 64;
}
else if (i + 2 >= length) {
byte4 = 64;
}
// Write to the ouput
result += base64Digits.charAt(byte1) + base64Digits.charAt(byte2) + base64Digits.charAt(byte3) + base64Digits.charAt(byte4);
i += 3;
}
return result;
}
ts.convertToBase64 = convertToBase64;
var carriageReturnLineFeed = "\r\n";
var lineFeed = "\n";
function getNewLineCharacter(options) {
if (options.newLine === 0 /* CarriageReturnLineFeed */) {
return carriageReturnLineFeed;
}
else if (options.newLine === 1 /* LineFeed */) {
return lineFeed;
}
else if (ts.sys) {
return ts.sys.newLine;
}
return carriageReturnLineFeed;
}
ts.getNewLineCharacter = getNewLineCharacter;
})(ts || (ts = {}));
var ts;
(function (ts) {
function getDefaultLibFileName(options) {
return options.target === 2 /* ES6 */ ? "lib.es6.d.ts" : "lib.d.ts";
}
ts.getDefaultLibFileName = getDefaultLibFileName;
function textSpanEnd(span) {
return span.start + span.length;
}
ts.textSpanEnd = textSpanEnd;
function textSpanIsEmpty(span) {
return span.length === 0;
}
ts.textSpanIsEmpty = textSpanIsEmpty;
function textSpanContainsPosition(span, position) {
return position >= span.start && position < textSpanEnd(span);
}
ts.textSpanContainsPosition = textSpanContainsPosition;
// Returns true if 'span' contains 'other'.
function textSpanContainsTextSpan(span, other) {
return other.start >= span.start && textSpanEnd(other) <= textSpanEnd(span);
}
ts.textSpanContainsTextSpan = textSpanContainsTextSpan;
function textSpanOverlapsWith(span, other) {
var overlapStart = Math.max(span.start, other.start);
var overlapEnd = Math.min(textSpanEnd(span), textSpanEnd(other));
return overlapStart < overlapEnd;
}
ts.textSpanOverlapsWith = textSpanOverlapsWith;
function textSpanOverlap(span1, span2) {
var overlapStart = Math.max(span1.start, span2.start);
var overlapEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2));
if (overlapStart < overlapEnd) {
return createTextSpanFromBounds(overlapStart, overlapEnd);
}
return undefined;
}
ts.textSpanOverlap = textSpanOverlap;
function textSpanIntersectsWithTextSpan(span, other) {
return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start;
}
ts.textSpanIntersectsWithTextSpan = textSpanIntersectsWithTextSpan;
function textSpanIntersectsWith(span, start, length) {
var end = start + length;
return start <= textSpanEnd(span) && end >= span.start;
}
ts.textSpanIntersectsWith = textSpanIntersectsWith;
function decodedTextSpanIntersectsWith(start1, length1, start2, length2) {
var end1 = start1 + length1;
var end2 = start2 + length2;
return start2 <= end1 && end2 >= start1;
}
ts.decodedTextSpanIntersectsWith = decodedTextSpanIntersectsWith;
function textSpanIntersectsWithPosition(span, position) {
return position <= textSpanEnd(span) && position >= span.start;
}
ts.textSpanIntersectsWithPosition = textSpanIntersectsWithPosition;
function textSpanIntersection(span1, span2) {
var intersectStart = Math.max(span1.start, span2.start);
var intersectEnd = Math.min(textSpanEnd(span1), textSpanEnd(span2));
if (intersectStart <= intersectEnd) {
return createTextSpanFromBounds(intersectStart, intersectEnd);
}
return undefined;
}
ts.textSpanIntersection = textSpanIntersection;
function createTextSpan(start, length) {
if (start < 0) {
throw new Error("start < 0");
}
if (length < 0) {
throw new Error("length < 0");
}
return { start: start, length: length };
}
ts.createTextSpan = createTextSpan;
function createTextSpanFromBounds(start, end) {
return createTextSpan(start, end - start);
}
ts.createTextSpanFromBounds = createTextSpanFromBounds;
function textChangeRangeNewSpan(range) {
return createTextSpan(range.span.start, range.newLength);
}
ts.textChangeRangeNewSpan = textChangeRangeNewSpan;
function textChangeRangeIsUnchanged(range) {
return textSpanIsEmpty(range.span) && range.newLength === 0;
}
ts.textChangeRangeIsUnchanged = textChangeRangeIsUnchanged;
function createTextChangeRange(span, newLength) {
if (newLength < 0) {
throw new Error("newLength < 0");
}
return { span: span, newLength: newLength };
}
ts.createTextChangeRange = createTextChangeRange;
ts.unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0);
/**
* Called to merge all the changes that occurred across several versions of a script snapshot
* into a single change. i.e. if a user keeps making successive edits to a script we will
* have a text change from V1 to V2, V2 to V3, ..., Vn.
*
* This function will then merge those changes into a single change range valid between V1 and
* Vn.
*/
function collapseTextChangeRangesAcrossMultipleVersions(changes) {
if (changes.length === 0) {
return ts.unchangedTextChangeRange;
}
if (changes.length === 1) {
return changes[0];
}
// We change from talking about { { oldStart, oldLength }, newLength } to { oldStart, oldEnd, newEnd }
// as it makes things much easier to reason about.
var change0 = changes[0];
var oldStartN = change0.span.start;
var oldEndN = textSpanEnd(change0.span);
var newEndN = oldStartN + change0.newLength;
for (var i = 1; i < changes.length; i++) {
var nextChange = changes[i];
// Consider the following case:
// i.e. two edits. The first represents the text change range { { 10, 50 }, 30 }. i.e. The span starting
// at 10, with length 50 is reduced to length 30. The second represents the text change range { { 30, 30 }, 40 }.
// i.e. the span starting at 30 with length 30 is increased to length 40.
//
// 0 10 20 30 40 50 60 70 80 90 100
// -------------------------------------------------------------------------------------------------------
// | /
// | /----
// T1 | /----
// | /----
// | /----
// -------------------------------------------------------------------------------------------------------
// | \
// | \
// T2 | \
// | \
// | \
// -------------------------------------------------------------------------------------------------------
//
// Merging these turns out to not be too difficult. First, determining the new start of the change is trivial
// it's just the min of the old and new starts. i.e.:
//
// 0 10 20 30 40 50 60 70 80 90 100
// ------------------------------------------------------------*------------------------------------------
// | /
// | /----
// T1 | /----
// | /----
// | /----
// ----------------------------------------$-------------------$------------------------------------------
// . | \
// . | \
// T2 . | \
// . | \
// . | \
// ----------------------------------------------------------------------*--------------------------------
//
// (Note the dots represent the newly inferrred start.
// Determining the new and old end is also pretty simple. Basically it boils down to paying attention to the
// absolute positions at the asterixes, and the relative change between the dollar signs. Basically, we see
// which if the two $'s precedes the other, and we move that one forward until they line up. in this case that
// means:
//
// 0 10 20 30 40 50 60 70 80 90 100
// --------------------------------------------------------------------------------*----------------------
// | /
// | /----
// T1 | /----
// | /----
// | /----
// ------------------------------------------------------------$------------------------------------------
// . | \
// . | \
// T2 . | \
// . | \
// . | \
// ----------------------------------------------------------------------*--------------------------------
//
// In other words (in this case), we're recognizing that the second edit happened after where the first edit
// ended with a delta of 20 characters (60 - 40). Thus, if we go back in time to where the first edit started
// that's the same as if we started at char 80 instead of 60.
//
// As it so happens, the same logic applies if the second edit precedes the first edit. In that case rahter
// than pusing the first edit forward to match the second, we'll push the second edit forward to match the
// first.
//
// In this case that means we have { oldStart: 10, oldEnd: 80, newEnd: 70 } or, in TextChangeRange
// semantics: { { start: 10, length: 70 }, newLength: 60 }
//
// The math then works out as follows.
// If we have { oldStart1, oldEnd1, newEnd1 } and { oldStart2, oldEnd2, newEnd2 } then we can compute the
// final result like so:
//
// {
// oldStart3: Min(oldStart1, oldStart2),
// oldEnd3 : Max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1)),
// newEnd3 : Max(newEnd2, newEnd2 + (newEnd1 - oldEnd2))
// }
var oldStart1 = oldStartN;
var oldEnd1 = oldEndN;
var newEnd1 = newEndN;
var oldStart2 = nextChange.span.start;
var oldEnd2 = textSpanEnd(nextChange.span);
var newEnd2 = oldStart2 + nextChange.newLength;
oldStartN = Math.min(oldStart1, oldStart2);
oldEndN = Math.max(oldEnd1, oldEnd1 + (oldEnd2 - newEnd1));
newEndN = Math.max(newEnd2, newEnd2 + (newEnd1 - oldEnd2));
}
return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), /*newLength:*/ newEndN - oldStartN);
}
ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions;
function getTypeParameterOwner(d) {
if (d && d.kind === 135 /* TypeParameter */) {
for (var current = d; current; current = current.parent) {
if (ts.isFunctionLike(current) || ts.isClassLike(current) || current.kind === 213 /* InterfaceDeclaration */) {
return current;
}
}
}
}
ts.getTypeParameterOwner = getTypeParameterOwner;
})(ts || (ts = {}));
/// <reference path="scanner.ts"/>
/// <reference path="utilities.ts"/>
var ts;
(function (ts) {
var nodeConstructors = new Array(270 /* Count */);
/* @internal */ ts.parseTime = 0;
function getNodeConstructor(kind) {
return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind));
}
ts.getNodeConstructor = getNodeConstructor;
function createNode(kind) {
return new (getNodeConstructor(kind))();
}
ts.createNode = createNode;
function visitNode(cbNode, node) {
if (node) {
return cbNode(node);
}
}
function visitNodeArray(cbNodes, nodes) {
if (nodes) {
return cbNodes(nodes);
}
}
function visitEachNode(cbNode, nodes) {
if (nodes) {
for (var _i = 0; _i < nodes.length; _i++) {
var node = nodes[_i];
var result = cbNode(node);
if (result) {
return result;
}
}
}
}
// Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes
// stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise,
// embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns
// a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned.
function forEachChild(node, cbNode, cbNodeArray) {
if (!node) {
return;
}
// The visitXXX functions could be written as local functions that close over the cbNode and cbNodeArray
// callback parameters, but that causes a closure allocation for each invocation with noticeable effects
// on performance.
var visitNodes = cbNodeArray ? visitNodeArray : visitEachNode;
var cbNodes = cbNodeArray || cbNode;
switch (node.kind) {
case 133 /* QualifiedName */:
return visitNode(cbNode, node.left) ||
visitNode(cbNode, node.right);
case 135 /* TypeParameter */:
return visitNode(cbNode, node.name) ||
visitNode(cbNode, node.constraint) ||
visitNode(cbNode, node.expression);
case 136 /* Parameter */:
case 139 /* PropertyDeclaration */:
case 138 /* PropertySignature */:
case 243 /* PropertyAssignment */:
case 244 /* ShorthandPropertyAssignment */:
case 209 /* VariableDeclaration */:
case 161 /* 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 150 /* FunctionType */:
case 151 /* ConstructorType */:
case 145 /* CallSignature */:
case 146 /* ConstructSignature */:
case 147 /* IndexSignature */:
return visitNodes(cbNodes, node.decorators) ||
visitNodes(cbNodes, node.modifiers) ||
visitNodes(cbNodes, node.typeParameters) ||
visitNodes(cbNodes, node.parameters) ||
visitNode(cbNode, node.type);
case 141 /* MethodDeclaration */:
case 140 /* MethodSignature */:
case 142 /* Constructor */:
case 143 /* GetAccessor */:
case 144 /* SetAccessor */:
case 171 /* FunctionExpression */:
case 211 /* FunctionDeclaration */:
case 172 /* 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 149 /* TypeReference */:
return visitNode(cbNode, node.typeName) ||
visitNodes(cbNodes, node.typeArguments);
case 148 /* TypePredicate */:
return visitNode(cbNode, node.parameterName) ||
visitNode(cbNode, node.type);
case 152 /* TypeQuery */:
return visitNode(cbNode, node.exprName);
case 153 /* TypeLiteral */:
return visitNodes(cbNodes, node.members);
case 154 /* ArrayType */:
return visitNode(cbNode, node.elementType);
case 155 /* TupleType */:
return visitNodes(cbNodes, node.elementTypes);
case 156 /* UnionType */:
case 157 /* IntersectionType */:
return visitNodes(cbNodes, node.types);
case 158 /* ParenthesizedType */:
return visitNode(cbNode, node.type);
case 159 /* ObjectBindingPattern */:
case 160 /* ArrayBindingPattern */:
return visitNodes(cbNodes, node.elements);
case 162 /* ArrayLiteralExpression */:
return visitNodes(cbNodes, node.elements);
case 163 /* ObjectLiteralExpression */:
return visitNodes(cbNodes, node.properties);
case 164 /* PropertyAccessExpression */:
return visitNode(cbNode, node.expression) ||
visitNode(cbNode, node.dotToken) ||
visitNode(cbNode, node.name);
case 165 /* ElementAccessExpression */:
return visitNode(cbNode, node.expression) ||
visitNode(cbNode, node.argumentExpression);
case 166 /* CallExpression */:
case 167 /* NewExpression */:
return visitNode(cbNode, node.expression) ||
visitNodes(cbNodes, node.typeArguments) ||
visitNodes(cbNodes, node.arguments);
case 168 /* TaggedTemplateExpression */:
return visitNode(cbNode, node.tag) ||
visitNode(cbNode, node.template);
case 169 /* TypeAssertionExpression */:
return visitNode(cbNode, node.type) ||
visitNode(cbNode, node.expression);
case 170 /* ParenthesizedExpression */:
return visitNode(cbNode, node.expression);
case 173 /* DeleteExpression */:
return visitNode(cbNode, node.expression);
case 174 /* TypeOfExpression */:
return visitNode(cbNode, node.expression);
case 175 /* VoidExpression */:
return visitNode(cbNode, node.expression);
case 177 /* PrefixUnaryExpression */:
return visitNode(cbNode, node.operand);
case 182 /* YieldExpression */:
return visitNode(cbNode, node.asteriskToken) ||
visitNode(cbNode, node.expression);
case 176 /* AwaitExpression */:
return visitNode(cbNode, node.expression);
case 178 /* PostfixUnaryExpression */:
return visitNode(cbNode, node.operand);
case 179 /* BinaryExpression */:
return visitNode(cbNode, node.left) ||
visitNode(cbNode, node.operatorToken) ||
visitNode(cbNode, node.right);
case 187 /* AsExpression */:
return visitNode(cbNode, node.expression) ||
visitNode(cbNode, node.type);
case 180 /* ConditionalExpression */:
return visitNode(cbNode, node.condition) ||
visitNode(cbNode, node.questionToken) ||
visitNode(cbNode, node.whenTrue) ||
visitNode(cbNode, node.colonToken) ||
visitNode(cbNode, node.whenFalse);
case 183 /* SpreadElementExpression */:
return visitNode(cbNode, node.expression);
case 190 /* Block */:
case 217 /* ModuleBlock */:
return visitNodes(cbNodes, node.statements);
case 246 /* SourceFile */:
return visitNodes(cbNodes, node.statements) ||
visitNode(cbNode, node.endOfFileToken);
case 191 /* VariableStatement */:
return visitNodes(cbNodes, node.decorators) ||
visitNodes(cbNodes, node.modifiers) ||
visitNode(cbNode, node.declarationList);
case 210 /* VariableDeclarationList */:
return visitNodes(cbNodes, node.declarations);
case 193 /* ExpressionStatement */:
return visitNode(cbNode, node.expression);
case 194 /* IfStatement */:
return visitNode(cbNode, node.expression) ||
visitNode(cbNode, node.thenStatement) ||
visitNode(cbNode, node.elseStatement);
case 195 /* DoStatement */:
return visitNode(cbNode, node.statement) ||
visitNode(cbNode, node.expression);
case 196 /* WhileStatement */:
return visitNode(cbNode, node.expression) ||
visitNode(cbNode, node.statement);
case 197 /* ForStatement */:
return visitNode(cbNode, node.initializer) ||
visitNode(cbNode, node.condition) ||
visitNode(cbNode, node.incrementor) ||
visitNode(cbNode, node.statement);
case 198 /* ForInStatement */:
return visitNode(cbNode, node.initializer) ||
visitNode(cbNode, node.expression) ||
visitNode(cbNode, node.statement);
case 199 /* ForOfStatement */:
return visitNode(cbNode, node.initializer) ||
visitNode(cbNode, node.expression) ||
visitNode(cbNode, node.statement);
case 200 /* ContinueStatement */:
case 201 /* BreakStatement */:
return visitNode(cbNode, node.label);
case 202 /* ReturnStatement */:
return visitNode(cbNode, node.expression);
case 203 /* WithStatement */:
return visitNode(cbNode, node.expression) ||
visitNode(cbNode, node.statement);
case 204 /* SwitchStatement */:
return visitNode(cbNode, node.expression) ||
visitNode(cbNode, node.caseBlock);
case 218 /* CaseBlock */:
return visitNodes(cbNodes, node.clauses);
case 239 /* CaseClause */:
return visitNode(cbNode, node.expression) ||
visitNodes(cbNodes, node.statements);
case 240 /* DefaultClause */:
return visitNodes(cbNodes, node.statements);
case 205 /* LabeledStatement */:
return visitNode(cbNode, node.label) ||
visitNode(cbNode, node.statement);
case 206 /* ThrowStatement */:
return visitNode(cbNode, node.expression);
case 207 /* TryStatement */:
return visitNode(cbNode, node.tryBlock) ||
visitNode(cbNode, node.catchClause) ||
visitNode(cbNode, node.finallyBlock);
case 242 /* CatchClause */:
return visitNode(cbNode, node.variableDeclaration) ||
visitNode(cbNode, node.block);
case 137 /* Decorator */:
return visitNode(cbNode, node.expression);
case 212 /* ClassDeclaration */:
case 184 /* 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 213 /* 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 214 /* TypeAliasDeclaration */:
return visitNodes(cbNodes, node.decorators) ||
visitNodes(cbNodes, node.modifiers) ||
visitNode(cbNode, node.name) ||
visitNodes(cbNodes, node.typeParameters) ||
visitNode(cbNode, node.type);
case 215 /* EnumDeclaration */:
return visitNodes(cbNodes, node.decorators) ||
visitNodes(cbNodes, node.modifiers) ||
visitNode(cbNode, node.name) ||
visitNodes(cbNodes, node.members);
case 245 /* EnumMember */:
return visitNode(cbNode, node.name) ||
visitNode(cbNode, node.initializer);
case 216 /* ModuleDeclaration */:
return visitNodes(cbNodes, node.decorators) ||
visitNodes(cbNodes, node.modifiers) ||
visitNode(cbNode, node.name) ||
visitNode(cbNode, node.body);
case 219 /* ImportEqualsDeclaration */:
return visitNodes(cbNodes, node.decorators) ||
visitNodes(cbNodes, node.modifiers) ||
visitNode(cbNode, node.name) ||
visitNode(cbNode, node.moduleReference);
case 220 /* ImportDeclaration */:
return visitNodes(cbNodes, node.decorators) ||
visitNodes(cbNodes, node.modifiers) ||
visitNode(cbNode, node.importClause) ||
visitNode(cbNode, node.moduleSpecifier);
case 221 /* ImportClause */:
return visitNode(cbNode, node.name) ||
visitNode(cbNode, node.namedBindings);
case 222 /* NamespaceImport */:
return visitNode(cbNode, node.name);
case 223 /* NamedImports */:
case 227 /* NamedExports */:
return visitNodes(cbNodes, node.elements);
case 226 /* ExportDeclaration */:
return visitNodes(cbNodes, node.decorators) ||
visitNodes(cbNodes, node.modifiers) ||
visitNode(cbNode, node.exportClause) ||
visitNode(cbNode, node.moduleSpecifier);
case 224 /* ImportSpecifier */:
case 228 /* ExportSpecifier */:
return visitNode(cbNode, node.propertyName) ||
visitNode(cbNode, node.name);
case 225 /* ExportAssignment */:
return visitNodes(cbNodes, node.decorators) ||
visitNodes(cbNodes, node.modifiers) ||
visitNode(cbNode, node.expression);
case 181 /* TemplateExpression */:
return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans);
case 188 /* TemplateSpan */:
return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal);
case 134 /* ComputedPropertyName */:
return visitNode(cbNode, node.expression);
case 241 /* HeritageClause */:
return visitNodes(cbNodes, node.types);
case 186 /* ExpressionWithTypeArguments */:
return visitNode(cbNode, node.expression) ||
visitNodes(cbNodes, node.typeArguments);
case 230 /* ExternalModuleReference */:
return visitNode(cbNode, node.expression);
case 229 /* MissingDeclaration */:
return visitNodes(cbNodes, node.decorators);
case 231 /* JsxElement */:
return visitNode(cbNode, node.openingElement) ||
visitNodes(cbNodes, node.children) ||
visitNode(cbNode, node.closingElement);
case 232 /* JsxSelfClosingElement */:
case 233 /* JsxOpeningElement */:
return visitNode(cbNode, node.tagName) ||
visitNodes(cbNodes, node.attributes);
case 236 /* JsxAttribute */:
return visitNode(cbNode, node.name) ||
visitNode(cbNode, node.initializer);
case 237 /* JsxSpreadAttribute */:
return visitNode(cbNode, node.expression);
case 238 /* JsxExpression */:
return visitNode(cbNode, node.expression);
case 235 /* JsxClosingElement */:
return visitNode(cbNode, node.tagName);
case 247 /* JSDocTypeExpression */:
return visitNode(cbNode, node.type);
case 251 /* JSDocUnionType */:
return visitNodes(cbNodes, node.types);
case 252 /* JSDocTupleType */:
return visitNodes(cbNodes, node.types);
case 250 /* JSDocArrayType */:
return visitNode(cbNode, node.elementType);
case 254 /* JSDocNonNullableType */:
return visitNode(cbNode, node.type);
case 253 /* JSDocNullableType */:
return visitNode(cbNode, node.type);
case 255 /* JSDocRecordType */:
return visitNodes(cbNodes, node.members);
case 257 /* JSDocTypeReference */:
return visitNode(cbNode, node.name) ||
visitNodes(cbNodes, node.typeArguments);
case 258 /* JSDocOptionalType */:
return visitNode(cbNode, node.type);
case 259 /* JSDocFunctionType */:
return visitNodes(cbNodes, node.parameters) ||
visitNode(cbNode, node.type);
case 260 /* JSDocVariadicType */:
return visitNode(cbNode, node.type);
case 261 /* JSDocConstructorType */:
return visitNode(cbNode, node.type);
case 262 /* JSDocThisType */:
return visitNode(cbNode, node.type);
case 256 /* JSDocRecordMember */:
return visitNode(cbNode, node.name) ||
visitNode(cbNode, node.type);
case 263 /* JSDocComment */:
return visitNodes(cbNodes, node.tags);
case 265 /* JSDocParameterTag */:
return visitNode(cbNode, node.preParameterName) ||
visitNode(cbNode, node.typeExpression) ||
visitNode(cbNode, node.postParameterName);
case 266 /* JSDocReturnTag */:
return visitNode(cbNode, node.typeExpression);
case 267 /* JSDocTypeTag */:
return visitNode(cbNode, node.typeExpression);
case 268 /* JSDocTemplateTag */:
return visitNodes(cbNodes, node.typeParameters);
}
}
ts.forEachChild = forEachChild;
function createSourceFile(fileName, sourceText, languageVersion, setParentNodes) {
if (setParentNodes === void 0) { setParentNodes = false; }
var start = new Date().getTime();
var result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes);
ts.parseTime += new Date().getTime() - start;
return result;
}
ts.createSourceFile = createSourceFile;
// Produces a new SourceFile for the 'newText' provided. The 'textChangeRange' parameter
// indicates what changed between the 'text' that this SourceFile has and the 'newText'.
// The SourceFile will be created with the compiler attempting to reuse as many nodes from
// this file as possible.
//
// Note: this function mutates nodes from this SourceFile. That means any existing nodes
// from this SourceFile that are being held onto may change as a result (including
// becoming detached from any SourceFile). It is recommended that this SourceFile not
// be used once 'update' is called on it.
function updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks) {
return IncrementalParser.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks);
}
ts.updateSourceFile = updateSourceFile;
/* @internal */
function parseIsolatedJSDocComment(content, start, length) {
return Parser.JSDocParser.parseIsolatedJSDocComment(content, start, length);
}
ts.parseIsolatedJSDocComment = parseIsolatedJSDocComment;
/* @internal */
// Exposed only for testing.
function parseJSDocTypeExpressionForTests(content, start, length) {
return Parser.JSDocParser.parseJSDocTypeExpressionForTests(content, start, length);
}
ts.parseJSDocTypeExpressionForTests = parseJSDocTypeExpressionForTests;
// Implement the parser as a singleton module. We do this for perf reasons because creating
// parser instances can actually be expensive enough to impact us on projects with many source
// files.
var Parser;
(function (Parser) {
// Share a single scanner across all calls to parse a source file. This helps speed things
// up by avoiding the cost of creating/compiling scanners over and over again.
var scanner = ts.createScanner(2 /* Latest */, /*skipTrivia*/ true);
var disallowInAndDecoratorContext = 1 /* DisallowIn */ | 4 /* Decorator */;
var sourceFile;
var parseDiagnostics;
var syntaxCursor;
var token;
var sourceText;
var nodeCount;
var identifiers;
var identifierCount;
var parsingContext;
// Flags that dictate what parsing context we're in. For example:
// Whether or not we are in strict parsing mode. All that changes in strict parsing mode is
// that some tokens that would be considered identifiers may be considered keywords.
//
// When adding more parser context flags, consider which is the more common case that the
// flag will be in. This should be the 'false' state for that flag. The reason for this is
// that we don't store data in our nodes unless the value is in the *non-default* state. So,
// for example, more often than code 'allows-in' (or doesn't 'disallow-in'). We opt for
// 'disallow-in' set to 'false'. Otherwise, if we had 'allowsIn' set to 'true', then almost
// all nodes would need extra state on them to store this info.
//
// Note: 'allowIn' and 'allowYield' track 1:1 with the [in] and [yield] concepts in the ES6
// grammar specification.
//
// An important thing about these context concepts. By default they are effectively inherited
// while parsing through every grammar production. i.e. if you don't change them, then when
// you parse a sub-production, it will have the same context values as the parent production.
// This is great most of the time. After all, consider all the 'expression' grammar productions
// and how nearly all of them pass along the 'in' and 'yield' context values:
//
// EqualityExpression[In, Yield] :
// RelationalExpression[?In, ?Yield]
// EqualityExpression[?In, ?Yield] == RelationalExpression[?In, ?Yield]
// EqualityExpression[?In, ?Yield] != RelationalExpression[?In, ?Yield]
// EqualityExpression[?In, ?Yield] === RelationalExpression[?In, ?Yield]
// EqualityExpression[?In, ?Yield] !== RelationalExpression[?In, ?Yield]
//
// Where you have to be careful is then understanding what the points are in the grammar
// where the values are *not* passed along. For example:
//
// SingleNameBinding[Yield,GeneratorParameter]
// [+GeneratorParameter]BindingIdentifier[Yield] Initializer[In]opt
// [~GeneratorParameter]BindingIdentifier[?Yield]Initializer[In, ?Yield]opt
//
// Here this is saying that if the GeneratorParameter context flag is set, that we should
// explicitly set the 'yield' context flag to false before calling into the BindingIdentifier
// and we should explicitly unset the 'yield' context flag before calling into the Initializer.
// production. Conversely, if the GeneratorParameter context flag is not set, then we
// should leave the 'yield' context flag alone.
//
// Getting this all correct is tricky and requires careful reading of the grammar to
// understand when these values should be changed versus when they should be inherited.
//
// Note: it should not be necessary to save/restore these flags during speculative/lookahead
// parsing. These context flags are naturally stored and restored through normal recursive
// descent parsing and unwinding.
var contextFlags;
// Whether or not we've had a parse error since creating the last AST node. If we have
// encountered an error, it will be stored on the next AST node we create. Parse errors
// can be broken down into three categories:
//
// 1) An error that occurred during scanning. For example, an unterminated literal, or a
// character that was completely not understood.
//
// 2) A token was expected, but was not present. This type of error is commonly produced
// by the 'parseExpected' function.
//
// 3) A token was present that no parsing function was able to consume. This type of error
// only occurs in the 'abortParsingListOrMoveToNextToken' function when the parser
// decides to skip the token.
//
// In all of these cases, we want to mark the next node as having had an error before it.
// With this mark, we can know in incremental settings if this node can be reused, or if
// we have to reparse it. If we don't keep this information around, we may just reuse the
// node. in that event we would then not produce the same errors as we did before, causing
// significant confusion problems.
//
// Note: it is necessary that this value be saved/restored during speculative/lookahead
// parsing. During lookahead parsing, we will often create a node. That node will have
// this value attached, and then this value will be set back to 'false'. If we decide to
// rewind, we must get back to the same value we had prior to the lookahead.
//
// Note: any errors at the end of the file that do not precede a regular node, should get
// attached to the EOF token.
var parseErrorBeforeNextFinishedNode = false;
function parseSourceFile(fileName, _sourceText, languageVersion, _syntaxCursor, setParentNodes) {
initializeState(fileName, _sourceText, languageVersion, _syntaxCursor);
var result = parseSourceFileWorker(fileName, languageVersion, setParentNodes);
clearState();
return result;
}
Parser.parseSourceFile = parseSourceFile;
function initializeState(fileName, _sourceText, languageVersion, _syntaxCursor) {
sourceText = _sourceText;
syntaxCursor = _syntaxCursor;
parseDiagnostics = [];
parsingContext = 0;
identifiers = {};
identifierCount = 0;
nodeCount = 0;
contextFlags = ts.isJavaScript(fileName) ? 32 /* JavaScriptFile */ : 0 /* None */;
parseErrorBeforeNextFinishedNode = false;
// Initialize and prime the scanner before parsing the source elements.
scanner.setText(sourceText);
scanner.setOnError(scanError);
scanner.setScriptTarget(languageVersion);
scanner.setLanguageVariant(ts.isTsx(fileName) ? 1 /* JSX */ : 0 /* Standard */);
}
function clearState() {
// Clear out the text the scanner is pointing at, so it doesn't keep anything alive unnecessarily.
scanner.setText("");
scanner.setOnError(undefined);
// Clear any data. We don't want to accidently hold onto it for too long.
parseDiagnostics = undefined;
sourceFile = undefined;
identifiers = undefined;
syntaxCursor = undefined;
sourceText = undefined;
}
function parseSourceFileWorker(fileName, languageVersion, setParentNodes) {
sourceFile = createSourceFile(fileName, languageVersion);
// Prime the scanner.
token = nextToken();
processReferenceComments(sourceFile);
sourceFile.statements = parseList(0 /* SourceElements */, parseStatement);
ts.Debug.assert(token === 1 /* EndOfFileToken */);
sourceFile.endOfFileToken = parseTokenNode();
setExternalModuleIndicator(sourceFile);
sourceFile.nodeCount = nodeCount;
sourceFile.identifierCount = identifierCount;
sourceFile.identifiers = identifiers;
sourceFile.parseDiagnostics = parseDiagnostics;
if (setParentNodes) {
fixupParentReferences(sourceFile);
}
// If this is a javascript file, proactively see if we can get JSDoc comments for
// relevant nodes in the file. We'll use these to provide typing informaion if they're
// available.
if (ts.isJavaScript(fileName)) {
addJSDocComments();
}
return sourceFile;
}
function addJSDocComments() {
forEachChild(sourceFile, visit);
return;
function visit(node) {
// Add additional cases as necessary depending on how we see JSDoc comments used
// in the wild.
switch (node.kind) {
case 191 /* VariableStatement */:
case 211 /* FunctionDeclaration */:
case 136 /* Parameter */:
addJSDocComment(node);
}
forEachChild(node, visit);
}
}
function addJSDocComment(node) {
var comments = ts.getLeadingCommentRangesOfNode(node, sourceFile);
if (comments) {
for (var _i = 0; _i < comments.length; _i++) {
var comment = comments[_i];
var jsDocComment = JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos);
if (jsDocComment) {
node.jsDocComment = jsDocComment;
}
}
}
}
function fixupParentReferences(sourceFile) {
// normally parent references are set during binding. However, for clients that only need
// a syntax tree, and no semantic features, then the binding process is an unnecessary
// overhead. This functions allows us to set all the parents, without all the expense of
// binding.
var parent = sourceFile;
forEachChild(sourceFile, visitNode);
return;
function visitNode(n) {
// walk down setting parents that differ from the parent we think it should be. This
// allows us to quickly bail out of setting parents for subtrees during incremental
// parsing
if (n.parent !== parent) {
n.parent = parent;
var saveParent = parent;
parent = n;
forEachChild(n, visitNode);
parent = saveParent;
}
}
}
Parser.fixupParentReferences = fixupParentReferences;
function createSourceFile(fileName, languageVersion) {
var sourceFile = createNode(246 /* SourceFile */, /*pos*/ 0);
sourceFile.pos = 0;
sourceFile.end = sourceText.length;
sourceFile.text = sourceText;
sourceFile.bindDiagnostics = [];
sourceFile.languageVersion = languageVersion;
sourceFile.fileName = ts.normalizePath(fileName);
sourceFile.flags = ts.fileExtensionIs(sourceFile.fileName, ".d.ts") ? 8192 /* DeclarationFile */ : 0;
sourceFile.languageVariant = ts.isTsx(sourceFile.fileName) ? 1 /* JSX */ : 0 /* Standard */;
return sourceFile;
}
function setContextFlag(val, flag) {
if (val) {
contextFlags |= flag;
}
else {
contextFlags &= ~flag;
}
}
function setDisallowInContext(val) {
setContextFlag(val, 1 /* DisallowIn */);
}
function setYieldContext(val) {
setContextFlag(val, 2 /* Yield */);
}
function setDecoratorContext(val) {
setContextFlag(val, 4 /* Decorator */);
}
function setAwaitContext(val) {
setContextFlag(val, 8 /* Await */);
}
function 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(false, contextFlagsToClear);
var result = func();
// restore the context flags we just cleared
setContextFlag(true, contextFlagsToClear);
return result;
}
// no need to do anything special as we are not in any of the requested contexts
return func();
}
function doInsideOfContext(context, func) {
// contextFlagsToSet will contain only the context flags that
// are not currently set that we need to temporarily enable.
// 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 contextFlagsToSet = context & ~contextFlags;
if (contextFlagsToSet) {
// set the requested context flags
setContextFlag(true, contextFlagsToSet);
var result = func();
// reset the context flags we just set
setContextFlag(false, contextFlagsToSet);
return result;
}
// no need to do anything special as we are already in all of the requested contexts
return func();
}
function allowInAnd(func) {
return doOutsideOfContext(1 /* DisallowIn */, func);
}
function disallowInAnd(func) {
return doInsideOfContext(1 /* DisallowIn */, func);
}
function doInYieldContext(func) {
return doInsideOfContext(2 /* Yield */, func);
}
function doOutsideOfYieldContext(func) {
return doOutsideOfContext(2 /* Yield */, func);
}
function doInDecoratorContext(func) {
return doInsideOfContext(4 /* Decorator */, func);
}
function doInAwaitContext(func) {
return doInsideOfContext(8 /* Await */, func);
}
function doOutsideOfAwaitContext(func) {
return doOutsideOfContext(8 /* Await */, func);
}
function doInYieldAndAwaitContext(func) {
return doInsideOfContext(2 /* Yield */ | 8 /* Await */, func);
}
function doOutsideOfYieldAndAwaitContext(func) {
return doOutsideOfContext(2 /* Yield */ | 8 /* Await */, func);
}
function inContext(flags) {
return (contextFlags & flags) !== 0;
}
function inYieldContext() {
return inContext(2 /* Yield */);
}
function inDisallowInContext() {
return inContext(1 /* DisallowIn */);
}
function inDecoratorContext() {
return inContext(4 /* Decorator */);
}
function inAwaitContext() {
return inContext(8 /* Await */);
}
function parseErrorAtCurrentToken(message, arg0) {
var start = scanner.getTokenPos();
var length = scanner.getTextPos() - start;
parseErrorAtPosition(start, length, message, arg0);
}
function parseErrorAtPosition(start, length, message, arg0) {
// Don't report another error if it would just be at the same position as the last error.
var lastError = ts.lastOrUndefined(parseDiagnostics);
if (!lastError || start !== lastError.start) {
parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, start, length, message, arg0));
}
// Mark that we've encountered an error. We'll set an appropriate bit on the next
// node we finish so that it can't be reused incrementally.
parseErrorBeforeNextFinishedNode = true;
}
function scanError(message, length) {
var pos = scanner.getTextPos();
parseErrorAtPosition(pos, length || 0, message);
}
function getNodePos() {
return scanner.getStartPos();
}
function getNodeEnd() {
return scanner.getStartPos();
}
function nextToken() {
return token = scanner.scan();
}
function getTokenPos(pos) {
return ts.skipTrivia(sourceText, pos);
}
function reScanGreaterToken() {
return token = scanner.reScanGreaterToken();
}
function reScanSlashToken() {
return token = scanner.reScanSlashToken();
}
function reScanTemplateToken() {
return token = scanner.reScanTemplateToken();
}
function scanJsxIdentifier() {
return token = scanner.scanJsxIdentifier();
}
function scanJsxText() {
return token = scanner.scanJsxToken();
}
function 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 = token;
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/restorating 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 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) {
token = saveToken;
parseDiagnostics.length = saveParseDiagnosticsLength;
parseErrorBeforeNextFinishedNode = saveParseErrorBeforeNextFinishedNode;
}
return result;
}
// Invokes the provided callback then unconditionally restores the parser to the state it
// was in immediately prior to invoking the callback. The result of invoking the callback
// is returned from this function.
function lookAhead(callback) {
return speculationHelper(callback, /*isLookAhead*/ true);
}
// Invokes the provided callback. If the callback returns something falsy, then it restores
// the parser to the state it was in immediately prior to invoking the callback. If the
// callback returns something truthy, then the parser state is not rolled back. The result
// of invoking the callback is returned from this function.
function tryParse(callback) {
return speculationHelper(callback, /*isLookAhead*/ false);
}
// Ignore strict mode flag because we will report an error in type checker instead.
function isIdentifier() {
if (token === 67 /* 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 === 112 /* 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 === 117 /* AwaitKeyword */ && inAwaitContext()) {
return false;
}
return token > 103 /* LastReservedWord */;
}
function 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;
}
function parseOptional(t) {
if (token === t) {
nextToken();
return true;
}
return false;
}
function parseOptionalToken(t) {
if (token === t) {
return parseTokenNode();
}
return undefined;
}
function parseExpectedToken(t, reportAtCurrentPosition, diagnosticMessage, arg0) {
return parseOptionalToken(t) ||
createMissingNode(t, reportAtCurrentPosition, diagnosticMessage, arg0);
}
function parseTokenNode() {
var node = createNode(token);
nextToken();
return finishNode(node);
}
function canParseSemicolon() {
// If there's a real semicolon, then we can always parse it out.
if (token === 23 /* SemicolonToken */) {
return true;
}
// We can parse out an optional semicolon in ASI cases in the following cases.
return token === 16 /* CloseBraceToken */ || token === 1 /* EndOfFileToken */ || scanner.hasPrecedingLineBreak();
}
function parseSemicolon() {
if (canParseSemicolon()) {
if (token === 23 /* SemicolonToken */) {
// consume the semicolon if it was explicitly provided.
nextToken();
}
return true;
}
else {
return parseExpected(23 /* SemicolonToken */);
}
}
function createNode(kind, pos) {
nodeCount++;
var node = new (nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)))();
if (!(pos >= 0)) {
pos = scanner.getStartPos();
}
node.pos = pos;
node.end = pos;
return node;
}
function finishNode(node, end) {
node.end = end === undefined ? scanner.getStartPos() : end;
if (contextFlags) {
node.parserContextFlags = 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.parserContextFlags |= 16 /* ThisNodeHasError */;
}
return node;
}
function createMissingNode(kind, reportAtCurrentPosition, diagnosticMessage, arg0) {
if (reportAtCurrentPosition) {
parseErrorAtPosition(scanner.getStartPos(), 0, diagnosticMessage, arg0);
}
else {
parseErrorAtCurrentToken(diagnosticMessage, arg0);
}
var result = createNode(kind, scanner.getStartPos());
result.text = "";
return finishNode(result);
}
function internIdentifier(text) {
text = ts.escapeIdentifier(text);
return ts.hasProperty(identifiers, text) ? identifiers[text] : (identifiers[text] = text);
}
// An identifier that starts with two underscores has an extra underscore character prepended to it to avoid issues
// with magic property names like '__proto__'. The 'identifiers' object is used to share a single string instance for
// each identifier in order to reduce memory consumption.
function createIdentifier(isIdentifier, diagnosticMessage) {
identifierCount++;
if (isIdentifier) {
var node = createNode(67 /* Identifier */);
// Store original token kind if it is not just an Identifier so we can report appropriate error later in type checker
if (token !== 67 /* Identifier */) {
node.originalKeywordKind = token;
}
node.text = internIdentifier(scanner.getTokenValue());
nextToken();
return finishNode(node);
}
return createMissingNode(67 /* Identifier */, /*reportAtCurrentPosition*/ false, diagnosticMessage || ts.Diagnostics.Identifier_expected);
}
function parseIdentifier(diagnosticMessage) {
return createIdentifier(isIdentifier(), diagnosticMessage);
}
function parseIdentifierName() {
return createIdentifier(isIdentifierOrKeyword());
}
function isLiteralPropertyName() {
return isIdentifierOrKeyword() ||
token === 9 /* StringLiteral */ ||
token === 8 /* NumericLiteral */;
}
function parsePropertyNameWorker(allowComputedPropertyNames) {
if (token === 9 /* StringLiteral */ || token === 8 /* NumericLiteral */) {
return parseLiteralNode(/*internName*/ true);
}
if (allowComputedPropertyNames && token === 19 /* OpenBracketToken */) {
return parseComputedPropertyName();
}
return parseIdentifierName();
}
function parsePropertyName() {
return parsePropertyNameWorker(/*allowComputedPropertyNames:*/ true);
}
function parseSimplePropertyName() {
return parsePropertyNameWorker(/*allowComputedPropertyNames:*/ false);
}
function isSimplePropertyName() {
return token === 9 /* StringLiteral */ || token === 8 /* NumericLiteral */ || isIdentifierOrKeyword();
}
function parseComputedPropertyName() {
// PropertyName [Yield]:
// LiteralPropertyName
// ComputedPropertyName[?Yield]
var node = createNode(134 /* ComputedPropertyName */);
parseExpected(19 /* OpenBracketToken */);
// We parse any expression (including a comma expression). But the grammar
// says that only an assignment expression is allowed, so the grammar checker
// will error if it sees a comma expression.
node.expression = allowInAnd(parseExpression);
parseExpected(20 /* CloseBracketToken */);
return finishNode(node);
}
function parseContextualModifier(t) {
return token === t && tryParse(nextTokenCanFollowModifier);
}
function nextTokenCanFollowModifier() {
if (token === 72 /* ConstKeyword */) {
// 'const' is only a modifier if followed by 'enum'.
return nextToken() === 79 /* EnumKeyword */;
}
if (token === 80 /* ExportKeyword */) {
nextToken();
if (token === 75 /* DefaultKeyword */) {
return lookAhead(nextTokenIsClassOrFunction);
}
return token !== 37 /* AsteriskToken */ && token !== 15 /* OpenBraceToken */ && canFollowModifier();
}
if (token === 75 /* DefaultKeyword */) {
return nextTokenIsClassOrFunction();
}
nextToken();
return canFollowModifier();
}
function parseAnyContextualModifier() {
return ts.isModifier(token) && tryParse(nextTokenCanFollowModifier);
}
function canFollowModifier() {
return token === 19 /* OpenBracketToken */
|| token === 15 /* OpenBraceToken */
|| token === 37 /* AsteriskToken */
|| isLiteralPropertyName();
}
function nextTokenIsClassOrFunction() {
nextToken();
return token === 71 /* ClassKeyword */ || token === 85 /* FunctionKeyword */;
}
// True if positioned at the start of a list element
function 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 === 23 /* SemicolonToken */ && inErrorRecovery) && isStartOfStatement();
case 2 /* SwitchClauses */:
return token === 69 /* CaseKeyword */ || token === 75 /* DefaultKeyword */;
case 4 /* TypeMembers */:
return isStartOfTypeMember();
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 === 23 /* 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 === 19 /* OpenBracketToken */ || isLiteralPropertyName();
case 12 /* ObjectLiteralMembers */:
return token === 19 /* OpenBracketToken */ || token === 37 /* AsteriskToken */ || isLiteralPropertyName();
case 9 /* ObjectBindingElements */:
return 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 === 15 /* 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 === 24 /* CommaToken */ || token === 22 /* DotDotDotToken */ || isIdentifierOrPattern();
case 17 /* TypeParameters */:
return isIdentifier();
case 11 /* ArgumentExpressions */:
case 15 /* ArrayLiteralMembers */:
return token === 24 /* CommaToken */ || token === 22 /* DotDotDotToken */ || isStartOfExpression();
case 16 /* Parameters */:
return isStartOfParameter();
case 18 /* TypeArguments */:
case 19 /* TupleElementTypes */:
return token === 24 /* CommaToken */ || isStartOfType();
case 20 /* HeritageClauses */:
return isHeritageClause();
case 21 /* ImportOrExportSpecifiers */:
return isIdentifierOrKeyword();
case 13 /* JsxAttributes */:
return isIdentifierOrKeyword() || token === 15 /* OpenBraceToken */;
case 14 /* JsxChildren */:
return true;
case 22 /* JSDocFunctionParameters */:
case 23 /* JSDocTypeArguments */:
case 25 /* JSDocTupleTypes */:
return JSDocParser.isJSDocType();
case 24 /* JSDocRecordMembers */:
return isSimplePropertyName();
}
ts.Debug.fail("Non-exhaustive case in 'isListElement'.");
}
function isValidHeritageClauseObjectLiteral() {
ts.Debug.assert(token === 15 /* OpenBraceToken */);
if (nextToken() === 16 /* CloseBraceToken */) {
// if we see "extends {}" then only treat the {} as what we're extending (and not
// the class body) if we have:
//
// extends {} {
// extends {},
// extends {} extends
// extends {} implements
var next = nextToken();
return next === 24 /* CommaToken */ || next === 15 /* OpenBraceToken */ || next === 81 /* ExtendsKeyword */ || next === 104 /* ImplementsKeyword */;
}
return true;
}
function nextTokenIsIdentifier() {
nextToken();
return isIdentifier();
}
function nextTokenIsIdentifierOrKeyword() {
nextToken();
return isIdentifierOrKeyword();
}
function isHeritageClauseExtendsOrImplementsKeyword() {
if (token === 104 /* ImplementsKeyword */ ||
token === 81 /* ExtendsKeyword */) {
return lookAhead(nextTokenIsStartOfExpression);
}
return false;
}
function nextTokenIsStartOfExpression() {
nextToken();
return isStartOfExpression();
}
// True if positioned at a list terminator
function isListTerminator(kind) {
if (token === 1 /* EndOfFileToken */) {
// Being at the end of the file ends all lists.
return true;
}
switch (kind) {
case 1 /* BlockStatements */:
case 2 /* SwitchClauses */:
case 4 /* TypeMembers */:
case 5 /* ClassMembers */:
case 6 /* EnumMembers */:
case 12 /* ObjectLiteralMembers */:
case 9 /* ObjectBindingElements */:
case 21 /* ImportOrExportSpecifiers */:
return token === 16 /* CloseBraceToken */;
case 3 /* SwitchClauseStatements */:
return token === 16 /* CloseBraceToken */ || token === 69 /* CaseKeyword */ || token === 75 /* DefaultKeyword */;
case 7 /* HeritageClauseElement */:
return token === 15 /* OpenBraceToken */ || token === 81 /* ExtendsKeyword */ || token === 104 /* ImplementsKeyword */;
case 8 /* VariableDeclarations */:
return isVariableDeclaratorListTerminator();
case 17 /* TypeParameters */:
// Tokens other than '>' are here for better error recovery
return token === 27 /* GreaterThanToken */ || token === 17 /* OpenParenToken */ || token === 15 /* OpenBraceToken */ || token === 81 /* ExtendsKeyword */ || token === 104 /* ImplementsKeyword */;
case 11 /* ArgumentExpressions */:
// Tokens other than ')' are here for better error recovery
return token === 18 /* CloseParenToken */ || token === 23 /* SemicolonToken */;
case 15 /* ArrayLiteralMembers */:
case 19 /* TupleElementTypes */:
case 10 /* ArrayBindingElements */:
return token === 20 /* CloseBracketToken */;
case 16 /* Parameters */:
// Tokens other than ')' and ']' (the latter for index signatures) are here for better error recovery
return token === 18 /* CloseParenToken */ || token === 20 /* CloseBracketToken */ /*|| token === SyntaxKind.OpenBraceToken*/;
case 18 /* TypeArguments */:
// Tokens other than '>' are here for better error recovery
return token === 27 /* GreaterThanToken */ || token === 17 /* OpenParenToken */;
case 20 /* HeritageClauses */:
return token === 15 /* OpenBraceToken */ || token === 16 /* CloseBraceToken */;
case 13 /* JsxAttributes */:
return token === 27 /* GreaterThanToken */ || token === 38 /* SlashToken */;
case 14 /* JsxChildren */:
return token === 25 /* LessThanToken */ && lookAhead(nextTokenIsSlash);
case 22 /* JSDocFunctionParameters */:
return token === 18 /* CloseParenToken */ || token === 53 /* ColonToken */ || token === 16 /* CloseBraceToken */;
case 23 /* JSDocTypeArguments */:
return token === 27 /* GreaterThanToken */ || token === 16 /* CloseBraceToken */;
case 25 /* JSDocTupleTypes */:
return token === 20 /* CloseBracketToken */ || token === 16 /* CloseBraceToken */;
case 24 /* JSDocRecordMembers */:
return token === 16 /* CloseBraceToken */;
}
}
function 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 === 34 /* EqualsGreaterThanToken */) {
return true;
}
// Keep trying to parse out variable declarators.
return false;
}
// True if positioned at element or terminator of the current list or any enclosing list
function isInSomeParsingContext() {
for (var kind = 0; kind < 26 /* Count */; kind++) {
if (parsingContext & (1 << kind)) {
if (isListElement(kind, /* inErrorRecovery */ true) || isListTerminator(kind)) {
return true;
}
}
}
return false;
}
// Parses a list of elements
function parseList(kind, parseElement) {
var saveParsingContext = parsingContext;
parsingContext |= 1 << kind;
var result = [];
result.pos = getNodePos();
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;
}
function parseListElement(parsingContext, parseElement) {
var node = currentNode(parsingContext);
if (node) {
return consumeNode(node);
}
return parseElement();
}
function 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 presense of strict mode may cause us to parse the tokens in the file
// differetly.
//
// 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.parserContextFlags & 31 /* ParserGeneratedFlags */;
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 currest list parsing context that we're currently at.
if (!canReuseNode(node, parsingContext)) {
return undefined;
}
return node;
}
function consumeNode(node) {
// Move the scanner so it is after the node we just consumed.
scanner.setTextPos(node.end);
nextToken();
return node;
}
function canReuseNode(node, parsingContext) {
switch (parsingContext) {
case 5 /* ClassMembers */:
return isReusableClassMember(node);
case 2 /* SwitchClauses */:
return isReusableSwitchClause(node);
case 0 /* SourceElements */:
case 1 /* BlockStatements */:
case 3 /* SwitchClauseStatements */:
return isReusableStatement(node);
case 6 /* EnumMembers */:
return isReusableEnumMember(node);
case 4 /* TypeMembers */:
return isReusableTypeMember(node);
case 8 /* VariableDeclarations */:
return isReusableVariableDeclaration(node);
case 16 /* Parameters */:
return isReusableParameter(node);
// Any other lists we do not care about reusing nodes in. But feel free to add if
// you can do so safely. Danger areas involve nodes that may involve speculative
// parsing. If speculative parsing is involved with the node, then the range the
// parser reached while looking ahead might be in the edited range (see the example
// in canReuseVariableDeclaratorNode for a good case of this).
case 20 /* HeritageClauses */:
// This would probably be safe to reuse. There is no speculative parsing with
// heritage clauses.
case 17 /* TypeParameters */:
// This would probably be safe to reuse. There is no speculative parsing with
// type parameters. Note that that's because type *parameters* only occur in
// unambiguous *type* contexts. While type *arguments* occur in very ambiguous
// *expression* contexts.
case 19 /* TupleElementTypes */:
// This would probably be safe to reuse. There is no speculative parsing with
// tuple types.
// Technically, type argument list types are probably safe to reuse. While
// speculative parsing is involved with them (since type argument lists are only
// produced from speculative parsing a < as a type argument list), we only have
// the types because speculative parsing succeeded. Thus, the lookahead never
// went past the end of the list and rewound.
case 18 /* TypeArguments */:
// Note: these are almost certainly not safe to ever reuse. Expressions commonly
// need a large amount of lookahead, and we should not reuse them as they may
// have actually intersected the edit.
case 11 /* ArgumentExpressions */:
// This is not safe to reuse for the same reason as the 'AssignmentExpression'
// cases. i.e. a property assignment may end with an expression, and thus might
// have lookahead far beyond it's old node.
case 12 /* ObjectLiteralMembers */:
// This is probably not safe to reuse. There can be speculative parsing with
// type names in a heritage clause. There can be generic names in the type
// name list, and there can be left hand side expressions (which can have type
// arguments.)
case 7 /* HeritageClauseElement */:
// Perhaps safe to reuse, but it's unlikely we'd see more than a dozen attributes
// on any given element. Same for children.
case 13 /* JsxAttributes */:
case 14 /* JsxChildren */:
}
return false;
}
function isReusableClassMember(node) {
if (node) {
switch (node.kind) {
case 142 /* Constructor */:
case 147 /* IndexSignature */:
case 143 /* GetAccessor */:
case 144 /* SetAccessor */:
case 139 /* PropertyDeclaration */:
case 189 /* SemicolonClassElement */:
return true;
case 141 /* MethodDeclaration */:
// Method declarations are not necessarily reusable. An object-literal
// may have a method calls "constructor(...)" and we must reparse that
// into an actual .ConstructorDeclaration.
var methodDeclaration = node;
var nameIsConstructor = methodDeclaration.name.kind === 67 /* Identifier */ &&
methodDeclaration.name.originalKeywordKind === 119 /* ConstructorKeyword */;
return !nameIsConstructor;
}
}
return false;
}
function isReusableSwitchClause(node) {
if (node) {
switch (node.kind) {
case 239 /* CaseClause */:
case 240 /* DefaultClause */:
return true;
}
}
return false;
}
function isReusableStatement(node) {
if (node) {
switch (node.kind) {
case 211 /* FunctionDeclaration */:
case 191 /* VariableStatement */:
case 190 /* Block */:
case 194 /* IfStatement */:
case 193 /* ExpressionStatement */:
case 206 /* ThrowStatement */:
case 202 /* ReturnStatement */:
case 204 /* SwitchStatement */:
case 201 /* BreakStatement */:
case 200 /* ContinueStatement */:
case 198 /* ForInStatement */:
case 199 /* ForOfStatement */:
case 197 /* ForStatement */:
case 196 /* WhileStatement */:
case 203 /* WithStatement */:
case 192 /* EmptyStatement */:
case 207 /* TryStatement */:
case 205 /* LabeledStatement */:
case 195 /* DoStatement */:
case 208 /* DebuggerStatement */:
case 220 /* ImportDeclaration */:
case 219 /* ImportEqualsDeclaration */:
case 226 /* ExportDeclaration */:
case 225 /* ExportAssignment */:
case 216 /* ModuleDeclaration */:
case 212 /* ClassDeclaration */:
case 213 /* InterfaceDeclaration */:
case 215 /* EnumDeclaration */:
case 214 /* TypeAliasDeclaration */:
return true;
}
}
return false;
}
function isReusableEnumMember(node) {
return node.kind === 245 /* EnumMember */;
}
function isReusableTypeMember(node) {
if (node) {
switch (node.kind) {
case 146 /* ConstructSignature */:
case 140 /* MethodSignature */:
case 147 /* IndexSignature */:
case 138 /* PropertySignature */:
case 145 /* CallSignature */:
return true;
}
}
return false;
}
function isReusableVariableDeclaration(node) {
if (node.kind !== 209 /* VariableDeclaration */) {
return false;
}
// Very subtle incremental parsing bug. Consider the following code:
//
// let v = new List < A, B
//
// This is actually legal code. It's a list of variable declarators "v = new List<A"
// on one side and "B" on the other. If you then change that to:
//
// let v = new List < A, B >()
//
// then we have a problem. "v = new List<A" doesn't intersect the change range, so we
// start reparsing at "B" and we completely fail to handle this properly.
//
// In order to prevent this, we do not allow a variable declarator to be reused if it
// has an initializer.
var variableDeclarator = node;
return variableDeclarator.initializer === undefined;
}
function isReusableParameter(node) {
if (node.kind !== 136 /* Parameter */) {
return false;
}
// See the comment in isReusableVariableDeclaration for why we do this.
var parameter = node;
return parameter.initializer === undefined;
}
// Returns true if we should abort parsing.
function abortParsingListOrMoveToNextToken(kind) {
parseErrorAtCurrentToken(parsingContextErrors(kind));
if (isInSomeParsingContext()) {
return true;
}
nextToken();
return false;
}
function parsingContextErrors(context) {
switch (context) {
case 0 /* SourceElements */: return ts.Diagnostics.Declaration_or_statement_expected;
case 1 /* BlockStatements */: return ts.Diagnostics.Declaration_or_statement_expected;
case 2 /* SwitchClauses */: return ts.Diagnostics.case_or_default_expected;
case 3 /* SwitchClauseStatements */: return ts.Diagnostics.Statement_expected;
case 4 /* TypeMembers */: return ts.Diagnostics.Property_or_signature_expected;
case 5 /* ClassMembers */: return ts.Diagnostics.Unexpected_token_A_constructor_method_accessor_or_property_was_expected;
case 6 /* EnumMembers */: return ts.Diagnostics.Enum_member_expected;
case 7 /* HeritageClauseElement */: return ts.Diagnostics.Expression_expected;
case 8 /* VariableDeclarations */: return ts.Diagnostics.Variable_declaration_expected;
case 9 /* ObjectBindingElements */: return ts.Diagnostics.Property_destructuring_pattern_expected;
case 10 /* ArrayBindingElements */: return ts.Diagnostics.Array_element_destructuring_pattern_expected;
case 11 /* ArgumentExpressions */: return ts.Diagnostics.Argument_expression_expected;
case 12 /* ObjectLiteralMembers */: return ts.Diagnostics.Property_assignment_expected;
case 15 /* ArrayLiteralMembers */: return ts.Diagnostics.Expression_or_comma_expected;
case 16 /* Parameters */: return ts.Diagnostics.Parameter_declaration_expected;
case 17 /* TypeParameters */: return ts.Diagnostics.Type_parameter_declaration_expected;
case 18 /* TypeArguments */: return ts.Diagnostics.Type_argument_expected;
case 19 /* TupleElementTypes */: return ts.Diagnostics.Type_expected;
case 20 /* HeritageClauses */: return ts.Diagnostics.Unexpected_token_expected;
case 21 /* ImportOrExportSpecifiers */: return ts.Diagnostics.Identifier_expected;
case 13 /* JsxAttributes */: return ts.Diagnostics.Identifier_expected;
case 14 /* JsxChildren */: return ts.Diagnostics.Identifier_expected;
case 22 /* JSDocFunctionParameters */: return ts.Diagnostics.Parameter_declaration_expected;
case 23 /* JSDocTypeArguments */: return ts.Diagnostics.Type_argument_expected;
case 25 /* JSDocTupleTypes */: return ts.Diagnostics.Type_expected;
case 24 /* JSDocRecordMembers */: return ts.Diagnostics.Property_assignment_expected;
}
}
;
// Parses a comma-delimited list of elements
function parseDelimitedList(kind, parseElement, considerSemicolonAsDelimeter) {
var saveParsingContext = parsingContext;
parsingContext |= 1 << kind;
var result = [];
result.pos = getNodePos();
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(24 /* 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(24 /* 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 (considerSemicolonAsDelimeter && token === 23 /* 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;
}
function createMissingList() {
var pos = getNodePos();
var result = [];
result.pos = pos;
result.end = pos;
return result;
}
function parseBracketedList(kind, parseElement, open, close) {
if (parseExpected(open)) {
var result = parseDelimitedList(kind, parseElement);
parseExpected(close);
return result;
}
return createMissingList();
}
// The allowReservedWords parameter controls whether reserved words are permitted after the first dot
function parseEntityName(allowReservedWords, diagnosticMessage) {
var entity = parseIdentifier(diagnosticMessage);
while (parseOptional(21 /* DotToken */)) {
var node = createNode(133 /* QualifiedName */, entity.pos);
node.left = entity;
node.right = parseRightSideOfDot(allowReservedWords);
entity = finishNode(node);
}
return entity;
}
function 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() && isIdentifierOrKeyword()) {
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(67 /* Identifier */, /*reportAtCurrentToken*/ true, ts.Diagnostics.Identifier_expected);
}
}
return allowIdentifierNames ? parseIdentifierName() : parseIdentifier();
}
function parseTemplateExpression() {
var template = createNode(181 /* TemplateExpression */);
template.head = parseLiteralNode();
ts.Debug.assert(template.head.kind === 12 /* TemplateHead */, "Template head has wrong token kind");
var templateSpans = [];
templateSpans.pos = getNodePos();
do {
templateSpans.push(parseTemplateSpan());
} while (ts.lastOrUndefined(templateSpans).literal.kind === 13 /* TemplateMiddle */);
templateSpans.end = getNodeEnd();
template.templateSpans = templateSpans;
return finishNode(template);
}
function parseTemplateSpan() {
var span = createNode(188 /* TemplateSpan */);
span.expression = allowInAnd(parseExpression);
var literal;
if (token === 16 /* CloseBraceToken */) {
reScanTemplateToken();
literal = parseLiteralNode();
}
else {
literal = parseExpectedToken(14 /* TemplateTail */, /*reportAtCurrentPosition*/ false, ts.Diagnostics._0_expected, ts.tokenToString(16 /* CloseBraceToken */));
}
span.literal = literal;
return finishNode(span);
}
function parseLiteralNode(internName) {
var node = createNode(token);
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.flags |= 65536 /* OctalLiteral */;
}
return node;
}
// TYPES
function parseTypeReferenceOrTypePredicate() {
var typeName = parseEntityName(/*allowReservedWords*/ false, ts.Diagnostics.Type_expected);
if (typeName.kind === 67 /* Identifier */ && token === 122 /* IsKeyword */ && !scanner.hasPrecedingLineBreak()) {
nextToken();
var node_1 = createNode(148 /* TypePredicate */, typeName.pos);
node_1.parameterName = typeName;
node_1.type = parseType();
return finishNode(node_1);
}
var node = createNode(149 /* TypeReference */, typeName.pos);
node.typeName = typeName;
if (!scanner.hasPrecedingLineBreak() && token === 25 /* LessThanToken */) {
node.typeArguments = parseBracketedList(18 /* TypeArguments */, parseType, 25 /* LessThanToken */, 27 /* GreaterThanToken */);
}
return finishNode(node);
}
function parseTypeQuery() {
var node = createNode(152 /* TypeQuery */);
parseExpected(99 /* TypeOfKeyword */);
node.exprName = parseEntityName(/*allowReservedWords*/ true);
return finishNode(node);
}
function parseTypeParameter() {
var node = createNode(135 /* TypeParameter */);
node.name = parseIdentifier();
if (parseOptional(81 /* 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);
}
function parseTypeParameters() {
if (token === 25 /* LessThanToken */) {
return parseBracketedList(17 /* TypeParameters */, parseTypeParameter, 25 /* LessThanToken */, 27 /* GreaterThanToken */);
}
}
function parseParameterType() {
if (parseOptional(53 /* ColonToken */)) {
return token === 9 /* StringLiteral */
? parseLiteralNode(/*internName*/ true)
: parseType();
}
return undefined;
}
function isStartOfParameter() {
return token === 22 /* DotDotDotToken */ || isIdentifierOrPattern() || ts.isModifier(token) || token === 54 /* AtToken */;
}
function setModifiers(node, modifiers) {
if (modifiers) {
node.flags |= modifiers.flags;
node.modifiers = modifiers;
}
}
function parseParameter() {
var node = createNode(136 /* Parameter */);
node.decorators = parseDecorators();
setModifiers(node, parseModifiers());
node.dotDotDotToken = parseOptionalToken(22 /* DotDotDotToken */);
// FormalParameter [Yield,Await]:
// BindingElement[?Yield,?Await]
node.name = parseIdentifierOrPattern();
if (ts.getFullWidth(node.name) === 0 && node.flags === 0 && ts.isModifier(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(52 /* 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 finishNode(node);
}
function parseBindingElementInitializer(inParameter) {
return inParameter ? parseParameterInitializer() : parseNonParameterInitializer();
}
function parseParameterInitializer() {
return parseInitializer(/*inParameter*/ true);
}
function fillSignature(returnToken, yieldContext, awaitContext, requireCompleteParameterList, signature) {
var returnTokenRequired = returnToken === 34 /* EqualsGreaterThanToken */;
signature.typeParameters = parseTypeParameters();
signature.parameters = parseParameterList(yieldContext, awaitContext, requireCompleteParameterList);
if (returnTokenRequired) {
parseExpected(returnToken);
signature.type = parseType();
}
else if (parseOptional(returnToken)) {
signature.type = parseType();
}
}
function 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(17 /* OpenParenToken */)) {
var savedYieldContext = inYieldContext();
var savedAwaitContext = inAwaitContext();
setYieldContext(yieldContext);
setAwaitContext(awaitContext);
var result = parseDelimitedList(16 /* Parameters */, parseParameter);
setYieldContext(savedYieldContext);
setAwaitContext(savedAwaitContext);
if (!parseExpected(18 /* 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();
}
function 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(24 /* CommaToken */)) {
return;
}
// Didn't have a comma. We must have a (possible ASI) semicolon.
parseSemicolon();
}
function parseSignatureMember(kind) {
var node = createNode(kind);
if (kind === 146 /* ConstructSignature */) {
parseExpected(90 /* NewKeyword */);
}
fillSignature(53 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node);
parseTypeMemberSemicolon();
return finishNode(node);
}
function isIndexSignature() {
if (token !== 19 /* OpenBracketToken */) {
return false;
}
return lookAhead(isUnambiguouslyIndexSignature);
}
function isUnambiguouslyIndexSignature() {
// The only allowed sequence is:
//
// [id:
//
// However, for error recovery, we also check the following cases:
//
// [...
// [id,
// [id?,
// [id?:
// [id?]
// [public id
// [private id
// [protected id
// []
//
nextToken();
if (token === 22 /* DotDotDotToken */ || token === 20 /* CloseBracketToken */) {
return true;
}
if (ts.isModifier(token)) {
nextToken();
if (isIdentifier()) {
return true;
}
}
else if (!isIdentifier()) {
return false;
}
else {
// Skip the identifier
nextToken();
}
// A colon signifies a well formed indexer
// A comma should be a badly formed indexer because comma expressions are not allowed
// in computed properties.
if (token === 53 /* ColonToken */ || token === 24 /* CommaToken */) {
return true;
}
// Question mark could be an indexer with an optional property,
// or it could be a conditional expression in a computed property.
if (token !== 52 /* QuestionToken */) {
return false;
}
// If any of the following tokens are after the question mark, it cannot
// be a conditional expression, so treat it as an indexer.
nextToken();
return token === 53 /* ColonToken */ || token === 24 /* CommaToken */ || token === 20 /* CloseBracketToken */;
}
function parseIndexSignatureDeclaration(fullStart, decorators, modifiers) {
var node = createNode(147 /* IndexSignature */, fullStart);
node.decorators = decorators;
setModifiers(node, modifiers);
node.parameters = parseBracketedList(16 /* Parameters */, parseParameter, 19 /* OpenBracketToken */, 20 /* CloseBracketToken */);
node.type = parseTypeAnnotation();
parseTypeMemberSemicolon();
return finishNode(node);
}
function parsePropertyOrMethodSignature() {
var fullStart = scanner.getStartPos();
var name = parsePropertyName();
var questionToken = parseOptionalToken(52 /* QuestionToken */);
if (token === 17 /* OpenParenToken */ || token === 25 /* LessThanToken */) {
var method = createNode(140 /* MethodSignature */, fullStart);
method.name = name;
method.questionToken = questionToken;
// Method signatues don't exist in expression contexts. So they have neither
// [Yield] nor [Await]
fillSignature(53 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, method);
parseTypeMemberSemicolon();
return finishNode(method);
}
else {
var property = createNode(138 /* PropertySignature */, fullStart);
property.name = name;
property.questionToken = questionToken;
property.type = parseTypeAnnotation();
parseTypeMemberSemicolon();
return finishNode(property);
}
}
function isStartOfTypeMember() {
switch (token) {
case 17 /* OpenParenToken */:
case 25 /* LessThanToken */:
case 19 /* OpenBracketToken */:
return true;
default:
if (ts.isModifier(token)) {
var result = lookAhead(isStartOfIndexSignatureDeclaration);
if (result) {
return result;
}
}
return isLiteralPropertyName() && lookAhead(isTypeMemberWithLiteralPropertyName);
}
}
function isStartOfIndexSignatureDeclaration() {
while (ts.isModifier(token)) {
nextToken();
}
return isIndexSignature();
}
function isTypeMemberWithLiteralPropertyName() {
nextToken();
return token === 17 /* OpenParenToken */ ||
token === 25 /* LessThanToken */ ||
token === 52 /* QuestionToken */ ||
token === 53 /* ColonToken */ ||
canParseSemicolon();
}
function parseTypeMember() {
switch (token) {
case 17 /* OpenParenToken */:
case 25 /* LessThanToken */:
return parseSignatureMember(145 /* CallSignature */);
case 19 /* OpenBracketToken */:
// Indexer or computed property
return isIndexSignature()
? parseIndexSignatureDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined)
: parsePropertyOrMethodSignature();
case 90 /* NewKeyword */:
if (lookAhead(isStartOfConstructSignature)) {
return parseSignatureMember(146 /* ConstructSignature */);
}
// fall through.
case 9 /* StringLiteral */:
case 8 /* NumericLiteral */:
return parsePropertyOrMethodSignature();
default:
// Index declaration as allowed as a type member. But as per the grammar,
// they also allow modifiers. So we have to check for an index declaration
// that might be following modifiers. This ensures that things work properly
// when incrementally parsing as the parser will produce the Index declaration
// if it has the same text regardless of whether it is inside a class or an
// object type.
if (ts.isModifier(token)) {
var result = tryParse(parseIndexSignatureWithModifiers);
if (result) {
return result;
}
}
if (isIdentifierOrKeyword()) {
return parsePropertyOrMethodSignature();
}
}
}
function parseIndexSignatureWithModifiers() {
var fullStart = scanner.getStartPos();
var decorators = parseDecorators();
var modifiers = parseModifiers();
return isIndexSignature()
? parseIndexSignatureDeclaration(fullStart, decorators, modifiers)
: undefined;
}
function isStartOfConstructSignature() {
nextToken();
return token === 17 /* OpenParenToken */ || token === 25 /* LessThanToken */;
}
function parseTypeLiteral() {
var node = createNode(153 /* TypeLiteral */);
node.members = parseObjectTypeMembers();
return finishNode(node);
}
function parseObjectTypeMembers() {
var members;
if (parseExpected(15 /* OpenBraceToken */)) {
members = parseList(4 /* TypeMembers */, parseTypeMember);
parseExpected(16 /* CloseBraceToken */);
}
else {
members = createMissingList();
}
return members;
}
function parseTupleType() {
var node = createNode(155 /* TupleType */);
node.elementTypes = parseBracketedList(19 /* TupleElementTypes */, parseType, 19 /* OpenBracketToken */, 20 /* CloseBracketToken */);
return finishNode(node);
}
function parseParenthesizedType() {
var node = createNode(158 /* ParenthesizedType */);
parseExpected(17 /* OpenParenToken */);
node.type = parseType();
parseExpected(18 /* CloseParenToken */);
return finishNode(node);
}
function parseFunctionOrConstructorType(kind) {
var node = createNode(kind);
if (kind === 151 /* ConstructorType */) {
parseExpected(90 /* NewKeyword */);
}
fillSignature(34 /* EqualsGreaterThanToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node);
return finishNode(node);
}
function parseKeywordAndNoDot() {
var node = parseTokenNode();
return token === 21 /* DotToken */ ? undefined : node;
}
function parseNonArrayType() {
switch (token) {
case 115 /* AnyKeyword */:
case 128 /* StringKeyword */:
case 126 /* NumberKeyword */:
case 118 /* BooleanKeyword */:
case 129 /* SymbolKeyword */:
// If these are followed by a dot, then parse these out as a dotted type reference instead.
var node = tryParse(parseKeywordAndNoDot);
return node || parseTypeReferenceOrTypePredicate();
case 101 /* VoidKeyword */:
return parseTokenNode();
case 99 /* TypeOfKeyword */:
return parseTypeQuery();
case 15 /* OpenBraceToken */:
return parseTypeLiteral();
case 19 /* OpenBracketToken */:
return parseTupleType();
case 17 /* OpenParenToken */:
return parseParenthesizedType();
default:
return parseTypeReferenceOrTypePredicate();
}
}
function isStartOfType() {
switch (token) {
case 115 /* AnyKeyword */:
case 128 /* StringKeyword */:
case 126 /* NumberKeyword */:
case 118 /* BooleanKeyword */:
case 129 /* SymbolKeyword */:
case 101 /* VoidKeyword */:
case 99 /* TypeOfKeyword */:
case 15 /* OpenBraceToken */:
case 19 /* OpenBracketToken */:
case 25 /* LessThanToken */:
case 90 /* NewKeyword */:
return true;
case 17 /* 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();
}
}
function isStartOfParenthesizedOrFunctionType() {
nextToken();
return token === 18 /* CloseParenToken */ || isStartOfParameter() || isStartOfType();
}
function parseArrayTypeOrHigher() {
var type = parseNonArrayType();
while (!scanner.hasPrecedingLineBreak() && parseOptional(19 /* OpenBracketToken */)) {
parseExpected(20 /* CloseBracketToken */);
var node = createNode(154 /* ArrayType */, type.pos);
node.elementType = type;
type = finishNode(node);
}
return type;
}
function parseUnionOrIntersectionType(kind, parseConstituentType, operator) {
var type = parseConstituentType();
if (token === operator) {
var types = [type];
types.pos = type.pos;
while (parseOptional(operator)) {
types.push(parseConstituentType());
}
types.end = getNodeEnd();
var node = createNode(kind, type.pos);
node.types = types;
type = finishNode(node);
}
return type;
}
function parseIntersectionTypeOrHigher() {
return parseUnionOrIntersectionType(157 /* IntersectionType */, parseArrayTypeOrHigher, 45 /* AmpersandToken */);
}
function parseUnionTypeOrHigher() {
return parseUnionOrIntersectionType(156 /* UnionType */, parseIntersectionTypeOrHigher, 46 /* BarToken */);
}
function isStartOfFunctionType() {
if (token === 25 /* LessThanToken */) {
return true;
}
return token === 17 /* OpenParenToken */ && lookAhead(isUnambiguouslyStartOfFunctionType);
}
function isUnambiguouslyStartOfFunctionType() {
nextToken();
if (token === 18 /* CloseParenToken */ || token === 22 /* DotDotDotToken */) {
// ( )
// ( ...
return true;
}
if (isIdentifier() || ts.isModifier(token)) {
nextToken();
if (token === 53 /* ColonToken */ || token === 24 /* CommaToken */ ||
token === 52 /* QuestionToken */ || token === 55 /* EqualsToken */ ||
isIdentifier() || ts.isModifier(token)) {
// ( id :
// ( id ,
// ( id ?
// ( id =
// ( modifier id
return true;
}
if (token === 18 /* CloseParenToken */) {
nextToken();
if (token === 34 /* EqualsGreaterThanToken */) {
// ( id ) =>
return true;
}
}
}
return false;
}
function 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(10 /* TypeExcludesFlags */, parseTypeWorker);
}
function parseTypeWorker() {
if (isStartOfFunctionType()) {
return parseFunctionOrConstructorType(150 /* FunctionType */);
}
if (token === 90 /* NewKeyword */) {
return parseFunctionOrConstructorType(151 /* ConstructorType */);
}
return parseUnionTypeOrHigher();
}
function parseTypeAnnotation() {
return parseOptional(53 /* ColonToken */) ? parseType() : undefined;
}
// EXPRESSIONS
function isStartOfLeftHandSideExpression() {
switch (token) {
case 95 /* ThisKeyword */:
case 93 /* SuperKeyword */:
case 91 /* NullKeyword */:
case 97 /* TrueKeyword */:
case 82 /* FalseKeyword */:
case 8 /* NumericLiteral */:
case 9 /* StringLiteral */:
case 11 /* NoSubstitutionTemplateLiteral */:
case 12 /* TemplateHead */:
case 17 /* OpenParenToken */:
case 19 /* OpenBracketToken */:
case 15 /* OpenBraceToken */:
case 85 /* FunctionKeyword */:
case 71 /* ClassKeyword */:
case 90 /* NewKeyword */:
case 38 /* SlashToken */:
case 59 /* SlashEqualsToken */:
case 67 /* Identifier */:
return true;
default:
return isIdentifier();
}
}
function isStartOfExpression() {
if (isStartOfLeftHandSideExpression()) {
return true;
}
switch (token) {
case 35 /* PlusToken */:
case 36 /* MinusToken */:
case 49 /* TildeToken */:
case 48 /* ExclamationToken */:
case 76 /* DeleteKeyword */:
case 99 /* TypeOfKeyword */:
case 101 /* VoidKeyword */:
case 40 /* PlusPlusToken */:
case 41 /* MinusMinusToken */:
case 25 /* LessThanToken */:
case 117 /* AwaitKeyword */:
case 112 /* 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();
}
}
function isStartOfExpressionStatement() {
// As per the grammar, none of '{' or 'function' or 'class' can start an expression statement.
return token !== 15 /* OpenBraceToken */ &&
token !== 85 /* FunctionKeyword */ &&
token !== 71 /* ClassKeyword */ &&
token !== 54 /* AtToken */ &&
isStartOfExpression();
}
function allowInAndParseExpression() {
return allowInAnd(parseExpression);
}
function parseExpression() {
// Expression[in]:
// AssignmentExpression[in]
// Expression[in] , AssignmentExpression[in]
// clear the decorator context when parsing Expression, as it should be unambiguous when parsing a decorator
var saveDecoratorContext = inDecoratorContext();
if (saveDecoratorContext) {
setDecoratorContext(false);
}
var expr = parseAssignmentExpressionOrHigher();
var operatorToken;
while ((operatorToken = parseOptionalToken(24 /* CommaToken */))) {
expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher());
}
if (saveDecoratorContext) {
setDecoratorContext(true);
}
return expr;
}
function parseInitializer(inParameter) {
if (token !== 55 /* 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 === 15 /* 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(55 /* EqualsToken */);
return parseAssignmentExpressionOrHigher();
}
function parseAssignmentExpressionOrHigher() {
// AssignmentExpression[in,yield]:
// 1) ConditionalExpression[?in,?yield]
// 2) LeftHandSideExpression = AssignmentExpression[?in,?yield]
// 3) LeftHandSideExpression AssignmentOperator AssignmentExpression[?in,?yield]
// 4) ArrowFunctionExpression[?in,?yield]
// 5) [+Yield] YieldExpression[?In]
//
// Note: for ease of implementation we treat productions '2' and '3' as the same thing.
// (i.e. they're both BinaryExpressions with an assignment operator in it).
// First, do the simple check if we have a YieldExpression (production '5').
if (isYieldExpression()) {
return parseYieldExpression();
}
// Then, check if we have an arrow function (production '4') that starts with a parenthesized
// parameter list. If we do, we must *not* recurse for productions 1, 2 or 3. An ArrowFunction is
// not a LeftHandSideExpression, nor does it start a ConditionalExpression. So we are done
// with AssignmentExpression if we see one.
var arrowExpression = tryParseParenthesizedArrowFunctionExpression();
if (arrowExpression) {
return arrowExpression;
}
// Now try to see if we're in production '1', '2' or '3'. A conditional expression can
// start with a LogicalOrExpression, while the assignment productions can only start with
// LeftHandSideExpressions.
//
// So, first, we try to just parse out a BinaryExpression. If we get something that is a
// LeftHandSide or higher, then we can try to parse out the assignment expression part.
// Otherwise, we try to parse out the conditional expression bit. We want to allow any
// binary expression here, so we pass in the 'lowest' precedence here so that it matches
// and consumes anything.
var expr = parseBinaryExpressionOrHigher(/*precedence*/ 0);
// To avoid a look-ahead, we did not handle the case of an arrow function with a single un-parenthesized
// parameter ('x => ...') above. We handle it here by checking if the parsed expression was a single
// identifier and the current token is an arrow.
if (expr.kind === 67 /* Identifier */ && token === 34 /* EqualsGreaterThanToken */) {
return parseSimpleArrowFunctionExpression(expr);
}
// Now see if we might be in cases '2' or '3'.
// If the expression was a LHS expression, and we have an assignment operator, then
// we're in '2' or '3'. Consume the assignment and return.
//
// Note: we call reScanGreaterToken so that we get an appropriately merged token
// for cases like > > = becoming >>=
if (ts.isLeftHandSideExpression(expr) && ts.isAssignmentOperator(reScanGreaterToken())) {
return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher());
}
// It wasn't an assignment or a lambda. This is a conditional expression:
return parseConditionalExpressionRest(expr);
}
function isYieldExpression() {
if (token === 112 /* YieldKeyword */) {
// If we have a 'yield' keyword, and htis is a context where yield expressions are
// allowed, then definitely parse out a yield expression.
if (inYieldContext()) {
return true;
}
// We're in a context where 'yield expr' is not allowed. However, if we can
// definitely tell that the user was trying to parse a 'yield expr' and not
// just a normal expr that start with a 'yield' identifier, then parse out
// a 'yield expr'. We can then report an error later that they are only
// allowed in generator expressions.
//
// for example, if we see 'yield(foo)', then we'll have to treat that as an
// invocation expression of something called 'yield'. However, if we have
// 'yield foo' then that is not legal as a normal expression, so we can
// definitely recognize this as a yield expression.
//
// for now we just check if the next token is an identifier. More heuristics
// can be added here later as necessary. We just need to make sure that we
// don't accidently consume something legal.
return lookAhead(nextTokenIsIdentifierOrKeywordOrNumberOnSameLine);
}
return false;
}
function nextTokenIsIdentifierOnSameLine() {
nextToken();
return !scanner.hasPrecedingLineBreak() && isIdentifier();
}
function parseYieldExpression() {
var node = createNode(182 /* YieldExpression */);
// YieldExpression[In] :
// yield
// yield [no LineTerminator here] [Lexical goal InputElementRegExp]AssignmentExpression[?In, Yield]
// yield [no LineTerminator here] * [Lexical goal InputElementRegExp]AssignmentExpression[?In, Yield]
nextToken();
if (!scanner.hasPrecedingLineBreak() &&
(token === 37 /* AsteriskToken */ || isStartOfExpression())) {
node.asteriskToken = parseOptionalToken(37 /* AsteriskToken */);
node.expression = parseAssignmentExpressionOrHigher();
return finishNode(node);
}
else {
// if the next token is not on the same line as yield. or we don't have an '*' or
// the start of an expressin, then this is just a simple "yield" expression.
return finishNode(node);
}
}
function parseSimpleArrowFunctionExpression(identifier) {
ts.Debug.assert(token === 34 /* EqualsGreaterThanToken */, "parseSimpleArrowFunctionExpression should only have been called if we had a =>");
var node = createNode(172 /* ArrowFunction */, identifier.pos);
var parameter = createNode(136 /* Parameter */, identifier.pos);
parameter.name = identifier;
finishNode(parameter);
node.parameters = [parameter];
node.parameters.pos = parameter.pos;
node.parameters.end = parameter.end;
node.equalsGreaterThanToken = parseExpectedToken(34 /* EqualsGreaterThanToken */, false, ts.Diagnostics._0_expected, "=>");
node.body = parseArrowFunctionExpressionBody(/*isAsync*/ false);
return finishNode(node);
}
function tryParseParenthesizedArrowFunctionExpression() {
var triState = isParenthesizedArrowFunctionExpression();
if (triState === 0 /* False */) {
// It's definitely not a parenthesized arrow function expression.
return undefined;
}
// If we definitely have an arrow function, then we can just parse one, not requiring a
// following => or { token. Otherwise, we *might* have an arrow function. Try to parse
// it out, but don't allow any ambiguity, and return 'undefined' if this could be an
// expression instead.
var arrowFunction = triState === 1 /* True */
? parseParenthesizedArrowFunctionExpressionHead(/*allowAmbiguity*/ true)
: tryParse(parsePossibleParenthesizedArrowFunctionExpressionHead);
if (!arrowFunction) {
// Didn't appear to actually be a parenthesized arrow function. Just bail out.
return undefined;
}
var isAsync = !!(arrowFunction.flags & 512 /* Async */);
// If we have an arrow, then try to parse the body. Even if not, try to parse if we
// have an opening brace, just in case we're in an error state.
var lastToken = token;
arrowFunction.equalsGreaterThanToken = parseExpectedToken(34 /* EqualsGreaterThanToken */, /*reportAtCurrentPosition*/ false, ts.Diagnostics._0_expected, "=>");
arrowFunction.body = (lastToken === 34 /* EqualsGreaterThanToken */ || lastToken === 15 /* OpenBraceToken */)
? parseArrowFunctionExpressionBody(isAsync)
: parseIdentifier();
return finishNode(arrowFunction);
}
// True -> We definitely expect a parenthesized arrow function here.
// False -> There *cannot* be a parenthesized arrow function here.
// Unknown -> There *might* be a parenthesized arrow function here.
// Speculatively look ahead to be sure, and rollback if not.
function isParenthesizedArrowFunctionExpression() {
if (token === 17 /* OpenParenToken */ || token === 25 /* LessThanToken */ || token === 116 /* AsyncKeyword */) {
return lookAhead(isParenthesizedArrowFunctionExpressionWorker);
}
if (token === 34 /* EqualsGreaterThanToken */) {
// ERROR RECOVERY TWEAK:
// If we see a standalone => try to parse it as an arrow function expression as that's
// likely what the user intended to write.
return 1 /* True */;
}
// Definitely not a parenthesized arrow function.
return 0 /* False */;
}
function isParenthesizedArrowFunctionExpressionWorker() {
if (token === 116 /* AsyncKeyword */) {
nextToken();
if (scanner.hasPrecedingLineBreak()) {
return 0 /* False */;
}
if (token !== 17 /* OpenParenToken */ && token !== 25 /* LessThanToken */) {
return 0 /* False */;
}
}
var first = token;
var second = nextToken();
if (first === 17 /* OpenParenToken */) {
if (second === 18 /* CloseParenToken */) {
// Simple cases: "() =>", "(): ", and "() {".
// This is an arrow function with no parameters.
// The last one is not actually an arrow function,
// but this is probably what the user intended.
var third = nextToken();
switch (third) {
case 34 /* EqualsGreaterThanToken */:
case 53 /* ColonToken */:
case 15 /* OpenBraceToken */:
return 1 /* True */;
default:
return 0 /* False */;
}
}
// If encounter "([" or "({", this could be the start of a binding pattern.
// Examples:
// ([ x ]) => { }
// ({ x }) => { }
// ([ x ])
// ({ x })
if (second === 19 /* OpenBracketToken */ || second === 15 /* OpenBraceToken */) {
return 2 /* Unknown */;
}
// Simple case: "(..."
// This is an arrow function with a rest parameter.
if (second === 22 /* DotDotDotToken */) {
return 1 /* True */;
}
// If we had "(" followed by something that's not an identifier,
// then this definitely doesn't look like a lambda.
// Note: we could be a little more lenient and allow
// "(public" or "(private". These would not ever actually be allowed,
// but we could provide a good error message instead of bailing out.
if (!isIdentifier()) {
return 0 /* False */;
}
// If we have something like "(a:", then we must have a
// type-annotated parameter in an arrow function expression.
if (nextToken() === 53 /* ColonToken */) {
return 1 /* True */;
}
// This *could* be a parenthesized arrow function.
// Return Unknown to let the caller know.
return 2 /* Unknown */;
}
else {
ts.Debug.assert(first === 25 /* LessThanToken */);
// If we have "<" not followed by an identifier,
// then this definitely is not an arrow function.
if (!isIdentifier()) {
return 0 /* False */;
}
// JSX overrides
if (sourceFile.languageVariant === 1 /* JSX */) {
var isArrowFunctionInJsx = lookAhead(function () {
var third = nextToken();
if (third === 81 /* ExtendsKeyword */) {
var fourth = nextToken();
switch (fourth) {
case 55 /* EqualsToken */:
case 27 /* GreaterThanToken */:
return false;
default:
return true;
}
}
else if (third === 24 /* CommaToken */) {
return true;
}
return false;
});
if (isArrowFunctionInJsx) {
return 1 /* True */;
}
return 0 /* False */;
}
// This *could* be a parenthesized arrow function.
return 2 /* Unknown */;
}
}
function parsePossibleParenthesizedArrowFunctionExpressionHead() {
return parseParenthesizedArrowFunctionExpressionHead(/*allowAmbiguity*/ false);
}
function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity) {
var node = createNode(172 /* ArrowFunction */);
setModifiers(node, parseModifiersForArrowFunction());
var isAsync = !!(node.flags & 512 /* Async */);
// Arrow functions are never generators.
//
// If we're speculatively parsing a signature for a parenthesized arrow function, then
// we have to have a complete parameter list. Otherwise we might see something like
// a => (b => c)
// And think that "(b =>" was actually a parenthesized arrow function with a missing
// close paren.
fillSignature(53 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ !allowAmbiguity, node);
// If we couldn't get parameters, we definitely could not parse out an arrow function.
if (!node.parameters) {
return undefined;
}
// Parsing a signature isn't enough.
// Parenthesized arrow signatures often look like other valid expressions.
// For instance:
// - "(x = 10)" is an assignment expression parsed as a signature with a default parameter value.
// - "(x,y)" is a comma expression parsed as a signature with two parameters.
// - "a ? (b): c" will have "(b):" parsed as a signature with a return type annotation.
//
// So we need just a bit of lookahead to ensure that it can only be a signature.
if (!allowAmbiguity && token !== 34 /* EqualsGreaterThanToken */ && token !== 15 /* OpenBraceToken */) {
// Returning undefined here will cause our caller to rewind to where we started from.
return undefined;
}
return node;
}
function parseArrowFunctionExpressionBody(isAsync) {
if (token === 15 /* OpenBraceToken */) {
return parseFunctionBlock(/*allowYield*/ false, /*allowAwait*/ isAsync, /*ignoreMissingOpenBrace*/ false);
}
if (token !== 23 /* SemicolonToken */ &&
token !== 85 /* FunctionKeyword */ &&
token !== 71 /* ClassKeyword */ &&
isStartOfStatement() &&
!isStartOfExpressionStatement()) {
// Check if we got a plain statement (i.e. no expression-statements, no function/class expressions/declarations)
//
// Here we try to recover from a potential error situation in the case where the
// user meant to supply a block. For example, if the user wrote:
//
// a =>
// let v = 0;
// }
//
// they may be missing an open brace. Check to see if that's the case so we can
// try to recover better. If we don't do this, then the next close curly we see may end
// up preemptively closing the containing construct.
//
// Note: even when 'ignoreMissingOpenBrace' is passed as true, parseBody will still error.
return parseFunctionBlock(/*allowYield*/ false, /*allowAwait*/ isAsync, /*ignoreMissingOpenBrace*/ true);
}
return isAsync
? doInAwaitContext(parseAssignmentExpressionOrHigher)
: doOutsideOfAwaitContext(parseAssignmentExpressionOrHigher);
}
function parseConditionalExpressionRest(leftOperand) {
// Note: we are passed in an expression which was produced from parseBinaryExpressionOrHigher.
var questionToken = parseOptionalToken(52 /* QuestionToken */);
if (!questionToken) {
return leftOperand;
}
// Note: we explicitly 'allowIn' in the whenTrue part of the condition expression, and
// we do not that for the 'whenFalse' part.
var node = createNode(180 /* ConditionalExpression */, leftOperand.pos);
node.condition = leftOperand;
node.questionToken = questionToken;
node.whenTrue = doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher);
node.colonToken = parseExpectedToken(53 /* ColonToken */, /*reportAtCurrentPosition*/ false, ts.Diagnostics._0_expected, ts.tokenToString(53 /* ColonToken */));
node.whenFalse = parseAssignmentExpressionOrHigher();
return finishNode(node);
}
function parseBinaryExpressionOrHigher(precedence) {
var leftOperand = parseUnaryExpressionOrHigher();
return parseBinaryExpressionRest(precedence, leftOperand);
}
function isInOrOfKeyword(t) {
return t === 88 /* InKeyword */ || t === 132 /* OfKeyword */;
}
function parseBinaryExpressionRest(precedence, leftOperand) {
while (true) {
// We either have a binary operator here, or we're finished. We call
// reScanGreaterToken so that we merge token sequences like > and = into >=
reScanGreaterToken();
var newPrecedence = getBinaryOperatorPrecedence();
// Check the precedence to see if we should "take" this operator
if (newPrecedence <= precedence) {
break;
}
if (token === 88 /* InKeyword */ && inDisallowInContext()) {
break;
}
if (token === 114 /* AsKeyword */) {
// Make sure we *do* perform ASI for constructs like this:
// var x = foo
// as (Bar)
// This should be parsed as an initialized variable, followed
// by a function call to 'as' with the argument 'Bar'
if (scanner.hasPrecedingLineBreak()) {
break;
}
else {
nextToken();
leftOperand = makeAsExpression(leftOperand, parseType());
}
}
else {
leftOperand = makeBinaryExpression(leftOperand, parseTokenNode(), parseBinaryExpressionOrHigher(newPrecedence));
}
}
return leftOperand;
}
function isBinaryOperator() {
if (inDisallowInContext() && token === 88 /* InKeyword */) {
return false;
}
return getBinaryOperatorPrecedence() > 0;
}
function getBinaryOperatorPrecedence() {
switch (token) {
case 51 /* BarBarToken */:
return 1;
case 50 /* AmpersandAmpersandToken */:
return 2;
case 46 /* BarToken */:
return 3;
case 47 /* CaretToken */:
return 4;
case 45 /* AmpersandToken */:
return 5;
case 30 /* EqualsEqualsToken */:
case 31 /* ExclamationEqualsToken */:
case 32 /* EqualsEqualsEqualsToken */:
case 33 /* ExclamationEqualsEqualsToken */:
return 6;
case 25 /* LessThanToken */:
case 27 /* GreaterThanToken */:
case 28 /* LessThanEqualsToken */:
case 29 /* GreaterThanEqualsToken */:
case 89 /* InstanceOfKeyword */:
case 88 /* InKeyword */:
case 114 /* AsKeyword */:
return 7;
case 42 /* LessThanLessThanToken */:
case 43 /* GreaterThanGreaterThanToken */:
case 44 /* GreaterThanGreaterThanGreaterThanToken */:
return 8;
case 35 /* PlusToken */:
case 36 /* MinusToken */:
return 9;
case 37 /* AsteriskToken */:
case 38 /* SlashToken */:
case 39 /* PercentToken */:
return 10;
}
// -1 is lower than all other precedences. Returning it will cause binary expression
// parsing to stop.
return -1;
}
function makeBinaryExpression(left, operatorToken, right) {
var node = createNode(179 /* BinaryExpression */, left.pos);
node.left = left;
node.operatorToken = operatorToken;
node.right = right;
return finishNode(node);
}
function makeAsExpression(left, right) {
var node = createNode(187 /* AsExpression */, left.pos);
node.expression = left;
node.type = right;
return finishNode(node);
}
function parsePrefixUnaryExpression() {
var node = createNode(177 /* PrefixUnaryExpression */);
node.operator = token;
nextToken();
node.operand = parseUnaryExpressionOrHigher();
return finishNode(node);
}
function parseDeleteExpression() {
var node = createNode(173 /* DeleteExpression */);
nextToken();
node.expression = parseUnaryExpressionOrHigher();
return finishNode(node);
}
function parseTypeOfExpression() {
var node = createNode(174 /* TypeOfExpression */);
nextToken();
node.expression = parseUnaryExpressionOrHigher();
return finishNode(node);
}
function parseVoidExpression() {
var node = createNode(175 /* VoidExpression */);
nextToken();
node.expression = parseUnaryExpressionOrHigher();
return finishNode(node);
}
function isAwaitExpression() {
if (token === 117 /* AwaitKeyword */) {
if (inAwaitContext()) {
return true;
}
// here we are using similar heuristics as 'isYieldExpression'
return lookAhead(nextTokenIsIdentifierOnSameLine);
}
return false;
}
function parseAwaitExpression() {
var node = createNode(176 /* AwaitExpression */);
nextToken();
node.expression = parseUnaryExpressionOrHigher();
return finishNode(node);
}
function parseUnaryExpressionOrHigher() {
if (isAwaitExpression()) {
return parseAwaitExpression();
}
switch (token) {
case 35 /* PlusToken */:
case 36 /* MinusToken */:
case 49 /* TildeToken */:
case 48 /* ExclamationToken */:
case 40 /* PlusPlusToken */:
case 41 /* MinusMinusToken */:
return parsePrefixUnaryExpression();
case 76 /* DeleteKeyword */:
return parseDeleteExpression();
case 99 /* TypeOfKeyword */:
return parseTypeOfExpression();
case 101 /* VoidKeyword */:
return parseVoidExpression();
case 25 /* LessThanToken */:
if (sourceFile.languageVariant !== 1 /* JSX */) {
return parseTypeAssertion();
}
if (lookAhead(nextTokenIsIdentifierOrKeyword)) {
return parseJsxElementOrSelfClosingElement(/*inExpressionContext*/ true);
}
// Fall through
default:
return parsePostfixExpressionOrHigher();
}
}
function parsePostfixExpressionOrHigher() {
var expression = parseLeftHandSideExpressionOrHigher();
ts.Debug.assert(ts.isLeftHandSideExpression(expression));
if ((token === 40 /* PlusPlusToken */ || token === 41 /* MinusMinusToken */) && !scanner.hasPrecedingLineBreak()) {
var node = createNode(178 /* PostfixUnaryExpression */, expression.pos);
node.operand = expression;
node.operator = token;
nextToken();
return finishNode(node);
}
return expression;
}
function 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 === 93 /* 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);
}
function 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);
}
function parseSuperExpression() {
var expression = parseTokenNode();
if (token === 17 /* OpenParenToken */ || token === 21 /* DotToken */ || token === 19 /* OpenBracketToken */) {
return expression;
}
// If we have seen "super" it must be followed by '(' or '.'.
// If it wasn't then just try to parse out a '.' and report an error.
var node = createNode(164 /* PropertyAccessExpression */, expression.pos);
node.expression = expression;
node.dotToken = parseExpectedToken(21 /* DotToken */, /*reportAtCurrentPosition*/ false, ts.Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access);
node.name = parseRightSideOfDot(/*allowIdentifierNames*/ true);
return finishNode(node);
}
function parseJsxElementOrSelfClosingElement(inExpressionContext) {
var opening = parseJsxOpeningOrSelfClosingElement(inExpressionContext);
if (opening.kind === 233 /* JsxOpeningElement */) {
var node = createNode(231 /* JsxElement */, opening.pos);
node.openingElement = opening;
node.children = parseJsxChildren(node.openingElement.tagName);
node.closingElement = parseJsxClosingElement(inExpressionContext);
return finishNode(node);
}
else {
ts.Debug.assert(opening.kind === 232 /* JsxSelfClosingElement */);
// Nothing else to do for self-closing elements
return opening;
}
}
function parseJsxText() {
var node = createNode(234 /* JsxText */, scanner.getStartPos());
token = scanner.scanJsxToken();
return finishNode(node);
}
function parseJsxChild() {
switch (token) {
case 234 /* JsxText */:
return parseJsxText();
case 15 /* OpenBraceToken */:
return parseJsxExpression(/*inExpressionContext*/ false);
case 25 /* LessThanToken */:
return parseJsxElementOrSelfClosingElement(/*inExpressionContext*/ false);
}
ts.Debug.fail("Unknown JSX child kind " + token);
}
function parseJsxChildren(openingTagName) {
var result = [];
result.pos = scanner.getStartPos();
var saveParsingContext = parsingContext;
parsingContext |= 1 << 14 /* JsxChildren */;
while (true) {
token = scanner.reScanJsxToken();
if (token === 26 /* LessThanSlashToken */) {
break;
}
else if (token === 1 /* EndOfFileToken */) {
parseErrorAtCurrentToken(ts.Diagnostics.Expected_corresponding_JSX_closing_tag_for_0, ts.getTextOfNodeFromSourceText(sourceText, openingTagName));
break;
}
result.push(parseJsxChild());
}
result.end = scanner.getTokenPos();
parsingContext = saveParsingContext;
return result;
}
function parseJsxOpeningOrSelfClosingElement(inExpressionContext) {
var fullStart = scanner.getStartPos();
parseExpected(25 /* LessThanToken */);
var tagName = parseJsxElementName();
var attributes = parseList(13 /* JsxAttributes */, parseJsxAttribute);
var node;
if (token === 27 /* GreaterThanToken */) {
// Closing tag, so scan the immediately-following text with the JSX scanning instead
// of regular scanning to avoid treating illegal characters (e.g. '#') as immediate
// scanning errors
node = createNode(233 /* JsxOpeningElement */, fullStart);
scanJsxText();
}
else {
parseExpected(38 /* SlashToken */);
if (inExpressionContext) {
parseExpected(27 /* GreaterThanToken */);
}
else {
parseExpected(27 /* GreaterThanToken */, /*diagnostic*/ undefined, /*advance*/ false);
scanJsxText();
}
node = createNode(232 /* JsxSelfClosingElement */, fullStart);
}
node.tagName = tagName;
node.attributes = attributes;
return finishNode(node);
}
function parseJsxElementName() {
scanJsxIdentifier();
var elementName = parseIdentifierName();
while (parseOptional(21 /* DotToken */)) {
scanJsxIdentifier();
var node = createNode(133 /* QualifiedName */, elementName.pos);
node.left = elementName;
node.right = parseIdentifierName();
elementName = finishNode(node);
}
return elementName;
}
function parseJsxExpression(inExpressionContext) {
var node = createNode(238 /* JsxExpression */);
parseExpected(15 /* OpenBraceToken */);
if (token !== 16 /* CloseBraceToken */) {
node.expression = parseExpression();
}
if (inExpressionContext) {
parseExpected(16 /* CloseBraceToken */);
}
else {
parseExpected(16 /* CloseBraceToken */, /*message*/ undefined, /*advance*/ false);
scanJsxText();
}
return finishNode(node);
}
function parseJsxAttribute() {
if (token === 15 /* OpenBraceToken */) {
return parseJsxSpreadAttribute();
}
scanJsxIdentifier();
var node = createNode(236 /* JsxAttribute */);
node.name = parseIdentifierName();
if (parseOptional(55 /* EqualsToken */)) {
switch (token) {
case 9 /* StringLiteral */:
node.initializer = parseLiteralNode();
break;
default:
node.initializer = parseJsxExpression(/*inExpressionContext*/ true);
break;
}
}
return finishNode(node);
}
function parseJsxSpreadAttribute() {
var node = createNode(237 /* JsxSpreadAttribute */);
parseExpected(15 /* OpenBraceToken */);
parseExpected(22 /* DotDotDotToken */);
node.expression = parseExpression();
parseExpected(16 /* CloseBraceToken */);
return finishNode(node);
}
function parseJsxClosingElement(inExpressionContext) {
var node = createNode(235 /* JsxClosingElement */);
parseExpected(26 /* LessThanSlashToken */);
node.tagName = parseJsxElementName();
if (inExpressionContext) {
parseExpected(27 /* GreaterThanToken */);
}
else {
parseExpected(27 /* GreaterThanToken */, /*diagnostic*/ undefined, /*advance*/ false);
scanJsxText();
}
return finishNode(node);
}
function parseTypeAssertion() {
var node = createNode(169 /* TypeAssertionExpression */);
parseExpected(25 /* LessThanToken */);
node.type = parseType();
parseExpected(27 /* GreaterThanToken */);
node.expression = parseUnaryExpressionOrHigher();
return finishNode(node);
}
function parseMemberExpressionRest(expression) {
while (true) {
var dotToken = parseOptionalToken(21 /* DotToken */);
if (dotToken) {
var propertyAccess = createNode(164 /* PropertyAccessExpression */, expression.pos);
propertyAccess.expression = expression;
propertyAccess.dotToken = dotToken;
propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true);
expression = finishNode(propertyAccess);
continue;
}
// when in the [Decorator] context, we do not parse ElementAccess as it could be part of a ComputedPropertyName
if (!inDecoratorContext() && parseOptional(19 /* OpenBracketToken */)) {
var indexedAccess = createNode(165 /* 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 !== 20 /* 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(20 /* CloseBracketToken */);
expression = finishNode(indexedAccess);
continue;
}
if (token === 11 /* NoSubstitutionTemplateLiteral */ || token === 12 /* TemplateHead */) {
var tagExpression = createNode(168 /* TaggedTemplateExpression */, expression.pos);
tagExpression.tag = expression;
tagExpression.template = token === 11 /* NoSubstitutionTemplateLiteral */
? parseLiteralNode()
: parseTemplateExpression();
expression = finishNode(tagExpression);
continue;
}
return expression;
}
}
function parseCallExpressionRest(expression) {
while (true) {
expression = parseMemberExpressionRest(expression);
if (token === 25 /* LessThanToken */) {
// See if this is the start of a generic invocation. If so, consume it and
// keep checking for postfix expressions. Otherwise, it's just a '<' that's
// part of an arithmetic expression. Break out so we consume it higher in the
// stack.
var typeArguments = tryParse(parseTypeArgumentsInExpression);
if (!typeArguments) {
return expression;
}
var callExpr = createNode(166 /* CallExpression */, expression.pos);
callExpr.expression = expression;
callExpr.typeArguments = typeArguments;
callExpr.arguments = parseArgumentList();
expression = finishNode(callExpr);
continue;
}
else if (token === 17 /* OpenParenToken */) {
var callExpr = createNode(166 /* CallExpression */, expression.pos);
callExpr.expression = expression;
callExpr.arguments = parseArgumentList();
expression = finishNode(callExpr);
continue;
}
return expression;
}
}
function parseArgumentList() {
parseExpected(17 /* OpenParenToken */);
var result = parseDelimitedList(11 /* ArgumentExpressions */, parseArgumentExpression);
parseExpected(18 /* CloseParenToken */);
return result;
}
function parseTypeArgumentsInExpression() {
if (!parseOptional(25 /* LessThanToken */)) {
return undefined;
}
var typeArguments = parseDelimitedList(18 /* TypeArguments */, parseType);
if (!parseExpected(27 /* GreaterThanToken */)) {
// If it doesn't have the closing > then it's definitely not an type argument list.
return undefined;
}
// If we have a '<', then only parse this as a arugment list if the type arguments
// are complete and we have an open paren. if we don't, rewind and return nothing.
return typeArguments && canFollowTypeArgumentsInExpression()
? typeArguments
: undefined;
}
function canFollowTypeArgumentsInExpression() {
switch (token) {
case 17 /* OpenParenToken */: // foo<x>(
// this case are the only case where this token can legally follow a type argument
// list. So we definitely want to treat this as a type arg list.
case 21 /* DotToken */: // foo<x>.
case 18 /* CloseParenToken */: // foo<x>)
case 20 /* CloseBracketToken */: // foo<x>]
case 53 /* ColonToken */: // foo<x>:
case 23 /* SemicolonToken */: // foo<x>;
case 52 /* QuestionToken */: // foo<x>?
case 30 /* EqualsEqualsToken */: // foo<x> ==
case 32 /* EqualsEqualsEqualsToken */: // foo<x> ===
case 31 /* ExclamationEqualsToken */: // foo<x> !=
case 33 /* ExclamationEqualsEqualsToken */: // foo<x> !==
case 50 /* AmpersandAmpersandToken */: // foo<x> &&
case 51 /* BarBarToken */: // foo<x> ||
case 47 /* CaretToken */: // foo<x> ^
case 45 /* AmpersandToken */: // foo<x> &
case 46 /* BarToken */: // foo<x> |
case 16 /* CloseBraceToken */: // foo<x> }
case 1 /* EndOfFileToken */:
// these cases can't legally follow a type arg list. However, they're not legal
// expressions either. The user is probably in the middle of a generic type. So
// treat it as such.
return true;
case 24 /* CommaToken */: // foo<x>,
case 15 /* OpenBraceToken */: // foo<x> {
// We don't want to treat these as type arguments. Otherwise we'll parse this
// as an invocation expression. Instead, we want to parse out the expression
// in isolation from the type arguments.
default:
// Anything else treat as an expression.
return false;
}
}
function parsePrimaryExpression() {
switch (token) {
case 8 /* NumericLiteral */:
case 9 /* StringLiteral */:
case 11 /* NoSubstitutionTemplateLiteral */:
return parseLiteralNode();
case 95 /* ThisKeyword */:
case 93 /* SuperKeyword */:
case 91 /* NullKeyword */:
case 97 /* TrueKeyword */:
case 82 /* FalseKeyword */:
return parseTokenNode();
case 17 /* OpenParenToken */:
return parseParenthesizedExpression();
case 19 /* OpenBracketToken */:
return parseArrayLiteralExpression();
case 15 /* OpenBraceToken */:
return parseObjectLiteralExpression();
case 116 /* 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 71 /* ClassKeyword */:
return parseClassExpression();
case 85 /* FunctionKeyword */:
return parseFunctionExpression();
case 90 /* NewKeyword */:
return parseNewExpression();
case 38 /* SlashToken */:
case 59 /* SlashEqualsToken */:
if (reScanSlashToken() === 10 /* RegularExpressionLiteral */) {
return parseLiteralNode();
}
break;
case 12 /* TemplateHead */:
return parseTemplateExpression();
}
return parseIdentifier(ts.Diagnostics.Expression_expected);
}
function parseParenthesizedExpression() {
var node = createNode(170 /* ParenthesizedExpression */);
parseExpected(17 /* OpenParenToken */);
node.expression = allowInAnd(parseExpression);
parseExpected(18 /* CloseParenToken */);
return finishNode(node);
}
function parseSpreadElement() {
var node = createNode(183 /* SpreadElementExpression */);
parseExpected(22 /* DotDotDotToken */);
node.expression = parseAssignmentExpressionOrHigher();
return finishNode(node);
}
function parseArgumentOrArrayLiteralElement() {
return token === 22 /* DotDotDotToken */ ? parseSpreadElement() :
token === 24 /* CommaToken */ ? createNode(185 /* OmittedExpression */) :
parseAssignmentExpressionOrHigher();
}
function parseArgumentExpression() {
return doOutsideOfContext(disallowInAndDecoratorContext, parseArgumentOrArrayLiteralElement);
}
function parseArrayLiteralExpression() {
var node = createNode(162 /* ArrayLiteralExpression */);
parseExpected(19 /* OpenBracketToken */);
if (scanner.hasPrecedingLineBreak())
node.flags |= 2048 /* MultiLine */;
node.elements = parseDelimitedList(15 /* ArrayLiteralMembers */, parseArgumentOrArrayLiteralElement);
parseExpected(20 /* CloseBracketToken */);
return finishNode(node);
}
function tryParseAccessorDeclaration(fullStart, decorators, modifiers) {
if (parseContextualModifier(121 /* GetKeyword */)) {
return parseAccessorDeclaration(143 /* GetAccessor */, fullStart, decorators, modifiers);
}
else if (parseContextualModifier(127 /* SetKeyword */)) {
return parseAccessorDeclaration(144 /* SetAccessor */, fullStart, decorators, modifiers);
}
return undefined;
}
function parseObjectLiteralElement() {
var fullStart = scanner.getStartPos();
var decorators = parseDecorators();
var modifiers = parseModifiers();
var accessor = tryParseAccessorDeclaration(fullStart, decorators, modifiers);
if (accessor) {
return accessor;
}
var asteriskToken = parseOptionalToken(37 /* AsteriskToken */);
var tokenIsIdentifier = isIdentifier();
var nameToken = token;
var propertyName = parsePropertyName();
// Disallowing of optional property assignments happens in the grammar checker.
var questionToken = parseOptionalToken(52 /* QuestionToken */);
if (asteriskToken || token === 17 /* OpenParenToken */ || token === 25 /* LessThanToken */) {
return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, propertyName, questionToken);
}
// Parse to check if it is short-hand property assignment or normal property assignment
if ((token === 24 /* CommaToken */ || token === 16 /* CloseBraceToken */) && tokenIsIdentifier) {
var shorthandDeclaration = createNode(244 /* ShorthandPropertyAssignment */, fullStart);
shorthandDeclaration.name = propertyName;
shorthandDeclaration.questionToken = questionToken;
return finishNode(shorthandDeclaration);
}
else {
var propertyAssignment = createNode(243 /* PropertyAssignment */, fullStart);
propertyAssignment.name = propertyName;
propertyAssignment.questionToken = questionToken;
parseExpected(53 /* ColonToken */);
propertyAssignment.initializer = allowInAnd(parseAssignmentExpressionOrHigher);
return finishNode(propertyAssignment);
}
}
function parseObjectLiteralExpression() {
var node = createNode(163 /* ObjectLiteralExpression */);
parseExpected(15 /* OpenBraceToken */);
if (scanner.hasPrecedingLineBreak()) {
node.flags |= 2048 /* MultiLine */;
}
node.properties = parseDelimitedList(12 /* ObjectLiteralMembers */, parseObjectLiteralElement, /*considerSemicolonAsDelimeter*/ true);
parseExpected(16 /* CloseBraceToken */);
return finishNode(node);
}
function parseFunctionExpression() {
// GeneratorExpression:
// function* BindingIdentifier [Yield][opt](FormalParameters[Yield]){ GeneratorBody }
//
// FunctionExpression:
// function BindingIdentifier[opt](FormalParameters){ FunctionBody }
var saveDecoratorContext = inDecoratorContext();
if (saveDecoratorContext) {
setDecoratorContext(false);
}
var node = createNode(171 /* FunctionExpression */);
setModifiers(node, parseModifiers());
parseExpected(85 /* FunctionKeyword */);
node.asteriskToken = parseOptionalToken(37 /* AsteriskToken */);
var isGenerator = !!node.asteriskToken;
var isAsync = !!(node.flags & 512 /* Async */);
node.name =
isGenerator && isAsync ? doInYieldAndAwaitContext(parseOptionalIdentifier) :
isGenerator ? doInYieldContext(parseOptionalIdentifier) :
isAsync ? doInAwaitContext(parseOptionalIdentifier) :
parseOptionalIdentifier();
fillSignature(53 /* ColonToken */, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node);
node.body = parseFunctionBlock(/*allowYield*/ isGenerator, /*allowAwait*/ isAsync, /*ignoreMissingOpenBrace*/ false);
if (saveDecoratorContext) {
setDecoratorContext(true);
}
return finishNode(node);
}
function parseOptionalIdentifier() {
return isIdentifier() ? parseIdentifier() : undefined;
}
function parseNewExpression() {
var node = createNode(167 /* NewExpression */);
parseExpected(90 /* NewKeyword */);
node.expression = parseMemberExpressionOrHigher();
node.typeArguments = tryParse(parseTypeArgumentsInExpression);
if (node.typeArguments || token === 17 /* OpenParenToken */) {
node.arguments = parseArgumentList();
}
return finishNode(node);
}
// STATEMENTS
function parseBlock(ignoreMissingOpenBrace, diagnosticMessage) {
var node = createNode(190 /* Block */);
if (parseExpected(15 /* OpenBraceToken */, diagnosticMessage) || ignoreMissingOpenBrace) {
node.statements = parseList(1 /* BlockStatements */, parseStatement);
parseExpected(16 /* CloseBraceToken */);
}
else {
node.statements = createMissingList();
}
return finishNode(node);
}
function parseFunctionBlock(allowYield, allowAwait, ignoreMissingOpenBrace, diagnosticMessage) {
var savedYieldContext = inYieldContext();
setYieldContext(allowYield);
var savedAwaitContext = inAwaitContext();
setAwaitContext(allowAwait);
// We may be in a [Decorator] context when parsing a function expression or
// arrow function. The body of the function is not in [Decorator] context.
var saveDecoratorContext = inDecoratorContext();
if (saveDecoratorContext) {
setDecoratorContext(false);
}
var block = parseBlock(ignoreMissingOpenBrace, diagnosticMessage);
if (saveDecoratorContext) {
setDecoratorContext(true);
}
setYieldContext(savedYieldContext);
setAwaitContext(savedAwaitContext);
return block;
}
function parseEmptyStatement() {
var node = createNode(192 /* EmptyStatement */);
parseExpected(23 /* SemicolonToken */);
return finishNode(node);
}
function parseIfStatement() {
var node = createNode(194 /* IfStatement */);
parseExpected(86 /* IfKeyword */);
parseExpected(17 /* OpenParenToken */);
node.expression = allowInAnd(parseExpression);
parseExpected(18 /* CloseParenToken */);
node.thenStatement = parseStatement();
node.elseStatement = parseOptional(78 /* ElseKeyword */) ? parseStatement() : undefined;
return finishNode(node);
}
function parseDoStatement() {
var node = createNode(195 /* DoStatement */);
parseExpected(77 /* DoKeyword */);
node.statement = parseStatement();
parseExpected(102 /* WhileKeyword */);
parseExpected(17 /* OpenParenToken */);
node.expression = allowInAnd(parseExpression);
parseExpected(18 /* CloseParenToken */);
// From: https://mail.mozilla.org/pipermail/es-discuss/2011-August/016188.html
// 157 min --- All allen at wirfs-brock.com CONF --- "do{;}while(false)false" prohibited in
// spec but allowed in consensus reality. Approved -- this is the de-facto standard whereby
// do;while(0)x will have a semicolon inserted before x.
parseOptional(23 /* SemicolonToken */);
return finishNode(node);
}
function parseWhileStatement() {
var node = createNode(196 /* WhileStatement */);
parseExpected(102 /* WhileKeyword */);
parseExpected(17 /* OpenParenToken */);
node.expression = allowInAnd(parseExpression);
parseExpected(18 /* CloseParenToken */);
node.statement = parseStatement();
return finishNode(node);
}
function parseForOrForInOrForOfStatement() {
var pos = getNodePos();
parseExpected(84 /* ForKeyword */);
parseExpected(17 /* OpenParenToken */);
var initializer = undefined;
if (token !== 23 /* SemicolonToken */) {
if (token === 100 /* VarKeyword */ || token === 106 /* LetKeyword */ || token === 72 /* ConstKeyword */) {
initializer = parseVariableDeclarationList(/*inForStatementInitializer*/ true);
}
else {
initializer = disallowInAnd(parseExpression);
}
}
var forOrForInOrForOfStatement;
if (parseOptional(88 /* InKeyword */)) {
var forInStatement = createNode(198 /* ForInStatement */, pos);
forInStatement.initializer = initializer;
forInStatement.expression = allowInAnd(parseExpression);
parseExpected(18 /* CloseParenToken */);
forOrForInOrForOfStatement = forInStatement;
}
else if (parseOptional(132 /* OfKeyword */)) {
var forOfStatement = createNode(199 /* ForOfStatement */, pos);
forOfStatement.initializer = initializer;
forOfStatement.expression = allowInAnd(parseAssignmentExpressionOrHigher);
parseExpected(18 /* CloseParenToken */);
forOrForInOrForOfStatement = forOfStatement;
}
else {
var forStatement = createNode(197 /* ForStatement */, pos);
forStatement.initializer = initializer;
parseExpected(23 /* SemicolonToken */);
if (token !== 23 /* SemicolonToken */ && token !== 18 /* CloseParenToken */) {
forStatement.condition = allowInAnd(parseExpression);
}
parseExpected(23 /* SemicolonToken */);
if (token !== 18 /* CloseParenToken */) {
forStatement.incrementor = allowInAnd(parseExpression);
}
parseExpected(18 /* CloseParenToken */);
forOrForInOrForOfStatement = forStatement;
}
forOrForInOrForOfStatement.statement = parseStatement();
return finishNode(forOrForInOrForOfStatement);
}
function parseBreakOrContinueStatement(kind) {
var node = createNode(kind);
parseExpected(kind === 201 /* BreakStatement */ ? 68 /* BreakKeyword */ : 73 /* ContinueKeyword */);
if (!canParseSemicolon()) {
node.label = parseIdentifier();
}
parseSemicolon();
return finishNode(node);
}
function parseReturnStatement() {
var node = createNode(202 /* ReturnStatement */);
parseExpected(92 /* ReturnKeyword */);
if (!canParseSemicolon()) {
node.expression = allowInAnd(parseExpression);
}
parseSemicolon();
return finishNode(node);
}
function parseWithStatement() {
var node = createNode(203 /* WithStatement */);
parseExpected(103 /* WithKeyword */);
parseExpected(17 /* OpenParenToken */);
node.expression = allowInAnd(parseExpression);
parseExpected(18 /* CloseParenToken */);
node.statement = parseStatement();
return finishNode(node);
}
function parseCaseClause() {
var node = createNode(239 /* CaseClause */);
parseExpected(69 /* CaseKeyword */);
node.expression = allowInAnd(parseExpression);
parseExpected(53 /* ColonToken */);
node.statements = parseList(3 /* SwitchClauseStatements */, parseStatement);
return finishNode(node);
}
function parseDefaultClause() {
var node = createNode(240 /* DefaultClause */);
parseExpected(75 /* DefaultKeyword */);
parseExpected(53 /* ColonToken */);
node.statements = parseList(3 /* SwitchClauseStatements */, parseStatement);
return finishNode(node);
}
function parseCaseOrDefaultClause() {
return token === 69 /* CaseKeyword */ ? parseCaseClause() : parseDefaultClause();
}
function parseSwitchStatement() {
var node = createNode(204 /* SwitchStatement */);
parseExpected(94 /* SwitchKeyword */);
parseExpected(17 /* OpenParenToken */);
node.expression = allowInAnd(parseExpression);
parseExpected(18 /* CloseParenToken */);
var caseBlock = createNode(218 /* CaseBlock */, scanner.getStartPos());
parseExpected(15 /* OpenBraceToken */);
caseBlock.clauses = parseList(2 /* SwitchClauses */, parseCaseOrDefaultClause);
parseExpected(16 /* CloseBraceToken */);
node.caseBlock = finishNode(caseBlock);
return finishNode(node);
}
function parseThrowStatement() {
// ThrowStatement[Yield] :
// throw [no LineTerminator here]Expression[In, ?Yield];
// Because of automatic semicolon insertion, we need to report error if this
// throw could be terminated with a semicolon. Note: we can't call 'parseExpression'
// directly as that might consume an expression on the following line.
// We just return 'undefined' in that case. The actual error will be reported in the
// grammar walker.
var node = createNode(206 /* ThrowStatement */);
parseExpected(96 /* ThrowKeyword */);
node.expression = scanner.hasPrecedingLineBreak() ? undefined : allowInAnd(parseExpression);
parseSemicolon();
return finishNode(node);
}
// TODO: Review for error recovery
function parseTryStatement() {
var node = createNode(207 /* TryStatement */);
parseExpected(98 /* TryKeyword */);
node.tryBlock = parseBlock(/*ignoreMissingOpenBrace*/ false);
node.catchClause = token === 70 /* CatchKeyword */ ? parseCatchClause() : undefined;
// If we don't have a catch clause, then we must have a finally clause. Try to parse
// one out no matter what.
if (!node.catchClause || token === 83 /* FinallyKeyword */) {
parseExpected(83 /* FinallyKeyword */);
node.finallyBlock = parseBlock(/*ignoreMissingOpenBrace*/ false);
}
return finishNode(node);
}
function parseCatchClause() {
var result = createNode(242 /* CatchClause */);
parseExpected(70 /* CatchKeyword */);
if (parseExpected(17 /* OpenParenToken */)) {
result.variableDeclaration = parseVariableDeclaration();
}
parseExpected(18 /* CloseParenToken */);
result.block = parseBlock(/*ignoreMissingOpenBrace*/ false);
return finishNode(result);
}
function parseDebuggerStatement() {
var node = createNode(208 /* DebuggerStatement */);
parseExpected(74 /* DebuggerKeyword */);
parseSemicolon();
return finishNode(node);
}
function parseExpressionOrLabeledStatement() {
// Avoiding having to do the lookahead for a labeled statement by just trying to parse
// out an expression, seeing if it is identifier and then seeing if it is followed by
// a colon.
var fullStart = scanner.getStartPos();
var expression = allowInAnd(parseExpression);
if (expression.kind === 67 /* Identifier */ && parseOptional(53 /* ColonToken */)) {
var labeledStatement = createNode(205 /* LabeledStatement */, fullStart);
labeledStatement.label = expression;
labeledStatement.statement = parseStatement();
return finishNode(labeledStatement);
}
else {
var expressionStatement = createNode(193 /* ExpressionStatement */, fullStart);
expressionStatement.expression = expression;
parseSemicolon();
return finishNode(expressionStatement);
}
}
function isIdentifierOrKeyword() {
return token >= 67 /* Identifier */;
}
function nextTokenIsIdentifierOrKeywordOnSameLine() {
nextToken();
return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak();
}
function nextTokenIsFunctionKeywordOnSameLine() {
nextToken();
return token === 85 /* FunctionKeyword */ && !scanner.hasPrecedingLineBreak();
}
function nextTokenIsIdentifierOrKeywordOrNumberOnSameLine() {
nextToken();
return (isIdentifierOrKeyword() || token === 8 /* NumericLiteral */) && !scanner.hasPrecedingLineBreak();
}
function isDeclaration() {
while (true) {
switch (token) {
case 100 /* VarKeyword */:
case 106 /* LetKeyword */:
case 72 /* ConstKeyword */:
case 85 /* FunctionKeyword */:
case 71 /* ClassKeyword */:
case 79 /* 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 105 /* InterfaceKeyword */:
case 130 /* TypeKeyword */:
return nextTokenIsIdentifierOnSameLine();
case 123 /* ModuleKeyword */:
case 124 /* NamespaceKeyword */:
return nextTokenIsIdentifierOrStringLiteralOnSameLine();
case 116 /* AsyncKeyword */:
case 120 /* DeclareKeyword */:
nextToken();
// ASI takes effect for this modifier.
if (scanner.hasPrecedingLineBreak()) {
return false;
}
continue;
case 87 /* ImportKeyword */:
nextToken();
return token === 9 /* StringLiteral */ || token === 37 /* AsteriskToken */ ||
token === 15 /* OpenBraceToken */ || isIdentifierOrKeyword();
case 80 /* ExportKeyword */:
nextToken();
if (token === 55 /* EqualsToken */ || token === 37 /* AsteriskToken */ ||
token === 15 /* OpenBraceToken */ || token === 75 /* DefaultKeyword */) {
return true;
}
continue;
case 110 /* PublicKeyword */:
case 108 /* PrivateKeyword */:
case 109 /* ProtectedKeyword */:
case 111 /* StaticKeyword */:
case 113 /* AbstractKeyword */:
nextToken();
continue;
default:
return false;
}
}
}
function isStartOfDeclaration() {
return lookAhead(isDeclaration);
}
function isStartOfStatement() {
switch (token) {
case 54 /* AtToken */:
case 23 /* SemicolonToken */:
case 15 /* OpenBraceToken */:
case 100 /* VarKeyword */:
case 106 /* LetKeyword */:
case 85 /* FunctionKeyword */:
case 71 /* ClassKeyword */:
case 79 /* EnumKeyword */:
case 86 /* IfKeyword */:
case 77 /* DoKeyword */:
case 102 /* WhileKeyword */:
case 84 /* ForKeyword */:
case 73 /* ContinueKeyword */:
case 68 /* BreakKeyword */:
case 92 /* ReturnKeyword */:
case 103 /* WithKeyword */:
case 94 /* SwitchKeyword */:
case 96 /* ThrowKeyword */:
case 98 /* TryKeyword */:
case 74 /* 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 70 /* CatchKeyword */:
case 83 /* FinallyKeyword */:
return true;
case 72 /* ConstKeyword */:
case 80 /* ExportKeyword */:
case 87 /* ImportKeyword */:
return isStartOfDeclaration();
case 116 /* AsyncKeyword */:
case 120 /* DeclareKeyword */:
case 105 /* InterfaceKeyword */:
case 123 /* ModuleKeyword */:
case 124 /* NamespaceKeyword */:
case 130 /* TypeKeyword */:
// When these don't start a declaration, they're an identifier in an expression statement
return true;
case 110 /* PublicKeyword */:
case 108 /* PrivateKeyword */:
case 109 /* ProtectedKeyword */:
case 111 /* StaticKeyword */:
// 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();
}
}
function nextTokenIsIdentifierOrStartOfDestructuring() {
nextToken();
return isIdentifier() || token === 15 /* OpenBraceToken */ || token === 19 /* OpenBracketToken */;
}
function isLetDeclaration() {
// In ES6 'let' always starts a lexical declaration if followed by an identifier or {
// or [.
return lookAhead(nextTokenIsIdentifierOrStartOfDestructuring);
}
function parseStatement() {
switch (token) {
case 23 /* SemicolonToken */:
return parseEmptyStatement();
case 15 /* OpenBraceToken */:
return parseBlock(/*ignoreMissingOpenBrace*/ false);
case 100 /* VarKeyword */:
return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined);
case 106 /* LetKeyword */:
if (isLetDeclaration()) {
return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined);
}
break;
case 85 /* FunctionKeyword */:
return parseFunctionDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined);
case 71 /* ClassKeyword */:
return parseClassDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined);
case 86 /* IfKeyword */:
return parseIfStatement();
case 77 /* DoKeyword */:
return parseDoStatement();
case 102 /* WhileKeyword */:
return parseWhileStatement();
case 84 /* ForKeyword */:
return parseForOrForInOrForOfStatement();
case 73 /* ContinueKeyword */:
return parseBreakOrContinueStatement(200 /* ContinueStatement */);
case 68 /* BreakKeyword */:
return parseBreakOrContinueStatement(201 /* BreakStatement */);
case 92 /* ReturnKeyword */:
return parseReturnStatement();
case 103 /* WithKeyword */:
return parseWithStatement();
case 94 /* SwitchKeyword */:
return parseSwitchStatement();
case 96 /* ThrowKeyword */:
return parseThrowStatement();
case 98 /* TryKeyword */:
// Include 'catch' and 'finally' for error recovery.
case 70 /* CatchKeyword */:
case 83 /* FinallyKeyword */:
return parseTryStatement();
case 74 /* DebuggerKeyword */:
return parseDebuggerStatement();
case 54 /* AtToken */:
return parseDeclaration();
case 116 /* AsyncKeyword */:
case 105 /* InterfaceKeyword */:
case 130 /* TypeKeyword */:
case 123 /* ModuleKeyword */:
case 124 /* NamespaceKeyword */:
case 120 /* DeclareKeyword */:
case 72 /* ConstKeyword */:
case 79 /* EnumKeyword */:
case 80 /* ExportKeyword */:
case 87 /* ImportKeyword */:
case 108 /* PrivateKeyword */:
case 109 /* ProtectedKeyword */:
case 110 /* PublicKeyword */:
case 113 /* AbstractKeyword */:
case 111 /* StaticKeyword */:
if (isStartOfDeclaration()) {
return parseDeclaration();
}
break;
}
return parseExpressionOrLabeledStatement();
}
function parseDeclaration() {
var fullStart = getNodePos();
var decorators = parseDecorators();
var modifiers = parseModifiers();
switch (token) {
case 100 /* VarKeyword */:
case 106 /* LetKeyword */:
case 72 /* ConstKeyword */:
return parseVariableStatement(fullStart, decorators, modifiers);
case 85 /* FunctionKeyword */:
return parseFunctionDeclaration(fullStart, decorators, modifiers);
case 71 /* ClassKeyword */:
return parseClassDeclaration(fullStart, decorators, modifiers);
case 105 /* InterfaceKeyword */:
return parseInterfaceDeclaration(fullStart, decorators, modifiers);
case 130 /* TypeKeyword */:
return parseTypeAliasDeclaration(fullStart, decorators, modifiers);
case 79 /* EnumKeyword */:
return parseEnumDeclaration(fullStart, decorators, modifiers);
case 123 /* ModuleKeyword */:
case 124 /* NamespaceKeyword */:
return parseModuleDeclaration(fullStart, decorators, modifiers);
case 87 /* ImportKeyword */:
return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers);
case 80 /* ExportKeyword */:
nextToken();
return token === 75 /* DefaultKeyword */ || token === 55 /* EqualsToken */ ?
parseExportAssignment(fullStart, decorators, modifiers) :
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(229 /* MissingDeclaration */, /*reportAtCurrentPosition*/ true, ts.Diagnostics.Declaration_expected);
node.pos = fullStart;
node.decorators = decorators;
setModifiers(node, modifiers);
return finishNode(node);
}
}
}
function nextTokenIsIdentifierOrStringLiteralOnSameLine() {
nextToken();
return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token === 9 /* StringLiteral */);
}
function parseFunctionBlockOrSemicolon(isGenerator, isAsync, diagnosticMessage) {
if (token !== 15 /* OpenBraceToken */ && canParseSemicolon()) {
parseSemicolon();
return;
}
return parseFunctionBlock(isGenerator, isAsync, /*ignoreMissingOpenBrace*/ false, diagnosticMessage);
}
// DECLARATIONS
function parseArrayBindingElement() {
if (token === 24 /* CommaToken */) {
return createNode(185 /* OmittedExpression */);
}
var node = createNode(161 /* BindingElement */);
node.dotDotDotToken = parseOptionalToken(22 /* DotDotDotToken */);
node.name = parseIdentifierOrPattern();
node.initializer = parseBindingElementInitializer(/*inParameter*/ false);
return finishNode(node);
}
function parseObjectBindingElement() {
var node = createNode(161 /* BindingElement */);
// TODO(andersh): Handle computed properties
var tokenIsIdentifier = isIdentifier();
var propertyName = parsePropertyName();
if (tokenIsIdentifier && token !== 53 /* ColonToken */) {
node.name = propertyName;
}
else {
parseExpected(53 /* ColonToken */);
node.propertyName = propertyName;
node.name = parseIdentifierOrPattern();
}
node.initializer = parseBindingElementInitializer(/*inParameter*/ false);
return finishNode(node);
}
function parseObjectBindingPattern() {
var node = createNode(159 /* ObjectBindingPattern */);
parseExpected(15 /* OpenBraceToken */);
node.elements = parseDelimitedList(9 /* ObjectBindingElements */, parseObjectBindingElement);
parseExpected(16 /* CloseBraceToken */);
return finishNode(node);
}
function parseArrayBindingPattern() {
var node = createNode(160 /* ArrayBindingPattern */);
parseExpected(19 /* OpenBracketToken */);
node.elements = parseDelimitedList(10 /* ArrayBindingElements */, parseArrayBindingElement);
parseExpected(20 /* CloseBracketToken */);
return finishNode(node);
}
function isIdentifierOrPattern() {
return token === 15 /* OpenBraceToken */ || token === 19 /* OpenBracketToken */ || isIdentifier();
}
function parseIdentifierOrPattern() {
if (token === 19 /* OpenBracketToken */) {
return parseArrayBindingPattern();
}
if (token === 15 /* OpenBraceToken */) {
return parseObjectBindingPattern();
}
return parseIdentifier();
}
function parseVariableDeclaration() {
var node = createNode(209 /* VariableDeclaration */);
node.name = parseIdentifierOrPattern();
node.type = parseTypeAnnotation();
if (!isInOrOfKeyword(token)) {
node.initializer = parseInitializer(/*inParameter*/ false);
}
return finishNode(node);
}
function parseVariableDeclarationList(inForStatementInitializer) {
var node = createNode(210 /* VariableDeclarationList */);
switch (token) {
case 100 /* VarKeyword */:
break;
case 106 /* LetKeyword */:
node.flags |= 16384 /* Let */;
break;
case 72 /* ConstKeyword */:
node.flags |= 32768 /* 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 === 132 /* OfKeyword */ && lookAhead(canFollowContextualOfKeyword)) {
node.declarations = createMissingList();
}
else {
var savedDisallowIn = inDisallowInContext();
setDisallowInContext(inForStatementInitializer);
node.declarations = parseDelimitedList(8 /* VariableDeclarations */, parseVariableDeclaration);
setDisallowInContext(savedDisallowIn);
}
return finishNode(node);
}
function canFollowContextualOfKeyword() {
return nextTokenIsIdentifier() && nextToken() === 18 /* CloseParenToken */;
}
function parseVariableStatement(fullStart, decorators, modifiers) {
var node = createNode(191 /* VariableStatement */, fullStart);
node.decorators = decorators;
setModifiers(node, modifiers);
node.declarationList = parseVariableDeclarationList(/*inForStatementInitializer*/ false);
parseSemicolon();
return finishNode(node);
}
function parseFunctionDeclaration(fullStart, decorators, modifiers) {
var node = createNode(211 /* FunctionDeclaration */, fullStart);
node.decorators = decorators;
setModifiers(node, modifiers);
parseExpected(85 /* FunctionKeyword */);
node.asteriskToken = parseOptionalToken(37 /* AsteriskToken */);
node.name = node.flags & 1024 /* Default */ ? parseOptionalIdentifier() : parseIdentifier();
var isGenerator = !!node.asteriskToken;
var isAsync = !!(node.flags & 512 /* Async */);
fillSignature(53 /* ColonToken */, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node);
node.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, ts.Diagnostics.or_expected);
return finishNode(node);
}
function parseConstructorDeclaration(pos, decorators, modifiers) {
var node = createNode(142 /* Constructor */, pos);
node.decorators = decorators;
setModifiers(node, modifiers);
parseExpected(119 /* ConstructorKeyword */);
fillSignature(53 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node);
node.body = parseFunctionBlockOrSemicolon(/*isGenerator*/ false, /*isAsync*/ false, ts.Diagnostics.or_expected);
return finishNode(node);
}
function parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, diagnosticMessage) {
var method = createNode(141 /* MethodDeclaration */, fullStart);
method.decorators = decorators;
setModifiers(method, modifiers);
method.asteriskToken = asteriskToken;
method.name = name;
method.questionToken = questionToken;
var isGenerator = !!asteriskToken;
var isAsync = !!(method.flags & 512 /* Async */);
fillSignature(53 /* ColonToken */, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, method);
method.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, diagnosticMessage);
return finishNode(method);
}
function parsePropertyDeclaration(fullStart, decorators, modifiers, name, questionToken) {
var property = createNode(139 /* PropertyDeclaration */, fullStart);
property.decorators = decorators;
setModifiers(property, modifiers);
property.name = name;
property.questionToken = questionToken;
property.type = parseTypeAnnotation();
// For instance properties specifically, since they are evaluated inside the constructor,
// we do *not * want to parse yield expressions, so we specifically turn the yield context
// off. The grammar would look something like this:
//
// MemberVariableDeclaration[Yield]:
// AccessibilityModifier_opt PropertyName TypeAnnotation_opt Initialiser_opt[In];
// AccessibilityModifier_opt static_opt PropertyName TypeAnnotation_opt Initialiser_opt[In, ?Yield];
//
// The checker may still error in the static case to explicitly disallow the yield expression.
property.initializer = modifiers && modifiers.flags & 128 /* Static */
? allowInAnd(parseNonParameterInitializer)
: doOutsideOfContext(2 /* Yield */ | 1 /* DisallowIn */, parseNonParameterInitializer);
parseSemicolon();
return finishNode(property);
}
function parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers) {
var asteriskToken = parseOptionalToken(37 /* 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(52 /* QuestionToken */);
if (asteriskToken || token === 17 /* OpenParenToken */ || token === 25 /* LessThanToken */) {
return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, ts.Diagnostics.or_expected);
}
else {
return parsePropertyDeclaration(fullStart, decorators, modifiers, name, questionToken);
}
}
function parseNonParameterInitializer() {
return parseInitializer(/*inParameter*/ false);
}
function parseAccessorDeclaration(kind, fullStart, decorators, modifiers) {
var node = createNode(kind, fullStart);
node.decorators = decorators;
setModifiers(node, modifiers);
node.name = parsePropertyName();
fillSignature(53 /* ColonToken */, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node);
node.body = parseFunctionBlockOrSemicolon(/*isGenerator*/ false, /*isAsync*/ false);
return finishNode(node);
}
function isClassMemberModifier(idToken) {
switch (idToken) {
case 110 /* PublicKeyword */:
case 108 /* PrivateKeyword */:
case 109 /* ProtectedKeyword */:
case 111 /* StaticKeyword */:
return true;
default:
return false;
}
}
function isClassMemberStart() {
var idToken;
if (token === 54 /* AtToken */) {
return true;
}
// Eat up all modifiers, but hold on to the last one in case it is actually an identifier.
while (ts.isModifier(token)) {
idToken = token;
// If the idToken is a class modifier (protected, private, public, and static), it is
// certain that we are starting to parse class member. This allows better error recovery
// Example:
// public foo() ... // true
// public @dec blah ... // true; we will then report an error later
// export public ... // true; we will then report an error later
if (isClassMemberModifier(idToken)) {
return true;
}
nextToken();
}
if (token === 37 /* AsteriskToken */) {
return true;
}
// Try to get the first property-like token following all modifiers.
// This can either be an identifier or the 'get' or 'set' keywords.
if (isLiteralPropertyName()) {
idToken = token;
nextToken();
}
// Index signatures and computed properties are class members; we can parse.
if (token === 19 /* OpenBracketToken */) {
return true;
}
// If we were able to get any potential identifier...
if (idToken !== undefined) {
// If we have a non-keyword identifier, or if we have an accessor, then it's safe to parse.
if (!ts.isKeyword(idToken) || idToken === 127 /* SetKeyword */ || idToken === 121 /* GetKeyword */) {
return true;
}
// If it *is* a keyword, but not an accessor, check a little farther along
// to see if it should actually be parsed as a class member.
switch (token) {
case 17 /* OpenParenToken */: // Method declaration
case 25 /* LessThanToken */: // Generic Method declaration
case 53 /* ColonToken */: // Type Annotation for declaration
case 55 /* EqualsToken */: // Initializer for declaration
case 52 /* QuestionToken */:
return true;
default:
// Covers
// - Semicolons (declaration termination)
// - Closing braces (end-of-class, must be declaration)
// - End-of-files (not valid, but permitted so that it gets caught later on)
// - Line-breaks (enabling *automatic semicolon insertion*)
return canParseSemicolon();
}
}
return false;
}
function parseDecorators() {
var decorators;
while (true) {
var decoratorStart = getNodePos();
if (!parseOptional(54 /* AtToken */)) {
break;
}
if (!decorators) {
decorators = [];
decorators.pos = scanner.getStartPos();
}
var decorator = createNode(137 /* Decorator */, decoratorStart);
decorator.expression = doInDecoratorContext(parseLeftHandSideExpressionOrHigher);
decorators.push(finishNode(decorator));
}
if (decorators) {
decorators.end = getNodeEnd();
}
return decorators;
}
function parseModifiers() {
var flags = 0;
var modifiers;
while (true) {
var modifierStart = scanner.getStartPos();
var modifierKind = token;
if (!parseAnyContextualModifier()) {
break;
}
if (!modifiers) {
modifiers = [];
modifiers.pos = modifierStart;
}
flags |= ts.modifierToFlag(modifierKind);
modifiers.push(finishNode(createNode(modifierKind, modifierStart)));
}
if (modifiers) {
modifiers.flags = flags;
modifiers.end = scanner.getStartPos();
}
return modifiers;
}
function parseModifiersForArrowFunction() {
var flags = 0;
var modifiers;
if (token === 116 /* AsyncKeyword */) {
var modifierStart = scanner.getStartPos();
var modifierKind = token;
nextToken();
modifiers = [];
modifiers.pos = modifierStart;
flags |= ts.modifierToFlag(modifierKind);
modifiers.push(finishNode(createNode(modifierKind, modifierStart)));
modifiers.flags = flags;
modifiers.end = scanner.getStartPos();
}
return modifiers;
}
function parseClassElement() {
if (token === 23 /* SemicolonToken */) {
var result = createNode(189 /* SemicolonClassElement */);
nextToken();
return finishNode(result);
}
var fullStart = getNodePos();
var decorators = parseDecorators();
var modifiers = parseModifiers();
var accessor = tryParseAccessorDeclaration(fullStart, decorators, modifiers);
if (accessor) {
return accessor;
}
if (token === 119 /* ConstructorKeyword */) {
return parseConstructorDeclaration(fullStart, decorators, modifiers);
}
if (isIndexSignature()) {
return parseIndexSignatureDeclaration(fullStart, decorators, modifiers);
}
// It is very important that we check this *after* checking indexers because
// the [ token can start an index signature or a computed property name
if (isIdentifierOrKeyword() ||
token === 9 /* StringLiteral */ ||
token === 8 /* NumericLiteral */ ||
token === 37 /* AsteriskToken */ ||
token === 19 /* OpenBracketToken */) {
return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers);
}
if (decorators || modifiers) {
// treat this as a property declaration with a missing name.
var name_7 = createMissingNode(67 /* Identifier */, /*reportAtCurrentPosition*/ true, ts.Diagnostics.Declaration_expected);
return parsePropertyDeclaration(fullStart, decorators, modifiers, name_7, /*questionToken*/ undefined);
}
// 'isClassMemberStart' should have hinted not to attempt parsing.
ts.Debug.fail("Should not have attempted to parse class member declaration.");
}
function parseClassExpression() {
return parseClassDeclarationOrExpression(
/*fullStart*/ scanner.getStartPos(),
/*decorators*/ undefined,
/*modifiers*/ undefined, 184 /* ClassExpression */);
}
function parseClassDeclaration(fullStart, decorators, modifiers) {
return parseClassDeclarationOrExpression(fullStart, decorators, modifiers, 212 /* ClassDeclaration */);
}
function parseClassDeclarationOrExpression(fullStart, decorators, modifiers, kind) {
var node = createNode(kind, fullStart);
node.decorators = decorators;
setModifiers(node, modifiers);
parseExpected(71 /* ClassKeyword */);
node.name = parseOptionalIdentifier();
node.typeParameters = parseTypeParameters();
node.heritageClauses = parseHeritageClauses(/*isClassHeritageClause*/ true);
if (parseExpected(15 /* OpenBraceToken */)) {
// ClassTail[Yield,Await] : (Modified) See 14.5
// ClassHeritage[?Yield,?Await]opt { ClassBody[?Yield,?Await]opt }
node.members = parseClassMembers();
parseExpected(16 /* CloseBraceToken */);
}
else {
node.members = createMissingList();
}
return finishNode(node);
}
function parseHeritageClauses(isClassHeritageClause) {
// ClassTail[Yield,Await] : (Modified) See 14.5
// ClassHeritage[?Yield,?Await]opt { ClassBody[?Yield,?Await]opt }
if (isHeritageClause()) {
return parseList(20 /* HeritageClauses */, parseHeritageClause);
}
return undefined;
}
function parseHeritageClausesWorker() {
return parseList(20 /* HeritageClauses */, parseHeritageClause);
}
function parseHeritageClause() {
if (token === 81 /* ExtendsKeyword */ || token === 104 /* ImplementsKeyword */) {
var node = createNode(241 /* HeritageClause */);
node.token = token;
nextToken();
node.types = parseDelimitedList(7 /* HeritageClauseElement */, parseExpressionWithTypeArguments);
return finishNode(node);
}
return undefined;
}
function parseExpressionWithTypeArguments() {
var node = createNode(186 /* ExpressionWithTypeArguments */);
node.expression = parseLeftHandSideExpressionOrHigher();
if (token === 25 /* LessThanToken */) {
node.typeArguments = parseBracketedList(18 /* TypeArguments */, parseType, 25 /* LessThanToken */, 27 /* GreaterThanToken */);
}
return finishNode(node);
}
function isHeritageClause() {
return token === 81 /* ExtendsKeyword */ || token === 104 /* ImplementsKeyword */;
}
function parseClassMembers() {
return parseList(5 /* ClassMembers */, parseClassElement);
}
function parseInterfaceDeclaration(fullStart, decorators, modifiers) {
var node = createNode(213 /* InterfaceDeclaration */, fullStart);
node.decorators = decorators;
setModifiers(node, modifiers);
parseExpected(105 /* InterfaceKeyword */);
node.name = parseIdentifier();
node.typeParameters = parseTypeParameters();
node.heritageClauses = parseHeritageClauses(/*isClassHeritageClause*/ false);
node.members = parseObjectTypeMembers();
return finishNode(node);
}
function parseTypeAliasDeclaration(fullStart, decorators, modifiers) {
var node = createNode(214 /* TypeAliasDeclaration */, fullStart);
node.decorators = decorators;
setModifiers(node, modifiers);
parseExpected(130 /* TypeKeyword */);
node.name = parseIdentifier();
node.typeParameters = parseTypeParameters();
parseExpected(55 /* EqualsToken */);
node.type = parseType();
parseSemicolon();
return finishNode(node);
}
// In an ambient declaration, the grammar only allows integer literals as initializers.
// In a non-ambient declaration, the grammar allows uninitialized members only in a
// ConstantEnumMemberSection, which starts at the beginning of an enum declaration
// or any time an integer literal initializer is encountered.
function parseEnumMember() {
var node = createNode(245 /* EnumMember */, scanner.getStartPos());
node.name = parsePropertyName();
node.initializer = allowInAnd(parseNonParameterInitializer);
return finishNode(node);
}
function parseEnumDeclaration(fullStart, decorators, modifiers) {
var node = createNode(215 /* EnumDeclaration */, fullStart);
node.decorators = decorators;
setModifiers(node, modifiers);
parseExpected(79 /* EnumKeyword */);
node.name = parseIdentifier();
if (parseExpected(15 /* OpenBraceToken */)) {
node.members = parseDelimitedList(6 /* EnumMembers */, parseEnumMember);
parseExpected(16 /* CloseBraceToken */);
}
else {
node.members = createMissingList();
}
return finishNode(node);
}
function parseModuleBlock() {
var node = createNode(217 /* ModuleBlock */, scanner.getStartPos());
if (parseExpected(15 /* OpenBraceToken */)) {
node.statements = parseList(1 /* BlockStatements */, parseStatement);
parseExpected(16 /* CloseBraceToken */);
}
else {
node.statements = createMissingList();
}
return finishNode(node);
}
function parseModuleOrNamespaceDeclaration(fullStart, decorators, modifiers, flags) {
var node = createNode(216 /* ModuleDeclaration */, fullStart);
node.decorators = decorators;
setModifiers(node, modifiers);
node.flags |= flags;
node.name = parseIdentifier();
node.body = parseOptional(21 /* DotToken */)
? parseModuleOrNamespaceDeclaration(getNodePos(), /*decorators*/ undefined, /*modifiers*/ undefined, 1 /* Export */)
: parseModuleBlock();
return finishNode(node);
}
function parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers) {
var node = createNode(216 /* ModuleDeclaration */, fullStart);
node.decorators = decorators;
setModifiers(node, modifiers);
node.name = parseLiteralNode(/*internName*/ true);
node.body = parseModuleBlock();
return finishNode(node);
}
function parseModuleDeclaration(fullStart, decorators, modifiers) {
var flags = modifiers ? modifiers.flags : 0;
if (parseOptional(124 /* NamespaceKeyword */)) {
flags |= 131072 /* Namespace */;
}
else {
parseExpected(123 /* ModuleKeyword */);
if (token === 9 /* StringLiteral */) {
return parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers);
}
}
return parseModuleOrNamespaceDeclaration(fullStart, decorators, modifiers, flags);
}
function isExternalModuleReference() {
return token === 125 /* RequireKeyword */ &&
lookAhead(nextTokenIsOpenParen);
}
function nextTokenIsOpenParen() {
return nextToken() === 17 /* OpenParenToken */;
}
function nextTokenIsSlash() {
return nextToken() === 38 /* SlashToken */;
}
function nextTokenIsCommaOrFromKeyword() {
nextToken();
return token === 24 /* CommaToken */ ||
token === 131 /* FromKeyword */;
}
function parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers) {
parseExpected(87 /* ImportKeyword */);
var afterImportPos = scanner.getStartPos();
var identifier;
if (isIdentifier()) {
identifier = parseIdentifier();
if (token !== 24 /* CommaToken */ && token !== 131 /* FromKeyword */) {
// ImportEquals declaration of type:
// import x = require("mod"); or
// import x = M.x;
var importEqualsDeclaration = createNode(219 /* ImportEqualsDeclaration */, fullStart);
importEqualsDeclaration.decorators = decorators;
setModifiers(importEqualsDeclaration, modifiers);
importEqualsDeclaration.name = identifier;
parseExpected(55 /* EqualsToken */);
importEqualsDeclaration.moduleReference = parseModuleReference();
parseSemicolon();
return finishNode(importEqualsDeclaration);
}
}
// Import statement
var importDeclaration = createNode(220 /* ImportDeclaration */, fullStart);
importDeclaration.decorators = decorators;
setModifiers(importDeclaration, modifiers);
// ImportDeclaration:
// import ImportClause from ModuleSpecifier ;
// import ModuleSpecifier;
if (identifier ||
token === 37 /* AsteriskToken */ ||
token === 15 /* OpenBraceToken */) {
importDeclaration.importClause = parseImportClause(identifier, afterImportPos);
parseExpected(131 /* FromKeyword */);
}
importDeclaration.moduleSpecifier = parseModuleSpecifier();
parseSemicolon();
return finishNode(importDeclaration);
}
function parseImportClause(identifier, fullStart) {
// ImportClause:
// ImportedDefaultBinding
// NameSpaceImport
// NamedImports
// ImportedDefaultBinding, NameSpaceImport
// ImportedDefaultBinding, NamedImports
var importClause = createNode(221 /* ImportClause */, fullStart);
if (identifier) {
// ImportedDefaultBinding:
// ImportedBinding
importClause.name = identifier;
}
// If there was no default import or if there is comma token after default import
// parse namespace or named imports
if (!importClause.name ||
parseOptional(24 /* CommaToken */)) {
importClause.namedBindings = token === 37 /* AsteriskToken */ ? parseNamespaceImport() : parseNamedImportsOrExports(223 /* NamedImports */);
}
return finishNode(importClause);
}
function parseModuleReference() {
return isExternalModuleReference()
? parseExternalModuleReference()
: parseEntityName(/*allowReservedWords*/ false);
}
function parseExternalModuleReference() {
var node = createNode(230 /* ExternalModuleReference */);
parseExpected(125 /* RequireKeyword */);
parseExpected(17 /* OpenParenToken */);
node.expression = parseModuleSpecifier();
parseExpected(18 /* CloseParenToken */);
return finishNode(node);
}
function parseModuleSpecifier() {
// We allow arbitrary expressions here, even though the grammar only allows string
// literals. We check to ensure that it is only a string literal later in the grammar
// walker.
var result = parseExpression();
// Ensure the string being required is in our 'identifier' table. This will ensure
// that features like 'find refs' will look inside this file when search for its name.
if (result.kind === 9 /* StringLiteral */) {
internIdentifier(result.text);
}
return result;
}
function parseNamespaceImport() {
// NameSpaceImport:
// * as ImportedBinding
var namespaceImport = createNode(222 /* NamespaceImport */);
parseExpected(37 /* AsteriskToken */);
parseExpected(114 /* AsKeyword */);
namespaceImport.name = parseIdentifier();
return finishNode(namespaceImport);
}
function parseNamedImportsOrExports(kind) {
var node = createNode(kind);
// NamedImports:
// { }
// { ImportsList }
// { ImportsList, }
// ImportsList:
// ImportSpecifier
// ImportsList, ImportSpecifier
node.elements = parseBracketedList(21 /* ImportOrExportSpecifiers */, kind === 223 /* NamedImports */ ? parseImportSpecifier : parseExportSpecifier, 15 /* OpenBraceToken */, 16 /* CloseBraceToken */);
return finishNode(node);
}
function parseExportSpecifier() {
return parseImportOrExportSpecifier(228 /* ExportSpecifier */);
}
function parseImportSpecifier() {
return parseImportOrExportSpecifier(224 /* ImportSpecifier */);
}
function parseImportOrExportSpecifier(kind) {
var node = createNode(kind);
// ImportSpecifier:
// BindingIdentifier
// IdentifierName as BindingIdentifier
// ExportSpecififer:
// IdentifierName
// IdentifierName as IdentifierName
var checkIdentifierIsKeyword = ts.isKeyword(token) && !isIdentifier();
var checkIdentifierStart = scanner.getTokenPos();
var checkIdentifierEnd = scanner.getTextPos();
var identifierName = parseIdentifierName();
if (token === 114 /* AsKeyword */) {
node.propertyName = identifierName;
parseExpected(114 /* AsKeyword */);
checkIdentifierIsKeyword = ts.isKeyword(token) && !isIdentifier();
checkIdentifierStart = scanner.getTokenPos();
checkIdentifierEnd = scanner.getTextPos();
node.name = parseIdentifierName();
}
else {
node.name = identifierName;
}
if (kind === 224 /* ImportSpecifier */ && checkIdentifierIsKeyword) {
// Report error identifier expected
parseErrorAtPosition(checkIdentifierStart, checkIdentifierEnd - checkIdentifierStart, ts.Diagnostics.Identifier_expected);
}
return finishNode(node);
}
function parseExportDeclaration(fullStart, decorators, modifiers) {
var node = createNode(226 /* ExportDeclaration */, fullStart);
node.decorators = decorators;
setModifiers(node, modifiers);
if (parseOptional(37 /* AsteriskToken */)) {
parseExpected(131 /* FromKeyword */);
node.moduleSpecifier = parseModuleSpecifier();
}
else {
node.exportClause = parseNamedImportsOrExports(227 /* NamedExports */);
// It is not uncommon to accidentally omit the 'from' keyword. Additionally, in editing scenarios,
// the 'from' keyword can be parsed as a named export when the export clause is unterminated (i.e. `export { from "moduleName";`)
// If we don't have a 'from' keyword, see if we have a string literal such that ASI won't take effect.
if (token === 131 /* FromKeyword */ || (token === 9 /* StringLiteral */ && !scanner.hasPrecedingLineBreak())) {
parseExpected(131 /* FromKeyword */);
node.moduleSpecifier = parseModuleSpecifier();
}
}
parseSemicolon();
return finishNode(node);
}
function parseExportAssignment(fullStart, decorators, modifiers) {
var node = createNode(225 /* ExportAssignment */, fullStart);
node.decorators = decorators;
setModifiers(node, modifiers);
if (parseOptional(55 /* EqualsToken */)) {
node.isExportEquals = true;
}
else {
parseExpected(75 /* DefaultKeyword */);
}
node.expression = parseAssignmentExpressionOrHigher();
parseSemicolon();
return finishNode(node);
}
function processReferenceComments(sourceFile) {
var triviaScanner = ts.createScanner(sourceFile.languageVersion, /*skipTrivia*/ false, 0 /* Standard */, sourceText);
var referencedFiles = [];
var amdDependencies = [];
var amdModuleName;
// Keep scanning all the leading trivia in the file until we get to something that
// isn't trivia. Any single line comment will be analyzed to see if it is a
// reference comment.
while (true) {
var kind = triviaScanner.scan();
if (kind === 5 /* WhitespaceTrivia */ || kind === 4 /* NewLineTrivia */ || kind === 3 /* MultiLineCommentTrivia */) {
continue;
}
if (kind !== 2 /* SingleLineCommentTrivia */) {
break;
}
var range = { pos: triviaScanner.getTokenPos(), end: triviaScanner.getTextPos(), kind: triviaScanner.getToken() };
var comment = sourceText.substring(range.pos, range.end);
var referencePathMatchResult = ts.getFileReferenceFromReferencePath(comment, range);
if (referencePathMatchResult) {
var fileReference = referencePathMatchResult.fileReference;
sourceFile.hasNoDefaultLib = referencePathMatchResult.isNoDefaultLib;
var diagnosticMessage = referencePathMatchResult.diagnosticMessage;
if (fileReference) {
referencedFiles.push(fileReference);
}
if (diagnosticMessage) {
parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage));
}
}
else {
var amdModuleNameRegEx = /^\/\/\/\s*<amd-module\s+name\s*=\s*('|")(.+?)\1/gim;
var amdModuleNameMatchResult = amdModuleNameRegEx.exec(comment);
if (amdModuleNameMatchResult) {
if (amdModuleName) {
parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, ts.Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments));
}
amdModuleName = amdModuleNameMatchResult[2];
}
var amdDependencyRegEx = /^\/\/\/\s*<amd-dependency\s/gim;
var pathRegex = /\spath\s*=\s*('|")(.+?)\1/gim;
var nameRegex = /\sname\s*=\s*('|")(.+?)\1/gim;
var amdDependencyMatchResult = amdDependencyRegEx.exec(comment);
if (amdDependencyMatchResult) {
var pathMatchResult = pathRegex.exec(comment);
var nameMatchResult = nameRegex.exec(comment);
if (pathMatchResult) {
var amdDependency = { path: pathMatchResult[2], name: nameMatchResult ? nameMatchResult[2] : undefined };
amdDependencies.push(amdDependency);
}
}
}
}
sourceFile.referencedFiles = referencedFiles;
sourceFile.amdDependencies = amdDependencies;
sourceFile.moduleName = amdModuleName;
}
function setExternalModuleIndicator(sourceFile) {
sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) {
return node.flags & 1 /* Export */
|| node.kind === 219 /* ImportEqualsDeclaration */ && node.moduleReference.kind === 230 /* ExternalModuleReference */
|| node.kind === 220 /* ImportDeclaration */
|| node.kind === 225 /* ExportAssignment */
|| node.kind === 226 /* ExportDeclaration */
? node
: undefined;
});
}
var ParsingContext;
(function (ParsingContext) {
ParsingContext[ParsingContext["SourceElements"] = 0] = "SourceElements";
ParsingContext[ParsingContext["BlockStatements"] = 1] = "BlockStatements";
ParsingContext[ParsingContext["SwitchClauses"] = 2] = "SwitchClauses";
ParsingContext[ParsingContext["SwitchClauseStatements"] = 3] = "SwitchClauseStatements";
ParsingContext[ParsingContext["TypeMembers"] = 4] = "TypeMembers";
ParsingContext[ParsingContext["ClassMembers"] = 5] = "ClassMembers";
ParsingContext[ParsingContext["EnumMembers"] = 6] = "EnumMembers";
ParsingContext[ParsingContext["HeritageClauseElement"] = 7] = "HeritageClauseElement";
ParsingContext[ParsingContext["VariableDeclarations"] = 8] = "VariableDeclarations";
ParsingContext[ParsingContext["ObjectBindingElements"] = 9] = "ObjectBindingElements";
ParsingContext[ParsingContext["ArrayBindingElements"] = 10] = "ArrayBindingElements";
ParsingContext[ParsingContext["ArgumentExpressions"] = 11] = "ArgumentExpressions";
ParsingContext[ParsingContext["ObjectLiteralMembers"] = 12] = "ObjectLiteralMembers";
ParsingContext[ParsingContext["JsxAttributes"] = 13] = "JsxAttributes";
ParsingContext[ParsingContext["JsxChildren"] = 14] = "JsxChildren";
ParsingContext[ParsingContext["ArrayLiteralMembers"] = 15] = "ArrayLiteralMembers";
ParsingContext[ParsingContext["Parameters"] = 16] = "Parameters";
ParsingContext[ParsingContext["TypeParameters"] = 17] = "TypeParameters";
ParsingContext[ParsingContext["TypeArguments"] = 18] = "TypeArguments";
ParsingContext[ParsingContext["TupleElementTypes"] = 19] = "TupleElementTypes";
ParsingContext[ParsingContext["HeritageClauses"] = 20] = "HeritageClauses";
ParsingContext[ParsingContext["ImportOrExportSpecifiers"] = 21] = "ImportOrExportSpecifiers";
ParsingContext[ParsingContext["JSDocFunctionParameters"] = 22] = "JSDocFunctionParameters";
ParsingContext[ParsingContext["JSDocTypeArguments"] = 23] = "JSDocTypeArguments";
ParsingContext[ParsingContext["JSDocRecordMembers"] = 24] = "JSDocRecordMembers";
ParsingContext[ParsingContext["JSDocTupleTypes"] = 25] = "JSDocTupleTypes";
ParsingContext[ParsingContext["Count"] = 26] = "Count"; // Number of parsing contexts
})(ParsingContext || (ParsingContext = {}));
var Tristate;
(function (Tristate) {
Tristate[Tristate["False"] = 0] = "False";
Tristate[Tristate["True"] = 1] = "True";
Tristate[Tristate["Unknown"] = 2] = "Unknown";
})(Tristate || (Tristate = {}));
var JSDocParser;
(function (JSDocParser) {
function isJSDocType() {
switch (token) {
case 37 /* AsteriskToken */:
case 52 /* QuestionToken */:
case 17 /* OpenParenToken */:
case 19 /* OpenBracketToken */:
case 48 /* ExclamationToken */:
case 15 /* OpenBraceToken */:
case 85 /* FunctionKeyword */:
case 22 /* DotDotDotToken */:
case 90 /* NewKeyword */:
case 95 /* ThisKeyword */:
return true;
}
return isIdentifierOrKeyword();
}
JSDocParser.isJSDocType = isJSDocType;
function parseJSDocTypeExpressionForTests(content, start, length) {
initializeState("file.js", content, 2 /* Latest */, /*_syntaxCursor:*/ undefined);
var jsDocTypeExpression = parseJSDocTypeExpression(start, length);
var diagnostics = parseDiagnostics;
clearState();
return jsDocTypeExpression ? { jsDocTypeExpression: jsDocTypeExpression, diagnostics: diagnostics } : undefined;
}
JSDocParser.parseJSDocTypeExpressionForTests = parseJSDocTypeExpressionForTests;
// Parses out a JSDoc type expression. The starting position should be right at the open
// curly in the type expression. Returns 'undefined' if it encounters any errors while parsing.
/* @internal */
function parseJSDocTypeExpression(start, length) {
scanner.setText(sourceText, start, length);
// Prime the first token for us to start processing.
token = nextToken();
var result = createNode(247 /* JSDocTypeExpression */);
parseExpected(15 /* OpenBraceToken */);
result.type = parseJSDocTopLevelType();
parseExpected(16 /* CloseBraceToken */);
fixupParentReferences(result);
return finishNode(result);
}
JSDocParser.parseJSDocTypeExpression = parseJSDocTypeExpression;
function parseJSDocTopLevelType() {
var type = parseJSDocType();
if (token === 46 /* BarToken */) {
var unionType = createNode(251 /* JSDocUnionType */, type.pos);
unionType.types = parseJSDocTypeList(type);
type = finishNode(unionType);
}
if (token === 55 /* EqualsToken */) {
var optionalType = createNode(258 /* JSDocOptionalType */, type.pos);
nextToken();
optionalType.type = type;
type = finishNode(optionalType);
}
return type;
}
function parseJSDocType() {
var type = parseBasicTypeExpression();
while (true) {
if (token === 19 /* OpenBracketToken */) {
var arrayType = createNode(250 /* JSDocArrayType */, type.pos);
arrayType.elementType = type;
nextToken();
parseExpected(20 /* CloseBracketToken */);
type = finishNode(arrayType);
}
else if (token === 52 /* QuestionToken */) {
var nullableType = createNode(253 /* JSDocNullableType */, type.pos);
nullableType.type = type;
nextToken();
type = finishNode(nullableType);
}
else if (token === 48 /* ExclamationToken */) {
var nonNullableType = createNode(254 /* JSDocNonNullableType */, type.pos);
nonNullableType.type = type;
nextToken();
type = finishNode(nonNullableType);
}
else {
break;
}
}
return type;
}
function parseBasicTypeExpression() {
switch (token) {
case 37 /* AsteriskToken */:
return parseJSDocAllType();
case 52 /* QuestionToken */:
return parseJSDocUnknownOrNullableType();
case 17 /* OpenParenToken */:
return parseJSDocUnionType();
case 19 /* OpenBracketToken */:
return parseJSDocTupleType();
case 48 /* ExclamationToken */:
return parseJSDocNonNullableType();
case 15 /* OpenBraceToken */:
return parseJSDocRecordType();
case 85 /* FunctionKeyword */:
return parseJSDocFunctionType();
case 22 /* DotDotDotToken */:
return parseJSDocVariadicType();
case 90 /* NewKeyword */:
return parseJSDocConstructorType();
case 95 /* ThisKeyword */:
return parseJSDocThisType();
case 115 /* AnyKeyword */:
case 128 /* StringKeyword */:
case 126 /* NumberKeyword */:
case 118 /* BooleanKeyword */:
case 129 /* SymbolKeyword */:
case 101 /* VoidKeyword */:
return parseTokenNode();
}
return parseJSDocTypeReference();
}
function parseJSDocThisType() {
var result = createNode(262 /* JSDocThisType */);
nextToken();
parseExpected(53 /* ColonToken */);
result.type = parseJSDocType();
return finishNode(result);
}
function parseJSDocConstructorType() {
var result = createNode(261 /* JSDocConstructorType */);
nextToken();
parseExpected(53 /* ColonToken */);
result.type = parseJSDocType();
return finishNode(result);
}
function parseJSDocVariadicType() {
var result = createNode(260 /* JSDocVariadicType */);
nextToken();
result.type = parseJSDocType();
return finishNode(result);
}
function parseJSDocFunctionType() {
var result = createNode(259 /* JSDocFunctionType */);
nextToken();
parseExpected(17 /* OpenParenToken */);
result.parameters = parseDelimitedList(22 /* JSDocFunctionParameters */, parseJSDocParameter);
checkForTrailingComma(result.parameters);
parseExpected(18 /* CloseParenToken */);
if (token === 53 /* ColonToken */) {
nextToken();
result.type = parseJSDocType();
}
return finishNode(result);
}
function parseJSDocParameter() {
var parameter = createNode(136 /* Parameter */);
parameter.type = parseJSDocType();
return finishNode(parameter);
}
function parseJSDocOptionalType(type) {
var result = createNode(258 /* JSDocOptionalType */, type.pos);
nextToken();
result.type = type;
return finishNode(result);
}
function parseJSDocTypeReference() {
var result = createNode(257 /* JSDocTypeReference */);
result.name = parseSimplePropertyName();
while (parseOptional(21 /* DotToken */)) {
if (token === 25 /* LessThanToken */) {
result.typeArguments = parseTypeArguments();
break;
}
else {
result.name = parseQualifiedName(result.name);
}
}
return finishNode(result);
}
function parseTypeArguments() {
// Move past the <
nextToken();
var typeArguments = parseDelimitedList(23 /* JSDocTypeArguments */, parseJSDocType);
checkForTrailingComma(typeArguments);
checkForEmptyTypeArgumentList(typeArguments);
parseExpected(27 /* GreaterThanToken */);
return typeArguments;
}
function checkForEmptyTypeArgumentList(typeArguments) {
if (parseDiagnostics.length === 0 && typeArguments && typeArguments.length === 0) {
var start = typeArguments.pos - "<".length;
var end = ts.skipTrivia(sourceText, typeArguments.end) + ">".length;
return parseErrorAtPosition(start, end - start, ts.Diagnostics.Type_argument_list_cannot_be_empty);
}
}
function parseQualifiedName(left) {
var result = createNode(133 /* QualifiedName */, left.pos);
result.left = left;
result.right = parseIdentifierName();
return finishNode(result);
}
function parseJSDocRecordType() {
var result = createNode(255 /* JSDocRecordType */);
nextToken();
result.members = parseDelimitedList(24 /* JSDocRecordMembers */, parseJSDocRecordMember);
checkForTrailingComma(result.members);
parseExpected(16 /* CloseBraceToken */);
return finishNode(result);
}
function parseJSDocRecordMember() {
var result = createNode(256 /* JSDocRecordMember */);
result.name = parseSimplePropertyName();
if (token === 53 /* ColonToken */) {
nextToken();
result.type = parseJSDocType();
}
return finishNode(result);
}
function parseJSDocNonNullableType() {
var result = createNode(254 /* JSDocNonNullableType */);
nextToken();
result.type = parseJSDocType();
return finishNode(result);
}
function parseJSDocTupleType() {
var result = createNode(252 /* JSDocTupleType */);
nextToken();
result.types = parseDelimitedList(25 /* JSDocTupleTypes */, parseJSDocType);
checkForTrailingComma(result.types);
parseExpected(20 /* CloseBracketToken */);
return finishNode(result);
}
function checkForTrailingComma(list) {
if (parseDiagnostics.length === 0 && list.hasTrailingComma) {
var start = list.end - ",".length;
parseErrorAtPosition(start, ",".length, ts.Diagnostics.Trailing_comma_not_allowed);
}
}
function parseJSDocUnionType() {
var result = createNode(251 /* JSDocUnionType */);
nextToken();
result.types = parseJSDocTypeList(parseJSDocType());
parseExpected(18 /* CloseParenToken */);
return finishNode(result);
}
function parseJSDocTypeList(firstType) {
ts.Debug.assert(!!firstType);
var types = [];
types.pos = firstType.pos;
types.push(firstType);
while (parseOptional(46 /* BarToken */)) {
types.push(parseJSDocType());
}
types.end = scanner.getStartPos();
return types;
}
function parseJSDocAllType() {
var result = createNode(248 /* JSDocAllType */);
nextToken();
return finishNode(result);
}
function parseJSDocUnknownOrNullableType() {
var pos = scanner.getStartPos();
// skip the ?
nextToken();
// Need to lookahead to decide if this is a nullable or unknown type.
// Here are cases where we'll pick the unknown type:
//
// Foo(?,
// { a: ? }
// Foo(?)
// Foo<?>
// Foo(?=
// (?|
if (token === 24 /* CommaToken */ ||
token === 16 /* CloseBraceToken */ ||
token === 18 /* CloseParenToken */ ||
token === 27 /* GreaterThanToken */ ||
token === 55 /* EqualsToken */ ||
token === 46 /* BarToken */) {
var result = createNode(249 /* JSDocUnknownType */, pos);
return finishNode(result);
}
else {
var result = createNode(253 /* JSDocNullableType */, pos);
result.type = parseJSDocType();
return finishNode(result);
}
}
function parseIsolatedJSDocComment(content, start, length) {
initializeState("file.js", content, 2 /* Latest */, /*_syntaxCursor:*/ undefined);
var jsDocComment = parseJSDocComment(/*parent:*/ undefined, start, length);
var diagnostics = parseDiagnostics;
clearState();
return jsDocComment ? { jsDocComment: jsDocComment, diagnostics: diagnostics } : undefined;
}
JSDocParser.parseIsolatedJSDocComment = parseIsolatedJSDocComment;
function parseJSDocComment(parent, start, length) {
var comment = parseJSDocCommentWorker(start, length);
if (comment) {
fixupParentReferences(comment);
comment.parent = parent;
}
return comment;
}
JSDocParser.parseJSDocComment = parseJSDocComment;
function 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 pos;
// NOTE(cyrusn): This is essentially a handwritten scanner for JSDocComments. I
// considered using an actual Scanner, but this would complicate things. The
// scanner would need to know it was in a Doc Comment. Otherwise, it would then
// produce comments *inside* the doc comment. In the end it was just easier to
// write a simple scanner rather than go that route.
if (length >= "/** */".length) {
if (content.charCodeAt(start) === 47 /* slash */ &&
content.charCodeAt(start + 1) === 42 /* asterisk */ &&
content.charCodeAt(start + 2) === 42 /* asterisk */ &&
content.charCodeAt(start + 3) !== 42 /* asterisk */) {
// Initially we can parse out a tag. We also have seen a starting asterisk.
// This is so that /** * @type */ doesn't parse.
var canParseTag = true;
var seenAsterisk = true;
for (pos = start + "/**".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at */ && canParseTag) {
parseTag();
// Once we parse out a tag, we cannot keep parsing out tags on this line.
canParseTag = false;
continue;
}
if (ts.isLineBreak(ch)) {
// After a line break, we can parse a tag, and we haven't seen as asterisk
// on the next line yet.
canParseTag = true;
seenAsterisk = false;
continue;
}
if (ts.isWhiteSpace(ch)) {
// Whitespace doesn't affect any of our parsing.
continue;
}
// Ignore the first asterisk on a line.
if (ch === 42 /* asterisk */) {
if (seenAsterisk) {
// If we've already seen an asterisk, then we can no longer parse a tag
// on this line.
canParseTag = false;
}
seenAsterisk = true;
continue;
}
// Anything else is doc comment text. We can't do anything with it. Because it
// wasn't a tag, we can no longer parse a tag on this line until we hit the next
// line break.
canParseTag = false;
}
}
}
return createJSDocComment();
function createJSDocComment() {
if (!tags) {
return undefined;
}
var result = createNode(263 /* JSDocComment */, start);
result.tags = tags;
return finishNode(result, end);
}
function skipWhitespace() {
while (pos < end && ts.isWhiteSpace(content.charCodeAt(pos))) {
pos++;
}
}
function parseTag() {
ts.Debug.assert(content.charCodeAt(pos - 1) === 64 /* at */);
var atToken = createNode(54 /* AtToken */, pos - 1);
atToken.end = pos;
var tagName = scanIdentifier();
if (!tagName) {
return;
}
var tag = handleTag(atToken, tagName) || handleUnknownTag(atToken, tagName);
addTag(tag);
}
function handleTag(atToken, tagName) {
if (tagName) {
switch (tagName.text) {
case "param":
return handleParamTag(atToken, tagName);
case "return":
case "returns":
return handleReturnTag(atToken, tagName);
case "template":
return handleTemplateTag(atToken, tagName);
case "type":
return handleTypeTag(atToken, tagName);
}
}
return undefined;
}
function handleUnknownTag(atToken, tagName) {
var result = createNode(264 /* JSDocTag */, atToken.pos);
result.atToken = atToken;
result.tagName = tagName;
return finishNode(result, pos);
}
function addTag(tag) {
if (tag) {
if (!tags) {
tags = [];
tags.pos = tag.pos;
}
tags.push(tag);
tags.end = tag.end;
}
}
function tryParseTypeExpression() {
skipWhitespace();
if (content.charCodeAt(pos) !== 123 /* openBrace */) {
return undefined;
}
var typeExpression = parseJSDocTypeExpression(pos, end - pos);
pos = typeExpression.end;
return typeExpression;
}
function handleParamTag(atToken, tagName) {
var typeExpression = tryParseTypeExpression();
skipWhitespace();
var name;
var isBracketed;
if (content.charCodeAt(pos) === 91 /* openBracket */) {
pos++;
skipWhitespace();
name = scanIdentifier();
isBracketed = true;
}
else {
name = scanIdentifier();
}
if (!name) {
parseErrorAtPosition(pos, 0, ts.Diagnostics.Identifier_expected);
}
var preName, postName;
if (typeExpression) {
postName = name;
}
else {
preName = name;
}
if (!typeExpression) {
typeExpression = tryParseTypeExpression();
}
var result = createNode(265 /* JSDocParameterTag */, atToken.pos);
result.atToken = atToken;
result.tagName = tagName;
result.preParameterName = preName;
result.typeExpression = typeExpression;
result.postParameterName = postName;
result.isBracketed = isBracketed;
return finishNode(result, pos);
}
function handleReturnTag(atToken, tagName) {
if (ts.forEach(tags, function (t) { return t.kind === 266 /* JSDocReturnTag */; })) {
parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text);
}
var result = createNode(266 /* JSDocReturnTag */, atToken.pos);
result.atToken = atToken;
result.tagName = tagName;
result.typeExpression = tryParseTypeExpression();
return finishNode(result, pos);
}
function handleTypeTag(atToken, tagName) {
if (ts.forEach(tags, function (t) { return t.kind === 267 /* JSDocTypeTag */; })) {
parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text);
}
var result = createNode(267 /* JSDocTypeTag */, atToken.pos);
result.atToken = atToken;
result.tagName = tagName;
result.typeExpression = tryParseTypeExpression();
return finishNode(result, pos);
}
function handleTemplateTag(atToken, tagName) {
if (ts.forEach(tags, function (t) { return t.kind === 268 /* JSDocTemplateTag */; })) {
parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text);
}
var typeParameters = [];
typeParameters.pos = pos;
while (true) {
skipWhitespace();
var startPos = pos;
var name_8 = scanIdentifier();
if (!name_8) {
parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected);
return undefined;
}
var typeParameter = createNode(135 /* TypeParameter */, name_8.pos);
typeParameter.name = name_8;
finishNode(typeParameter, pos);
typeParameters.push(typeParameter);
skipWhitespace();
if (content.charCodeAt(pos) !== 44 /* comma */) {
break;
}
pos++;
}
typeParameters.end = pos;
var result = createNode(268 /* JSDocTemplateTag */, atToken.pos);
result.atToken = atToken;
result.tagName = tagName;
result.typeParameters = typeParameters;
return finishNode(result, pos);
}
function scanIdentifier() {
var startPos = pos;
for (; pos < end; pos++) {
var ch = content.charCodeAt(pos);
if (pos === startPos && ts.isIdentifierStart(ch, 2 /* Latest */)) {
continue;
}
else if (pos > startPos && ts.isIdentifierPart(ch, 2 /* Latest */)) {
continue;
}
break;
}
if (startPos === pos) {
return undefined;
}
var result = createNode(67 /* Identifier */, startPos);
result.text = content.substring(startPos, pos);
return finishNode(result, pos);
}
}
JSDocParser.parseJSDocCommentWorker = parseJSDocCommentWorker;
})(JSDocParser = Parser.JSDocParser || (Parser.JSDocParser = {}));
})(Parser || (Parser = {}));
var IncrementalParser;
(function (IncrementalParser) {
function updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks) {
aggressiveChecks = aggressiveChecks || ts.Debug.shouldAssert(2 /* Aggressive */);
checkChangeRange(sourceFile, newText, textChangeRange, aggressiveChecks);
if (ts.textChangeRangeIsUnchanged(textChangeRange)) {
// if the text didn't change, then we can just return our current source file as-is.
return sourceFile;
}
if (sourceFile.statements.length === 0) {
// If we don't have any statements in the current source file, then there's no real
// way to incrementally parse. So just do a full parse instead.
return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setNodeParents*/ true);
}
// Make sure we're not trying to incrementally update a source file more than once. Once
// we do an update the original source file is considered unusbale from that point onwards.
//
// This is because we do incremental parsing in-place. i.e. we take nodes from the old
// tree and give them new positions and parents. From that point on, trusting the old
// tree at all is not possible as far too much of it may violate invariants.
var incrementalSourceFile = sourceFile;
ts.Debug.assert(!incrementalSourceFile.hasBeenIncrementallyParsed);
incrementalSourceFile.hasBeenIncrementallyParsed = true;
var oldText = sourceFile.text;
var syntaxCursor = createSyntaxCursor(sourceFile);
// Make the actual change larger so that we know to reparse anything whose lookahead
// might have intersected the change.
var changeRange = extendToAffectedRange(sourceFile, textChangeRange);
checkChangeRange(sourceFile, newText, changeRange, aggressiveChecks);
// Ensure that extending the affected range only moved the start of the change range
// earlier in the file.
ts.Debug.assert(changeRange.span.start <= textChangeRange.span.start);
ts.Debug.assert(ts.textSpanEnd(changeRange.span) === ts.textSpanEnd(textChangeRange.span));
ts.Debug.assert(ts.textSpanEnd(ts.textChangeRangeNewSpan(changeRange)) === ts.textSpanEnd(ts.textChangeRangeNewSpan(textChangeRange)));
// The is the amount the nodes after the edit range need to be adjusted. It can be
// positive (if the edit added characters), negative (if the edit deleted characters)
// or zero (if this was a pure overwrite with nothing added/removed).
var delta = ts.textChangeRangeNewSpan(changeRange).length - changeRange.span.length;
// If we added or removed characters during the edit, then we need to go and adjust all
// the nodes after the edit. Those nodes may move forward (if we inserted chars) or they
// may move backward (if we deleted chars).
//
// Doing this helps us out in two ways. First, it means that any nodes/tokens we want
// to reuse are already at the appropriate position in the new text. That way when we
// reuse them, we don't have to figure out if they need to be adjusted. Second, it makes
// it very easy to determine if we can reuse a node. If the node's position is at where
// we are in the text, then we can reuse it. Otherwise we can't. If the node's position
// is ahead of us, then we'll need to rescan tokens. If the node's position is behind
// us, then we'll need to skip it or crumble it as appropriate
//
// We will also adjust the positions of nodes that intersect the change range as well.
// By doing this, we ensure that all the positions in the old tree are consistent, not
// just the positions of nodes entirely before/after the change range. By being
// consistent, we can then easily map from positions to nodes in the old tree easily.
//
// Also, mark any syntax elements that intersect the changed span. We know, up front,
// that we cannot reuse these elements.
updateTokenPositionsAndMarkElements(incrementalSourceFile, changeRange.span.start, ts.textSpanEnd(changeRange.span), ts.textSpanEnd(ts.textChangeRangeNewSpan(changeRange)), delta, oldText, newText, aggressiveChecks);
// Now that we've set up our internal incremental state just proceed and parse the
// source file in the normal fashion. When possible the parser will retrieve and
// reuse nodes from the old tree.
//
// Note: passing in 'true' for setNodeParents is very important. When incrementally
// parsing, we will be reusing nodes from the old tree, and placing it into new
// parents. If we don't set the parents now, we'll end up with an observably
// inconsistent tree. Setting the parents on the new tree should be very fast. We
// will immediately bail out of walking any subtrees when we can see that their parents
// are already correct.
var result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /* setParentNode */ true);
return result;
}
IncrementalParser.updateSourceFile = updateSourceFile;
function moveElementEntirelyPastChangeRange(element, isArray, delta, oldText, newText, aggressiveChecks) {
if (isArray) {
visitArray(element);
}
else {
visitNode(element);
}
return;
function visitNode(node) {
var text = "";
if (aggressiveChecks && shouldCheckNode(node)) {
text = oldText.substring(node.pos, node.end);
}
// Ditch any existing LS children we may have created. This way we can avoid
// moving them forward.
if (node._children) {
node._children = undefined;
}
if (node.jsDocComment) {
node.jsDocComment = undefined;
}
node.pos += delta;
node.end += delta;
if (aggressiveChecks && shouldCheckNode(node)) {
ts.Debug.assert(text === newText.substring(node.pos, node.end));
}
forEachChild(node, visitNode, visitArray);
checkNodePositions(node, aggressiveChecks);
}
function visitArray(array) {
array._children = undefined;
array.pos += delta;
array.end += delta;
for (var _i = 0; _i < array.length; _i++) {
var node = array[_i];
visitNode(node);
}
}
}
function shouldCheckNode(node) {
switch (node.kind) {
case 9 /* StringLiteral */:
case 8 /* NumericLiteral */:
case 67 /* Identifier */:
return true;
}
return false;
}
function adjustIntersectingElement(element, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta) {
ts.Debug.assert(element.end >= changeStart, "Adjusting an element that was entirely before the change range");
ts.Debug.assert(element.pos <= changeRangeOldEnd, "Adjusting an element that was entirely after the change range");
ts.Debug.assert(element.pos <= element.end);
// We have an element that intersects the change range in some way. It may have its
// start, or its end (or both) in the changed range. We want to adjust any part
// that intersects such that the final tree is in a consistent state. i.e. all
// chlidren have spans within the span of their parent, and all siblings are ordered
// properly.
// We may need to update both the 'pos' and the 'end' of the element.
// If the 'pos' is before the start of the change, then we don't need to touch it.
// If it isn't, then the 'pos' must be inside the change. How we update it will
// depend if delta is positive or negative. If delta is positive then we have
// something like:
//
// -------------------AAA-----------------
// -------------------BBBCCCCCCC-----------------
//
// In this case, we consider any node that started in the change range to still be
// starting at the same position.
//
// however, if the delta is negative, then we instead have something like this:
//
// -------------------XXXYYYYYYY-----------------
// -------------------ZZZ-----------------
//
// In this case, any element that started in the 'X' range will keep its position.
// However any element htat started after that will have their pos adjusted to be
// at the end of the new range. i.e. any node that started in the 'Y' range will
// be adjusted to have their start at the end of the 'Z' range.
//
// The element will keep its position if possible. Or Move backward to the new-end
// if it's in the 'Y' range.
element.pos = Math.min(element.pos, changeRangeNewEnd);
// If the 'end' is after the change range, then we always adjust it by the delta
// amount. However, if the end is in the change range, then how we adjust it
// will depend on if delta is positive or negative. If delta is positive then we
// have something like:
//
// -------------------AAA-----------------
// -------------------BBBCCCCCCC-----------------
//
// In this case, we consider any node that ended inside the change range to keep its
// end position.
//
// however, if the delta is negative, then we instead have something like this:
//
// -------------------XXXYYYYYYY-----------------
// -------------------ZZZ-----------------
//
// In this case, any element that ended in the 'X' range will keep its position.
// However any element htat ended after that will have their pos adjusted to be
// at the end of the new range. i.e. any node that ended in the 'Y' range will
// be adjusted to have their end at the end of the 'Z' range.
if (element.end >= changeRangeOldEnd) {
// Element ends after the change range. Always adjust the end pos.
element.end += delta;
}
else {
// Element ends in the change range. The element will keep its position if
// possible. Or Move backward to the new-end if it's in the 'Y' range.
element.end = Math.min(element.end, changeRangeNewEnd);
}
ts.Debug.assert(element.pos <= element.end);
if (element.parent) {
ts.Debug.assert(element.pos >= element.parent.pos);
ts.Debug.assert(element.end <= element.parent.end);
}
}
function checkNodePositions(node, aggressiveChecks) {
if (aggressiveChecks) {
var pos = node.pos;
forEachChild(node, function (child) {
ts.Debug.assert(child.pos >= pos);
pos = child.end;
});
ts.Debug.assert(pos <= node.end);
}
}
function updateTokenPositionsAndMarkElements(sourceFile, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta, oldText, newText, aggressiveChecks) {
visitNode(sourceFile);
return;
function visitNode(child) {
ts.Debug.assert(child.pos <= child.end);
if (child.pos > changeRangeOldEnd) {
// Node is entirely past the change range. We need to move both its pos and
// end, forward or backward appropriately.
moveElementEntirelyPastChangeRange(child, /*isArray*/ false, delta, oldText, newText, aggressiveChecks);
return;
}
// Check if the element intersects the change range. If it does, then it is not
// reusable. Also, we'll need to recurse to see what constituent portions we may
// be able to use.
var fullEnd = child.end;
if (fullEnd >= changeStart) {
child.intersectsChange = true;
child._children = undefined;
// Adjust the pos or end (or both) of the intersecting element accordingly.
adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
forEachChild(child, visitNode, visitArray);
checkNodePositions(child, aggressiveChecks);
return;
}
// Otherwise, the node is entirely before the change range. No need to do anything with it.
ts.Debug.assert(fullEnd < changeStart);
}
function visitArray(array) {
ts.Debug.assert(array.pos <= array.end);
if (array.pos > changeRangeOldEnd) {
// Array is entirely after the change range. We need to move it, and move any of
// its children.
moveElementEntirelyPastChangeRange(array, /*isArray*/ true, delta, oldText, newText, aggressiveChecks);
return;
}
// Check if the element intersects the change range. If it does, then it is not
// reusable. Also, we'll need to recurse to see what constituent portions we may
// be able to use.
var fullEnd = array.end;
if (fullEnd >= changeStart) {
array.intersectsChange = true;
array._children = undefined;
// Adjust the pos or end (or both) of the intersecting array accordingly.
adjustIntersectingElement(array, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
for (var _i = 0; _i < array.length; _i++) {
var node = array[_i];
visitNode(node);
}
return;
}
// Otherwise, the array is entirely before the change range. No need to do anything with it.
ts.Debug.assert(fullEnd < changeStart);
}
}
function extendToAffectedRange(sourceFile, changeRange) {
// Consider the following code:
// void foo() { /; }
//
// If the text changes with an insertion of / just before the semicolon then we end up with:
// void foo() { //; }
//
// If we were to just use the changeRange a is, then we would not rescan the { token
// (as it does not intersect the actual original change range). Because an edit may
// change the token touching it, we actually need to look back *at least* one token so
// that the prior token sees that change.
var maxLookahead = 1;
var start = changeRange.span.start;
// the first iteration aligns us with the change start. subsequent iteration move us to
// the left by maxLookahead tokens. We only need to do this as long as we're not at the
// start of the tree.
for (var i = 0; start > 0 && i <= maxLookahead; i++) {
var nearestNode = findNearestNodeStartingBeforeOrAtPosition(sourceFile, start);
ts.Debug.assert(nearestNode.pos <= start);
var position = nearestNode.pos;
start = Math.max(0, position - 1);
}
var finalSpan = ts.createTextSpanFromBounds(start, ts.textSpanEnd(changeRange.span));
var finalLength = changeRange.newLength + (changeRange.span.start - start);
return ts.createTextChangeRange(finalSpan, finalLength);
}
function findNearestNodeStartingBeforeOrAtPosition(sourceFile, position) {
var bestResult = sourceFile;
var lastNodeEntirelyBeforePosition;
forEachChild(sourceFile, visit);
if (lastNodeEntirelyBeforePosition) {
var lastChildOfLastEntireNodeBeforePosition = getLastChild(lastNodeEntirelyBeforePosition);
if (lastChildOfLastEntireNodeBeforePosition.pos > bestResult.pos) {
bestResult = lastChildOfLastEntireNodeBeforePosition;
}
}
return bestResult;
function getLastChild(node) {
while (true) {
var lastChild = getLastChildWorker(node);
if (lastChild) {
node = lastChild;
}
else {
return node;
}
}
}
function getLastChildWorker(node) {
var last = undefined;
forEachChild(node, function (child) {
if (ts.nodeIsPresent(child)) {
last = child;
}
});
return last;
}
function visit(child) {
if (ts.nodeIsMissing(child)) {
// Missing nodes are effectively invisible to us. We never even consider them
// When trying to find the nearest node before us.
return;
}
// If the child intersects this position, then this node is currently the nearest
// node that starts before the position.
if (child.pos <= position) {
if (child.pos >= bestResult.pos) {
// This node starts before the position, and is closer to the position than
// the previous best node we found. It is now the new best node.
bestResult = child;
}
// Now, the node may overlap the position, or it may end entirely before the
// position. If it overlaps with the position, then either it, or one of its
// children must be the nearest node before the position. So we can just
// recurse into this child to see if we can find something better.
if (position < child.end) {
// The nearest node is either this child, or one of the children inside
// of it. We've already marked this child as the best so far. Recurse
// in case one of the children is better.
forEachChild(child, visit);
// Once we look at the children of this node, then there's no need to
// continue any further.
return true;
}
else {
ts.Debug.assert(child.end <= position);
// The child ends entirely before this position. Say you have the following
// (where $ is the position)
//
// <complex expr 1> ? <complex expr 2> $ : <...> <...>
//
// We would want to find the nearest preceding node in "complex expr 2".
// To support that, we keep track of this node, and once we're done searching
// for a best node, we recurse down this node to see if we can find a good
// result in it.
//
// This approach allows us to quickly skip over nodes that are entirely
// before the position, while still allowing us to find any nodes in the
// last one that might be what we want.
lastNodeEntirelyBeforePosition = child;
}
}
else {
ts.Debug.assert(child.pos > position);
// We're now at a node that is entirely past the position we're searching for.
// This node (and all following nodes) could never contribute to the result,
// so just skip them by returning 'true' here.
return true;
}
}
}
function checkChangeRange(sourceFile, newText, textChangeRange, aggressiveChecks) {
var oldText = sourceFile.text;
if (textChangeRange) {
ts.Debug.assert((oldText.length - textChangeRange.span.length + textChangeRange.newLength) === newText.length);
if (aggressiveChecks || ts.Debug.shouldAssert(3 /* VeryAggressive */)) {
var oldTextPrefix = oldText.substr(0, textChangeRange.span.start);
var newTextPrefix = newText.substr(0, textChangeRange.span.start);
ts.Debug.assert(oldTextPrefix === newTextPrefix);
var oldTextSuffix = oldText.substring(ts.textSpanEnd(textChangeRange.span), oldText.length);
var newTextSuffix = newText.substring(ts.textSpanEnd(ts.textChangeRangeNewSpan(textChangeRange)), newText.length);
ts.Debug.assert(oldTextSuffix === newTextSuffix);
}
}
}
function createSyntaxCursor(sourceFile) {
var currentArray = sourceFile.statements;
var currentArrayIndex = 0;
ts.Debug.assert(currentArrayIndex < currentArray.length);
var current = currentArray[currentArrayIndex];
var lastQueriedPosition = -1 /* Value */;
return {
currentNode: function (position) {
// Only compute the current node if the position is different than the last time
// we were asked. The parser commonly asks for the node at the same position
// twice. Once to know if can read an appropriate list element at a certain point,
// and then to actually read and consume the node.
if (position !== lastQueriedPosition) {
// Much of the time the parser will need the very next node in the array that
// we just returned a node from.So just simply check for that case and move
// forward in the array instead of searching for the node again.
if (current && current.end === position && currentArrayIndex < (currentArray.length - 1)) {
currentArrayIndex++;
current = currentArray[currentArrayIndex];
}
// If we don't have a node, or the node we have isn't in the right position,
// then try to find a viable node at the position requested.
if (!current || current.pos !== position) {
findHighestListElementThatStartsAtPosition(position);
}
}
// Cache this query so that we don't do any extra work if the parser calls back
// into us. Note: this is very common as the parser will make pairs of calls like
// 'isListElement -> parseListElement'. If we were unable to find a node when
// called with 'isListElement', we don't want to redo the work when parseListElement
// is called immediately after.
lastQueriedPosition = position;
// Either we don'd have a node, or we have a node at the position being asked for.
ts.Debug.assert(!current || current.pos === position);
return current;
}
};
// Finds the highest element in the tree we can find that starts at the provided position.
// The element must be a direct child of some node list in the tree. This way after we
// return it, we can easily return its next sibling in the list.
function findHighestListElementThatStartsAtPosition(position) {
// Clear out any cached state about the last node we found.
currentArray = undefined;
currentArrayIndex = -1 /* Value */;
current = undefined;
// Recurse into the source file to find the highest node at this position.
forEachChild(sourceFile, visitNode, visitArray);
return;
function visitNode(node) {
if (position >= node.pos && position < node.end) {
// Position was within this node. Keep searching deeper to find the node.
forEachChild(node, visitNode, visitArray);
// don't procede any futher in the search.
return true;
}
// position wasn't in this node, have to keep searching.
return false;
}
function visitArray(array) {
if (position >= array.pos && position < array.end) {
// position was in this array. Search through this array to see if we find a
// viable element.
for (var i = 0, n = array.length; i < n; i++) {
var child = array[i];
if (child) {
if (child.pos === position) {
// Found the right node. We're done.
currentArray = array;
currentArrayIndex = i;
current = child;
return true;
}
else {
if (child.pos < position && position < child.end) {
// Position in somewhere within this child. Search in it and
// stop searching in this array.
forEachChild(child, visitNode, visitArray);
return true;
}
}
}
}
}
// position wasn't in this array, have to keep searching.
return false;
}
}
}
var InvalidPosition;
(function (InvalidPosition) {
InvalidPosition[InvalidPosition["Value"] = -1] = "Value";
})(InvalidPosition || (InvalidPosition = {}));
})(IncrementalParser || (IncrementalParser = {}));
})(ts || (ts = {}));
/// <reference path="binder.ts"/>
/* @internal */
var ts;
(function (ts) {
var nextSymbolId = 1;
var nextNodeId = 1;
var nextMergeId = 1;
function getNodeId(node) {
if (!node.id)
node.id = nextNodeId++;
return node.id;
}
ts.getNodeId = getNodeId;
ts.checkTime = 0;
function getSymbolId(symbol) {
if (!symbol.id) {
symbol.id = nextSymbolId++;
}
return symbol.id;
}
ts.getSymbolId = getSymbolId;
function createTypeChecker(host, produceDiagnostics) {
// Cancellation that controls whether or not we can cancel in the middle of type checking.
// In general cancelling is *not* safe for the type checker. We might be in the middle of
// computing something, and we will leave our internals in an inconsistent state. Callers
// who set the cancellation token should catch if a cancellation exception occurs, and
// should throw away and create a new TypeChecker.
//
// Currently we only support setting the cancellation token when getting diagnostics. This
// is because diagnostics can be quite expensive, and we want to allow hosts to bail out if
// they no longer need the information (for example, if the user started editing again).
var cancellationToken;
var Symbol = ts.objectAllocator.getSymbolConstructor();
var Type = ts.objectAllocator.getTypeConstructor();
var Signature = ts.objectAllocator.getSignatureConstructor();
var typeCount = 0;
var emptyArray = [];
var emptySymbols = {};
var compilerOptions = host.getCompilerOptions();
var languageVersion = compilerOptions.target || 0 /* ES3 */;
var emitResolver = createResolver();
var undefinedSymbol = createSymbol(4 /* Property */ | 67108864 /* Transient */, "undefined");
var argumentsSymbol = createSymbol(4 /* Property */ | 67108864 /* Transient */, "arguments");
var checker = {
getNodeCount: function () { return ts.sum(host.getSourceFiles(), "nodeCount"); },
getIdentifierCount: function () { return ts.sum(host.getSourceFiles(), "identifierCount"); },
getSymbolCount: function () { return ts.sum(host.getSourceFiles(), "symbolCount"); },
getTypeCount: function () { return typeCount; },
isUndefinedSymbol: function (symbol) { return symbol === undefinedSymbol; },
isArgumentsSymbol: function (symbol) { return symbol === argumentsSymbol; },
getDiagnostics: getDiagnostics,
getGlobalDiagnostics: getGlobalDiagnostics,
// The language service will always care about the narrowed type of a symbol, because that is
// the type the language says the symbol should have.
getTypeOfSymbolAtLocation: getNarrowedTypeOfSymbol,
getDeclaredTypeOfSymbol: getDeclaredTypeOfSymbol,
getPropertiesOfType: getPropertiesOfType,
getPropertyOfType: getPropertyOfType,
getSignaturesOfType: getSignaturesOfType,
getIndexTypeOfType: getIndexTypeOfType,
getBaseTypes: getBaseTypes,
getReturnTypeOfSignature: getReturnTypeOfSignature,
getSymbolsInScope: getSymbolsInScope,
getSymbolAtLocation: getSymbolAtLocation,
getShorthandAssignmentValueSymbol: getShorthandAssignmentValueSymbol,
getTypeAtLocation: getTypeOfNode,
typeToString: typeToString,
getSymbolDisplayBuilder: getSymbolDisplayBuilder,
symbolToString: symbolToString,
getAugmentedPropertiesOfType: getAugmentedPropertiesOfType,
getRootSymbols: getRootSymbols,
getContextualType: getContextualType,
getFullyQualifiedName: getFullyQualifiedName,
getResolvedSignature: getResolvedSignature,
getConstantValue: getConstantValue,
isValidPropertyAccess: isValidPropertyAccess,
getSignatureFromDeclaration: getSignatureFromDeclaration,
isImplementationOfOverload: isImplementationOfOverload,
getAliasedSymbol: resolveAlias,
getEmitResolver: getEmitResolver,
getExportsOfModule: getExportsOfModuleAsArray,
getJsxElementAttributesType: getJsxElementAttributesType,
getJsxIntrinsicTagNames: getJsxIntrinsicTagNames,
isOptionalParameter: isOptionalParameter
};
var unknownSymbol = createSymbol(4 /* Property */ | 67108864 /* Transient */, "unknown");
var resolvingSymbol = createSymbol(67108864 /* Transient */, "__resolving__");
var anyType = createIntrinsicType(1 /* Any */, "any");
var stringType = createIntrinsicType(2 /* String */, "string");
var numberType = createIntrinsicType(4 /* Number */, "number");
var booleanType = createIntrinsicType(8 /* Boolean */, "boolean");
var esSymbolType = createIntrinsicType(16777216 /* ESSymbol */, "symbol");
var voidType = createIntrinsicType(16 /* Void */, "void");
var undefinedType = createIntrinsicType(32 /* Undefined */ | 2097152 /* ContainsUndefinedOrNull */, "undefined");
var nullType = createIntrinsicType(64 /* Null */ | 2097152 /* ContainsUndefinedOrNull */, "null");
var unknownType = createIntrinsicType(1 /* Any */, "unknown");
var circularType = createIntrinsicType(1 /* Any */, "__circular__");
var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
var emptyGenericType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
emptyGenericType.instantiations = {};
var anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
// The anyFunctionType contains the anyFunctionType by definition. The flag is further propagated
// in getPropagatingFlagsOfTypes, and it is checked in inferFromTypes.
anyFunctionType.flags |= 8388608 /* ContainsAnyFunctionType */;
var noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
var anySignature = createSignature(undefined, undefined, emptyArray, anyType, undefined, 0, false, false);
var unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, undefined, 0, false, false);
var globals = {};
var globalESSymbolConstructorSymbol;
var getGlobalPromiseConstructorSymbol;
var globalObjectType;
var globalFunctionType;
var globalArrayType;
var globalStringType;
var globalNumberType;
var globalBooleanType;
var globalRegExpType;
var globalTemplateStringsArrayType;
var globalESSymbolType;
var jsxElementType;
/** Lazily loaded, use getJsxIntrinsicElementType() */
var jsxIntrinsicElementsType;
var globalIterableType;
var globalIteratorType;
var globalIterableIteratorType;
var anyArrayType;
var getGlobalClassDecoratorType;
var getGlobalParameterDecoratorType;
var getGlobalPropertyDecoratorType;
var getGlobalMethodDecoratorType;
var getGlobalTypedPropertyDescriptorType;
var getGlobalPromiseType;
var tryGetGlobalPromiseType;
var getGlobalPromiseLikeType;
var getInstantiatedGlobalPromiseLikeType;
var getGlobalPromiseConstructorLikeType;
var getGlobalThenableType;
var tupleTypes = {};
var unionTypes = {};
var intersectionTypes = {};
var stringLiteralTypes = {};
var emitExtends = false;
var emitDecorate = false;
var emitParam = false;
var emitAwaiter = false;
var emitGenerator = false;
var resolutionTargets = [];
var resolutionResults = [];
var resolutionPropertyNames = [];
var mergedSymbols = [];
var symbolLinks = [];
var nodeLinks = [];
var potentialThisCollisions = [];
var awaitedTypeStack = [];
var diagnostics = ts.createDiagnosticCollection();
var primitiveTypeInfo = {
"string": {
type: stringType,
flags: 258 /* StringLike */
},
"number": {
type: numberType,
flags: 132 /* NumberLike */
},
"boolean": {
type: booleanType,
flags: 8 /* Boolean */
},
"symbol": {
type: esSymbolType,
flags: 16777216 /* ESSymbol */
}
};
var JsxNames = {
JSX: "JSX",
IntrinsicElements: "IntrinsicElements",
ElementClass: "ElementClass",
ElementAttributesPropertyNameContainer: "ElementAttributesProperty",
Element: "Element"
};
var subtypeRelation = {};
var assignableRelation = {};
var identityRelation = {};
// This is for caching the result of getSymbolDisplayBuilder. Do not access directly.
var _displayBuilder;
var TypeSystemPropertyName;
(function (TypeSystemPropertyName) {
TypeSystemPropertyName[TypeSystemPropertyName["Type"] = 0] = "Type";
TypeSystemPropertyName[TypeSystemPropertyName["ResolvedBaseConstructorType"] = 1] = "ResolvedBaseConstructorType";
TypeSystemPropertyName[TypeSystemPropertyName["DeclaredType"] = 2] = "DeclaredType";
TypeSystemPropertyName[TypeSystemPropertyName["ResolvedReturnType"] = 3] = "ResolvedReturnType";
})(TypeSystemPropertyName || (TypeSystemPropertyName = {}));
initializeTypeChecker();
return checker;
function getEmitResolver(sourceFile, cancellationToken) {
// Ensure we have all the type information in place for this file so that all the
// emitter questions of this resolver will return the right information.
getDiagnostics(sourceFile, cancellationToken);
return emitResolver;
}
function error(location, message, arg0, arg1, arg2) {
var diagnostic = location
? ts.createDiagnosticForNode(location, message, arg0, arg1, arg2)
: ts.createCompilerDiagnostic(message, arg0, arg1, arg2);
diagnostics.add(diagnostic);
}
function createSymbol(flags, name) {
return new Symbol(flags, name);
}
function getExcludedSymbolFlags(flags) {
var result = 0;
if (flags & 2 /* BlockScopedVariable */)
result |= 107455 /* BlockScopedVariableExcludes */;
if (flags & 1 /* FunctionScopedVariable */)
result |= 107454 /* FunctionScopedVariableExcludes */;
if (flags & 4 /* Property */)
result |= 107455 /* PropertyExcludes */;
if (flags & 8 /* EnumMember */)
result |= 107455 /* EnumMemberExcludes */;
if (flags & 16 /* Function */)
result |= 106927 /* FunctionExcludes */;
if (flags & 32 /* Class */)
result |= 899519 /* ClassExcludes */;
if (flags & 64 /* Interface */)
result |= 792960 /* InterfaceExcludes */;
if (flags & 256 /* RegularEnum */)
result |= 899327 /* RegularEnumExcludes */;
if (flags & 128 /* ConstEnum */)
result |= 899967 /* ConstEnumExcludes */;
if (flags & 512 /* ValueModule */)
result |= 106639 /* ValueModuleExcludes */;
if (flags & 8192 /* Method */)
result |= 99263 /* MethodExcludes */;
if (flags & 32768 /* GetAccessor */)
result |= 41919 /* GetAccessorExcludes */;
if (flags & 65536 /* SetAccessor */)
result |= 74687 /* SetAccessorExcludes */;
if (flags & 262144 /* TypeParameter */)
result |= 530912 /* TypeParameterExcludes */;
if (flags & 524288 /* TypeAlias */)
result |= 793056 /* TypeAliasExcludes */;
if (flags & 8388608 /* Alias */)
result |= 8388608 /* AliasExcludes */;
return result;
}
function recordMergedSymbol(target, source) {
if (!source.mergeId)
source.mergeId = nextMergeId++;
mergedSymbols[source.mergeId] = target;
}
function cloneSymbol(symbol) {
var result = createSymbol(symbol.flags | 33554432 /* Merged */, symbol.name);
result.declarations = symbol.declarations.slice(0);
result.parent = symbol.parent;
if (symbol.valueDeclaration)
result.valueDeclaration = symbol.valueDeclaration;
if (symbol.constEnumOnlyModule)
result.constEnumOnlyModule = true;
if (symbol.members)
result.members = cloneSymbolTable(symbol.members);
if (symbol.exports)
result.exports = cloneSymbolTable(symbol.exports);
recordMergedSymbol(result, symbol);
return result;
}
function mergeSymbol(target, source) {
if (!(target.flags & getExcludedSymbolFlags(source.flags))) {
if (source.flags & 512 /* ValueModule */ && target.flags & 512 /* ValueModule */ && target.constEnumOnlyModule && !source.constEnumOnlyModule) {
// reset flag when merging instantiated module into value module that has only const enums
target.constEnumOnlyModule = false;
}
target.flags |= source.flags;
if (!target.valueDeclaration && source.valueDeclaration)
target.valueDeclaration = source.valueDeclaration;
ts.forEach(source.declarations, function (node) {
target.declarations.push(node);
});
if (source.members) {
if (!target.members)
target.members = {};
mergeSymbolTable(target.members, source.members);
}
if (source.exports) {
if (!target.exports)
target.exports = {};
mergeSymbolTable(target.exports, source.exports);
}
recordMergedSymbol(target, source);
}
else {
var message = target.flags & 2 /* BlockScopedVariable */ || source.flags & 2 /* BlockScopedVariable */
? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0;
ts.forEach(source.declarations, function (node) {
error(node.name ? node.name : node, message, symbolToString(source));
});
ts.forEach(target.declarations, function (node) {
error(node.name ? node.name : node, message, symbolToString(source));
});
}
}
function cloneSymbolTable(symbolTable) {
var result = {};
for (var id in symbolTable) {
if (ts.hasProperty(symbolTable, id)) {
result[id] = symbolTable[id];
}
}
return result;
}
function mergeSymbolTable(target, source) {
for (var id in source) {
if (ts.hasProperty(source, id)) {
if (!ts.hasProperty(target, id)) {
target[id] = source[id];
}
else {
var symbol = target[id];
if (!(symbol.flags & 33554432 /* Merged */)) {
target[id] = symbol = cloneSymbol(symbol);
}
mergeSymbol(symbol, source[id]);
}
}
}
}
function getSymbolLinks(symbol) {
if (symbol.flags & 67108864 /* Transient */)
return symbol;
var id = getSymbolId(symbol);
return symbolLinks[id] || (symbolLinks[id] = {});
}
function getNodeLinks(node) {
var nodeId = getNodeId(node);
return nodeLinks[nodeId] || (nodeLinks[nodeId] = {});
}
function getSourceFile(node) {
return ts.getAncestor(node, 246 /* SourceFile */);
}
function isGlobalSourceFile(node) {
return node.kind === 246 /* SourceFile */ && !ts.isExternalModule(node);
}
function getSymbol(symbols, name, meaning) {
if (meaning && ts.hasProperty(symbols, name)) {
var symbol = symbols[name];
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.
}
/** Returns true if node1 is defined before node 2**/
function isDefinedBefore(node1, node2) {
var file1 = ts.getSourceFileOfNode(node1);
var file2 = ts.getSourceFileOfNode(node2);
if (file1 === file2) {
return node1.pos <= node2.pos;
}
if (!compilerOptions.outFile && !compilerOptions.out) {
return true;
}
var sourceFiles = host.getSourceFiles();
return sourceFiles.indexOf(file1) <= sourceFiles.indexOf(file2);
}
// Resolve a given name for a given meaning at a given location. An error is reported if the name was not found and
// the nameNotFoundMessage argument is not undefined. Returns the resolved symbol, or undefined if no symbol with
// the given name can be found.
function resolveName(location, name, meaning, nameNotFoundMessage, nameArg) {
var result;
var lastLocation;
var propertyWithInvalidInitializer;
var errorLocation = location;
var grandparent;
loop: while (location) {
// Locals of a source file are not in scope (because they get merged into the global symbol table)
if (location.locals && !isGlobalSourceFile(location)) {
if (result = getSymbol(location.locals, name, meaning)) {
// Type parameters of a function are in scope in the entire function declaration, including the parameter
// list and return type. However, local types are only in scope in the function body.
if (!(meaning & 793056 /* Type */) ||
!(result.flags & (793056 /* Type */ & ~262144 /* TypeParameter */)) ||
!ts.isFunctionLike(location) ||
lastLocation === location.body) {
break loop;
}
result = undefined;
}
}
switch (location.kind) {
case 246 /* SourceFile */:
if (!ts.isExternalModule(location))
break;
case 216 /* ModuleDeclaration */:
var moduleExports = getSymbolOfNode(location).exports;
if (location.kind === 246 /* SourceFile */ ||
(location.kind === 216 /* ModuleDeclaration */ && location.name.kind === 9 /* StringLiteral */)) {
// It's an external module. Because of module/namespace merging, a module's exports are in scope,
// yet we never want to treat an export specifier as putting a member in scope. Therefore,
// if the name we find is purely an export specifier, it is not actually considered in scope.
// Two things to note about this:
// 1. We have to check this without calling getSymbol. The problem with calling getSymbol
// on an export specifier is that it might find the export specifier itself, and try to
// resolve it as an alias. This will cause the checker to consider the export specifier
// a circular alias reference when it might not be.
// 2. We check === SymbolFlags.Alias in order to check that the symbol is *purely*
// an alias. If we used &, we'd be throwing out symbols that have non alias aspects,
// which is not the desired behavior.
if (ts.hasProperty(moduleExports, name) &&
moduleExports[name].flags === 8388608 /* Alias */ &&
ts.getDeclarationOfKind(moduleExports[name], 228 /* ExportSpecifier */)) {
break;
}
result = moduleExports["default"];
var localSymbol = ts.getLocalSymbolForExportDefault(result);
if (result && localSymbol && (result.flags & meaning) && localSymbol.name === name) {
break loop;
}
result = undefined;
}
if (result = getSymbol(moduleExports, name, meaning & 8914931 /* ModuleMember */)) {
break loop;
}
break;
case 215 /* EnumDeclaration */:
if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8 /* EnumMember */)) {
break loop;
}
break;
case 139 /* PropertyDeclaration */:
case 138 /* PropertySignature */:
// TypeScript 1.0 spec (April 2014): 8.4.1
// Initializer expressions for instance member variables are evaluated in the scope
// of the class constructor body but are not permitted to reference parameters or
// local variables of the constructor. This effectively means that entities from outer scopes
// by the same name as a constructor parameter or local variable are inaccessible
// in initializer expressions for instance member variables.
if (ts.isClassLike(location.parent) && !(location.flags & 128 /* Static */)) {
var ctor = findConstructorDeclaration(location.parent);
if (ctor && ctor.locals) {
if (getSymbol(ctor.locals, name, meaning & 107455 /* Value */)) {
// Remember the property node, it will be used later to report appropriate error
propertyWithInvalidInitializer = location;
}
}
}
break;
case 212 /* ClassDeclaration */:
case 184 /* ClassExpression */:
case 213 /* InterfaceDeclaration */:
if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793056 /* Type */)) {
if (lastLocation && lastLocation.flags & 128 /* Static */) {
// TypeScript 1.0 spec (April 2014): 3.4.1
// The scope of a type parameter extends over the entire declaration with which the type
// parameter list is associated, with the exception of static member declarations in classes.
error(errorLocation, ts.Diagnostics.Static_members_cannot_reference_class_type_parameters);
return undefined;
}
break loop;
}
if (location.kind === 184 /* 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 134 /* ComputedPropertyName */:
grandparent = location.parent.parent;
if (ts.isClassLike(grandparent) || grandparent.kind === 213 /* InterfaceDeclaration */) {
// A reference to this grandparent's type parameters would be an error
if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793056 /* Type */)) {
error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type);
return undefined;
}
}
break;
case 141 /* MethodDeclaration */:
case 140 /* MethodSignature */:
case 142 /* Constructor */:
case 143 /* GetAccessor */:
case 144 /* SetAccessor */:
case 211 /* FunctionDeclaration */:
case 172 /* ArrowFunction */:
if (meaning & 3 /* Variable */ && name === "arguments") {
result = argumentsSymbol;
break loop;
}
break;
case 171 /* 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 137 /* 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 === 136 /* Parameter */) {
location = location.parent;
}
//
// function y() {}
// class C {
// @y method(x, y) {} // <-- decorator y should be resolved at the class declaration, not the method.
// }
//
if (location.parent && ts.isClassElement(location.parent)) {
location = location.parent;
}
break;
}
lastLocation = location;
location = location.parent;
}
if (!result) {
result = getSymbol(globals, name, meaning);
}
if (!result) {
if (nameNotFoundMessage) {
error(errorLocation, nameNotFoundMessage, typeof nameArg === "string" ? nameArg : ts.declarationNameToString(nameArg));
}
return undefined;
}
// Perform extra checks only if error reporting was requested
if (nameNotFoundMessage) {
if (propertyWithInvalidInitializer) {
// We have a match, but the reference occurred within a property initializer and the identifier also binds
// to a local variable in the constructor where the code will be emitted.
var propertyName = propertyWithInvalidInitializer.name;
error(errorLocation, ts.Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor, ts.declarationNameToString(propertyName), typeof nameArg === "string" ? nameArg : ts.declarationNameToString(nameArg));
return undefined;
}
// Only check for block-scoped variable if we are looking for the
// name with variable meaning
// For example,
// declare module foo {
// interface bar {}
// }
// let foo/*1*/: foo/*2*/.bar;
// The foo at /*1*/ and /*2*/ will share same symbol with two meaning
// block - scope variable and namespace module. However, only when we
// try to resolve name in /*1*/ which is used in variable position,
// we want to check for block- scoped
if (meaning & 2 /* BlockScopedVariable */ && result.flags & 2 /* BlockScopedVariable */) {
checkResolvedBlockScopedVariable(result, errorLocation);
}
}
return result;
}
function checkResolvedBlockScopedVariable(result, errorLocation) {
ts.Debug.assert((result.flags & 2 /* BlockScopedVariable */) !== 0);
// Block-scoped variables cannot be used before their definition
var declaration = ts.forEach(result.declarations, function (d) { return ts.isBlockOrCatchScoped(d) ? d : undefined; });
ts.Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined");
// first check if usage is lexically located after the declaration
var isUsedBeforeDeclaration = !isDefinedBefore(declaration, errorLocation);
if (!isUsedBeforeDeclaration) {
// lexical check succeeded however code still can be illegal.
// - block scoped variables cannot be used in its initializers
// let x = x; // illegal but usage is lexically after definition
// - in ForIn/ForOf statements variable cannot be contained in expression part
// for (let x in x)
// for (let x of x)
// climb up to the variable declaration skipping binding patterns
var variableDeclaration = ts.getAncestor(declaration, 209 /* VariableDeclaration */);
var container = ts.getEnclosingBlockScopeContainer(variableDeclaration);
if (variableDeclaration.parent.parent.kind === 191 /* VariableStatement */ ||
variableDeclaration.parent.parent.kind === 197 /* ForStatement */) {
// variable statement/for statement case,
// use site should not be inside variable declaration (initializer of declaration or binding element)
isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, variableDeclaration, container);
}
else if (variableDeclaration.parent.parent.kind === 199 /* ForOfStatement */ ||
variableDeclaration.parent.parent.kind === 198 /* ForInStatement */) {
// ForIn/ForOf case - use site should not be used in expression part
var expression = variableDeclaration.parent.parent.expression;
isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, expression, container);
}
}
if (isUsedBeforeDeclaration) {
error(errorLocation, ts.Diagnostics.Block_scoped_variable_0_used_before_its_declaration, ts.declarationNameToString(declaration.name));
}
}
/* Starting from 'initial' node walk up the parent chain until 'stopAt' node is reached.
* If at any point current node is equal to 'parent' node - return true.
* Return false if 'stopAt' node is reached or isFunctionLike(current) === true.
*/
function isSameScopeDescendentOf(initial, parent, stopAt) {
if (!parent) {
return false;
}
for (var current = initial; current && current !== stopAt && !ts.isFunctionLike(current); current = current.parent) {
if (current === parent) {
return true;
}
}
return false;
}
function getAnyImportSyntax(node) {
if (ts.isAliasSymbolDeclaration(node)) {
if (node.kind === 219 /* ImportEqualsDeclaration */) {
return node;
}
while (node && node.kind !== 220 /* ImportDeclaration */) {
node = node.parent;
}
return node;
}
}
function getDeclarationOfAliasSymbol(symbol) {
return ts.forEach(symbol.declarations, function (d) { return ts.isAliasSymbolDeclaration(d) ? d : undefined; });
}
function getTargetOfImportEqualsDeclaration(node) {
if (node.moduleReference.kind === 230 /* ExternalModuleReference */) {
return resolveExternalModuleSymbol(resolveExternalModuleName(node, ts.getExternalModuleImportEqualsDeclarationExpression(node)));
}
return getSymbolOfPartOfRightHandSideOfImportEquals(node.moduleReference, node);
}
function getTargetOfImportClause(node) {
var moduleSymbol = resolveExternalModuleName(node, node.parent.moduleSpecifier);
if (moduleSymbol) {
var exportDefaultSymbol = resolveSymbol(moduleSymbol.exports["default"]);
if (!exportDefaultSymbol) {
error(node.name, ts.Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol));
}
return exportDefaultSymbol;
}
}
function getTargetOfNamespaceImport(node) {
var moduleSpecifier = node.parent.parent.moduleSpecifier;
return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier);
}
function getMemberOfModuleVariable(moduleSymbol, name) {
if (moduleSymbol.flags & 3 /* Variable */) {
var typeAnnotation = moduleSymbol.valueDeclaration.type;
if (typeAnnotation) {
return getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name);
}
}
}
// This function creates a synthetic symbol that combines the value side of one symbol with the
// type/namespace side of another symbol. Consider this example:
//
// declare module graphics {
// interface Point {
// x: number;
// y: number;
// }
// }
// declare var graphics: {
// Point: new (x: number, y: number) => graphics.Point;
// }
// declare module "graphics" {
// export = graphics;
// }
//
// An 'import { Point } from "graphics"' needs to create a symbol that combines the value side 'Point'
// property with the type/namespace side interface 'Point'.
function combineValueAndTypeSymbols(valueSymbol, typeSymbol) {
if (valueSymbol.flags & (793056 /* Type */ | 1536 /* Namespace */)) {
return valueSymbol;
}
var result = createSymbol(valueSymbol.flags | typeSymbol.flags, valueSymbol.name);
result.declarations = ts.concatenate(valueSymbol.declarations, typeSymbol.declarations);
result.parent = valueSymbol.parent || typeSymbol.parent;
if (valueSymbol.valueDeclaration)
result.valueDeclaration = valueSymbol.valueDeclaration;
if (typeSymbol.members)
result.members = typeSymbol.members;
if (valueSymbol.exports)
result.exports = valueSymbol.exports;
return result;
}
function getExportOfModule(symbol, name) {
if (symbol.flags & 1536 /* Module */) {
var exports = getExportsOfSymbol(symbol);
if (ts.hasProperty(exports, name)) {
return resolveSymbol(exports[name]);
}
}
}
function getPropertyOfVariable(symbol, name) {
if (symbol.flags & 3 /* Variable */) {
var typeAnnotation = symbol.valueDeclaration.type;
if (typeAnnotation) {
return resolveSymbol(getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name));
}
}
}
function getExternalModuleMember(node, specifier) {
var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier);
var targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier);
if (targetSymbol) {
var name_9 = specifier.propertyName || specifier.name;
if (name_9.text) {
var symbolFromModule = getExportOfModule(targetSymbol, name_9.text);
var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_9.text);
var symbol = symbolFromModule && symbolFromVariable ?
combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) :
symbolFromModule || symbolFromVariable;
if (!symbol) {
error(name_9, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_9));
}
return symbol;
}
}
}
function getTargetOfImportSpecifier(node) {
return getExternalModuleMember(node.parent.parent.parent, node);
}
function getTargetOfExportSpecifier(node) {
return node.parent.parent.moduleSpecifier ?
getExternalModuleMember(node.parent.parent, node) :
resolveEntityName(node.propertyName || node.name, 107455 /* Value */ | 793056 /* Type */ | 1536 /* Namespace */);
}
function getTargetOfExportAssignment(node) {
return resolveEntityName(node.expression, 107455 /* Value */ | 793056 /* Type */ | 1536 /* Namespace */);
}
function getTargetOfAliasDeclaration(node) {
switch (node.kind) {
case 219 /* ImportEqualsDeclaration */:
return getTargetOfImportEqualsDeclaration(node);
case 221 /* ImportClause */:
return getTargetOfImportClause(node);
case 222 /* NamespaceImport */:
return getTargetOfNamespaceImport(node);
case 224 /* ImportSpecifier */:
return getTargetOfImportSpecifier(node);
case 228 /* ExportSpecifier */:
return getTargetOfExportSpecifier(node);
case 225 /* ExportAssignment */:
return getTargetOfExportAssignment(node);
}
}
function resolveSymbol(symbol) {
return symbol && symbol.flags & 8388608 /* Alias */ && !(symbol.flags & (107455 /* Value */ | 793056 /* Type */ | 1536 /* Namespace */)) ? resolveAlias(symbol) : symbol;
}
function resolveAlias(symbol) {
ts.Debug.assert((symbol.flags & 8388608 /* Alias */) !== 0, "Should only get Alias here.");
var links = getSymbolLinks(symbol);
if (!links.target) {
links.target = resolvingSymbol;
var node = getDeclarationOfAliasSymbol(symbol);
var target = getTargetOfAliasDeclaration(node);
if (links.target === resolvingSymbol) {
links.target = target || unknownSymbol;
}
else {
error(node, ts.Diagnostics.Circular_definition_of_import_alias_0, symbolToString(symbol));
}
}
else if (links.target === resolvingSymbol) {
links.target = unknownSymbol;
}
return links.target;
}
function markExportAsReferenced(node) {
var symbol = getSymbolOfNode(node);
var target = resolveAlias(symbol);
if (target) {
var markAlias = (target === unknownSymbol && compilerOptions.isolatedModules) ||
(target !== unknownSymbol && (target.flags & 107455 /* Value */) && !isConstEnumOrConstEnumOnlyModule(target));
if (markAlias) {
markAliasSymbolAsReferenced(symbol);
}
}
}
// When an alias symbol is referenced, we need to mark the entity it references as referenced and in turn repeat that until
// we reach a non-alias or an exported entity (which is always considered referenced). We do this by checking the target of
// the alias as an expression (which recursively takes us back here if the target references another alias).
function markAliasSymbolAsReferenced(symbol) {
var links = getSymbolLinks(symbol);
if (!links.referenced) {
links.referenced = true;
var node = getDeclarationOfAliasSymbol(symbol);
if (node.kind === 225 /* ExportAssignment */) {
// export default <symbol>
checkExpressionCached(node.expression);
}
else if (node.kind === 228 /* ExportSpecifier */) {
// export { <symbol> } or export { <symbol> as foo }
checkExpressionCached(node.propertyName || node.name);
}
else if (ts.isInternalModuleImportEqualsDeclaration(node)) {
// import foo = <symbol>
checkExpressionCached(node.moduleReference);
}
}
}
// This function is only for imports with entity names
function getSymbolOfPartOfRightHandSideOfImportEquals(entityName, importDeclaration) {
if (!importDeclaration) {
importDeclaration = ts.getAncestor(entityName, 219 /* ImportEqualsDeclaration */);
ts.Debug.assert(importDeclaration !== undefined);
}
// There are three things we might try to look for. In the following examples,
// the search term is enclosed in |...|:
//
// import a = |b|; // Namespace
// import a = |b.c|; // Value, type, namespace
// import a = |b.c|.d; // Namespace
if (entityName.kind === 67 /* Identifier */ && ts.isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
entityName = entityName.parent;
}
// Check for case 1 and 3 in the above example
if (entityName.kind === 67 /* Identifier */ || entityName.parent.kind === 133 /* QualifiedName */) {
return resolveEntityName(entityName, 1536 /* Namespace */);
}
else {
// Case 2 in above example
// entityName.kind could be a QualifiedName or a Missing identifier
ts.Debug.assert(entityName.parent.kind === 219 /* ImportEqualsDeclaration */);
return resolveEntityName(entityName, 107455 /* Value */ | 793056 /* Type */ | 1536 /* Namespace */);
}
}
function getFullyQualifiedName(symbol) {
return symbol.parent ? getFullyQualifiedName(symbol.parent) + "." + symbolToString(symbol) : symbolToString(symbol);
}
// Resolves a qualified name and any involved aliases
function resolveEntityName(name, meaning, ignoreErrors) {
if (ts.nodeIsMissing(name)) {
return undefined;
}
var symbol;
if (name.kind === 67 /* Identifier */) {
var message = meaning === 1536 /* Namespace */ ? ts.Diagnostics.Cannot_find_namespace_0 : ts.Diagnostics.Cannot_find_name_0;
symbol = resolveName(name, name.text, meaning, ignoreErrors ? undefined : message, name);
if (!symbol) {
return undefined;
}
}
else if (name.kind === 133 /* QualifiedName */ || name.kind === 164 /* PropertyAccessExpression */) {
var left = name.kind === 133 /* QualifiedName */ ? name.left : name.expression;
var right = name.kind === 133 /* QualifiedName */ ? name.right : name.name;
var namespace = resolveEntityName(left, 1536 /* Namespace */, ignoreErrors);
if (!namespace || namespace === unknownSymbol || ts.nodeIsMissing(right)) {
return undefined;
}
symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning);
if (!symbol) {
if (!ignoreErrors) {
error(right, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(namespace), ts.declarationNameToString(right));
}
return undefined;
}
}
else {
ts.Debug.fail("Unknown entity name kind.");
}
ts.Debug.assert((symbol.flags & 16777216 /* Instantiated */) === 0, "Should never get an instantiated symbol here.");
return symbol.flags & meaning ? symbol : resolveAlias(symbol);
}
function isExternalModuleNameRelative(moduleName) {
// TypeScript 1.0 spec (April 2014): 11.2.1
// An external module name is "relative" if the first term is "." or "..".
return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\";
}
function resolveExternalModuleName(location, moduleReferenceExpression) {
if (moduleReferenceExpression.kind !== 9 /* StringLiteral */) {
return;
}
var moduleReferenceLiteral = moduleReferenceExpression;
var searchPath = ts.getDirectoryPath(getSourceFile(location).fileName);
// Module names are escaped in our symbol table. However, string literal values aren't.
// Escape the name in the "require(...)" clause to ensure we find the right symbol.
var moduleName = ts.escapeIdentifier(moduleReferenceLiteral.text);
if (!moduleName) {
return;
}
var isRelative = isExternalModuleNameRelative(moduleName);
if (!isRelative) {
var symbol = getSymbol(globals, "\"" + moduleName + "\"", 512 /* ValueModule */);
if (symbol) {
return symbol;
}
}
var fileName = ts.getResolvedModuleFileName(getSourceFile(location), moduleReferenceLiteral.text);
var sourceFile = fileName && host.getSourceFile(fileName);
if (sourceFile) {
if (sourceFile.symbol) {
return sourceFile.symbol;
}
error(moduleReferenceLiteral, ts.Diagnostics.File_0_is_not_a_module, sourceFile.fileName);
return;
}
error(moduleReferenceLiteral, ts.Diagnostics.Cannot_find_module_0, moduleName);
}
// An external module with an 'export =' declaration resolves to the target of the 'export =' declaration,
// and an external module with no 'export =' declaration resolves to the module itself.
function resolveExternalModuleSymbol(moduleSymbol) {
return moduleSymbol && resolveSymbol(moduleSymbol.exports["export="]) || moduleSymbol;
}
// An external module with an 'export =' declaration may be referenced as an ES6 module provided the 'export ='
// references a symbol that is at least declared as a module or a variable. The target of the 'export =' may
// combine other declarations with the module or variable (e.g. a class/module, function/module, interface/variable).
function resolveESModuleSymbol(moduleSymbol, moduleReferenceExpression) {
var symbol = resolveExternalModuleSymbol(moduleSymbol);
if (symbol && !(symbol.flags & (1536 /* Module */ | 3 /* Variable */))) {
error(moduleReferenceExpression, ts.Diagnostics.Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol));
symbol = undefined;
}
return symbol;
}
function getExportAssignmentSymbol(moduleSymbol) {
return moduleSymbol.exports["export="];
}
function getExportsOfModuleAsArray(moduleSymbol) {
return symbolsToArray(getExportsOfModule(moduleSymbol));
}
function getExportsOfSymbol(symbol) {
return symbol.flags & 1536 /* Module */ ? getExportsOfModule(symbol) : symbol.exports || emptySymbols;
}
function getExportsOfModule(moduleSymbol) {
var links = getSymbolLinks(moduleSymbol);
return links.resolvedExports || (links.resolvedExports = getExportsForModule(moduleSymbol));
}
function extendExportSymbols(target, source) {
for (var id in source) {
if (id !== "default" && !ts.hasProperty(target, id)) {
target[id] = source[id];
}
}
}
function getExportsForModule(moduleSymbol) {
var result;
var visitedSymbols = [];
visit(moduleSymbol);
return result || moduleSymbol.exports;
// The ES6 spec permits export * declarations in a module to circularly reference the module itself. For example,
// module 'a' can 'export * from "b"' and 'b' can 'export * from "a"' without error.
function visit(symbol) {
if (symbol && symbol.flags & 1952 /* HasExports */ && !ts.contains(visitedSymbols, symbol)) {
visitedSymbols.push(symbol);
if (symbol !== moduleSymbol) {
if (!result) {
result = cloneSymbolTable(moduleSymbol.exports);
}
extendExportSymbols(result, symbol.exports);
}
// All export * declarations are collected in an __export symbol by the binder
var exportStars = symbol.exports["__export"];
if (exportStars) {
for (var _i = 0, _a = exportStars.declarations; _i < _a.length; _i++) {
var node = _a[_i];
visit(resolveExternalModuleName(node, node.moduleSpecifier));
}
}
}
}
}
function getMergedSymbol(symbol) {
var merged;
return symbol && symbol.mergeId && (merged = mergedSymbols[symbol.mergeId]) ? merged : symbol;
}
function getSymbolOfNode(node) {
return getMergedSymbol(node.symbol);
}
function getParentOfSymbol(symbol) {
return getMergedSymbol(symbol.parent);
}
function getExportSymbolOfValueSymbolIfExported(symbol) {
return symbol && (symbol.flags & 1048576 /* ExportValue */) !== 0
? getMergedSymbol(symbol.exportSymbol)
: symbol;
}
function 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;
}
function findConstructorDeclaration(node) {
var members = node.members;
for (var _i = 0; _i < members.length; _i++) {
var member = members[_i];
if (member.kind === 142 /* Constructor */ && ts.nodeIsPresent(member.body)) {
return member;
}
}
}
function createType(flags) {
var result = new Type(checker, flags);
result.id = typeCount++;
return result;
}
function createIntrinsicType(kind, intrinsicName) {
var type = createType(kind);
type.intrinsicName = intrinsicName;
return type;
}
function createObjectType(kind, symbol) {
var type = createType(kind);
type.symbol = symbol;
return type;
}
// A reserved member name starts with two underscores, but the third character cannot be an underscore
// or the @ symbol. A third underscore indicates an escaped form of an identifer that started
// with at least two underscores. The @ character indicates that the name is denoted by a well known ES
// Symbol instance.
function isReservedMemberName(name) {
return name.charCodeAt(0) === 95 /* _ */ &&
name.charCodeAt(1) === 95 /* _ */ &&
name.charCodeAt(2) !== 95 /* _ */ &&
name.charCodeAt(2) !== 64 /* at */;
}
function getNamedMembers(members) {
var result;
for (var id in members) {
if (ts.hasProperty(members, id)) {
if (!isReservedMemberName(id)) {
if (!result)
result = [];
var symbol = members[id];
if (symbolIsValue(symbol)) {
result.push(symbol);
}
}
}
}
return result || emptyArray;
}
function setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType) {
type.members = members;
type.properties = getNamedMembers(members);
type.callSignatures = callSignatures;
type.constructSignatures = constructSignatures;
if (stringIndexType)
type.stringIndexType = stringIndexType;
if (numberIndexType)
type.numberIndexType = numberIndexType;
return type;
}
function createAnonymousType(symbol, members, callSignatures, constructSignatures, stringIndexType, numberIndexType) {
return setObjectTypeMembers(createObjectType(65536 /* Anonymous */, symbol), members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
}
function forEachSymbolTableInScope(enclosingDeclaration, callback) {
var result;
for (var location_1 = enclosingDeclaration; location_1; location_1 = location_1.parent) {
// Locals of a source file are not in scope (because they get merged into the global symbol table)
if (location_1.locals && !isGlobalSourceFile(location_1)) {
if (result = callback(location_1.locals)) {
return result;
}
}
switch (location_1.kind) {
case 246 /* SourceFile */:
if (!ts.isExternalModule(location_1)) {
break;
}
case 216 /* ModuleDeclaration */:
if (result = callback(getSymbolOfNode(location_1).exports)) {
return result;
}
break;
case 212 /* ClassDeclaration */:
case 213 /* InterfaceDeclaration */:
if (result = callback(getSymbolOfNode(location_1).members)) {
return result;
}
break;
}
}
return callback(globals);
}
function getQualifiedLeftMeaning(rightMeaning) {
// If we are looking in value space, the parent meaning is value, other wise it is namespace
return rightMeaning === 107455 /* Value */ ? 107455 /* Value */ : 1536 /* Namespace */;
}
function getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, useOnlyExternalAliasing) {
function getAccessibleSymbolChainFromSymbolTable(symbols) {
function canQualifySymbol(symbolFromSymbolTable, meaning) {
// If the symbol is equivalent and doesn't need further qualification, this symbol is accessible
if (!needsQualification(symbolFromSymbolTable, enclosingDeclaration, meaning)) {
return true;
}
// If symbol needs qualification, make sure that parent is accessible, if it is then this symbol is accessible too
var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning), useOnlyExternalAliasing);
return !!accessibleParent;
}
function isAccessible(symbolFromSymbolTable, resolvedAliasSymbol) {
if (symbol === (resolvedAliasSymbol || symbolFromSymbolTable)) {
// if the symbolFromSymbolTable is not external module (it could be if it was determined as ambient external module and would be in globals table)
// and if symbolfrom symbolTable or alias resolution matches the symbol,
// check the symbol can be qualified, it is only then this symbol is accessible
return !ts.forEach(symbolFromSymbolTable.declarations, hasExternalModuleSymbol) &&
canQualifySymbol(symbolFromSymbolTable, meaning);
}
}
// If symbol is directly available by its name in the symbol table
if (isAccessible(ts.lookUp(symbols, symbol.name))) {
return [symbol];
}
// Check if symbol is any of the alias
return ts.forEachValue(symbols, function (symbolFromSymbolTable) {
if (symbolFromSymbolTable.flags & 8388608 /* Alias */
&& symbolFromSymbolTable.name !== "export="
&& !ts.getDeclarationOfKind(symbolFromSymbolTable, 228 /* ExportSpecifier */)) {
if (!useOnlyExternalAliasing ||
// Is this external alias, then use it to name
ts.forEach(symbolFromSymbolTable.declarations, ts.isExternalModuleImportEqualsDeclaration)) {
var resolvedImportedSymbol = resolveAlias(symbolFromSymbolTable);
if (isAccessible(symbolFromSymbolTable, resolveAlias(symbolFromSymbolTable))) {
return [symbolFromSymbolTable];
}
// Look in the exported members, if we can find accessibleSymbolChain, symbol is accessible using this chain
// but only if the symbolFromSymbolTable can be qualified
var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined;
if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) {
return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports);
}
}
}
});
}
if (symbol) {
return forEachSymbolTableInScope(enclosingDeclaration, getAccessibleSymbolChainFromSymbolTable);
}
}
function needsQualification(symbol, enclosingDeclaration, meaning) {
var qualify = false;
forEachSymbolTableInScope(enclosingDeclaration, function (symbolTable) {
// If symbol of this name is not available in the symbol table we are ok
if (!ts.hasProperty(symbolTable, symbol.name)) {
// Continue to the next symbol table
return false;
}
// If the symbol with this name is present it should refer to the symbol
var symbolFromSymbolTable = symbolTable[symbol.name];
if (symbolFromSymbolTable === symbol) {
// No need to qualify
return true;
}
// Qualify if the symbol from symbol table has same meaning as expected
symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608 /* Alias */ && !ts.getDeclarationOfKind(symbolFromSymbolTable, 228 /* ExportSpecifier */)) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable;
if (symbolFromSymbolTable.flags & meaning) {
qualify = true;
return true;
}
// Continue to the next symbol table
return false;
});
return qualify;
}
function isSymbolAccessible(symbol, enclosingDeclaration, meaning) {
if (symbol && enclosingDeclaration && !(symbol.flags & 262144 /* TypeParameter */)) {
var initialSymbol = symbol;
var meaningToLook = meaning;
while (symbol) {
// Symbol is accessible if it by itself is accessible
var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, /*useOnlyExternalAliasing*/ false);
if (accessibleSymbolChain) {
var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]);
if (!hasAccessibleDeclarations) {
return {
accessibility: 1 /* NotAccessible */,
errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning),
errorModuleName: symbol !== initialSymbol ? symbolToString(symbol, enclosingDeclaration, 1536 /* Namespace */) : undefined
};
}
return hasAccessibleDeclarations;
}
// If we haven't got the accessible symbol, it doesn't mean the symbol is actually inaccessible.
// It could be a qualified symbol and hence verify the path
// e.g.:
// module m {
// export class c {
// }
// }
// let x: typeof m.c
// In the above example when we start with checking if typeof m.c symbol is accessible,
// we are going to see if c can be accessed in scope directly.
// But it can't, hence the accessible is going to be undefined, but that doesn't mean m.c is inaccessible
// It is accessible if the parent m is accessible because then m.c can be accessed through qualification
meaningToLook = getQualifiedLeftMeaning(meaning);
symbol = getParentOfSymbol(symbol);
}
// This could be a symbol that is not exported in the external module
// or it could be a symbol from different external module that is not aliased and hence cannot be named
var symbolExternalModule = ts.forEach(initialSymbol.declarations, getExternalModuleContainer);
if (symbolExternalModule) {
var enclosingExternalModule = getExternalModuleContainer(enclosingDeclaration);
if (symbolExternalModule !== enclosingExternalModule) {
// name from different external module that is not visible
return {
accessibility: 2 /* CannotBeNamed */,
errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning),
errorModuleName: symbolToString(symbolExternalModule)
};
}
}
// Just a local name that is not accessible
return {
accessibility: 1 /* NotAccessible */,
errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning)
};
}
return { accessibility: 0 /* Accessible */ };
function getExternalModuleContainer(declaration) {
for (; declaration; declaration = declaration.parent) {
if (hasExternalModuleSymbol(declaration)) {
return getSymbolOfNode(declaration);
}
}
}
}
function hasExternalModuleSymbol(declaration) {
return (declaration.kind === 216 /* ModuleDeclaration */ && declaration.name.kind === 9 /* StringLiteral */) ||
(declaration.kind === 246 /* SourceFile */ && ts.isExternalModule(declaration));
}
function hasVisibleDeclarations(symbol) {
var aliasesToMakeVisible;
if (ts.forEach(symbol.declarations, function (declaration) { return !getIsDeclarationVisible(declaration); })) {
return undefined;
}
return { accessibility: 0 /* Accessible */, aliasesToMakeVisible: aliasesToMakeVisible };
function getIsDeclarationVisible(declaration) {
if (!isDeclarationVisible(declaration)) {
// Mark the unexported alias as visible if its parent is visible
// because these kind of aliases can be used to name types in declaration file
var anyImportSyntax = getAnyImportSyntax(declaration);
if (anyImportSyntax &&
!(anyImportSyntax.flags & 1 /* Export */) &&
isDeclarationVisible(anyImportSyntax.parent)) {
getNodeLinks(declaration).isVisible = true;
if (aliasesToMakeVisible) {
if (!ts.contains(aliasesToMakeVisible, anyImportSyntax)) {
aliasesToMakeVisible.push(anyImportSyntax);
}
}
else {
aliasesToMakeVisible = [anyImportSyntax];
}
return true;
}
// Declaration is not visible
return false;
}
return true;
}
}
function isEntityNameVisible(entityName, enclosingDeclaration) {
// get symbol of the first identifier of the entityName
var meaning;
if (entityName.parent.kind === 152 /* TypeQuery */) {
// Typeof value
meaning = 107455 /* Value */ | 1048576 /* ExportValue */;
}
else if (entityName.kind === 133 /* QualifiedName */ || entityName.kind === 164 /* PropertyAccessExpression */ ||
entityName.parent.kind === 219 /* ImportEqualsDeclaration */) {
// Left identifier from type reference or TypeAlias
// Entity name of the import declaration
meaning = 1536 /* Namespace */;
}
else {
// Type Reference or TypeAlias entity = Identifier
meaning = 793056 /* Type */;
}
var firstIdentifier = getFirstIdentifier(entityName);
var symbol = resolveName(enclosingDeclaration, firstIdentifier.text, meaning, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined);
// Verify if the symbol is accessible
return (symbol && hasVisibleDeclarations(symbol)) || {
accessibility: 1 /* NotAccessible */,
errorSymbolName: ts.getTextOfNode(firstIdentifier),
errorNode: firstIdentifier
};
}
function writeKeyword(writer, kind) {
writer.writeKeyword(ts.tokenToString(kind));
}
function writePunctuation(writer, kind) {
writer.writePunctuation(ts.tokenToString(kind));
}
function writeSpace(writer) {
writer.writeSpace(" ");
}
function symbolToString(symbol, enclosingDeclaration, meaning) {
var writer = ts.getSingleLineStringWriter();
getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning);
var result = writer.string();
ts.releaseStringWriter(writer);
return result;
}
function signatureToString(signature, enclosingDeclaration, flags) {
var writer = ts.getSingleLineStringWriter();
getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags);
var result = writer.string();
ts.releaseStringWriter(writer);
return result;
}
function typeToString(type, enclosingDeclaration, flags) {
var writer = ts.getSingleLineStringWriter();
getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
var result = writer.string();
ts.releaseStringWriter(writer);
var maxLength = compilerOptions.noErrorTruncation || flags & 4 /* NoTruncation */ ? undefined : 100;
if (maxLength && result.length >= maxLength) {
result = result.substr(0, maxLength - "...".length) + "...";
}
return result;
}
function getTypeAliasForTypeLiteral(type) {
if (type.symbol && type.symbol.flags & 2048 /* TypeLiteral */) {
var node = type.symbol.declarations[0].parent;
while (node.kind === 158 /* ParenthesizedType */) {
node = node.parent;
}
if (node.kind === 214 /* TypeAliasDeclaration */) {
return getSymbolOfNode(node);
}
}
return undefined;
}
function getSymbolDisplayBuilder() {
function getNameOfSymbol(symbol) {
if (symbol.declarations && symbol.declarations.length) {
var declaration = symbol.declarations[0];
if (declaration.name) {
return ts.declarationNameToString(declaration.name);
}
switch (declaration.kind) {
case 184 /* ClassExpression */:
return "(Anonymous class)";
case 171 /* FunctionExpression */:
case 172 /* ArrowFunction */:
return "(Anonymous function)";
}
}
return symbol.name;
}
/**
* Writes only the name of the symbol out to the writer. Uses the original source text
* for the name of the symbol if it is available to match how the user inputted the name.
*/
function appendSymbolNameOnly(symbol, writer) {
writer.writeSymbol(getNameOfSymbol(symbol), symbol);
}
/**
* Enclosing declaration is optional when we don't want to get qualified name in the enclosing declaration scope
* Meaning needs to be specified if the enclosing declaration is given
*/
function buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning, flags, typeFlags) {
var parentSymbol;
function appendParentTypeArgumentsAndSymbolName(symbol) {
if (parentSymbol) {
// Write type arguments of instantiated class/interface here
if (flags & 1 /* WriteTypeParametersOrArguments */) {
if (symbol.flags & 16777216 /* Instantiated */) {
buildDisplayForTypeArgumentsAndDelimiters(getTypeParametersOfClassOrInterface(parentSymbol), symbol.mapper, writer, enclosingDeclaration);
}
else {
buildTypeParameterDisplayFromSymbol(parentSymbol, writer, enclosingDeclaration);
}
}
writePunctuation(writer, 21 /* DotToken */);
}
parentSymbol = symbol;
appendSymbolNameOnly(symbol, writer);
}
// Let the writer know we just wrote out a symbol. The declaration emitter writer uses
// this to determine if an import it has previously seen (and not written out) needs
// to be written to the file once the walk of the tree is complete.
//
// NOTE(cyrusn): This approach feels somewhat unfortunate. A simple pass over the tree
// up front (for example, during checking) could determine if we need to emit the imports
// and we could then access that data during declaration emit.
writer.trackSymbol(symbol, enclosingDeclaration, meaning);
function walkSymbol(symbol, meaning) {
if (symbol) {
var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & 2 /* UseOnlyExternalAliasing */));
if (!accessibleSymbolChain ||
needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) {
// Go up and add our parent.
walkSymbol(getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol), getQualifiedLeftMeaning(meaning));
}
if (accessibleSymbolChain) {
for (var _i = 0; _i < accessibleSymbolChain.length; _i++) {
var accessibleSymbol = accessibleSymbolChain[_i];
appendParentTypeArgumentsAndSymbolName(accessibleSymbol);
}
}
else {
// If we didn't find accessible symbol chain for this symbol, break if this is external module
if (!parentSymbol && ts.forEach(symbol.declarations, hasExternalModuleSymbol)) {
return;
}
// if this is anonymous type break
if (symbol.flags & 2048 /* TypeLiteral */ || symbol.flags & 4096 /* ObjectLiteral */) {
return;
}
appendParentTypeArgumentsAndSymbolName(symbol);
}
}
}
// Get qualified name if the symbol is not a type parameter
// and there is an enclosing declaration or we specifically
// asked for it
var isTypeParameter = symbol.flags & 262144 /* TypeParameter */;
var typeFormatFlag = 128 /* UseFullyQualifiedType */ & typeFlags;
if (!isTypeParameter && (enclosingDeclaration || typeFormatFlag)) {
walkSymbol(symbol, meaning);
return;
}
return appendParentTypeArgumentsAndSymbolName(symbol);
}
function buildTypeDisplay(type, writer, enclosingDeclaration, globalFlags, symbolStack) {
var globalFlagsToPass = globalFlags & 16 /* WriteOwnNameForAnyLike */;
return writeType(type, globalFlags);
function writeType(type, flags) {
// Write undefined/null type as any
if (type.flags & 16777343 /* Intrinsic */) {
// Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving
writer.writeKeyword(!(globalFlags & 16 /* WriteOwnNameForAnyLike */) && isTypeAny(type)
? "any"
: type.intrinsicName);
}
else if (type.flags & 4096 /* Reference */) {
writeTypeReference(type, flags);
}
else if (type.flags & (1024 /* Class */ | 2048 /* Interface */ | 128 /* Enum */ | 512 /* TypeParameter */)) {
// The specified symbol flags need to be reinterpreted as type flags
buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, 793056 /* Type */, 0 /* None */, flags);
}
else if (type.flags & 8192 /* Tuple */) {
writeTupleType(type);
}
else if (type.flags & 49152 /* UnionOrIntersection */) {
writeUnionOrIntersectionType(type, flags);
}
else if (type.flags & 65536 /* Anonymous */) {
writeAnonymousType(type, flags);
}
else if (type.flags & 256 /* StringLiteral */) {
writer.writeStringLiteral(type.text);
}
else {
// Should never get here
// { ... }
writePunctuation(writer, 15 /* OpenBraceToken */);
writeSpace(writer);
writePunctuation(writer, 22 /* DotDotDotToken */);
writeSpace(writer);
writePunctuation(writer, 16 /* CloseBraceToken */);
}
}
function writeTypeList(types, delimiter) {
for (var i = 0; i < types.length; i++) {
if (i > 0) {
if (delimiter !== 24 /* CommaToken */) {
writeSpace(writer);
}
writePunctuation(writer, delimiter);
writeSpace(writer);
}
writeType(types[i], delimiter === 24 /* CommaToken */ ? 0 /* None */ : 64 /* InElementType */);
}
}
function writeSymbolTypeReference(symbol, typeArguments, pos, end) {
// Unnamed function expressions, arrow functions, and unnamed class expressions have reserved names that
// we don't want to display
if (!isReservedMemberName(symbol.name)) {
buildSymbolDisplay(symbol, writer, enclosingDeclaration, 793056 /* Type */);
}
if (pos < end) {
writePunctuation(writer, 25 /* LessThanToken */);
writeType(typeArguments[pos++], 0 /* None */);
while (pos < end) {
writePunctuation(writer, 24 /* CommaToken */);
writeSpace(writer);
writeType(typeArguments[pos++], 0 /* None */);
}
writePunctuation(writer, 27 /* GreaterThanToken */);
}
}
function writeTypeReference(type, flags) {
var typeArguments = type.typeArguments;
if (type.target === globalArrayType && !(flags & 1 /* WriteArrayAsGenericType */)) {
writeType(typeArguments[0], 64 /* InElementType */);
writePunctuation(writer, 19 /* OpenBracketToken */);
writePunctuation(writer, 20 /* CloseBracketToken */);
}
else {
// Write the type reference in the format f<A>.g<B>.C<X, Y> where A and B are type arguments
// for outer type parameters, and f and g are the respective declaring containers of those
// type parameters.
var outerTypeParameters = type.target.outerTypeParameters;
var i = 0;
if (outerTypeParameters) {
var length_1 = outerTypeParameters.length;
while (i < length_1) {
// Find group of type arguments for type parameters with the same declaring container.
var start = i;
var parent_3 = getParentSymbolOfTypeParameter(outerTypeParameters[i]);
do {
i++;
} while (i < length_1 && getParentSymbolOfTypeParameter(outerTypeParameters[i]) === parent_3);
// When type parameters are their own type arguments for the whole group (i.e. we have
// the default outer type arguments), we don't show the group.
if (!ts.rangeEquals(outerTypeParameters, typeArguments, start, i)) {
writeSymbolTypeReference(parent_3, typeArguments, start, i);
writePunctuation(writer, 21 /* DotToken */);
}
}
}
writeSymbolTypeReference(type.symbol, typeArguments, i, typeArguments.length);
}
}
function writeTupleType(type) {
writePunctuation(writer, 19 /* OpenBracketToken */);
writeTypeList(type.elementTypes, 24 /* CommaToken */);
writePunctuation(writer, 20 /* CloseBracketToken */);
}
function writeUnionOrIntersectionType(type, flags) {
if (flags & 64 /* InElementType */) {
writePunctuation(writer, 17 /* OpenParenToken */);
}
writeTypeList(type.types, type.flags & 16384 /* Union */ ? 46 /* BarToken */ : 45 /* AmpersandToken */);
if (flags & 64 /* InElementType */) {
writePunctuation(writer, 18 /* CloseParenToken */);
}
}
function writeAnonymousType(type, flags) {
var symbol = type.symbol;
if (symbol) {
// Always use 'typeof T' for type of class, enum, and module objects
if (symbol.flags & (32 /* Class */ | 384 /* Enum */ | 512 /* ValueModule */)) {
writeTypeofSymbol(type, flags);
}
else if (shouldWriteTypeOfFunctionSymbol()) {
writeTypeofSymbol(type, flags);
}
else if (ts.contains(symbolStack, symbol)) {
// If type is an anonymous type literal in a type alias declaration, use type alias name
var typeAlias = getTypeAliasForTypeLiteral(type);
if (typeAlias) {
// The specified symbol flags need to be reinterpreted as type flags
buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056 /* Type */, 0 /* None */, flags);
}
else {
// Recursive usage, use any
writeKeyword(writer, 115 /* AnyKeyword */);
}
}
else {
// Since instantiations of the same anonymous type have the same symbol, tracking symbols instead
// of types allows us to catch circular references to instantiations of the same anonymous type
if (!symbolStack) {
symbolStack = [];
}
symbolStack.push(symbol);
writeLiteralType(type, flags);
symbolStack.pop();
}
}
else {
// Anonymous types with no symbol are never circular
writeLiteralType(type, flags);
}
function shouldWriteTypeOfFunctionSymbol() {
var isStaticMethodSymbol = !!(symbol.flags & 8192 /* Method */ &&
ts.forEach(symbol.declarations, function (declaration) { return declaration.flags & 128 /* Static */; }));
var isNonLocalFunctionSymbol = !!(symbol.flags & 16 /* Function */) &&
(symbol.parent ||
ts.forEach(symbol.declarations, function (declaration) {
return declaration.parent.kind === 246 /* SourceFile */ || declaration.parent.kind === 217 /* ModuleBlock */;
}));
if (isStaticMethodSymbol || isNonLocalFunctionSymbol) {
// typeof is allowed only for static/non local functions
return !!(flags & 2 /* UseTypeOfFunction */) ||
(ts.contains(symbolStack, symbol)); // it is type of the symbol uses itself recursively
}
}
}
function writeTypeofSymbol(type, typeFormatFlags) {
writeKeyword(writer, 99 /* TypeOfKeyword */);
writeSpace(writer);
buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, 107455 /* Value */, 0 /* None */, typeFormatFlags);
}
function getIndexerParameterName(type, indexKind, fallbackName) {
var declaration = getIndexDeclarationOfSymbol(type.symbol, indexKind);
if (!declaration) {
// declaration might not be found if indexer was added from the contextual type.
// in this case use fallback name
return fallbackName;
}
ts.Debug.assert(declaration.parameters.length !== 0);
return ts.declarationNameToString(declaration.parameters[0].name);
}
function writeLiteralType(type, flags) {
var resolved = resolveStructuredTypeMembers(type);
if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) {
if (!resolved.callSignatures.length && !resolved.constructSignatures.length) {
writePunctuation(writer, 15 /* OpenBraceToken */);
writePunctuation(writer, 16 /* CloseBraceToken */);
return;
}
if (resolved.callSignatures.length === 1 && !resolved.constructSignatures.length) {
if (flags & 64 /* InElementType */) {
writePunctuation(writer, 17 /* OpenParenToken */);
}
buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, symbolStack);
if (flags & 64 /* InElementType */) {
writePunctuation(writer, 18 /* CloseParenToken */);
}
return;
}
if (resolved.constructSignatures.length === 1 && !resolved.callSignatures.length) {
if (flags & 64 /* InElementType */) {
writePunctuation(writer, 17 /* OpenParenToken */);
}
writeKeyword(writer, 90 /* NewKeyword */);
writeSpace(writer);
buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | 8 /* WriteArrowStyleSignature */, symbolStack);
if (flags & 64 /* InElementType */) {
writePunctuation(writer, 18 /* CloseParenToken */);
}
return;
}
}
writePunctuation(writer, 15 /* OpenBraceToken */);
writer.writeLine();
writer.increaseIndent();
for (var _i = 0, _a = resolved.callSignatures; _i < _a.length; _i++) {
var signature = _a[_i];
buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack);
writePunctuation(writer, 23 /* SemicolonToken */);
writer.writeLine();
}
for (var _b = 0, _c = resolved.constructSignatures; _b < _c.length; _b++) {
var signature = _c[_b];
writeKeyword(writer, 90 /* NewKeyword */);
writeSpace(writer);
buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack);
writePunctuation(writer, 23 /* SemicolonToken */);
writer.writeLine();
}
if (resolved.stringIndexType) {
// [x: string]:
writePunctuation(writer, 19 /* OpenBracketToken */);
writer.writeParameter(getIndexerParameterName(resolved, 0 /* String */, /*fallbackName*/ "x"));
writePunctuation(writer, 53 /* ColonToken */);
writeSpace(writer);
writeKeyword(writer, 128 /* StringKeyword */);
writePunctuation(writer, 20 /* CloseBracketToken */);
writePunctuation(writer, 53 /* ColonToken */);
writeSpace(writer);
writeType(resolved.stringIndexType, 0 /* None */);
writePunctuation(writer, 23 /* SemicolonToken */);
writer.writeLine();
}
if (resolved.numberIndexType) {
// [x: number]:
writePunctuation(writer, 19 /* OpenBracketToken */);
writer.writeParameter(getIndexerParameterName(resolved, 1 /* Number */, /*fallbackName*/ "x"));
writePunctuation(writer, 53 /* ColonToken */);
writeSpace(writer);
writeKeyword(writer, 126 /* NumberKeyword */);
writePunctuation(writer, 20 /* CloseBracketToken */);
writePunctuation(writer, 53 /* ColonToken */);
writeSpace(writer);
writeType(resolved.numberIndexType, 0 /* None */);
writePunctuation(writer, 23 /* SemicolonToken */);
writer.writeLine();
}
for (var _d = 0, _e = resolved.properties; _d < _e.length; _d++) {
var p = _e[_d];
var t = getTypeOfSymbol(p);
if (p.flags & (16 /* Function */ | 8192 /* Method */) && !getPropertiesOfObjectType(t).length) {
var signatures = getSignaturesOfType(t, 0 /* Call */);
for (var _f = 0; _f < signatures.length; _f++) {
var signature = signatures[_f];
buildSymbolDisplay(p, writer);
if (p.flags & 536870912 /* Optional */) {
writePunctuation(writer, 52 /* QuestionToken */);
}
buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack);
writePunctuation(writer, 23 /* SemicolonToken */);
writer.writeLine();
}
}
else {
buildSymbolDisplay(p, writer);
if (p.flags & 536870912 /* Optional */) {
writePunctuation(writer, 52 /* QuestionToken */);
}
writePunctuation(writer, 53 /* ColonToken */);
writeSpace(writer);
writeType(t, 0 /* None */);
writePunctuation(writer, 23 /* SemicolonToken */);
writer.writeLine();
}
}
writer.decreaseIndent();
writePunctuation(writer, 16 /* CloseBraceToken */);
}
}
function buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaraiton, flags) {
var targetSymbol = getTargetSymbol(symbol);
if (targetSymbol.flags & 32 /* Class */ || targetSymbol.flags & 64 /* Interface */ || targetSymbol.flags & 524288 /* TypeAlias */) {
buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol), writer, enclosingDeclaraiton, flags);
}
}
function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, symbolStack) {
appendSymbolNameOnly(tp.symbol, writer);
var constraint = getConstraintOfTypeParameter(tp);
if (constraint) {
writeSpace(writer);
writeKeyword(writer, 81 /* ExtendsKeyword */);
writeSpace(writer);
buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, symbolStack);
}
}
function buildParameterDisplay(p, writer, enclosingDeclaration, flags, symbolStack) {
var parameterNode = p.valueDeclaration;
if (ts.isRestParameter(parameterNode)) {
writePunctuation(writer, 22 /* DotDotDotToken */);
}
appendSymbolNameOnly(p, writer);
if (isOptionalParameter(parameterNode)) {
writePunctuation(writer, 52 /* QuestionToken */);
}
writePunctuation(writer, 53 /* ColonToken */);
writeSpace(writer);
buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, symbolStack);
}
function buildDisplayForTypeParametersAndDelimiters(typeParameters, writer, enclosingDeclaration, flags, symbolStack) {
if (typeParameters && typeParameters.length) {
writePunctuation(writer, 25 /* LessThanToken */);
for (var i = 0; i < typeParameters.length; i++) {
if (i > 0) {
writePunctuation(writer, 24 /* CommaToken */);
writeSpace(writer);
}
buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, symbolStack);
}
writePunctuation(writer, 27 /* GreaterThanToken */);
}
}
function buildDisplayForTypeArgumentsAndDelimiters(typeParameters, mapper, writer, enclosingDeclaration, flags, symbolStack) {
if (typeParameters && typeParameters.length) {
writePunctuation(writer, 25 /* LessThanToken */);
for (var i = 0; i < typeParameters.length; i++) {
if (i > 0) {
writePunctuation(writer, 24 /* CommaToken */);
writeSpace(writer);
}
buildTypeDisplay(mapper(typeParameters[i]), writer, enclosingDeclaration, 0 /* None */);
}
writePunctuation(writer, 27 /* GreaterThanToken */);
}
}
function buildDisplayForParametersAndDelimiters(parameters, writer, enclosingDeclaration, flags, symbolStack) {
writePunctuation(writer, 17 /* OpenParenToken */);
for (var i = 0; i < parameters.length; i++) {
if (i > 0) {
writePunctuation(writer, 24 /* CommaToken */);
writeSpace(writer);
}
buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, symbolStack);
}
writePunctuation(writer, 18 /* CloseParenToken */);
}
function buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) {
if (flags & 8 /* WriteArrowStyleSignature */) {
writeSpace(writer);
writePunctuation(writer, 34 /* EqualsGreaterThanToken */);
}
else {
writePunctuation(writer, 53 /* ColonToken */);
}
writeSpace(writer);
var returnType;
if (signature.typePredicate) {
writer.writeParameter(signature.typePredicate.parameterName);
writeSpace(writer);
writeKeyword(writer, 122 /* IsKeyword */);
writeSpace(writer);
returnType = signature.typePredicate.type;
}
else {
returnType = getReturnTypeOfSignature(signature);
}
buildTypeDisplay(returnType, writer, enclosingDeclaration, flags, symbolStack);
}
function buildSignatureDisplay(signature, writer, enclosingDeclaration, flags, symbolStack) {
if (signature.target && (flags & 32 /* WriteTypeArgumentsOfSignature */)) {
// Instantiated signature, write type arguments instead
// This is achieved by passing in the mapper separately
buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration);
}
else {
buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, symbolStack);
}
buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, symbolStack);
buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack);
}
return _displayBuilder || (_displayBuilder = {
buildSymbolDisplay: buildSymbolDisplay,
buildTypeDisplay: buildTypeDisplay,
buildTypeParameterDisplay: buildTypeParameterDisplay,
buildParameterDisplay: buildParameterDisplay,
buildDisplayForParametersAndDelimiters: buildDisplayForParametersAndDelimiters,
buildDisplayForTypeParametersAndDelimiters: buildDisplayForTypeParametersAndDelimiters,
buildTypeParameterDisplayFromSymbol: buildTypeParameterDisplayFromSymbol,
buildSignatureDisplay: buildSignatureDisplay,
buildReturnTypeDisplay: buildReturnTypeDisplay
});
}
function isDeclarationVisible(node) {
function getContainingExternalModule(node) {
for (; node; node = node.parent) {
if (node.kind === 216 /* ModuleDeclaration */) {
if (node.name.kind === 9 /* StringLiteral */) {
return node;
}
}
else if (node.kind === 246 /* SourceFile */) {
return ts.isExternalModule(node) ? node : undefined;
}
}
ts.Debug.fail("getContainingModule cant reach here");
}
function isUsedInExportAssignment(node) {
// Get source File and see if it is external module and has export assigned symbol
var externalModule = getContainingExternalModule(node);
var exportAssignmentSymbol;
var resolvedExportSymbol;
if (externalModule) {
// This is export assigned symbol node
var externalModuleSymbol = getSymbolOfNode(externalModule);
exportAssignmentSymbol = getExportAssignmentSymbol(externalModuleSymbol);
var symbolOfNode = getSymbolOfNode(node);
if (isSymbolUsedInExportAssignment(symbolOfNode)) {
return true;
}
// if symbolOfNode is alias declaration, resolve the symbol declaration and check
if (symbolOfNode.flags & 8388608 /* Alias */) {
return isSymbolUsedInExportAssignment(resolveAlias(symbolOfNode));
}
}
// Check if the symbol is used in export assignment
function isSymbolUsedInExportAssignment(symbol) {
if (exportAssignmentSymbol === symbol) {
return true;
}
if (exportAssignmentSymbol && !!(exportAssignmentSymbol.flags & 8388608 /* Alias */)) {
// if export assigned symbol is alias declaration, resolve the alias
resolvedExportSymbol = resolvedExportSymbol || resolveAlias(exportAssignmentSymbol);
if (resolvedExportSymbol === symbol) {
return true;
}
// Container of resolvedExportSymbol is visible
return ts.forEach(resolvedExportSymbol.declarations, function (current) {
while (current) {
if (current === node) {
return true;
}
current = current.parent;
}
});
}
}
}
function determineIfDeclarationIsVisible() {
switch (node.kind) {
case 161 /* BindingElement */:
return isDeclarationVisible(node.parent.parent);
case 209 /* VariableDeclaration */:
if (ts.isBindingPattern(node.name) &&
!node.name.elements.length) {
// If the binding pattern is empty, this variable declaration is not visible
return false;
}
// Otherwise fall through
case 216 /* ModuleDeclaration */:
case 212 /* ClassDeclaration */:
case 213 /* InterfaceDeclaration */:
case 214 /* TypeAliasDeclaration */:
case 211 /* FunctionDeclaration */:
case 215 /* EnumDeclaration */:
case 219 /* ImportEqualsDeclaration */:
var parent_4 = getDeclarationContainer(node);
// If the node is not exported or it is not ambient module element (except import declaration)
if (!(ts.getCombinedNodeFlags(node) & 1 /* Export */) &&
!(node.kind !== 219 /* ImportEqualsDeclaration */ && parent_4.kind !== 246 /* SourceFile */ && ts.isInAmbientContext(parent_4))) {
return isGlobalSourceFile(parent_4);
}
// Exported members/ambient module elements (exception import declaration) are visible if parent is visible
return isDeclarationVisible(parent_4);
case 139 /* PropertyDeclaration */:
case 138 /* PropertySignature */:
case 143 /* GetAccessor */:
case 144 /* SetAccessor */:
case 141 /* MethodDeclaration */:
case 140 /* MethodSignature */:
if (node.flags & (32 /* Private */ | 64 /* Protected */)) {
// Private/protected properties/methods are not visible
return false;
}
// Public properties/methods are visible if its parents are visible, so let it fall into next case statement
case 142 /* Constructor */:
case 146 /* ConstructSignature */:
case 145 /* CallSignature */:
case 147 /* IndexSignature */:
case 136 /* Parameter */:
case 217 /* ModuleBlock */:
case 150 /* FunctionType */:
case 151 /* ConstructorType */:
case 153 /* TypeLiteral */:
case 149 /* TypeReference */:
case 154 /* ArrayType */:
case 155 /* TupleType */:
case 156 /* UnionType */:
case 157 /* IntersectionType */:
case 158 /* ParenthesizedType */:
return isDeclarationVisible(node.parent);
// Default binding, import specifier and namespace import is visible
// only on demand so by default it is not visible
case 221 /* ImportClause */:
case 222 /* NamespaceImport */:
case 224 /* ImportSpecifier */:
return false;
// Type parameters are always visible
case 135 /* TypeParameter */:
// Source file is always visible
case 246 /* SourceFile */:
return true;
// Export assignements do not create name bindings outside the module
case 225 /* ExportAssignment */:
return false;
default:
ts.Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + node.kind);
}
}
if (node) {
var links = getNodeLinks(node);
if (links.isVisible === undefined) {
links.isVisible = !!determineIfDeclarationIsVisible();
}
return links.isVisible;
}
}
function collectLinkedAliases(node) {
var exportSymbol;
if (node.parent && node.parent.kind === 225 /* ExportAssignment */) {
exportSymbol = resolveName(node.parent, node.text, 107455 /* Value */ | 793056 /* Type */ | 1536 /* Namespace */ | 8388608 /* Alias */, ts.Diagnostics.Cannot_find_name_0, node);
}
else if (node.parent.kind === 228 /* ExportSpecifier */) {
var exportSpecifier = node.parent;
exportSymbol = exportSpecifier.parent.parent.moduleSpecifier ?
getExternalModuleMember(exportSpecifier.parent.parent, exportSpecifier) :
resolveEntityName(exportSpecifier.propertyName || exportSpecifier.name, 107455 /* Value */ | 793056 /* Type */ | 1536 /* Namespace */ | 8388608 /* Alias */);
}
var result = [];
if (exportSymbol) {
buildVisibleNodeList(exportSymbol.declarations);
}
return result;
function buildVisibleNodeList(declarations) {
ts.forEach(declarations, function (declaration) {
getNodeLinks(declaration).isVisible = true;
var resultNode = getAnyImportSyntax(declaration) || declaration;
if (!ts.contains(result, resultNode)) {
result.push(resultNode);
}
if (ts.isInternalModuleImportEqualsDeclaration(declaration)) {
// Add the referenced top container visible
var internalModuleReference = declaration.moduleReference;
var firstIdentifier = getFirstIdentifier(internalModuleReference);
var importSymbol = resolveName(declaration, firstIdentifier.text, 107455 /* Value */ | 793056 /* Type */ | 1536 /* Namespace */, ts.Diagnostics.Cannot_find_name_0, firstIdentifier);
buildVisibleNodeList(importSymbol.declarations);
}
});
}
}
/**
* Push an entry on the type resolution stack. If an entry with the given target and the given property name
* is already on the stack, and no entries in between already have a type, then a circularity has occurred.
* In this case, the result values of the existing entry and all entries pushed after it are changed to false,
* and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned.
* In order to see if the same query has already been done before, the target object and the propertyName both
* must match the one passed in.
*
* @param target The symbol, type, or signature whose type is being queried
* @param propertyName The property name that should be used to query the target for its type
*/
function 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(true);
resolutionPropertyNames.push(propertyName);
return true;
}
function findResolutionCycleStartIndex(target, propertyName) {
for (var i = resolutionTargets.length - 1; i >= 0; i--) {
if (hasType(resolutionTargets[i], resolutionPropertyNames[i])) {
return -1;
}
if (resolutionTargets[i] === target && resolutionPropertyNames[i] === propertyName) {
return i;
}
}
return -1;
}
function hasType(target, propertyName) {
if (propertyName === 0 /* Type */) {
return getSymbolLinks(target).type;
}
if (propertyName === 2 /* DeclaredType */) {
return getSymbolLinks(target).declaredType;
}
if (propertyName === 1 /* ResolvedBaseConstructorType */) {
ts.Debug.assert(!!(target.flags & 1024 /* Class */));
return target.resolvedBaseConstructorType;
}
if (propertyName === 3 /* ResolvedReturnType */) {
return target.resolvedReturnType;
}
ts.Debug.fail("Unhandled TypeSystemPropertyName " + propertyName);
}
// Pop an entry from the type resolution stack and return its associated result value. The result value will
// be true if no circularities were detected, or false if a circularity was found.
function popTypeResolution() {
resolutionTargets.pop();
resolutionPropertyNames.pop();
return resolutionResults.pop();
}
function getDeclarationContainer(node) {
node = ts.getRootDeclaration(node);
// Parent chain:
// VaribleDeclaration -> VariableDeclarationList -> VariableStatement -> 'Declaration Container'
return node.kind === 209 /* VariableDeclaration */ ? node.parent.parent.parent : node.parent;
}
function getTypeOfPrototypeProperty(prototype) {
// TypeScript 1.0 spec (April 2014): 8.4
// Every class automatically contains a static property member named 'prototype',
// the type of which is an instantiation of the class type with type Any supplied as a type argument for each type parameter.
// It is an error to explicitly declare a static property member with the name 'prototype'.
var classType = getDeclaredTypeOfSymbol(prototype.parent);
return classType.typeParameters ? createTypeReference(classType, ts.map(classType.typeParameters, function (_) { return anyType; })) : classType;
}
// Return the type of the given property in the given type, or undefined if no such property exists
function getTypeOfPropertyOfType(type, name) {
var prop = getPropertyOfType(type, name);
return prop ? getTypeOfSymbol(prop) : undefined;
}
function isTypeAny(type) {
return type && (type.flags & 1 /* Any */) !== 0;
}
// Return the inferred type for a binding element
function getTypeForBindingElement(declaration) {
var pattern = declaration.parent;
var parentType = getTypeForVariableLikeDeclaration(pattern.parent);
// If parent has the unknown (error) type, then so does this binding element
if (parentType === unknownType) {
return unknownType;
}
// If no type was specified or inferred for parent, or if the specified or inferred type is any,
// infer from the initializer of the binding element if one is present. Otherwise, go with the
// undefined or any type of the parent.
if (!parentType || isTypeAny(parentType)) {
if (declaration.initializer) {
return checkExpressionCached(declaration.initializer);
}
return parentType;
}
var type;
if (pattern.kind === 159 /* ObjectBindingPattern */) {
// Use explicitly specified property name ({ p: xxx } form), or otherwise the implied name ({ p } form)
var name_10 = declaration.propertyName || declaration.name;
// Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature,
// or otherwise the type of the string index signature.
type = getTypeOfPropertyOfType(parentType, name_10.text) ||
isNumericLiteralName(name_10.text) && getIndexTypeOfType(parentType, 1 /* Number */) ||
getIndexTypeOfType(parentType, 0 /* String */);
if (!type) {
error(name_10, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_10));
return unknownType;
}
}
else {
// This elementType will be used if the specific property corresponding to this index is not
// present (aka the tuple element property). This call also checks that the parentType is in
// fact an iterable or array (depending on target language).
var elementType = checkIteratedTypeOrElementType(parentType, pattern, /*allowStringInput*/ false);
if (!declaration.dotDotDotToken) {
// Use specific property type when parent is a tuple or numeric index type when parent is an array
var propName = "" + ts.indexOf(pattern.elements, declaration);
type = isTupleLikeType(parentType)
? getTypeOfPropertyOfType(parentType, propName)
: elementType;
if (!type) {
if (isTupleType(parentType)) {
error(declaration, ts.Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, typeToString(parentType), parentType.elementTypes.length, pattern.elements.length);
}
else {
error(declaration, ts.Diagnostics.Type_0_has_no_property_1, typeToString(parentType), propName);
}
return unknownType;
}
}
else {
// Rest element has an array type with the same element type as the parent type
type = createArrayType(elementType);
}
}
return type;
}
// Return the inferred type for a variable, parameter, or property declaration
function getTypeForVariableLikeDeclaration(declaration) {
// A variable declared in a for..in statement is always of type any
if (declaration.parent.parent.kind === 198 /* ForInStatement */) {
return anyType;
}
if (declaration.parent.parent.kind === 199 /* ForOfStatement */) {
// checkRightHandSideOfForOf will return undefined if the for-of expression type was
// missing properties/signatures required to get its iteratedType (like
// [Symbol.iterator] or next). This may be because we accessed properties from anyType,
// or it may have led to an error inside getElementTypeOfIterable.
return checkRightHandSideOfForOf(declaration.parent.parent.expression) || anyType;
}
if (ts.isBindingPattern(declaration.parent)) {
return getTypeForBindingElement(declaration);
}
// Use type from type annotation if one is present
if (declaration.type) {
return getTypeFromTypeNode(declaration.type);
}
if (declaration.kind === 136 /* 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 === 144 /* SetAccessor */ && !ts.hasDynamicName(func)) {
var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 143 /* GetAccessor */);
if (getter) {
return getReturnTypeOfSignature(getSignatureFromDeclaration(getter));
}
}
// Use contextual parameter type if one is available
var type = getContextuallyTypedParameterType(declaration);
if (type) {
return type;
}
}
// Use the type of the initializer expression if one is present
if (declaration.initializer) {
return checkExpressionCached(declaration.initializer);
}
// If it is a short-hand property assignment, use the type of the identifier
if (declaration.kind === 244 /* 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);
}
// No type specified and nothing can be inferred
return undefined;
}
// Return the type implied by a binding pattern element. This is the type of the initializer of the element if
// one is present. Otherwise, if the element is itself a binding pattern, it is the type implied by the binding
// pattern. Otherwise, it is the type any.
function getTypeFromBindingElement(element) {
if (element.initializer) {
return getWidenedType(checkExpressionCached(element.initializer));
}
if (ts.isBindingPattern(element.name)) {
return getTypeFromBindingPattern(element.name);
}
return anyType;
}
// Return the type implied by an object binding pattern
function getTypeFromObjectBindingPattern(pattern) {
var members = {};
ts.forEach(pattern.elements, function (e) {
var flags = 4 /* Property */ | 67108864 /* Transient */ | (e.initializer ? 536870912 /* Optional */ : 0);
var name = e.propertyName || e.name;
var symbol = createSymbol(flags, name.text);
symbol.type = getTypeFromBindingElement(e);
members[symbol.name] = symbol;
});
return createAnonymousType(undefined, members, emptyArray, emptyArray, undefined, undefined);
}
// Return the type implied by an array binding pattern
function getTypeFromArrayBindingPattern(pattern) {
var hasSpreadElement = false;
var elementTypes = [];
ts.forEach(pattern.elements, function (e) {
elementTypes.push(e.kind === 185 /* OmittedExpression */ || e.dotDotDotToken ? anyType : getTypeFromBindingElement(e));
if (e.dotDotDotToken) {
hasSpreadElement = true;
}
});
if (!elementTypes.length) {
return languageVersion >= 2 /* ES6 */ ? createIterableType(anyType) : anyArrayType;
}
else if (hasSpreadElement) {
var unionOfElements = getUnionType(elementTypes);
return languageVersion >= 2 /* ES6 */ ? createIterableType(unionOfElements) : createArrayType(unionOfElements);
}
// If the pattern has at least one element, and no rest element, then it should imply a tuple type.
return createTupleType(elementTypes);
}
// Return the type implied by a binding pattern. This is the type implied purely by the binding pattern itself
// and without regard to its context (i.e. without regard any type annotation or initializer associated with the
// declaration in which the binding pattern is contained). For example, the implied type of [x, y] is [any, any]
// and the implied type of { x, y: z = 1 } is { x: any; y: number; }. The type implied by a binding pattern is
// used as the contextual type of an initializer associated with the binding pattern. Also, for a destructuring
// parameter with no type annotation or initializer, the type implied by the binding pattern becomes the type of
// the parameter.
function getTypeFromBindingPattern(pattern) {
return pattern.kind === 159 /* ObjectBindingPattern */
? getTypeFromObjectBindingPattern(pattern)
: getTypeFromArrayBindingPattern(pattern);
}
// Return the type associated with a variable, parameter, or property declaration. In the simple case this is the type
// specified in a type annotation or inferred from an initializer. However, in the case of a destructuring declaration it
// is a bit more involved. For example:
//
// var [x, s = ""] = [1, "one"];
//
// Here, the array literal [1, "one"] is contextually typed by the type [any, string], which is the implied type of the
// binding pattern [x, s = ""]. Because the contextual type is a tuple type, the resulting type of [1, "one"] is the
// tuple type [number, string]. Thus, the type inferred for 'x' is number and the type inferred for 's' is string.
function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) {
var type = getTypeForVariableLikeDeclaration(declaration);
if (type) {
if (reportErrors) {
reportErrorsFromWidening(declaration, type);
}
// During a normal type check we'll never get to here with a property assignment (the check of the containing
// object literal uses a different path). We exclude widening only so that language services and type verification
// tools see the actual type.
return declaration.kind !== 243 /* PropertyAssignment */ ? getWidenedType(type) : type;
}
// Rest parameters default to type any[], other parameters default to type any
type = declaration.dotDotDotToken ? anyArrayType : anyType;
// Report implicit any errors unless this is a private property within an ambient declaration
if (reportErrors && compilerOptions.noImplicitAny) {
var root = ts.getRootDeclaration(declaration);
if (!isPrivateWithinAmbient(root) && !(root.kind === 136 /* Parameter */ && isPrivateWithinAmbient(root.parent))) {
reportImplicitAnyError(declaration, type);
}
}
return type;
}
function 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 (declaration.parent.kind === 242 /* CatchClause */) {
return links.type = anyType;
}
// Handle export default expressions
if (declaration.kind === 225 /* ExportAssignment */) {
return links.type = checkExpression(declaration.expression);
}
// Handle variable, parameter or property
if (!pushTypeResolution(symbol, 0 /* Type */)) {
return unknownType;
}
var type = getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true);
if (!popTypeResolution()) {
if (symbol.valueDeclaration.type) {
// Variable has type annotation that circularly references the variable itself
type = unknownType;
error(symbol.valueDeclaration, ts.Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, symbolToString(symbol));
}
else {
// Variable has initializer that circularly references the variable itself
type = anyType;
if (compilerOptions.noImplicitAny) {
error(symbol.valueDeclaration, ts.Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol));
}
}
}
links.type = type;
}
return links.type;
}
function getAnnotatedAccessorType(accessor) {
if (accessor) {
if (accessor.kind === 143 /* GetAccessor */) {
return accessor.type && getTypeFromTypeNode(accessor.type);
}
else {
var setterTypeAnnotation = ts.getSetAccessorTypeAnnotationNode(accessor);
return setterTypeAnnotation && getTypeFromTypeNode(setterTypeAnnotation);
}
}
return undefined;
}
function getTypeOfAccessors(symbol) {
var links = getSymbolLinks(symbol);
if (!links.type) {
if (!pushTypeResolution(symbol, 0 /* Type */)) {
return unknownType;
}
var getter = ts.getDeclarationOfKind(symbol, 143 /* GetAccessor */);
var setter = ts.getDeclarationOfKind(symbol, 144 /* SetAccessor */);
var type;
// First try to see if the user specified a return type on the get-accessor.
var getterReturnType = getAnnotatedAccessorType(getter);
if (getterReturnType) {
type = getterReturnType;
}
else {
// If the user didn't specify a return type, try to use the set-accessor's parameter type.
var setterParameterType = getAnnotatedAccessorType(setter);
if (setterParameterType) {
type = setterParameterType;
}
else {
// If there are no specified types, try to infer it from the body of the get accessor if it exists.
if (getter && getter.body) {
type = getReturnTypeFromBody(getter);
}
else {
if (compilerOptions.noImplicitAny) {
error(setter, ts.Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_type_annotation, symbolToString(symbol));
}
type = anyType;
}
}
}
if (!popTypeResolution()) {
type = anyType;
if (compilerOptions.noImplicitAny) {
var getter_1 = ts.getDeclarationOfKind(symbol, 143 /* GetAccessor */);
error(getter_1, ts.Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol));
}
}
links.type = type;
}
return links.type;
}
function getTypeOfFuncClassEnumModule(symbol) {
var links = getSymbolLinks(symbol);
if (!links.type) {
links.type = createObjectType(65536 /* Anonymous */, symbol);
}
return links.type;
}
function getTypeOfEnumMember(symbol) {
var links = getSymbolLinks(symbol);
if (!links.type) {
links.type = getDeclaredTypeOfEnum(getParentOfSymbol(symbol));
}
return links.type;
}
function getTypeOfAlias(symbol) {
var links = getSymbolLinks(symbol);
if (!links.type) {
var targetSymbol = resolveAlias(symbol);
// It only makes sense to get the type of a value symbol. If the result of resolving
// the alias is not a value, then it has no type. To get the type associated with a
// type symbol, call getDeclaredTypeOfSymbol.
// This check is important because without it, a call to getTypeOfSymbol could end
// up recursively calling getTypeOfAlias, causing a stack overflow.
links.type = targetSymbol.flags & 107455 /* Value */
? getTypeOfSymbol(targetSymbol)
: unknownType;
}
return links.type;
}
function getTypeOfInstantiatedSymbol(symbol) {
var links = getSymbolLinks(symbol);
if (!links.type) {
links.type = instantiateType(getTypeOfSymbol(links.target), links.mapper);
}
return links.type;
}
function 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;
}
function getTargetType(type) {
return type.flags & 4096 /* Reference */ ? type.target : type;
}
function hasBaseType(type, checkBase) {
return check(type);
function check(type) {
var target = getTargetType(type);
return target === checkBase || ts.forEach(getBaseTypes(target), check);
}
}
// Appends the type parameters given by a list of declarations to a set of type parameters and returns the resulting set.
// The function allocates a new array if the input type parameter set is undefined, but otherwise it modifies the set
// in-place and returns the same array.
function appendTypeParameters(typeParameters, declarations) {
for (var _i = 0; _i < declarations.length; _i++) {
var declaration = declarations[_i];
var tp = getDeclaredTypeOfTypeParameter(getSymbolOfNode(declaration));
if (!typeParameters) {
typeParameters = [tp];
}
else if (!ts.contains(typeParameters, tp)) {
typeParameters.push(tp);
}
}
return typeParameters;
}
// Appends the outer type parameters of a node to a set of type parameters and returns the resulting set. The function
// allocates a new array if the input type parameter set is undefined, but otherwise it modifies the set in-place and
// returns the same array.
function appendOuterTypeParameters(typeParameters, node) {
while (true) {
node = node.parent;
if (!node) {
return typeParameters;
}
if (node.kind === 212 /* ClassDeclaration */ || node.kind === 184 /* ClassExpression */ ||
node.kind === 211 /* FunctionDeclaration */ || node.kind === 171 /* FunctionExpression */ ||
node.kind === 141 /* MethodDeclaration */ || node.kind === 172 /* ArrowFunction */) {
var declarations = node.typeParameters;
if (declarations) {
return appendTypeParameters(appendOuterTypeParameters(typeParameters, node), declarations);
}
}
}
}
// The outer type parameters are those defined by enclosing generic classes, methods, or functions.
function getOuterTypeParametersOfClassOrInterface(symbol) {
var declaration = symbol.flags & 32 /* Class */ ? symbol.valueDeclaration : ts.getDeclarationOfKind(symbol, 213 /* InterfaceDeclaration */);
return appendOuterTypeParameters(undefined, declaration);
}
// The local type parameters are the combined set of type parameters from all declarations of the class,
// interface, or type alias.
function getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol) {
var result;
for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) {
var node = _a[_i];
if (node.kind === 213 /* InterfaceDeclaration */ || node.kind === 212 /* ClassDeclaration */ ||
node.kind === 184 /* ClassExpression */ || node.kind === 214 /* TypeAliasDeclaration */) {
var declaration = node;
if (declaration.typeParameters) {
result = appendTypeParameters(result, declaration.typeParameters);
}
}
}
return result;
}
// The full set of type parameters for a generic class or interface type consists of its outer type parameters plus
// its locally declared type parameters.
function getTypeParametersOfClassOrInterface(symbol) {
return ts.concatenate(getOuterTypeParametersOfClassOrInterface(symbol), getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol));
}
function isConstructorType(type) {
return type.flags & 80896 /* ObjectType */ && getSignaturesOfType(type, 1 /* Construct */).length > 0;
}
function getBaseTypeNodeOfClass(type) {
return ts.getClassExtendsHeritageClauseElement(type.symbol.valueDeclaration);
}
function getConstructorsForTypeArguments(type, typeArgumentNodes) {
var typeArgCount = typeArgumentNodes ? typeArgumentNodes.length : 0;
return ts.filter(getSignaturesOfType(type, 1 /* Construct */), function (sig) { return (sig.typeParameters ? sig.typeParameters.length : 0) === typeArgCount; });
}
function getInstantiatedConstructorsForTypeArguments(type, typeArgumentNodes) {
var signatures = getConstructorsForTypeArguments(type, typeArgumentNodes);
if (typeArgumentNodes) {
var typeArguments = ts.map(typeArgumentNodes, getTypeFromTypeNode);
signatures = ts.map(signatures, function (sig) { return getSignatureInstantiation(sig, typeArguments); });
}
return signatures;
}
// The base constructor of a class can resolve to
// undefinedType if the class has no extends clause,
// unknownType if an error occurred during resolution of the extends expression,
// nullType if the extends expression is the null value, or
// an object type with at least one construct signature.
function getBaseConstructorTypeOfClass(type) {
if (!type.resolvedBaseConstructorType) {
var baseTypeNode = getBaseTypeNodeOfClass(type);
if (!baseTypeNode) {
return type.resolvedBaseConstructorType = undefinedType;
}
if (!pushTypeResolution(type, 1 /* ResolvedBaseConstructorType */)) {
return unknownType;
}
var baseConstructorType = checkExpression(baseTypeNode.expression);
if (baseConstructorType.flags & 80896 /* ObjectType */) {
// Resolving the members of a class requires us to resolve the base class of that class.
// We force resolution here such that we catch circularities now.
resolveStructuredTypeMembers(baseConstructorType);
}
if (!popTypeResolution()) {
error(type.symbol.valueDeclaration, ts.Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_base_expression, symbolToString(type.symbol));
return type.resolvedBaseConstructorType = unknownType;
}
if (baseConstructorType !== unknownType && baseConstructorType !== nullType && !isConstructorType(baseConstructorType)) {
error(baseTypeNode.expression, ts.Diagnostics.Type_0_is_not_a_constructor_function_type, typeToString(baseConstructorType));
return type.resolvedBaseConstructorType = unknownType;
}
type.resolvedBaseConstructorType = baseConstructorType;
}
return type.resolvedBaseConstructorType;
}
function getBaseTypes(type) {
if (!type.resolvedBaseTypes) {
if (type.symbol.flags & 32 /* Class */) {
resolveBaseTypesOfClass(type);
}
else if (type.symbol.flags & 64 /* Interface */) {
resolveBaseTypesOfInterface(type);
}
else {
ts.Debug.fail("type must be class or interface");
}
}
return type.resolvedBaseTypes;
}
function resolveBaseTypesOfClass(type) {
type.resolvedBaseTypes = emptyArray;
var baseContructorType = getBaseConstructorTypeOfClass(type);
if (!(baseContructorType.flags & 80896 /* ObjectType */)) {
return;
}
var baseTypeNode = getBaseTypeNodeOfClass(type);
var baseType;
if (baseContructorType.symbol && baseContructorType.symbol.flags & 32 /* Class */) {
// When base constructor type is a class we know that the constructors all have the same type parameters as the
// class and all return the instance type of the class. There is no need for further checks and we can apply the
// type arguments in the same manner as a type reference to get the same error reporting experience.
baseType = getTypeFromClassOrInterfaceReference(baseTypeNode, baseContructorType.symbol);
}
else {
// The class derives from a "class-like" constructor function, check that we have at least one construct signature
// with a matching number of type parameters and use the return type of the first instantiated signature. Elsewhere
// we check that all instantiated signatures return the same type.
var constructors = getInstantiatedConstructorsForTypeArguments(baseContructorType, baseTypeNode.typeArguments);
if (!constructors.length) {
error(baseTypeNode.expression, ts.Diagnostics.No_base_constructor_has_the_specified_number_of_type_arguments);
return;
}
baseType = getReturnTypeOfSignature(constructors[0]);
}
if (baseType === unknownType) {
return;
}
if (!(getTargetType(baseType).flags & (1024 /* Class */ | 2048 /* Interface */))) {
error(baseTypeNode.expression, ts.Diagnostics.Base_constructor_return_type_0_is_not_a_class_or_interface_type, typeToString(baseType));
return;
}
if (type === baseType || hasBaseType(baseType, type)) {
error(type.symbol.valueDeclaration, ts.Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, /*enclosingDeclaration*/ undefined, 1 /* WriteArrayAsGenericType */));
return;
}
type.resolvedBaseTypes = [baseType];
}
function resolveBaseTypesOfInterface(type) {
type.resolvedBaseTypes = [];
for (var _i = 0, _a = type.symbol.declarations; _i < _a.length; _i++) {
var declaration = _a[_i];
if (declaration.kind === 213 /* InterfaceDeclaration */ && ts.getInterfaceBaseTypeNodes(declaration)) {
for (var _b = 0, _c = ts.getInterfaceBaseTypeNodes(declaration); _b < _c.length; _b++) {
var node = _c[_b];
var baseType = getTypeFromTypeNode(node);
if (baseType !== unknownType) {
if (getTargetType(baseType).flags & (1024 /* Class */ | 2048 /* Interface */)) {
if (type !== baseType && !hasBaseType(baseType, type)) {
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);
}
}
}
}
}
}
function getDeclaredTypeOfClassOrInterface(symbol) {
var links = getSymbolLinks(symbol);
if (!links.declaredType) {
var kind = symbol.flags & 32 /* Class */ ? 1024 /* Class */ : 2048 /* Interface */;
var type = links.declaredType = createObjectType(kind, symbol);
var outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol);
var localTypeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol);
if (outerTypeParameters || localTypeParameters) {
type.flags |= 4096 /* Reference */;
type.typeParameters = ts.concatenate(outerTypeParameters, localTypeParameters);
type.outerTypeParameters = outerTypeParameters;
type.localTypeParameters = localTypeParameters;
type.instantiations = {};
type.instantiations[getTypeListId(type.typeParameters)] = type;
type.target = type;
type.typeArguments = type.typeParameters;
}
}
return links.declaredType;
}
function getDeclaredTypeOfTypeAlias(symbol) {
var links = getSymbolLinks(symbol);
if (!links.declaredType) {
// Note that we use the links object as the target here because the symbol object is used as the unique
// identity for resolution of the 'type' property in SymbolLinks.
if (!pushTypeResolution(symbol, 2 /* DeclaredType */)) {
return unknownType;
}
var declaration = ts.getDeclarationOfKind(symbol, 214 /* TypeAliasDeclaration */);
var type = getTypeFromTypeNode(declaration.type);
if (popTypeResolution()) {
links.typeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol);
if (links.typeParameters) {
// Initialize the instantiation cache for generic type aliases. The declared type corresponds to
// an instantiation of the type alias with the type parameters supplied as type arguments.
links.instantiations = {};
links.instantiations[getTypeListId(links.typeParameters)] = type;
}
}
else {
type = unknownType;
error(declaration.name, ts.Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol));
}
links.declaredType = type;
}
return links.declaredType;
}
function getDeclaredTypeOfEnum(symbol) {
var links = getSymbolLinks(symbol);
if (!links.declaredType) {
var type = createType(128 /* Enum */);
type.symbol = symbol;
links.declaredType = type;
}
return links.declaredType;
}
function getDeclaredTypeOfTypeParameter(symbol) {
var links = getSymbolLinks(symbol);
if (!links.declaredType) {
var type = createType(512 /* TypeParameter */);
type.symbol = symbol;
if (!ts.getDeclarationOfKind(symbol, 135 /* TypeParameter */).constraint) {
type.constraint = noConstraintType;
}
links.declaredType = type;
}
return links.declaredType;
}
function getDeclaredTypeOfAlias(symbol) {
var links = getSymbolLinks(symbol);
if (!links.declaredType) {
links.declaredType = getDeclaredTypeOfSymbol(resolveAlias(symbol));
}
return links.declaredType;
}
function getDeclaredTypeOfSymbol(symbol) {
ts.Debug.assert((symbol.flags & 16777216 /* Instantiated */) === 0);
if (symbol.flags & (32 /* Class */ | 64 /* Interface */)) {
return getDeclaredTypeOfClassOrInterface(symbol);
}
if (symbol.flags & 524288 /* TypeAlias */) {
return getDeclaredTypeOfTypeAlias(symbol);
}
if (symbol.flags & 384 /* Enum */) {
return getDeclaredTypeOfEnum(symbol);
}
if (symbol.flags & 262144 /* TypeParameter */) {
return getDeclaredTypeOfTypeParameter(symbol);
}
if (symbol.flags & 8388608 /* Alias */) {
return getDeclaredTypeOfAlias(symbol);
}
return unknownType;
}
function createSymbolTable(symbols) {
var result = {};
for (var _i = 0; _i < symbols.length; _i++) {
var symbol = symbols[_i];
result[symbol.name] = symbol;
}
return result;
}
function createInstantiatedSymbolTable(symbols, mapper) {
var result = {};
for (var _i = 0; _i < symbols.length; _i++) {
var symbol = symbols[_i];
result[symbol.name] = instantiateSymbol(symbol, mapper);
}
return result;
}
function addInheritedMembers(symbols, baseSymbols) {
for (var _i = 0; _i < baseSymbols.length; _i++) {
var s = baseSymbols[_i];
if (!ts.hasProperty(symbols, s.name)) {
symbols[s.name] = s;
}
}
}
function addInheritedSignatures(signatures, baseSignatures) {
if (baseSignatures) {
for (var _i = 0; _i < baseSignatures.length; _i++) {
var signature = baseSignatures[_i];
signatures.push(signature);
}
}
}
function resolveDeclaredMembers(type) {
if (!type.declaredProperties) {
var symbol = type.symbol;
type.declaredProperties = getNamedMembers(symbol.members);
type.declaredCallSignatures = getSignaturesOfSymbol(symbol.members["__call"]);
type.declaredConstructSignatures = getSignaturesOfSymbol(symbol.members["__new"]);
type.declaredStringIndexType = getIndexTypeOfSymbol(symbol, 0 /* String */);
type.declaredNumberIndexType = getIndexTypeOfSymbol(symbol, 1 /* Number */);
}
return type;
}
function resolveClassOrInterfaceMembers(type) {
var target = resolveDeclaredMembers(type);
var members = target.symbol.members;
var callSignatures = target.declaredCallSignatures;
var constructSignatures = target.declaredConstructSignatures;
var stringIndexType = target.declaredStringIndexType;
var numberIndexType = target.declaredNumberIndexType;
var baseTypes = getBaseTypes(target);
if (baseTypes.length) {
members = createSymbolTable(target.declaredProperties);
for (var _i = 0; _i < baseTypes.length; _i++) {
var baseType = baseTypes[_i];
addInheritedMembers(members, getPropertiesOfObjectType(baseType));
callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(baseType, 0 /* Call */));
constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(baseType, 1 /* Construct */));
stringIndexType = stringIndexType || getIndexTypeOfType(baseType, 0 /* String */);
numberIndexType = numberIndexType || getIndexTypeOfType(baseType, 1 /* Number */);
}
}
setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
}
function resolveTypeReferenceMembers(type) {
var target = resolveDeclaredMembers(type.target);
var mapper = createTypeMapper(target.typeParameters, type.typeArguments);
var members = createInstantiatedSymbolTable(target.declaredProperties, mapper);
var callSignatures = instantiateList(target.declaredCallSignatures, mapper, instantiateSignature);
var constructSignatures = instantiateList(target.declaredConstructSignatures, mapper, instantiateSignature);
var stringIndexType = target.declaredStringIndexType ? instantiateType(target.declaredStringIndexType, mapper) : undefined;
var numberIndexType = target.declaredNumberIndexType ? instantiateType(target.declaredNumberIndexType, mapper) : undefined;
ts.forEach(getBaseTypes(target), function (baseType) {
var instantiatedBaseType = instantiateType(baseType, mapper);
addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType));
callSignatures = ts.concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, 0 /* Call */));
constructSignatures = ts.concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, 1 /* Construct */));
stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, 0 /* String */);
numberIndexType = numberIndexType || getIndexTypeOfType(instantiatedBaseType, 1 /* Number */);
});
setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
}
function createSignature(declaration, typeParameters, parameters, resolvedReturnType, typePredicate, minArgumentCount, hasRestParameter, hasStringLiterals) {
var sig = new Signature(checker);
sig.declaration = declaration;
sig.typeParameters = typeParameters;
sig.parameters = parameters;
sig.resolvedReturnType = resolvedReturnType;
sig.typePredicate = typePredicate;
sig.minArgumentCount = minArgumentCount;
sig.hasRestParameter = hasRestParameter;
sig.hasStringLiterals = hasStringLiterals;
return sig;
}
function cloneSignature(sig) {
return createSignature(sig.declaration, sig.typeParameters, sig.parameters, sig.resolvedReturnType, sig.typePredicate, sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals);
}
function getDefaultConstructSignatures(classType) {
if (!getBaseTypes(classType).length) {
return [createSignature(undefined, classType.localTypeParameters, emptyArray, classType, undefined, 0, false, false)];
}
var baseConstructorType = getBaseConstructorTypeOfClass(classType);
var baseSignatures = getSignaturesOfType(baseConstructorType, 1 /* Construct */);
var baseTypeNode = getBaseTypeNodeOfClass(classType);
var typeArguments = ts.map(baseTypeNode.typeArguments, getTypeFromTypeNode);
var typeArgCount = typeArguments ? typeArguments.length : 0;
var result = [];
for (var _i = 0; _i < baseSignatures.length; _i++) {
var baseSig = baseSignatures[_i];
var typeParamCount = baseSig.typeParameters ? baseSig.typeParameters.length : 0;
if (typeParamCount === typeArgCount) {
var sig = typeParamCount ? getSignatureInstantiation(baseSig, typeArguments) : cloneSignature(baseSig);
sig.typeParameters = classType.localTypeParameters;
sig.resolvedReturnType = classType;
result.push(sig);
}
}
return result;
}
function createTupleTypeMemberSymbols(memberTypes) {
var members = {};
for (var i = 0; i < memberTypes.length; i++) {
var symbol = createSymbol(4 /* Property */ | 67108864 /* Transient */, "" + i);
symbol.type = memberTypes[i];
members[i] = symbol;
}
return members;
}
function resolveTupleTypeMembers(type) {
var arrayType = resolveStructuredTypeMembers(createArrayType(getUnionType(type.elementTypes, /*noSubtypeReduction*/ true)));
var members = createTupleTypeMemberSymbols(type.elementTypes);
addInheritedMembers(members, arrayType.properties);
setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType);
}
function findMatchingSignature(signatureList, signature, partialMatch, ignoreReturnTypes) {
for (var _i = 0; _i < signatureList.length; _i++) {
var s = signatureList[_i];
if (compareSignatures(s, signature, partialMatch, ignoreReturnTypes, compareTypes)) {
return s;
}
}
}
function findMatchingSignatures(signatureLists, signature, listIndex) {
if (signature.typeParameters) {
// We require an exact match for generic signatures, so we only return signatures from the first
// signature list and only if they have exact matches in the other signature lists.
if (listIndex > 0) {
return undefined;
}
for (var i = 1; i < signatureLists.length; i++) {
if (!findMatchingSignature(signatureLists[i], signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ false)) {
return undefined;
}
}
return [signature];
}
var result = undefined;
for (var i = 0; i < signatureLists.length; i++) {
// Allow matching non-generic signatures to have excess parameters and different return types
var match = i === listIndex ? signature : findMatchingSignature(signatureLists[i], signature, /*partialMatch*/ true, /*ignoreReturnTypes*/ true);
if (!match) {
return undefined;
}
if (!ts.contains(result, match)) {
(result || (result = [])).push(match);
}
}
return result;
}
// The signatures of a union type are those signatures that are present in each of the constituent types.
// Generic signatures must match exactly, but non-generic signatures are allowed to have extra optional
// parameters and may differ in return types. When signatures differ in return types, the resulting return
// type is the union of the constituent return types.
function getUnionSignatures(types, kind) {
var signatureLists = ts.map(types, function (t) { return getSignaturesOfType(t, kind); });
var result = undefined;
for (var i = 0; i < signatureLists.length; i++) {
for (var _i = 0, _a = signatureLists[i]; _i < _a.length; _i++) {
var signature = _a[_i];
// Only process signatures with parameter lists that aren't already in the result list
if (!result || !findMatchingSignature(result, signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ true)) {
var unionSignatures = findMatchingSignatures(signatureLists, signature, i);
if (unionSignatures) {
var s = signature;
// Union the result types when more than one signature matches
if (unionSignatures.length > 1) {
s = cloneSignature(signature);
// Clear resolved return type we possibly got from cloneSignature
s.resolvedReturnType = undefined;
s.unionSignatures = unionSignatures;
}
(result || (result = [])).push(s);
}
}
}
}
return result || emptyArray;
}
function getUnionIndexType(types, kind) {
var indexTypes = [];
for (var _i = 0; _i < types.length; _i++) {
var type = types[_i];
var indexType = getIndexTypeOfType(type, kind);
if (!indexType) {
return undefined;
}
indexTypes.push(indexType);
}
return getUnionType(indexTypes);
}
function resolveUnionTypeMembers(type) {
// The members and properties collections are empty for union types. To get all properties of a union
// type use getPropertiesOfType (only the language service uses this).
var callSignatures = getUnionSignatures(type.types, 0 /* Call */);
var constructSignatures = getUnionSignatures(type.types, 1 /* Construct */);
var stringIndexType = getUnionIndexType(type.types, 0 /* String */);
var numberIndexType = getUnionIndexType(type.types, 1 /* Number */);
setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexType, numberIndexType);
}
function intersectTypes(type1, type2) {
return !type1 ? type2 : !type2 ? type1 : getIntersectionType([type1, type2]);
}
function resolveIntersectionTypeMembers(type) {
// The members and properties collections are empty for intersection types. To get all properties of an
// intersection type use getPropertiesOfType (only the language service uses this).
var callSignatures = emptyArray;
var constructSignatures = emptyArray;
var stringIndexType = undefined;
var numberIndexType = undefined;
for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment