Index: sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart |
diff --git a/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart b/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart |
index d7eea273c3686935df699552d2169673ea669450..c468a92e0387cef1199d8ae4a87b016c92c75b4d 100644 |
--- a/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart |
+++ b/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart |
@@ -1529,8 +1529,17 @@ if (typeof $printHelperName === "function") { |
} else { |
mainBuffer.add('\n'); |
} |
- compiler.assembledCode = mainBuffer.getText(); |
- outputSourceMap(compiler.assembledCode, ''); |
+ String assembledCode = mainBuffer.getText(); |
+ if (generateSourceMap) { |
+ outputSourceMap(assembledCode, mainBuffer, '', |
+ compiler.sourceMapUri, compiler.outputUri); |
+ assembledCode += |
floitsch
2014/03/07 10:27:24
It seems more efficient if we don't have to create
Johnni Winther
2014/03/07 12:38:48
Done.
|
+ generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri); |
+ } |
+ compiler.outputProvider('', 'js') |
+ ..add(assembledCode) |
+ ..close(); |
+ compiler.assembledCode = assembledCode; |
mainBuffer.write( |
jsAst.prettyPrint( |
@@ -1547,6 +1556,25 @@ if (typeof $printHelperName === "function") { |
return compiler.assembledCode; |
} |
+ String generateSourceMapTag(Uri sourceMapUri, Uri fileUri) { |
+ if (sourceMapUri != null && fileUri != null) { |
+ // Using # is the new proposed standard. @ caused problems in Internet |
+ // Explorer due to "Conditional Compilation Statements" in JScript, |
+ // see: |
+ // http://msdn.microsoft.com/en-us/library/7kx09ct1(v=vs.80).aspx |
+ // About source maps, see: |
+ // https://docs.google.com/a/google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit |
+ // TODO(http://dartbug.com/11914): Remove @ line. |
floitsch
2014/03/07 10:27:24
I just tried with Chrome beta, and at least there
Johnni Winther
2014/03/07 12:38:48
Will do it in a separate CL.
|
+ String sourceMapFileName = relativize(fileUri, sourceMapUri, false); |
+ return ''' |
+ |
+//# sourceMappingURL=$sourceMapFileName |
+//@ sourceMappingURL=$sourceMapFileName |
+'''; |
+ } |
+ return ''; |
+ } |
+ |
ClassBuilder getElementDescriptorForOutputUnit(Element element, |
OutputUnit outputUnit) { |
Map<OutputUnit, ClassBuilder> descriptors = |
@@ -1623,7 +1651,8 @@ if (typeof $printHelperName === "function") { |
compiler.outputProvider(outputUnit.name, 'js') |
..add(code) |
..close(); |
- outputSourceMap(compiler.assembledCode, outputUnit.name); |
+ |
+ // TODO(johnniwinther): Support source maps for deferred code. |
} |
} |
@@ -1633,20 +1662,24 @@ if (typeof $printHelperName === "function") { |
return '// Generated by dart2js, the Dart to JavaScript compiler$suffix.\n'; |
} |
- String buildSourceMap(CodeBuffer buffer, SourceFile compiledFile) { |
+ String buildSourceMap(CodeBuffer buffer, |
floitsch
2014/03/07 10:27:24
If buildSourceMap is not used anywhere else I woul
Johnni Winther
2014/03/07 12:38:48
Done.
|
+ SourceFile compiledFile, |
+ [Uri sourceMapUri, Uri fileUri]) { |
SourceMapBuilder sourceMapBuilder = |
- new SourceMapBuilder(compiler.sourceMapUri); |
+ new SourceMapBuilder(sourceMapUri, fileUri); |
buffer.forEachSourceLocation(sourceMapBuilder.addMapping); |
return sourceMapBuilder.build(compiledFile); |
} |
- void outputSourceMap(String code, String name) { |
+ void outputSourceMap(String code, CodeBuffer buffer, String name, |
+ [Uri sourceMapUri, Uri fileUri]) { |
if (!generateSourceMap) return; |
// Create a source file for the compilation output. This allows using |
// [:getLine:] to transform offsets to line numbers in [SourceMapBuilder]. |
SourceFile compiledFile = |
- new StringSourceFile(null, compiler.assembledCode); |
- String sourceMap = buildSourceMap(mainBuffer, compiledFile); |
+ new StringSourceFile(null, code); |
+ String sourceMap = buildSourceMap(mainBuffer, compiledFile, |
+ sourceMapUri, fileUri); |
compiler.outputProvider(name, 'js.map') |
..add(sourceMap) |
..close(); |