InterpolationMap constructor

InterpolationMap(
  1. Interpolation _interpolation,
  2. Iterable<SourceLocation> targetLocations
)

Creates a new interpolation map that maps the given targetLocations in the generated string to the contents of the interpolation.

Each target location at index i corresponds to the character in the generated string after interpolation.contents[i].

Implementation

InterpolationMap(
    this._interpolation, Iterable<SourceLocation> targetLocations)
    : _targetLocations = List.unmodifiable(targetLocations) {
  var expectedLocations = math.max(0, _interpolation.contents.length - 1);
  if (_targetLocations.length != expectedLocations) {
    throw ArgumentError(
        "InterpolationMap must have $expectedLocations targetLocations if the "
        "interpolation has ${_interpolation.contents.length} components.");
  }
}