Chromium Code Reviews| Index: pkg/dev_compiler/lib/src/compiler/compiler.dart |
| diff --git a/pkg/dev_compiler/lib/src/compiler/compiler.dart b/pkg/dev_compiler/lib/src/compiler/compiler.dart |
| index 75337de7bc9ec6e8929f1708792e258dd2ca6eb1..8758122caa359803875b929d802d6c0388ef6a09 100644 |
| --- a/pkg/dev_compiler/lib/src/compiler/compiler.dart |
| +++ b/pkg/dev_compiler/lib/src/compiler/compiler.dart |
| @@ -443,6 +443,15 @@ class JSModuleFile { |
| /// the libraries in this module. |
| final List<int> summaryBytes; |
| + /// Unique identifier used to location where to insline the source map |
|
vsm
2017/03/13 15:25:28
insline -> inline
Jacob
2017/03/13 15:51:12
Done.
|
| + /// in an existing generated JS file |
| + /// |
| + /// Due to execution order constriants we have cannot generate the source map |
|
vsm
2017/03/13 15:25:27
constriants -> constraints
Jacob
2017/03/13 15:51:12
cleaned up this comment.
|
| + /// by the time we would need it to insert the sourcemap directly so instead |
| + /// we have to generate the JS with this ID and then replace the ID with the |
| + /// actual sourcemap after the fact. |
| + static String sourceMapHoleID = 'SourceMap3G5a8h6JVhHfdGuDxZr1EF9GQC8y0e6u'; |
| + |
| JSModuleFile( |
| this.name, this.errors, this.options, this.moduleTree, this.summaryBytes); |
| @@ -485,7 +494,9 @@ class JSModuleFile { |
| if (options.sourceMap && sourceMap != null) { |
| builtMap = |
| placeSourceMap(sourceMap.build(jsUrl), mapUrl, options.bazelMapping); |
| - |
| + if (name == 'dart_sdk') { |
| + builtMap = cleanupSdkSourcemap(builtMap); |
| + } |
| if (options.sourceMapComment) { |
| var relativeMapUrl = path |
| .toUri( |
| @@ -493,18 +504,20 @@ class JSModuleFile { |
| .toString(); |
| assert(path.dirname(jsUrl) == path.dirname(mapUrl)); |
| printer.emit('\n//# sourceMappingURL='); |
| - if (options.inlineSourceMap) { |
| - var bytes = UTF8.encode(JSON.encode(builtMap)); |
| - var base64 = BASE64.encode(bytes); |
| - printer..emit('data:application/json;base64,')..emit(base64); |
| - } else { |
| - printer.emit(relativeMapUrl); |
| - } |
| + printer.emit(relativeMapUrl); |
| printer.emit('\n'); |
| } |
| } |
| - return new JSModuleCode(printer.getText(), builtMap); |
| + var text = printer.getText(); |
| + var rawSourceMap = options.inlineSourceMap ? JSON.encode(builtMap) : null; |
| + // Encode the sourcemap as an escaped string rather than JSON |
| + // as Dart code using the sourcemap can't take advantage of it being JS |
| + // JSON so we might as well encode it as a String which should be quicker |
| + // to parse. |
| + text = text.replaceFirst(sourceMapHoleID, JSON.encode(rawSourceMap)); |
|
vsm
2017/03/13 15:25:27
So, are we sending the source map twice now? Once
Jacob
2017/03/13 15:51:12
We are encoding the source map in the source file
|
| + |
| + return new JSModuleCode(text, builtMap); |
| } |
| /// Similar to [getCode] but immediately writes the resulting files. |
| @@ -584,3 +597,24 @@ Map placeSourceMap( |
| map['file'] = transformUri(map['file']); |
| return map; |
| } |
| + |
| +/// Cleanup the dart_sdk source map. |
| +/// |
| +/// Strip out files that should not be included in the sdk sourcemap as they |
| +/// are implementation details that would just confuse users. |
| +/// Normalize sdk urls to use "dart:" for more understandable stack traces. |
| +Map cleanupSdkSourcemap(Map sourceMap) { |
| + var map = new Map.from(sourceMap); |
| + var list = new List.from(map['sources']); |
| + map['sources'] = list; |
| + for (var i = 0; i < list.length; ++i) { |
| + var url = list[i]; |
| + if (url.contains('/js_lib/')) { |
|
vsm
2017/03/13 15:25:28
Perhaps everything under _internal?
Jacob
2017/03/13 15:51:13
Done.
|
| + list[i] = null; |
| + } else { |
| + // TODO(jacobr): use a cleaner way to normalize dart: urls. |
|
vsm
2017/03/13 15:25:28
Yeah, should be able to plumb the analyzer normali
Jacob
2017/03/13 15:51:12
I think these relative urls are technically correc
|
| + list[i] = url.replaceFirst('../../../gen/patched_sdk/lib/', 'dart:'); |
| + } |
| + } |
| + return map; |
| +} |