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 // Assume these are in the same directory and use relative paths. |
Jennifer Messerly
2016/08/26 23:06:37
I don't understand why we need this assumption. Ca
vsm
2016/08/26 23:19:48
Done.
| |
367 assert(path.dirname(jsUrl) == path.dirname(mapUrl)); | |
368 printer.emit('\n//# sourceMappingURL=${path.basename(mapUrl)}\n'); | |
367 } | 369 } |
368 | 370 |
369 Map builtMap; | 371 Map builtMap; |
370 if (sourceMap != null) { | 372 if (sourceMap != null) { |
371 builtMap = placeSourceMap(sourceMap.build(jsUrl), mapUrl); | 373 builtMap = placeSourceMap(sourceMap.build(path.basename(jsUrl)), mapUrl); |
Jennifer Messerly
2016/08/26 23:06:37
here too, I don't see why this is needed, the whol
vsm
2016/08/26 23:19:48
done - see below.
| |
372 } | 374 } |
373 return new JSModuleCode(printer.getText(), builtMap); | 375 return new JSModuleCode(printer.getText(), builtMap); |
374 } | 376 } |
375 | 377 |
376 /// Similar to [getCode] but immediately writes the resulting files. | 378 /// Similar to [getCode] but immediately writes the resulting files. |
377 /// | 379 /// |
378 /// If [mapPath] is not supplied but [options.sourceMap] is set, mapPath | 380 /// If [mapPath] is not supplied but [options.sourceMap] is set, mapPath |
379 /// will default to [jsPath].map. | 381 /// will default to [jsPath].map. |
380 void writeCodeSync(ModuleFormat format, String jsPath, [String mapPath]) { | 382 void writeCodeSync(ModuleFormat format, String jsPath, [String mapPath]) { |
381 if (mapPath == null) mapPath = jsPath + '.map'; | 383 if (mapPath == null) mapPath = jsPath + '.map'; |
(...skipping 30 matching lines...) Expand all Loading... | |
412 | 414 |
413 var map = new Map.from(sourceMap); | 415 var map = new Map.from(sourceMap); |
414 List list = new List.from(map['sources']); | 416 List list = new List.from(map['sources']); |
415 map['sources'] = list; | 417 map['sources'] = list; |
416 for (int i = 0; i < list.length; i++) { | 418 for (int i = 0; i < list.length; i++) { |
417 list[i] = | 419 list[i] = |
418 path.toUri(path.relative(path.fromUri(list[i]), from: dir)).toString(); | 420 path.toUri(path.relative(path.fromUri(list[i]), from: dir)).toString(); |
419 } | 421 } |
420 return map; | 422 return map; |
421 } | 423 } |
OLD | NEW |