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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 | 175 |
| 176 // Indices associated with file urls that will be part of the source map. We | 176 // Indices associated with file urls that will be part of the source map. We |
| 177 // use a linked hash-map so that `_urls.keys[_urls[u]] == u` | 177 // use a linked hash-map so that `_urls.keys[_urls[u]] == u` |
| 178 var urls = new LinkedHashMap<String, int>(); | 178 var urls = new LinkedHashMap<String, int>(); |
| 179 | 179 |
| 180 // Indices associated with identifiers that will be part of the source map. | 180 // Indices associated with identifiers that will be part of the source map. |
| 181 // We use a linked hash-map so that `_names.keys[_names[n]] == n` | 181 // We use a linked hash-map so that `_names.keys[_names[n]] == n` |
| 182 var names = new LinkedHashMap<String, int>(); | 182 var names = new LinkedHashMap<String, int>(); |
| 183 | 183 |
| 184 var lineNum; | 184 var lineNum; |
| 185 var targetEntries; | 185 List<TargetEntry> targetEntries; |
| 186 for (var sourceEntry in sourceEntries) { | 186 for (var sourceEntry in sourceEntries) { |
| 187 if (lineNum == null || sourceEntry.target.line > lineNum) { | 187 if (lineNum == null || sourceEntry.target.line > lineNum) { |
| 188 lineNum = sourceEntry.target.line; | 188 lineNum = sourceEntry.target.line; |
| 189 targetEntries = <TargetEntry>[]; | 189 targetEntries = <TargetEntry>[]; |
| 190 lines.add(new TargetLineEntry(lineNum, targetEntries)); | 190 lines.add(new TargetLineEntry(lineNum, targetEntries)); |
| 191 } | 191 } |
| 192 | 192 |
| 193 if (sourceEntry.source == null) { | 193 if (sourceEntry.source == null) { |
| 194 targetEntries.add(new TargetEntry(sourceEntry.target.column)); | 194 targetEntries.add(new TargetEntry(sourceEntry.target.column)); |
| 195 } else { | 195 } else { |
| 196 var sourceUrl = sourceEntry.source.sourceUrl; | 196 var sourceUrl = sourceEntry.source.sourceUrl; |
| 197 var urlId = urls.putIfAbsent( | 197 var urlId = urls.putIfAbsent( |
| 198 sourceUrl == null ? '' : sourceUrl.toString(), () => urls.length); | 198 sourceUrl == null ? '' : sourceUrl.toString(), () => urls.length); |
| 199 var srcNameId = sourceEntry.identifierName == null ? null : | 199 var srcNameId = sourceEntry.identifierName == null ? null : |
| 200 names.putIfAbsent(sourceEntry.identifierName, () => names.length); | 200 names.putIfAbsent(sourceEntry.identifierName, () => names.length); |
| 201 targetEntries.add(new TargetEntry( | 201 targetEntries.add(new TargetEntry( |
| 202 sourceEntry.target.column, | 202 sourceEntry.target.column, |
| 203 urlId, | 203 urlId, |
| 204 sourceEntry.source.line, | 204 sourceEntry.source.line, |
| 205 sourceEntry.source.column, | 205 sourceEntry.source.column, |
| 206 srcNameId)); | 206 srcNameId)); |
| 207 } | 207 } |
| 208 } | 208 } |
| 209 return new SingleMapping._( | 209 return new SingleMapping._( |
| 210 fileUrl, urls.keys.toList(), names.keys.toList(), lines); | 210 fileUrl, urls.keys.toList(), names.keys.toList(), lines); |
| 211 } | 211 } |
| 212 | 212 |
| 213 SingleMapping.fromJson(Map map, {mapUrl}) | 213 SingleMapping.fromJson(Map map, {mapUrl}) |
| 214 : targetUrl = map['file'], | 214 : targetUrl = map['file'], |
| 215 urls = map['sources'], | 215 urls = map['sources'] as List<String>, |
|
Siggi Cherem (dart-lang)
2016/03/24 01:15:02
+leafp - would this cause a runtime check failure?
Leaf
2016/03/24 03:23:41
Yep. If map['sources'] returns something with rei
nweiz
2016/03/24 19:07:54
Good catch, done.
@leafp: That would also be nice
Siggi Cherem (dart-lang)
2016/03/24 19:36:19
+1 - it would be good to avoid coping.
| |
| 216 names = map['names'], | 216 names = map['names'] as List<String>, |
| 217 sourceRoot = map['sourceRoot'], | 217 sourceRoot = map['sourceRoot'], |
| 218 lines = <TargetLineEntry>[], | 218 lines = <TargetLineEntry>[], |
| 219 _mapUrl = mapUrl is String ? Uri.parse(mapUrl) : mapUrl { | 219 _mapUrl = mapUrl is String ? Uri.parse(mapUrl) : mapUrl { |
| 220 int line = 0; | 220 int line = 0; |
| 221 int column = 0; | 221 int column = 0; |
| 222 int srcUrlId = 0; | 222 int srcUrlId = 0; |
| 223 int srcLine = 0; | 223 int srcLine = 0; |
| 224 int srcColumn = 0; | 224 int srcColumn = 0; |
| 225 int srcNameId = 0; | 225 int srcNameId = 0; |
| 226 var tokenizer = new _MappingTokenizer(map['mappings']); | 226 var tokenizer = new _MappingTokenizer(map['mappings']); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 static const _TokenKind EOF = const _TokenKind(isEof: true); | 522 static const _TokenKind EOF = const _TokenKind(isEof: true); |
| 523 static const _TokenKind VALUE = const _TokenKind(); | 523 static const _TokenKind VALUE = const _TokenKind(); |
| 524 final bool isNewLine; | 524 final bool isNewLine; |
| 525 final bool isNewSegment; | 525 final bool isNewSegment; |
| 526 final bool isEof; | 526 final bool isEof; |
| 527 bool get isValue => !isNewLine && !isNewSegment && !isEof; | 527 bool get isValue => !isNewLine && !isNewSegment && !isEof; |
| 528 | 528 |
| 529 const _TokenKind( | 529 const _TokenKind( |
| 530 {this.isNewLine: false, this.isNewSegment: false, this.isEof: false}); | 530 {this.isNewLine: false, this.isNewSegment: false, this.isEof: false}); |
| 531 } | 531 } |
| OLD | NEW |