diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index f4ac24c5fc8..ed7ecd6c9f6 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -983,25 +983,22 @@ module ts { } function nextTokenCanFollowModifierForArrowFunction() { - return nextTokenCanFollowModifier(/*isArrowFunction*/ true); + nextToken(); + return canFollowModifierForArrowFunction(); } - function nextTokenCanFollowModifier(isArrowFunction?: boolean) { + function nextTokenCanFollowModifier() { nextToken(); - return canFollowModifier(isArrowFunction); + return canFollowModifier(); } function parseAnyContextualModifier(isArrowFunction?: boolean): boolean { return isModifier(token) && tryParse(isArrowFunction - ? nextTokenCanFollowContextualModifierForArrowFunction + ? nextTokenCanFollowModifierForArrowFunction : nextTokenCanFollowContextualModifier); } - function nextTokenCanFollowContextualModifierForArrowFunction() { - return nextTokenCanFollowContextualModifier(/*isArrowFunction*/ true); - } - - function nextTokenCanFollowContextualModifier(isArrowFunction?: boolean) { + function nextTokenCanFollowContextualModifier() { if (token === SyntaxKind.ConstKeyword) { // 'const' is only a modifier if followed by 'enum'. return nextToken() === SyntaxKind.EnumKeyword; @@ -1017,24 +1014,24 @@ module ts { return nextTokenIsClassOrFunction(); } nextToken(); - return canFollowModifier(isArrowFunction); + return canFollowModifier(); } - - function canFollowModifier(isArrowFunction?: boolean): boolean { + + function canFollowModifierForArrowFunction(): boolean { // Arrow functions can have an `async` modifier, but the rules for what can follow that modifier // differ from the rules for any other declaration. // The `async` modifier on an async function can only be followed by an open parenthesis, // or a less than token (in the case of a generic arrow function). // In addition, the `async` modifier must appear on the same line as the following token. - if (isArrowFunction) { - if (scanner.hasPrecedingLineBreak()) { - return false; - } - - return token === SyntaxKind.OpenParenToken - || token === SyntaxKind.LessThanToken; + if (scanner.hasPrecedingLineBreak()) { + return false; } - + + return token === SyntaxKind.OpenParenToken + || token === SyntaxKind.LessThanToken; + } + + function canFollowModifier(): boolean { return token === SyntaxKind.OpenBracketToken || token === SyntaxKind.OpenBraceToken || token === SyntaxKind.AsteriskToken diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 29206c53f39..0b5df05ff00 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -344,11 +344,11 @@ module ts { // If this node was parsed as part of a decorator Decorator = 1 << 4, - // If this node was parsed in the parameters of an async function. - AsyncParameter = 1 << 5, - // If this node was parsed in the 'await' context created when parsing an async function. - Await = 1 << 6, + Await = 1 << 5, + + // If this node was parsed in the parameters of an async function. + AsyncParameter = 1 << 6, // If the parser encountered an error when parsing the code that created this node. Note // the parser only sets this directly on the node it creates right after encountering the @@ -356,7 +356,7 @@ module ts { ThisNodeHasError = 1 << 7, // Context flags set directly by the parser. - ParserGeneratedFlags = StrictMode | DisallowIn | Yield | GeneratorParameter | Decorator | ThisNodeHasError | AsyncParameter | Await, + ParserGeneratedFlags = StrictMode | DisallowIn | Yield | GeneratorParameter | Decorator | ThisNodeHasError | Await | AsyncParameter, // Context flags passed as part of the modified ES6 grammar. YieldAndGeneratorParameterFlags = Yield | GeneratorParameter, diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 805bc877fee..b8aa89aca52 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1101,7 +1101,7 @@ module ts { } export function isAsyncFunctionLike(node: Node): boolean { - return isFunctionLike(node) && !isAccessor(node) && (node.flags & NodeFlags.Async) === NodeFlags.Async; + return isFunctionLike(node) && (node.flags & NodeFlags.Async) !== 0 && !isAccessor(node); } /**