| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:collection' show HashSet, Queue; | 5 import 'dart:collection' show HashSet, Queue; |
| 6 import 'dart:convert' show BASE64, JSON, UTF8; | 6 import 'dart:convert' show BASE64, JSON, UTF8; |
| 7 import 'dart:io' show File; | 7 import 'dart:io' show File; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart' | 9 import 'package:analyzer/analyzer.dart' |
| 10 show AnalysisError, CompilationUnit, ErrorSeverity; | 10 show AnalysisError, CompilationUnit, ErrorSeverity; |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 path.relative(path.fromUri(mapUrl), from: path.dirname(jsUrl))) | 502 path.relative(path.fromUri(mapUrl), from: path.dirname(jsUrl))) |
| 503 .toString(); | 503 .toString(); |
| 504 assert(path.dirname(jsUrl) == path.dirname(mapUrl)); | 504 assert(path.dirname(jsUrl) == path.dirname(mapUrl)); |
| 505 printer.emit('\n//# sourceMappingURL='); | 505 printer.emit('\n//# sourceMappingURL='); |
| 506 printer.emit(relativeMapUrl); | 506 printer.emit(relativeMapUrl); |
| 507 printer.emit('\n'); | 507 printer.emit('\n'); |
| 508 } | 508 } |
| 509 } | 509 } |
| 510 | 510 |
| 511 var text = printer.getText(); | 511 var text = printer.getText(); |
| 512 var rawSourceMap = options.inlineSourceMap ? JSON.encode(builtMap) : null; | 512 var rawSourceMap = 'null'; |
| 513 if (options.inlineSourceMap) { |
| 514 var bytes = UTF8.encode(JSON.encode(builtMap)); |
| 515 // Base64 encode instead of json escaping to work around V8 bug |
| 516 // unescaping strings with a large number of slashes. |
| 517 rawSourceMap = "'${BASE64.encode(bytes)}'"; |
| 518 } |
| 513 // Encode the sourcemap as an escaped string rather than JSON | 519 // Encode the sourcemap as an escaped string rather than JSON |
| 514 // as Dart code using the sourcemap can't take advantage of it being JS | 520 // as Dart code using the sourcemap can't take advantage of it being JS |
| 515 // JSON so we might as well encode it as a String which should be quicker | 521 // JSON so we might as well encode it as a String which should be quicker |
| 516 // to parse. | 522 // to parse. |
| 517 text = text.replaceFirst(sourceMapHoleID, JSON.encode(rawSourceMap)); | 523 text = text.replaceFirst(sourceMapHoleID, rawSourceMap); |
| 518 | 524 |
| 519 return new JSModuleCode(text, builtMap); | 525 return new JSModuleCode(text, builtMap); |
| 520 } | 526 } |
| 521 | 527 |
| 522 /// Similar to [getCode] but immediately writes the resulting files. | 528 /// Similar to [getCode] but immediately writes the resulting files. |
| 523 /// | 529 /// |
| 524 /// If [mapPath] is not supplied but [options.sourceMap] is set, mapPath | 530 /// If [mapPath] is not supplied but [options.sourceMap] is set, mapPath |
| 525 /// will default to [jsPath].map. | 531 /// will default to [jsPath].map. |
| 526 void writeCodeSync(ModuleFormat format, String jsPath, | 532 void writeCodeSync(ModuleFormat format, String jsPath, |
| 527 {bool singleOutFile: false}) { | 533 {bool singleOutFile: false}) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 /// are implementation details that would just confuse users. | 609 /// are implementation details that would just confuse users. |
| 604 /// Normalize sdk urls to use "dart:" for more understandable stack traces. | 610 /// Normalize sdk urls to use "dart:" for more understandable stack traces. |
| 605 Map cleanupSdkSourcemap(Map sourceMap) { | 611 Map cleanupSdkSourcemap(Map sourceMap) { |
| 606 var map = new Map.from(sourceMap); | 612 var map = new Map.from(sourceMap); |
| 607 var list = new List.from(map['sources']); | 613 var list = new List.from(map['sources']); |
| 608 map['sources'] = map['sources'] | 614 map['sources'] = map['sources'] |
| 609 .map((url) => url.contains('/_internal/') ? null : url) | 615 .map((url) => url.contains('/_internal/') ? null : url) |
| 610 .toList(); | 616 .toList(); |
| 611 return map; | 617 return map; |
| 612 } | 618 } |
| OLD | NEW |