-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathvariable-parser.ts
More file actions
35 lines (33 loc) · 1.37 KB
/
Copy pathvariable-parser.ts
File metadata and controls
35 lines (33 loc) · 1.37 KB
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
import { SyntaxKind, VariableStatement } from 'typescript';
import { CallableDeclaration } from '../declarations/Declaration';
import { VariableDeclaration } from '../declarations/VariableDeclaration';
import { Resource } from '../resources/Resource';
import { isCallableDeclaration } from '../type-guards/TypescriptHeroGuards';
import { getNodeType, isNodeExported } from './parse-utilities';
/**
* Parse a variable. Information such as "is the variable const" are calculated here.
*
* @export
* @param {(Resource | CallableDeclaration)} parent
* @param {VariableStatement} node
*/
export function parseVariable(parent: Resource | CallableDeclaration, node: VariableStatement): void {
const isConst = node.declarationList.getChildren().some(o => o.kind === SyntaxKind.ConstKeyword);
if (node.declarationList && node.declarationList.declarations) {
node.declarationList.declarations.forEach((o) => {
const declaration = new VariableDeclaration(
o.name.getText(),
isConst,
isNodeExported(node),
getNodeType(o.type),
node.getStart(),
node.getEnd(),
);
if (isCallableDeclaration(parent)) {
parent.variables.push(declaration);
} else {
parent.declarations.push(declaration);
}
});
}
}