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 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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 // In singleOutFile mode we wrap each module in an eval statement to | 495 // In singleOutFile mode we wrap each module in an eval statement to |
496 // leverage sourceURL to improve the debugging experience when source maps | 496 // leverage sourceURL to improve the debugging experience when source maps |
497 // are not enabled. | 497 // are not enabled. |
498 // | 498 // |
499 // Note: We replace all `/` with `.` so that we don't break relative urls | 499 // Note: We replace all `/` with `.` so that we don't break relative urls |
500 // to sources in the original sourcemap. The name of this file is bogus | 500 // to sources in the original sourcemap. The name of this file is bogus |
501 // anyways, so it has very little effect on things. | 501 // anyways, so it has very little effect on things. |
502 c += '\n//# sourceURL=${name.replaceAll("/", ".")}.js\n'; | 502 c += '\n//# sourceURL=${name.replaceAll("/", ".")}.js\n'; |
503 c = 'eval(${JSON.encode(c)});\n'; | 503 c = 'eval(${JSON.encode(c)});\n'; |
504 } | 504 } |
505 new File(jsPath).writeAsStringSync(c); | 505 |
| 506 var file = new File(jsPath); |
| 507 if (!file.parent.existsSync()) file.parent.createSync(recursive: true); |
| 508 file.writeAsStringSync(c); |
| 509 |
506 // TODO(jacobr): it is a bit strange we are writing the source map to a file | 510 // TODO(jacobr): it is a bit strange we are writing the source map to a file |
507 // even when options.inlineSourceMap is true. To be consistent perhaps we | 511 // even when options.inlineSourceMap is true. To be consistent perhaps we |
508 // should also write a copy of the source file without a sourcemap even when | 512 // should also write a copy of the source file without a sourcemap even when |
509 // inlineSourceMap is true. | 513 // inlineSourceMap is true. |
510 if (code.sourceMap != null) { | 514 if (code.sourceMap != null) { |
511 new File(mapPath).writeAsStringSync(JSON.encode(code.sourceMap)); | 515 file = new File(mapPath); |
| 516 if (!file.parent.existsSync()) file.parent.createSync(recursive: true); |
| 517 file.writeAsStringSync(JSON.encode(code.sourceMap)); |
512 } | 518 } |
513 } | 519 } |
514 } | 520 } |
515 | 521 |
516 /// The output of compiling a JavaScript module in a particular format. | 522 /// The output of compiling a JavaScript module in a particular format. |
517 class JSModuleCode { | 523 class JSModuleCode { |
518 /// The JavaScript code for this module. | 524 /// The JavaScript code for this module. |
519 /// | 525 /// |
520 /// If a [sourceMap] is available, this will include the `sourceMappingURL` | 526 /// If a [sourceMap] is available, this will include the `sourceMappingURL` |
521 /// comment at end of the file. | 527 /// comment at end of the file. |
(...skipping 24 matching lines...) Expand all Loading... |
546 // Fall back to a relative path. | 552 // Fall back to a relative path. |
547 return path.toUri(path.relative(path.fromUri(uri), from: dir)).toString(); | 553 return path.toUri(path.relative(path.fromUri(uri), from: dir)).toString(); |
548 } | 554 } |
549 | 555 |
550 for (int i = 0; i < list.length; i++) { | 556 for (int i = 0; i < list.length; i++) { |
551 list[i] = transformUri(list[i]); | 557 list[i] = transformUri(list[i]); |
552 } | 558 } |
553 map['file'] = transformUri(map['file']); | 559 map['file'] = transformUri(map['file']); |
554 return map; | 560 return map; |
555 } | 561 } |
OLD | NEW |