@@ -6,14 +6,9 @@ export const convertMethod: ASTConverter<ts.MethodDeclaration> = (node, options)
6
6
const tsModule = options . typescript
7
7
const methodName = node . name . getText ( )
8
8
9
- const outputMethod = tsModule . createArrowFunction (
10
- node . modifiers ,
11
- node . typeParameters ,
12
- node . parameters ,
13
- node . type ,
14
- tsModule . createToken ( tsModule . SyntaxKind . EqualsGreaterThanToken ) ,
15
- node . body ?? tsModule . createBlock ( [ ] )
16
- )
9
+ const result = options . useFunctionDeclaration
10
+ ? convertMethodAsFunctionDeclaration ( tsModule , node )
11
+ : convertMethodAsArrowFunction ( tsModule , node )
17
12
18
13
return {
19
14
tag : 'Method' ,
@@ -24,19 +19,46 @@ export const convertMethod: ASTConverter<ts.MethodDeclaration> = (node, options)
24
19
nodes : [
25
20
copySyntheticComments (
26
21
tsModule ,
27
- tsModule . createVariableStatement (
28
- undefined ,
29
- tsModule . createVariableDeclarationList ( [
30
- tsModule . createVariableDeclaration (
31
- tsModule . createIdentifier ( methodName ) ,
32
- undefined ,
33
- outputMethod
34
- )
35
- ] ,
36
- tsModule . NodeFlags . Const )
37
- ) ,
22
+ result ,
38
23
node
39
24
)
40
25
] as ts . Statement [ ]
41
26
}
42
27
}
28
+
29
+ const convertMethodAsFunctionDeclaration = ( tsModule : typeof ts , node : ts . MethodDeclaration ) : ts . FunctionDeclaration => {
30
+ return tsModule . createFunctionDeclaration (
31
+ undefined ,
32
+ undefined ,
33
+ node . asteriskToken ,
34
+ node . name . getText ( ) ,
35
+ node . typeParameters ,
36
+ node . parameters ,
37
+ node . type ,
38
+ node . body ?? tsModule . createBlock ( [ ] )
39
+ )
40
+ }
41
+
42
+ const convertMethodAsArrowFunction = ( tsModule : typeof ts , node : ts . MethodDeclaration ) : ts . VariableStatement => {
43
+ const methodName = node . name . getText ( )
44
+ const outputMethod = tsModule . createArrowFunction (
45
+ undefined ,
46
+ node . typeParameters ,
47
+ node . parameters ,
48
+ node . type ,
49
+ tsModule . createToken ( tsModule . SyntaxKind . EqualsGreaterThanToken ) ,
50
+ node . body ?? tsModule . createBlock ( [ ] )
51
+ )
52
+
53
+ return tsModule . createVariableStatement (
54
+ undefined ,
55
+ tsModule . createVariableDeclarationList ( [
56
+ tsModule . createVariableDeclaration (
57
+ tsModule . createIdentifier ( methodName ) ,
58
+ undefined ,
59
+ outputMethod
60
+ )
61
+ ] ,
62
+ tsModule . NodeFlags . Const )
63
+ )
64
+ }
0 commit comments