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 JSON; | 6 import 'dart:convert' show JSON; |
7 import 'dart:io' show File; | 7 import 'dart:io' show File; |
8 import 'package:analyzer/dart/element/element.dart' show LibraryElement; | 8 import 'package:analyzer/dart/element/element.dart' show LibraryElement; |
9 import 'package:analyzer/analyzer.dart' | 9 import 'package:analyzer/analyzer.dart' |
10 show AnalysisError, CompilationUnit, ErrorSeverity; | 10 show AnalysisError, CompilationUnit, ErrorSeverity; |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 printer = sourceMapContext; | 356 printer = sourceMapContext; |
357 } else { | 357 } else { |
358 printer = new JS.SimpleJavaScriptPrintingContext(); | 358 printer = new JS.SimpleJavaScriptPrintingContext(); |
359 } | 359 } |
360 | 360 |
361 var tree = transformModuleFormat(format, moduleTree); | 361 var tree = transformModuleFormat(format, moduleTree); |
362 tree.accept( | 362 tree.accept( |
363 new JS.Printer(opts, printer, localNamer: new JS.TemporaryNamer(tree))); | 363 new JS.Printer(opts, printer, localNamer: new JS.TemporaryNamer(tree))); |
364 | 364 |
365 if (options.sourceMap && options.sourceMapComment) { | 365 if (options.sourceMap && options.sourceMapComment) { |
366 printer.emit('\n//# sourceMappingURL=$mapUrl\n'); | 366 var relativeMapUrl = path |
| 367 .toUri(path.relative(path.fromUri(mapUrl), from: path.dirname(jsUrl))) |
| 368 .toString(); |
| 369 assert(path.dirname(jsUrl) == path.dirname(mapUrl)); |
| 370 printer.emit('\n//# sourceMappingURL=$relativeMapUrl\n'); |
367 } | 371 } |
368 | 372 |
369 Map builtMap; | 373 Map builtMap; |
370 if (sourceMap != null) { | 374 if (sourceMap != null) { |
371 builtMap = placeSourceMap(sourceMap.build(jsUrl), mapUrl); | 375 builtMap = placeSourceMap(sourceMap.build(jsUrl), mapUrl); |
372 } | 376 } |
373 return new JSModuleCode(printer.getText(), builtMap); | 377 return new JSModuleCode(printer.getText(), builtMap); |
374 } | 378 } |
375 | 379 |
376 /// Similar to [getCode] but immediately writes the resulting files. | 380 /// Similar to [getCode] but immediately writes the resulting files. |
(...skipping 29 matching lines...) Expand all Loading... |
406 | 410 |
407 /// Adjusts the source paths in [sourceMap] to be relative to [sourceMapPath], | 411 /// Adjusts the source paths in [sourceMap] to be relative to [sourceMapPath], |
408 /// and returns the new map. | 412 /// and returns the new map. |
409 // TODO(jmesserly): find a new home for this. | 413 // TODO(jmesserly): find a new home for this. |
410 Map placeSourceMap(Map sourceMap, String sourceMapPath) { | 414 Map placeSourceMap(Map sourceMap, String sourceMapPath) { |
411 var dir = path.dirname(sourceMapPath); | 415 var dir = path.dirname(sourceMapPath); |
412 | 416 |
413 var map = new Map.from(sourceMap); | 417 var map = new Map.from(sourceMap); |
414 List list = new List.from(map['sources']); | 418 List list = new List.from(map['sources']); |
415 map['sources'] = list; | 419 map['sources'] = list; |
| 420 String relative(String uri) => |
| 421 path.toUri(path.relative(path.fromUri(uri), from: dir)).toString(); |
416 for (int i = 0; i < list.length; i++) { | 422 for (int i = 0; i < list.length; i++) { |
417 list[i] = | 423 list[i] = relative(list[i]); |
418 path.toUri(path.relative(path.fromUri(list[i]), from: dir)).toString(); | |
419 } | 424 } |
| 425 map['file'] = relative(map['file']); |
420 return map; | 426 return map; |
421 } | 427 } |
OLD | NEW |