forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpullFlags.ts
More file actions
142 lines (104 loc) · 4.66 KB
/
Copy pathpullFlags.ts
File metadata and controls
142 lines (104 loc) · 4.66 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0.
// See LICENSE.txt in the project root for complete license information.
///<reference path='..\references.ts' />
module TypeScript {
export enum PullElementFlags {
None = 0,
Exported = 1,
Private = 1 << 1,
Public = 1 << 2,
Ambient = 1 << 3,
Static = 1 << 4,
Optional = 1 << 7,
Signature = 1 << 11,
Enum = 1 << 12,
ArrowFunction = 1 << 13,
ClassConstructorVariable = 1 << 14,
InitializedModule = 1 << 15,
InitializedDynamicModule = 1 << 16,
MustCaptureThis = 1 << 18,
DeclaredInAWithBlock = 1 << 21,
HasReturnStatement = 1 << 22,
PropertyParameter = 1 << 23,
IsAnnotatedWithAny = 1 << 24,
HasDefaultArgs = 1 << 25,
ConstructorParameter = 1 << 26,
ImplicitVariable = ClassConstructorVariable | InitializedModule | InitializedDynamicModule | Enum,
SomeInitializedModule = InitializedModule | InitializedDynamicModule | Enum,
}
function mapFlagToTokenKind(flag: PullElementFlags): SyntaxKind {
switch (flag) {
case PullElementFlags.Ambient:
return SyntaxKind.DeclareKeyword;
case PullElementFlags.Exported:
return SyntaxKind.ExportKeyword;
case PullElementFlags.Public:
return SyntaxKind.PublicKeyword;
case PullElementFlags.Private:
return SyntaxKind.PrivateKeyword;
case PullElementFlags.Static:
return SyntaxKind.StaticKeyword;
default:
throw Errors.invalidOperation();
}
}
export function hasModifier(modifiers: ISyntaxToken[], flag: PullElementFlags): boolean {
var kind = mapFlagToTokenKind(flag);
for (var i = 0, n = modifiers.length; i < n; i++) {
var modifier = modifiers[i];
if (modifier.kind() === kind) {
return true;
}
}
return false;
}
export enum PullElementKind {
None = 0,
Global = 0,
Script = 1 << 0,
Primitive = 1 << 1,
Container = 1 << 2,
Class = 1 << 3,
Interface = 1 << 4,
DynamicModule = 1 << 5,
Enum = 1 << 6,
TypeAlias = 1 << 7,
ObjectLiteral = 1 << 8,
Variable = 1 << 9,
CatchVariable = 1 << 10,
Parameter = 1 << 11,
Property = 1 << 12,
TypeParameter = 1 << 13,
Function = 1 << 14,
ConstructorMethod = 1 << 15,
Method = 1 << 16,
FunctionExpression = 1 << 17,
GetAccessor = 1 << 18,
SetAccessor = 1 << 19,
CallSignature = 1 << 20,
ConstructSignature = 1 << 21,
IndexSignature = 1 << 22,
ObjectType = 1 << 23,
FunctionType = 1 << 24,
ConstructorType = 1 << 25,
EnumMember = 1 << 26,
WithBlock = 1 << 27,
CatchBlock = 1 << 28,
// WARNING: To prevent JS VMs from wrapping these values as floats, we don't want to utilize more than the 31 bits above. (Doing so would
// seriously slow down bitwise operations
All = Script | Global | Primitive | Container | Class | Interface | DynamicModule | Enum | TypeAlias |
ObjectLiteral | Variable | Parameter | Property | TypeParameter | Function | ConstructorMethod | Method |
FunctionExpression | GetAccessor | SetAccessor | CallSignature | ConstructSignature | IndexSignature | ObjectType |
FunctionType | ConstructorType | EnumMember | WithBlock | CatchBlock,
SomeFunction = Function | ConstructorMethod | Method | FunctionExpression | GetAccessor | SetAccessor,
// Warning: SomeValue and SomeType (along with their constituents) must be disjoint
SomeValue = Variable | Parameter | Property | EnumMember | SomeFunction,
SomeType = Script | Global | Primitive | Class | Interface |
Enum | ObjectLiteral | ObjectType | FunctionType | ConstructorType | TypeParameter,
AcceptableAlias = Variable | SomeFunction | Class | Interface | Enum | Container | ObjectType | FunctionType | ConstructorType,
SomeContainer = Container | DynamicModule | TypeAlias,
SomeSignature = CallSignature | ConstructSignature | IndexSignature,
SomeTypeReference = Interface | ObjectType | FunctionType | ConstructorType,
SomeInstantiatableType = Class | Interface | TypeParameter,
}
}