Chromium Code Reviews| Index: pkg/source_maps/lib/builder.dart |
| diff --git a/pkg/source_maps/lib/builder.dart b/pkg/source_maps/lib/builder.dart |
| index ef22e3123720dcdf9d726c85662ac3b06c24cd61..946bfe9f653bcff0c6b1c493a0cedc691585e5dd 100644 |
| --- a/pkg/source_maps/lib/builder.dart |
| +++ b/pkg/source_maps/lib/builder.dart |
| @@ -7,24 +7,18 @@ library source_maps.builder; |
| // TODO(sigmund): add a builder for multi-section mappings. |
| -import 'dart:collection'; |
| import 'dart:convert'; |
| +import 'parser.dart'; |
| import 'span.dart'; |
| -import 'src/vlq.dart'; |
| /// Builds a source map given a set of mappings. |
| class SourceMapBuilder { |
| final List<Entry> _entries = <Entry>[]; |
| - /// Indices associated with file urls that will be part of the source map. We |
| - /// use a linked hash-map so that `_urls.keys[_urls[u]] == u` |
| - final Map<String, int> _urls = new LinkedHashMap<String, int>(); |
| - |
| - /// Indices associated with identifiers that will be part of the source map. |
| - /// We use a linked hash-map so that `_names.keys[_names[n]] == n` |
| - final Map<String, int> _names = new LinkedHashMap<String, int>(); |
| + // TODO(tjblasi): This is clearly bad. |
|
Siggi Cherem (dart-lang)
2014/07/08 00:31:00
see the suggestion in SingleMapping, maybe that he
tjblasi
2014/07/08 16:36:19
Done.
|
| + List<Entry> get entries => _entries; |
| /// Adds an entry mapping the [targetOffset] to [source]. |
| void addFromOffset(Location source, |
| @@ -48,78 +42,11 @@ class SourceMapBuilder { |
| /// Encodes all mappings added to this builder as a json map. |
| Map build(String fileUrl) { |
| - var buff = new StringBuffer(); |
| - var line = 0; |
| - var column = 0; |
| - var srcLine = 0; |
| - var srcColumn = 0; |
| - var srcUrlId = 0; |
| - var srcNameId = 0; |
| - var first = true; |
| - |
| - // The encoding needs to be sorted by the target offsets. |
| - _entries.sort(); |
| - for (var entry in _entries) { |
| - int nextLine = entry.target.line; |
| - if (nextLine > line) { |
| - for (int i = line; i < nextLine; ++i) { |
| - buff.write(';'); |
| - } |
| - line = nextLine; |
| - column = 0; |
| - first = true; |
| - } |
| - |
| - if (!first) buff.write(','); |
| - first = false; |
| - column = _append(buff, column, entry.target.column); |
| - |
| - // Encoding can be just the column offset if there is no source |
| - // information. |
| - var source = entry.source; |
| - if (source == null) continue; |
| - var newUrlId = _indexOf(_urls, source.sourceUrl); |
| - |
| - srcUrlId = _append(buff, srcUrlId, newUrlId); |
| - srcLine = _append(buff, srcLine, source.line); |
| - srcColumn = _append(buff, srcColumn, source.column); |
| - |
| - if (entry.identifierName == null) continue; |
| - srcNameId = _append(buff, srcNameId, |
| - _indexOf(_names, entry.identifierName)); |
| - } |
| - |
| - var result = { |
| - 'version': 3, |
| - 'sourceRoot': '', |
| - 'sources': _urls.keys.toList(), |
| - 'names' : _names.keys.toList(), |
| - 'mappings' : buff.toString() |
| - }; |
| - if (fileUrl != null) { |
| - result['file'] = fileUrl; |
| - } |
| - return result; |
| + return new SingleMapping.fromBuilder(this, fileUrl).toMap(); |
| } |
| /// Encodes all mappings added to this builder as a json string. |
| String toJson(String fileUrl) => JSON.encode(build(fileUrl)); |
| - |
| - /// Get the index of [value] in [map], or create one if it doesn't exist. |
| - int _indexOf(Map<String, int> map, String value) { |
| - return map.putIfAbsent(value, () { |
| - int index = map.length; |
| - map[value] = index; |
| - return index; |
| - }); |
| - } |
| - |
| - /// Appends to [buff] a VLQ encoding of [newValue] using the difference |
| - /// between [oldValue] and [newValue] |
| - static int _append(StringBuffer buff, int oldValue, int newValue) { |
| - buff.writeAll(encodeVlq(newValue - oldValue)); |
| - return newValue; |
| - } |
| } |
| /// An entry in the source map builder. |