3
3
module ts . formatting {
4
4
export module SmartIndenter {
5
5
6
- interface LineAndCharacter {
7
- line : number ;
8
- character : number ;
9
- }
10
-
11
6
export function getIndentation ( position : number , sourceFile : SourceFile , options : TypeScript . FormattingOptions ) : number {
12
7
if ( position > sourceFile . text . length ) {
13
8
return 0 ; // past EOF
@@ -111,23 +106,6 @@ module ts.formatting {
111
106
return indentation ;
112
107
}
113
108
114
- function isDeclaration ( n : Node ) : boolean {
115
- switch ( n . kind ) {
116
- case SyntaxKind . ClassDeclaration :
117
- case SyntaxKind . EnumDeclaration :
118
- case SyntaxKind . FunctionDeclaration :
119
- case SyntaxKind . ImportDeclaration :
120
- case SyntaxKind . Method :
121
- case SyntaxKind . Property :
122
- case SyntaxKind . ModuleDeclaration :
123
- case SyntaxKind . InterfaceDeclaration :
124
- case SyntaxKind . VariableDeclaration :
125
- return true ;
126
- default :
127
- return false ;
128
- }
129
- }
130
-
131
109
function isStatement ( n : Node ) : boolean {
132
110
switch ( n . kind ) {
133
111
case SyntaxKind . BreakStatement :
@@ -153,7 +131,9 @@ module ts.formatting {
153
131
}
154
132
}
155
133
156
- // function returns -1 if indentation cannot be determined
134
+ /*
135
+ * Function returns -1 if indentation cannot be determined
136
+ */
157
137
function getActualIndentationForListItemBeforeComma ( commaToken : Node , sourceFile : SourceFile , options : TypeScript . FormattingOptions ) : number {
158
138
// previous token is comma that separates items in list - find the previous item and try to derive indentation from it
159
139
var precedingListItem = findPrecedingListItem ( commaToken ) ;
@@ -167,7 +147,9 @@ module ts.formatting {
167
147
return - 1 ;
168
148
}
169
149
170
- // function returns -1 if actual indentation for node should not be used (i.e because node is nested expression)
150
+ /*
151
+ * Function returns -1 if actual indentation for node should not be used (i.e because node is nested expression)
152
+ */
171
153
function getActualIndentationForNode ( current : Node , parent : Node , currentLineAndChar : LineAndCharacter , parentAndChildShareLine : boolean , sourceFile : SourceFile , options : TypeScript . FormattingOptions ) : number {
172
154
var useActualIndentation =
173
155
( isDeclaration ( current ) || isStatement ( current ) ) &&
@@ -306,7 +288,7 @@ module ts.formatting {
306
288
return column ;
307
289
}
308
290
309
- if ( charCode === CharacterCodes . tab && ! options . useTabs ) {
291
+ if ( charCode === CharacterCodes . tab ) {
310
292
column += options . spacesPerTab ;
311
293
}
312
294
else {
@@ -391,7 +373,9 @@ module ts.formatting {
391
373
}
392
374
}
393
375
394
- /// checks if node is something that can contain tokens (except EOF) - filters out EOF tokens, Missing\Omitted expressions, empty SyntaxLists and expression statements that wrap any of listed nodes.
376
+ /*
377
+ * Checks if node is something that can contain tokens (except EOF) - filters out EOF tokens, Missing\Omitted expressions, empty SyntaxLists and expression statements that wrap any of listed nodes.
378
+ */
395
379
function isCandidateNode ( n : Node ) : boolean {
396
380
if ( n . kind === SyntaxKind . ExpressionStatement ) {
397
381
return isCandidateNode ( ( < ExpressionStatement > n ) . expression ) ;
@@ -456,8 +440,10 @@ module ts.formatting {
456
440
}
457
441
}
458
442
459
- /// checks if node ends with 'expectedLastToken'.
460
- /// If child at position 'length - 1' is 'SemicolonToken' it is skipped and 'expectedLastToken' is compared with child at position 'length - 2'.
443
+ /*
444
+ * Checks if node ends with 'expectedLastToken'.
445
+ * If child at position 'length - 1' is 'SemicolonToken' it is skipped and 'expectedLastToken' is compared with child at position 'length - 2'.
446
+ */
461
447
function nodeEndsWith ( n : Node , expectedLastToken : SyntaxKind , sourceFile : SourceFile ) : boolean {
462
448
var children = n . getChildren ( sourceFile ) ;
463
449
if ( children . length ) {
@@ -472,7 +458,9 @@ module ts.formatting {
472
458
return false ;
473
459
}
474
460
475
- // this function is always called when position of the cursor is located after the node
461
+ /*
462
+ * This function is always called when position of the cursor is located after the node
463
+ */
476
464
function isCompletedNode ( n : Node , sourceFile : SourceFile ) : boolean {
477
465
switch ( n . kind ) {
478
466
case SyntaxKind . ClassDeclaration :
0 commit comments