OLD | NEW |
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.transformer; | 5 library pub.asset.serialize.transformer; |
6 | 6 |
7 import 'dart:isolate'; | 7 import 'dart:isolate'; |
8 | 8 |
9 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
10 // TODO(nweiz): don't import from "src" once issue 14966 is fixed. | |
11 import 'package:barback/src/internal_asset.dart'; | |
12 | 10 |
13 import '../serialize.dart'; | 11 import '../serialize.dart'; |
14 import 'transform.dart'; | 12 import 'transform.dart'; |
15 | 13 |
16 /// Converts [transformer] into a serializable map. | 14 /// Converts [transformer] into a serializable map. |
17 Map serializeTransformer(Transformer transformer) { | 15 Map _serializeTransformer(Transformer transformer) { |
18 var port = new ReceivePort(); | 16 var port = new ReceivePort(); |
19 port.listen((wrappedMessage) { | 17 port.listen((wrappedMessage) { |
20 respond(wrappedMessage, (message) { | 18 respond(wrappedMessage, (message) { |
21 if (message['type'] == 'isPrimary') { | 19 if (message['type'] == 'isPrimary') { |
22 return transformer.isPrimary(deserializeId(message['id'])); | 20 return transformer.isPrimary(deserializeId(message['id'])); |
| 21 } else if (message['type'] == 'declareOutputs') { |
| 22 return (transformer as DeclaringTransformer).declareOutputs( |
| 23 new ForeignDeclaringTransform(message['transform'])) |
| 24 .then((_) => null); |
23 } else { | 25 } else { |
24 assert(message['type'] == 'apply'); | 26 assert(message['type'] == 'apply'); |
25 | 27 |
26 // Make sure we return null so that if the transformer's [apply] returns | 28 // Make sure we return null so that if the transformer's [apply] returns |
27 // a non-serializable value it doesn't cause problems. | 29 // a non-serializable value it doesn't cause problems. |
28 return transformer.apply( | 30 return transformer.apply( |
29 new ForeignTransform(message['transform'])).then((_) => null); | 31 new ForeignTransform(message['transform'])).then((_) => null); |
30 } | 32 } |
31 }); | 33 }); |
32 }); | 34 }); |
33 | 35 |
| 36 var type; |
| 37 if (transformer is LazyTransformer) { |
| 38 type = 'LazyTransformer'; |
| 39 } else if (transformer is DeclaringTransformer) { |
| 40 type = 'DeclaringTransformer'; |
| 41 } else { |
| 42 type = 'Transformer'; |
| 43 } |
| 44 |
34 return { | 45 return { |
35 'type': 'Transformer', | 46 'type': type, |
36 'toString': transformer.toString(), | 47 'toString': transformer.toString(), |
37 'port': port.sendPort | 48 'port': port.sendPort |
38 }; | 49 }; |
39 } | 50 } |
40 | 51 |
41 // Converts [group] into a serializable map. | 52 // Converts [group] into a serializable map. |
42 Map serializeTransformerGroup(TransformerGroup group) { | 53 Map _serializeTransformerGroup(TransformerGroup group) { |
43 return { | 54 return { |
44 'type': 'TransformerGroup', | 55 'type': 'TransformerGroup', |
45 'toString': group.toString(), | 56 'toString': group.toString(), |
46 'phases': group.phases.map((phase) { | 57 'phases': group.phases.map((phase) { |
47 return phase.map(serializeTransformerOrGroup).toList(); | 58 return phase.map(serializeTransformerOrGroup).toList(); |
48 }).toList() | 59 }).toList() |
49 }; | 60 }; |
50 } | 61 } |
51 | 62 |
52 /// Converts [transformerOrGroup] into a serializable map. | 63 /// Converts [transformerOrGroup] into a serializable map. |
53 Map serializeTransformerOrGroup(transformerOrGroup) { | 64 Map serializeTransformerOrGroup(transformerOrGroup) { |
54 if (transformerOrGroup is Transformer) { | 65 if (transformerOrGroup is Transformer) { |
55 return serializeTransformer(transformerOrGroup); | 66 return _serializeTransformer(transformerOrGroup); |
56 } else { | 67 } else { |
57 assert(transformerOrGroup is TransformerGroup); | 68 assert(transformerOrGroup is TransformerGroup); |
58 return serializeTransformerGroup(transformerOrGroup); | 69 return _serializeTransformerGroup(transformerOrGroup); |
59 } | 70 } |
60 } | 71 } |
OLD | NEW |