@@ -2229,9 +2229,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
22292229 emitEmbeddedStatement ( node . statement ) ;
22302230 }
22312231
2232- /* Returns true if start of variable declaration list was emitted.
2233- * Return false if nothing was written - this can happen for source file level variable declarations
2234- * in system modules - such variable declarations are hoisted.
2232+ /**
2233+ * Returns true if start of variable declaration list was emitted.
2234+ * Returns false if nothing was written - this can happen for source file level variable declarations
2235+ * in system modules where such variable declarations are hoisted.
22352236 */
22362237 function tryEmitStartOfVariableDeclarationList ( decl : VariableDeclarationList , startPos ?: number ) : boolean {
22372238 if ( shouldHoistVariable ( decl , /*checkIfSourceFileLevelDecl*/ true ) ) {
@@ -3060,6 +3061,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
30603061
30613062 function emitVariableStatement ( node : VariableStatement ) {
30623063 let startIsEmitted = false ;
3064+
30633065 if ( node . flags & NodeFlags . Export ) {
30643066 if ( isES6ExportedDeclaration ( node ) ) {
30653067 // Exported ES6 module member
@@ -3070,6 +3072,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
30703072 else {
30713073 startIsEmitted = tryEmitStartOfVariableDeclarationList ( node . declarationList ) ;
30723074 }
3075+
30733076 if ( startIsEmitted ) {
30743077 emitCommaList ( node . declarationList . declarations ) ;
30753078 write ( ";" ) ;
@@ -3085,6 +3088,28 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
30853088 }
30863089 }
30873090
3091+ function shouldEmitLeadingAndTrailingCommentsForVariableStatement ( node : VariableStatement ) {
3092+ // If we're not exporting the variables, there's nothing special here.
3093+ // Always emit comments for these nodes.
3094+ if ( ! ( node . flags & NodeFlags . Export ) ) {
3095+ return true ;
3096+ }
3097+
3098+ // If we are exporting, but it's a top-level ES6 module exports,
3099+ // we'll emit the declaration list verbatim, so emit comments too.
3100+ if ( isES6ExportedDeclaration ( node ) ) {
3101+ return true ;
3102+ }
3103+
3104+ // Otherwise, only emit if we have at least one initializer present.
3105+ for ( let declaration of node . declarationList . declarations ) {
3106+ if ( declaration . initializer ) {
3107+ return true ;
3108+ }
3109+ }
3110+ return false ;
3111+ }
3112+
30883113 function emitParameter ( node : ParameterDeclaration ) {
30893114 if ( languageVersion < ScriptTarget . ES6 ) {
30903115 if ( isBindingPattern ( node . name ) ) {
@@ -5747,6 +5772,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
57475772 case SyntaxKind . ExportAssignment :
57485773 return false ;
57495774
5775+ case SyntaxKind . VariableStatement :
5776+ return shouldEmitLeadingAndTrailingCommentsForVariableStatement ( < VariableStatement > node ) ;
5777+
57505778 case SyntaxKind . ModuleDeclaration :
57515779 // Only emit the leading/trailing comments for a module if we're actually
57525780 // emitting the module as well.
0 commit comments