spanFor method
Returns the span associated with line
and column
.
uri
is the optional location of the output file to find the span for
to disambiguate cases where a mapping may have different mappings for
different output files.
Implementation
@override
SourceMapSpan? spanFor(int line, int column,
{Map<String, SourceFile>? files, String? uri}) {
var entry = _findColumn(line, column, _findLine(line));
if (entry == null) return null;
var sourceUrlId = entry.sourceUrlId;
if (sourceUrlId == null) return null;
var url = urls[sourceUrlId];
if (sourceRoot != null) {
url = '$sourceRoot$url';
}
var sourceNameId = entry.sourceNameId;
var file = files?[url];
if (file != null) {
var start = file.getOffset(entry.sourceLine!, entry.sourceColumn);
if (sourceNameId != null) {
var text = names[sourceNameId];
return SourceMapFileSpan(file.span(start, start + text.length),
isIdentifier: true);
} else {
return SourceMapFileSpan(file.location(start).pointSpan());
}
} else {
var start = SourceLocation(0,
sourceUrl: _mapUrl?.resolve(url) ?? url,
line: entry.sourceLine,
column: entry.sourceColumn);
// Offset and other context is not available.
if (sourceNameId != null) {
return SourceMapSpan.identifier(start, names[sourceNameId]);
} else {
return SourceMapSpan(start, start, '');
}
}
}