@@ -16,6 +16,14 @@ namespace ts {
16
16
}
17
17
18
18
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
+ } ;
19
27
20
28
export function getNullSourceMapWriter ( ) : SourceMapWriter {
21
29
if ( nullSourceMapWriter === undefined ) {
@@ -79,13 +87,7 @@ namespace ts {
79
87
80
88
// Last recorded and encoded spans
81
89
lastRecordedSourceMapSpan = undefined ;
82
- lastEncodedSourceMapSpan = {
83
- emittedLine : 1 ,
84
- emittedColumn : 1 ,
85
- sourceLine : 1 ,
86
- sourceColumn : 1 ,
87
- sourceIndex : 0
88
- } ;
90
+ lastEncodedSourceMapSpan = defaultLastEncodedSourceMapSpan ;
89
91
lastEncodedNameIndex = 0 ;
90
92
91
93
// Initialize source map data
@@ -159,10 +161,12 @@ namespace ts {
159
161
// Pop sourceMapDecodedMappings to remove last entry
160
162
sourceMapData . sourceMapDecodedMappings . pop ( ) ;
161
163
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)
163
167
lastEncodedSourceMapSpan = sourceMapData . sourceMapDecodedMappings . length ?
164
168
sourceMapData . sourceMapDecodedMappings [ sourceMapData . sourceMapDecodedMappings . length - 1 ] :
165
- undefined ;
169
+ defaultLastEncodedSourceMapSpan ;
166
170
167
171
// TODO: Update lastEncodedNameIndex
168
172
// Since we dont support this any more, lets not worry about it right now.
0 commit comments