| Index: sdk/lib/_internal/pub/asset/dart/serialize.dart
|
| diff --git a/sdk/lib/_internal/pub/asset/dart/serialize.dart b/sdk/lib/_internal/pub/asset/dart/serialize.dart
|
| index 5e3237818c7ff255a8d14c664885d514900e6b67..f37ab70a179dd9004f8115800b379e68185676a9 100644
|
| --- a/sdk/lib/_internal/pub/asset/dart/serialize.dart
|
| +++ b/sdk/lib/_internal/pub/asset/dart/serialize.dart
|
| @@ -8,7 +8,14 @@ import 'dart:async';
|
| import 'dart:isolate';
|
|
|
| import 'package:barback/barback.dart';
|
| -import 'package:source_maps/span.dart';
|
| +
|
| +//# if source_maps >=0.9.0 <0.10.0
|
| +//> import 'package:source_maps/span.dart';
|
| +//# end
|
| +
|
| +//# if source_span
|
| +import 'package:source_span/source_span.dart';
|
| +//# end
|
|
|
| import 'serialize/exception.dart';
|
| import 'utils.dart';
|
| @@ -25,42 +32,63 @@ Map serializeId(AssetId id) => {'package': id.package, 'path': id.path};
|
| AssetId deserializeId(Map id) => new AssetId(id['package'], id['path']);
|
|
|
| /// Converts [span] into a serializable map.
|
| -Map serializeSpan(Span span) {
|
| +///
|
| +/// [span] may be a [SourceSpan] or a [Span].
|
| +Map serializeSpan(span) {
|
| // TODO(nweiz): convert FileSpans to FileSpans.
|
| + // Handily, this code works for both source_map and source_span spans.
|
| return {
|
| - 'type': 'fixed',
|
| - 'sourceUrl': span.sourceUrl,
|
| + 'sourceUrl': span.sourceUrl.toString(),
|
| 'start': serializeLocation(span.start),
|
| + 'end': serializeLocation(span.end),
|
| 'text': span.text,
|
| - 'isIdentifier': span.isIdentifier
|
| };
|
| }
|
|
|
| -/// Converts a serializable map into a [Span].
|
| -Span deserializeSpan(Map span) {
|
| - assert(span['type'] == 'fixed');
|
| - var location = deserializeLocation(span['start']);
|
| - return new FixedSpan(span['sourceUrl'], location.offset, location.line,
|
| - location.column, text: span['text'], isIdentifier: span['isIdentifier']);
|
| +/// Converts a serializable map into a [SourceSpan].
|
| +SourceSpan deserializeSpan(Map span) {
|
| + return new SourceSpan(
|
| + deserializeLocation(span['start']),
|
| + deserializeLocation(span['end']),
|
| + span['text']);
|
| }
|
|
|
| /// Converts [location] into a serializable map.
|
| -Map serializeLocation(Location location) {
|
| +///
|
| +/// [location] may be a [SourceLocation] or a [SourceLocation].
|
| +Map serializeLocation(location) {
|
| +//# if source_maps >=0.9.0 <0.10.0
|
| +//> if (location is Location) {
|
| +//> return {
|
| +//> 'sourceUrl': location.sourceUrl,
|
| +//> 'offset': location.offset,
|
| +//> 'line': location.line,
|
| +//> 'column': location.column
|
| +//> };
|
| +//> }
|
| +//# end
|
| +
|
| +//# if source_span
|
| // TODO(nweiz): convert FileLocations to FileLocations.
|
| - return {
|
| - 'type': 'fixed',
|
| - 'sourceUrl': location.sourceUrl,
|
| - 'offset': location.offset,
|
| - 'line': location.line,
|
| - 'column': location.column
|
| - };
|
| + if (location is SourceLocation) {
|
| + return {
|
| + 'sourceUrl': location.sourceUrl.toString(),
|
| + 'offset': location.offset,
|
| + 'line': location.line,
|
| + 'column': location.column
|
| + };
|
| + }
|
| +//# end
|
| +
|
| + throw new ArgumentError("Unknown type ${location.runtimeType} for location.");
|
| }
|
|
|
| /// Converts a serializable map into a [Location].
|
| -Location deserializeLocation(Map location) {
|
| - assert(location['type'] == 'fixed');
|
| - return new FixedLocation(location['offset'], location['sourceUrl'],
|
| - location['line'], location['column']);
|
| +SourceLocation deserializeLocation(Map location) {
|
| + return new SourceLocation(location['offset'],
|
| + sourceUrl: location['sourceUrl'],
|
| + line: location['line'],
|
| + column: location['column']);
|
| }
|
|
|
| /// Converts [stream] into a serializable map.
|
|
|