OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// Contains a builder object useful for creating source maps programatically. | 5 /// Contains a builder object useful for creating source maps programatically. |
6 library source_maps.builder; | 6 library source_maps.builder; |
7 | 7 |
8 // TODO(sigmund): add a builder for multi-section mappings. | 8 // TODO(sigmund): add a builder for multi-section mappings. |
9 | 9 |
10 import 'dart:json' as json; | |
11 import 'dart:collection'; | 10 import 'dart:collection'; |
| 11 import 'dart:convert'; |
12 | 12 |
13 import 'span.dart'; | 13 import 'span.dart'; |
14 import 'src/vlq.dart'; | 14 import 'src/vlq.dart'; |
15 | 15 |
16 /// Builds a source map given a set of mappings. | 16 /// Builds a source map given a set of mappings. |
17 class SourceMapBuilder { | 17 class SourceMapBuilder { |
18 | 18 |
19 final List<Entry> _entries = <Entry>[]; | 19 final List<Entry> _entries = <Entry>[]; |
20 | 20 |
21 /// Indices associated with file urls that will be part of the source map. We | 21 /// Indices associated with file urls that will be part of the source map. We |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 'names' : _names.keys.toList(), | 101 'names' : _names.keys.toList(), |
102 'mappings' : buff.toString() | 102 'mappings' : buff.toString() |
103 }; | 103 }; |
104 if (fileUrl != null) { | 104 if (fileUrl != null) { |
105 result['file'] = fileUrl; | 105 result['file'] = fileUrl; |
106 } | 106 } |
107 return result; | 107 return result; |
108 } | 108 } |
109 | 109 |
110 /// Encodes all mappings added to this builder as a json string. | 110 /// Encodes all mappings added to this builder as a json string. |
111 String toJson(String fileUrl) => json.stringify(build(fileUrl)); | 111 String toJson(String fileUrl) => JSON.encode(build(fileUrl)); |
112 | 112 |
113 /// Get the index of [value] in [map], or create one if it doesn't exist. | 113 /// Get the index of [value] in [map], or create one if it doesn't exist. |
114 int _indexOf(Map<String, int> map, String value) { | 114 int _indexOf(Map<String, int> map, String value) { |
115 return map.putIfAbsent(value, () { | 115 return map.putIfAbsent(value, () { |
116 int index = map.length; | 116 int index = map.length; |
117 map[value] = index; | 117 map[value] = index; |
118 return index; | 118 return index; |
119 }); | 119 }); |
120 } | 120 } |
121 | 121 |
(...skipping 23 matching lines...) Expand all Loading... |
145 /// because source map files are encoded by printing each mapping in order as | 145 /// because source map files are encoded by printing each mapping in order as |
146 /// they appear in the target file. | 146 /// they appear in the target file. |
147 int compareTo(Entry other) { | 147 int compareTo(Entry other) { |
148 int res = target.compareTo(other.target); | 148 int res = target.compareTo(other.target); |
149 if (res != 0) return res; | 149 if (res != 0) return res; |
150 res = source.sourceUrl.compareTo(other.source.sourceUrl); | 150 res = source.sourceUrl.compareTo(other.source.sourceUrl); |
151 if (res != 0) return res; | 151 if (res != 0) return res; |
152 return source.compareTo(other.source); | 152 return source.compareTo(other.source); |
153 } | 153 } |
154 } | 154 } |
OLD | NEW |