forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntaxList.ts
More file actions
57 lines (45 loc) · 1.87 KB
/
Copy pathsyntaxList.ts
File metadata and controls
57 lines (45 loc) · 1.87 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
///<reference path='references.ts' />
interface Array<T> {
__data: number;
kind: TypeScript.SyntaxKind;
parent: TypeScript.ISyntaxElement;
}
module TypeScript {
export interface ISeparatedSyntaxList<T extends ISyntaxNodeOrToken> extends Array<ISyntaxNodeOrToken> {
//separatorCount(): number;
//separatorAt(index: number): TypeScript.ISyntaxToken;
//nonSeparatorCount(): number;
//nonSeparatorAt(index: number): T;
}
}
module TypeScript {
export function separatorCount(list: ISeparatedSyntaxList<ISyntaxNodeOrToken>) {
return list === undefined ? 0 : list.length >> 1;
}
export function nonSeparatorCount(list: ISeparatedSyntaxList<ISyntaxNodeOrToken>) {
return list === undefined ? 0 : (list.length + 1) >> 1;
}
export function separatorAt(list: ISeparatedSyntaxList<ISyntaxNodeOrToken>, index: number): ISyntaxToken {
return <ISyntaxToken>list[(index << 1) + 1];
}
export function nonSeparatorAt<T extends ISyntaxNodeOrToken>(list: ISeparatedSyntaxList<T>, index: number): T {
return <T>list[index << 1];
}
}
module TypeScript.Syntax {
function addArrayPrototypeValue(name: string, val: any) {
if (Object.defineProperty && (<any>Array.prototype)[name] === undefined) {
Object.defineProperty(Array.prototype, name, { value: val, writable: false, enumerable: false });
}
else {
(<any>Array.prototype)[name] = val;
}
}
addArrayPrototypeValue("kind", SyntaxKind.List);
export function list<T extends ISyntaxNodeOrToken>(nodes: T[]): T[] {
return nodes;
}
export function separatedList<T extends ISyntaxNodeOrToken>(nodesAndTokens: ISyntaxNodeOrToken[]): ISeparatedSyntaxList<T> {
return <ISeparatedSyntaxList<T>>nodesAndTokens;
}
}