1+ /// <reference path="types.ts"/>
2+ /// <reference path="utilities.ts"/>
3+ /* @internal */
4+ namespace ts {
5+ export function createNodeArray < T extends Node > ( elements ?: T [ ] , location ?: TextRange ) : NodeArray < T > ;
6+ export function createNodeArray < T extends Node , TArray extends NodeArray < T > > ( elements : TArray , location ?: TextRange ) : TArray ;
7+ export function createNodeArray < T extends Node , TArray extends NodeArray < T > > ( elements ?: T [ ] , location ?: TextRange ) : TArray {
8+ const array = < TArray > ( elements || [ ] ) ;
9+ if ( location ) {
10+ array . pos = location . pos ;
11+ array . end = location . end ;
12+ }
13+ else if ( array . pos === undefined || array . end === undefined ) {
14+ array . pos = - 1 ;
15+ array . end = - 1 ;
16+ }
17+
18+ return array ;
19+ }
20+
21+ export function createNodeArrayNode < T extends Node > ( elements ?: ( T | NodeArrayNode < T > ) [ ] ) : NodeArrayNode < T > {
22+ const array = < NodeArrayNode < T > > createNodeArray ( elements ) ;
23+ array . kind = SyntaxKind . NodeArrayNode ;
24+ return array ;
25+ }
26+
27+ export function createReturn ( expression ?: Expression ) : ReturnStatement {
28+ const node = < ReturnStatement > createSynthesizedNode ( SyntaxKind . ReturnStatement ) ;
29+ node . expression = expression ;
30+ return node ;
31+ }
32+
33+ export function createStatement ( expression : Expression ) : ExpressionStatement {
34+ const node = < ExpressionStatement > createSynthesizedNode ( SyntaxKind . ExpressionStatement ) ;
35+ node . expression = expression ;
36+ return node ;
37+ }
38+
39+ export function createVariableStatement ( declarationList : VariableDeclarationList ) : VariableStatement {
40+ const node = < VariableStatement > createSynthesizedNode ( SyntaxKind . VariableStatement ) ;
41+ node . declarationList = declarationList ;
42+ return node ;
43+ }
44+
45+ export function createVariableDeclarationList ( declarations : VariableDeclaration [ ] ) : VariableDeclarationList {
46+ const node = < VariableDeclarationList > createSynthesizedNode ( SyntaxKind . VariableDeclarationList ) ;
47+ node . declarations = createNodeArray ( declarations ) ;
48+ return node ;
49+ }
50+
51+ export function createBlock ( statements : Statement [ ] ) : Block {
52+ const block = < Block > createSynthesizedNode ( SyntaxKind . Block ) ;
53+ block . statements = createNodeArray ( statements ) ;
54+ return block ;
55+ }
56+ }
0 commit comments