forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbaseNodeFactory.ts
More file actions
60 lines (52 loc) · 2.61 KB
/
baseNodeFactory.ts
File metadata and controls
60 lines (52 loc) · 2.61 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
import {
Node,
objectAllocator,
SyntaxKind,
} from "../_namespaces/ts.js";
/**
* A `BaseNodeFactory` is an abstraction over an `ObjectAllocator` that handles caching `Node` constructors
* and allocating `Node` instances based on a set of predefined types.
*
* @internal
*/
export interface BaseNodeFactory {
createBaseSourceFileNode(kind: SyntaxKind.SourceFile): Node;
createBaseIdentifierNode(kind: SyntaxKind.Identifier): Node;
createBasePrivateIdentifierNode(kind: SyntaxKind.PrivateIdentifier): Node;
createBaseTokenNode(kind: SyntaxKind): Node;
createBaseNode(kind: SyntaxKind): Node;
}
/**
* Creates a `BaseNodeFactory` which can be used to create `Node` instances from the constructors provided by the object allocator.
*
* @internal
*/
export function createBaseNodeFactory(): BaseNodeFactory {
let NodeConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
let TokenConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
let IdentifierConstructor: new (kind: SyntaxKind.Identifier, pos: number, end: number) => Node;
let PrivateIdentifierConstructor: new (kind: SyntaxKind.PrivateIdentifier, pos: number, end: number) => Node;
let SourceFileConstructor: new (kind: SyntaxKind.SourceFile, pos: number, end: number) => Node;
return {
createBaseSourceFileNode,
createBaseIdentifierNode,
createBasePrivateIdentifierNode,
createBaseTokenNode,
createBaseNode,
};
function createBaseSourceFileNode(kind: SyntaxKind.SourceFile): Node {
return new (SourceFileConstructor || (SourceFileConstructor = objectAllocator.getSourceFileConstructor()))(kind, /*pos*/ -1, /*end*/ -1);
}
function createBaseIdentifierNode(kind: SyntaxKind.Identifier): Node {
return new (IdentifierConstructor || (IdentifierConstructor = objectAllocator.getIdentifierConstructor()))(kind, /*pos*/ -1, /*end*/ -1);
}
function createBasePrivateIdentifierNode(kind: SyntaxKind.PrivateIdentifier): Node {
return new (PrivateIdentifierConstructor || (PrivateIdentifierConstructor = objectAllocator.getPrivateIdentifierConstructor()))(kind, /*pos*/ -1, /*end*/ -1);
}
function createBaseTokenNode(kind: SyntaxKind): Node {
return new (TokenConstructor || (TokenConstructor = objectAllocator.getTokenConstructor()))(kind, /*pos*/ -1, /*end*/ -1);
}
function createBaseNode(kind: SyntaxKind): Node {
return new (NodeConstructor || (NodeConstructor = objectAllocator.getNodeConstructor()))(kind, /*pos*/ -1, /*end*/ -1);
}
}