Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: sdk/lib/_internal/pub/asset/dart/serialize.dart

Issue 423823010: Support source_span spans in barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/barback/pubspec.yaml ('k') | sdk/lib/_internal/pub/lib/src/barback.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library pub.asset.serialize; 5 library pub.asset.serialize;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:isolate'; 8 import 'dart:isolate';
9 9
10 import 'package:barback/barback.dart'; 10 import 'package:barback/barback.dart';
11 import 'package:source_maps/span.dart'; 11
12 //# if source_maps >=0.9.0 <0.10.0
13 //> import 'package:source_maps/span.dart';
14 //# end
15
16 //# if source_span
17 import 'package:source_span/source_span.dart';
18 //# end
12 19
13 import 'serialize/exception.dart'; 20 import 'serialize/exception.dart';
14 import 'utils.dart'; 21 import 'utils.dart';
15 22
16 export 'serialize/aggregate_transform.dart'; 23 export 'serialize/aggregate_transform.dart';
17 export 'serialize/exception.dart'; 24 export 'serialize/exception.dart';
18 export 'serialize/transform.dart'; 25 export 'serialize/transform.dart';
19 export 'serialize/transformer.dart'; 26 export 'serialize/transformer.dart';
20 27
21 /// Converts [id] into a serializable map. 28 /// Converts [id] into a serializable map.
22 Map serializeId(AssetId id) => {'package': id.package, 'path': id.path}; 29 Map serializeId(AssetId id) => {'package': id.package, 'path': id.path};
23 30
24 /// Converts a serializable map into an [AssetId]. 31 /// Converts a serializable map into an [AssetId].
25 AssetId deserializeId(Map id) => new AssetId(id['package'], id['path']); 32 AssetId deserializeId(Map id) => new AssetId(id['package'], id['path']);
26 33
27 /// Converts [span] into a serializable map. 34 /// Converts [span] into a serializable map.
28 Map serializeSpan(Span span) { 35 ///
36 /// [span] may be a [SourceSpan] or a [Span].
37 Map serializeSpan(span) {
29 // TODO(nweiz): convert FileSpans to FileSpans. 38 // TODO(nweiz): convert FileSpans to FileSpans.
39 // Handily, this code works for both source_map and source_span spans.
30 return { 40 return {
31 'type': 'fixed', 41 'sourceUrl': span.sourceUrl.toString(),
32 'sourceUrl': span.sourceUrl,
33 'start': serializeLocation(span.start), 42 'start': serializeLocation(span.start),
43 'end': serializeLocation(span.end),
34 'text': span.text, 44 'text': span.text,
35 'isIdentifier': span.isIdentifier
36 }; 45 };
37 } 46 }
38 47
39 /// Converts a serializable map into a [Span]. 48 /// Converts a serializable map into a [SourceSpan].
40 Span deserializeSpan(Map span) { 49 SourceSpan deserializeSpan(Map span) {
41 assert(span['type'] == 'fixed'); 50 return new SourceSpan(
42 var location = deserializeLocation(span['start']); 51 deserializeLocation(span['start']),
43 return new FixedSpan(span['sourceUrl'], location.offset, location.line, 52 deserializeLocation(span['end']),
44 location.column, text: span['text'], isIdentifier: span['isIdentifier']); 53 span['text']);
45 } 54 }
46 55
47 /// Converts [location] into a serializable map. 56 /// Converts [location] into a serializable map.
48 Map serializeLocation(Location location) { 57 ///
58 /// [location] may be a [SourceLocation] or a [SourceLocation].
59 Map serializeLocation(location) {
60 //# if source_maps >=0.9.0 <0.10.0
61 //> if (location is Location) {
62 //> return {
63 //> 'sourceUrl': location.sourceUrl,
64 //> 'offset': location.offset,
65 //> 'line': location.line,
66 //> 'column': location.column
67 //> };
68 //> }
69 //# end
70
71 //# if source_span
49 // TODO(nweiz): convert FileLocations to FileLocations. 72 // TODO(nweiz): convert FileLocations to FileLocations.
50 return { 73 if (location is SourceLocation) {
51 'type': 'fixed', 74 return {
52 'sourceUrl': location.sourceUrl, 75 'sourceUrl': location.sourceUrl.toString(),
53 'offset': location.offset, 76 'offset': location.offset,
54 'line': location.line, 77 'line': location.line,
55 'column': location.column 78 'column': location.column
56 }; 79 };
80 }
81 //# end
82
83 throw new ArgumentError("Unknown type ${location.runtimeType} for location.");
57 } 84 }
58 85
59 /// Converts a serializable map into a [Location]. 86 /// Converts a serializable map into a [Location].
60 Location deserializeLocation(Map location) { 87 SourceLocation deserializeLocation(Map location) {
61 assert(location['type'] == 'fixed'); 88 return new SourceLocation(location['offset'],
62 return new FixedLocation(location['offset'], location['sourceUrl'], 89 sourceUrl: location['sourceUrl'],
63 location['line'], location['column']); 90 line: location['line'],
91 column: location['column']);
64 } 92 }
65 93
66 /// Converts [stream] into a serializable map. 94 /// Converts [stream] into a serializable map.
67 /// 95 ///
68 /// [serializeEvent] is used to serialize each event from the stream. 96 /// [serializeEvent] is used to serialize each event from the stream.
69 Map serializeStream(Stream stream, serializeEvent(event)) { 97 Map serializeStream(Stream stream, serializeEvent(event)) {
70 var receivePort = new ReceivePort(); 98 var receivePort = new ReceivePort();
71 var map = {'replyTo': receivePort.sendPort}; 99 var map = {'replyTo': receivePort.sendPort};
72 100
73 receivePort.first.then((message) { 101 receivePort.first.then((message) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 var replyTo = wrappedMessage['replyTo']; 175 var replyTo = wrappedMessage['replyTo'];
148 new Future.sync(() => callback(wrappedMessage['message'])) 176 new Future.sync(() => callback(wrappedMessage['message']))
149 .then((result) => replyTo.send({'type': 'success', 'value': result})) 177 .then((result) => replyTo.send({'type': 'success', 'value': result}))
150 .catchError((error, stackTrace) { 178 .catchError((error, stackTrace) {
151 replyTo.send({ 179 replyTo.send({
152 'type': 'error', 180 'type': 'error',
153 'error': serializeException(error, stackTrace) 181 'error': serializeException(error, stackTrace)
154 }); 182 });
155 }); 183 });
156 } 184 }
OLDNEW
« no previous file with comments | « pkg/barback/pubspec.yaml ('k') | sdk/lib/_internal/pub/lib/src/barback.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698