From 661634b4a535d7fd0b0fb65389decefa61ddffca Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Fri, 29 Jan 2016 18:20:05 -0800 Subject: [PATCH] Fix lastEncodedSourceMapSpan from being set to undefined --- src/compiler/sourcemap.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/compiler/sourcemap.ts b/src/compiler/sourcemap.ts index 8abf1432b0c..86bad38cb6e 100644 --- a/src/compiler/sourcemap.ts +++ b/src/compiler/sourcemap.ts @@ -16,6 +16,14 @@ namespace ts { } let nullSourceMapWriter: SourceMapWriter; + // Used for initialize lastEncodedSourceMapSpan and reset lastEncodedSourceMapSpan when updateLastEncodedAndRecordedSpans + const defaultLastEncodedSourceMapSpan: SourceMapSpan = { + emittedLine: 1, + emittedColumn: 1, + sourceLine: 1, + sourceColumn: 1, + sourceIndex: 0 + }; export function getNullSourceMapWriter(): SourceMapWriter { if (nullSourceMapWriter === undefined) { @@ -79,13 +87,7 @@ namespace ts { // Last recorded and encoded spans lastRecordedSourceMapSpan = undefined; - lastEncodedSourceMapSpan = { - emittedLine: 1, - emittedColumn: 1, - sourceLine: 1, - sourceColumn: 1, - sourceIndex: 0 - }; + lastEncodedSourceMapSpan = defaultLastEncodedSourceMapSpan; lastEncodedNameIndex = 0; // Initialize source map data @@ -159,10 +161,12 @@ namespace ts { // Pop sourceMapDecodedMappings to remove last entry sourceMapData.sourceMapDecodedMappings.pop(); - // Change the last encoded source map + // Point the lastEncodedSourceMapSpace to the previous encoded sourceMapSpan + // If the list is empty which indicates that we are at the beginning of the file, + // we have to reset it to default value (same value when we first initialize sourceMapWriter) lastEncodedSourceMapSpan = sourceMapData.sourceMapDecodedMappings.length ? sourceMapData.sourceMapDecodedMappings[sourceMapData.sourceMapDecodedMappings.length - 1] : - undefined; + defaultLastEncodedSourceMapSpan; // TODO: Update lastEncodedNameIndex // Since we dont support this any more, lets not worry about it right now.