SourceLocation constructor

SourceLocation(
  1. int offset, {
  2. Object? sourceUrl,
  3. int? line,
  4. int? column,
})

Creates a new location indicating offset within sourceUrl.

line and column default to assuming the source is a single line. This means that line defaults to 0 and column defaults to offset.

sourceUrl may be either a String, a Uri, or null.

Implementation

SourceLocation(this.offset, {Object? sourceUrl, int? line, int? column})
    : sourceUrl =
          sourceUrl is String ? Uri.parse(sourceUrl) : sourceUrl as Uri?,
      line = line ?? 0,
      column = column ?? offset {
  if (offset < 0) {
    throw RangeError('Offset may not be negative, was $offset.');
  } else if (line != null && line < 0) {
    throw RangeError('Line may not be negative, was $line.');
  } else if (column != null && column < 0) {
    throw RangeError('Column may not be negative, was $column.');
  }
}