@@ -16,6 +16,14 @@ namespace ts {
1616 }
1717
1818 let nullSourceMapWriter : SourceMapWriter ;
19+ // Used for initialize lastEncodedSourceMapSpan and reset lastEncodedSourceMapSpan when updateLastEncodedAndRecordedSpans
20+ const defaultLastEncodedSourceMapSpan : SourceMapSpan = {
21+ emittedLine : 1 ,
22+ emittedColumn : 1 ,
23+ sourceLine : 1 ,
24+ sourceColumn : 1 ,
25+ sourceIndex : 0
26+ } ;
1927
2028 export function getNullSourceMapWriter ( ) : SourceMapWriter {
2129 if ( nullSourceMapWriter === undefined ) {
@@ -79,13 +87,7 @@ namespace ts {
7987
8088 // Last recorded and encoded spans
8189 lastRecordedSourceMapSpan = undefined ;
82- lastEncodedSourceMapSpan = {
83- emittedLine : 1 ,
84- emittedColumn : 1 ,
85- sourceLine : 1 ,
86- sourceColumn : 1 ,
87- sourceIndex : 0
88- } ;
90+ lastEncodedSourceMapSpan = defaultLastEncodedSourceMapSpan ;
8991 lastEncodedNameIndex = 0 ;
9092
9193 // Initialize source map data
@@ -159,10 +161,12 @@ namespace ts {
159161 // Pop sourceMapDecodedMappings to remove last entry
160162 sourceMapData . sourceMapDecodedMappings . pop ( ) ;
161163
162- // Change the last encoded source map
164+ // Point the lastEncodedSourceMapSpace to the previous encoded sourceMapSpan
165+ // If the list is empty which indicates that we are at the beginning of the file,
166+ // we have to reset it to default value (same value when we first initialize sourceMapWriter)
163167 lastEncodedSourceMapSpan = sourceMapData . sourceMapDecodedMappings . length ?
164168 sourceMapData . sourceMapDecodedMappings [ sourceMapData . sourceMapDecodedMappings . length - 1 ] :
165- undefined ;
169+ defaultLastEncodedSourceMapSpan ;
166170
167171 // TODO: Update lastEncodedNameIndex
168172 // Since we dont support this any more, lets not worry about it right now.
0 commit comments