@@ -179,11 +179,11 @@ class BasicSourceMapConsumer extends SourceMapConsumer {
179
179
}
180
180
181
181
const version = util . getArg ( sourceMap , "version" ) ;
182
- let sources = util . getArg ( sourceMap , "sources" ) ;
182
+ const sources = util . getArg ( sourceMap , "sources" ) . map ( String ) ;
183
183
// Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
184
184
// requires the array) to play nice here.
185
185
const names = util . getArg ( sourceMap , "names" , [ ] ) ;
186
- let sourceRoot = util . getArg ( sourceMap , "sourceRoot" , null ) ;
186
+ const sourceRoot = util . getArg ( sourceMap , "sourceRoot" , null ) ;
187
187
const sourcesContent = util . getArg ( sourceMap , "sourcesContent" , null ) ;
188
188
const mappings = util . getArg ( sourceMap , "mappings" ) ;
189
189
const file = util . getArg ( sourceMap , "file" , null ) ;
@@ -194,36 +194,16 @@ class BasicSourceMapConsumer extends SourceMapConsumer {
194
194
throw new Error ( "Unsupported version: " + version ) ;
195
195
}
196
196
197
- if ( sourceRoot ) {
198
- sourceRoot = util . normalize ( sourceRoot ) ;
199
- }
200
-
201
- sources = sources
202
- . map ( String )
203
- // Some source maps produce relative source paths like "./foo.js" instead of
204
- // "foo.js". Normalize these first so that future comparisons will succeed.
205
- // See bugzil.la/1090768.
206
- . map ( util . normalize )
207
- // Always ensure that absolute sources are internally stored relative to
208
- // the source root, if the source root is absolute. Not doing this would
209
- // be particularly problematic when the source root is a prefix of the
210
- // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
211
- . map ( function ( source ) {
212
- return sourceRoot && util . isAbsolute ( sourceRoot ) && util . isAbsolute ( source )
213
- ? util . relative ( sourceRoot , source )
214
- : source ;
215
- } ) ;
216
-
217
197
// Pass `true` below to allow duplicate names and sources. While source maps
218
198
// are intended to be compressed and deduplicated, the TypeScript compiler
219
199
// sometimes generates source maps with duplicates in them. See Github issue
220
200
// #72 and bugzil.la/889492.
221
201
that . _names = ArraySet . fromArray ( names . map ( String ) , true ) ;
222
202
that . _sources = ArraySet . fromArray ( sources , true ) ;
223
203
224
- that . _absoluteSources = that . _sources . toArray ( ) . map ( function ( s ) {
204
+ that . _absoluteSources = ArraySet . fromArray ( that . _sources . toArray ( ) . map ( function ( s ) {
225
205
return util . computeSourceURL ( sourceRoot , s , aSourceMapURL ) ;
226
- } ) ;
206
+ } ) , true ) ;
227
207
228
208
that . sourceRoot = sourceRoot ;
229
209
that . sourcesContent = sourcesContent ;
@@ -247,21 +227,16 @@ class BasicSourceMapConsumer extends SourceMapConsumer {
247
227
* found.
248
228
*/
249
229
_findSourceIndex ( aSource ) {
250
- let relativeSource = aSource ;
251
- if ( this . sourceRoot != null ) {
252
- relativeSource = util . relative ( this . sourceRoot , relativeSource ) ;
230
+ // Treat the source as map-relative overall by default.
231
+ const sourceAsMapRelative = util . computeSourceURL ( null , aSource , this . _sourceMapURL ) ;
232
+ if ( this . _absoluteSources . has ( sourceAsMapRelative ) ) {
233
+ return this . _absoluteSources . indexOf ( sourceAsMapRelative ) ;
253
234
}
254
235
255
- if ( this . _sources . has ( relativeSource ) ) {
256
- return this . _sources . indexOf ( relativeSource ) ;
257
- }
258
-
259
- // Maybe aSource is an absolute URL as returned by |sources|. In
260
- // this case we can't simply undo the transform.
261
- for ( let i = 0 ; i < this . _absoluteSources . length ; ++ i ) {
262
- if ( this . _absoluteSources [ i ] == aSource ) {
263
- return i ;
264
- }
236
+ // Fall back to treating the source as sourceRoot-relative.
237
+ const sourceAsSourceRootRelative = util . computeSourceURL ( this . sourceRoot , aSource , this . _sourceMapURL ) ;
238
+ if ( this . _absoluteSources . has ( sourceAsSourceRootRelative ) ) {
239
+ return this . _absoluteSources . indexOf ( sourceAsSourceRootRelative ) ;
265
240
}
266
241
267
242
return - 1 ;
@@ -281,7 +256,7 @@ class BasicSourceMapConsumer extends SourceMapConsumer {
281
256
}
282
257
283
258
get sources ( ) {
284
- return this . _absoluteSources . slice ( ) ;
259
+ return this . _absoluteSources . toArray ( ) ;
285
260
}
286
261
287
262
_getMappingsPtr ( ) {
@@ -341,13 +316,11 @@ class BasicSourceMapConsumer extends SourceMapConsumer {
341
316
eachMapping ( aCallback , aContext , aOrder ) {
342
317
const context = aContext || null ;
343
318
const order = aOrder || SourceMapConsumer . GENERATED_ORDER ;
344
- const sourceRoot = this . sourceRoot ;
345
319
346
320
this . _wasm . withMappingCallback (
347
321
mapping => {
348
322
if ( mapping . source !== null ) {
349
- mapping . source = this . _sources . at ( mapping . source ) ;
350
- mapping . source = util . computeSourceURL ( sourceRoot , mapping . source , this . _sourceMapURL ) ;
323
+ mapping . source = this . _absoluteSources . at ( mapping . source ) ;
351
324
352
325
if ( mapping . name !== null ) {
353
326
mapping . name = this . _names . at ( mapping . name ) ;
@@ -496,8 +469,7 @@ class BasicSourceMapConsumer extends SourceMapConsumer {
496
469
if ( mapping . generatedLine === needle . generatedLine ) {
497
470
let source = util . getArg ( mapping , "source" , null ) ;
498
471
if ( source !== null ) {
499
- source = this . _sources . at ( source ) ;
500
- source = util . computeSourceURL ( this . sourceRoot , source , this . _sourceMapURL ) ;
472
+ source = this . _absoluteSources . at ( source ) ;
501
473
}
502
474
503
475
let name = util . getArg ( mapping , "name" , null ) ;
@@ -549,30 +521,6 @@ class BasicSourceMapConsumer extends SourceMapConsumer {
549
521
return this . sourcesContent [ index ] ;
550
522
}
551
523
552
- let relativeSource = aSource ;
553
- if ( this . sourceRoot != null ) {
554
- relativeSource = util . relative ( this . sourceRoot , relativeSource ) ;
555
- }
556
-
557
- let url ;
558
- if ( this . sourceRoot != null
559
- && ( url = util . urlParse ( this . sourceRoot ) ) ) {
560
- // XXX: file:// URIs and absolute paths lead to unexpected behavior for
561
- // many users. We can help them out when they expect file:// URIs to
562
- // behave like it would if they were running a local HTTP server. See
563
- // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
564
- const fileUriAbsPath = relativeSource . replace ( / ^ f i l e : \/ \/ / , "" ) ;
565
- if ( url . scheme == "file"
566
- && this . _sources . has ( fileUriAbsPath ) ) {
567
- return this . sourcesContent [ this . _sources . indexOf ( fileUriAbsPath ) ] ;
568
- }
569
-
570
- if ( ( ! url . path || url . path == "/" )
571
- && this . _sources . has ( "/" + relativeSource ) ) {
572
- return this . sourcesContent [ this . _sources . indexOf ( "/" + relativeSource ) ] ;
573
- }
574
- }
575
-
576
524
// This function is used recursively from
577
525
// IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
578
526
// don't want to throw if we can't find the source - we just want to
@@ -581,7 +529,7 @@ class BasicSourceMapConsumer extends SourceMapConsumer {
581
529
return null ;
582
530
}
583
531
584
- throw new Error ( '"' + relativeSource + '" is not in the SourceMap.' ) ;
532
+ throw new Error ( '"' + aSource + '" is not in the SourceMap.' ) ;
585
533
}
586
534
587
535
/**
0 commit comments