9
9
import decircular from 'decircular' ;
10
10
import dedent from 'dedent' ;
11
11
12
- export function addJsDocTypeComment ( node : AstTypes . Node , type : string ) {
12
+ export function addJsDocTypeComment ( node : AstTypes . Node , type : string ) : void {
13
13
const comment : AstTypes . CommentBlock = {
14
14
type : 'CommentBlock' ,
15
15
value : `* @type {${ type } } ` ,
@@ -22,7 +22,10 @@ export function addJsDocTypeComment(node: AstTypes.Node, type: string) {
22
22
if ( ! found ) node . comments . push ( comment ) ;
23
23
}
24
24
25
- export function typeAnnotateExpression ( node : AstKinds . ExpressionKind , type : string ) {
25
+ export function typeAnnotateExpression (
26
+ node : AstKinds . ExpressionKind ,
27
+ type : string
28
+ ) : AstTypes . TSAsExpression {
26
29
const expression : AstTypes . TSAsExpression = {
27
30
type : 'TSAsExpression' ,
28
31
expression : node ,
@@ -39,7 +42,7 @@ export function createSpreadElement(expression: AstKinds.ExpressionKind): AstTyp
39
42
} ;
40
43
}
41
44
42
- export function createLiteral ( value : string | null = null ) {
45
+ export function createLiteral ( value : string | null = null ) : AstTypes . Literal {
43
46
const literal : AstTypes . Literal = {
44
47
type : 'Literal' ,
45
48
value
@@ -48,7 +51,7 @@ export function createLiteral(value: string | null = null) {
48
51
return literal ;
49
52
}
50
53
51
- export function areNodesEqual ( ast1 : AstTypes . ASTNode , ast2 : AstTypes . ASTNode ) {
54
+ export function areNodesEqual ( ast1 : AstTypes . ASTNode , ast2 : AstTypes . ASTNode ) : boolean {
52
55
// We're deep cloning these trees so that we can strip the locations off of them for comparisons.
53
56
// Without this, we'd be getting false negatives due to slight differences in formatting style.
54
57
// These ASTs are also filled to the brim with circular references, which prevents
@@ -60,23 +63,28 @@ export function areNodesEqual(ast1: AstTypes.ASTNode, ast2: AstTypes.ASTNode) {
60
63
) ;
61
64
}
62
65
63
- export function blockStatement ( ) {
66
+ export function blockStatement ( ) : AstTypes . BlockStatement {
64
67
const statement : AstTypes . BlockStatement = {
65
68
type : 'BlockStatement' ,
66
69
body : [ ]
67
70
} ;
68
71
return statement ;
69
72
}
70
73
71
- export function expressionStatement ( expression : AstKinds . ExpressionKind ) {
74
+ export function expressionStatement (
75
+ expression : AstKinds . ExpressionKind
76
+ ) : AstTypes . ExpressionStatement {
72
77
const statement : AstTypes . ExpressionStatement = {
73
78
type : 'ExpressionStatement' ,
74
79
expression
75
80
} ;
76
81
return statement ;
77
82
}
78
83
79
- export function addFromString ( ast : AstTypes . BlockStatement | AstTypes . Program , value : string ) {
84
+ export function addFromString (
85
+ ast : AstTypes . BlockStatement | AstTypes . Program ,
86
+ value : string
87
+ ) : void {
80
88
const program = parseScript ( dedent ( value ) ) ;
81
89
82
90
for ( const childNode of program . body ) {
@@ -105,7 +113,7 @@ export function statementFromString(value: string): AstKinds.StatementKind {
105
113
export function addStatement (
106
114
ast : AstTypes . BlockStatement | AstTypes . Program ,
107
115
statement : AstKinds . StatementKind
108
- ) {
116
+ ) : void {
109
117
if ( ! hasNode ( ast , statement ) ) ast . body . push ( statement ) ;
110
118
}
111
119
0 commit comments