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

Unified Diff: lib/compiler/implementation/emitter.dart

Issue 10579019: First shot at source maps generation in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix the tests. Created 8 years, 6 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/compiler/implementation/dart2js.dart ('k') | lib/compiler/implementation/leg.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/emitter.dart
diff --git a/lib/compiler/implementation/emitter.dart b/lib/compiler/implementation/emitter.dart
index f6afda53dc2eaaf8e7ec13c099be1dbf5e167999..e00e960182a8a7afe5049ee0d2f222cdfe961b00 100644
--- a/lib/compiler/implementation/emitter.dart
+++ b/lib/compiler/implementation/emitter.dart
@@ -34,11 +34,16 @@ class CodeEmitterTask extends CompilerTask {
String classesCollector;
final Map<int, String> boundClosureCache;
- CodeEmitterTask(Compiler compiler)
+ final bool generateSourceMap;
+ final List<SourceMappingEntry> sourceMappings;
+
+ CodeEmitterTask(Compiler compiler, [bool generateSourceMap = false])
: namer = compiler.namer,
boundClosureBuffer = new StringBuffer(),
mainBuffer = new StringBuffer(),
boundClosureCache = new Map<int, String>(),
+ generateSourceMap = generateSourceMap,
+ sourceMappings = new List<SourceMappingEntry>(),
super(compiler) {
nativeEmitter = new NativeEmitter(this);
}
@@ -616,7 +621,14 @@ function(collectedClasses) {
generatedCode.forEach((Element element, String codeBlock) {
if (!element.isInstanceMember()) {
String functionName = functionNamer(element);
- buffer.add('$isolateProperties.$functionName = $codeBlock;\n\n');
+ buffer.add('$isolateProperties.$functionName = ');
+ int beginPosition = buffer.length;
+ buffer.add(codeBlock);
+ int endPosition = buffer.length;
+ buffer.add(';\n\n');
+ if (generateSourceMap) {
+ addSourceMapping(element, beginPosition, endPosition);
+ }
}
});
}
@@ -1032,7 +1044,29 @@ if (typeof window != 'undefined' && typeof document != 'undefined' &&
emitFinishIsolateConstructor(mainBuffer);
mainBuffer.add('}\n');
compiler.assembledCode = mainBuffer.toString();
+
+ if (generateSourceMap) {
+ SourceFile compiledFile = new SourceFile(null, compiler.assembledCode);
+ String sourceMap = new SourceMapBuilder().build(sourceMappings,
+ compiledFile);
+ // TODO(podivilov): We should find a better way to return source maps to
+ // compiler. Using diagnostic handler for that purpose is a temporary
+ // hack.
+ compiler.reportDiagnostic(
+ null, sourceMap, new api.Diagnostic(-1, 'source map'));
+ }
});
return compiler.assembledCode;
}
+
+ void addSourceMapping(FunctionElement element,
+ int beginPosition,
+ int endPosition) {
+ SourceFile sourceFile = element.getCompilationUnit().script.file;
+ FunctionExpression expression = element.cachedNode;
+ sourceMappings.add(new SourceMappingEntry(
+ sourceFile, expression.getBeginToken().charOffset, beginPosition));
+ sourceMappings.add(new SourceMappingEntry(
+ sourceFile, expression.getEndToken().charOffset, endPosition));
+ }
}
« no previous file with comments | « lib/compiler/implementation/dart2js.dart ('k') | lib/compiler/implementation/leg.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698