Chromium Code Reviews| 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 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 buff.write(map.toString()); | 198 buff.write(map.toString()); |
| 199 } | 199 } |
| 200 return buff.toString(); | 200 return buff.toString(); |
| 201 } | 201 } |
| 202 | 202 |
| 203 SourceMapSpan spanFor(int line, int column, | 203 SourceMapSpan spanFor(int line, int column, |
| 204 {Map<String, SourceFile> files, String uri}) { | 204 {Map<String, SourceFile> files, String uri}) { |
| 205 if (uri == null) { | 205 if (uri == null) { |
| 206 throw new ArgumentError.notNull('uri'); | 206 throw new ArgumentError.notNull('uri'); |
| 207 } | 207 } |
| 208 if (_mappings.containsKey(uri)) { | 208 |
| 209 return _mappings[uri].spanFor(line, column, files: files, uri: uri); | 209 // Fall back to looking up uri suffixes of decreasing length if the full |
|
Siggi Cherem (dart-lang)
2016/12/14 15:46:10
Let's keep the first `if` from before (where you c
Jacob
2016/12/14 18:49:42
Changed the wording of the comment from fall back
| |
| 210 } | 210 // uri does not match a source map. |
| 211 // Fall back to looking up the source map on just the basename. | 211 var parts = path.split(uri); |
|
Siggi Cherem (dart-lang)
2016/12/14 15:46:10
do we expect uri to contain any scheme? (do we nee
Jacob
2016/12/14 18:49:42
Good point.
path.split doesn't handle package: the
| |
| 212 var name = path.basename(uri.toString()); | 212 for (var i = 0; i < parts.length; ++i) { |
| 213 if (_mappings.containsKey(name)) { | 213 var candidate = path.joinAll(parts.skip(i)); |
| 214 return _mappings[name].spanFor(line, column, files: files, uri: name); | 214 if (_mappings.containsKey(candidate)) { |
| 215 return _mappings[candidate] | |
| 216 .spanFor(line, column, files: files, uri: candidate); | |
| 217 } | |
| 215 } | 218 } |
| 216 | 219 |
| 217 // Note: when there is no source map for an uri, this behaves like an | 220 // Note: when there is no source map for an uri, this behaves like an |
| 218 // identity function, returning the requested location as the result. | 221 // identity function, returning the requested location as the result. |
| 219 | 222 |
| 220 // Create a mock offset for the output location. We compute it in terms | 223 // Create a mock offset for the output location. We compute it in terms |
| 221 // of the input line and column to minimize the chances that two different | 224 // of the input line and column to minimize the chances that two different |
| 222 // line and column locations are mapped to the same offset. | 225 // line and column locations are mapped to the same offset. |
| 223 var offset = line * 1000000 + column; | 226 var offset = line * 1000000 + column; |
| 224 var location = new SourceLocation(offset, | 227 var location = new SourceLocation(offset, |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 611 static const _TokenKind EOF = const _TokenKind(isEof: true); | 614 static const _TokenKind EOF = const _TokenKind(isEof: true); |
| 612 static const _TokenKind VALUE = const _TokenKind(); | 615 static const _TokenKind VALUE = const _TokenKind(); |
| 613 final bool isNewLine; | 616 final bool isNewLine; |
| 614 final bool isNewSegment; | 617 final bool isNewSegment; |
| 615 final bool isEof; | 618 final bool isEof; |
| 616 bool get isValue => !isNewLine && !isNewSegment && !isEof; | 619 bool get isValue => !isNewLine && !isNewSegment && !isEof; |
| 617 | 620 |
| 618 const _TokenKind( | 621 const _TokenKind( |
| 619 {this.isNewLine: false, this.isNewSegment: false, this.isEof: false}); | 622 {this.isNewLine: false, this.isNewSegment: false, this.isEof: false}); |
| 620 } | 623 } |
| OLD | NEW |