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.cast<Map>()) {
    var offset = section['offset'] as Map?;
    if (offset == null) throw FormatException('section missing offset');

    var line = offset['line'] as int?;
    if (line == null) throw FormatException('offset missing line');

    var column = offset['column'] as int?;
    if (column == null) throw FormatException('offset missing column');

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

    var url = section['url'] as String?;
    var map = section['map'] as 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');
  }
}