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

Unified Diff: lib/src/codegen/js_printer.dart

Issue 1530133003: Support source maps in server mode (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 5 years 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
Index: lib/src/codegen/js_printer.dart
diff --git a/lib/src/codegen/js_printer.dart b/lib/src/codegen/js_printer.dart
index 021678f2a59e5603865adcc7659222a26600f170..945c1563e80726169a47a1dce5ac8131c68257e9 100644
--- a/lib/src/codegen/js_printer.dart
+++ b/lib/src/codegen/js_printer.dart
@@ -18,7 +18,8 @@ import '../utils.dart' show computeHash, locationForOffset;
import 'js_names.dart' show TemporaryNamer;
-String writeJsLibrary(JS.Program jsTree, String outputPath,
+String writeJsLibrary(JS.Program jsTree, String outputPath, String inputDir,
+ String serverUrl,
{bool emitSourceMaps: false, bool arrowFnBindThisWorkaround: false}) {
var outFilename = path.basename(outputPath);
var outDir = path.dirname(outputPath);
@@ -27,7 +28,7 @@ String writeJsLibrary(JS.Program jsTree, String outputPath,
JS.JavaScriptPrintingContext context;
if (emitSourceMaps) {
var printer = new srcmaps.Printer(outFilename);
- context = new SourceMapPrintingContext(printer, outDir);
+ context = new SourceMapPrintingContext(printer, outDir, inputDir, serverUrl);
} else {
context = new JS.SimpleJavaScriptPrintingContext();
}
@@ -72,11 +73,13 @@ String writeJsLibrary(JS.Program jsTree, String outputPath,
class SourceMapPrintingContext extends JS.JavaScriptPrintingContext {
final srcmaps.Printer printer;
final String outputDir;
+ final String inputDir;
+ final String serverUrl;
CompilationUnit unit;
Uri uri;
- SourceMapPrintingContext(this.printer, this.outputDir);
+ SourceMapPrintingContext(this.printer, this.outputDir, this.inputDir, this.serverUrl);
Jennifer Messerly 2015/12/16 18:40:07 slight factoring thing, I wonder if we should pass
vsm 2016/01/07 21:22:03 added a todo
void emit(String string) {
printer.add(string);
@@ -95,6 +98,7 @@ class SourceMapPrintingContext extends JS.JavaScriptPrintingContext {
unit = node.getAncestor((n) => n is CompilationUnit);
uri = _makeRelativeUri(unit.element.source.uri);
}
+ if (unit == null) return;
assert(unit != null);
var loc = _location(node.offset);
@@ -113,7 +117,15 @@ class SourceMapPrintingContext extends JS.JavaScriptPrintingContext {
locationForOffset(unit.lineInfo, uri, offset);
Uri _makeRelativeUri(Uri src) {
- return new Uri(path: path.relative(src.path, from: outputDir));
+ if (serverUrl == null) {
+ return new Uri(path: path.relative(src.path, from: outputDir));
+ } else {
+ if (src.path.startsWith('/')) {
+ return new Uri(path: serverUrl + path.relative(src.path, from: inputDir));
Jennifer Messerly 2015/12/16 18:40:07 the name here's a little confusing, if this was a
vsm 2016/01/07 21:22:03 i think i was abusing the path argument to the Uri
+ } else {
+ return new Uri(path: serverUrl + 'packages/' + src.path);
+ }
+ }
}
void exitNode(JS.Node jsNode) {

Powered by Google App Engine
This is Rietveld 408576698