1
- import { nameof } from "@ts-morph/common" ;
1
+ import { nameof , SyntaxKind } from "@ts-morph/common" ;
2
2
import { expect } from "chai" ;
3
- import { AsyncableNode , FunctionDeclaration } from "../../../../compiler" ;
3
+ import { AsyncableNode , FunctionDeclaration , Node , VariableStatement } from "../../../../compiler" ;
4
4
import { AsyncableNodeStructure } from "../../../../structures" ;
5
5
import { getInfoFromText } from "../../testHelpers" ;
6
6
@@ -43,8 +43,10 @@ describe("AsyncableNode", () => {
43
43
44
44
describe ( nameof < AsyncableNode > ( "setIsAsync" ) , ( ) => {
45
45
function doTest ( text : string , value : boolean , expected : string ) {
46
- const { firstChild, sourceFile } = getInfoFromText < FunctionDeclaration > ( text ) ;
47
- firstChild . setIsAsync ( value ) ;
46
+ let { firstChild, sourceFile } = getInfoFromText ( text ) ;
47
+ if ( firstChild . getKind ( ) === SyntaxKind . VariableStatement )
48
+ firstChild = ( firstChild as VariableStatement ) . getDeclarations ( ) [ 0 ] . getInitializerOrThrow ( ) ;
49
+ ( firstChild as any as AsyncableNode ) . setIsAsync ( value ) ;
48
50
expect ( sourceFile . getText ( ) ) . to . equal ( expected ) ;
49
51
}
50
52
@@ -55,6 +57,12 @@ describe("AsyncableNode", () => {
55
57
it ( "should set as not async when async" , ( ) => {
56
58
doTest ( "async function Identifier() {}" , false , "function Identifier() {}" ) ;
57
59
} ) ;
60
+
61
+ it ( "should handle arrow function" , ( ) => {
62
+ doTest ( "const f = a => a * 2;" , true , "const f = async a => a * 2;" ) ;
63
+ doTest ( "const f = async a => a * 2;" , true , "const f = async a => a * 2;" ) ;
64
+ doTest ( "const f = async a => a * 2;" , false , "const f = a => a * 2;" ) ;
65
+ } ) ;
58
66
} ) ;
59
67
60
68
describe ( nameof < FunctionDeclaration > ( "getStructure" ) , ( ) => {
0 commit comments