@@ -101,7 +101,7 @@ module ts {
101
101
} ;
102
102
}
103
103
104
- function createTextWriter ( writeSymbol : ( symbol : Symbol , enclosingDeclaration ?: Node , meaning ?: SymbolFlags ) => void ) : EmitTextWriter {
104
+ function createTextWriter ( trackSymbol : ( symbol : Symbol , enclosingDeclaration ?: Node , meaning ?: SymbolFlags ) => void ) : EmitTextWriter {
105
105
var output = "" ;
106
106
var indent = 0 ;
107
107
var lineStart = true ;
@@ -149,7 +149,7 @@ module ts {
149
149
150
150
return {
151
151
write : write ,
152
- writeSymbol : writeSymbol ,
152
+ trackSymbol : trackSymbol ,
153
153
rawWrite : rawWrite ,
154
154
writeLiteral : writeLiteral ,
155
155
writeLine : writeLine ,
@@ -182,7 +182,7 @@ module ts {
182
182
} ) ;
183
183
}
184
184
185
- function emitComments ( comments : Comment [ ] , trailingSeparator : boolean , writer : EmitTextWriter , writeComment : ( comment : Comment , writer : EmitTextWriter ) => void ) {
185
+ function emitComments ( comments : CommentRange [ ] , trailingSeparator : boolean , writer : EmitTextWriter , writeComment : ( comment : CommentRange , writer : EmitTextWriter ) => void ) {
186
186
var emitLeadingSpace = ! trailingSeparator ;
187
187
forEach ( comments , comment => {
188
188
if ( emitLeadingSpace ) {
@@ -203,15 +203,15 @@ module ts {
203
203
} ) ;
204
204
}
205
205
206
- function emitNewLineBeforeLeadingComments ( node : TextRange , leadingComments : Comment [ ] , writer : EmitTextWriter ) {
206
+ function emitNewLineBeforeLeadingComments ( node : TextRange , leadingComments : CommentRange [ ] , writer : EmitTextWriter ) {
207
207
// If the leading comments start on different line than the start of node, write new line
208
208
if ( leadingComments && leadingComments . length && node . pos !== leadingComments [ 0 ] . pos &&
209
209
getLineOfLocalPosition ( node . pos ) !== getLineOfLocalPosition ( leadingComments [ 0 ] . pos ) ) {
210
210
writer . writeLine ( ) ;
211
211
}
212
212
}
213
213
214
- function writeCommentRange ( comment : Comment , writer : EmitTextWriter ) {
214
+ function writeCommentRange ( comment : CommentRange , writer : EmitTextWriter ) {
215
215
if ( currentSourceFile . text . charCodeAt ( comment . pos + 1 ) === CharacterCodes . asterisk ) {
216
216
var firstCommentLineAndCharacter = currentSourceFile . getLineAndCharacterFromPosition ( comment . pos ) ;
217
217
var firstCommentLineIndent : number ;
@@ -307,7 +307,7 @@ module ts {
307
307
}
308
308
309
309
function emitJavaScript ( jsFilePath : string , root ?: SourceFile ) {
310
- var writer = createTextWriter ( writeSymbol ) ;
310
+ var writer = createTextWriter ( trackSymbol ) ;
311
311
var write = writer . write ;
312
312
var writeLine = writer . writeLine ;
313
313
var increaseIndent = writer . increaseIndent ;
@@ -363,7 +363,7 @@ module ts {
363
363
/** Sourcemap data that will get encoded */
364
364
var sourceMapData : SourceMapData ;
365
365
366
- function writeSymbol ( symbol : Symbol , enclosingDeclaration : Node , meaning : SymbolFlags ) { }
366
+ function trackSymbol ( symbol : Symbol , enclosingDeclaration : Node , meaning : SymbolFlags ) { }
367
367
368
368
function initializeEmitterWithSourceMaps ( ) {
369
369
var sourceMapDir : string ; // The directory in which sourcemap will be
@@ -585,7 +585,7 @@ module ts {
585
585
sourceMapNameIndices . pop ( ) ;
586
586
} ;
587
587
588
- function writeCommentRangeWithMap ( comment : Comment , writer : EmitTextWriter ) {
588
+ function writeCommentRangeWithMap ( comment : CommentRange , writer : EmitTextWriter ) {
589
589
recordSourceMapSpan ( comment . pos ) ;
590
590
writeCommentRange ( comment , writer ) ;
591
591
recordSourceMapSpan ( comment . end ) ;
@@ -916,14 +916,15 @@ module ts {
916
916
}
917
917
918
918
function emitPropertyAccess ( node : PropertyAccess ) {
919
- var text = resolver . getPropertyAccessSubstitution ( node ) ;
920
- if ( text ) {
921
- write ( text ) ;
922
- return ;
919
+ var constantValue = resolver . getConstantValue ( node ) ;
920
+ if ( constantValue !== undefined ) {
921
+ write ( constantValue . toString ( ) + " /* " + identifierToString ( node . right ) + " */" ) ;
922
+ }
923
+ else {
924
+ emit ( node . left ) ;
925
+ write ( "." ) ;
926
+ emit ( node . right ) ;
923
927
}
924
- emit ( node . left ) ;
925
- write ( "." ) ;
926
- emit ( node . right ) ;
927
928
}
928
929
929
930
function emitIndexedAccess ( node : IndexedAccess ) {
@@ -2155,7 +2156,7 @@ module ts {
2155
2156
2156
2157
function getLeadingCommentsWithoutDetachedComments ( ) {
2157
2158
// get the leading comments from detachedPos
2158
- var leadingComments = getLeadingComments ( currentSourceFile . text , detachedCommentsInfo [ detachedCommentsInfo . length - 1 ] . detachedCommentEndPos ) ;
2159
+ var leadingComments = getLeadingCommentRanges ( currentSourceFile . text , detachedCommentsInfo [ detachedCommentsInfo . length - 1 ] . detachedCommentEndPos ) ;
2159
2160
if ( detachedCommentsInfo . length - 1 ) {
2160
2161
detachedCommentsInfo . pop ( ) ;
2161
2162
}
@@ -2169,14 +2170,14 @@ module ts {
2169
2170
function getLeadingCommentsToEmit ( node : Node ) {
2170
2171
// Emit the leading comments only if the parent's pos doesn't match because parent should take care of emitting these comments
2171
2172
if ( node . parent . kind === SyntaxKind . SourceFile || node . pos !== node . parent . pos ) {
2172
- var leadingComments : Comment [ ] ;
2173
+ var leadingComments : CommentRange [ ] ;
2173
2174
if ( hasDetachedComments ( node . pos ) ) {
2174
2175
// get comments without detached comments
2175
2176
leadingComments = getLeadingCommentsWithoutDetachedComments ( ) ;
2176
2177
}
2177
2178
else {
2178
2179
// get the leading comments from the node
2179
- leadingComments = getLeadingCommentsOfNode ( node , currentSourceFile ) ;
2180
+ leadingComments = getLeadingCommentRangesOfNode ( node , currentSourceFile ) ;
2180
2181
}
2181
2182
return leadingComments ;
2182
2183
}
@@ -2192,32 +2193,32 @@ module ts {
2192
2193
function emitTrailingDeclarationComments ( node : Node ) {
2193
2194
// Emit the trailing comments only if the parent's end doesn't match
2194
2195
if ( node . parent . kind === SyntaxKind . SourceFile || node . end !== node . parent . end ) {
2195
- var trailingComments = getTrailingComments ( currentSourceFile . text , node . end ) ;
2196
+ var trailingComments = getTrailingCommentRanges ( currentSourceFile . text , node . end ) ;
2196
2197
// trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/
2197
2198
emitComments ( trailingComments , /*trailingSeparator*/ false , writer , writeComment ) ;
2198
2199
}
2199
2200
}
2200
2201
2201
2202
function emitLeadingCommentsOfLocalPosition ( pos : number ) {
2202
- var leadingComments : Comment [ ] ;
2203
+ var leadingComments : CommentRange [ ] ;
2203
2204
if ( hasDetachedComments ( pos ) ) {
2204
2205
// get comments without detached comments
2205
2206
leadingComments = getLeadingCommentsWithoutDetachedComments ( ) ;
2206
2207
}
2207
2208
else {
2208
2209
// get the leading comments from the node
2209
- leadingComments = getLeadingComments ( currentSourceFile . text , pos ) ;
2210
+ leadingComments = getLeadingCommentRanges ( currentSourceFile . text , pos ) ;
2210
2211
}
2211
2212
emitNewLineBeforeLeadingComments ( { pos : pos , end : pos } , leadingComments , writer ) ;
2212
2213
// Leading comments are emitted at /*leading comment1 */space/*leading comment*/space
2213
2214
emitComments ( leadingComments , /*trailingSeparator*/ true , writer , writeComment ) ;
2214
2215
}
2215
2216
2216
2217
function emitDetachedCommentsAtPosition ( node : TextRange ) {
2217
- var leadingComments = getLeadingComments ( currentSourceFile . text , node . pos ) ;
2218
+ var leadingComments = getLeadingCommentRanges ( currentSourceFile . text , node . pos ) ;
2218
2219
if ( leadingComments ) {
2219
- var detachedComments : Comment [ ] = [ ] ;
2220
- var lastComment : Comment ;
2220
+ var detachedComments : CommentRange [ ] = [ ] ;
2221
+ var lastComment : CommentRange ;
2221
2222
2222
2223
forEach ( leadingComments , comment => {
2223
2224
if ( lastComment ) {
@@ -2261,7 +2262,7 @@ module ts {
2261
2262
function emitPinnedOrTripleSlashCommentsOfNode ( node : Node ) {
2262
2263
var pinnedComments = ts . filter ( getLeadingCommentsToEmit ( node ) , isPinnedOrTripleSlashComment ) ;
2263
2264
2264
- function isPinnedOrTripleSlashComment ( comment : Comment ) {
2265
+ function isPinnedOrTripleSlashComment ( comment : CommentRange ) {
2265
2266
if ( currentSourceFile . text . charCodeAt ( comment . pos + 1 ) === CharacterCodes . asterisk ) {
2266
2267
return currentSourceFile . text . charCodeAt ( comment . pos + 2 ) === CharacterCodes . exclamation ;
2267
2268
}
@@ -2300,7 +2301,7 @@ module ts {
2300
2301
}
2301
2302
2302
2303
function emitDeclarations ( jsFilePath : string , root ?: SourceFile ) {
2303
- var writer = createTextWriter ( writeSymbol ) ;
2304
+ var writer = createTextWriter ( trackSymbol ) ;
2304
2305
var write = writer . write ;
2305
2306
var writeLine = writer . writeLine ;
2306
2307
var increaseIndent = writer . increaseIndent ;
@@ -2328,7 +2329,7 @@ module ts {
2328
2329
var oldWriter = writer ;
2329
2330
forEach ( importDeclarations , aliasToWrite => {
2330
2331
var aliasEmitInfo = forEach ( aliasDeclarationEmitInfo , declEmitInfo => declEmitInfo . declaration === aliasToWrite ? declEmitInfo : undefined ) ;
2331
- writer = createTextWriter ( writeSymbol ) ;
2332
+ writer = createTextWriter ( trackSymbol ) ;
2332
2333
for ( var declarationIndent = aliasEmitInfo . indent ; declarationIndent ; declarationIndent -- ) {
2333
2334
writer . increaseIndent ( ) ;
2334
2335
}
@@ -2339,10 +2340,9 @@ module ts {
2339
2340
writer = oldWriter ;
2340
2341
}
2341
2342
2342
- function writeSymbol ( symbol : Symbol , enclosingDeclaration ?: Node , meaning ?: SymbolFlags ) {
2343
+ function trackSymbol ( symbol : Symbol , enclosingDeclaration ?: Node , meaning ?: SymbolFlags ) {
2343
2344
var symbolAccesibilityResult = resolver . isSymbolAccessible ( symbol , enclosingDeclaration , meaning ) ;
2344
2345
if ( symbolAccesibilityResult . accessibility === SymbolAccessibility . Accessible ) {
2345
- resolver . writeSymbol ( symbol , enclosingDeclaration , meaning , writer ) ;
2346
2346
2347
2347
// write the aliases
2348
2348
if ( symbolAccesibilityResult && symbolAccesibilityResult . aliasesToMakeVisible ) {
0 commit comments