@@ -1854,8 +1854,51 @@ namespace ts {
18541854 return SyntaxKind . FirstTriviaToken <= token && token <= SyntaxKind . LastTriviaToken ;
18551855 }
18561856
1857- export function isAsyncFunctionLike ( node : Node ) : boolean {
1858- return isFunctionLike ( node ) && hasModifier ( node , ModifierFlags . Async ) && ! isAccessor ( node ) ;
1857+ export const enum FunctionFlags {
1858+ Normal = 0 ,
1859+ Generator = 1 << 0 ,
1860+ Async = 1 << 1 ,
1861+ AsyncOrAsyncGenerator = Async | Generator ,
1862+ Invalid = 1 << 2 ,
1863+ InvalidAsyncOrAsyncGenerator = AsyncOrAsyncGenerator | Invalid ,
1864+ InvalidGenerator = Generator | Invalid ,
1865+ }
1866+
1867+ export function getFunctionFlags ( node : FunctionLikeDeclaration ) {
1868+ let flags = FunctionFlags . Normal ;
1869+ switch ( node . kind ) {
1870+ case SyntaxKind . FunctionDeclaration :
1871+ case SyntaxKind . FunctionExpression :
1872+ case SyntaxKind . MethodDeclaration :
1873+ if ( node . asteriskToken ) {
1874+ flags |= FunctionFlags . Generator ;
1875+ }
1876+ // fall through
1877+ case SyntaxKind . ArrowFunction :
1878+ if ( hasModifier ( node , ModifierFlags . Async ) ) {
1879+ flags |= FunctionFlags . Async ;
1880+ }
1881+ break ;
1882+ }
1883+
1884+ if ( ! node . body ) {
1885+ flags |= FunctionFlags . Invalid ;
1886+ }
1887+
1888+ return flags ;
1889+ }
1890+
1891+ export function isAsyncFunction ( node : Node ) : boolean {
1892+ switch ( node . kind ) {
1893+ case SyntaxKind . FunctionDeclaration :
1894+ case SyntaxKind . FunctionExpression :
1895+ case SyntaxKind . ArrowFunction :
1896+ case SyntaxKind . MethodDeclaration :
1897+ return ( < FunctionLikeDeclaration > node ) . body !== undefined
1898+ && ( < FunctionLikeDeclaration > node ) . asteriskToken === undefined
1899+ && hasModifier ( node , ModifierFlags . Async ) ;
1900+ }
1901+ return false ;
18591902 }
18601903
18611904 export function isStringOrNumericLiteral ( kind : SyntaxKind ) : boolean {
0 commit comments