forked from dsherret/ts-morph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VariableStatement.ts
106 lines (93 loc) · 3.96 KB
/
VariableStatement.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { VariableDeclarationStructure, VariableStatementStructure, VariableStatementSpecificStructure } from "../../../structures";
import { ts } from "../../../typescript";
import { AmbientableNode, ChildOrderableNode, ExportableNode, JSDocableNode, ModifierableNode } from "../base";
import { callBaseSet } from "../callBaseSet";
import { NamespaceChildableNode } from "../module";
import { Statement } from "./Statement";
import { VariableDeclaration, VariableDeclarationKind, VariableDeclarationList } from "../variable";
import { callBaseGetStructure } from "../callBaseGetStructure";
export const VariableStatementBase = ChildOrderableNode(NamespaceChildableNode(JSDocableNode(AmbientableNode(ExportableNode(ModifierableNode(Statement))))));
export class VariableStatement extends VariableStatementBase<ts.VariableStatement> {
/**
* Get variable declaration list.
*/
getDeclarationList(): VariableDeclarationList {
return this._getNodeFromCompilerNode(this.compilerNode.declarationList);
}
/**
* Get the variable declarations.
*/
getDeclarations(): VariableDeclaration[] {
return this.getDeclarationList().getDeclarations();
}
/**
* Gets the variable declaration kind.
*/
getDeclarationKind(): VariableDeclarationKind {
return this.getDeclarationList().getDeclarationKind();
}
/**
* Gets the variable declaration kind keyword.
*/
getDeclarationKindKeyword() {
return this.getDeclarationList().getDeclarationKindKeyword();
}
/**
* Sets the variable declaration kind.
* @param type - Type to set.
*/
setDeclarationKind(type: VariableDeclarationKind) {
return this.getDeclarationList().setDeclarationKind(type);
}
/**
* Add a variable declaration to the statement.
* @param structure - Structure representing the variable declaration to add.
*/
addDeclaration(structure: VariableDeclarationStructure) {
return this.getDeclarationList().addDeclaration(structure);
}
/**
* Adds variable declarations to the statement.
* @param structures - Structures representing the variable declarations to add.
*/
addDeclarations(structures: ReadonlyArray<VariableDeclarationStructure>) {
return this.getDeclarationList().addDeclarations(structures);
}
/**
* Inserts a variable declaration at the specified index within the statement.
* @param index - Child index to insert at.
* @param structure - Structure representing the variable declaration to insert.
*/
insertDeclaration(index: number, structure: VariableDeclarationStructure) {
return this.getDeclarationList().insertDeclaration(index, structure);
}
/**
* Inserts variable declarations at the specified index within the statement.
* @param index - Child index to insert at.
* @param structures - Structures representing the variable declarations to insert.
*/
insertDeclarations(index: number, structures: ReadonlyArray<VariableDeclarationStructure>) {
return this.getDeclarationList().insertDeclarations(index, structures);
}
/**
* Sets the node from a structure.
* @param structure - Structure to set the node with.
*/
set(structure: Partial<VariableStatementStructure>) {
callBaseSet(VariableStatementBase.prototype, this, structure);
this.getDeclarationList().set({
declarationKind: structure.declarationKind,
declarations: structure.declarations
});
return this;
}
/**
* Gets the structure equivalent to this node.
*/
getStructure(): VariableStatementStructure {
return callBaseGetStructure<VariableStatementSpecificStructure>(VariableStatementBase.prototype, this, {
declarationKind: this.getDeclarationKind(),
declarations: this.getDeclarations().map(declaration => declaration.getStructure())
}) as any as VariableStatementStructure;
}
}