Add support for parsing async/await in fidelity.

Conflicts:
	src/services/syntax/SyntaxGenerator.js.map
This commit is contained in:
Cyrus Najmabadi 2014-11-25 17:13:16 -08:00
parent af4a12151c
commit 05668cede7
22 changed files with 1026 additions and 594 deletions

View file

@ -20,7 +20,7 @@ module TypeScript {
Parameter_cannot_have_question_mark_and_initializer: "Parameter cannot have question mark and initializer.",
A_required_parameter_cannot_follow_an_optional_parameter: "A required parameter cannot follow an optional parameter.",
Index_signatures_cannot_have_rest_parameters: "Index signatures cannot have rest parameters.",
Index_signature_parameter_cannot_have_accessibility_modifiers: "Index signature parameter cannot have accessibility modifiers.",
Index_signature_parameter_cannot_have_modifiers: "Index signature parameter cannot have modifiers.",
Index_signature_parameter_cannot_have_a_question_mark: "Index signature parameter cannot have a question mark.",
Index_signature_parameter_cannot_have_an_initializer: "Index signature parameter cannot have an initializer.",
Index_signature_must_have_a_type_annotation: "Index signature must have a type annotation.",
@ -99,6 +99,10 @@ module TypeScript {
yield_expression_must_be_contained_within_a_generator_declaration: "'yield' expression must be contained within a generator declaration.",
Unterminated_regular_expression_literal: "Unterminated regular expression literal.",
Unterminated_template_literal: "Unterminated template literal.",
await_expression_must_be_contained_within_an_async_declaration: "'await' expression must be contained within an async declaration.",
async_arrow_function_parameters_must_be_parenthesized: "'async' arrow function parameters must be parenthesized.",
A_generator_declaration_cannot_have_the_async_modifier: "A generator declaration cannot have the 'async' modifier.",
async_modifier_cannot_appear_here: "'async' modifier cannot appear here.",
Duplicate_identifier_0: "Duplicate identifier '{0}'.",
The_name_0_does_not_exist_in_the_current_scope: "The name '{0}' does not exist in the current scope.",
The_name_0_does_not_refer_to_a_value: "The name '{0}' does not refer to a value.",

View file

@ -22,7 +22,7 @@ module TypeScript {
"Parameter cannot have question mark and initializer.": { "code": 1015, "category": DiagnosticCategory.Error },
"A required parameter cannot follow an optional parameter.": { "code": 1016, "category": DiagnosticCategory.Error },
"Index signatures cannot have rest parameters.": { "code": 1017, "category": DiagnosticCategory.Error },
"Index signature parameter cannot have accessibility modifiers.": { "code": 1018, "category": DiagnosticCategory.Error },
"Index signature parameter cannot have modifiers.": { "code": 1018, "category": DiagnosticCategory.Error },
"Index signature parameter cannot have a question mark.": { "code": 1019, "category": DiagnosticCategory.Error },
"Index signature parameter cannot have an initializer.": { "code": 1020, "category": DiagnosticCategory.Error },
"Index signature must have a type annotation.": { "code": 1021, "category": DiagnosticCategory.Error },
@ -101,6 +101,10 @@ module TypeScript {
"'yield' expression must be contained within a generator declaration.": { "code": 1113, "category": DiagnosticCategory.Error },
"Unterminated regular expression literal.": { "code": 1114, "category": DiagnosticCategory.Error },
"Unterminated template literal.": { "code": 1115, "category": DiagnosticCategory.Error },
"'await' expression must be contained within an 'async' declaration.": { "code": 1116, "category": DiagnosticCategory.Error },
"'async' arrow function parameters must be parenthesized.": { "code": 1117, "category": DiagnosticCategory.Error },
"A generator declaration cannot have the 'async' modifier.": { "code": 1118, "category": DiagnosticCategory.Error },
"'async' modifier cannot appear here.": { "code": 1119, "category": DiagnosticCategory.Error },
"Duplicate identifier '{0}'.": { "code": 2000, "category": DiagnosticCategory.Error },
"The name '{0}' does not exist in the current scope.": { "code": 2001, "category": DiagnosticCategory.Error },
"The name '{0}' does not refer to a value.": { "code": 2002, "category": DiagnosticCategory.Error },

View file

@ -75,7 +75,7 @@
"category": "Error",
"code": 1017
},
"Index signature parameter cannot have accessibility modifiers.": {
"Index signature parameter cannot have modifiers.": {
"category": "Error",
"code": 1018
},
@ -391,6 +391,22 @@
"category": "Error",
"code": 1115
},
"'await' expression must be contained within an 'async' declaration.": {
"category": "Error",
"code": 1116
},
"'async' arrow function parameters must be parenthesized.": {
"category": "Error",
"code": 1117
},
"A generator declaration cannot have the 'async' modifier.": {
"category": "Error",
"code": 1118
},
"'async' modifier cannot appear here.": {
"category": "Error",
"code": 1119
},
"Duplicate identifier '{0}'.": {
"category": "Error",
"code": 2000

View file

@ -472,159 +472,162 @@ var TypeScript;
SyntaxKind[SyntaxKind["StaticKeyword"] = 60] = "StaticKeyword";
SyntaxKind[SyntaxKind["YieldKeyword"] = 61] = "YieldKeyword";
SyntaxKind[SyntaxKind["AnyKeyword"] = 62] = "AnyKeyword";
SyntaxKind[SyntaxKind["BooleanKeyword"] = 63] = "BooleanKeyword";
SyntaxKind[SyntaxKind["ConstructorKeyword"] = 64] = "ConstructorKeyword";
SyntaxKind[SyntaxKind["DeclareKeyword"] = 65] = "DeclareKeyword";
SyntaxKind[SyntaxKind["GetKeyword"] = 66] = "GetKeyword";
SyntaxKind[SyntaxKind["ModuleKeyword"] = 67] = "ModuleKeyword";
SyntaxKind[SyntaxKind["RequireKeyword"] = 68] = "RequireKeyword";
SyntaxKind[SyntaxKind["NumberKeyword"] = 69] = "NumberKeyword";
SyntaxKind[SyntaxKind["SetKeyword"] = 70] = "SetKeyword";
SyntaxKind[SyntaxKind["StringKeyword"] = 71] = "StringKeyword";
SyntaxKind[SyntaxKind["OpenBraceToken"] = 72] = "OpenBraceToken";
SyntaxKind[SyntaxKind["CloseBraceToken"] = 73] = "CloseBraceToken";
SyntaxKind[SyntaxKind["OpenParenToken"] = 74] = "OpenParenToken";
SyntaxKind[SyntaxKind["CloseParenToken"] = 75] = "CloseParenToken";
SyntaxKind[SyntaxKind["OpenBracketToken"] = 76] = "OpenBracketToken";
SyntaxKind[SyntaxKind["CloseBracketToken"] = 77] = "CloseBracketToken";
SyntaxKind[SyntaxKind["DotToken"] = 78] = "DotToken";
SyntaxKind[SyntaxKind["DotDotDotToken"] = 79] = "DotDotDotToken";
SyntaxKind[SyntaxKind["SemicolonToken"] = 80] = "SemicolonToken";
SyntaxKind[SyntaxKind["CommaToken"] = 81] = "CommaToken";
SyntaxKind[SyntaxKind["LessThanToken"] = 82] = "LessThanToken";
SyntaxKind[SyntaxKind["GreaterThanToken"] = 83] = "GreaterThanToken";
SyntaxKind[SyntaxKind["LessThanEqualsToken"] = 84] = "LessThanEqualsToken";
SyntaxKind[SyntaxKind["GreaterThanEqualsToken"] = 85] = "GreaterThanEqualsToken";
SyntaxKind[SyntaxKind["EqualsEqualsToken"] = 86] = "EqualsEqualsToken";
SyntaxKind[SyntaxKind["EqualsGreaterThanToken"] = 87] = "EqualsGreaterThanToken";
SyntaxKind[SyntaxKind["ExclamationEqualsToken"] = 88] = "ExclamationEqualsToken";
SyntaxKind[SyntaxKind["EqualsEqualsEqualsToken"] = 89] = "EqualsEqualsEqualsToken";
SyntaxKind[SyntaxKind["ExclamationEqualsEqualsToken"] = 90] = "ExclamationEqualsEqualsToken";
SyntaxKind[SyntaxKind["PlusToken"] = 91] = "PlusToken";
SyntaxKind[SyntaxKind["MinusToken"] = 92] = "MinusToken";
SyntaxKind[SyntaxKind["AsteriskToken"] = 93] = "AsteriskToken";
SyntaxKind[SyntaxKind["PercentToken"] = 94] = "PercentToken";
SyntaxKind[SyntaxKind["PlusPlusToken"] = 95] = "PlusPlusToken";
SyntaxKind[SyntaxKind["MinusMinusToken"] = 96] = "MinusMinusToken";
SyntaxKind[SyntaxKind["LessThanLessThanToken"] = 97] = "LessThanLessThanToken";
SyntaxKind[SyntaxKind["GreaterThanGreaterThanToken"] = 98] = "GreaterThanGreaterThanToken";
SyntaxKind[SyntaxKind["GreaterThanGreaterThanGreaterThanToken"] = 99] = "GreaterThanGreaterThanGreaterThanToken";
SyntaxKind[SyntaxKind["AmpersandToken"] = 100] = "AmpersandToken";
SyntaxKind[SyntaxKind["BarToken"] = 101] = "BarToken";
SyntaxKind[SyntaxKind["CaretToken"] = 102] = "CaretToken";
SyntaxKind[SyntaxKind["ExclamationToken"] = 103] = "ExclamationToken";
SyntaxKind[SyntaxKind["TildeToken"] = 104] = "TildeToken";
SyntaxKind[SyntaxKind["AmpersandAmpersandToken"] = 105] = "AmpersandAmpersandToken";
SyntaxKind[SyntaxKind["BarBarToken"] = 106] = "BarBarToken";
SyntaxKind[SyntaxKind["QuestionToken"] = 107] = "QuestionToken";
SyntaxKind[SyntaxKind["ColonToken"] = 108] = "ColonToken";
SyntaxKind[SyntaxKind["EqualsToken"] = 109] = "EqualsToken";
SyntaxKind[SyntaxKind["PlusEqualsToken"] = 110] = "PlusEqualsToken";
SyntaxKind[SyntaxKind["MinusEqualsToken"] = 111] = "MinusEqualsToken";
SyntaxKind[SyntaxKind["AsteriskEqualsToken"] = 112] = "AsteriskEqualsToken";
SyntaxKind[SyntaxKind["PercentEqualsToken"] = 113] = "PercentEqualsToken";
SyntaxKind[SyntaxKind["LessThanLessThanEqualsToken"] = 114] = "LessThanLessThanEqualsToken";
SyntaxKind[SyntaxKind["GreaterThanGreaterThanEqualsToken"] = 115] = "GreaterThanGreaterThanEqualsToken";
SyntaxKind[SyntaxKind["GreaterThanGreaterThanGreaterThanEqualsToken"] = 116] = "GreaterThanGreaterThanGreaterThanEqualsToken";
SyntaxKind[SyntaxKind["AmpersandEqualsToken"] = 117] = "AmpersandEqualsToken";
SyntaxKind[SyntaxKind["BarEqualsToken"] = 118] = "BarEqualsToken";
SyntaxKind[SyntaxKind["CaretEqualsToken"] = 119] = "CaretEqualsToken";
SyntaxKind[SyntaxKind["SlashToken"] = 120] = "SlashToken";
SyntaxKind[SyntaxKind["SlashEqualsToken"] = 121] = "SlashEqualsToken";
SyntaxKind[SyntaxKind["SourceUnit"] = 122] = "SourceUnit";
SyntaxKind[SyntaxKind["QualifiedName"] = 123] = "QualifiedName";
SyntaxKind[SyntaxKind["ObjectType"] = 124] = "ObjectType";
SyntaxKind[SyntaxKind["FunctionType"] = 125] = "FunctionType";
SyntaxKind[SyntaxKind["ArrayType"] = 126] = "ArrayType";
SyntaxKind[SyntaxKind["ConstructorType"] = 127] = "ConstructorType";
SyntaxKind[SyntaxKind["GenericType"] = 128] = "GenericType";
SyntaxKind[SyntaxKind["TypeQuery"] = 129] = "TypeQuery";
SyntaxKind[SyntaxKind["TupleType"] = 130] = "TupleType";
SyntaxKind[SyntaxKind["UnionType"] = 131] = "UnionType";
SyntaxKind[SyntaxKind["ParenthesizedType"] = 132] = "ParenthesizedType";
SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 133] = "InterfaceDeclaration";
SyntaxKind[SyntaxKind["FunctionDeclaration"] = 134] = "FunctionDeclaration";
SyntaxKind[SyntaxKind["ModuleDeclaration"] = 135] = "ModuleDeclaration";
SyntaxKind[SyntaxKind["ClassDeclaration"] = 136] = "ClassDeclaration";
SyntaxKind[SyntaxKind["EnumDeclaration"] = 137] = "EnumDeclaration";
SyntaxKind[SyntaxKind["ImportDeclaration"] = 138] = "ImportDeclaration";
SyntaxKind[SyntaxKind["ExportAssignment"] = 139] = "ExportAssignment";
SyntaxKind[SyntaxKind["MemberFunctionDeclaration"] = 140] = "MemberFunctionDeclaration";
SyntaxKind[SyntaxKind["MemberVariableDeclaration"] = 141] = "MemberVariableDeclaration";
SyntaxKind[SyntaxKind["ConstructorDeclaration"] = 142] = "ConstructorDeclaration";
SyntaxKind[SyntaxKind["IndexMemberDeclaration"] = 143] = "IndexMemberDeclaration";
SyntaxKind[SyntaxKind["GetAccessor"] = 144] = "GetAccessor";
SyntaxKind[SyntaxKind["SetAccessor"] = 145] = "SetAccessor";
SyntaxKind[SyntaxKind["PropertySignature"] = 146] = "PropertySignature";
SyntaxKind[SyntaxKind["CallSignature"] = 147] = "CallSignature";
SyntaxKind[SyntaxKind["ConstructSignature"] = 148] = "ConstructSignature";
SyntaxKind[SyntaxKind["IndexSignature"] = 149] = "IndexSignature";
SyntaxKind[SyntaxKind["MethodSignature"] = 150] = "MethodSignature";
SyntaxKind[SyntaxKind["Block"] = 151] = "Block";
SyntaxKind[SyntaxKind["IfStatement"] = 152] = "IfStatement";
SyntaxKind[SyntaxKind["VariableStatement"] = 153] = "VariableStatement";
SyntaxKind[SyntaxKind["ExpressionStatement"] = 154] = "ExpressionStatement";
SyntaxKind[SyntaxKind["ReturnStatement"] = 155] = "ReturnStatement";
SyntaxKind[SyntaxKind["SwitchStatement"] = 156] = "SwitchStatement";
SyntaxKind[SyntaxKind["BreakStatement"] = 157] = "BreakStatement";
SyntaxKind[SyntaxKind["ContinueStatement"] = 158] = "ContinueStatement";
SyntaxKind[SyntaxKind["ForStatement"] = 159] = "ForStatement";
SyntaxKind[SyntaxKind["ForInStatement"] = 160] = "ForInStatement";
SyntaxKind[SyntaxKind["EmptyStatement"] = 161] = "EmptyStatement";
SyntaxKind[SyntaxKind["ThrowStatement"] = 162] = "ThrowStatement";
SyntaxKind[SyntaxKind["WhileStatement"] = 163] = "WhileStatement";
SyntaxKind[SyntaxKind["TryStatement"] = 164] = "TryStatement";
SyntaxKind[SyntaxKind["LabeledStatement"] = 165] = "LabeledStatement";
SyntaxKind[SyntaxKind["DoStatement"] = 166] = "DoStatement";
SyntaxKind[SyntaxKind["DebuggerStatement"] = 167] = "DebuggerStatement";
SyntaxKind[SyntaxKind["WithStatement"] = 168] = "WithStatement";
SyntaxKind[SyntaxKind["PrefixUnaryExpression"] = 169] = "PrefixUnaryExpression";
SyntaxKind[SyntaxKind["DeleteExpression"] = 170] = "DeleteExpression";
SyntaxKind[SyntaxKind["TypeOfExpression"] = 171] = "TypeOfExpression";
SyntaxKind[SyntaxKind["VoidExpression"] = 172] = "VoidExpression";
SyntaxKind[SyntaxKind["ConditionalExpression"] = 173] = "ConditionalExpression";
SyntaxKind[SyntaxKind["BinaryExpression"] = 174] = "BinaryExpression";
SyntaxKind[SyntaxKind["PostfixUnaryExpression"] = 175] = "PostfixUnaryExpression";
SyntaxKind[SyntaxKind["MemberAccessExpression"] = 176] = "MemberAccessExpression";
SyntaxKind[SyntaxKind["InvocationExpression"] = 177] = "InvocationExpression";
SyntaxKind[SyntaxKind["ArrayLiteralExpression"] = 178] = "ArrayLiteralExpression";
SyntaxKind[SyntaxKind["ObjectLiteralExpression"] = 179] = "ObjectLiteralExpression";
SyntaxKind[SyntaxKind["ObjectCreationExpression"] = 180] = "ObjectCreationExpression";
SyntaxKind[SyntaxKind["ParenthesizedExpression"] = 181] = "ParenthesizedExpression";
SyntaxKind[SyntaxKind["ParenthesizedArrowFunctionExpression"] = 182] = "ParenthesizedArrowFunctionExpression";
SyntaxKind[SyntaxKind["SimpleArrowFunctionExpression"] = 183] = "SimpleArrowFunctionExpression";
SyntaxKind[SyntaxKind["CastExpression"] = 184] = "CastExpression";
SyntaxKind[SyntaxKind["ElementAccessExpression"] = 185] = "ElementAccessExpression";
SyntaxKind[SyntaxKind["FunctionExpression"] = 186] = "FunctionExpression";
SyntaxKind[SyntaxKind["OmittedExpression"] = 187] = "OmittedExpression";
SyntaxKind[SyntaxKind["TemplateExpression"] = 188] = "TemplateExpression";
SyntaxKind[SyntaxKind["TemplateAccessExpression"] = 189] = "TemplateAccessExpression";
SyntaxKind[SyntaxKind["YieldExpression"] = 190] = "YieldExpression";
SyntaxKind[SyntaxKind["VariableDeclaration"] = 191] = "VariableDeclaration";
SyntaxKind[SyntaxKind["VariableDeclarator"] = 192] = "VariableDeclarator";
SyntaxKind[SyntaxKind["ArgumentList"] = 193] = "ArgumentList";
SyntaxKind[SyntaxKind["ParameterList"] = 194] = "ParameterList";
SyntaxKind[SyntaxKind["TypeArgumentList"] = 195] = "TypeArgumentList";
SyntaxKind[SyntaxKind["TypeParameterList"] = 196] = "TypeParameterList";
SyntaxKind[SyntaxKind["HeritageClause"] = 197] = "HeritageClause";
SyntaxKind[SyntaxKind["EqualsValueClause"] = 198] = "EqualsValueClause";
SyntaxKind[SyntaxKind["CaseSwitchClause"] = 199] = "CaseSwitchClause";
SyntaxKind[SyntaxKind["DefaultSwitchClause"] = 200] = "DefaultSwitchClause";
SyntaxKind[SyntaxKind["ElseClause"] = 201] = "ElseClause";
SyntaxKind[SyntaxKind["CatchClause"] = 202] = "CatchClause";
SyntaxKind[SyntaxKind["FinallyClause"] = 203] = "FinallyClause";
SyntaxKind[SyntaxKind["TemplateClause"] = 204] = "TemplateClause";
SyntaxKind[SyntaxKind["TypeParameter"] = 205] = "TypeParameter";
SyntaxKind[SyntaxKind["Constraint"] = 206] = "Constraint";
SyntaxKind[SyntaxKind["SimplePropertyAssignment"] = 207] = "SimplePropertyAssignment";
SyntaxKind[SyntaxKind["FunctionPropertyAssignment"] = 208] = "FunctionPropertyAssignment";
SyntaxKind[SyntaxKind["Parameter"] = 209] = "Parameter";
SyntaxKind[SyntaxKind["EnumElement"] = 210] = "EnumElement";
SyntaxKind[SyntaxKind["TypeAnnotation"] = 211] = "TypeAnnotation";
SyntaxKind[SyntaxKind["ExpressionBody"] = 212] = "ExpressionBody";
SyntaxKind[SyntaxKind["ComputedPropertyName"] = 213] = "ComputedPropertyName";
SyntaxKind[SyntaxKind["ExternalModuleReference"] = 214] = "ExternalModuleReference";
SyntaxKind[SyntaxKind["ModuleNameModuleReference"] = 215] = "ModuleNameModuleReference";
SyntaxKind[SyntaxKind["AsyncKeyword"] = 63] = "AsyncKeyword";
SyntaxKind[SyntaxKind["AwaitKeyword"] = 64] = "AwaitKeyword";
SyntaxKind[SyntaxKind["BooleanKeyword"] = 65] = "BooleanKeyword";
SyntaxKind[SyntaxKind["ConstructorKeyword"] = 66] = "ConstructorKeyword";
SyntaxKind[SyntaxKind["DeclareKeyword"] = 67] = "DeclareKeyword";
SyntaxKind[SyntaxKind["GetKeyword"] = 68] = "GetKeyword";
SyntaxKind[SyntaxKind["ModuleKeyword"] = 69] = "ModuleKeyword";
SyntaxKind[SyntaxKind["RequireKeyword"] = 70] = "RequireKeyword";
SyntaxKind[SyntaxKind["NumberKeyword"] = 71] = "NumberKeyword";
SyntaxKind[SyntaxKind["SetKeyword"] = 72] = "SetKeyword";
SyntaxKind[SyntaxKind["StringKeyword"] = 73] = "StringKeyword";
SyntaxKind[SyntaxKind["OpenBraceToken"] = 74] = "OpenBraceToken";
SyntaxKind[SyntaxKind["CloseBraceToken"] = 75] = "CloseBraceToken";
SyntaxKind[SyntaxKind["OpenParenToken"] = 76] = "OpenParenToken";
SyntaxKind[SyntaxKind["CloseParenToken"] = 77] = "CloseParenToken";
SyntaxKind[SyntaxKind["OpenBracketToken"] = 78] = "OpenBracketToken";
SyntaxKind[SyntaxKind["CloseBracketToken"] = 79] = "CloseBracketToken";
SyntaxKind[SyntaxKind["DotToken"] = 80] = "DotToken";
SyntaxKind[SyntaxKind["DotDotDotToken"] = 81] = "DotDotDotToken";
SyntaxKind[SyntaxKind["SemicolonToken"] = 82] = "SemicolonToken";
SyntaxKind[SyntaxKind["CommaToken"] = 83] = "CommaToken";
SyntaxKind[SyntaxKind["LessThanToken"] = 84] = "LessThanToken";
SyntaxKind[SyntaxKind["GreaterThanToken"] = 85] = "GreaterThanToken";
SyntaxKind[SyntaxKind["LessThanEqualsToken"] = 86] = "LessThanEqualsToken";
SyntaxKind[SyntaxKind["GreaterThanEqualsToken"] = 87] = "GreaterThanEqualsToken";
SyntaxKind[SyntaxKind["EqualsEqualsToken"] = 88] = "EqualsEqualsToken";
SyntaxKind[SyntaxKind["EqualsGreaterThanToken"] = 89] = "EqualsGreaterThanToken";
SyntaxKind[SyntaxKind["ExclamationEqualsToken"] = 90] = "ExclamationEqualsToken";
SyntaxKind[SyntaxKind["EqualsEqualsEqualsToken"] = 91] = "EqualsEqualsEqualsToken";
SyntaxKind[SyntaxKind["ExclamationEqualsEqualsToken"] = 92] = "ExclamationEqualsEqualsToken";
SyntaxKind[SyntaxKind["PlusToken"] = 93] = "PlusToken";
SyntaxKind[SyntaxKind["MinusToken"] = 94] = "MinusToken";
SyntaxKind[SyntaxKind["AsteriskToken"] = 95] = "AsteriskToken";
SyntaxKind[SyntaxKind["PercentToken"] = 96] = "PercentToken";
SyntaxKind[SyntaxKind["PlusPlusToken"] = 97] = "PlusPlusToken";
SyntaxKind[SyntaxKind["MinusMinusToken"] = 98] = "MinusMinusToken";
SyntaxKind[SyntaxKind["LessThanLessThanToken"] = 99] = "LessThanLessThanToken";
SyntaxKind[SyntaxKind["GreaterThanGreaterThanToken"] = 100] = "GreaterThanGreaterThanToken";
SyntaxKind[SyntaxKind["GreaterThanGreaterThanGreaterThanToken"] = 101] = "GreaterThanGreaterThanGreaterThanToken";
SyntaxKind[SyntaxKind["AmpersandToken"] = 102] = "AmpersandToken";
SyntaxKind[SyntaxKind["BarToken"] = 103] = "BarToken";
SyntaxKind[SyntaxKind["CaretToken"] = 104] = "CaretToken";
SyntaxKind[SyntaxKind["ExclamationToken"] = 105] = "ExclamationToken";
SyntaxKind[SyntaxKind["TildeToken"] = 106] = "TildeToken";
SyntaxKind[SyntaxKind["AmpersandAmpersandToken"] = 107] = "AmpersandAmpersandToken";
SyntaxKind[SyntaxKind["BarBarToken"] = 108] = "BarBarToken";
SyntaxKind[SyntaxKind["QuestionToken"] = 109] = "QuestionToken";
SyntaxKind[SyntaxKind["ColonToken"] = 110] = "ColonToken";
SyntaxKind[SyntaxKind["EqualsToken"] = 111] = "EqualsToken";
SyntaxKind[SyntaxKind["PlusEqualsToken"] = 112] = "PlusEqualsToken";
SyntaxKind[SyntaxKind["MinusEqualsToken"] = 113] = "MinusEqualsToken";
SyntaxKind[SyntaxKind["AsteriskEqualsToken"] = 114] = "AsteriskEqualsToken";
SyntaxKind[SyntaxKind["PercentEqualsToken"] = 115] = "PercentEqualsToken";
SyntaxKind[SyntaxKind["LessThanLessThanEqualsToken"] = 116] = "LessThanLessThanEqualsToken";
SyntaxKind[SyntaxKind["GreaterThanGreaterThanEqualsToken"] = 117] = "GreaterThanGreaterThanEqualsToken";
SyntaxKind[SyntaxKind["GreaterThanGreaterThanGreaterThanEqualsToken"] = 118] = "GreaterThanGreaterThanGreaterThanEqualsToken";
SyntaxKind[SyntaxKind["AmpersandEqualsToken"] = 119] = "AmpersandEqualsToken";
SyntaxKind[SyntaxKind["BarEqualsToken"] = 120] = "BarEqualsToken";
SyntaxKind[SyntaxKind["CaretEqualsToken"] = 121] = "CaretEqualsToken";
SyntaxKind[SyntaxKind["SlashToken"] = 122] = "SlashToken";
SyntaxKind[SyntaxKind["SlashEqualsToken"] = 123] = "SlashEqualsToken";
SyntaxKind[SyntaxKind["SourceUnit"] = 124] = "SourceUnit";
SyntaxKind[SyntaxKind["QualifiedName"] = 125] = "QualifiedName";
SyntaxKind[SyntaxKind["ObjectType"] = 126] = "ObjectType";
SyntaxKind[SyntaxKind["FunctionType"] = 127] = "FunctionType";
SyntaxKind[SyntaxKind["ArrayType"] = 128] = "ArrayType";
SyntaxKind[SyntaxKind["ConstructorType"] = 129] = "ConstructorType";
SyntaxKind[SyntaxKind["GenericType"] = 130] = "GenericType";
SyntaxKind[SyntaxKind["TypeQuery"] = 131] = "TypeQuery";
SyntaxKind[SyntaxKind["TupleType"] = 132] = "TupleType";
SyntaxKind[SyntaxKind["UnionType"] = 133] = "UnionType";
SyntaxKind[SyntaxKind["ParenthesizedType"] = 134] = "ParenthesizedType";
SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 135] = "InterfaceDeclaration";
SyntaxKind[SyntaxKind["FunctionDeclaration"] = 136] = "FunctionDeclaration";
SyntaxKind[SyntaxKind["ModuleDeclaration"] = 137] = "ModuleDeclaration";
SyntaxKind[SyntaxKind["ClassDeclaration"] = 138] = "ClassDeclaration";
SyntaxKind[SyntaxKind["EnumDeclaration"] = 139] = "EnumDeclaration";
SyntaxKind[SyntaxKind["ImportDeclaration"] = 140] = "ImportDeclaration";
SyntaxKind[SyntaxKind["ExportAssignment"] = 141] = "ExportAssignment";
SyntaxKind[SyntaxKind["MemberFunctionDeclaration"] = 142] = "MemberFunctionDeclaration";
SyntaxKind[SyntaxKind["MemberVariableDeclaration"] = 143] = "MemberVariableDeclaration";
SyntaxKind[SyntaxKind["ConstructorDeclaration"] = 144] = "ConstructorDeclaration";
SyntaxKind[SyntaxKind["IndexMemberDeclaration"] = 145] = "IndexMemberDeclaration";
SyntaxKind[SyntaxKind["GetAccessor"] = 146] = "GetAccessor";
SyntaxKind[SyntaxKind["SetAccessor"] = 147] = "SetAccessor";
SyntaxKind[SyntaxKind["PropertySignature"] = 148] = "PropertySignature";
SyntaxKind[SyntaxKind["CallSignature"] = 149] = "CallSignature";
SyntaxKind[SyntaxKind["ConstructSignature"] = 150] = "ConstructSignature";
SyntaxKind[SyntaxKind["IndexSignature"] = 151] = "IndexSignature";
SyntaxKind[SyntaxKind["MethodSignature"] = 152] = "MethodSignature";
SyntaxKind[SyntaxKind["Block"] = 153] = "Block";
SyntaxKind[SyntaxKind["IfStatement"] = 154] = "IfStatement";
SyntaxKind[SyntaxKind["VariableStatement"] = 155] = "VariableStatement";
SyntaxKind[SyntaxKind["ExpressionStatement"] = 156] = "ExpressionStatement";
SyntaxKind[SyntaxKind["ReturnStatement"] = 157] = "ReturnStatement";
SyntaxKind[SyntaxKind["SwitchStatement"] = 158] = "SwitchStatement";
SyntaxKind[SyntaxKind["BreakStatement"] = 159] = "BreakStatement";
SyntaxKind[SyntaxKind["ContinueStatement"] = 160] = "ContinueStatement";
SyntaxKind[SyntaxKind["ForStatement"] = 161] = "ForStatement";
SyntaxKind[SyntaxKind["ForInStatement"] = 162] = "ForInStatement";
SyntaxKind[SyntaxKind["EmptyStatement"] = 163] = "EmptyStatement";
SyntaxKind[SyntaxKind["ThrowStatement"] = 164] = "ThrowStatement";
SyntaxKind[SyntaxKind["WhileStatement"] = 165] = "WhileStatement";
SyntaxKind[SyntaxKind["TryStatement"] = 166] = "TryStatement";
SyntaxKind[SyntaxKind["LabeledStatement"] = 167] = "LabeledStatement";
SyntaxKind[SyntaxKind["DoStatement"] = 168] = "DoStatement";
SyntaxKind[SyntaxKind["DebuggerStatement"] = 169] = "DebuggerStatement";
SyntaxKind[SyntaxKind["WithStatement"] = 170] = "WithStatement";
SyntaxKind[SyntaxKind["PrefixUnaryExpression"] = 171] = "PrefixUnaryExpression";
SyntaxKind[SyntaxKind["DeleteExpression"] = 172] = "DeleteExpression";
SyntaxKind[SyntaxKind["TypeOfExpression"] = 173] = "TypeOfExpression";
SyntaxKind[SyntaxKind["VoidExpression"] = 174] = "VoidExpression";
SyntaxKind[SyntaxKind["ConditionalExpression"] = 175] = "ConditionalExpression";
SyntaxKind[SyntaxKind["BinaryExpression"] = 176] = "BinaryExpression";
SyntaxKind[SyntaxKind["PostfixUnaryExpression"] = 177] = "PostfixUnaryExpression";
SyntaxKind[SyntaxKind["MemberAccessExpression"] = 178] = "MemberAccessExpression";
SyntaxKind[SyntaxKind["InvocationExpression"] = 179] = "InvocationExpression";
SyntaxKind[SyntaxKind["ArrayLiteralExpression"] = 180] = "ArrayLiteralExpression";
SyntaxKind[SyntaxKind["ObjectLiteralExpression"] = 181] = "ObjectLiteralExpression";
SyntaxKind[SyntaxKind["ObjectCreationExpression"] = 182] = "ObjectCreationExpression";
SyntaxKind[SyntaxKind["ParenthesizedExpression"] = 183] = "ParenthesizedExpression";
SyntaxKind[SyntaxKind["ParenthesizedArrowFunctionExpression"] = 184] = "ParenthesizedArrowFunctionExpression";
SyntaxKind[SyntaxKind["SimpleArrowFunctionExpression"] = 185] = "SimpleArrowFunctionExpression";
SyntaxKind[SyntaxKind["CastExpression"] = 186] = "CastExpression";
SyntaxKind[SyntaxKind["ElementAccessExpression"] = 187] = "ElementAccessExpression";
SyntaxKind[SyntaxKind["FunctionExpression"] = 188] = "FunctionExpression";
SyntaxKind[SyntaxKind["OmittedExpression"] = 189] = "OmittedExpression";
SyntaxKind[SyntaxKind["TemplateExpression"] = 190] = "TemplateExpression";
SyntaxKind[SyntaxKind["TemplateAccessExpression"] = 191] = "TemplateAccessExpression";
SyntaxKind[SyntaxKind["YieldExpression"] = 192] = "YieldExpression";
SyntaxKind[SyntaxKind["AwaitExpression"] = 193] = "AwaitExpression";
SyntaxKind[SyntaxKind["VariableDeclaration"] = 194] = "VariableDeclaration";
SyntaxKind[SyntaxKind["VariableDeclarator"] = 195] = "VariableDeclarator";
SyntaxKind[SyntaxKind["ArgumentList"] = 196] = "ArgumentList";
SyntaxKind[SyntaxKind["ParameterList"] = 197] = "ParameterList";
SyntaxKind[SyntaxKind["TypeArgumentList"] = 198] = "TypeArgumentList";
SyntaxKind[SyntaxKind["TypeParameterList"] = 199] = "TypeParameterList";
SyntaxKind[SyntaxKind["HeritageClause"] = 200] = "HeritageClause";
SyntaxKind[SyntaxKind["EqualsValueClause"] = 201] = "EqualsValueClause";
SyntaxKind[SyntaxKind["CaseSwitchClause"] = 202] = "CaseSwitchClause";
SyntaxKind[SyntaxKind["DefaultSwitchClause"] = 203] = "DefaultSwitchClause";
SyntaxKind[SyntaxKind["ElseClause"] = 204] = "ElseClause";
SyntaxKind[SyntaxKind["CatchClause"] = 205] = "CatchClause";
SyntaxKind[SyntaxKind["FinallyClause"] = 206] = "FinallyClause";
SyntaxKind[SyntaxKind["TemplateClause"] = 207] = "TemplateClause";
SyntaxKind[SyntaxKind["TypeParameter"] = 208] = "TypeParameter";
SyntaxKind[SyntaxKind["Constraint"] = 209] = "Constraint";
SyntaxKind[SyntaxKind["SimplePropertyAssignment"] = 210] = "SimplePropertyAssignment";
SyntaxKind[SyntaxKind["FunctionPropertyAssignment"] = 211] = "FunctionPropertyAssignment";
SyntaxKind[SyntaxKind["Parameter"] = 212] = "Parameter";
SyntaxKind[SyntaxKind["EnumElement"] = 213] = "EnumElement";
SyntaxKind[SyntaxKind["TypeAnnotation"] = 214] = "TypeAnnotation";
SyntaxKind[SyntaxKind["ExpressionBody"] = 215] = "ExpressionBody";
SyntaxKind[SyntaxKind["ComputedPropertyName"] = 216] = "ComputedPropertyName";
SyntaxKind[SyntaxKind["ExternalModuleReference"] = 217] = "ExternalModuleReference";
SyntaxKind[SyntaxKind["ModuleNameModuleReference"] = 218] = "ModuleNameModuleReference";
SyntaxKind[SyntaxKind["FirstStandardKeyword"] = SyntaxKind.BreakKeyword] = "FirstStandardKeyword";
SyntaxKind[SyntaxKind["LastStandardKeyword"] = SyntaxKind.WithKeyword] = "LastStandardKeyword";
SyntaxKind[SyntaxKind["FirstFutureReservedKeyword"] = SyntaxKind.ClassKeyword] = "FirstFutureReservedKeyword";
@ -654,16 +657,18 @@ var TypeScript;
(function (SyntaxFacts) {
var textToKeywordKind = {
"any": 62 /* AnyKeyword */,
"boolean": 63 /* BooleanKeyword */,
"async": 63 /* AsyncKeyword */,
"await": 64 /* AwaitKeyword */,
"boolean": 65 /* BooleanKeyword */,
"break": 17 /* BreakKeyword */,
"case": 18 /* CaseKeyword */,
"catch": 19 /* CatchKeyword */,
"class": 46 /* ClassKeyword */,
"continue": 20 /* ContinueKeyword */,
"const": 47 /* ConstKeyword */,
"constructor": 64 /* ConstructorKeyword */,
"constructor": 66 /* ConstructorKeyword */,
"debugger": 21 /* DebuggerKeyword */,
"declare": 65 /* DeclareKeyword */,
"declare": 67 /* DeclareKeyword */,
"default": 22 /* DefaultKeyword */,
"delete": 23 /* DeleteKeyword */,
"do": 24 /* DoKeyword */,
@ -675,7 +680,7 @@ var TypeScript;
"finally": 27 /* FinallyKeyword */,
"for": 28 /* ForKeyword */,
"function": 29 /* FunctionKeyword */,
"get": 66 /* GetKeyword */,
"get": 68 /* GetKeyword */,
"if": 30 /* IfKeyword */,
"implements": 53 /* ImplementsKeyword */,
"import": 51 /* ImportKeyword */,
@ -683,19 +688,19 @@ var TypeScript;
"instanceof": 32 /* InstanceOfKeyword */,
"interface": 54 /* InterfaceKeyword */,
"let": 55 /* LetKeyword */,
"module": 67 /* ModuleKeyword */,
"module": 69 /* ModuleKeyword */,
"new": 33 /* NewKeyword */,
"null": 34 /* NullKeyword */,
"number": 69 /* NumberKeyword */,
"number": 71 /* NumberKeyword */,
"package": 56 /* PackageKeyword */,
"private": 57 /* PrivateKeyword */,
"protected": 58 /* ProtectedKeyword */,
"public": 59 /* PublicKeyword */,
"require": 68 /* RequireKeyword */,
"require": 70 /* RequireKeyword */,
"return": 35 /* ReturnKeyword */,
"set": 70 /* SetKeyword */,
"set": 72 /* SetKeyword */,
"static": 60 /* StaticKeyword */,
"string": 71 /* StringKeyword */,
"string": 73 /* StringKeyword */,
"super": 52 /* SuperKeyword */,
"switch": 36 /* SwitchKeyword */,
"this": 37 /* ThisKeyword */,
@ -708,56 +713,56 @@ var TypeScript;
"while": 44 /* WhileKeyword */,
"with": 45 /* WithKeyword */,
"yield": 61 /* YieldKeyword */,
"{": 72 /* OpenBraceToken */,
"}": 73 /* CloseBraceToken */,
"(": 74 /* OpenParenToken */,
")": 75 /* CloseParenToken */,
"[": 76 /* OpenBracketToken */,
"]": 77 /* CloseBracketToken */,
".": 78 /* DotToken */,
"...": 79 /* DotDotDotToken */,
";": 80 /* SemicolonToken */,
",": 81 /* CommaToken */,
"<": 82 /* LessThanToken */,
">": 83 /* GreaterThanToken */,
"<=": 84 /* LessThanEqualsToken */,
">=": 85 /* GreaterThanEqualsToken */,
"==": 86 /* EqualsEqualsToken */,
"=>": 87 /* EqualsGreaterThanToken */,
"!=": 88 /* ExclamationEqualsToken */,
"===": 89 /* EqualsEqualsEqualsToken */,
"!==": 90 /* ExclamationEqualsEqualsToken */,
"+": 91 /* PlusToken */,
"-": 92 /* MinusToken */,
"*": 93 /* AsteriskToken */,
"%": 94 /* PercentToken */,
"++": 95 /* PlusPlusToken */,
"--": 96 /* MinusMinusToken */,
"<<": 97 /* LessThanLessThanToken */,
">>": 98 /* GreaterThanGreaterThanToken */,
">>>": 99 /* GreaterThanGreaterThanGreaterThanToken */,
"&": 100 /* AmpersandToken */,
"|": 101 /* BarToken */,
"^": 102 /* CaretToken */,
"!": 103 /* ExclamationToken */,
"~": 104 /* TildeToken */,
"&&": 105 /* AmpersandAmpersandToken */,
"||": 106 /* BarBarToken */,
"?": 107 /* QuestionToken */,
":": 108 /* ColonToken */,
"=": 109 /* EqualsToken */,
"+=": 110 /* PlusEqualsToken */,
"-=": 111 /* MinusEqualsToken */,
"*=": 112 /* AsteriskEqualsToken */,
"%=": 113 /* PercentEqualsToken */,
"<<=": 114 /* LessThanLessThanEqualsToken */,
">>=": 115 /* GreaterThanGreaterThanEqualsToken */,
">>>=": 116 /* GreaterThanGreaterThanGreaterThanEqualsToken */,
"&=": 117 /* AmpersandEqualsToken */,
"|=": 118 /* BarEqualsToken */,
"^=": 119 /* CaretEqualsToken */,
"/": 120 /* SlashToken */,
"/=": 121 /* SlashEqualsToken */
"{": 74 /* OpenBraceToken */,
"}": 75 /* CloseBraceToken */,
"(": 76 /* OpenParenToken */,
")": 77 /* CloseParenToken */,
"[": 78 /* OpenBracketToken */,
"]": 79 /* CloseBracketToken */,
".": 80 /* DotToken */,
"...": 81 /* DotDotDotToken */,
";": 82 /* SemicolonToken */,
",": 83 /* CommaToken */,
"<": 84 /* LessThanToken */,
">": 85 /* GreaterThanToken */,
"<=": 86 /* LessThanEqualsToken */,
">=": 87 /* GreaterThanEqualsToken */,
"==": 88 /* EqualsEqualsToken */,
"=>": 89 /* EqualsGreaterThanToken */,
"!=": 90 /* ExclamationEqualsToken */,
"===": 91 /* EqualsEqualsEqualsToken */,
"!==": 92 /* ExclamationEqualsEqualsToken */,
"+": 93 /* PlusToken */,
"-": 94 /* MinusToken */,
"*": 95 /* AsteriskToken */,
"%": 96 /* PercentToken */,
"++": 97 /* PlusPlusToken */,
"--": 98 /* MinusMinusToken */,
"<<": 99 /* LessThanLessThanToken */,
">>": 100 /* GreaterThanGreaterThanToken */,
">>>": 101 /* GreaterThanGreaterThanGreaterThanToken */,
"&": 102 /* AmpersandToken */,
"|": 103 /* BarToken */,
"^": 104 /* CaretToken */,
"!": 105 /* ExclamationToken */,
"~": 106 /* TildeToken */,
"&&": 107 /* AmpersandAmpersandToken */,
"||": 108 /* BarBarToken */,
"?": 109 /* QuestionToken */,
":": 110 /* ColonToken */,
"=": 111 /* EqualsToken */,
"+=": 112 /* PlusEqualsToken */,
"-=": 113 /* MinusEqualsToken */,
"*=": 114 /* AsteriskEqualsToken */,
"%=": 115 /* PercentEqualsToken */,
"<<=": 116 /* LessThanLessThanEqualsToken */,
">>=": 117 /* GreaterThanGreaterThanEqualsToken */,
">>>=": 118 /* GreaterThanGreaterThanGreaterThanEqualsToken */,
"&=": 119 /* AmpersandEqualsToken */,
"|=": 120 /* BarEqualsToken */,
"^=": 121 /* CaretEqualsToken */,
"/": 122 /* SlashToken */,
"/=": 123 /* SlashEqualsToken */
};
var kindToText = new Array();
for (var name in textToKeywordKind) {
@ -765,7 +770,7 @@ var TypeScript;
kindToText[textToKeywordKind[name]] = name;
}
}
kindToText[64 /* ConstructorKeyword */] = "constructor";
kindToText[66 /* ConstructorKeyword */] = "constructor";
function getTokenKind(text) {
if (textToKeywordKind.hasOwnProperty(text)) {
return textToKeywordKind[text];
@ -788,12 +793,12 @@ var TypeScript;
SyntaxFacts.isAnyPunctuation = isAnyPunctuation;
function isPrefixUnaryExpressionOperatorToken(tokenKind) {
switch (tokenKind) {
case 91 /* PlusToken */:
case 92 /* MinusToken */:
case 104 /* TildeToken */:
case 103 /* ExclamationToken */:
case 95 /* PlusPlusToken */:
case 96 /* MinusMinusToken */:
case 93 /* PlusToken */:
case 94 /* MinusToken */:
case 106 /* TildeToken */:
case 105 /* ExclamationToken */:
case 97 /* PlusPlusToken */:
case 98 /* MinusMinusToken */:
return true;
default:
return false;
@ -802,42 +807,42 @@ var TypeScript;
SyntaxFacts.isPrefixUnaryExpressionOperatorToken = isPrefixUnaryExpressionOperatorToken;
function isBinaryExpressionOperatorToken(tokenKind) {
switch (tokenKind) {
case 93 /* AsteriskToken */:
case 120 /* SlashToken */:
case 94 /* PercentToken */:
case 91 /* PlusToken */:
case 92 /* MinusToken */:
case 97 /* LessThanLessThanToken */:
case 98 /* GreaterThanGreaterThanToken */:
case 99 /* GreaterThanGreaterThanGreaterThanToken */:
case 82 /* LessThanToken */:
case 83 /* GreaterThanToken */:
case 84 /* LessThanEqualsToken */:
case 85 /* GreaterThanEqualsToken */:
case 95 /* AsteriskToken */:
case 122 /* SlashToken */:
case 96 /* PercentToken */:
case 93 /* PlusToken */:
case 94 /* MinusToken */:
case 99 /* LessThanLessThanToken */:
case 100 /* GreaterThanGreaterThanToken */:
case 101 /* GreaterThanGreaterThanGreaterThanToken */:
case 84 /* LessThanToken */:
case 85 /* GreaterThanToken */:
case 86 /* LessThanEqualsToken */:
case 87 /* GreaterThanEqualsToken */:
case 32 /* InstanceOfKeyword */:
case 31 /* InKeyword */:
case 86 /* EqualsEqualsToken */:
case 88 /* ExclamationEqualsToken */:
case 89 /* EqualsEqualsEqualsToken */:
case 90 /* ExclamationEqualsEqualsToken */:
case 100 /* AmpersandToken */:
case 102 /* CaretToken */:
case 101 /* BarToken */:
case 105 /* AmpersandAmpersandToken */:
case 106 /* BarBarToken */:
case 118 /* BarEqualsToken */:
case 117 /* AmpersandEqualsToken */:
case 119 /* CaretEqualsToken */:
case 114 /* LessThanLessThanEqualsToken */:
case 115 /* GreaterThanGreaterThanEqualsToken */:
case 116 /* GreaterThanGreaterThanGreaterThanEqualsToken */:
case 110 /* PlusEqualsToken */:
case 111 /* MinusEqualsToken */:
case 112 /* AsteriskEqualsToken */:
case 121 /* SlashEqualsToken */:
case 113 /* PercentEqualsToken */:
case 109 /* EqualsToken */:
case 81 /* CommaToken */:
case 88 /* EqualsEqualsToken */:
case 90 /* ExclamationEqualsToken */:
case 91 /* EqualsEqualsEqualsToken */:
case 92 /* ExclamationEqualsEqualsToken */:
case 102 /* AmpersandToken */:
case 104 /* CaretToken */:
case 103 /* BarToken */:
case 107 /* AmpersandAmpersandToken */:
case 108 /* BarBarToken */:
case 120 /* BarEqualsToken */:
case 119 /* AmpersandEqualsToken */:
case 121 /* CaretEqualsToken */:
case 116 /* LessThanLessThanEqualsToken */:
case 117 /* GreaterThanGreaterThanEqualsToken */:
case 118 /* GreaterThanGreaterThanGreaterThanEqualsToken */:
case 112 /* PlusEqualsToken */:
case 113 /* MinusEqualsToken */:
case 114 /* AsteriskEqualsToken */:
case 123 /* SlashEqualsToken */:
case 115 /* PercentEqualsToken */:
case 111 /* EqualsToken */:
case 83 /* CommaToken */:
return true;
default:
return false;
@ -846,18 +851,18 @@ var TypeScript;
SyntaxFacts.isBinaryExpressionOperatorToken = isBinaryExpressionOperatorToken;
function isAssignmentOperatorToken(tokenKind) {
switch (tokenKind) {
case 118 /* BarEqualsToken */:
case 117 /* AmpersandEqualsToken */:
case 119 /* CaretEqualsToken */:
case 114 /* LessThanLessThanEqualsToken */:
case 115 /* GreaterThanGreaterThanEqualsToken */:
case 116 /* GreaterThanGreaterThanGreaterThanEqualsToken */:
case 110 /* PlusEqualsToken */:
case 111 /* MinusEqualsToken */:
case 112 /* AsteriskEqualsToken */:
case 121 /* SlashEqualsToken */:
case 113 /* PercentEqualsToken */:
case 109 /* EqualsToken */:
case 120 /* BarEqualsToken */:
case 119 /* AmpersandEqualsToken */:
case 121 /* CaretEqualsToken */:
case 116 /* LessThanLessThanEqualsToken */:
case 117 /* GreaterThanGreaterThanEqualsToken */:
case 118 /* GreaterThanGreaterThanGreaterThanEqualsToken */:
case 112 /* PlusEqualsToken */:
case 113 /* MinusEqualsToken */:
case 114 /* AsteriskEqualsToken */:
case 123 /* SlashEqualsToken */:
case 115 /* PercentEqualsToken */:
case 111 /* EqualsToken */:
return true;
default:
return false;
@ -866,18 +871,18 @@ var TypeScript;
SyntaxFacts.isAssignmentOperatorToken = isAssignmentOperatorToken;
function isType(kind) {
switch (kind) {
case 126 /* ArrayType */:
case 128 /* ArrayType */:
case 62 /* AnyKeyword */:
case 69 /* NumberKeyword */:
case 63 /* BooleanKeyword */:
case 71 /* StringKeyword */:
case 71 /* NumberKeyword */:
case 65 /* BooleanKeyword */:
case 73 /* StringKeyword */:
case 43 /* VoidKeyword */:
case 125 /* FunctionType */:
case 124 /* ObjectType */:
case 127 /* ConstructorType */:
case 129 /* TypeQuery */:
case 128 /* GenericType */:
case 123 /* QualifiedName */:
case 127 /* FunctionType */:
case 126 /* ObjectType */:
case 129 /* ConstructorType */:
case 131 /* TypeQuery */:
case 130 /* GenericType */:
case 125 /* QualifiedName */:
case 9 /* IdentifierName */:
return true;
}
@ -1103,6 +1108,7 @@ var definitions = [
baseType: 'ISyntaxNode',
interfaces: ['IUnaryExpressionSyntax'],
children: [
{ name: 'asyncKeyword', isToken: true, isOptional: true },
{ name: 'parameter', type: 'ParameterSyntax' },
{ name: 'equalsGreaterThanToken', isToken: true, excludeFromAST: true },
{ name: 'body', type: 'BlockSyntax | IExpressionSyntax' }
@ -1114,6 +1120,7 @@ var definitions = [
baseType: 'ISyntaxNode',
interfaces: ['IUnaryExpressionSyntax'],
children: [
{ name: 'asyncKeyword', isToken: true, isOptional: true },
{ name: 'callSignature', type: 'CallSignatureSyntax' },
{ name: 'equalsGreaterThanToken', isToken: true, excludeFromAST: true },
{ name: 'body', type: 'BlockSyntax | IExpressionSyntax' }
@ -1770,6 +1777,7 @@ var definitions = [
baseType: 'ISyntaxNode',
interfaces: ['IPropertyAssignmentSyntax'],
children: [
{ name: 'asyncKeyword', isToken: true, isOptional: true },
{ name: 'asterixToken', isToken: true, isOptional: true },
{ name: 'propertyName', type: 'IPropertyNameSyntax' },
{ name: 'callSignature', type: 'CallSignatureSyntax' },
@ -1781,6 +1789,7 @@ var definitions = [
baseType: 'ISyntaxNode',
interfaces: ['IPrimaryExpressionSyntax'],
children: [
{ name: 'asyncKeyword', isToken: true, isOptional: true },
{ name: 'functionKeyword', isToken: true, excludeFromAST: true },
{ name: 'asterixToken', isToken: true, isOptional: true },
{ name: 'identifier', isToken: true, isOptional: true },
@ -1888,6 +1897,15 @@ var definitions = [
{ name: 'expression', type: 'IExpressionSyntax', isOptional: true }
]
},
{
name: 'AwaitExpressionSyntax',
baseType: 'ISyntaxNode',
interfaces: ['IUnaryExpressionSyntax'],
children: [
{ name: 'awaitKeyword', isToken: true },
{ name: 'expression', type: 'IExpressionSyntax', isOptional: true }
]
},
{
name: 'DebuggerStatementSyntax',
baseType: 'ISyntaxNode',
@ -2160,7 +2178,11 @@ function max(array, func) {
}
function generateUtilities() {
var result = "";
result += " var fixedWidthArray = [";
return result;
}
function generateScannerUtilities() {
var result = "///<reference path='references.ts' />\r\n" + "\r\n" + "module TypeScript {\r\n" + " export module ScannerUtilities {\r\n";
result += " export var fixedWidthArray = [";
for (var i = 0; i <= TypeScript.SyntaxKind.LastFixedWidth; i++) {
if (i) {
result += ", ";
@ -2173,13 +2195,6 @@ function generateUtilities() {
}
}
result += "];\r\n";
result += " function fixedWidthTokenLength(kind: SyntaxKind) {\r\n";
result += " return fixedWidthArray[kind];\r\n";
result += " }\r\n";
return result;
}
function generateScannerUtilities() {
var result = "///<reference path='references.ts' />\r\n" + "\r\n" + "module TypeScript {\r\n" + " export module ScannerUtilities {\r\n";
var i;
var keywords = [];
for (i = TypeScript.SyntaxKind.FirstKeyword; i <= TypeScript.SyntaxKind.LastKeyword; i++) {

File diff suppressed because one or more lines are too long

View file

@ -6,19 +6,21 @@ module TypeScript {
DisallowIn = 1 << 1,
Yield = 1 << 2,
GeneratorParameter = 1 << 3,
Async = 1 << 4,
Mask = 0xF
Mask = 0x1F
}
export enum SyntaxNodeConstants {
None = 0,
// The first four bit of the flags are used to store parser context flags.
// The width of the node is stored in the remainder of the int. This allows us up to 128MB
// for a node by using all 27 bits. However, in the common case, we'll use less than 27 bits
// for the width. Thus, the info will be stored in a single int in chakra.
DataComputed = 1 << 4, // 0000 0000 0000 0000 0000 0000 0001 0000
IncrementallyUnusableMask = 1 << 5, // 0000 0000 0000 0000 0000 0000 0010 0000
FullWidthShift = 1 << 6, // 1111 1111 1111 1111 1111 1111 1100 0000
// The first five bit of the flags are used to store parser context flags. The next bit
// marks if we've computed the transitive data for the node. The next bit marks if the node
// is incrementally unusable.
//
// The width of the node is stored in the remainder of the number.
DataComputed = 1 << 5, // 0000 0000 0000 0000 0000 0000 0010 0000
IncrementallyUnusableMask = 1 << 6, // 0000 0000 0000 0000 0000 0000 0100 0000
FullWidthShift = 1 << 7, // 1111 1111 1111 1111 1111 1111 1000 0000
}
}

View file

@ -208,6 +208,127 @@ module TypeScript.Parser {
var _skippedTokens: ISyntaxToken[] = undefined;
function setContextFlag(val: boolean, flag: ParserContextFlags) {
if (val) {
contextFlags |= flag;
}
else {
contextFlags &= ~flag;
}
}
function setStrictModeContext(val: boolean) {
setContextFlag(val, ParserContextFlags.StrictMode);
}
function setDisallowInContext(val: boolean) {
setContextFlag(val, ParserContextFlags.DisallowIn);
}
function setYieldContext(val: boolean) {
setContextFlag(val, ParserContextFlags.Yield);
}
function setGeneratorParameterContext(val: boolean) {
setContextFlag(val, ParserContextFlags.GeneratorParameter);
}
function setAsyncContext(val: boolean) {
setContextFlag(val, ParserContextFlags.Async);
}
function inStrictModeContext() {
return (contextFlags & ParserContextFlags.StrictMode) !== 0;
}
function inDisallowInContext() {
return (contextFlags & ParserContextFlags.DisallowIn) !== 0;
}
function inYieldContext() {
return (contextFlags & ParserContextFlags.Yield) !== 0;
}
function inGeneratorParameterContext() {
return (contextFlags & ParserContextFlags.GeneratorParameter) !== 0;
}
function inAsyncContext() {
return (contextFlags & ParserContextFlags.Async) !== 0;
}
function allowInAnd<T>(func: () => T): T {
if (inDisallowInContext()) {
setDisallowInContext(false);
var result = func();
setDisallowInContext(true);
return result;
}
// no need to do anything special if 'in' is already allowed.
return func();
}
function disallowInAnd<T>(func: () => T): T {
if (inDisallowInContext()) {
// no need to do anything special if 'in' is already disallowed.
return func();
}
setDisallowInContext(true);
var result = func();
setDisallowInContext(false);
return result;
}
function enterYieldContextAnd<T>(func: () => T): T {
if (inYieldContext()) {
// no need to do anything special if we're already in the [Yield] context.
return func();
}
setYieldContext(true);
var result = func();
setYieldContext(false);
return result;
}
function exitYieldContextAnd<T>(func: () => T): T {
if (inYieldContext()) {
setYieldContext(false);
var result = func();
setYieldContext(true);
return result;
}
// no need to do anything special if we're not in the [Yield] context.
return func();
}
function enterAsyncContextAnd<T>(func: () => T): T {
if (inAsyncContext()) {
// no need to do anything special if we're already in the [Async] context.
return func();
}
setAsyncContext(true);
var result = func();
setAsyncContext(false);
return result;
}
function exitAsyncContextAnd<T>(func: () => T): T {
if (inAsyncContext()) {
setAsyncContext(false);
var result = func();
setAsyncContext(true);
return result;
}
// no need to do anything special if we're not in the [Async] context.
return func();
}
function parseSyntaxTree(_source: IParserSource, isDeclaration: boolean): SyntaxTree {
// First, set up our state.
fileName = _source.fileName;
@ -418,6 +539,12 @@ module TypeScript.Parser {
return false;
}
// If we have an 'await' keyword, and we're in the [async] context, then 'await' is
// considered a keyword and is not an identifier.
if (tokenKind === SyntaxKind.AwaitKeyword && inAsyncContext()) {
return false;
}
// Keywords are only identifiers if they're FutureReservedStrictWords and we're in
// strict mode. *Or* if it's a typescript 'keyword'.
if (tokenKind >= SyntaxKind.FirstFutureReservedStrictKeyword) {
@ -626,47 +753,6 @@ module TypeScript.Parser {
throw Errors.invalidOperation();
}
function setContextFlag(val: boolean, flag: ParserContextFlags) {
if (val) {
contextFlags |= flag;
}
else {
contextFlags &= ~flag;
}
}
function setStrictModeContext(val: boolean) {
setContextFlag(val, ParserContextFlags.StrictMode);
}
function setDisallowInContext(val: boolean) {
setContextFlag(val, ParserContextFlags.DisallowIn);
}
function setYieldContext(val: boolean) {
setContextFlag(val, ParserContextFlags.Yield);
}
function setGeneratorParameterContext(val: boolean) {
setContextFlag(val, ParserContextFlags.GeneratorParameter);
}
function inStrictModeContext() {
return (contextFlags & ParserContextFlags.StrictMode) !== 0;
}
function inDisallowInContext() {
return (contextFlags & ParserContextFlags.DisallowIn) !== 0;
}
function inYieldContext() {
return (contextFlags & ParserContextFlags.Yield) !== 0;
}
function inGeneratorParameterContext() {
return (contextFlags & ParserContextFlags.GeneratorParameter) !== 0;
}
function parseSourceUnit(): SourceUnitSyntax {
// Note: saving and restoring the 'isInStrictMode' state is not really necessary here
// (as it will never be read afterwards). However, for symmetry with the rest of the
@ -976,54 +1062,6 @@ module TypeScript.Parser {
return isPropertyName(/*peekToken:*/ 0, inErrorRecovery);
}
function allowInAnd<T>(func: () => T): T {
if (inDisallowInContext()) {
setDisallowInContext(false);
var result = func();
setDisallowInContext(true);
return result;
}
// no need to do anything special if 'in' is already allowed.
return func();
}
function disallowInAnd<T>(func: () => T): T {
if (inDisallowInContext()) {
// no need to do anything special if 'in' is already disallowed.
return func();
}
setDisallowInContext(true);
var result = func();
setDisallowInContext(false);
return result;
}
function enterYieldContextAnd<T>(func: () => T): T {
if (inYieldContext()) {
// no need to do anything special if we're already in the [Yield] context.
return func();
}
setYieldContext(true);
var result = func();
setYieldContext(false);
return result;
}
function exitYieldContextAnd<T>(func: () => T): T {
if (inYieldContext()) {
setYieldContext(false);
var result = func();
setYieldContext(true);
return result;
}
// no need to do anything special if we're not in the [Yield] context.
return func();
}
function tryParseEnumElementEqualsValueClause(): EqualsValueClauseSyntax {
return isEqualsValueClause(/*inParameter*/ false) ? allowInAnd(parseEqualsValueClause) : undefined;
@ -1051,6 +1089,7 @@ module TypeScript.Parser {
case SyntaxKind.ProtectedKeyword:
case SyntaxKind.StaticKeyword:
case SyntaxKind.DeclareKeyword:
case SyntaxKind.AsyncKeyword:
return true;
}
@ -1059,23 +1098,39 @@ module TypeScript.Parser {
function isModifier(token: ISyntaxToken, index: number): boolean {
if (isModifierKind(token.kind)) {
// These are modifiers only if we see an actual keyword, identifier, string literal
// or number following.
//
// [ is for: static [a: number] ...
// [ is for: static [computedProp()] ...
// Because modifiers are also identifiers, we only want to consider something to
// be truly a modifier if the thing following it is something that can be modified.
var nextToken = peekToken(index + 1);
var nextTokenKind = nextToken.kind;
switch (nextTokenKind) {
// public foo'
// 'public' is a modifier.
case SyntaxKind.IdentifierName:
// public [a: number]: string
// 'public' is a modifier here.
case SyntaxKind.OpenBracketToken:
// public 0
// 'public' is def a modifier here.
case SyntaxKind.NumericLiteral:
// public "0"
// 'public' is def a modifier here.
case SyntaxKind.StringLiteral:
// public `0`
// 'public' is def a modifier here.
case SyntaxKind.NoSubstitutionTemplateToken:
// public * foo
// 'public' is def a modifier here.
case SyntaxKind.AsteriskToken:
return true;
default:
// public static or public class
// 'public' is def a modifier here.
return SyntaxFacts.isAnyKeyword(nextTokenKind);
}
}
@ -1190,15 +1245,15 @@ module TypeScript.Parser {
function parseGetAccessor(modifiers: ISyntaxToken[], getKeyword: ISyntaxToken): GetAccessorSyntax {
return new GetAccessorSyntax(contextFlags,
modifiers, consumeToken(getKeyword), parsePropertyName(),
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false),
parseFunctionBody(/*isGenerator:*/ false));
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false),
parseFunctionBody(/*isGenerator:*/ false, /*asyncContext:*/ false));
}
function parseSetAccessor(modifiers: ISyntaxToken[], setKeyword: ISyntaxToken): SetAccessorSyntax {
return new SetAccessorSyntax(contextFlags,
modifiers, consumeToken(setKeyword), parsePropertyName(),
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false),
parseFunctionBody(/*isGenerator:*/ false));
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false),
parseFunctionBody(/*isGenerator:*/ false, /*asyncContext:*/ false));
}
function isClassElement(inErrorRecovery: boolean): boolean {
@ -1326,21 +1381,32 @@ module TypeScript.Parser {
return new ConstructorDeclarationSyntax(contextFlags,
parseModifiers(),
eatToken(SyntaxKind.ConstructorKeyword),
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false),
parseFunctionBody(/*isGenerator:*/ false));
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false),
parseFunctionBody(/*isGenerator:*/ false, /*asyncContext:*/ false));
}
function parseMemberFunctionDeclaration(modifiers: ISyntaxToken[], asteriskToken: ISyntaxToken, propertyName: IPropertyNameSyntax): MemberFunctionDeclarationSyntax {
// Note: if we see an arrow after the close paren, then try to parse out a function
// block anyways. It's likely the user just though '=> expr' was legal anywhere a
// block was legal.
var asyncContext = containsAsync(modifiers);
var isGenerator = asteriskToken !== undefined;
return new MemberFunctionDeclarationSyntax(contextFlags,
modifiers,
asteriskToken,
propertyName,
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ isGenerator),
parseFunctionBody(isGenerator));
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ isGenerator, /*asyncContext:*/ asyncContext),
parseFunctionBody(isGenerator, asyncContext));
}
function containsAsync(modifiers: ISyntaxToken[]): boolean {
for (var i = 0, n = modifiers.length; i < n; i++) {
if (modifiers[i].kind === SyntaxKind.AsyncKeyword) {
return true;
}
}
return false;
}
function parseMemberVariableDeclaration(modifiers: ISyntaxToken[], propertyName: IPropertyNameSyntax): MemberVariableDeclarationSyntax {
@ -1371,23 +1437,25 @@ module TypeScript.Parser {
}
function parseFunctionDeclarationWorker(modifiers: ISyntaxToken[], functionKeyword: ISyntaxToken, asteriskToken: ISyntaxToken): FunctionDeclarationSyntax {
// FunctionDeclaration[Yield, Default] : // function BindingIdentifier[?Yield] ( FormalParameters ) { FunctionBody }
// FunctionDeclaration[Yield, Default] :
// function BindingIdentifier[?Yield] ( FormalParameters ) { FunctionBody }
// GeneratorDeclaration[Yield, Default] :
// function * BindingIdentifier[?Yield](FormalParameters[Yield, GeneratorParameter]) { GeneratorBody[Yield] }
var asyncContext = containsAsync(modifiers);
var isGenerator = asteriskToken !== undefined;
return new FunctionDeclarationSyntax(contextFlags,
modifiers,
functionKeyword,
asteriskToken,
eatIdentifierToken(),
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ isGenerator),
parseFunctionBody(isGenerator));
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ isGenerator, /*asyncContext:*/ asyncContext),
parseFunctionBody(isGenerator, asyncContext));
}
function parseFunctionBody(isGenerator: boolean): BlockSyntax | ExpressionBody | ISyntaxToken {
function parseFunctionBody(isGenerator: boolean, asyncContext: boolean): BlockSyntax | ExpressionBody | ISyntaxToken {
return isBlockOrArrow()
? parseFunctionBlockOrExpressionBody(/*yieldContext:*/ isGenerator)
? parseFunctionBlockOrExpressionBody(/*yieldContext:*/ isGenerator, /*asyncContext:*/ asyncContext)
: eatExplicitOrAutomaticSemicolon(/*allowWithoutNewline:*/ false);
}
@ -1485,7 +1553,7 @@ module TypeScript.Parser {
// A call signature for a type member can both use 'yield' as a parameter name, and
// does not have parameter initializers. So we can pass 'false' for both [Yield]
// and [GeneratorParameter].
return parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false);
return parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false);
}
else if (isConstructSignature()) {
return parseConstructSignature();
@ -1513,7 +1581,7 @@ module TypeScript.Parser {
// Construct signatures have no [Yield] or [GeneratorParameter] restrictions.
return new ConstructSignatureSyntax(contextFlags,
eatToken(SyntaxKind.NewKeyword),
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false));
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false));
}
function parseIndexSignature(): IndexSignatureSyntax {
@ -1529,7 +1597,7 @@ module TypeScript.Parser {
return new MethodSignatureSyntax(contextFlags,
propertyName,
questionToken,
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false));
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false));
}
function parsePropertySignature(propertyName: IPropertyNameSyntax, questionToken: ISyntaxToken): PropertySignatureSyntax {
@ -2196,10 +2264,22 @@ module TypeScript.Parser {
return true;
case SyntaxKind.YieldKeyword:
// Yield always starts an expression. Either it is an identifier (in which case
// 'yield' 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 in strict mode (or both)) and it started a yield expression.
return true;
case SyntaxKind.AwaitKeyword:
// 'await' always starts an expression. Either it is an identifier (in which case
// it is definitely an expression). Or it's a keyword and it started an await
// expression.
return true;
case SyntaxKind.AsyncKeyword:
// 'async' always starts an expression. Either it is an identifier (in which case
// it is definitely an expression). Or it's a keyword and it started an async
// function/arrow expression.
return true;
}
return isIdentifier(currentToken);
@ -2449,6 +2529,40 @@ module TypeScript.Parser {
return parseConditionalExpressionRest(leftOperand);
}
function parsePossibleAwaitExpression(awaitKeyword: ISyntaxToken): IUnaryExpressionSyntax {
if (inAsyncContext()) {
// If we're in an async context, then 'await' definitely starts an await expression.
return parseAwaitExpression(awaitKeyword);
}
// We're in a context where 'await expr' is not allowed. However, if we can
// definitely tell that the user was trying to parse a 'await expr' and not
// just a normal expr that start with a 'await' identifier, then parse out
// an 'await expr'. We can then report an error later that they are only
// allowed in async contexts.
//
// for example, if we see 'await(foo)', then we'll have to treat that as an
// invocation expression of something called 'await'. However, if we have
// 'await foo' then that is not legal as a normal expression, so we can
// definitely recognize this as a await 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.
if (isUnambiguouslyYieldOrAwaitExpression()) {
return parseAwaitExpression(awaitKeyword);
}
// Not an 'await' expression. Parse this with our normal postfix parsing rules.
return tryParsePostfixExpressionOrHigher(awaitKeyword, /*force:*/ true);
}
function parseAwaitExpression(awaitKeyword: ISyntaxToken): AwaitExpressionSyntax {
return new AwaitExpressionSyntax(contextFlags,
consumeToken(awaitKeyword),
parseAssignmentExpressionOrHigher());
}
function isYieldExpression(_currentToken: ISyntaxToken): boolean {
if (_currentToken.kind === SyntaxKind.YieldKeyword) {
// If we have a 'yield' keyword, and htis is a context where yield expressions are
@ -2463,29 +2577,69 @@ module TypeScript.Parser {
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.
var token1 = peekToken(1);
if (!isOnDifferentLineThanPreviousToken(token1) && isIdentifier(token1)) {
return true;
}
return isUnambiguouslyYieldOrAwaitExpression();
}
return false;
}
function isUnambiguouslyYieldOrAwaitExpression() {
// We're in a context where 'yield expr' or 'await expr' is not allowed. However, if
// we can definitely tell that the user was trying to parse one of these then parse it
// out and report an error later in the grammar checker.
//
// 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.
var token1 = peekToken(1);
if (isOnDifferentLineThanPreviousToken(token1)) {
// Next token is on the next line. Thanks to ASI, this might start some other
// construct. Can't assume this is a yield or await expr.
return false;
}
// 'await a' or 'yield a'. Definitely a yield/await expression. C
if (isIdentifier(token1)) {
return true;
}
var currentTokenKind = token1.kind;
switch (currentTokenKind) {
case SyntaxKind.ThisKeyword:
case SyntaxKind.TrueKeyword:
case SyntaxKind.FalseKeyword:
case SyntaxKind.NullKeyword:
case SyntaxKind.NumericLiteral:
case SyntaxKind.StringLiteral:
case SyntaxKind.FunctionKeyword:
case SyntaxKind.OpenBraceToken:
case SyntaxKind.NewKeyword:
return true
case SyntaxKind.NoSubstitutionTemplateToken:
case SyntaxKind.TemplateStartToken:
// yield `foo`
// This is a tagged template expressoin.
return false;
case SyntaxKind.SlashToken:
case SyntaxKind.SlashEqualsToken:
// yield / foo
// This is a divide expression.
return false;
case SyntaxKind.OpenBracketToken:
// yield[foo]
// This is a indexed access expression.
return false;
case SyntaxKind.OpenParenToken:
// yield(foo)
// This is an invocation expression.
return false;
default:
return false;
}
}
function parseYieldExpression(yieldKeyword: ISyntaxToken): YieldExpressionSyntax {
// YieldExpression[In] :
// yield
@ -2524,10 +2678,16 @@ module TypeScript.Parser {
case SyntaxKind.PlusPlusToken:
case SyntaxKind.MinusMinusToken:
return new PrefixUnaryExpressionSyntax(contextFlags, consumeToken(_currentToken), tryParseUnaryExpressionOrHigher(currentToken(), /*force:*/ true));
case SyntaxKind.TypeOfKeyword: return parseTypeOfExpression(_currentToken);
case SyntaxKind.VoidKeyword: return parseVoidExpression(_currentToken);
case SyntaxKind.DeleteKeyword: return parseDeleteExpression(_currentToken);
case SyntaxKind.LessThanToken: return parseCastExpression(_currentToken);
case SyntaxKind.TypeOfKeyword:
return parseTypeOfExpression(_currentToken);
case SyntaxKind.VoidKeyword:
return parseVoidExpression(_currentToken);
case SyntaxKind.DeleteKeyword:
return parseDeleteExpression(_currentToken);
case SyntaxKind.LessThanToken:
return parseCastExpression(_currentToken);
case SyntaxKind.AwaitKeyword:
return parsePossibleAwaitExpression(_currentToken);
default:
return tryParsePostfixExpressionOrHigher(_currentToken, force);
}
@ -2933,6 +3093,12 @@ module TypeScript.Parser {
}
function tryParsePrimaryExpression(_currentToken: ISyntaxToken, force: boolean): IPrimaryExpressionSyntax {
// Have to check for 'async function' first as 'async' is an identifier and will be
// consumed immediately below this.
if (_currentToken.kind === SyntaxKind.AsyncKeyword && peekToken(1).kind === SyntaxKind.FunctionKeyword) {
return parseFunctionExpression();
}
if (isIdentifier(_currentToken)) {
return eatIdentifierToken();
}
@ -2947,17 +3113,19 @@ module TypeScript.Parser {
case SyntaxKind.RegularExpressionLiteral:
case SyntaxKind.StringLiteral:
return consumeToken(_currentToken);
case SyntaxKind.FunctionKeyword: return parseFunctionExpression(_currentToken);
case SyntaxKind.OpenBracketToken: return parseArrayLiteralExpression(_currentToken);
case SyntaxKind.OpenBraceToken: return parseObjectLiteralExpression(_currentToken);
case SyntaxKind.OpenParenToken: return parseParenthesizedExpression(_currentToken);
case SyntaxKind.NewKeyword: return parseObjectCreationExpression(_currentToken);
case SyntaxKind.FunctionKeyword:
return parseFunctionExpression();
case SyntaxKind.OpenBracketToken:
return parseArrayLiteralExpression(_currentToken);
case SyntaxKind.OpenBraceToken:
return parseObjectLiteralExpression(_currentToken);
case SyntaxKind.OpenParenToken:
return parseParenthesizedExpression(_currentToken);
case SyntaxKind.NewKeyword:
return parseObjectCreationExpression(_currentToken);
case SyntaxKind.NoSubstitutionTemplateToken:
case SyntaxKind.TemplateStartToken:
return parseTemplateExpression(_currentToken);
case SyntaxKind.SlashToken:
case SyntaxKind.SlashEqualsToken:
// If we see a standalone / or /= and we're expecting an expression, then reparse
@ -3007,23 +3175,36 @@ module TypeScript.Parser {
return new VoidExpressionSyntax(contextFlags, consumeToken(voidKeyword), tryParseUnaryExpressionOrHigher(currentToken(), /*force:*/ true));
}
function parseFunctionExpression(functionKeyword: ISyntaxToken): FunctionExpressionSyntax {
return parseFunctionExpressionWorker(consumeToken(functionKeyword), tryEatToken(SyntaxKind.AsteriskToken));
}
function parseFunctionExpressionWorker(functionKeyword: ISyntaxToken, asteriskToken: ISyntaxToken) {
function parseFunctionExpression(): FunctionExpressionSyntax {
// GeneratorExpression :
// function * BindingIdentifier[Yield]opt (FormalParameters[Yield, GeneratorParameter]) { GeneratorBody[Yield] }
// FunctionExpression:
// function BindingIdentifieropt(FormalParameters) { FunctionBody }
var isGenerator = asteriskToken !== undefined;
var asyncKeyword: ISyntaxToken;
var asteriskToken: ISyntaxToken;
return new FunctionExpressionSyntax(contextFlags,
functionKeyword,
asteriskToken,
asteriskToken ? enterYieldContextAnd(eatOptionalIdentifierToken) : eatOptionalIdentifierToken(),
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ isGenerator),
parseFunctionBody(isGenerator));
asyncKeyword = tryEatToken(SyntaxKind.AsyncKeyword),
eatToken(SyntaxKind.FunctionKeyword),
asteriskToken = tryEatToken(SyntaxKind.AsteriskToken),
tryEatFunctionExpressionIdentifier(!!asteriskToken, !!asyncKeyword),
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ !!asteriskToken, /*asyncContext:*/ !!asyncKeyword),
parseFunctionBody(!!asteriskToken, !!asyncKeyword));
}
function tryEatFunctionExpressionIdentifier(yieldContext: boolean, asyncContext: boolean) {
var savedYieldContext = inYieldContext();
var savedAsyncContext = inAsyncContext();
setYieldContext(yieldContext);
setAsyncContext(asyncContext);
var result = eatOptionalIdentifierToken();
setYieldContext(savedYieldContext);
setAsyncContext(savedAsyncContext);
return result;
}
function parseObjectCreationExpression(newKeyword: ISyntaxToken): ObjectCreationExpressionSyntax {
@ -3096,7 +3277,7 @@ module TypeScript.Parser {
function tryParseParenthesizedArrowFunctionExpression(): ParenthesizedArrowFunctionExpressionSyntax {
var tokenKind = currentToken().kind;
if (tokenKind !== SyntaxKind.OpenParenToken && tokenKind !== SyntaxKind.LessThanToken) {
if (tokenKind !== SyntaxKind.AsyncKeyword && tokenKind !== SyntaxKind.OpenParenToken && tokenKind !== SyntaxKind.LessThanToken) {
return undefined;
}
@ -3134,8 +3315,7 @@ module TypeScript.Parser {
}
function tryParseParenthesizedArrowFunctionExpressionWorker(requireArrow: boolean): ParenthesizedArrowFunctionExpressionSyntax {
var _currentToken = currentToken();
// Debug.assert(currentToken.kind === SyntaxKind.OpenParenToken || currentToken.kind === SyntaxKind.LessThanToken);
var asyncKeyword = tryEatToken(SyntaxKind.AsyncKeyword);
// From the static semantic section:
// 1.If the [Yield] grammar parameter is present for CoverParenthesizedExpressionAndArrowParameterList[Yield]
@ -3144,25 +3324,27 @@ module TypeScript.Parser {
// 2.If the [Yield] grammar parameter is not present for CoverParenthesizedExpressionAndArrowParameterList[Yield]
// return the result of parsing the lexical token stream matched by CoverParenthesizedExpressionAndArrowParameterList
// using ArrowFormalParameters as the goal symbol.
var callSignature = parseCallSignature(/*requireCompleteTypeParameterList:*/ true, /*yieldAndGeneratorParameterContext:*/ inYieldContext());
var callSignature = parseCallSignature(/*requireCompleteTypeParameterList:*/ true, /*yieldAndGeneratorParameterContext:*/ inYieldContext(), /*asyncContext:*/ !!asyncKeyword);
if (requireArrow && currentToken().kind !== SyntaxKind.EqualsGreaterThanToken) {
return undefined;
}
return new ParenthesizedArrowFunctionExpressionSyntax(contextFlags,
asyncKeyword,
callSignature,
eatToken(SyntaxKind.EqualsGreaterThanToken),
parseArrowFunctionBody());
parseArrowFunctionBody(!!asyncKeyword));
}
function parseArrowFunctionBody(): BlockSyntax | IExpressionSyntax {
function parseArrowFunctionBody(asyncContext: boolean): BlockSyntax | IExpressionSyntax {
// ConciseBody[In] :
// [lookahead not in {] AssignmentExpression[?In]
// { FunctionBody }
if (currentToken().kind === SyntaxKind.OpenBraceToken) {
return parseFunctionBlock(/*allowYield:*/ false, /*equalsGreaterThanToken:*/ undefined);
// arrow functions are never generators, so their bodies are never in the yield context.
return parseFunctionBlock(/*yieldContext:*/ false, /*asyncContext:*/ asyncContext, /*equalsGreaterThanToken:*/ undefined);
}
// We didn't have a block. However, we may be in an error situation. For example,
@ -3184,11 +3366,11 @@ module TypeScript.Parser {
return new BlockSyntax(contextFlags,
/*equalsGreaterThanToken*/ undefined,
eatToken(SyntaxKind.OpenBraceToken),
parseFunctionBlockStatements(),
parseFunctionBlockStatements(/*yieldContext:*/ false, asyncContext),
eatToken(SyntaxKind.CloseBraceToken));
}
return parseAssignmentExpressionOrHigher();
return asyncContext ? enterAsyncContextAnd(parseAssignmentExpressionOrHigher) : exitAsyncContextAnd(parseAssignmentExpressionOrHigher);
}
function isSimpleArrowFunctionExpression(_currentToken: ISyntaxToken): boolean {
@ -3199,16 +3381,22 @@ module TypeScript.Parser {
return true;
}
// 'async a' is always the start of an async arrow function.
if (_currentToken.kind === SyntaxKind.AsyncKeyword && isIdentifier(peekToken(1))) {
return true;
}
return isIdentifier(_currentToken) &&
peekToken(1).kind === SyntaxKind.EqualsGreaterThanToken;
}
function parseSimpleArrowFunctionExpression(): SimpleArrowFunctionExpressionSyntax {
// Debug.assert(isSimpleArrowFunctionExpression());
return new SimpleArrowFunctionExpressionSyntax(contextFlags,
eatSimpleParameter(),
var asyncKeyword: ISyntaxToken;
return new SimpleArrowFunctionExpressionSyntax(contextFlags,
asyncKeyword = tryEatToken(SyntaxKind.AsyncKeyword),
asyncKeyword ? enterAsyncContextAnd(eatSimpleParameter) : exitAsyncContextAnd(eatSimpleParameter),
eatToken(SyntaxKind.EqualsGreaterThanToken),
parseArrowFunctionBody());
parseArrowFunctionBody(/*asyncContext:*/ !!asyncKeyword));
}
function isFunctionBlock(): boolean {
@ -3222,14 +3410,20 @@ module TypeScript.Parser {
}
function isDefinitelyArrowFunctionExpression(): boolean {
var token0 = currentToken();
var peekIndex = 0;
if (currentToken().kind === SyntaxKind.AsyncKeyword) {
// skip past any 'async' keyword we see.
peekIndex++;
}
var token0 = peekToken(peekIndex);
if (token0.kind !== SyntaxKind.OpenParenToken) {
// If it didn't start with an (, then it could be generic. That's too complicated
// and we can't say it's 'definitely' an arrow function.
return false;
}
var token1 = peekToken(1);
var token1 = peekToken(peekIndex + 1);
var token1Kind = token1.kind;
var token2: ISyntaxToken;
@ -3242,7 +3436,7 @@ module TypeScript.Parser {
// To prevent this, we are a little stricter, and we require that we at least see:
// "():" or "() =>" or "() {}". Note: the last one is illegal. However it
// most likely is a missing => and not a parenthesized expression.
token2 = peekToken(2);
token2 = peekToken(peekIndex + 2);
var token2Kind = token2.kind;
return token2Kind === SyntaxKind.ColonToken ||
token2Kind === SyntaxKind.EqualsGreaterThanToken ||
@ -3255,7 +3449,7 @@ module TypeScript.Parser {
return true;
}
token2 = peekToken(2);
token2 = peekToken(peekIndex + 2);
token2Kind = token2.kind;
if (SyntaxFacts.isAccessibilityModifier(token1Kind)) {
@ -3284,7 +3478,7 @@ module TypeScript.Parser {
return true;
}
var token3 = peekToken(3);
var token3 = peekToken(peekIndex + 3);
var token3Kind = token3.kind;
if (token2Kind === SyntaxKind.QuestionToken) {
// (id?
@ -3327,14 +3521,19 @@ module TypeScript.Parser {
}
function isPossiblyArrowFunctionExpression(): boolean {
var token0 = currentToken();
var peekIndex = 0;
if (currentToken().kind === SyntaxKind.AsyncKeyword) {
peekIndex++;
}
var token0 = peekToken(peekIndex);
if (token0.kind !== SyntaxKind.OpenParenToken) {
// If it didn't start with an (, then it could be generic. That's too complicated
// and we have to say it's possibly an arrow function.
return true;
}
var token1 = peekToken(1);
var token1 = peekToken(peekIndex + 1);
if (!isIdentifier(token1)) {
// All other arrow functions must start with (id
@ -3342,7 +3541,7 @@ module TypeScript.Parser {
return false;
}
var token2 = peekToken(2);
var token2 = peekToken(peekIndex + 2);
var token2Kind = token2.kind;
if (token2Kind === SyntaxKind.EqualsToken) {
// (id =
@ -3365,7 +3564,7 @@ module TypeScript.Parser {
if (token2Kind === SyntaxKind.CloseParenToken) {
// (id)
var token3 = peekToken(3);
var token3 = peekToken(peekIndex + 3);
if (token3.kind === SyntaxKind.ColonToken) {
// (id):
//
@ -3400,6 +3599,14 @@ module TypeScript.Parser {
// shorthand property assignment.
var _currentToken = currentToken();
if (_currentToken.kind === SyntaxKind.AsyncKeyword) {
// 'async' might start an asynchronous property, or it might just be the name
// of a property.
if (peekToken(1).kind === SyntaxKind.AsteriskToken || isPropertyName(/*peekIndex:*/ 1, inErrorRecovery)) {
return parseFunctionPropertyAssignment(eatToken(SyntaxKind.AsyncKeyword), tryEatToken(SyntaxKind.AsteriskToken), parsePropertyName());
}
}
if (isIdentifier(_currentToken)) {
var token1 = peekToken(1);
if (token1.kind !== SyntaxKind.ColonToken &&
@ -3414,11 +3621,11 @@ module TypeScript.Parser {
//
// then this is a shorthand property assignment. Just return the identifier
// token as is.
return consumeToken(_currentToken);
return eatIdentifierToken();
}
}
// All the rest of the property assignments start with property names or an asterix.
// All the rest of the property assignments start with property names, an asterix.
// They are:
// id: e
// [e1]: e2
@ -3426,12 +3633,14 @@ module TypeScript.Parser {
// [e]() { }
// *id() { }
// *[e]() { }
// async id() { }
// async [e]() { }
if (_currentToken.kind === SyntaxKind.AsteriskToken || isPropertyName(/*peekIndex:*/ 0, inErrorRecovery)) {
var asterixToken = tryEatToken(SyntaxKind.AsteriskToken);
var propertyName = parsePropertyName();
if (asterixToken !== undefined || isCallSignature(/*peekIndex:*/ 0)) {
return parseFunctionPropertyAssignment(asterixToken, propertyName);
return parseFunctionPropertyAssignment(undefined, asterixToken, propertyName);
}
else {
// PropertyName[?Yield] : AssignmentExpression[In, ?Yield]
@ -3533,13 +3742,13 @@ module TypeScript.Parser {
eatToken(SyntaxKind.CloseBracketToken));
}
function parseFunctionPropertyAssignment(asteriskToken: ISyntaxToken, propertyName: IPropertyNameSyntax): FunctionPropertyAssignmentSyntax {
var isGenerator = asteriskToken !== undefined;
function parseFunctionPropertyAssignment(asyncKeyword: ISyntaxToken, asteriskToken: ISyntaxToken, propertyName: IPropertyNameSyntax): FunctionPropertyAssignmentSyntax {
return new FunctionPropertyAssignmentSyntax(contextFlags,
asyncKeyword,
asteriskToken,
propertyName,
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ isGenerator),
parseFunctionBody(isGenerator));
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ !!asteriskToken, !!asyncKeyword),
parseFunctionBody(!!asteriskToken, !!asyncKeyword));
}
function parseArrayLiteralExpression(openBracketToken: ISyntaxToken): ArrayLiteralExpressionSyntax {
@ -3561,7 +3770,7 @@ module TypeScript.Parser {
eatToken(SyntaxKind.CloseBraceToken));
}
function parseFunctionBlockOrExpressionBody(_allowYield: boolean): BlockSyntax | ExpressionBody {
function parseFunctionBlockOrExpressionBody(yieldContext: boolean, asyncContext: boolean): BlockSyntax | ExpressionBody {
// If we got an errant => then we want to parse what's coming up without requiring an
// open brace. We do this because it's not uncommon for people to get confused as to
// where/when they can use an => and we want to have good error recovery here.
@ -3574,32 +3783,39 @@ module TypeScript.Parser {
}
}
return parseFunctionBlock(_allowYield, equalsGreaterThanToken);
return parseFunctionBlock(yieldContext, asyncContext, equalsGreaterThanToken);
}
function parseFunctionBlock(_allowYield: boolean, equalsGreaterThanToken: ISyntaxToken): BlockSyntax {
function parseFunctionBlock(yieldContext: boolean, asyncContext: boolean, equalsGreaterThanToken: ISyntaxToken): BlockSyntax {
var openBraceToken: ISyntaxToken;
return new BlockSyntax(contextFlags,
equalsGreaterThanToken,
openBraceToken = eatToken(SyntaxKind.OpenBraceToken),
equalsGreaterThanToken || openBraceToken.fullWidth() > 0
? _allowYield ? enterYieldContextAnd(parseFunctionBlockStatements) : exitYieldContextAnd(parseFunctionBlockStatements)
: [],
equalsGreaterThanToken || openBraceToken.fullWidth() > 0 ? parseFunctionBlockStatements(yieldContext, asyncContext) : [],
eatToken(SyntaxKind.CloseBraceToken));
}
function parseFunctionBlockStatements() {
var savedIsInStrictMode = inStrictModeContext();
function parseFunctionBlockStatements(yieldContext: boolean, asyncContext: boolean) {
var savedStrictModeContext = inStrictModeContext();
var savedYieldContext = inYieldContext();
var savedAsyncContext = inAsyncContext();
setYieldContext(yieldContext);
setAsyncContext(asyncContext);
var statements = parseSyntaxList<IStatementSyntax>(ListParsingState.Block_Statements, updateStrictModeState);
setStrictModeContext(savedIsInStrictMode);
setStrictModeContext(savedStrictModeContext);
setYieldContext(savedYieldContext);
setAsyncContext(savedAsyncContext);
return statements;
}
function parseCallSignature(requireCompleteTypeParameterList: boolean, yieldAndGeneratorParameterContext: boolean): CallSignatureSyntax {
function parseCallSignature(requireCompleteTypeParameterList: boolean, yieldAndGeneratorParameterContext: boolean, asyncContext: boolean): CallSignatureSyntax {
return new CallSignatureSyntax(contextFlags,
tryParseTypeParameterList(requireCompleteTypeParameterList),
parseParameterList(yieldAndGeneratorParameterContext),
parseParameterList(yieldAndGeneratorParameterContext, asyncContext),
parseOptionalTypeAnnotation(/*allowStringLiteral:*/ false));
}
@ -3653,7 +3869,7 @@ module TypeScript.Parser {
// have 'Yield' And 'GeneratorParameter' not in sync. i.e. any production calling
// this FormalParameters production either always sets both to true, or always sets
// both to false. As such we only have a single parameter to represent both.
function parseParameterList(yieldAndGeneratorParameterContext: boolean): ParameterListSyntax {
function parseParameterList(yieldAndGeneratorParameterContext: boolean, asyncContext: boolean): ParameterListSyntax {
// FormalParameters[Yield,GeneratorParameter] :
// ...
//
@ -3672,9 +3888,11 @@ module TypeScript.Parser {
var savedYieldContext = inYieldContext();
var savedGeneratorParameterContext = inGeneratorParameterContext();
var savedAsyncContext = inAsyncContext();
setYieldContext(yieldAndGeneratorParameterContext);
setGeneratorParameterContext(yieldAndGeneratorParameterContext);
setAsyncContext(asyncContext);
var openParenToken: ISyntaxToken;
var result = new ParameterListSyntax(contextFlags,
@ -3684,6 +3902,7 @@ module TypeScript.Parser {
setYieldContext(savedYieldContext);
setGeneratorParameterContext(savedGeneratorParameterContext);
setAsyncContext(savedAsyncContext);
return result;
}
@ -3941,7 +4160,7 @@ module TypeScript.Parser {
// aren't in the [Yield] or [GeneratorParameter] context.
return new FunctionTypeSyntax(contextFlags,
tryParseTypeParameterList(/*requireCompleteTypeParameterList:*/ false),
parseParameterList(/*yieldAndGeneratorParameterContext:*/ false),
parseParameterList(/*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false),
eatToken(SyntaxKind.EqualsGreaterThanToken), parseType());
}
@ -3951,7 +4170,7 @@ module TypeScript.Parser {
return new ConstructorTypeSyntax(contextFlags,
eatToken(SyntaxKind.NewKeyword),
tryParseTypeParameterList(/*requireCompleteTypeParameterList:*/ false),
parseParameterList(/*yieldAndGeneratorParameterContext:*/ false),
parseParameterList(/*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false),
eatToken(SyntaxKind.EqualsGreaterThanToken), parseType());
}

View file

@ -1027,6 +1027,14 @@ module TypeScript.PrettyPrinter {
public visitYieldExpression(node: YieldExpressionSyntax): void {
this.appendToken(node.yieldKeyword);
this.ensureSpace();
this.appendToken(node.asterixToken);
this.ensureSpace();
visitNodeOrToken(this, node.expression);
}
public visitAwaitExpression(node: AwaitExpressionSyntax): void {
this.appendToken(node.awaitKeyword);
this.ensureSpace();
visitNodeOrToken(this, node.expression);
}

View file

@ -9,9 +9,9 @@
// Scanner depends on SyntaxKind and SyntaxFacts
///<reference path='syntaxKind.ts' />
///<reference path='syntaxFacts.ts' />
///<reference path='scannerUtilities.generated.ts' />
///<reference path='scanner.ts' />
///<reference path='scannerUtilities.generated.ts' />
///<reference path='slidingWindow.ts' />
///<reference path='syntax.ts' />
///<reference path='syntaxElement.ts' />

View file

@ -202,6 +202,7 @@ module TypeScript.Scanner {
public childCount: number;
constructor(private _fullStart: number, public kind: SyntaxKind) {
Debug.assert(!isNaN(_fullStart));
}
public setFullStart(fullStart: number): void {
@ -236,6 +237,7 @@ module TypeScript.Scanner {
private cachedText: string;
constructor(private _fullStart: number, public kind: SyntaxKind, private _packedFullWidthAndInfo: number, cachedText: string) {
Debug.assert(!isNaN(_fullStart));
if (cachedText !== undefined) {
this.cachedText = cachedText;
}
@ -1480,6 +1482,7 @@ module TypeScript.Scanner {
}
function absolutePosition() {
Debug.assert(!isNaN(_absolutePosition));
return _absolutePosition;
}
@ -1551,6 +1554,7 @@ module TypeScript.Scanner {
// We're consuming the token that was just fetched from us by the parser. We just
// need to move ourselves forward and ditch this token from the sliding window.
_absolutePosition += (<ISyntaxToken>nodeOrToken).fullWidth();
Debug.assert(!isNaN(_absolutePosition));
slidingWindow.moveToNextItem();
}
else {
@ -1646,7 +1650,7 @@ module TypeScript.Scanner {
};
}
var fixedWidthArray = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 4, 5, 8, 8, 7, 6, 2, 4, 5, 7, 3, 8, 2, 2, 10, 3, 4, 6, 6, 4, 5, 4, 3, 6, 3, 4, 5, 4, 5, 5, 4, 6, 7, 6, 5, 10, 9, 3, 7, 7, 9, 6, 6, 5, 3, 7, 11, 7, 3, 6, 7, 6, 3, 6, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 1, 1, 1, 1, 2, 2, 2, 2, 3, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 2, 2, 2, 1, 2];
var fixedWidthArray = ScannerUtilities.fixedWidthArray;
function fixedWidthTokenLength(kind: SyntaxKind) {
return fixedWidthArray[kind];
}

View file

@ -2,6 +2,7 @@
module TypeScript {
export module ScannerUtilities {
export var fixedWidthArray = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 4, 5, 8, 8, 7, 6, 2, 4, 5, 7, 3, 8, 2, 2, 10, 3, 4, 6, 6, 4, 5, 4, 3, 6, 3, 4, 5, 4, 5, 5, 4, 6, 7, 6, 5, 10, 9, 3, 7, 7, 9, 6, 6, 5, 3, 5, 5, 7, 11, 7, 3, 6, 7, 6, 3, 6, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 1, 1, 1, 1, 2, 2, 2, 2, 3, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 2, 2, 2, 1, 2];
export function identifierKind(str: string, start: number, length: number): SyntaxKind {
switch (length) {
case 2: // do, if, in
@ -47,8 +48,14 @@ module TypeScript {
case CharacterCodes.w: return (str.charCodeAt(start + 1) === CharacterCodes.i && str.charCodeAt(start + 2) === CharacterCodes.t && str.charCodeAt(start + 3) === CharacterCodes.h) ? SyntaxKind.WithKeyword : SyntaxKind.IdentifierName;
default: return SyntaxKind.IdentifierName;
}
case 5: // break, catch, class, const, false, super, throw, while, yield
case 5: // async, await, break, catch, class, const, false, super, throw, while, yield
switch(str.charCodeAt(start)) {
case CharacterCodes.a: // async, await
switch(str.charCodeAt(start + 1)) {
case CharacterCodes.s: return (str.charCodeAt(start + 2) === CharacterCodes.y && str.charCodeAt(start + 3) === CharacterCodes.n && str.charCodeAt(start + 4) === CharacterCodes.c) ? SyntaxKind.AsyncKeyword : SyntaxKind.IdentifierName;
case CharacterCodes.w: return (str.charCodeAt(start + 2) === CharacterCodes.a && str.charCodeAt(start + 3) === CharacterCodes.i && str.charCodeAt(start + 4) === CharacterCodes.t) ? SyntaxKind.AwaitKeyword : SyntaxKind.IdentifierName;
default: return SyntaxKind.IdentifierName;
}
case CharacterCodes.b: return (str.charCodeAt(start + 1) === CharacterCodes.r && str.charCodeAt(start + 2) === CharacterCodes.e && str.charCodeAt(start + 3) === CharacterCodes.a && str.charCodeAt(start + 4) === CharacterCodes.k) ? SyntaxKind.BreakKeyword : SyntaxKind.IdentifierName;
case CharacterCodes.c: // catch, class, const
switch(str.charCodeAt(start + 1)) {

View file

@ -42,6 +42,10 @@ module TypeScript {
return (parserContextFlags(node) & ParserContextFlags.GeneratorParameter) !== 0;
}
export function parsedInAsyncContext(node: ISyntaxNode): boolean {
return (parserContextFlags(node) & ParserContextFlags.Async) !== 0;
}
export function previousToken(token: ISyntaxToken): ISyntaxToken {
var start = token.fullStart();
if (start === 0) {

View file

@ -3,6 +3,8 @@
module TypeScript.SyntaxFacts {
var textToKeywordKind: any = {
"any": SyntaxKind.AnyKeyword,
"async": SyntaxKind.AsyncKeyword,
"await": SyntaxKind.AwaitKeyword,
"boolean": SyntaxKind.BooleanKeyword,
"break": SyntaxKind.BreakKeyword,
"case": SyntaxKind.CaseKeyword,

View file

@ -246,6 +246,7 @@ var definitions:ITypeDefinition[] = [
baseType: 'ISyntaxNode',
interfaces: ['IUnaryExpressionSyntax'],
children: [
<any>{ name: 'asyncKeyword', isToken: true, isOptional: true },
<any>{ name: 'parameter', type: 'ParameterSyntax' },
<any>{ name: 'equalsGreaterThanToken', isToken: true, excludeFromAST: true },
<any>{ name: 'body', type: 'BlockSyntax | IExpressionSyntax' }
@ -257,6 +258,7 @@ var definitions:ITypeDefinition[] = [
baseType: 'ISyntaxNode',
interfaces: ['IUnaryExpressionSyntax'],
children: [
<any>{ name: 'asyncKeyword', isToken: true, isOptional: true },
<any>{ name: 'callSignature', type: 'CallSignatureSyntax' },
<any>{ name: 'equalsGreaterThanToken', isToken: true, excludeFromAST: true },
<any>{ name: 'body', type: 'BlockSyntax | IExpressionSyntax' }
@ -916,6 +918,7 @@ var definitions:ITypeDefinition[] = [
baseType: 'ISyntaxNode',
interfaces: ['IPropertyAssignmentSyntax'],
children: [
<any>{ name: 'asyncKeyword', isToken: true, isOptional: true },
<any>{ name: 'asterixToken', isToken: true, isOptional: true },
<any>{ name: 'propertyName', type: 'IPropertyNameSyntax' },
<any>{ name: 'callSignature', type: 'CallSignatureSyntax' },
@ -927,6 +930,7 @@ var definitions:ITypeDefinition[] = [
baseType: 'ISyntaxNode',
interfaces: ['IPrimaryExpressionSyntax'],
children: [
<any>{ name: 'asyncKeyword', isToken: true, isOptional: true },
<any>{ name: 'functionKeyword', isToken: true, excludeFromAST: true },
<any>{ name: 'asterixToken', isToken: true, isOptional: true },
<any>{ name: 'identifier', isToken: true, isOptional: true },
@ -1023,6 +1027,14 @@ var definitions:ITypeDefinition[] = [
<any>{ name: 'asterixToken', isToken: true, isOptional: true },
<any>{ name: 'expression', type: 'IExpressionSyntax', isOptional: true }]
},
<any>{
name: 'AwaitExpressionSyntax',
baseType: 'ISyntaxNode',
interfaces: ['IUnaryExpressionSyntax'],
children: [
<any>{ name: 'awaitKeyword', isToken: true },
<any>{ name: 'expression', type: 'IExpressionSyntax', isOptional: true }]
},
<any>{
name: 'DebuggerStatementSyntax',
baseType: 'ISyntaxNode',
@ -1392,8 +1404,29 @@ function max<T>(array: T[], func: (v: T) => number): number {
}
function generateUtilities(): string {
var result = "";
result += " var fixedWidthArray = [";
var result = ""; //"module TypeScript.Scanner {";
//result += " function fixedWidthTokenLength(kind: SyntaxKind) {\r\n";
//result += " return fixedWidthArray[kind];\r\n";
//result += " switch (kind) {\r\n";
//for (var k = TypeScript.SyntaxKind.FirstFixedWidth; k <= TypeScript.SyntaxKind.LastFixedWidth; k++) {
// result += " case SyntaxKind." + syntaxKindName(k) + ": return " + TypeScript.SyntaxFacts.getText(k).length + ";\r\n";
//}
//result += " default: throw new Error();\r\n";
//result += " }\r\n";
// result += " }\r\n";
return result;
}
function generateScannerUtilities(): string {
var result = "///<reference path='references.ts' />\r\n" +
"\r\n" +
"module TypeScript {\r\n" +
" export module ScannerUtilities {\r\n";
result += " export var fixedWidthArray = [";
for (var i = 0; i <= TypeScript.SyntaxKind.LastFixedWidth; i++) {
if (i) {
result += ", ";
@ -1408,26 +1441,6 @@ function generateUtilities(): string {
}
result += "];\r\n";
result += " function fixedWidthTokenLength(kind: SyntaxKind) {\r\n";
result += " return fixedWidthArray[kind];\r\n";
//result += " switch (kind) {\r\n";
//for (var k = TypeScript.SyntaxKind.FirstFixedWidth; k <= TypeScript.SyntaxKind.LastFixedWidth; k++) {
// result += " case SyntaxKind." + syntaxKindName(k) + ": return " + TypeScript.SyntaxFacts.getText(k).length + ";\r\n";
//}
//result += " default: throw new Error();\r\n";
//result += " }\r\n";
result += " }\r\n";
return result;
}
function generateScannerUtilities(): string {
var result = "///<reference path='references.ts' />\r\n" +
"\r\n" +
"module TypeScript {\r\n" +
" export module ScannerUtilities {\r\n";
var i: number;
var keywords: { text: string; kind: TypeScript.SyntaxKind; }[] = [];

View file

@ -470,18 +470,20 @@ module TypeScript {
export interface ParenthesizedExpressionConstructor { new (data: number, openParenToken: ISyntaxToken, expression: IExpressionSyntax, closeParenToken: ISyntaxToken): ParenthesizedExpressionSyntax }
export interface ParenthesizedArrowFunctionExpressionSyntax extends ISyntaxNode, IUnaryExpressionSyntax {
asyncKeyword: ISyntaxToken;
callSignature: CallSignatureSyntax;
equalsGreaterThanToken: ISyntaxToken;
body: BlockSyntax | IExpressionSyntax;
}
export interface ParenthesizedArrowFunctionExpressionConstructor { new (data: number, callSignature: CallSignatureSyntax, equalsGreaterThanToken: ISyntaxToken, body: BlockSyntax | IExpressionSyntax): ParenthesizedArrowFunctionExpressionSyntax }
export interface ParenthesizedArrowFunctionExpressionConstructor { new (data: number, asyncKeyword: ISyntaxToken, callSignature: CallSignatureSyntax, equalsGreaterThanToken: ISyntaxToken, body: BlockSyntax | IExpressionSyntax): ParenthesizedArrowFunctionExpressionSyntax }
export interface SimpleArrowFunctionExpressionSyntax extends ISyntaxNode, IUnaryExpressionSyntax {
asyncKeyword: ISyntaxToken;
parameter: ParameterSyntax;
equalsGreaterThanToken: ISyntaxToken;
body: BlockSyntax | IExpressionSyntax;
}
export interface SimpleArrowFunctionExpressionConstructor { new (data: number, parameter: ParameterSyntax, equalsGreaterThanToken: ISyntaxToken, body: BlockSyntax | IExpressionSyntax): SimpleArrowFunctionExpressionSyntax }
export interface SimpleArrowFunctionExpressionConstructor { new (data: number, asyncKeyword: ISyntaxToken, parameter: ParameterSyntax, equalsGreaterThanToken: ISyntaxToken, body: BlockSyntax | IExpressionSyntax): SimpleArrowFunctionExpressionSyntax }
export interface CastExpressionSyntax extends ISyntaxNode, IUnaryExpressionSyntax {
lessThanToken: ISyntaxToken;
@ -500,13 +502,14 @@ module TypeScript {
export interface ElementAccessExpressionConstructor { new (data: number, expression: ILeftHandSideExpressionSyntax, openBracketToken: ISyntaxToken, argumentExpression: IExpressionSyntax, closeBracketToken: ISyntaxToken): ElementAccessExpressionSyntax }
export interface FunctionExpressionSyntax extends ISyntaxNode, IPrimaryExpressionSyntax {
asyncKeyword: ISyntaxToken;
functionKeyword: ISyntaxToken;
asterixToken: ISyntaxToken;
identifier: ISyntaxToken;
callSignature: CallSignatureSyntax;
body: BlockSyntax | ExpressionBody | ISyntaxToken;
}
export interface FunctionExpressionConstructor { new (data: number, functionKeyword: ISyntaxToken, asterixToken: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, body: BlockSyntax | ExpressionBody | ISyntaxToken): FunctionExpressionSyntax }
export interface FunctionExpressionConstructor { new (data: number, asyncKeyword: ISyntaxToken, functionKeyword: ISyntaxToken, asterixToken: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, body: BlockSyntax | ExpressionBody | ISyntaxToken): FunctionExpressionSyntax }
export interface OmittedExpressionSyntax extends ISyntaxNode, IExpressionSyntax {
}
@ -531,6 +534,12 @@ module TypeScript {
}
export interface YieldExpressionConstructor { new (data: number, yieldKeyword: ISyntaxToken, asterixToken: ISyntaxToken, expression: IExpressionSyntax): YieldExpressionSyntax }
export interface AwaitExpressionSyntax extends ISyntaxNode, IUnaryExpressionSyntax {
awaitKeyword: ISyntaxToken;
expression: IExpressionSyntax;
}
export interface AwaitExpressionConstructor { new (data: number, awaitKeyword: ISyntaxToken, expression: IExpressionSyntax): AwaitExpressionSyntax }
export interface VariableDeclarationSyntax extends ISyntaxNode {
varKeyword: ISyntaxToken;
variableDeclarators: ISeparatedSyntaxList<VariableDeclaratorSyntax>;
@ -648,12 +657,13 @@ module TypeScript {
export interface SimplePropertyAssignmentConstructor { new (data: number, propertyName: IPropertyNameSyntax, colonToken: ISyntaxToken, expression: IExpressionSyntax): SimplePropertyAssignmentSyntax }
export interface FunctionPropertyAssignmentSyntax extends ISyntaxNode, IPropertyAssignmentSyntax {
asyncKeyword: ISyntaxToken;
asterixToken: ISyntaxToken;
propertyName: IPropertyNameSyntax;
callSignature: CallSignatureSyntax;
body: BlockSyntax | ExpressionBody | ISyntaxToken;
}
export interface FunctionPropertyAssignmentConstructor { new (data: number, asterixToken: ISyntaxToken, propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, body: BlockSyntax | ExpressionBody | ISyntaxToken): FunctionPropertyAssignmentSyntax }
export interface FunctionPropertyAssignmentConstructor { new (data: number, asyncKeyword: ISyntaxToken, asterixToken: ISyntaxToken, propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, body: BlockSyntax | ExpressionBody | ISyntaxToken): FunctionPropertyAssignmentSyntax }
export interface ParameterSyntax extends ISyntaxNode {
dotDotDotToken: ISyntaxToken;

View file

@ -87,6 +87,8 @@ module TypeScript {
// TypeScript keywords.
AnyKeyword,
AsyncKeyword,
AwaitKeyword,
BooleanKeyword,
ConstructorKeyword,
DeclareKeyword,
@ -235,6 +237,7 @@ module TypeScript {
TemplateExpression,
TemplateAccessExpression,
YieldExpression,
AwaitExpression,
// Variable declarations
VariableDeclaration,

View file

@ -1282,41 +1282,47 @@ module TypeScript {
}
}
export var ParenthesizedArrowFunctionExpressionSyntax: ParenthesizedArrowFunctionExpressionConstructor = <any>function(data: number, callSignature: CallSignatureSyntax, equalsGreaterThanToken: ISyntaxToken, body: BlockSyntax | IExpressionSyntax) {
export var ParenthesizedArrowFunctionExpressionSyntax: ParenthesizedArrowFunctionExpressionConstructor = <any>function(data: number, asyncKeyword: ISyntaxToken, callSignature: CallSignatureSyntax, equalsGreaterThanToken: ISyntaxToken, body: BlockSyntax | IExpressionSyntax) {
if (data) { this.__data = data; }
this.asyncKeyword = asyncKeyword,
this.callSignature = callSignature,
this.equalsGreaterThanToken = equalsGreaterThanToken,
this.body = body,
asyncKeyword && (asyncKeyword.parent = this),
callSignature.parent = this,
equalsGreaterThanToken.parent = this,
body.parent = this;
};
ParenthesizedArrowFunctionExpressionSyntax.prototype.kind = SyntaxKind.ParenthesizedArrowFunctionExpression;
ParenthesizedArrowFunctionExpressionSyntax.prototype.childCount = 3;
ParenthesizedArrowFunctionExpressionSyntax.prototype.childCount = 4;
ParenthesizedArrowFunctionExpressionSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.callSignature;
case 1: return this.equalsGreaterThanToken;
case 2: return this.body;
case 0: return this.asyncKeyword;
case 1: return this.callSignature;
case 2: return this.equalsGreaterThanToken;
case 3: return this.body;
}
}
export var SimpleArrowFunctionExpressionSyntax: SimpleArrowFunctionExpressionConstructor = <any>function(data: number, parameter: ParameterSyntax, equalsGreaterThanToken: ISyntaxToken, body: BlockSyntax | IExpressionSyntax) {
export var SimpleArrowFunctionExpressionSyntax: SimpleArrowFunctionExpressionConstructor = <any>function(data: number, asyncKeyword: ISyntaxToken, parameter: ParameterSyntax, equalsGreaterThanToken: ISyntaxToken, body: BlockSyntax | IExpressionSyntax) {
if (data) { this.__data = data; }
this.asyncKeyword = asyncKeyword,
this.parameter = parameter,
this.equalsGreaterThanToken = equalsGreaterThanToken,
this.body = body,
asyncKeyword && (asyncKeyword.parent = this),
parameter.parent = this,
equalsGreaterThanToken.parent = this,
body.parent = this;
};
SimpleArrowFunctionExpressionSyntax.prototype.kind = SyntaxKind.SimpleArrowFunctionExpression;
SimpleArrowFunctionExpressionSyntax.prototype.childCount = 3;
SimpleArrowFunctionExpressionSyntax.prototype.childCount = 4;
SimpleArrowFunctionExpressionSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.parameter;
case 1: return this.equalsGreaterThanToken;
case 2: return this.body;
case 0: return this.asyncKeyword;
case 1: return this.parameter;
case 2: return this.equalsGreaterThanToken;
case 3: return this.body;
}
}
@ -1364,13 +1370,15 @@ module TypeScript {
}
}
export var FunctionExpressionSyntax: FunctionExpressionConstructor = <any>function(data: number, functionKeyword: ISyntaxToken, asterixToken: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, body: BlockSyntax | ExpressionBody | ISyntaxToken) {
export var FunctionExpressionSyntax: FunctionExpressionConstructor = <any>function(data: number, asyncKeyword: ISyntaxToken, functionKeyword: ISyntaxToken, asterixToken: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, body: BlockSyntax | ExpressionBody | ISyntaxToken) {
if (data) { this.__data = data; }
this.asyncKeyword = asyncKeyword,
this.functionKeyword = functionKeyword,
this.asterixToken = asterixToken,
this.identifier = identifier,
this.callSignature = callSignature,
this.body = body,
asyncKeyword && (asyncKeyword.parent = this),
functionKeyword.parent = this,
asterixToken && (asterixToken.parent = this),
identifier && (identifier.parent = this),
@ -1378,14 +1386,15 @@ module TypeScript {
body && (body.parent = this);
};
FunctionExpressionSyntax.prototype.kind = SyntaxKind.FunctionExpression;
FunctionExpressionSyntax.prototype.childCount = 5;
FunctionExpressionSyntax.prototype.childCount = 6;
FunctionExpressionSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.functionKeyword;
case 1: return this.asterixToken;
case 2: return this.identifier;
case 3: return this.callSignature;
case 4: return this.body;
case 0: return this.asyncKeyword;
case 1: return this.functionKeyword;
case 2: return this.asterixToken;
case 3: return this.identifier;
case 4: return this.callSignature;
case 5: return this.body;
}
}
@ -1449,6 +1458,22 @@ module TypeScript {
}
}
export var AwaitExpressionSyntax: AwaitExpressionConstructor = <any>function(data: number, awaitKeyword: ISyntaxToken, expression: IExpressionSyntax) {
if (data) { this.__data = data; }
this.awaitKeyword = awaitKeyword,
this.expression = expression,
awaitKeyword.parent = this,
expression && (expression.parent = this);
};
AwaitExpressionSyntax.prototype.kind = SyntaxKind.AwaitExpression;
AwaitExpressionSyntax.prototype.childCount = 2;
AwaitExpressionSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.awaitKeyword;
case 1: return this.expression;
}
}
export var VariableDeclarationSyntax: VariableDeclarationConstructor = <any>function(data: number, varKeyword: ISyntaxToken, variableDeclarators: ISeparatedSyntaxList<VariableDeclaratorSyntax>) {
if (data) { this.__data = data; }
this.varKeyword = varKeyword,
@ -1763,25 +1788,28 @@ module TypeScript {
}
}
export var FunctionPropertyAssignmentSyntax: FunctionPropertyAssignmentConstructor = <any>function(data: number, asterixToken: ISyntaxToken, propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, body: BlockSyntax | ExpressionBody | ISyntaxToken) {
export var FunctionPropertyAssignmentSyntax: FunctionPropertyAssignmentConstructor = <any>function(data: number, asyncKeyword: ISyntaxToken, asterixToken: ISyntaxToken, propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, body: BlockSyntax | ExpressionBody | ISyntaxToken) {
if (data) { this.__data = data; }
this.asyncKeyword = asyncKeyword,
this.asterixToken = asterixToken,
this.propertyName = propertyName,
this.callSignature = callSignature,
this.body = body,
asyncKeyword && (asyncKeyword.parent = this),
asterixToken && (asterixToken.parent = this),
propertyName.parent = this,
callSignature.parent = this,
body && (body.parent = this);
};
FunctionPropertyAssignmentSyntax.prototype.kind = SyntaxKind.FunctionPropertyAssignment;
FunctionPropertyAssignmentSyntax.prototype.childCount = 4;
FunctionPropertyAssignmentSyntax.prototype.childCount = 5;
FunctionPropertyAssignmentSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.asterixToken;
case 1: return this.propertyName;
case 2: return this.callSignature;
case 3: return this.body;
case 0: return this.asyncKeyword;
case 1: return this.asterixToken;
case 2: return this.propertyName;
case 3: return this.callSignature;
case 4: return this.body;
}
}

View file

@ -301,6 +301,7 @@ module TypeScript.Syntax {
public childCount: number;
constructor(public kind: SyntaxKind, private _fullStart: number) {
Debug.assert(!isNaN(_fullStart));
}
public setFullStart(fullStart: number): void {
@ -339,7 +340,6 @@ module TypeScript.Syntax {
class RealizedToken implements ISyntaxToken {
public _primaryExpressionBrand: any; public _memberExpressionBrand: any; public _leftHandSideExpressionBrand: any; public _postfixExpressionBrand: any; public _unaryExpressionBrand: any; public _expressionBrand: any; public _typeBrand: any; public _nameBrand: any; public _propertyAssignmentBrand: any; public _propertyNameBrand: any;
private _fullStart: number;
private _isKeywordConvertedToIdentifier: boolean;
private _leadingTrivia: ISyntaxTriviaList;
private _text: string;
@ -347,12 +347,12 @@ module TypeScript.Syntax {
public parent: ISyntaxElement;
public childCount: number;
constructor(fullStart: number,
constructor(private _fullStart: number,
public kind: SyntaxKind,
isKeywordConvertedToIdentifier: boolean,
leadingTrivia: ISyntaxTriviaList,
text: string) {
this._fullStart = fullStart;
Debug.assert(!isNaN(_fullStart));
this._isKeywordConvertedToIdentifier = isKeywordConvertedToIdentifier;
this._text = text;

View file

@ -137,13 +137,14 @@ module TypeScript {
this.text = syntaxTree.text;
}
private pushDiagnostic(element: ISyntaxElement, diagnosticKey: string, args?: any[]): void {
this.pushDiagnosticAt(start(element, this.text), width(element), diagnosticKey, args);
private pushDiagnostic(element: ISyntaxElement, diagnosticKey: string, args?: any[]): boolean {
return this.pushDiagnosticAt(start(element, this.text), width(element), diagnosticKey, args);
}
private pushDiagnosticAt(start: number, length: number, diagnosticKey: string, args?: any[]): void {
private pushDiagnosticAt(start: number, length: number, diagnosticKey: string, args?: any[]): boolean {
this.diagnostics.push(new Diagnostic(
this.syntaxTree.fileName(), this.syntaxTree.lineMap(), start, length, diagnosticKey, args));
return true;
}
public visitCatchClause(node: CatchClauseSyntax): void {
@ -206,26 +207,14 @@ module TypeScript {
return false;
}
private checkParameterListAcessibilityModifiers(node: ParameterListSyntax): boolean {
for (var i = 0, n = nonSeparatorCount(node.parameters); i < n; i++) {
var parameter = nonSeparatorAt(node.parameters, i);
if (this.checkParameterAccessibilityModifiers(node, parameter)) {
return true;
}
}
return false;
}
private checkParameterAccessibilityModifiers(parameterList: ParameterListSyntax, parameter: ParameterSyntax): boolean {
private checkParameterAccessibilityModifiers(parameter: ParameterSyntax): boolean {
if (parameter.modifiers.length > 0) {
var modifiers = parameter.modifiers;
for (var i = 0, n = modifiers.length; i < n; i++) {
var modifier = modifiers[i];
if (this.checkParameterAccessibilityModifier(parameterList, modifier, i)) {
if (this.checkParameterAccessibilityModifier(modifier, i)) {
return true;
}
}
@ -234,7 +223,7 @@ module TypeScript {
return false;
}
private checkParameterAccessibilityModifier(parameterList: ParameterListSyntax, modifier: ISyntaxToken, modifierIndex: number): boolean {
private checkParameterAccessibilityModifier(modifier: ISyntaxToken, modifierIndex: number): boolean {
if (!SyntaxFacts.isAccessibilityModifier(modifier.kind)) {
this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_cannot_appear_on_a_parameter, [modifier.text()]);
return true;
@ -272,8 +261,7 @@ module TypeScript {
}
public visitParameterList(node: ParameterListSyntax): void {
if (this.checkParameterListAcessibilityModifiers(node) ||
this.checkParameterListOrder(node) ||
if (this.checkParameterListOrder(node) ||
this.checkForTrailingComma(node.parameters)) {
return;
@ -348,7 +336,7 @@ module TypeScript {
return true;
}
else if (parameter.modifiers.length > 0) {
this.pushDiagnostic(parameter, DiagnosticCode.Index_signature_parameter_cannot_have_accessibility_modifiers);
this.pushDiagnostic(parameter, DiagnosticCode.Index_signature_parameter_cannot_have_modifiers);
return true;
}
else if (parameter.questionToken) {
@ -454,7 +442,8 @@ module TypeScript {
if (this.checkForDisallowedDeclareModifier(node.modifiers) ||
this.checkForRequiredDeclareModifier(node, node.identifier, node.modifiers) ||
this.checkModuleElementModifiers(node.modifiers) ||
this.checkClassDeclarationHeritageClauses(node)) {
this.checkClassDeclarationHeritageClauses(node) ||
this.checkForDisallowedAsyncModifier(node.modifiers)) {
return;
}
@ -506,7 +495,8 @@ module TypeScript {
public visitInterfaceDeclaration(node: InterfaceDeclarationSyntax): void {
if (this.checkInterfaceModifiers(node.modifiers) ||
this.checkModuleElementModifiers(node.modifiers) ||
this.checkInterfaceDeclarationHeritageClauses(node)) {
this.checkInterfaceDeclarationHeritageClauses(node) ||
this.checkForDisallowedAsyncModifier(node.modifiers)) {
return;
}
@ -517,34 +507,45 @@ module TypeScript {
private checkClassElementModifiers(list: ISyntaxToken[]): boolean {
var seenAccessibilityModifier = false;
var seenStaticModifier = false;
var seenAsyncModifier = false;
for (var i = 0, n = list.length; i < n; i++) {
var modifier = list[i];
if (SyntaxFacts.isAccessibilityModifier(modifier.kind)) {
if (seenAccessibilityModifier) {
this.pushDiagnostic(modifier, DiagnosticCode.Accessibility_modifier_already_seen);
return true;
return this.pushDiagnostic(modifier, DiagnosticCode.Accessibility_modifier_already_seen);
}
if (seenStaticModifier) {
var previousToken = list[i - 1];
this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_must_precede_1_modifier, [modifier.text(), previousToken.text()]);
return true;
return this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_must_precede_1_modifier, [modifier.text(), list[i - 1].text()]);
}
if (seenAsyncModifier) {
return this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_must_precede_1_modifier, [modifier.text(), SyntaxFacts.getText(SyntaxKind.AsyncKeyword)]);
}
seenAccessibilityModifier = true;
}
else if (modifier.kind === SyntaxKind.StaticKeyword) {
if (seenStaticModifier) {
this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_already_seen, [modifier.text()]);
return true;
return this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_already_seen, [modifier.text()]);
}
if (seenAsyncModifier) {
return this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_must_precede_1_modifier, [modifier.text(), SyntaxFacts.getText(SyntaxKind.AsyncKeyword)]);
}
seenStaticModifier = true;
}
else if (modifier.kind === SyntaxKind.AsyncKeyword) {
if (seenAsyncModifier) {
return this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_already_seen, [modifier.text()]);
}
seenAsyncModifier = true;
}
else {
this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_cannot_appear_on_a_class_element, [modifier.text()]);
return true;
return this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_cannot_appear_on_a_class_element, [modifier.text()]);
}
}
@ -552,7 +553,8 @@ module TypeScript {
}
public visitMemberVariableDeclaration(node: MemberVariableDeclarationSyntax): void {
if (this.checkClassElementModifiers(node.modifiers)) {
if (this.checkClassElementModifiers(node.modifiers) ||
this.checkForDisallowedAsyncModifier(node.modifiers)) {
return;
}
@ -579,7 +581,8 @@ module TypeScript {
public visitMemberFunctionDeclaration(node: MemberFunctionDeclarationSyntax): void {
if (this.checkClassElementModifiers(node.modifiers) ||
this.checkForDisallowedTemplatePropertyName(node.propertyName)) {
this.checkForDisallowedTemplatePropertyName(node.propertyName) ||
this.checkForAsyncGenerator(this.getAsyncModifier(node.modifiers), node.asterixToken)) {
return;
}
@ -636,7 +639,8 @@ module TypeScript {
this.checkForDisallowedAccessorTypeParameters(node.callSignature) ||
this.checkGetAccessorParameter(node) ||
this.checkForDisallowedTemplatePropertyName(node.propertyName) ||
this.checkForSemicolonInsteadOfBlock(node, node.body)) {
this.checkForSemicolonInsteadOfBlock(node, node.body) ||
this.checkForDisallowedAsyncModifier(node.modifiers)) {
return;
}
@ -710,6 +714,15 @@ module TypeScript {
return false;
}
public visitSimpleArrowFunctionExpression(node: SimpleArrowFunctionExpressionSyntax): void {
if (node.asyncKeyword) {
this.pushDiagnostic(node.asyncKeyword, DiagnosticCode.async_arrow_function_parameters_must_be_parenthesized);
return;
}
super.visitSimpleArrowFunctionExpression(node);
}
public visitSimplePropertyAssignment(node: SimplePropertyAssignmentSyntax): void {
if (this.checkForDisallowedTemplatePropertyName(node.propertyName)) {
return;
@ -727,13 +740,23 @@ module TypeScript {
this.checkForDisallowedSetAccessorTypeAnnotation(node) ||
this.checkSetAccessorParameter(node) ||
this.checkForDisallowedTemplatePropertyName(node.propertyName) ||
this.checkForSemicolonInsteadOfBlock(node, node.body)) {
this.checkForSemicolonInsteadOfBlock(node, node.body) ||
this.checkForDisallowedAsyncModifier(node.modifiers)) {
return;
}
super.visitSetAccessor(node);
}
private checkForDisallowedAsyncModifier(modifiers: ISyntaxToken[]) {
var asyncKeyword = this.getAsyncModifier(modifiers);
if (asyncKeyword) {
return this.pushDiagnostic(asyncKeyword, DiagnosticCode.async_modifier_cannot_appear_here);
}
return false;
}
public visitElementAccessExpression(node: ElementAccessExpressionSyntax): void {
if (this.checkForMissingArgumentExpression(node)) {
return;
@ -765,7 +788,8 @@ module TypeScript {
if (this.checkForDisallowedDeclareModifier(node.modifiers) ||
this.checkForRequiredDeclareModifier(node, node.identifier, node.modifiers) ||
this.checkModuleElementModifiers(node.modifiers),
this.checkEnumElements(node)) {
this.checkEnumElements(node) ||
this.checkForDisallowedAsyncModifier(node.modifiers)) {
return;
}
@ -823,6 +847,7 @@ module TypeScript {
private checkModuleElementModifiers(modifiers: ISyntaxToken[]): boolean {
var seenExportModifier = false;
var seenDeclareModifier = false;
var seenAsyncModifier = false;
for (var i = 0, n = modifiers.length; i < n; i++) {
var modifier = modifiers[i];
@ -838,6 +863,12 @@ module TypeScript {
return;
}
if (seenAsyncModifier) {
this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_must_precede_1_modifier,
[SyntaxFacts.getText(SyntaxKind.DeclareKeyword), SyntaxFacts.getText(SyntaxKind.AsyncKeyword)]);
return;
}
seenDeclareModifier = true;
}
else if (modifier.kind === SyntaxKind.ExportKeyword) {
@ -852,8 +883,22 @@ module TypeScript {
return;
}
if (seenAsyncModifier) {
this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_must_precede_1_modifier,
[SyntaxFacts.getText(SyntaxKind.ExportKeyword), SyntaxFacts.getText(SyntaxKind.AsyncKeyword)]);
return;
}
seenExportModifier = true;
}
else if (modifier.kind === SyntaxKind.AsyncKeyword) {
if (seenAsyncModifier) {
this.pushDiagnostic(modifier, DiagnosticCode._0_modifier_already_seen, [modifier.text()]);
return;
}
seenAsyncModifier = true;
}
}
return false;
@ -886,7 +931,8 @@ module TypeScript {
public visitImportDeclaration(node: ImportDeclarationSyntax): any {
if (this.checkForDisallowedDeclareModifierOnImportDeclaration(node.modifiers) ||
this.checkModuleElementModifiers(node.modifiers)) {
this.checkModuleElementModifiers(node.modifiers) ||
this.checkForDisallowedAsyncModifier(node.modifiers)) {
return;
}
@ -897,7 +943,8 @@ module TypeScript {
if (this.checkForDisallowedDeclareModifier(node.modifiers) ||
this.checkForRequiredDeclareModifier(node, firstToken(node.name), node.modifiers) ||
this.checkModuleElementModifiers(node.modifiers) ||
this.checkForDisallowedImportDeclaration(node)) {
this.checkForDisallowedImportDeclaration(node) ||
this.checkForDisallowedAsyncModifier(node.modifiers)) {
return;
}
@ -1392,7 +1439,8 @@ module TypeScript {
this.checkForDisallowedModifiers(node.modifiers) ||
this.checkForRequiredDeclareModifier(node, node.identifier, node.modifiers) ||
this.checkModuleElementModifiers(node.modifiers) ||
this.checkForDisallowedEvalOrArguments(node, node.identifier)) {
this.checkForDisallowedEvalOrArguments(node, node.identifier) ||
this.checkForAsyncGenerator(this.getAsyncModifier(node.modifiers), node.asterixToken)) {
return;
}
@ -1403,9 +1451,30 @@ module TypeScript {
this.inAmbientDeclaration = savedInAmbientDeclaration;
}
private getAsyncModifier(modifiers: ISyntaxToken[]): ISyntaxToken {
for (var i = 0, n = modifiers.length; i < n; i++) {
var modifier = modifiers[i];
if (modifier.kind === SyntaxKind.AsyncKeyword) {
return modifier;
}
}
return undefined;
}
private checkForAsyncGenerator(asyncKeyword: ISyntaxToken, asterixToken: ISyntaxToken) {
if (asyncKeyword && asterixToken) {
this.pushDiagnostic(asyncKeyword, DiagnosticCode.A_generator_declaration_cannot_have_the_async_modifier);
return true;
}
return false;
}
public visitFunctionExpression(node: FunctionExpressionSyntax): void {
if (this.checkForDisallowedEvalOrArguments(node, node.identifier) ||
this.checkForSemicolonInsteadOfBlock(node, node.body)) {
this.checkForSemicolonInsteadOfBlock(node, node.body) ||
this.checkForAsyncGenerator(node.asyncKeyword, node.asterixToken)) {
return;
}
@ -1414,7 +1483,8 @@ module TypeScript {
public visitFunctionPropertyAssignment(node: FunctionPropertyAssignmentSyntax): void {
if (this.checkForDisallowedTemplatePropertyName(node.propertyName) ||
this.checkForSemicolonInsteadOfBlock(node, node.body)) {
this.checkForSemicolonInsteadOfBlock(node, node.body) ||
this.checkForAsyncGenerator(node.asyncKeyword, node.asterixToken)) {
return;
}
@ -1425,7 +1495,8 @@ module TypeScript {
if (this.checkForDisallowedDeclareModifier(node.modifiers) ||
this.checkForDisallowedModifiers(node.modifiers) ||
this.checkForRequiredDeclareModifier(node, node.variableDeclaration.varKeyword, node.modifiers) ||
this.checkModuleElementModifiers(node.modifiers)) {
this.checkModuleElementModifiers(node.modifiers) ||
this.checkForDisallowedAsyncModifier(node.modifiers)) {
return;
}
@ -1535,7 +1606,8 @@ module TypeScript {
if (this.checkClassElementModifiers(node.modifiers) ||
this.checkConstructorModifiers(node.modifiers) ||
this.checkConstructorTypeParameterList(node) ||
this.checkConstructorTypeAnnotation(node)) {
this.checkConstructorTypeAnnotation(node) ||
this.checkForDisallowedAsyncModifier(node.modifiers)) {
return;
}
@ -1598,7 +1670,8 @@ module TypeScript {
}
public visitParameter(node: ParameterSyntax): void {
if (this.checkForDisallowedEvalOrArguments(node, node.identifier)) {
if (this.checkParameterAccessibilityModifiers(node) ||
this.checkForDisallowedEvalOrArguments(node, node.identifier)) {
return;
}
@ -1644,6 +1717,15 @@ module TypeScript {
super.visitYieldExpression(node);
}
public visitAwaitExpression(node: AwaitExpressionSyntax): void {
if (!parsedInAsyncContext(node)) {
this.pushDiagnostic(node.awaitKeyword, DiagnosticCode.await_expression_must_be_contained_within_an_async_declaration);
return;
}
super.visitAwaitExpression(node);
}
private checkIllegalAssignment(node: BinaryExpressionSyntax): boolean {
if (parsedInStrictModeContext(node) && SyntaxFacts.isAssignmentOperatorToken(node.operatorToken.kind) && this.isEvalOrArguments(node.left)) {
this.pushDiagnostic(node.operatorToken, DiagnosticCode.Invalid_use_of_0_in_strict_mode, [this.getEvalOrArguments(node.left)]);

View file

@ -73,6 +73,7 @@ module TypeScript {
case SyntaxKind.TemplateExpression: return visitor.visitTemplateExpression(<TemplateExpressionSyntax>element);
case SyntaxKind.TemplateAccessExpression: return visitor.visitTemplateAccessExpression(<TemplateAccessExpressionSyntax>element);
case SyntaxKind.YieldExpression: return visitor.visitYieldExpression(<YieldExpressionSyntax>element);
case SyntaxKind.AwaitExpression: return visitor.visitAwaitExpression(<AwaitExpressionSyntax>element);
case SyntaxKind.VariableDeclaration: return visitor.visitVariableDeclaration(<VariableDeclarationSyntax>element);
case SyntaxKind.VariableDeclarator: return visitor.visitVariableDeclarator(<VariableDeclaratorSyntax>element);
case SyntaxKind.ArgumentList: return visitor.visitArgumentList(<ArgumentListSyntax>element);
@ -173,6 +174,7 @@ module TypeScript {
visitTemplateExpression(node: TemplateExpressionSyntax): any;
visitTemplateAccessExpression(node: TemplateAccessExpressionSyntax): any;
visitYieldExpression(node: YieldExpressionSyntax): any;
visitAwaitExpression(node: AwaitExpressionSyntax): any;
visitVariableDeclaration(node: VariableDeclarationSyntax): any;
visitVariableDeclarator(node: VariableDeclaratorSyntax): any;
visitArgumentList(node: ArgumentListSyntax): any;

View file

@ -427,12 +427,14 @@ module TypeScript {
}
public visitParenthesizedArrowFunctionExpression(node: ParenthesizedArrowFunctionExpressionSyntax): void {
this.visitOptionalToken(node.asyncKeyword);
visitNodeOrToken(this, node.callSignature);
this.visitToken(node.equalsGreaterThanToken);
visitNodeOrToken(this, node.body);
}
public visitSimpleArrowFunctionExpression(node: SimpleArrowFunctionExpressionSyntax): void {
this.visitOptionalToken(node.asyncKeyword);
visitNodeOrToken(this, node.parameter);
this.visitToken(node.equalsGreaterThanToken);
visitNodeOrToken(this, node.body);
@ -453,6 +455,7 @@ module TypeScript {
}
public visitFunctionExpression(node: FunctionExpressionSyntax): void {
this.visitOptionalToken(node.asyncKeyword);
this.visitToken(node.functionKeyword);
this.visitOptionalToken(node.asterixToken);
this.visitOptionalToken(node.identifier);
@ -479,6 +482,11 @@ module TypeScript {
visitNodeOrToken(this, node.expression);
}
public visitAwaitExpression(node: AwaitExpressionSyntax): void {
this.visitToken(node.awaitKeyword);
visitNodeOrToken(this, node.expression);
}
public visitVariableDeclaration(node: VariableDeclarationSyntax): void {
this.visitToken(node.varKeyword);
this.visitList(node.variableDeclarators);
@ -579,6 +587,7 @@ module TypeScript {
}
public visitFunctionPropertyAssignment(node: FunctionPropertyAssignmentSyntax): void {
this.visitOptionalToken(node.asyncKeyword);
this.visitOptionalToken(node.asterixToken);
visitNodeOrToken(this, node.propertyName);
visitNodeOrToken(this, node.callSignature);

View file

@ -1,4 +0,0 @@
var fixedWidthArray = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 4, 5, 8, 8, 7, 6, 2, 4, 5, 7, 3, 8, 2, 2, 10, 3, 4, 6, 6, 4, 5, 4, 3, 6, 3, 4, 5, 4, 5, 5, 4, 6, 7, 6, 5, 10, 9, 3, 7, 7, 9, 6, 6, 5, 3, 7, 11, 7, 3, 6, 7, 6, 3, 6, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 1, 1, 1, 1, 2, 2, 2, 2, 3, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 2, 2, 2, 1, 2];
function fixedWidthTokenLength(kind: SyntaxKind) {
return fixedWidthArray[kind];
}