MultiSectionMapping.fromJson constructor

MultiSectionMapping.fromJson(
  1. List sections,
  2. Map<String, Map>? otherMaps, {
  3. Object? mapUrl,
})

Creates a section mapping from json.

Implementation

MultiSectionMapping.fromJson(List sections, Map<String, Map>? otherMaps,
    {/*String|Uri*/ Object? mapUrl}) {
  for (var section in sections) {
    var offset = section['offset'];
    if (offset == null) throw FormatException('section missing offset');

    var line = section['offset']['line'];
    if (line == null) throw FormatException('offset missing line');

    var column = section['offset']['column'];
    if (column == null) throw FormatException('offset missing column');

    _lineStart.add(line);
    _columnStart.add(column);

    var url = section['url'];
    var map = section['map'];

    if (url != null && map != null) {
      throw FormatException("section can't use both url and map entries");
    } else if (url != null) {
      var other = otherMaps?[url];
      if (otherMaps == null || other == null) {
        throw FormatException(
            'section contains refers to $url, but no map was '
            'given for it. Make sure a map is passed in "otherMaps"');
      }
      _maps.add(parseJson(other, otherMaps: otherMaps, mapUrl: url));
    } else if (map != null) {
      _maps.add(parseJson(map, otherMaps: otherMaps, mapUrl: mapUrl));
    } else {
      throw FormatException('section missing url or map');
    }
  }
  if (_lineStart.isEmpty) {
    throw FormatException('expected at least one section');
  }
}