1/* @internal */ 2namespace ts { 3 /** 4 * A `BaseNodeFactory` is an abstraction over an `ObjectAllocator` that handles caching `Node` constructors 5 * and allocating `Node` instances based on a set of predefined types. 6 */ 7 /* @internal */ 8 export interface BaseNodeFactory { 9 createBaseSourceFileNode(kind: SyntaxKind): Node; 10 createBaseIdentifierNode(kind: SyntaxKind): Node; 11 createBasePrivateIdentifierNode(kind: SyntaxKind): Node; 12 createBaseTokenNode(kind: SyntaxKind): Node; 13 createBaseNode(kind: SyntaxKind): Node; 14 } 15 16 /** 17 * Creates a `BaseNodeFactory` which can be used to create `Node` instances from the constructors provided by the object allocator. 18 */ 19 export function createBaseNodeFactory(): BaseNodeFactory { 20 let NodeConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node; 21 let TokenConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node; 22 let IdentifierConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node; 23 let PrivateIdentifierConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node; 24 let SourceFileConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node; 25 26 return { 27 createBaseSourceFileNode, 28 createBaseIdentifierNode, 29 createBasePrivateIdentifierNode, 30 createBaseTokenNode, 31 createBaseNode 32 }; 33 34 function createBaseSourceFileNode(kind: SyntaxKind): Node { 35 return new (SourceFileConstructor || (SourceFileConstructor = objectAllocator.getSourceFileConstructor()))(kind, /*pos*/ -1, /*end*/ -1); 36 } 37 38 function createBaseIdentifierNode(kind: SyntaxKind): Node { 39 return new (IdentifierConstructor || (IdentifierConstructor = objectAllocator.getIdentifierConstructor()))(kind, /*pos*/ -1, /*end*/ -1); 40 } 41 42 function createBasePrivateIdentifierNode(kind: SyntaxKind): Node { 43 return new (PrivateIdentifierConstructor || (PrivateIdentifierConstructor = objectAllocator.getPrivateIdentifierConstructor()))(kind, /*pos*/ -1, /*end*/ -1); 44 } 45 46 function createBaseTokenNode(kind: SyntaxKind): Node { 47 return new (TokenConstructor || (TokenConstructor = objectAllocator.getTokenConstructor()))(kind, /*pos*/ -1, /*end*/ -1); 48 } 49 50 function createBaseNode(kind: SyntaxKind): Node { 51 return new (NodeConstructor || (NodeConstructor = objectAllocator.getNodeConstructor()))(kind, /*pos*/ -1, /*end*/ -1); 52 } 53 } 54} 55