From 9a23b11b6aad15dff9aff3757d4435944f0f61fa Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 22 Jul 2016 14:28:53 -0700 Subject: [PATCH] Change parser to use token() function for accessing current token --- src/compiler/parser.ts | 612 +++++++++++++++++++++-------------------- 1 file changed, 311 insertions(+), 301 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e707ff6e5c1..b4a399e88b6 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -474,7 +474,7 @@ namespace ts { let parseDiagnostics: Diagnostic[]; let syntaxCursor: IncrementalParser.SyntaxCursor; - let token: SyntaxKind; + let currentToken: SyntaxKind; let sourceText: string; let nodeCount: number; let identifiers: Map; @@ -617,11 +617,11 @@ namespace ts { sourceFile.flags = contextFlags; // Prime the scanner. - token = nextToken(); + nextToken(); processReferenceComments(sourceFile); sourceFile.statements = parseList(ParsingContext.SourceElements, parseStatement); - Debug.assert(token === SyntaxKind.EndOfFileToken); + Debug.assert(token() === SyntaxKind.EndOfFileToken); sourceFile.endOfFileToken = parseTokenNode(); setExternalModuleIndicator(sourceFile); @@ -856,34 +856,44 @@ namespace ts { return scanner.getStartPos(); } + // Use this function to access the current token instead of reading the currentToken + // variable. Since function results aren't narrowed in control flow analysis, this ensures + // that the type checker doesn't make wrong assumptions about the type of the current + // token (e.g. a call to nextToken() changes the current token but the checker doesn't + // reason about this side effect). Mainstream VMs inline simple functions like this, so + // there is no performance penalty. + function token(): SyntaxKind { + return currentToken; + } + function nextToken(): SyntaxKind { - return token = scanner.scan(); + return currentToken = scanner.scan(); } function reScanGreaterToken(): SyntaxKind { - return token = scanner.reScanGreaterToken(); + return currentToken = scanner.reScanGreaterToken(); } function reScanSlashToken(): SyntaxKind { - return token = scanner.reScanSlashToken(); + return currentToken = scanner.reScanSlashToken(); } function reScanTemplateToken(): SyntaxKind { - return token = scanner.reScanTemplateToken(); + return currentToken = scanner.reScanTemplateToken(); } function scanJsxIdentifier(): SyntaxKind { - return token = scanner.scanJsxIdentifier(); + return currentToken = scanner.scanJsxIdentifier(); } function scanJsxText(): SyntaxKind { - return token = scanner.scanJsxToken(); + return currentToken = scanner.scanJsxToken(); } function speculationHelper(callback: () => T, isLookAhead: boolean): T { // Keep track of the state we'll need to rollback to if lookahead fails (or if the // caller asked us to always reset our state). - const saveToken = token; + const saveToken = currentToken; const saveParseDiagnosticsLength = parseDiagnostics.length; const saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; @@ -905,7 +915,7 @@ namespace ts { // If our callback returned something 'falsy' or we're just looking ahead, // then unconditionally restore us to where we were. if (!result || isLookAhead) { - token = saveToken; + currentToken = saveToken; parseDiagnostics.length = saveParseDiagnosticsLength; parseErrorBeforeNextFinishedNode = saveParseErrorBeforeNextFinishedNode; } @@ -932,27 +942,27 @@ namespace ts { // Ignore strict mode flag because we will report an error in type checker instead. function isIdentifier(): boolean { - if (token === SyntaxKind.Identifier) { + if (token() === SyntaxKind.Identifier) { return true; } // If we have a 'yield' keyword, and we're in the [yield] context, then 'yield' is // considered a keyword and is not an identifier. - if (token === SyntaxKind.YieldKeyword && inYieldContext()) { + if (token() === SyntaxKind.YieldKeyword && inYieldContext()) { return false; } // If we have a 'await' keyword, and we're in the [Await] context, then 'await' is // considered a keyword and is not an identifier. - if (token === SyntaxKind.AwaitKeyword && inAwaitContext()) { + if (token() === SyntaxKind.AwaitKeyword && inAwaitContext()) { return false; } - return token > SyntaxKind.LastReservedWord; + return token() > SyntaxKind.LastReservedWord; } function parseExpected(kind: SyntaxKind, diagnosticMessage?: DiagnosticMessage, shouldAdvance = true): boolean { - if (token === kind) { + if (token() === kind) { if (shouldAdvance) { nextToken(); } @@ -970,7 +980,7 @@ namespace ts { } function parseOptional(t: SyntaxKind): boolean { - if (token === t) { + if (token() === t) { nextToken(); return true; } @@ -978,7 +988,7 @@ namespace ts { } function parseOptionalToken(t: SyntaxKind): Node { - if (token === t) { + if (token() === t) { return parseTokenNode(); } return undefined; @@ -990,24 +1000,24 @@ namespace ts { } function parseTokenNode(): T { - const node = createNode(token); + const node = createNode(token()); nextToken(); return finishNode(node); } function canParseSemicolon() { // If there's a real semicolon, then we can always parse it out. - if (token === SyntaxKind.SemicolonToken) { + if (token() === SyntaxKind.SemicolonToken) { return true; } // We can parse out an optional semicolon in ASI cases in the following cases. - return token === SyntaxKind.CloseBraceToken || token === SyntaxKind.EndOfFileToken || scanner.hasPrecedingLineBreak(); + return token() === SyntaxKind.CloseBraceToken || token() === SyntaxKind.EndOfFileToken || scanner.hasPrecedingLineBreak(); } function parseSemicolon(): boolean { if (canParseSemicolon()) { - if (token === SyntaxKind.SemicolonToken) { + if (token() === SyntaxKind.SemicolonToken) { // consume the semicolon if it was explicitly provided. nextToken(); } @@ -1074,8 +1084,8 @@ namespace ts { const node = createNode(SyntaxKind.Identifier); // Store original token kind if it is not just an Identifier so we can report appropriate error later in type checker - if (token !== SyntaxKind.Identifier) { - node.originalKeywordKind = token; + if (token() !== SyntaxKind.Identifier) { + node.originalKeywordKind = token(); } node.text = internIdentifier(scanner.getTokenValue()); nextToken(); @@ -1090,20 +1100,20 @@ namespace ts { } function parseIdentifierName(): Identifier { - return createIdentifier(tokenIsIdentifierOrKeyword(token)); + return createIdentifier(tokenIsIdentifierOrKeyword(token())); } function isLiteralPropertyName(): boolean { - return tokenIsIdentifierOrKeyword(token) || - token === SyntaxKind.StringLiteral || - token === SyntaxKind.NumericLiteral; + return tokenIsIdentifierOrKeyword(token()) || + token() === SyntaxKind.StringLiteral || + token() === SyntaxKind.NumericLiteral; } function parsePropertyNameWorker(allowComputedPropertyNames: boolean): PropertyName { - if (token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral) { + if (token() === SyntaxKind.StringLiteral || token() === SyntaxKind.NumericLiteral) { return parseLiteralNode(/*internName*/ true); } - if (allowComputedPropertyNames && token === SyntaxKind.OpenBracketToken) { + if (allowComputedPropertyNames && token() === SyntaxKind.OpenBracketToken) { return parseComputedPropertyName(); } return parseIdentifierName(); @@ -1118,7 +1128,7 @@ namespace ts { } function isSimplePropertyName() { - return token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral || tokenIsIdentifierOrKeyword(token); + return token() === SyntaxKind.StringLiteral || token() === SyntaxKind.NumericLiteral || tokenIsIdentifierOrKeyword(token()); } function parseComputedPropertyName(): ComputedPropertyName { @@ -1138,7 +1148,7 @@ namespace ts { } function parseContextualModifier(t: SyntaxKind): boolean { - return token === t && tryParse(nextTokenCanFollowModifier); + return token() === t && tryParse(nextTokenCanFollowModifier); } function nextTokenIsOnSameLineAndCanFollowModifier() { @@ -1150,21 +1160,21 @@ namespace ts { } function nextTokenCanFollowModifier() { - if (token === SyntaxKind.ConstKeyword) { + if (token() === SyntaxKind.ConstKeyword) { // 'const' is only a modifier if followed by 'enum'. return nextToken() === SyntaxKind.EnumKeyword; } - if (token === SyntaxKind.ExportKeyword) { + if (token() === SyntaxKind.ExportKeyword) { nextToken(); - if (token === SyntaxKind.DefaultKeyword) { + if (token() === SyntaxKind.DefaultKeyword) { return lookAhead(nextTokenIsClassOrFunctionOrAsync); } - return token !== SyntaxKind.AsteriskToken && token !== SyntaxKind.AsKeyword && token !== SyntaxKind.OpenBraceToken && canFollowModifier(); + return token() !== SyntaxKind.AsteriskToken && token() !== SyntaxKind.AsKeyword && token() !== SyntaxKind.OpenBraceToken && canFollowModifier(); } - if (token === SyntaxKind.DefaultKeyword) { + if (token() === SyntaxKind.DefaultKeyword) { return nextTokenIsClassOrFunctionOrAsync(); } - if (token === SyntaxKind.StaticKeyword) { + if (token() === SyntaxKind.StaticKeyword) { nextToken(); return canFollowModifier(); } @@ -1173,21 +1183,21 @@ namespace ts { } function parseAnyContextualModifier(): boolean { - return isModifierKind(token) && tryParse(nextTokenCanFollowModifier); + return isModifierKind(token()) && tryParse(nextTokenCanFollowModifier); } function canFollowModifier(): boolean { - return token === SyntaxKind.OpenBracketToken - || token === SyntaxKind.OpenBraceToken - || token === SyntaxKind.AsteriskToken - || token === SyntaxKind.DotDotDotToken + return token() === SyntaxKind.OpenBracketToken + || token() === SyntaxKind.OpenBraceToken + || token() === SyntaxKind.AsteriskToken + || token() === SyntaxKind.DotDotDotToken || isLiteralPropertyName(); } function nextTokenIsClassOrFunctionOrAsync(): boolean { nextToken(); - return token === SyntaxKind.ClassKeyword || token === SyntaxKind.FunctionKeyword || - (token === SyntaxKind.AsyncKeyword && lookAhead(nextTokenIsFunctionKeywordOnSameLine)); + return token() === SyntaxKind.ClassKeyword || token() === SyntaxKind.FunctionKeyword || + (token() === SyntaxKind.AsyncKeyword && lookAhead(nextTokenIsFunctionKeywordOnSameLine)); } // True if positioned at the start of a list element @@ -1207,9 +1217,9 @@ namespace ts { // we're parsing. For example, if we have a semicolon in the middle of a class, then // we really don't want to assume the class is over and we're on a statement in the // outer module. We just want to consume and move on. - return !(token === SyntaxKind.SemicolonToken && inErrorRecovery) && isStartOfStatement(); + return !(token() === SyntaxKind.SemicolonToken && inErrorRecovery) && isStartOfStatement(); case ParsingContext.SwitchClauses: - return token === SyntaxKind.CaseKeyword || token === SyntaxKind.DefaultKeyword; + return token() === SyntaxKind.CaseKeyword || token() === SyntaxKind.DefaultKeyword; case ParsingContext.TypeMembers: return lookAhead(isTypeMemberStart); case ParsingContext.ClassMembers: @@ -1217,19 +1227,19 @@ namespace ts { // not in error recovery. If we're in error recovery, we don't want an errant // semicolon to be treated as a class member (since they're almost always used // for statements. - return lookAhead(isClassMemberStart) || (token === SyntaxKind.SemicolonToken && !inErrorRecovery); + return lookAhead(isClassMemberStart) || (token() === SyntaxKind.SemicolonToken && !inErrorRecovery); case ParsingContext.EnumMembers: // Include open bracket computed properties. This technically also lets in indexers, // which would be a candidate for improved error reporting. - return token === SyntaxKind.OpenBracketToken || isLiteralPropertyName(); + return token() === SyntaxKind.OpenBracketToken || isLiteralPropertyName(); case ParsingContext.ObjectLiteralMembers: - return token === SyntaxKind.OpenBracketToken || token === SyntaxKind.AsteriskToken || isLiteralPropertyName(); + return token() === SyntaxKind.OpenBracketToken || token() === SyntaxKind.AsteriskToken || isLiteralPropertyName(); case ParsingContext.ObjectBindingElements: - return token === SyntaxKind.OpenBracketToken || isLiteralPropertyName(); + return token() === SyntaxKind.OpenBracketToken || isLiteralPropertyName(); case ParsingContext.HeritageClauseElement: // If we see { } then only consume it as an expression if it is followed by , or { // That way we won't consume the body of a class in its heritage clause. - if (token === SyntaxKind.OpenBraceToken) { + if (token() === SyntaxKind.OpenBraceToken) { return lookAhead(isValidHeritageClauseObjectLiteral); } @@ -1245,23 +1255,23 @@ namespace ts { case ParsingContext.VariableDeclarations: return isIdentifierOrPattern(); case ParsingContext.ArrayBindingElements: - return token === SyntaxKind.CommaToken || token === SyntaxKind.DotDotDotToken || isIdentifierOrPattern(); + return token() === SyntaxKind.CommaToken || token() === SyntaxKind.DotDotDotToken || isIdentifierOrPattern(); case ParsingContext.TypeParameters: return isIdentifier(); case ParsingContext.ArgumentExpressions: case ParsingContext.ArrayLiteralMembers: - return token === SyntaxKind.CommaToken || token === SyntaxKind.DotDotDotToken || isStartOfExpression(); + return token() === SyntaxKind.CommaToken || token() === SyntaxKind.DotDotDotToken || isStartOfExpression(); case ParsingContext.Parameters: return isStartOfParameter(); case ParsingContext.TypeArguments: case ParsingContext.TupleElementTypes: - return token === SyntaxKind.CommaToken || isStartOfType(); + return token() === SyntaxKind.CommaToken || isStartOfType(); case ParsingContext.HeritageClauses: return isHeritageClause(); case ParsingContext.ImportOrExportSpecifiers: - return tokenIsIdentifierOrKeyword(token); + return tokenIsIdentifierOrKeyword(token()); case ParsingContext.JsxAttributes: - return tokenIsIdentifierOrKeyword(token) || token === SyntaxKind.OpenBraceToken; + return tokenIsIdentifierOrKeyword(token()) || token() === SyntaxKind.OpenBraceToken; case ParsingContext.JsxChildren: return true; case ParsingContext.JSDocFunctionParameters: @@ -1276,7 +1286,7 @@ namespace ts { } function isValidHeritageClauseObjectLiteral() { - Debug.assert(token === SyntaxKind.OpenBraceToken); + Debug.assert(token() === SyntaxKind.OpenBraceToken); if (nextToken() === SyntaxKind.CloseBraceToken) { // if we see "extends {}" then only treat the {} as what we're extending (and not // the class body) if we have: @@ -1300,12 +1310,12 @@ namespace ts { function nextTokenIsIdentifierOrKeyword() { nextToken(); - return tokenIsIdentifierOrKeyword(token); + return tokenIsIdentifierOrKeyword(token()); } function isHeritageClauseExtendsOrImplementsKeyword(): boolean { - if (token === SyntaxKind.ImplementsKeyword || - token === SyntaxKind.ExtendsKeyword) { + if (token() === SyntaxKind.ImplementsKeyword || + token() === SyntaxKind.ExtendsKeyword) { return lookAhead(nextTokenIsStartOfExpression); } @@ -1320,7 +1330,7 @@ namespace ts { // True if positioned at a list terminator function isListTerminator(kind: ParsingContext): boolean { - if (token === SyntaxKind.EndOfFileToken) { + if (token() === SyntaxKind.EndOfFileToken) { // Being at the end of the file ends all lists. return true; } @@ -1334,43 +1344,43 @@ namespace ts { case ParsingContext.ObjectLiteralMembers: case ParsingContext.ObjectBindingElements: case ParsingContext.ImportOrExportSpecifiers: - return token === SyntaxKind.CloseBraceToken; + return token() === SyntaxKind.CloseBraceToken; case ParsingContext.SwitchClauseStatements: - return token === SyntaxKind.CloseBraceToken || token === SyntaxKind.CaseKeyword || token === SyntaxKind.DefaultKeyword; + return token() === SyntaxKind.CloseBraceToken || token() === SyntaxKind.CaseKeyword || token() === SyntaxKind.DefaultKeyword; case ParsingContext.HeritageClauseElement: - return token === SyntaxKind.OpenBraceToken || token === SyntaxKind.ExtendsKeyword || token === SyntaxKind.ImplementsKeyword; + return token() === SyntaxKind.OpenBraceToken || token() === SyntaxKind.ExtendsKeyword || token() === SyntaxKind.ImplementsKeyword; case ParsingContext.VariableDeclarations: return isVariableDeclaratorListTerminator(); case ParsingContext.TypeParameters: // Tokens other than '>' are here for better error recovery - return token === SyntaxKind.GreaterThanToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.OpenBraceToken || token === SyntaxKind.ExtendsKeyword || token === SyntaxKind.ImplementsKeyword; + return token() === SyntaxKind.GreaterThanToken || token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.OpenBraceToken || token() === SyntaxKind.ExtendsKeyword || token() === SyntaxKind.ImplementsKeyword; case ParsingContext.ArgumentExpressions: // Tokens other than ')' are here for better error recovery - return token === SyntaxKind.CloseParenToken || token === SyntaxKind.SemicolonToken; + return token() === SyntaxKind.CloseParenToken || token() === SyntaxKind.SemicolonToken; case ParsingContext.ArrayLiteralMembers: case ParsingContext.TupleElementTypes: case ParsingContext.ArrayBindingElements: - return token === SyntaxKind.CloseBracketToken; + return token() === SyntaxKind.CloseBracketToken; case ParsingContext.Parameters: // Tokens other than ')' and ']' (the latter for index signatures) are here for better error recovery - return token === SyntaxKind.CloseParenToken || token === SyntaxKind.CloseBracketToken /*|| token === SyntaxKind.OpenBraceToken*/; + return token() === SyntaxKind.CloseParenToken || token() === SyntaxKind.CloseBracketToken /*|| token === SyntaxKind.OpenBraceToken*/; case ParsingContext.TypeArguments: // Tokens other than '>' are here for better error recovery - return token === SyntaxKind.GreaterThanToken || token === SyntaxKind.OpenParenToken; + return token() === SyntaxKind.GreaterThanToken || token() === SyntaxKind.OpenParenToken; case ParsingContext.HeritageClauses: - return token === SyntaxKind.OpenBraceToken || token === SyntaxKind.CloseBraceToken; + return token() === SyntaxKind.OpenBraceToken || token() === SyntaxKind.CloseBraceToken; case ParsingContext.JsxAttributes: - return token === SyntaxKind.GreaterThanToken || token === SyntaxKind.SlashToken; + return token() === SyntaxKind.GreaterThanToken || token() === SyntaxKind.SlashToken; case ParsingContext.JsxChildren: - return token === SyntaxKind.LessThanToken && lookAhead(nextTokenIsSlash); + return token() === SyntaxKind.LessThanToken && lookAhead(nextTokenIsSlash); case ParsingContext.JSDocFunctionParameters: - return token === SyntaxKind.CloseParenToken || token === SyntaxKind.ColonToken || token === SyntaxKind.CloseBraceToken; + return token() === SyntaxKind.CloseParenToken || token() === SyntaxKind.ColonToken || token() === SyntaxKind.CloseBraceToken; case ParsingContext.JSDocTypeArguments: - return token === SyntaxKind.GreaterThanToken || token === SyntaxKind.CloseBraceToken; + return token() === SyntaxKind.GreaterThanToken || token() === SyntaxKind.CloseBraceToken; case ParsingContext.JSDocTupleTypes: - return token === SyntaxKind.CloseBracketToken || token === SyntaxKind.CloseBraceToken; + return token() === SyntaxKind.CloseBracketToken || token() === SyntaxKind.CloseBraceToken; case ParsingContext.JSDocRecordMembers: - return token === SyntaxKind.CloseBraceToken; + return token() === SyntaxKind.CloseBraceToken; } } @@ -1383,7 +1393,7 @@ namespace ts { // in the case where we're parsing the variable declarator of a 'for-in' statement, we // are done if we see an 'in' keyword in front of us. Same with for-of - if (isInOrOfKeyword(token)) { + if (isInOrOfKeyword(token())) { return true; } @@ -1391,7 +1401,7 @@ namespace ts { // For better error recovery, if we see an '=>' then we just stop immediately. We've got an // arrow function here and it's going to be very unlikely that we'll resynchronize and get // another variable declaration. - if (token === SyntaxKind.EqualsGreaterThanToken) { + if (token() === SyntaxKind.EqualsGreaterThanToken) { return true; } @@ -1790,7 +1800,7 @@ namespace ts { // parse errors. For example, this can happen when people do things like use // a semicolon to delimit object literal members. Note: we'll have already // reported an error when we called parseExpected above. - if (considerSemicolonAsDelimiter && token === SyntaxKind.SemicolonToken && !scanner.hasPrecedingLineBreak()) { + if (considerSemicolonAsDelimiter && token() === SyntaxKind.SemicolonToken && !scanner.hasPrecedingLineBreak()) { nextToken(); } continue; @@ -1870,7 +1880,7 @@ namespace ts { // the code would be implicitly: "name.identifierOrKeyword; identifierNameOrKeyword". // In the first case though, ASI will not take effect because there is not a // line terminator after the identifier or keyword. - if (scanner.hasPrecedingLineBreak() && tokenIsIdentifierOrKeyword(token)) { + if (scanner.hasPrecedingLineBreak() && tokenIsIdentifierOrKeyword(token())) { const matchesPattern = lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine); if (matchesPattern) { @@ -1910,7 +1920,7 @@ namespace ts { let literal: TemplateLiteralFragment; - if (token === SyntaxKind.CloseBraceToken) { + if (token() === SyntaxKind.CloseBraceToken) { reScanTemplateToken(); literal = parseTemplateLiteralFragment(); } @@ -1923,11 +1933,11 @@ namespace ts { } function parseLiteralNode(internName?: boolean): LiteralExpression { - return parseLiteralLikeNode(token, internName); + return parseLiteralLikeNode(token(), internName); } function parseTemplateLiteralFragment(): TemplateLiteralFragment { - return parseLiteralLikeNode(token, /*internName*/ false); + return parseLiteralLikeNode(token(), /*internName*/ false); } function parseLiteralLikeNode(kind: SyntaxKind, internName: boolean): LiteralLikeNode { @@ -1969,7 +1979,7 @@ namespace ts { const typeName = parseEntityName(/*allowReservedWords*/ false, Diagnostics.Type_expected); const node = createNode(SyntaxKind.TypeReference, typeName.pos); node.typeName = typeName; - if (!scanner.hasPrecedingLineBreak() && token === SyntaxKind.LessThanToken) { + if (!scanner.hasPrecedingLineBreak() && token() === SyntaxKind.LessThanToken) { node.typeArguments = parseBracketedList(ParsingContext.TypeArguments, parseType, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken); } return finishNode(node); @@ -2023,7 +2033,7 @@ namespace ts { } function parseTypeParameters(): NodeArray { - if (token === SyntaxKind.LessThanToken) { + if (token() === SyntaxKind.LessThanToken) { return parseBracketedList(ParsingContext.TypeParameters, parseTypeParameter, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken); } } @@ -2037,7 +2047,7 @@ namespace ts { } function isStartOfParameter(): boolean { - return token === SyntaxKind.DotDotDotToken || isIdentifierOrPattern() || isModifierKind(token) || token === SyntaxKind.AtToken || token === SyntaxKind.ThisKeyword; + return token() === SyntaxKind.DotDotDotToken || isIdentifierOrPattern() || isModifierKind(token()) || token() === SyntaxKind.AtToken || token() === SyntaxKind.ThisKeyword; } function setModifiers(node: Node, modifiers: ModifiersArray) { @@ -2049,7 +2059,7 @@ namespace ts { function parseParameter(): ParameterDeclaration { const node = createNode(SyntaxKind.Parameter); - if (token === SyntaxKind.ThisKeyword) { + if (token() === SyntaxKind.ThisKeyword) { node.name = createIdentifier(/*isIdentifier*/true, undefined); node.type = parseParameterType(); return finishNode(node); @@ -2062,7 +2072,7 @@ namespace ts { // FormalParameter [Yield,Await]: // BindingElement[?Yield,?Await] node.name = parseIdentifierOrPattern(); - if (getFullWidth(node.name) === 0 && node.flags === 0 && isModifierKind(token)) { + if (getFullWidth(node.name) === 0 && node.flags === 0 && isModifierKind(token())) { // in cases like // 'use strict' // function foo(static) @@ -2181,7 +2191,7 @@ namespace ts { } function isIndexSignature(): boolean { - if (token !== SyntaxKind.OpenBracketToken) { + if (token() !== SyntaxKind.OpenBracketToken) { return false; } @@ -2206,11 +2216,11 @@ namespace ts { // [] // nextToken(); - if (token === SyntaxKind.DotDotDotToken || token === SyntaxKind.CloseBracketToken) { + if (token() === SyntaxKind.DotDotDotToken || token() === SyntaxKind.CloseBracketToken) { return true; } - if (isModifierKind(token)) { + if (isModifierKind(token())) { nextToken(); if (isIdentifier()) { return true; @@ -2227,20 +2237,20 @@ namespace ts { // A colon signifies a well formed indexer // A comma should be a badly formed indexer because comma expressions are not allowed // in computed properties. - if (token === SyntaxKind.ColonToken || token === SyntaxKind.CommaToken) { + if (token() === SyntaxKind.ColonToken || token() === SyntaxKind.CommaToken) { return true; } // Question mark could be an indexer with an optional property, // or it could be a conditional expression in a computed property. - if (token !== SyntaxKind.QuestionToken) { + if (token() !== SyntaxKind.QuestionToken) { return false; } // If any of the following tokens are after the question mark, it cannot // be a conditional expression, so treat it as an indexer. nextToken(); - return token === SyntaxKind.ColonToken || token === SyntaxKind.CommaToken || token === SyntaxKind.CloseBracketToken; + return token() === SyntaxKind.ColonToken || token() === SyntaxKind.CommaToken || token() === SyntaxKind.CloseBracketToken; } function parseIndexSignatureDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): IndexSignatureDeclaration { @@ -2257,7 +2267,7 @@ namespace ts { const name = parsePropertyName(); const questionToken = parseOptionalToken(SyntaxKind.QuestionToken); - if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { + if (token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken) { const method = createNode(SyntaxKind.MethodSignature, fullStart); setModifiers(method, modifiers); method.name = name; @@ -2276,7 +2286,7 @@ namespace ts { property.questionToken = questionToken; property.type = parseTypeAnnotation(); - if (token === SyntaxKind.EqualsToken) { + if (token() === SyntaxKind.EqualsToken) { // Although type literal properties cannot not have initializers, we attempt // to parse an initializer so we can report in the checker that an interface // property or type literal property cannot have an initializer. @@ -2291,40 +2301,40 @@ namespace ts { function isTypeMemberStart(): boolean { let idToken: SyntaxKind; // Return true if we have the start of a signature member - if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { + if (token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken) { return true; } // Eat up all modifiers, but hold on to the last one in case it is actually an identifier - while (isModifierKind(token)) { - idToken = token; + while (isModifierKind(token())) { + idToken = token(); nextToken(); } // Index signatures and computed property names are type members - if (token === SyntaxKind.OpenBracketToken) { + if (token() === SyntaxKind.OpenBracketToken) { return true; } // Try to get the first property-like token following all modifiers if (isLiteralPropertyName()) { - idToken = token; + idToken = token(); nextToken(); } // If we were able to get any potential identifier, check that it is // the start of a member declaration if (idToken) { - return token === SyntaxKind.OpenParenToken || - token === SyntaxKind.LessThanToken || - token === SyntaxKind.QuestionToken || - token === SyntaxKind.ColonToken || + return token() === SyntaxKind.OpenParenToken || + token() === SyntaxKind.LessThanToken || + token() === SyntaxKind.QuestionToken || + token() === SyntaxKind.ColonToken || canParseSemicolon(); } return false; } function parseTypeMember(): TypeElement { - if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { + if (token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken) { return parseSignatureMember(SyntaxKind.CallSignature); } - if (token === SyntaxKind.NewKeyword && lookAhead(isStartOfConstructSignature)) { + if (token() === SyntaxKind.NewKeyword && lookAhead(isStartOfConstructSignature)) { return parseSignatureMember(SyntaxKind.ConstructSignature); } const fullStart = getNodePos(); @@ -2337,7 +2347,7 @@ namespace ts { function isStartOfConstructSignature() { nextToken(); - return token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken; + return token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken; } function parseTypeLiteral(): TypeLiteralNode { @@ -2384,7 +2394,7 @@ namespace ts { function parseKeywordAndNoDot(): TypeNode { const node = parseTokenNode(); - return token === SyntaxKind.DotToken ? undefined : node; + return token() === SyntaxKind.DotToken ? undefined : node; } function parseLiteralTypeNode(): LiteralTypeNode { @@ -2399,7 +2409,7 @@ namespace ts { } function parseNonArrayType(): TypeNode { - switch (token) { + switch (token()) { case SyntaxKind.AnyKeyword: case SyntaxKind.StringKeyword: case SyntaxKind.NumberKeyword: @@ -2422,7 +2432,7 @@ namespace ts { return parseTokenNode(); case SyntaxKind.ThisKeyword: { const thisKeyword = parseThisTypeNode(); - if (token === SyntaxKind.IsKeyword && !scanner.hasPrecedingLineBreak()) { + if (token() === SyntaxKind.IsKeyword && !scanner.hasPrecedingLineBreak()) { return parseThisTypePredicate(thisKeyword); } else { @@ -2443,7 +2453,7 @@ namespace ts { } function isStartOfType(): boolean { - switch (token) { + switch (token()) { case SyntaxKind.AnyKeyword: case SyntaxKind.StringKeyword: case SyntaxKind.NumberKeyword: @@ -2477,7 +2487,7 @@ namespace ts { function isStartOfParenthesizedOrFunctionType() { nextToken(); - return token === SyntaxKind.CloseParenToken || isStartOfParameter() || isStartOfType(); + return token() === SyntaxKind.CloseParenToken || isStartOfParameter() || isStartOfType(); } function parseArrayTypeOrHigher(): TypeNode { @@ -2493,7 +2503,7 @@ namespace ts { function parseUnionOrIntersectionType(kind: SyntaxKind, parseConstituentType: () => TypeNode, operator: SyntaxKind): TypeNode { let type = parseConstituentType(); - if (token === operator) { + if (token() === operator) { const types = >[type]; types.pos = type.pos; while (parseOptional(operator)) { @@ -2516,22 +2526,22 @@ namespace ts { } function isStartOfFunctionType(): boolean { - if (token === SyntaxKind.LessThanToken) { + if (token() === SyntaxKind.LessThanToken) { return true; } - return token === SyntaxKind.OpenParenToken && lookAhead(isUnambiguouslyStartOfFunctionType); + return token() === SyntaxKind.OpenParenToken && lookAhead(isUnambiguouslyStartOfFunctionType); } function skipParameterStart(): boolean { - if (isModifierKind(token)) { + if (isModifierKind(token())) { // Skip modifiers parseModifiers(); } - if (isIdentifier() || token === SyntaxKind.ThisKeyword) { + if (isIdentifier() || token() === SyntaxKind.ThisKeyword) { nextToken(); return true; } - if (token === SyntaxKind.OpenBracketToken || token === SyntaxKind.OpenBraceToken) { + if (token() === SyntaxKind.OpenBracketToken || token() === SyntaxKind.OpenBraceToken) { // Return true if we can parse an array or object binding pattern with no errors const previousErrorCount = parseDiagnostics.length; parseIdentifierOrPattern(); @@ -2542,7 +2552,7 @@ namespace ts { function isUnambiguouslyStartOfFunctionType() { nextToken(); - if (token === SyntaxKind.CloseParenToken || token === SyntaxKind.DotDotDotToken) { + if (token() === SyntaxKind.CloseParenToken || token() === SyntaxKind.DotDotDotToken) { // ( ) // ( ... return true; @@ -2550,17 +2560,17 @@ namespace ts { if (skipParameterStart()) { // We successfully skipped modifiers (if any) and an identifier or binding pattern, // now see if we have something that indicates a parameter declaration - if (token === SyntaxKind.ColonToken || token === SyntaxKind.CommaToken || - token === SyntaxKind.QuestionToken || token === SyntaxKind.EqualsToken) { + if (token() === SyntaxKind.ColonToken || token() === SyntaxKind.CommaToken || + token() === SyntaxKind.QuestionToken || token() === SyntaxKind.EqualsToken) { // ( xxx : // ( xxx , // ( xxx ? // ( xxx = return true; } - if (token === SyntaxKind.CloseParenToken) { + if (token() === SyntaxKind.CloseParenToken) { nextToken(); - if (token === SyntaxKind.EqualsGreaterThanToken) { + if (token() === SyntaxKind.EqualsGreaterThanToken) { // ( xxx ) => return true; } @@ -2585,7 +2595,7 @@ namespace ts { function parseTypePredicatePrefix() { const id = parseIdentifier(); - if (token === SyntaxKind.IsKeyword && !scanner.hasPrecedingLineBreak()) { + if (token() === SyntaxKind.IsKeyword && !scanner.hasPrecedingLineBreak()) { nextToken(); return id; } @@ -2601,7 +2611,7 @@ namespace ts { if (isStartOfFunctionType()) { return parseFunctionOrConstructorType(SyntaxKind.FunctionType); } - if (token === SyntaxKind.NewKeyword) { + if (token() === SyntaxKind.NewKeyword) { return parseFunctionOrConstructorType(SyntaxKind.ConstructorType); } return parseUnionTypeOrHigher(); @@ -2613,7 +2623,7 @@ namespace ts { // EXPRESSIONS function isStartOfLeftHandSideExpression(): boolean { - switch (token) { + switch (token()) { case SyntaxKind.ThisKeyword: case SyntaxKind.SuperKeyword: case SyntaxKind.NullKeyword: @@ -2643,7 +2653,7 @@ namespace ts { return true; } - switch (token) { + switch (token()) { case SyntaxKind.PlusToken: case SyntaxKind.MinusToken: case SyntaxKind.TildeToken: @@ -2675,10 +2685,10 @@ namespace ts { function isStartOfExpressionStatement(): boolean { // As per the grammar, none of '{' or 'function' or 'class' can start an expression statement. - return token !== SyntaxKind.OpenBraceToken && - token !== SyntaxKind.FunctionKeyword && - token !== SyntaxKind.ClassKeyword && - token !== SyntaxKind.AtToken && + return token() !== SyntaxKind.OpenBraceToken && + token() !== SyntaxKind.FunctionKeyword && + token() !== SyntaxKind.ClassKeyword && + token() !== SyntaxKind.AtToken && isStartOfExpression(); } @@ -2706,7 +2716,7 @@ namespace ts { } function parseInitializer(inParameter: boolean): Expression { - if (token !== SyntaxKind.EqualsToken) { + if (token() !== SyntaxKind.EqualsToken) { // It's not uncommon during typing for the user to miss writing the '=' token. Check if // there is no newline after the last token and if we're on an expression. If so, parse // this as an equals-value clause with a missing equals. @@ -2715,7 +2725,7 @@ namespace ts { // it's more likely that a { would be a allowed (as an object literal). While this // is also allowed for parameters, the risk is that we consume the { as an object // literal when it really will be for the block following the parameter. - if (scanner.hasPrecedingLineBreak() || (inParameter && token === SyntaxKind.OpenBraceToken) || !isStartOfExpression()) { + if (scanner.hasPrecedingLineBreak() || (inParameter && token() === SyntaxKind.OpenBraceToken) || !isStartOfExpression()) { // preceding line break, open brace in a parameter (likely a function body) or current token is not an expression - // do not try to parse initializer return undefined; @@ -2776,7 +2786,7 @@ namespace ts { // To avoid a look-ahead, we did not handle the case of an arrow function with a single un-parenthesized // parameter ('x => ...') above. We handle it here by checking if the parsed expression was a single // identifier and the current token is an arrow. - if (expr.kind === SyntaxKind.Identifier && token === SyntaxKind.EqualsGreaterThanToken) { + if (expr.kind === SyntaxKind.Identifier && token() === SyntaxKind.EqualsGreaterThanToken) { return parseSimpleArrowFunctionExpression(expr); } @@ -2795,7 +2805,7 @@ namespace ts { } function isYieldExpression(): boolean { - if (token === SyntaxKind.YieldKeyword) { + if (token() === SyntaxKind.YieldKeyword) { // If we have a 'yield' keyword, and this is a context where yield expressions are // allowed, then definitely parse out a yield expression. if (inYieldContext()) { @@ -2837,7 +2847,7 @@ namespace ts { nextToken(); if (!scanner.hasPrecedingLineBreak() && - (token === SyntaxKind.AsteriskToken || isStartOfExpression())) { + (token() === SyntaxKind.AsteriskToken || isStartOfExpression())) { node.asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); node.expression = parseAssignmentExpressionOrHigher(); return finishNode(node); @@ -2850,7 +2860,7 @@ namespace ts { } function parseSimpleArrowFunctionExpression(identifier: Identifier, asyncModifier?: ModifiersArray): ArrowFunction { - Debug.assert(token === SyntaxKind.EqualsGreaterThanToken, "parseSimpleArrowFunctionExpression should only have been called if we had a =>"); + Debug.assert(token() === SyntaxKind.EqualsGreaterThanToken, "parseSimpleArrowFunctionExpression should only have been called if we had a =>"); let node: ArrowFunction; if (asyncModifier) { @@ -2899,7 +2909,7 @@ namespace ts { // If we have an arrow, then try to parse the body. Even if not, try to parse if we // have an opening brace, just in case we're in an error state. - const lastToken = token; + const lastToken = token(); arrowFunction.equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, /*reportAtCurrentPosition*/false, Diagnostics._0_expected, "=>"); arrowFunction.body = (lastToken === SyntaxKind.EqualsGreaterThanToken || lastToken === SyntaxKind.OpenBraceToken) ? parseArrowFunctionExpressionBody(isAsync) @@ -2913,11 +2923,11 @@ namespace ts { // Unknown -> There *might* be a parenthesized arrow function here. // Speculatively look ahead to be sure, and rollback if not. function isParenthesizedArrowFunctionExpression(): Tristate { - if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken || token === SyntaxKind.AsyncKeyword) { + if (token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken || token() === SyntaxKind.AsyncKeyword) { return lookAhead(isParenthesizedArrowFunctionExpressionWorker); } - if (token === SyntaxKind.EqualsGreaterThanToken) { + if (token() === SyntaxKind.EqualsGreaterThanToken) { // ERROR RECOVERY TWEAK: // If we see a standalone => try to parse it as an arrow function expression as that's // likely what the user intended to write. @@ -2928,17 +2938,17 @@ namespace ts { } function isParenthesizedArrowFunctionExpressionWorker() { - if (token === SyntaxKind.AsyncKeyword) { + if (token() === SyntaxKind.AsyncKeyword) { nextToken(); if (scanner.hasPrecedingLineBreak()) { return Tristate.False; } - if (token !== SyntaxKind.OpenParenToken && token !== SyntaxKind.LessThanToken) { + if (token() !== SyntaxKind.OpenParenToken && token() !== SyntaxKind.LessThanToken) { return Tristate.False; } } - const first = token; + const first = token(); const second = nextToken(); if (first === SyntaxKind.OpenParenToken) { @@ -3040,7 +3050,7 @@ namespace ts { function tryParseAsyncSimpleArrowFunctionExpression(): ArrowFunction { // We do a check here so that we won't be doing unnecessarily call to "lookAhead" - if (token === SyntaxKind.AsyncKeyword) { + if (token() === SyntaxKind.AsyncKeyword) { const isUnParenthesizedAsyncArrowFunction = lookAhead(isUnParenthesizedAsyncArrowFunctionWorker); if (isUnParenthesizedAsyncArrowFunction === Tristate.True) { const asyncModifier = parseModifiersForArrowFunction(); @@ -3055,16 +3065,16 @@ namespace ts { // AsyncArrowFunctionExpression: // 1) async[no LineTerminator here]AsyncArrowBindingIdentifier[?Yield][no LineTerminator here]=>AsyncConciseBody[?In] // 2) CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await][no LineTerminator here]=>AsyncConciseBody[?In] - if (token === SyntaxKind.AsyncKeyword) { + if (token() === SyntaxKind.AsyncKeyword) { nextToken(); // If the "async" is followed by "=>" token then it is not a begining of an async arrow-function // but instead a simple arrow-function which will be parsed inside "parseAssignmentExpressionOrHigher" - if (scanner.hasPrecedingLineBreak() || token === SyntaxKind.EqualsGreaterThanToken) { + if (scanner.hasPrecedingLineBreak() || token() === SyntaxKind.EqualsGreaterThanToken) { return Tristate.False; } // Check for un-parenthesized AsyncArrowFunction const expr = parseBinaryExpressionOrHigher(/*precedence*/ 0); - if (!scanner.hasPrecedingLineBreak() && expr.kind === SyntaxKind.Identifier && token === SyntaxKind.EqualsGreaterThanToken) { + if (!scanner.hasPrecedingLineBreak() && expr.kind === SyntaxKind.Identifier && token() === SyntaxKind.EqualsGreaterThanToken) { return Tristate.True; } } @@ -3099,7 +3109,7 @@ namespace ts { // - "a ? (b): c" will have "(b):" parsed as a signature with a return type annotation. // // So we need just a bit of lookahead to ensure that it can only be a signature. - if (!allowAmbiguity && token !== SyntaxKind.EqualsGreaterThanToken && token !== SyntaxKind.OpenBraceToken) { + if (!allowAmbiguity && token() !== SyntaxKind.EqualsGreaterThanToken && token() !== SyntaxKind.OpenBraceToken) { // Returning undefined here will cause our caller to rewind to where we started from. return undefined; } @@ -3108,13 +3118,13 @@ namespace ts { } function parseArrowFunctionExpressionBody(isAsync: boolean): Block | Expression { - if (token === SyntaxKind.OpenBraceToken) { + if (token() === SyntaxKind.OpenBraceToken) { return parseFunctionBlock(/*allowYield*/ false, /*allowAwait*/ isAsync, /*ignoreMissingOpenBrace*/ false); } - if (token !== SyntaxKind.SemicolonToken && - token !== SyntaxKind.FunctionKeyword && - token !== SyntaxKind.ClassKeyword && + if (token() !== SyntaxKind.SemicolonToken && + token() !== SyntaxKind.FunctionKeyword && + token() !== SyntaxKind.ClassKeyword && isStartOfStatement() && !isStartOfExpressionStatement()) { // Check if we got a plain statement (i.e. no expression-statements, no function/class expressions/declarations) @@ -3196,7 +3206,7 @@ namespace ts { // ^^token; leftOperand = b. Return b ** c to the caller as a rightOperand // a ** b - c // ^token; leftOperand = b. Return b to the caller as a rightOperand - const consumeCurrentOperator = token === SyntaxKind.AsteriskAsteriskToken ? + const consumeCurrentOperator = token() === SyntaxKind.AsteriskAsteriskToken ? newPrecedence >= precedence : newPrecedence > precedence; @@ -3204,11 +3214,11 @@ namespace ts { break; } - if (token === SyntaxKind.InKeyword && inDisallowInContext()) { + if (token() === SyntaxKind.InKeyword && inDisallowInContext()) { break; } - if (token === SyntaxKind.AsKeyword) { + if (token() === SyntaxKind.AsKeyword) { // Make sure we *do* perform ASI for constructs like this: // var x = foo // as (Bar) @@ -3231,7 +3241,7 @@ namespace ts { } function isBinaryOperator() { - if (inDisallowInContext() && token === SyntaxKind.InKeyword) { + if (inDisallowInContext() && token() === SyntaxKind.InKeyword) { return false; } @@ -3239,7 +3249,7 @@ namespace ts { } function getBinaryOperatorPrecedence(): number { - switch (token) { + switch (token()) { case SyntaxKind.BarBarToken: return 1; case SyntaxKind.AmpersandAmpersandToken: @@ -3300,7 +3310,7 @@ namespace ts { function parsePrefixUnaryExpression() { const node = createNode(SyntaxKind.PrefixUnaryExpression); - node.operator = token; + node.operator = token(); nextToken(); node.operand = parseSimpleUnaryExpression(); @@ -3329,7 +3339,7 @@ namespace ts { } function isAwaitExpression(): boolean { - if (token === SyntaxKind.AwaitKeyword) { + if (token() === SyntaxKind.AwaitKeyword) { if (inAwaitContext()) { return true; } @@ -3362,14 +3372,14 @@ namespace ts { if (isIncrementExpression()) { const incrementExpression = parseIncrementExpression(); - return token === SyntaxKind.AsteriskAsteriskToken ? + return token() === SyntaxKind.AsteriskAsteriskToken ? parseBinaryExpressionRest(getBinaryOperatorPrecedence(), incrementExpression) : incrementExpression; } - const unaryOperator = token; + const unaryOperator = token(); const simpleUnaryExpression = parseSimpleUnaryExpression(); - if (token === SyntaxKind.AsteriskAsteriskToken) { + if (token() === SyntaxKind.AsteriskAsteriskToken) { const start = skipTrivia(sourceText, simpleUnaryExpression.pos); if (simpleUnaryExpression.kind === SyntaxKind.TypeAssertionExpression) { parseErrorAtPosition(start, simpleUnaryExpression.end - start, Diagnostics.A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses); @@ -3395,7 +3405,7 @@ namespace ts { * 8) ! UnaryExpression[?yield] */ function parseSimpleUnaryExpression(): UnaryExpression { - switch (token) { + switch (token()) { case SyntaxKind.PlusToken: case SyntaxKind.MinusToken: case SyntaxKind.TildeToken: @@ -3430,7 +3440,7 @@ namespace ts { function isIncrementExpression(): boolean { // This function is called inside parseUnaryExpression to decide // whether to call parseSimpleUnaryExpression or call parseIncrementExpression directly - switch (token) { + switch (token()) { case SyntaxKind.PlusToken: case SyntaxKind.MinusToken: case SyntaxKind.TildeToken: @@ -3463,14 +3473,14 @@ namespace ts { * In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression */ function parseIncrementExpression(): IncrementExpression { - if (token === SyntaxKind.PlusPlusToken || token === SyntaxKind.MinusMinusToken) { + if (token() === SyntaxKind.PlusPlusToken || token() === SyntaxKind.MinusMinusToken) { const node = createNode(SyntaxKind.PrefixUnaryExpression); - node.operator = token; + node.operator = token(); nextToken(); node.operand = parseLeftHandSideExpressionOrHigher(); return finishNode(node); } - else if (sourceFile.languageVariant === LanguageVariant.JSX && token === SyntaxKind.LessThanToken && lookAhead(nextTokenIsIdentifierOrKeyword)) { + else if (sourceFile.languageVariant === LanguageVariant.JSX && token() === SyntaxKind.LessThanToken && lookAhead(nextTokenIsIdentifierOrKeyword)) { // JSXElement is part of primaryExpression return parseJsxElementOrSelfClosingElement(/*inExpressionContext*/ true); } @@ -3478,10 +3488,10 @@ namespace ts { const expression = parseLeftHandSideExpressionOrHigher(); Debug.assert(isLeftHandSideExpression(expression)); - if ((token === SyntaxKind.PlusPlusToken || token === SyntaxKind.MinusMinusToken) && !scanner.hasPrecedingLineBreak()) { + if ((token() === SyntaxKind.PlusPlusToken || token() === SyntaxKind.MinusMinusToken) && !scanner.hasPrecedingLineBreak()) { const node = createNode(SyntaxKind.PostfixUnaryExpression, expression.pos); node.operand = expression; - node.operator = token; + node.operator = token(); nextToken(); return finishNode(node); } @@ -3520,7 +3530,7 @@ namespace ts { // the last two CallExpression productions. Or we have a MemberExpression which either // completes the LeftHandSideExpression, or starts the beginning of the first four // CallExpression productions. - const expression = token === SyntaxKind.SuperKeyword + const expression = token() === SyntaxKind.SuperKeyword ? parseSuperExpression() : parseMemberExpressionOrHigher(); @@ -3583,7 +3593,7 @@ namespace ts { function parseSuperExpression(): MemberExpression { const expression = parseTokenNode(); - if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.DotToken || token === SyntaxKind.OpenBracketToken) { + if (token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.DotToken || token() === SyntaxKind.OpenBracketToken) { return expression; } @@ -3646,7 +3656,7 @@ namespace ts { // does less damage and we can report a better error. // Since JSX elements are invalid < operands anyway, this lookahead parse will only occur in error scenarios // of one sort or another. - if (inExpressionContext && token === SyntaxKind.LessThanToken) { + if (inExpressionContext && token() === SyntaxKind.LessThanToken) { const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElement(/*inExpressionContext*/true)); if (invalidElement) { parseErrorAtCurrentToken(Diagnostics.JSX_expressions_must_have_one_parent_element); @@ -3665,12 +3675,12 @@ namespace ts { function parseJsxText(): JsxText { const node = createNode(SyntaxKind.JsxText, scanner.getStartPos()); - token = scanner.scanJsxToken(); + currentToken = scanner.scanJsxToken(); return finishNode(node); } function parseJsxChild(): JsxChild { - switch (token) { + switch (token()) { case SyntaxKind.JsxText: return parseJsxText(); case SyntaxKind.OpenBraceToken: @@ -3678,7 +3688,7 @@ namespace ts { case SyntaxKind.LessThanToken: return parseJsxElementOrSelfClosingElement(/*inExpressionContext*/ false); } - Debug.fail("Unknown JSX child kind " + token); + Debug.fail("Unknown JSX child kind " + token()); } function parseJsxChildren(openingTagName: LeftHandSideExpression): NodeArray { @@ -3688,12 +3698,12 @@ namespace ts { parsingContext |= 1 << ParsingContext.JsxChildren; while (true) { - token = scanner.reScanJsxToken(); - if (token === SyntaxKind.LessThanSlashToken) { + currentToken = scanner.reScanJsxToken(); + if (token() === SyntaxKind.LessThanSlashToken) { // Closing tag break; } - else if (token === SyntaxKind.EndOfFileToken) { + else if (token() === SyntaxKind.EndOfFileToken) { // If we hit EOF, issue the error at the tag that lacks the closing element // rather than at the end of the file (which is useless) parseErrorAtPosition(openingTagName.pos, openingTagName.end - openingTagName.pos, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, openingTagName)); @@ -3719,7 +3729,7 @@ namespace ts { const attributes = parseList(ParsingContext.JsxAttributes, parseJsxAttribute); let node: JsxOpeningLikeElement; - if (token === SyntaxKind.GreaterThanToken) { + if (token() === SyntaxKind.GreaterThanToken) { // Closing tag, so scan the immediately-following text with the JSX scanning instead // of regular scanning to avoid treating illegal characters (e.g. '#') as immediate // scanning errors @@ -3751,7 +3761,7 @@ namespace ts { // primaryExpression in the form of an identifier and "this" keyword // We can't just simply use parseLeftHandSideExpressionOrHigher because then we will start consider class,function etc as a keyword // We only want to consider "this" as a primaryExpression - let expression: JsxTagNameExpression = token === SyntaxKind.ThisKeyword ? + let expression: JsxTagNameExpression = token() === SyntaxKind.ThisKeyword ? parseTokenNode() : parseIdentifierName(); while (parseOptional(SyntaxKind.DotToken)) { const propertyAccess: PropertyAccessExpression = createNode(SyntaxKind.PropertyAccessExpression, expression.pos); @@ -3766,7 +3776,7 @@ namespace ts { const node = createNode(SyntaxKind.JsxExpression); parseExpected(SyntaxKind.OpenBraceToken); - if (token !== SyntaxKind.CloseBraceToken) { + if (token() !== SyntaxKind.CloseBraceToken) { node.expression = parseAssignmentExpressionOrHigher(); } if (inExpressionContext) { @@ -3781,7 +3791,7 @@ namespace ts { } function parseJsxAttribute(): JsxAttribute | JsxSpreadAttribute { - if (token === SyntaxKind.OpenBraceToken) { + if (token() === SyntaxKind.OpenBraceToken) { return parseJsxSpreadAttribute(); } @@ -3789,7 +3799,7 @@ namespace ts { const node = createNode(SyntaxKind.JsxAttribute); node.name = parseIdentifierName(); if (parseOptional(SyntaxKind.EqualsToken)) { - switch (token) { + switch (token()) { case SyntaxKind.StringLiteral: node.initializer = parseLiteralNode(); break; @@ -3844,7 +3854,7 @@ namespace ts { continue; } - if (token === SyntaxKind.ExclamationToken && !scanner.hasPrecedingLineBreak()) { + if (token() === SyntaxKind.ExclamationToken && !scanner.hasPrecedingLineBreak()) { nextToken(); const nonNullExpression = createNode(SyntaxKind.NonNullExpression, expression.pos); nonNullExpression.expression = expression; @@ -3859,7 +3869,7 @@ namespace ts { // It's not uncommon for a user to write: "new Type[]". // Check for that common pattern and report a better error message. - if (token !== SyntaxKind.CloseBracketToken) { + if (token() !== SyntaxKind.CloseBracketToken) { indexedAccess.argumentExpression = allowInAnd(parseExpression); if (indexedAccess.argumentExpression.kind === SyntaxKind.StringLiteral || indexedAccess.argumentExpression.kind === SyntaxKind.NumericLiteral) { const literal = indexedAccess.argumentExpression; @@ -3872,10 +3882,10 @@ namespace ts { continue; } - if (token === SyntaxKind.NoSubstitutionTemplateLiteral || token === SyntaxKind.TemplateHead) { + if (token() === SyntaxKind.NoSubstitutionTemplateLiteral || token() === SyntaxKind.TemplateHead) { const tagExpression = createNode(SyntaxKind.TaggedTemplateExpression, expression.pos); tagExpression.tag = expression; - tagExpression.template = token === SyntaxKind.NoSubstitutionTemplateLiteral + tagExpression.template = token() === SyntaxKind.NoSubstitutionTemplateLiteral ? parseLiteralNode() : parseTemplateExpression(); expression = finishNode(tagExpression); @@ -3889,7 +3899,7 @@ namespace ts { function parseCallExpressionRest(expression: LeftHandSideExpression): LeftHandSideExpression { while (true) { expression = parseMemberExpressionRest(expression); - if (token === SyntaxKind.LessThanToken) { + if (token() === SyntaxKind.LessThanToken) { // See if this is the start of a generic invocation. If so, consume it and // keep checking for postfix expressions. Otherwise, it's just a '<' that's // part of an arithmetic expression. Break out so we consume it higher in the @@ -3906,7 +3916,7 @@ namespace ts { expression = finishNode(callExpr); continue; } - else if (token === SyntaxKind.OpenParenToken) { + else if (token() === SyntaxKind.OpenParenToken) { const callExpr = createNode(SyntaxKind.CallExpression, expression.pos); callExpr.expression = expression; callExpr.arguments = parseArgumentList(); @@ -3944,7 +3954,7 @@ namespace ts { } function canFollowTypeArgumentsInExpression(): boolean { - switch (token) { + switch (token()) { case SyntaxKind.OpenParenToken: // foo( // this case are the only case where this token can legally follow a type argument // list. So we definitely want to treat this as a type arg list. @@ -3984,7 +3994,7 @@ namespace ts { } function parsePrimaryExpression(): PrimaryExpression { - switch (token) { + switch (token()) { case SyntaxKind.NumericLiteral: case SyntaxKind.StringLiteral: case SyntaxKind.NoSubstitutionTemplateLiteral: @@ -4045,8 +4055,8 @@ namespace ts { } function parseArgumentOrArrayLiteralElement(): Expression { - return token === SyntaxKind.DotDotDotToken ? parseSpreadElement() : - token === SyntaxKind.CommaToken ? createNode(SyntaxKind.OmittedExpression) : + return token() === SyntaxKind.DotDotDotToken ? parseSpreadElement() : + token() === SyntaxKind.CommaToken ? createNode(SyntaxKind.OmittedExpression) : parseAssignmentExpressionOrHigher(); } @@ -4092,7 +4102,7 @@ namespace ts { // Disallowing of optional property assignments happens in the grammar checker. const questionToken = parseOptionalToken(SyntaxKind.QuestionToken); - if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { + if (asteriskToken || token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken) { return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, propertyName, questionToken); } @@ -4102,7 +4112,7 @@ namespace ts { // IdentifierReference[?Yield] Initializer[In, ?Yield] // this is necessary because ObjectLiteral productions are also used to cover grammar for ObjectAssignmentPattern const isShorthandPropertyAssignment = - tokenIsIdentifier && (token === SyntaxKind.CommaToken || token === SyntaxKind.CloseBraceToken || token === SyntaxKind.EqualsToken); + tokenIsIdentifier && (token() === SyntaxKind.CommaToken || token() === SyntaxKind.CloseBraceToken || token() === SyntaxKind.EqualsToken); if (isShorthandPropertyAssignment) { const shorthandDeclaration = createNode(SyntaxKind.ShorthandPropertyAssignment, fullStart); @@ -4181,7 +4191,7 @@ namespace ts { parseExpected(SyntaxKind.NewKeyword); node.expression = parseMemberExpressionOrHigher(); node.typeArguments = tryParse(parseTypeArgumentsInExpression); - if (node.typeArguments || token === SyntaxKind.OpenParenToken) { + if (node.typeArguments || token() === SyntaxKind.OpenParenToken) { node.arguments = parseArgumentList(); } @@ -4277,8 +4287,8 @@ namespace ts { parseExpected(SyntaxKind.OpenParenToken); let initializer: VariableDeclarationList | Expression = undefined; - if (token !== SyntaxKind.SemicolonToken) { - if (token === SyntaxKind.VarKeyword || token === SyntaxKind.LetKeyword || token === SyntaxKind.ConstKeyword) { + if (token() !== SyntaxKind.SemicolonToken) { + if (token() === SyntaxKind.VarKeyword || token() === SyntaxKind.LetKeyword || token() === SyntaxKind.ConstKeyword) { initializer = parseVariableDeclarationList(/*inForStatementInitializer*/ true); } else { @@ -4304,11 +4314,11 @@ namespace ts { const forStatement = createNode(SyntaxKind.ForStatement, pos); forStatement.initializer = initializer; parseExpected(SyntaxKind.SemicolonToken); - if (token !== SyntaxKind.SemicolonToken && token !== SyntaxKind.CloseParenToken) { + if (token() !== SyntaxKind.SemicolonToken && token() !== SyntaxKind.CloseParenToken) { forStatement.condition = allowInAnd(parseExpression); } parseExpected(SyntaxKind.SemicolonToken); - if (token !== SyntaxKind.CloseParenToken) { + if (token() !== SyntaxKind.CloseParenToken) { forStatement.incrementor = allowInAnd(parseExpression); } parseExpected(SyntaxKind.CloseParenToken); @@ -4372,7 +4382,7 @@ namespace ts { } function parseCaseOrDefaultClause(): CaseOrDefaultClause { - return token === SyntaxKind.CaseKeyword ? parseCaseClause() : parseDefaultClause(); + return token() === SyntaxKind.CaseKeyword ? parseCaseClause() : parseDefaultClause(); } function parseSwitchStatement(): SwitchStatement { @@ -4411,11 +4421,11 @@ namespace ts { parseExpected(SyntaxKind.TryKeyword); node.tryBlock = parseBlock(/*ignoreMissingOpenBrace*/ false); - node.catchClause = token === SyntaxKind.CatchKeyword ? parseCatchClause() : undefined; + node.catchClause = token() === SyntaxKind.CatchKeyword ? parseCatchClause() : undefined; // If we don't have a catch clause, then we must have a finally clause. Try to parse // one out no matter what. - if (!node.catchClause || token === SyntaxKind.FinallyKeyword) { + if (!node.catchClause || token() === SyntaxKind.FinallyKeyword) { parseExpected(SyntaxKind.FinallyKeyword); node.finallyBlock = parseBlock(/*ignoreMissingOpenBrace*/ false); } @@ -4465,22 +4475,22 @@ namespace ts { function nextTokenIsIdentifierOrKeywordOnSameLine() { nextToken(); - return tokenIsIdentifierOrKeyword(token) && !scanner.hasPrecedingLineBreak(); + return tokenIsIdentifierOrKeyword(token()) && !scanner.hasPrecedingLineBreak(); } function nextTokenIsFunctionKeywordOnSameLine() { nextToken(); - return token === SyntaxKind.FunctionKeyword && !scanner.hasPrecedingLineBreak(); + return token() === SyntaxKind.FunctionKeyword && !scanner.hasPrecedingLineBreak(); } function nextTokenIsIdentifierOrKeywordOrNumberOnSameLine() { nextToken(); - return (tokenIsIdentifierOrKeyword(token) || token === SyntaxKind.NumericLiteral) && !scanner.hasPrecedingLineBreak(); + return (tokenIsIdentifierOrKeyword(token()) || token() === SyntaxKind.NumericLiteral) && !scanner.hasPrecedingLineBreak(); } function isDeclaration(): boolean { while (true) { - switch (token) { + switch (token()) { case SyntaxKind.VarKeyword: case SyntaxKind.LetKeyword: case SyntaxKind.ConstKeyword: @@ -4532,17 +4542,17 @@ namespace ts { case SyntaxKind.GlobalKeyword: nextToken(); - return token === SyntaxKind.OpenBraceToken || token === SyntaxKind.Identifier || token === SyntaxKind.ExportKeyword; + return token() === SyntaxKind.OpenBraceToken || token() === SyntaxKind.Identifier || token() === SyntaxKind.ExportKeyword; case SyntaxKind.ImportKeyword: nextToken(); - return token === SyntaxKind.StringLiteral || token === SyntaxKind.AsteriskToken || - token === SyntaxKind.OpenBraceToken || tokenIsIdentifierOrKeyword(token); + return token() === SyntaxKind.StringLiteral || token() === SyntaxKind.AsteriskToken || + token() === SyntaxKind.OpenBraceToken || tokenIsIdentifierOrKeyword(token()); case SyntaxKind.ExportKeyword: nextToken(); - if (token === SyntaxKind.EqualsToken || token === SyntaxKind.AsteriskToken || - token === SyntaxKind.OpenBraceToken || token === SyntaxKind.DefaultKeyword || - token === SyntaxKind.AsKeyword) { + if (token() === SyntaxKind.EqualsToken || token() === SyntaxKind.AsteriskToken || + token() === SyntaxKind.OpenBraceToken || token() === SyntaxKind.DefaultKeyword || + token() === SyntaxKind.AsKeyword) { return true; } continue; @@ -4561,7 +4571,7 @@ namespace ts { } function isStartOfStatement(): boolean { - switch (token) { + switch (token()) { case SyntaxKind.AtToken: case SyntaxKind.SemicolonToken: case SyntaxKind.OpenBraceToken: @@ -4619,7 +4629,7 @@ namespace ts { function nextTokenIsIdentifierOrStartOfDestructuring() { nextToken(); - return isIdentifier() || token === SyntaxKind.OpenBraceToken || token === SyntaxKind.OpenBracketToken; + return isIdentifier() || token() === SyntaxKind.OpenBraceToken || token() === SyntaxKind.OpenBracketToken; } function isLetDeclaration() { @@ -4629,7 +4639,7 @@ namespace ts { } function parseStatement(): Statement { - switch (token) { + switch (token()) { case SyntaxKind.SemicolonToken: return parseEmptyStatement(); case SyntaxKind.OpenBraceToken: @@ -4703,7 +4713,7 @@ namespace ts { const fullStart = getNodePos(); const decorators = parseDecorators(); const modifiers = parseModifiers(); - switch (token) { + switch (token()) { case SyntaxKind.VarKeyword: case SyntaxKind.LetKeyword: case SyntaxKind.ConstKeyword: @@ -4726,7 +4736,7 @@ namespace ts { return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); case SyntaxKind.ExportKeyword: nextToken(); - switch (token) { + switch (token()) { case SyntaxKind.DefaultKeyword: case SyntaxKind.EqualsToken: return parseExportAssignment(fullStart, decorators, modifiers); @@ -4750,11 +4760,11 @@ namespace ts { function nextTokenIsIdentifierOrStringLiteralOnSameLine() { nextToken(); - return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token === SyntaxKind.StringLiteral); + return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token() === SyntaxKind.StringLiteral); } function parseFunctionBlockOrSemicolon(isGenerator: boolean, isAsync: boolean, diagnosticMessage?: DiagnosticMessage): Block { - if (token !== SyntaxKind.OpenBraceToken && canParseSemicolon()) { + if (token() !== SyntaxKind.OpenBraceToken && canParseSemicolon()) { parseSemicolon(); return; } @@ -4765,7 +4775,7 @@ namespace ts { // DECLARATIONS function parseArrayBindingElement(): BindingElement { - if (token === SyntaxKind.CommaToken) { + if (token() === SyntaxKind.CommaToken) { return createNode(SyntaxKind.OmittedExpression); } const node = createNode(SyntaxKind.BindingElement); @@ -4779,7 +4789,7 @@ namespace ts { const node = createNode(SyntaxKind.BindingElement); const tokenIsIdentifier = isIdentifier(); const propertyName = parsePropertyName(); - if (tokenIsIdentifier && token !== SyntaxKind.ColonToken) { + if (tokenIsIdentifier && token() !== SyntaxKind.ColonToken) { node.name = propertyName; } else { @@ -4808,14 +4818,14 @@ namespace ts { } function isIdentifierOrPattern() { - return token === SyntaxKind.OpenBraceToken || token === SyntaxKind.OpenBracketToken || isIdentifier(); + return token() === SyntaxKind.OpenBraceToken || token() === SyntaxKind.OpenBracketToken || isIdentifier(); } function parseIdentifierOrPattern(): Identifier | BindingPattern { - if (token === SyntaxKind.OpenBracketToken) { + if (token() === SyntaxKind.OpenBracketToken) { return parseArrayBindingPattern(); } - if (token === SyntaxKind.OpenBraceToken) { + if (token() === SyntaxKind.OpenBraceToken) { return parseObjectBindingPattern(); } return parseIdentifier(); @@ -4825,7 +4835,7 @@ namespace ts { const node = createNode(SyntaxKind.VariableDeclaration); node.name = parseIdentifierOrPattern(); node.type = parseTypeAnnotation(); - if (!isInOrOfKeyword(token)) { + if (!isInOrOfKeyword(token())) { node.initializer = parseInitializer(/*inParameter*/ false); } return finishNode(node); @@ -4834,7 +4844,7 @@ namespace ts { function parseVariableDeclarationList(inForStatementInitializer: boolean): VariableDeclarationList { const node = createNode(SyntaxKind.VariableDeclarationList); - switch (token) { + switch (token()) { case SyntaxKind.VarKeyword: break; case SyntaxKind.LetKeyword: @@ -4858,7 +4868,7 @@ namespace ts { // So we need to look ahead to determine if 'of' should be treated as a keyword in // this context. // The checker will then give an error that there is an empty declaration list. - if (token === SyntaxKind.OfKeyword && lookAhead(canFollowContextualOfKeyword)) { + if (token() === SyntaxKind.OfKeyword && lookAhead(canFollowContextualOfKeyword)) { node.declarations = createMissingList(); } else { @@ -4956,7 +4966,7 @@ namespace ts { // Note: this is not legal as per the grammar. But we allow it in the parser and // report an error in the grammar checker. const questionToken = parseOptionalToken(SyntaxKind.QuestionToken); - if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { + if (asteriskToken || token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken) { return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, Diagnostics.or_expected); } else { @@ -4994,13 +5004,13 @@ namespace ts { function isClassMemberStart(): boolean { let idToken: SyntaxKind; - if (token === SyntaxKind.AtToken) { + if (token() === SyntaxKind.AtToken) { return true; } // Eat up all modifiers, but hold on to the last one in case it is actually an identifier. - while (isModifierKind(token)) { - idToken = token; + while (isModifierKind(token())) { + idToken = token(); // If the idToken is a class modifier (protected, private, public, and static), it is // certain that we are starting to parse class member. This allows better error recovery // Example: @@ -5014,19 +5024,19 @@ namespace ts { nextToken(); } - if (token === SyntaxKind.AsteriskToken) { + if (token() === SyntaxKind.AsteriskToken) { return true; } // Try to get the first property-like token following all modifiers. // This can either be an identifier or the 'get' or 'set' keywords. if (isLiteralPropertyName()) { - idToken = token; + idToken = token(); nextToken(); } // Index signatures and computed properties are class members; we can parse. - if (token === SyntaxKind.OpenBracketToken) { + if (token() === SyntaxKind.OpenBracketToken) { return true; } @@ -5039,7 +5049,7 @@ namespace ts { // If it *is* a keyword, but not an accessor, check a little farther along // to see if it should actually be parsed as a class member. - switch (token) { + switch (token()) { case SyntaxKind.OpenParenToken: // Method declaration case SyntaxKind.LessThanToken: // Generic Method declaration case SyntaxKind.ColonToken: // Type Annotation for declaration @@ -5094,9 +5104,9 @@ namespace ts { let modifiers: ModifiersArray; while (true) { const modifierStart = scanner.getStartPos(); - const modifierKind = token; + const modifierKind = token(); - if (token === SyntaxKind.ConstKeyword && permitInvalidConstAsModifier) { + if (token() === SyntaxKind.ConstKeyword && permitInvalidConstAsModifier) { // We need to ensure that any subsequent modifiers appear on the same line // so that when 'const' is a standalone declaration, we don't issue an error. if (!tryParse(nextTokenIsOnSameLineAndCanFollowModifier)) { @@ -5127,9 +5137,9 @@ namespace ts { function parseModifiersForArrowFunction(): ModifiersArray { let flags = 0; let modifiers: ModifiersArray; - if (token === SyntaxKind.AsyncKeyword) { + if (token() === SyntaxKind.AsyncKeyword) { const modifierStart = scanner.getStartPos(); - const modifierKind = token; + const modifierKind = token(); nextToken(); modifiers = []; modifiers.pos = modifierStart; @@ -5143,7 +5153,7 @@ namespace ts { } function parseClassElement(): ClassElement { - if (token === SyntaxKind.SemicolonToken) { + if (token() === SyntaxKind.SemicolonToken) { const result = createNode(SyntaxKind.SemicolonClassElement); nextToken(); return finishNode(result); @@ -5158,7 +5168,7 @@ namespace ts { return accessor; } - if (token === SyntaxKind.ConstructorKeyword) { + if (token() === SyntaxKind.ConstructorKeyword) { return parseConstructorDeclaration(fullStart, decorators, modifiers); } @@ -5168,11 +5178,11 @@ namespace ts { // It is very important that we check this *after* checking indexers because // the [ token can start an index signature or a computed property name - if (tokenIsIdentifierOrKeyword(token) || - token === SyntaxKind.StringLiteral || - token === SyntaxKind.NumericLiteral || - token === SyntaxKind.AsteriskToken || - token === SyntaxKind.OpenBracketToken) { + if (tokenIsIdentifierOrKeyword(token()) || + token() === SyntaxKind.StringLiteral || + token() === SyntaxKind.NumericLiteral || + token() === SyntaxKind.AsteriskToken || + token() === SyntaxKind.OpenBracketToken) { return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); } @@ -5233,7 +5243,7 @@ namespace ts { } function isImplementsClause() { - return token === SyntaxKind.ImplementsKeyword && lookAhead(nextTokenIsIdentifierOrKeyword); + return token() === SyntaxKind.ImplementsKeyword && lookAhead(nextTokenIsIdentifierOrKeyword); } function parseHeritageClauses(isClassHeritageClause: boolean): NodeArray { @@ -5248,9 +5258,9 @@ namespace ts { } function parseHeritageClause() { - if (token === SyntaxKind.ExtendsKeyword || token === SyntaxKind.ImplementsKeyword) { + if (token() === SyntaxKind.ExtendsKeyword || token() === SyntaxKind.ImplementsKeyword) { const node = createNode(SyntaxKind.HeritageClause); - node.token = token; + node.token = token(); nextToken(); node.types = parseDelimitedList(ParsingContext.HeritageClauseElement, parseExpressionWithTypeArguments); return finishNode(node); @@ -5262,7 +5272,7 @@ namespace ts { function parseExpressionWithTypeArguments(): ExpressionWithTypeArguments { const node = createNode(SyntaxKind.ExpressionWithTypeArguments); node.expression = parseLeftHandSideExpressionOrHigher(); - if (token === SyntaxKind.LessThanToken) { + if (token() === SyntaxKind.LessThanToken) { node.typeArguments = parseBracketedList(ParsingContext.TypeArguments, parseType, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken); } @@ -5270,7 +5280,7 @@ namespace ts { } function isHeritageClause(): boolean { - return token === SyntaxKind.ExtendsKeyword || token === SyntaxKind.ImplementsKeyword; + return token() === SyntaxKind.ExtendsKeyword || token() === SyntaxKind.ImplementsKeyword; } function parseClassMembers() { @@ -5360,7 +5370,7 @@ namespace ts { const node = createNode(SyntaxKind.ModuleDeclaration, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - if (token === SyntaxKind.GlobalKeyword) { + if (token() === SyntaxKind.GlobalKeyword) { // parse 'global' as name of global scope augmentation node.name = parseIdentifier(); node.flags |= NodeFlags.GlobalAugmentation; @@ -5369,7 +5379,7 @@ namespace ts { node.name = parseLiteralNode(/*internName*/ true); } - if (token === SyntaxKind.OpenBraceToken) { + if (token() === SyntaxKind.OpenBraceToken) { node.body = parseModuleBlock(); } else { @@ -5381,7 +5391,7 @@ namespace ts { function parseModuleDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ModuleDeclaration { let flags = modifiers ? modifiers.flags : 0; - if (token === SyntaxKind.GlobalKeyword) { + if (token() === SyntaxKind.GlobalKeyword) { // global augmentation return parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers); } @@ -5390,7 +5400,7 @@ namespace ts { } else { parseExpected(SyntaxKind.ModuleKeyword); - if (token === SyntaxKind.StringLiteral) { + if (token() === SyntaxKind.StringLiteral) { return parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers); } } @@ -5398,7 +5408,7 @@ namespace ts { } function isExternalModuleReference() { - return token === SyntaxKind.RequireKeyword && + return token() === SyntaxKind.RequireKeyword && lookAhead(nextTokenIsOpenParen); } @@ -5431,7 +5441,7 @@ namespace ts { let identifier: Identifier; if (isIdentifier()) { identifier = parseIdentifier(); - if (token !== SyntaxKind.CommaToken && token !== SyntaxKind.FromKeyword) { + if (token() !== SyntaxKind.CommaToken && token() !== SyntaxKind.FromKeyword) { // ImportEquals declaration of type: // import x = require("mod"); or // import x = M.x; @@ -5455,8 +5465,8 @@ namespace ts { // import ImportClause from ModuleSpecifier ; // import ModuleSpecifier; if (identifier || // import id - token === SyntaxKind.AsteriskToken || // import * - token === SyntaxKind.OpenBraceToken) { // import { + token() === SyntaxKind.AsteriskToken || // import * + token() === SyntaxKind.OpenBraceToken) { // import { importDeclaration.importClause = parseImportClause(identifier, afterImportPos); parseExpected(SyntaxKind.FromKeyword); } @@ -5485,7 +5495,7 @@ namespace ts { // parse namespace or named imports if (!importClause.name || parseOptional(SyntaxKind.CommaToken)) { - importClause.namedBindings = token === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImportsOrExports(SyntaxKind.NamedImports); + importClause.namedBindings = token() === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImportsOrExports(SyntaxKind.NamedImports); } return finishNode(importClause); @@ -5507,7 +5517,7 @@ namespace ts { } function parseModuleSpecifier(): Expression { - if (token === SyntaxKind.StringLiteral) { + if (token() === SyntaxKind.StringLiteral) { const result = parseLiteralNode(); internIdentifier((result).text); return result; @@ -5563,14 +5573,14 @@ namespace ts { // ExportSpecifier: // IdentifierName // IdentifierName as IdentifierName - let checkIdentifierIsKeyword = isKeyword(token) && !isIdentifier(); + let checkIdentifierIsKeyword = isKeyword(token()) && !isIdentifier(); let checkIdentifierStart = scanner.getTokenPos(); let checkIdentifierEnd = scanner.getTextPos(); const identifierName = parseIdentifierName(); - if (token === SyntaxKind.AsKeyword) { + if (token() === SyntaxKind.AsKeyword) { node.propertyName = identifierName; parseExpected(SyntaxKind.AsKeyword); - checkIdentifierIsKeyword = isKeyword(token) && !isIdentifier(); + checkIdentifierIsKeyword = isKeyword(token()) && !isIdentifier(); checkIdentifierStart = scanner.getTokenPos(); checkIdentifierEnd = scanner.getTextPos(); node.name = parseIdentifierName(); @@ -5599,7 +5609,7 @@ namespace ts { // It is not uncommon to accidentally omit the 'from' keyword. Additionally, in editing scenarios, // the 'from' keyword can be parsed as a named export when the export clause is unterminated (i.e. `export { from "moduleName";`) // If we don't have a 'from' keyword, see if we have a string literal such that ASI won't take effect. - if (token === SyntaxKind.FromKeyword || (token === SyntaxKind.StringLiteral && !scanner.hasPrecedingLineBreak())) { + if (token() === SyntaxKind.FromKeyword || (token() === SyntaxKind.StringLiteral && !scanner.hasPrecedingLineBreak())) { parseExpected(SyntaxKind.FromKeyword); node.moduleSpecifier = parseModuleSpecifier(); } @@ -5744,7 +5754,7 @@ namespace ts { export namespace JSDocParser { export function isJSDocType() { - switch (token) { + switch (token()) { case SyntaxKind.AsteriskToken: case SyntaxKind.QuestionToken: case SyntaxKind.OpenParenToken: @@ -5758,13 +5768,13 @@ namespace ts { return true; } - return tokenIsIdentifierOrKeyword(token); + return tokenIsIdentifierOrKeyword(token()); } export function parseJSDocTypeExpressionForTests(content: string, start: number, length: number) { initializeState("file.js", content, ScriptTarget.Latest, /*_syntaxCursor:*/ undefined, ScriptKind.JS); scanner.setText(content, start, length); - token = scanner.scan(); + currentToken = scanner.scan(); const jsDocTypeExpression = parseJSDocTypeExpression(); const diagnostics = parseDiagnostics; clearState(); @@ -5787,13 +5797,13 @@ namespace ts { function parseJSDocTopLevelType(): JSDocType { let type = parseJSDocType(); - if (token === SyntaxKind.BarToken) { + if (token() === SyntaxKind.BarToken) { const unionType = createNode(SyntaxKind.JSDocUnionType, type.pos); unionType.types = parseJSDocTypeList(type); type = finishNode(unionType); } - if (token === SyntaxKind.EqualsToken) { + if (token() === SyntaxKind.EqualsToken) { const optionalType = createNode(SyntaxKind.JSDocOptionalType, type.pos); nextToken(); optionalType.type = type; @@ -5807,7 +5817,7 @@ namespace ts { let type = parseBasicTypeExpression(); while (true) { - if (token === SyntaxKind.OpenBracketToken) { + if (token() === SyntaxKind.OpenBracketToken) { const arrayType = createNode(SyntaxKind.JSDocArrayType, type.pos); arrayType.elementType = type; @@ -5816,14 +5826,14 @@ namespace ts { type = finishNode(arrayType); } - else if (token === SyntaxKind.QuestionToken) { + else if (token() === SyntaxKind.QuestionToken) { const nullableType = createNode(SyntaxKind.JSDocNullableType, type.pos); nullableType.type = type; nextToken(); type = finishNode(nullableType); } - else if (token === SyntaxKind.ExclamationToken) { + else if (token() === SyntaxKind.ExclamationToken) { const nonNullableType = createNode(SyntaxKind.JSDocNonNullableType, type.pos); nonNullableType.type = type; @@ -5839,7 +5849,7 @@ namespace ts { } function parseBasicTypeExpression(): JSDocType { - switch (token) { + switch (token()) { case SyntaxKind.AsteriskToken: return parseJSDocAllType(); case SyntaxKind.QuestionToken: @@ -5905,7 +5915,7 @@ namespace ts { checkForTrailingComma(result.parameters); parseExpected(SyntaxKind.CloseParenToken); - if (token === SyntaxKind.ColonToken) { + if (token() === SyntaxKind.ColonToken) { nextToken(); result.type = parseJSDocType(); } @@ -5926,12 +5936,12 @@ namespace ts { const result = createNode(SyntaxKind.JSDocTypeReference); result.name = parseSimplePropertyName(); - if (token === SyntaxKind.LessThanToken) { + if (token() === SyntaxKind.LessThanToken) { result.typeArguments = parseTypeArguments(); } else { while (parseOptional(SyntaxKind.DotToken)) { - if (token === SyntaxKind.LessThanToken) { + if (token() === SyntaxKind.LessThanToken) { result.typeArguments = parseTypeArguments(); break; } @@ -5985,7 +5995,7 @@ namespace ts { const result = createNode(SyntaxKind.JSDocRecordMember); result.name = parseSimplePropertyName(); - if (token === SyntaxKind.ColonToken) { + if (token() === SyntaxKind.ColonToken) { nextToken(); result.type = parseJSDocType(); } @@ -6063,12 +6073,12 @@ namespace ts { // Foo // Foo(?= // (?| - if (token === SyntaxKind.CommaToken || - token === SyntaxKind.CloseBraceToken || - token === SyntaxKind.CloseParenToken || - token === SyntaxKind.GreaterThanToken || - token === SyntaxKind.EqualsToken || - token === SyntaxKind.BarToken) { + if (token() === SyntaxKind.CommaToken || + token() === SyntaxKind.CloseBraceToken || + token() === SyntaxKind.CloseParenToken || + token() === SyntaxKind.GreaterThanToken || + token() === SyntaxKind.EqualsToken || + token() === SyntaxKind.BarToken) { const result = createNode(SyntaxKind.JSDocUnknownType, pos); return finishNode(result); @@ -6091,7 +6101,7 @@ namespace ts { } export function parseJSDocComment(parent: Node, start: number, length: number): JSDocComment { - const saveToken = token; + const saveToken = currentToken; const saveParseDiagnosticsLength = parseDiagnostics.length; const saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; @@ -6100,7 +6110,7 @@ namespace ts { comment.parent = parent; } - token = saveToken; + currentToken = saveToken; parseDiagnostics.length = saveParseDiagnosticsLength; parseErrorBeforeNextFinishedNode = saveParseErrorBeforeNextFinishedNode; @@ -6135,8 +6145,8 @@ namespace ts { let seenAsterisk = true; nextJSDocToken(); - while (token !== SyntaxKind.EndOfFileToken) { - switch (token) { + while (token() !== SyntaxKind.EndOfFileToken) { + switch (token()) { case SyntaxKind.AtToken: if (canParseTag) { parseTag(); @@ -6192,13 +6202,13 @@ namespace ts { } function skipWhitespace(): void { - while (token === SyntaxKind.WhitespaceTrivia || token === SyntaxKind.NewLineTrivia) { + while (token() === SyntaxKind.WhitespaceTrivia || token() === SyntaxKind.NewLineTrivia) { nextJSDocToken(); } } function parseTag(): void { - Debug.assert(token === SyntaxKind.AtToken); + Debug.assert(token() === SyntaxKind.AtToken); const atToken = createNode(SyntaxKind.AtToken, scanner.getTokenPos()); atToken.end = scanner.getTextPos(); nextJSDocToken(); @@ -6252,7 +6262,7 @@ namespace ts { } function tryParseTypeExpression(): JSDocTypeExpression { - if (token !== SyntaxKind.OpenBraceToken) { + if (token() !== SyntaxKind.OpenBraceToken) { return undefined; } @@ -6278,7 +6288,7 @@ namespace ts { parseExpected(SyntaxKind.CloseBracketToken); } - else if (tokenIsIdentifierOrKeyword(token)) { + else if (tokenIsIdentifierOrKeyword(token())) { name = parseJSDocIdentifierName(); } @@ -6387,9 +6397,9 @@ namespace ts { let seenAsterisk = false; let parentTagTerminated = false; - while (token !== SyntaxKind.EndOfFileToken && !parentTagTerminated) { + while (token() !== SyntaxKind.EndOfFileToken && !parentTagTerminated) { nextJSDocToken(); - switch (token) { + switch (token()) { case SyntaxKind.AtToken: if (canParseTag) { parentTagTerminated = !tryParseChildTag(jsDocTypeLiteral); @@ -6419,7 +6429,7 @@ namespace ts { } function tryParseChildTag(parentTag: JSDocTypeLiteral): boolean { - Debug.assert(token === SyntaxKind.AtToken); + Debug.assert(token() === SyntaxKind.AtToken); const atToken = createNode(SyntaxKind.AtToken, scanner.getStartPos()); atToken.end = scanner.getTextPos(); nextJSDocToken(); @@ -6471,7 +6481,7 @@ namespace ts { typeParameters.push(typeParameter); - if (token === SyntaxKind.CommaToken) { + if (token() === SyntaxKind.CommaToken) { nextJSDocToken(); } else { @@ -6489,11 +6499,11 @@ namespace ts { } function nextJSDocToken(): SyntaxKind { - return token = scanner.scanJSDocToken(); + return currentToken = scanner.scanJSDocToken(); } function parseJSDocIdentifierName(): Identifier { - return createJSDocIdentifier(tokenIsIdentifierOrKeyword(token)); + return createJSDocIdentifier(tokenIsIdentifierOrKeyword(token())); } function createJSDocIdentifier(isIdentifier: boolean): Identifier {