-
Notifications
You must be signed in to change notification settings - Fork 23
/
using_for_directive.ts
79 lines (65 loc) · 2.12 KB
/
using_for_directive.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
import { ASTNode } from "../../ast_node";
import { TypeName } from "../type/type_name";
import { UserDefinedTypeName } from "../type/user_defined_type_name";
import { IdentifierPath } from "./identifier_path";
export interface UsingCustomizedOperator {
definition: IdentifierPath;
operator: string;
}
export class UsingForDirective extends ASTNode {
/**
* A library type name or identifier.
* One of vLibraryName or vFunctionList should always be set.
*/
vLibraryName?: UserDefinedTypeName | IdentifierPath;
/**
* Function list for file-level using-for directives.
* One of vLibraryName or vFunctionList should always be set.
*/
vFunctionList?: Array<IdentifierPath | UsingCustomizedOperator>;
/**
* A target type name that the library functions will apply to.
*/
vTypeName?: TypeName;
/**
* Allows to apply vLibraryName or vFunctionList to the type everywhere,
* where type is accessible.
*/
isGlobal: boolean;
constructor(
id: number,
src: string,
isGlobal: boolean,
libraryName?: UserDefinedTypeName | IdentifierPath,
functionList?: Array<IdentifierPath | UsingCustomizedOperator>,
typeName?: TypeName,
raw?: any
) {
super(id, src, raw);
if (libraryName) {
this.vLibraryName = libraryName;
} else if (functionList) {
this.vFunctionList = functionList;
} else {
throw new Error("One of vLibraryName or vFunctionList should always be set");
}
this.vTypeName = typeName;
this.isGlobal = isGlobal;
this.acceptChildren();
}
get children(): readonly ASTNode[] {
const result = [];
if (this.vLibraryName) {
result.push(this.vLibraryName);
}
if (this.vFunctionList) {
for (const entry of this.vFunctionList) {
result.push(entry instanceof IdentifierPath ? entry : entry.definition);
}
}
if (this.vTypeName) {
result.push(this.vTypeName);
}
return result;
}
}