forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAstModuleVariable.ts
More file actions
38 lines (32 loc) · 1.28 KB
/
AstModuleVariable.ts
File metadata and controls
38 lines (32 loc) · 1.28 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
36
37
38
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as ts from 'typescript';
import { AstItemKind, IAstItemOptions } from './AstItem';
import { AstMember } from './AstMember';
/**
* This class is part of the AstItem abstract syntax tree. It represents variables
* that are exported by an AstNamespace (or conceivably an AstPackage in the future).
* The variables have a name, a type, and an initializer. The AstNamespace implementation
* currently requires them to use a primitive type and be declared as "const".
*/
export class AstModuleVariable extends AstMember {
public type: string;
public name: string;
public value: string;
constructor(options: IAstItemOptions) {
super(options);
this.kind = AstItemKind.ModuleVariable;
const propertySignature: ts.PropertySignature = options.declaration as ts.PropertySignature;
if (propertySignature.type) {
this.type = propertySignature.type.getText();
} else {
this.type = '';
}
this.name = propertySignature.name.getText();
if (propertySignature.initializer) {
this.value = propertySignature.initializer.getText(); // value of the export
} else {
this.value = '';
}
}
}