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

Side by Side Diff: lib/parser.dart

Issue 2736983002: Enabling adding and querying for source maps in a MappingBundle. (Closed)
Patch Set: Enabling adding and querying for source maps in a MappingBundle. Created 3 years, 9 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
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('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) 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 the top-level function to parse source maps version 3. 5 /// Contains the top-level function to parse source maps version 3.
6 library source_maps.parser; 6 library source_maps.parser;
7 7
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:convert'; 9 import 'dart:convert';
10 10
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 ..write(')'); 173 ..write(')');
174 } 174 }
175 buff.write(']'); 175 buff.write(']');
176 return buff.toString(); 176 return buff.toString();
177 } 177 }
178 } 178 }
179 179
180 class MappingBundle extends Mapping { 180 class MappingBundle extends Mapping {
181 Map<String, SingleMapping> _mappings = {}; 181 Map<String, SingleMapping> _mappings = {};
182 182
183 MappingBundle() {}
184
183 MappingBundle.fromJson(List json, {String mapUrl}) { 185 MappingBundle.fromJson(List json, {String mapUrl}) {
184 for (var map in json) { 186 for (var map in json) {
185 var mapping = parseJson(map, mapUrl: mapUrl) as SingleMapping; 187 addMapping(parseJson(map, mapUrl: mapUrl) as SingleMapping);
186 var targetUrl = mapping.targetUrl;
187 // TODO(jacobr): verify that targetUrl is valid uri instead of a windows
188 // path.
189 _mappings[targetUrl] = mapping;
190 } 188 }
191 } 189 }
192 190
191 addMapping(SingleMapping mapping) {
192 // TODO(jacobr): verify that targetUrl is valid uri instead of a windows
193 // path.
194 _mappings[mapping.targetUrl] = mapping;
195 }
196
193 /// Encodes the Mapping mappings as a json map. 197 /// Encodes the Mapping mappings as a json map.
194 List toJson() => _mappings.values.map((v) => v.toJson()).toList(); 198 List toJson() => _mappings.values.map((v) => v.toJson()).toList();
195 199
196 String toString() { 200 String toString() {
197 var buff = new StringBuffer(); 201 var buff = new StringBuffer();
198 for (var map in _mappings.values) { 202 for (var map in _mappings.values) {
199 buff.write(map.toString()); 203 buff.write(map.toString());
200 } 204 }
201 return buff.toString(); 205 return buff.toString();
202 } 206 }
203 207
208 bool containsMapping(String url) => _mappings.containsKey(url);
209
204 SourceMapSpan spanFor(int line, int column, 210 SourceMapSpan spanFor(int line, int column,
205 {Map<String, SourceFile> files, String uri}) { 211 {Map<String, SourceFile> files, String uri}) {
206 if (uri == null) { 212 if (uri == null) {
207 throw new ArgumentError.notNull('uri'); 213 throw new ArgumentError.notNull('uri');
208 } 214 }
209 215
210 // Find the longest suffix of the uri that matches the sourcemap 216 // Find the longest suffix of the uri that matches the sourcemap
211 // where the suffix starts after a path segment boundary. 217 // where the suffix starts after a path segment boundary.
212 // We consider ":" and "/" as path segment boundaries so that 218 // We consider ":" and "/" as path segment boundaries so that
213 // "package:" uris can be handled with minimal special casing. Having a 219 // "package:" uris can be handled with minimal special casing. Having a
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 static const _TokenKind EOF = const _TokenKind(isEof: true); 634 static const _TokenKind EOF = const _TokenKind(isEof: true);
629 static const _TokenKind VALUE = const _TokenKind(); 635 static const _TokenKind VALUE = const _TokenKind();
630 final bool isNewLine; 636 final bool isNewLine;
631 final bool isNewSegment; 637 final bool isNewSegment;
632 final bool isEof; 638 final bool isEof;
633 bool get isValue => !isNewLine && !isNewSegment && !isEof; 639 bool get isValue => !isNewLine && !isNewSegment && !isEof;
634 640
635 const _TokenKind( 641 const _TokenKind(
636 {this.isNewLine: false, this.isNewSegment: false, this.isEof: false}); 642 {this.isNewLine: false, this.isNewSegment: false, this.isEof: false});
637 } 643 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698