| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library deferred_load; | 5 library deferred_load; |
| 6 | 6 |
| 7 import 'common/tasks.dart' show CompilerTask; | 7 import 'common/tasks.dart' show CompilerTask; |
| 8 import 'common.dart'; | 8 import 'common.dart'; |
| 9 import 'compiler.dart' show Compiler; | 9 import 'compiler.dart' show Compiler; |
| 10 import 'constants/expressions.dart' show ConstantExpression; | 10 import 'constants/expressions.dart' show ConstantExpression; |
| (...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 /// Where | 920 /// Where |
| 921 /// | 921 /// |
| 922 /// - <library uri> is the relative uri of the library making a deferred | 922 /// - <library uri> is the relative uri of the library making a deferred |
| 923 /// import. | 923 /// import. |
| 924 /// - <library name> is the name of the library, and "<unnamed>" if it is | 924 /// - <library name> is the name of the library, and "<unnamed>" if it is |
| 925 /// unnamed. | 925 /// unnamed. |
| 926 /// - <prefix> is the `as` prefix used for a given deferred import. | 926 /// - <prefix> is the `as` prefix used for a given deferred import. |
| 927 /// - <list of files> is a list of the filenames the must be loaded when that | 927 /// - <list of files> is a list of the filenames the must be loaded when that |
| 928 /// import is loaded. | 928 /// import is loaded. |
| 929 Map<String, Map<String, dynamic>> computeDeferredMap() { | 929 Map<String, Map<String, dynamic>> computeDeferredMap() { |
| 930 JavaScriptBackend backend = compiler.backend; | |
| 931 Map<String, Map<String, dynamic>> mapping = | 930 Map<String, Map<String, dynamic>> mapping = |
| 932 new Map<String, Map<String, dynamic>>(); | 931 new Map<String, Map<String, dynamic>>(); |
| 933 _deferredImportDescriptions.keys.forEach((_DeferredImport import) { | 932 _deferredImportDescriptions.keys.forEach((_DeferredImport import) { |
| 934 List<OutputUnit> outputUnits = hunksToLoad[importDeferName[import]]; | 933 List<OutputUnit> outputUnits = hunksToLoad[importDeferName[import]]; |
| 935 ImportDescription description = _deferredImportDescriptions[import]; | 934 ImportDescription description = _deferredImportDescriptions[import]; |
| 936 Map<String, dynamic> libraryMap = mapping.putIfAbsent( | 935 Map<String, dynamic> libraryMap = mapping.putIfAbsent( |
| 937 description.importingUri, | 936 description.importingUri, |
| 938 () => <String, dynamic>{ | 937 () => <String, dynamic>{ |
| 939 "name": description.importingLibraryName, | 938 "name": description.importingLibraryName, |
| 940 "imports": <String, List<String>>{} | 939 "imports": <String, List<String>>{} |
| 941 }); | 940 }); |
| 942 | 941 |
| 943 libraryMap["imports"][importDeferName[import]] = | 942 libraryMap["imports"][importDeferName[import]] = |
| 944 outputUnits.map((OutputUnit outputUnit) { | 943 outputUnits.map((OutputUnit outputUnit) { |
| 945 return backend.deferredPartFileName(outputUnit.name); | 944 return deferredPartFileName(outputUnit.name); |
| 946 }).toList(); | 945 }).toList(); |
| 947 }); | 946 }); |
| 948 return mapping; | 947 return mapping; |
| 949 } | 948 } |
| 950 | 949 |
| 950 /// Returns the filename for the output-unit named [name]. |
| 951 /// |
| 952 /// The filename is of the form "<main output file>_<name>.part.js". |
| 953 /// If [addExtension] is false, the ".part.js" suffix is left out. |
| 954 String deferredPartFileName(String name, {bool addExtension: true}) { |
| 955 assert(name != ""); |
| 956 String outPath = compiler.options.outputUri != null |
| 957 ? compiler.options.outputUri.path |
| 958 : "out"; |
| 959 String outName = outPath.substring(outPath.lastIndexOf('/') + 1); |
| 960 String extension = addExtension ? ".part.js" : ""; |
| 961 return "${outName}_$name$extension"; |
| 962 } |
| 963 |
| 951 /// Creates a textual representation of the output unit content. | 964 /// Creates a textual representation of the output unit content. |
| 952 String dump() { | 965 String dump() { |
| 953 Map<OutputUnit, List<String>> elementMap = <OutputUnit, List<String>>{}; | 966 Map<OutputUnit, List<String>> elementMap = <OutputUnit, List<String>>{}; |
| 954 Map<OutputUnit, List<String>> constantMap = <OutputUnit, List<String>>{}; | 967 Map<OutputUnit, List<String>> constantMap = <OutputUnit, List<String>>{}; |
| 955 _elementToOutputUnit.forEach((Element element, OutputUnit output) { | 968 _elementToOutputUnit.forEach((Element element, OutputUnit output) { |
| 956 elementMap.putIfAbsent(output, () => <String>[]).add('$element'); | 969 elementMap.putIfAbsent(output, () => <String>[]).add('$element'); |
| 957 }); | 970 }); |
| 958 _constantToOutputUnit.forEach((ConstantValue value, OutputUnit output) { | 971 _constantToOutputUnit.forEach((ConstantValue value, OutputUnit output) { |
| 959 constantMap | 972 constantMap |
| 960 .putIfAbsent(output, () => <String>[]) | 973 .putIfAbsent(output, () => <String>[]) |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 | 1074 |
| 1062 bool operator ==(other) { | 1075 bool operator ==(other) { |
| 1063 if (other is! _DeclaredDeferredImport) return false; | 1076 if (other is! _DeclaredDeferredImport) return false; |
| 1064 return declaration == other.declaration; | 1077 return declaration == other.declaration; |
| 1065 } | 1078 } |
| 1066 | 1079 |
| 1067 int get hashCode => declaration.hashCode * 17; | 1080 int get hashCode => declaration.hashCode * 17; |
| 1068 | 1081 |
| 1069 String toString() => '$declaration'; | 1082 String toString() => '$declaration'; |
| 1070 } | 1083 } |
| OLD | NEW |