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

Unified Diff: lib/src/runner/browser/compiler_pool.dart

Issue 1295653003: Make source maps work in the browser. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 years, 4 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 | « CHANGELOG.md ('k') | lib/src/runner/browser/server.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/runner/browser/compiler_pool.dart
diff --git a/lib/src/runner/browser/compiler_pool.dart b/lib/src/runner/browser/compiler_pool.dart
index edeefaec8a08c31a25ca142744d1c7f96a8d9252..edc41bf20dd41f7191d43ea6518273063be29d6d 100644
--- a/lib/src/runner/browser/compiler_pool.dart
+++ b/lib/src/runner/browser/compiler_pool.dart
@@ -105,13 +105,30 @@ void main(_) {
if (buffer.isNotEmpty) print(buffer);
- if (exitCode != 0) {
- throw new LoadException(dartPath, "dart2js failed.");
- }
+ if (exitCode != 0) throw new LoadException(dartPath, "dart2js failed.");
+
+ _fixSourceMap(jsPath + '.map');
});
});
}
+ // TODO(nweiz): Remove this when sdk#17544 is fixed.
+ /// Fix up the source map at [mapPath] so that it points to absolute file:
+ /// URIs that are resolvable by the browser.
+ void _fixSourceMap(String mapPath) {
+ var map = JSON.decode(new File(mapPath).readAsStringSync());
+ var root = map['sourceRoot'];
+
+ map['sources'] = map['sources'].map((source) {
+ var url = Uri.parse(root + source);
+ if (url.scheme != '' && url.scheme != 'file') return source;
+ if (url.path.endsWith("/runInBrowser.dart")) return "";
+ return p.toUri(mapPath).resolveUri(url).toString();
+ }).toList();
+
+ new File(mapPath).writeAsStringSync(JSON.encode(map));
+ }
+
/// Sanitizes the bytes emitted by [stream], converts them to text, and writes
/// them to [buffer].
Future _printOutputStream(Stream<List<int>> stream, StringBuffer buffer) {
« no previous file with comments | « CHANGELOG.md ('k') | lib/src/runner/browser/server.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698