@@ -1857,28 +1857,17 @@ module ts {
18571857 }
18581858 }
18591859
1860- function emitCommaList ( nodes : Node [ ] ) {
1860+ function emitCommaList ( nodes : Node [ ] , eachNodeEmitFn : ( node : Node ) => void ) {
1861+ var currentWriterPos = writer . getTextPos ( ) ;
18611862 for ( var i = 0 , n = nodes . length ; i < n ; i ++ ) {
1862- if ( i ) {
1863+ if ( currentWriterPos !== writer . getTextPos ( ) ) {
18631864 write ( ", " ) ;
18641865 }
1865- emitNode ( nodes [ i ] ) ;
1866+ currentWriterPos = writer . getTextPos ( ) ;
1867+ eachNodeEmitFn ( nodes [ i ] ) ;
18661868 }
18671869 }
18681870
1869- function emitCommaSeparatedSymbolToString ( nodes : Node [ ] ) {
1870- if ( nodes ) {
1871- for ( var i = 0 , n = nodes . length ; i < n ; i ++ ) {
1872- if ( i ) {
1873- write ( ", " ) ;
1874- }
1875- // TODO(shkamat): get the symbol name in the scope for this node
1876- emitSourceTextOfNode ( nodes [ i ] ) ;
1877- }
1878- }
1879- }
1880-
1881-
18821871 function emitSourceTextOfNode ( node : Node ) {
18831872 write ( getSourceTextOfLocalNode ( node ) ) ;
18841873 }
@@ -1902,7 +1891,7 @@ module ts {
19021891 }
19031892
19041893 // If this node is in external module, check if this is export assigned
1905- if ( node . parent . flags & NodeFlags . ExternalModule ) {
1894+ if ( getContainerOfModuleElementDeclaration ( node ) . flags & NodeFlags . ExternalModule ) {
19061895 return resolver . isReferencedInExportAssignment ( node ) ;
19071896 }
19081897
@@ -1915,8 +1904,9 @@ module ts {
19151904 return true ;
19161905 }
19171906
1918- // emit the declaration if this is global source file
1919- return node . parent . kind === SyntaxKind . SourceFile && ! ( node . parent . flags & NodeFlags . ExternalModule ) ;
1907+ // emit the declaration if this is in global scope source file
1908+ var moduleDeclaration = getContainerOfModuleElementDeclaration ( node ) ;
1909+ return moduleDeclaration . kind === SyntaxKind . SourceFile && ! ( moduleDeclaration . flags & NodeFlags . ExternalModule ) ;
19201910 }
19211911
19221912 function emitDeclarationFlags ( node : Declaration ) {
@@ -2013,17 +2003,27 @@ module ts {
20132003 }
20142004
20152005 function emitTypeParameters ( typeParameters : TypeParameterDeclaration [ ] ) {
2006+ function emitTypeParameter ( node : TypeParameterDeclaration ) {
2007+ emitSourceTextOfNode ( node . name ) ;
2008+ if ( node . constraint ) {
2009+ write ( " extends " ) ;
2010+ // TODO(shkamat): emit constraint using type
2011+ emitSourceTextOfNode ( node . constraint ) ;
2012+ }
2013+ }
2014+
20162015 if ( typeParameters ) {
20172016 write ( "<" ) ;
2018- emitCommaSeparatedSymbolToString ( typeParameters ) ;
2017+ emitCommaList ( typeParameters , emitTypeParameter ) ;
20192018 write ( ">" ) ;
20202019 }
20212020 }
20222021
20232022 function emitHeritageClause ( typeReferences : TypeReferenceNode [ ] , isImplementsList : boolean ) {
20242023 if ( typeReferences ) {
20252024 write ( isImplementsList ? " implments " : " extends " ) ;
2026- emitCommaSeparatedSymbolToString ( typeReferences ) ;
2025+ // TODO(shkamat): get the symbol name in the scope for this node
2026+ emitCommaList ( typeReferences , emitSourceTextOfNode ) ;
20272027 }
20282028 }
20292029
@@ -2083,21 +2083,24 @@ module ts {
20832083 }
20842084
20852085 function emitVariableDeclaration ( node : VariableDeclaration ) {
2086- emitSourceTextOfNode ( node . name ) ;
2087- // If optional property emit ?
2088- if ( node . kind === SyntaxKind . Property && ( node . flags & NodeFlags . QuestionMark ) ) {
2089- write ( "?" ) ;
2090- }
2091- if ( ! ( node . flags & NodeFlags . Private ) ) {
2092- // TODO(shkamat): emit type of the node in given scope
2086+ if ( node . kind !== SyntaxKind . VariableDeclaration || canEmitModuleElementDeclaration ( node ) ) {
2087+ emitSourceTextOfNode ( node . name ) ;
2088+ // If optional property emit ?
2089+ if ( node . kind === SyntaxKind . Property && ( node . flags & NodeFlags . QuestionMark ) ) {
2090+ write ( "?" ) ;
2091+ }
2092+ if ( ! ( node . flags & NodeFlags . Private ) ) {
2093+ // TODO(shkamat): emit type of the node in given scope
2094+ }
20932095 }
20942096 }
20952097
20962098 function emitVariableStatement ( node : VariableStatement ) {
2097- if ( canEmitModuleElementDeclaration ( node ) ) {
2099+ var hasDeclarationWithEmit = forEach ( node . declarations , varDeclaration => canEmitModuleElementDeclaration ( varDeclaration ) ) ;
2100+ if ( hasDeclarationWithEmit ) {
20982101 emitDeclarationFlags ( node ) ;
20992102 write ( "var " ) ;
2100- emitCommaList ( node . declarations ) ;
2103+ emitCommaList ( node . declarations , emitVariableDeclaration ) ;
21012104 write ( ";" ) ;
21022105 writeLine ( ) ;
21032106 }
@@ -2154,7 +2157,7 @@ module ts {
21542157 }
21552158
21562159 // Parameters
2157- emitCommaList ( node . parameters ) ;
2160+ emitCommaList ( node . parameters , emitParameterDeclaration ) ;
21582161
21592162 if ( node . kind === SyntaxKind . IndexSignature ) {
21602163 write ( "]" ) ;
@@ -2186,8 +2189,6 @@ module ts {
21862189
21872190 function emitNode ( node : Node ) {
21882191 switch ( node . kind ) {
2189- case SyntaxKind . Parameter :
2190- return emitParameterDeclaration ( < ParameterDeclaration > node ) ;
21912192 case SyntaxKind . Constructor :
21922193 case SyntaxKind . FunctionDeclaration :
21932194 case SyntaxKind . Method :
@@ -2202,8 +2203,6 @@ module ts {
22022203 return emitAccessorDeclaration ( < AccessorDeclaration > node ) ;
22032204 case SyntaxKind . VariableStatement :
22042205 return emitVariableStatement ( < VariableStatement > node ) ;
2205- case SyntaxKind . VariableDeclaration :
2206- return emitVariableDeclaration ( < VariableDeclaration > node ) ;
22072206 case SyntaxKind . Property :
22082207 return emitPropertyDeclaration ( < PropertyDeclaration > node ) ;
22092208 case SyntaxKind . InterfaceDeclaration :
0 commit comments