@@ -343,28 +343,17 @@ class Locations {
343343 // Create TokenPos for each entry in the source map.
344344 for (var lineEntry in mapping.lines) {
345345 for (var entry in lineEntry.entries) {
346- final index = entry.sourceUrlId;
347- if (index == null ) continue ;
348- // Source map URLS are relative to the script. They may have platform separators
349- // or they may use URL semantics. To be sure, we split and re-join them.
350- // This works on Windows because path treats both / and \ as separators.
351- // It will fail if the path has both separators in it.
352- final relativeSegments = p.split (mapping.urls[index]);
353- final path = p.url.normalize (
354- p.url.joinAll ([scriptLocation, ...relativeSegments]),
355- );
356-
357- final dartUri = DartUri (path, _root);
358-
359- result.add (
360- Location .from (
361- modulePath,
362- lineEntry,
363- entry,
364- dartUri,
365- runtimeScriptId,
366- ),
346+ final location = _locationForSourceMapEntry (
347+ lineEntry: lineEntry,
348+ entry: entry,
349+ modulePath: modulePath,
350+ runtimeScriptId: runtimeScriptId,
351+ sourceUrls: mapping.urls,
352+ scriptLocation: scriptLocation,
367353 );
354+ if (location != null ) {
355+ result.add (location);
356+ }
368357 }
369358 }
370359 }
@@ -379,4 +368,41 @@ class Locations {
379368 return _moduleToLocations[module] = result;
380369 });
381370 }
371+
372+ /// Creates a TokenPos [Location] for an entry in the source map.
373+ Location ? _locationForSourceMapEntry ({
374+ required TargetLineEntry lineEntry,
375+ required TargetEntry entry,
376+ required String modulePath,
377+ required String ? runtimeScriptId,
378+ required List <String > sourceUrls,
379+ required String scriptLocation,
380+ }) {
381+ final index = entry.sourceUrlId;
382+ if (index == null ) return null ;
383+ // Source map URLS are relative to the script. They may have platform separators
384+ // or they may use URL semantics. To be sure, we split and re-join them.
385+ // This works on Windows because path treats both / and \ as separators.
386+ // It will fail if the path has both separators in it.
387+ final relativeSegments = p.split (sourceUrls[index]);
388+ final path = p.url.normalize (
389+ p.url.joinAll ([scriptLocation, ...relativeSegments]),
390+ );
391+
392+ try {
393+ final dartUri = DartUri (path, _root);
394+ return Location .from (
395+ modulePath,
396+ lineEntry,
397+ entry,
398+ dartUri,
399+ runtimeScriptId,
400+ );
401+ } catch (error) {
402+ // DartUri throws if the path format is unrecognized. Log any errors and
403+ // return null in that case.
404+ _logger.warning ('Error adding location for $path : $error ' );
405+ return null ;
406+ }
407+ }
382408}
0 commit comments