-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
FunctionBase.ts
71 lines (70 loc) · 2.35 KB
/
FunctionBase.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import type { Identifier } from '../expression/Identifier/spec';
import type { TSTypeAnnotation } from '../special/TSTypeAnnotation/spec';
import type { TSTypeParameterDeclaration } from '../special/TSTypeParameterDeclaration/spec';
import type { BlockStatement } from '../statement/BlockStatement/spec';
import type { Expression } from '../unions/Expression';
import type { Parameter } from '../unions/Parameter';
import type { BaseNode } from './BaseNode';
export interface FunctionBase extends BaseNode {
/**
* Whether the function is async:
* ```
* async function foo(...) {...}
* const x = async function (...) {...}
* const x = async (...) => {...}
* ```
*/
async: boolean;
/**
* The body of the function.
* - For an `ArrowFunctionExpression` this may be an `Expression` or `BlockStatement`.
* - For a `FunctionDeclaration` or `FunctionExpression` this is always a `BlockStatement.
* - For a `TSDeclareFunction` this is always `undefined`.
* - For a `TSEmptyBodyFunctionExpression` this is always `null`.
*/
body: BlockStatement | Expression | null | undefined;
/**
* This is only `true` if and only if the node is a `TSDeclareFunction` and it has `declare`:
* ```
* declare function foo(...) {...}
* ```
*/
declare: boolean;
/**
* This is only ever `true` if and only the node is an `ArrowFunctionExpression` and the body
* is an expression:
* ```
* (() => 1)
* ```
*/
expression: boolean;
/**
* Whether the function is a generator function:
* ```
* function *foo(...) {...}
* const x = function *(...) {...}
* ```
* This is always `false` for arrow functions as they cannot be generators.
*/
generator: boolean;
/**
* The function's name.
* - For an `ArrowFunctionExpression` this is always `null`.
* - For a `FunctionExpression` this may be `null` if the name is omitted.
* - For a `FunctionDeclaration` or `TSDeclareFunction` this may be `null` if
* and only if the parent is an `ExportDefaultDeclaration`.
*/
id: Identifier | null;
/**
* The list of parameters declared for the function.
*/
params: Parameter[];
/**
* The return type annotation for the function.
*/
returnType: TSTypeAnnotation | undefined;
/**
* The generic type parameter declaration for the function.
*/
typeParameters: TSTypeParameterDeclaration | undefined;
}