@@ -151,8 +151,8 @@ namespace ts {
151151
152152 // Initialize source map data
153153 completedSections = [ ] ;
154- sectionStartLine = 0 ;
155- sectionStartColumn = 0 ;
154+ sectionStartLine = 1 ;
155+ sectionStartColumn = 1 ;
156156 sourceMapData = {
157157 sourceMapFilePath,
158158 jsSourceMappingURL : ! compilerOptions . inlineSourceMap ? getBaseFileName ( normalizeSlashes ( sourceMapFilePath ) ) : undefined ! , // TODO: GH#18217
@@ -270,14 +270,11 @@ namespace ts {
270270
271271 function generateMap ( ) : SourceMap {
272272 if ( completedSections . length ) {
273- const last = {
274- offset : { line : sectionStartLine , column : sectionStartColumn } ,
275- map : captureSection ( )
276- } ;
273+ captureSectionalSpanIfNeeded ( /*reset*/ false ) ;
277274 return {
278275 version : 3 ,
279- file : last . map . file ,
280- sections : [ ... completedSections , last ]
276+ file : sourceMapData . sourceMapFile ,
277+ sections : completedSections
281278 } ;
282279 }
283280 else {
@@ -353,8 +350,8 @@ namespace ts {
353350 sourceLinePos . line ++ ;
354351 sourceLinePos . character ++ ;
355352
356- const emittedLine = writer . getLine ( ) - sectionStartLine ;
357- const emittedColumn = emittedLine === 0 ? writer . getColumn ( ) - sectionStartColumn : writer . getColumn ( ) ;
353+ const emittedLine = writer . getLine ( ) - sectionStartLine + 1 ;
354+ const emittedColumn = emittedLine === 0 ? ( writer . getColumn ( ) - sectionStartColumn + 1 ) : writer . getColumn ( ) ;
358355
359356 // If this location wasn't recorded or the location in source is going backwards, record the span
360357 if ( ! lastRecordedSourceMapSpan ||
@@ -389,6 +386,15 @@ namespace ts {
389386 }
390387 }
391388
389+ function captureSectionalSpanIfNeeded ( reset : boolean ) {
390+ if ( lastRecordedSourceMapSpan && lastRecordedSourceMapSpan === lastEncodedSourceMapSpan ) { // If we've recorded some spans, save them
391+ completedSections . push ( { offset : { line : sectionStartLine - 1 , column : sectionStartColumn - 1 } , map : captureSection ( ) } ) ;
392+ if ( reset ) {
393+ resetSectionalData ( ) ;
394+ }
395+ }
396+ }
397+
392398 /**
393399 * Emits a node with possible leading and trailing source maps.
394400 *
@@ -403,10 +409,7 @@ namespace ts {
403409
404410 if ( node ) {
405411 if ( isUnparsedSource ( node ) && node . sourceMapText !== undefined ) {
406- if ( lastRecordedSourceMapSpan && lastRecordedSourceMapSpan === lastEncodedSourceMapSpan ) { // If we've recorded some spans, save them
407- completedSections . push ( { offset : { line : sectionStartLine , column : sectionStartColumn } , map : captureSection ( ) } ) ;
408- resetSectionalData ( ) ;
409- }
412+ captureSectionalSpanIfNeeded ( /*reset*/ true ) ;
410413 const text = node . sourceMapText ;
411414 let parsed : { } | undefined ;
412415 try {
@@ -415,7 +418,7 @@ namespace ts {
415418 catch {
416419 // empty
417420 }
418- const offset = { line : writer . getLine ( ) , column : writer . getColumn ( ) } ;
421+ const offset = { line : writer . getLine ( ) - 1 , column : writer . getColumn ( ) - 1 } ;
419422 completedSections . push ( parsed
420423 ? {
421424 offset,
@@ -431,7 +434,7 @@ namespace ts {
431434 sectionStartLine = writer . getLine ( ) ;
432435 sectionStartColumn = writer . getColumn ( ) ;
433436 lastRecordedSourceMapSpan = undefined ! ;
434- lastEncodedSourceMapSpan = undefined ! ;
437+ lastEncodedSourceMapSpan = defaultLastEncodedSourceMapSpan ;
435438 return emitResult ;
436439 }
437440 const emitNode = node . emitNode ;
0 commit comments