Chromium Code Reviews| Index: lib/compiler/implementation/emitter.dart |
| diff --git a/lib/compiler/implementation/emitter.dart b/lib/compiler/implementation/emitter.dart |
| index 728f07805d7a1d670bfe7a1179672fea837f23ea..c97ba659b16a43ae82ca60cfe5297b1dd50bcb2d 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,26 @@ 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); |
| + compiler.reportDiagnostic( |
|
ahe
2012/06/20 11:56:59
Add TODO to explain this.
podivilov
2012/06/20 14:15:15
Done.
|
| + 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)); |
| + } |
| } |