@@ -17,7 +17,6 @@ type SourcePos = {
1717 line : number | undefined ;
1818 column : number | undefined ;
1919 filename : string | undefined ;
20- force : boolean ;
2120} ;
2221
2322function SourcePos ( ) : SourcePos {
@@ -26,7 +25,6 @@ function SourcePos(): SourcePos {
2625 line : undefined ,
2726 column : undefined ,
2827 filename : undefined ,
29- force : false ,
3028 } ;
3129}
3230
@@ -88,9 +86,8 @@ export default class Buffer {
8886
8987 append ( str : string ) : void {
9088 this . _flush ( ) ;
91- const { line, column, filename, identifierName, force } =
92- this . _sourcePosition ;
93- this . _append ( str , line , column , identifierName , filename , force ) ;
89+ const { line, column, filename, identifierName } = this . _sourcePosition ;
90+ this . _append ( str , line , column , identifierName , filename ) ;
9491 }
9592
9693 /**
@@ -104,23 +101,15 @@ export default class Buffer {
104101 }
105102 }
106103
107- const { line, column, filename, identifierName, force } =
108- this . _sourcePosition ;
109- this . _queue . unshift ( [ str , line , column , identifierName , filename , force ] ) ;
104+ const { line, column, filename, identifierName } = this . _sourcePosition ;
105+ this . _queue . unshift ( [ str , line , column , identifierName , filename ] ) ;
110106 }
111107
112108 /**
113109 * Same as queue, but this indentation will never have a sourcmap marker.
114110 */
115111 queueIndentation ( str : string ) : void {
116- this . _queue . unshift ( [
117- str ,
118- undefined ,
119- undefined ,
120- undefined ,
121- undefined ,
122- false ,
123- ] ) ;
112+ this . _queue . unshift ( [ str , undefined , undefined , undefined , undefined ] ) ;
124113 }
125114
126115 _flush ( ) : void {
@@ -132,11 +121,10 @@ export default class Buffer {
132121
133122 _append (
134123 str : string ,
135- line : number ,
136- column : number ,
124+ line : number | undefined ,
125+ column : number | undefined ,
137126 identifierName : string | undefined ,
138127 filename : string | undefined ,
139- force : boolean ,
140128 ) : void {
141129 this . _buf += str ;
142130 this . _last = str . charCodeAt ( str . length - 1 ) ;
@@ -151,7 +139,7 @@ export default class Buffer {
151139 // If the string starts with a newline char, then adding a mark is redundant.
152140 // This catches both "no newlines" and "newline after several chars".
153141 if ( i !== 0 ) {
154- this . _mark ( line , column , identifierName , filename , force ) ;
142+ this . _mark ( line , column , identifierName , filename ) ;
155143 }
156144
157145 // Now, find each reamining newline char in the string.
@@ -163,28 +151,20 @@ export default class Buffer {
163151 // We mark the start of each line, which happens directly after this newline char
164152 // unless this is the last char.
165153 if ( last < str . length ) {
166- this . _mark ( ++ line , 0 , identifierName , filename , force ) ;
154+ this . _mark ( ++ line , 0 , identifierName , filename ) ;
167155 }
168156 i = str . indexOf ( "\n" , last ) ;
169157 }
170158 this . _position . column += str . length - last ;
171159 }
172160
173161 _mark (
174- line : number ,
175- column : number ,
176- identifierName ?: string | null ,
177- filename ?: string | null ,
178- force ?: boolean ,
162+ line : number | undefined ,
163+ column : number | undefined ,
164+ identifierName : string | undefined ,
165+ filename : string | undefined ,
179166 ) : void {
180- this . _map ?. mark (
181- this . _position ,
182- line ,
183- column ,
184- identifierName ,
185- filename ,
186- force ,
187- ) ;
167+ this . _map ?. mark ( this . _position , line , column , identifierName , filename ) ;
188168 }
189169
190170 removeTrailingNewline ( ) : void {
@@ -262,11 +242,7 @@ export default class Buffer {
262242 * over "();", where previously it would have been a single mapping.
263243 */
264244 exactSource ( loc : any , cb : ( ) => void ) {
265- // In cases where parent expressions start at the same locations as the
266- // identifier itself, the current active location could already be the
267- // start of this range. We use 'force' here to explicitly start a new
268- // mapping range for this new token.
269- this . source ( "start" , loc , true /* force */ ) ;
245+ this . source ( "start" , loc ) ;
270246
271247 cb ( ) ;
272248
@@ -286,12 +262,12 @@ export default class Buffer {
286262 * will be given this position in the sourcemap.
287263 */
288264
289- source ( prop : string , loc : t . SourceLocation , force ?: boolean ) : void {
265+ source ( prop : string , loc : t . SourceLocation ) : void {
290266 if ( prop && ! loc ) return ;
291267
292268 // Since this is called extremely often, we re-use the same _sourcePosition
293269 // object for the whole lifetime of the buffer.
294- this . _normalizePosition ( prop , loc , this . _sourcePosition , force ) ;
270+ this . _normalizePosition ( prop , loc , this . _sourcePosition ) ;
295271 }
296272
297273 /**
@@ -314,23 +290,16 @@ export default class Buffer {
314290 cb ( ) ;
315291
316292 if (
317- // If the current active position is forced, we only want to reactivate
318- // the old position if it is different from the newest position.
319- ( ! this . _sourcePosition . force ||
320- this . _sourcePosition . line !== originalLine ||
321- this . _sourcePosition . column !== originalColumn ||
322- this . _sourcePosition . filename !== originalFilename ) &&
323293 // Verify if reactivating this specific position has been disallowed.
324- ( ! this . _disallowedPop ||
325- this . _disallowedPop . line !== originalLine ||
326- this . _disallowedPop . column !== originalColumn ||
327- this . _disallowedPop . filename !== originalFilename )
294+ ! this . _disallowedPop ||
295+ this . _disallowedPop . line !== originalLine ||
296+ this . _disallowedPop . column !== originalColumn ||
297+ this . _disallowedPop . filename !== originalFilename
328298 ) {
329299 this . _sourcePosition . line = originalLine ;
330300 this . _sourcePosition . column = originalColumn ;
331301 this . _sourcePosition . filename = originalFilename ;
332302 this . _sourcePosition . identifierName = originalIdentifierName ;
333- this . _sourcePosition . force = false ;
334303 this . _disallowedPop = null ;
335304 }
336305 }
@@ -343,42 +312,22 @@ export default class Buffer {
343312 _disallowPop ( prop : string , loc : t . SourceLocation ) {
344313 if ( prop && ! loc ) return ;
345314
346- this . _disallowedPop = this . _normalizePosition (
347- prop ,
348- loc ,
349- SourcePos ( ) ,
350- false ,
351- ) ;
315+ this . _disallowedPop = this . _normalizePosition ( prop , loc , SourcePos ( ) ) ;
352316 }
353317
354318 _normalizePosition (
355319 prop : string ,
356320 loc : Loc | undefined | null ,
357321 targetObj : SourcePos ,
358- force : boolean ,
359322 ) {
360323 const pos = loc ? loc [ prop ] : null ;
361324
362- const origLine = targetObj . line ;
363- const origColumn = targetObj . column ;
364- const origFilename = targetObj . filename ;
365-
366325 targetObj . identifierName =
367- ( prop === "start" && loc ?. identifierName ) || null ;
326+ ( prop === "start" && loc ?. identifierName ) || undefined ;
368327 targetObj . line = pos ?. line ;
369328 targetObj . column = pos ?. column ;
370329 targetObj . filename = loc ?. filename ;
371330
372- // We want to skip reassigning `force` if we're re-setting the same position.
373- if (
374- force ||
375- targetObj . line !== origLine ||
376- targetObj . column !== origColumn ||
377- targetObj . filename !== origFilename
378- ) {
379- targetObj . force = force ;
380- }
381-
382331 return targetObj ;
383332 }
384333
0 commit comments