| 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));
|
| + }
|
| }
|
|
|