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 // tslint:disable variable-name 21 let NodeConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node; 22 let TokenConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node; 23 let IdentifierConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node; 24 let PrivateIdentifierConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node; 25 let SourceFileConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node; 26 // tslint:enable variable-name 27 28 return { 29 createBaseSourceFileNode, 30 createBaseIdentifierNode, 31 createBasePrivateIdentifierNode, 32 createBaseTokenNode, 33 createBaseNode 34 }; 35 36 function createBaseSourceFileNode(kind: SyntaxKind): Node { 37 return new (SourceFileConstructor || (SourceFileConstructor = objectAllocator.getSourceFileConstructor()))(kind, /*pos*/ -1, /*end*/ -1); 38 } 39 40 function createBaseIdentifierNode(kind: SyntaxKind): Node { 41 return new (IdentifierConstructor || (IdentifierConstructor = objectAllocator.getIdentifierConstructor()))(kind, /*pos*/ -1, /*end*/ -1); 42 } 43 44 function createBasePrivateIdentifierNode(kind: SyntaxKind): Node { 45 return new (PrivateIdentifierConstructor || (PrivateIdentifierConstructor = objectAllocator.getPrivateIdentifierConstructor()))(kind, /*pos*/ -1, /*end*/ -1); 46 } 47 48 function createBaseTokenNode(kind: SyntaxKind): Node { 49 return new (TokenConstructor || (TokenConstructor = objectAllocator.getTokenConstructor()))(kind, /*pos*/ -1, /*end*/ -1); 50 } 51 52 function createBaseNode(kind: SyntaxKind): Node { 53 return new (NodeConstructor || (NodeConstructor = objectAllocator.getNodeConstructor()))(kind, /*pos*/ -1, /*end*/ -1); 54 } 55 } 56}