Chromium Code Reviews| Index: pkg/compiler/lib/src/deferred_load.dart |
| diff --git a/pkg/compiler/lib/src/deferred_load.dart b/pkg/compiler/lib/src/deferred_load.dart |
| index f11b6545e07036c08ab9558dca600908930a6545..37c8788e443ce6d6da3822d0b9878861664c178b 100644 |
| --- a/pkg/compiler/lib/src/deferred_load.dart |
| +++ b/pkg/compiler/lib/src/deferred_load.dart |
| @@ -40,6 +40,7 @@ import 'elements/elements.dart' show |
| import 'util/util.dart' show |
| Link, makeUnique; |
| +import 'util/uri_extras.dart' as uri_extras; |
| import 'util/setlet.dart' show |
| Setlet; |
| @@ -146,6 +147,10 @@ class DeferredLoadTask extends CompilerTask { |
| final Map<Import, LibraryElement> _allDeferredImports = |
| new Map<Import, LibraryElement>(); |
| + /// Because the token-stream is forgotten later in the program, we cache a |
| + /// description of each deferred import. |
| + final _deferredImportDescriptions = new Map<Import, ImportDescription>(); |
| + |
| // For each deferred import we want to know exactly what elements have to |
| // be loaded. |
| Map<Import, Set<Element>> _importedDeferredBy = null; |
| @@ -617,7 +622,7 @@ class DeferredLoadTask extends CompilerTask { |
| }); |
| } |
| - void ensureMetadataResolved(Compiler compiler) { |
| + void beforeResolution(Compiler compiler) { |
| if (compiler.mainApp == null) return; |
| _allDeferredImports[_fakeMainImport] = compiler.mainApp; |
| var lastDeferred; |
| @@ -671,13 +676,16 @@ class DeferredLoadTask extends CompilerTask { |
| // The last import we saw with the same prefix. |
| Import previousDeferredImport = prefixDeferredImport[prefix]; |
| if (import.isDeferred) { |
| - _allDeferredImports[import] = library.getLibraryFromTag(import); |
| + LibraryElement importedLibrary = library.getLibraryFromTag(import); |
| + _allDeferredImports[import] = importedLibrary; |
| if (prefix == null) { |
| compiler.reportError(import, |
| MessageKind.DEFERRED_LIBRARY_WITHOUT_PREFIX); |
| } else { |
| prefixDeferredImport[prefix] = import; |
| + _deferredImportDescriptions[import] = |
| + new ImportDescription(import, library, compiler); |
| } |
| isProgramSplit = true; |
| lastDeferred = import; |
| @@ -764,4 +772,40 @@ class DeferredLoadTask extends CompilerTask { |
| } |
| return null; |
| } |
| + |
| + /// Returns a json-style map for describing what files that are loaded by a |
| + /// given deferred import. |
|
floitsch
2015/01/05 15:46:19
Add comment what the keys and values are.
sigurdm
2015/01/06 09:02:20
Done.
|
| + Map<String, Map<String, List<String>>> getDeferredMap() { |
|
floitsch
2015/01/05 15:46:19
'getX' doesn't say why this is not a getter.
compu
sigurdm
2015/01/06 09:02:20
Done.
|
| + JavaScriptBackend backend = compiler.backend; |
| + Map<String, Map<String, List<String>>> mapping = |
|
floitsch
2015/01/05 15:46:19
Now I understand why you didn't add the types...
sigurdm
2015/01/06 09:02:20
First the map had a different structure that could
|
| + new Map<String, Map<String, List<String>>>(); |
| + _deferredImportDescriptions.keys.forEach((ast.Import import) { |
| + List<OutputUnit> outputUnits = hunksToLoad[importDeferName[import]]; |
| + ImportDescription description = _deferredImportDescriptions[import]; |
| + Map<String, List<String>> fileLists = |
| + mapping.putIfAbsent(description.importingUri, |
| + () => new Map<String, List<String>>()); |
| + |
| + fileLists[description.prefix] = outputUnits.map( |
| + (OutputUnit outputUnit) { |
| + return backend.outputFileName("${outputUnit.name}.part.js"); |
|
floitsch
2015/01/05 15:46:19
Don't add the extension here.
Ask for the deferred
sigurdm
2015/01/06 09:02:20
Done.
|
| + }).toList(); |
| + }); |
| + return mapping; |
| + } |
| } |
| + |
| +class ImportDescription { |
| + /// Relative uri to the importing library. |
| + final String importingUri; |
| + /// The prefix this import is imported as. |
| + final String prefix; |
| + |
| + ImportDescription(Import import, |
| + LibraryElement importingLibrary, |
| + Compiler compiler) |
| + : importingUri = uri_extras.relativize( |
| + compiler.mainApp.canonicalUri, |
| + importingLibrary.canonicalUri, false), |
| + prefix = import.prefix.source; |
| +} |