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

Unified Diff: pkg/source_maps/lib/parser.dart

Issue 383823002: Adding support for `sourceRoot` to the SingleMapping class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use string interpolation for concat rather than '+'. Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/source_maps/test/parser_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/source_maps/lib/parser.dart
diff --git a/pkg/source_maps/lib/parser.dart b/pkg/source_maps/lib/parser.dart
index 23835a60f3499546ca9e3dd2cd5eb4431128db8f..f53f7edcc743b3fb5ded10d28607b58429c4c0ed 100644
--- a/pkg/source_maps/lib/parser.dart
+++ b/pkg/source_maps/lib/parser.dart
@@ -16,6 +16,8 @@ import 'src/vlq.dart';
/// Parses a source map directly from a json string.
// TODO(sigmund): evaluate whether other maps should have the json parsed, or
// the string represenation.
+// TODO(tjblasi): Ignore the first line of [jsonMap] if the JSON safety string
+// `)]}'` begins the string representation of the map.
Mapping parse(String jsonMap, {Map<String, Map> otherMaps}) =>
parseJson(JSON.decode(jsonMap), otherMaps: otherMaps);
@@ -146,6 +148,9 @@ class SingleMapping extends Mapping {
/// Entries indicating the beginning of each span.
final List<TargetLineEntry> lines;
+ /// Source root appended to the start of all entries in [urls].
+ String sourceRoot = null;
+
SingleMapping._internal(this.targetUrl, this.urls, this.names, this.lines);
factory SingleMapping.fromEntries(
@@ -192,9 +197,9 @@ class SingleMapping extends Mapping {
SingleMapping.fromJson(Map map)
: targetUrl = map['file'],
- // TODO(sigmund): add support for 'sourceRoot'
urls = map['sources'],
names = map['names'],
+ sourceRoot = map['sourceRoot'],
lines = <TargetLineEntry>[] {
int line = 0;
int column = 0;
@@ -303,7 +308,7 @@ class SingleMapping extends Mapping {
var result = {
'version': 3,
- 'sourceRoot': '',
+ 'sourceRoot': sourceRoot == null ? '' : sourceRoot,
'sources': urls,
'names' : names,
'mappings' : buff.toString()
@@ -350,6 +355,9 @@ class SingleMapping extends Mapping {
var entry = _findColumn(line, column, _findLine(line));
if (entry == null || entry.sourceUrlId == null) return null;
var url = urls[entry.sourceUrlId];
+ if (sourceRoot != null) {
+ url = '${sourceRoot}${url}';
+ }
if (files != null && files[url] != null) {
var file = files[url];
var start = file.getOffset(entry.sourceLine, entry.sourceColumn);
@@ -374,6 +382,8 @@ class SingleMapping extends Mapping {
return (new StringBuffer("$runtimeType : [")
..write('targetUrl: ')
..write(targetUrl)
+ ..write(', sourceRoot: ')
+ ..write(sourceRoot)
..write(', urls: ')
..write(urls)
..write(', names: ')
@@ -392,13 +402,16 @@ class SingleMapping extends Mapping {
..write(': ')
..write(line)
..write(':')
- ..write(entry.column)
- ..write(' --> ')
- ..write(urls[entry.sourceUrlId])
- ..write(': ')
- ..write(entry.sourceLine)
- ..write(':')
- ..write(entry.sourceColumn);
+ ..write(entry.column);
+ if (entry.sourceUrlId != null) {
+ buff..write(' --> ')
+ ..write(sourceRoot)
+ ..write(urls[entry.sourceUrlId])
+ ..write(': ')
+ ..write(entry.sourceLine)
+ ..write(':')
+ ..write(entry.sourceColumn);
+ }
if (entry.sourceNameId != null) {
buff..write(' (')
..write(names[entry.sourceNameId])
« no previous file with comments | « no previous file | pkg/source_maps/test/parser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698