Chromium Code Reviews| 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..c0a88a3d6bc756df3c986cf9736ee8a72c8513fc 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]. |
|
Bob Nystrom
2014/07/29 22:57:00
Span -> SourceSpan.
nweiz
2014/07/29 23:04:18
Done.
|
| -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']); |
| +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 [Location]. |
| +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]. |
|
Bob Nystrom
2014/07/29 22:57:00
Location -> SourceLocation.
nweiz
2014/07/29 23:04:18
Done.
|
| -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. |