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

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: Address comments Created 4 years, 11 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 | « lib/src/codegen/js_codegen.dart ('k') | lib/src/server/server.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/codegen/js_printer.dart
diff --git a/lib/src/codegen/js_printer.dart b/lib/src/codegen/js_printer.dart
index 900f719e6ff14fba0c204e01f4f4f71e73512a77..05f76510ccab793aac699b832da3f5406f5c0b28 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, Uri serverUri,
{bool emitSourceMaps: false, bool arrowFnBindThisWorkaround: false}) {
var outFilename = path.basename(outputPath);
var outDir = path.dirname(outputPath);
@@ -27,7 +28,8 @@ 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, serverUri);
} else {
context = new JS.SimpleJavaScriptPrintingContext();
}
@@ -73,11 +75,17 @@ String writeJsLibrary(JS.Program jsTree, String outputPath,
class SourceMapPrintingContext extends JS.JavaScriptPrintingContext {
final srcmaps.Printer printer;
final String outputDir;
+ final String inputDir;
+
+ // TODO(vsm): we could abstract this out and have a generic Uri mapping
+ // instead of hardcoding a notion of a server uri.
+ final Uri serverUri;
CompilationUnit unit;
Uri uri;
- SourceMapPrintingContext(this.printer, this.outputDir);
+ SourceMapPrintingContext(
+ this.printer, this.outputDir, this.inputDir, this.serverUri);
void emit(String string) {
printer.add(string);
@@ -96,6 +104,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);
@@ -114,7 +123,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 (serverUri == null) {
+ return new Uri(path: path.relative(src.path, from: outputDir));
+ } else {
+ if (src.path.startsWith('/')) {
+ return serverUri.resolve(path.relative(src.path, from: inputDir));
+ } else {
+ return serverUri.resolve(path.join('packages', src.path));
+ }
+ }
}
void exitNode(JS.Node jsNode) {
« no previous file with comments | « lib/src/codegen/js_codegen.dart ('k') | lib/src/server/server.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698