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..2b0ab4d236b111b289753f172816dabc20c23abf 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,7 +676,10 @@ 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; |
| + _deferredImportDescriptions[import] = |
| + new ImportDescription(import, library, compiler); |
| if (prefix == null) { |
| compiler.reportError(import, |
| @@ -764,4 +772,37 @@ class DeferredLoadTask extends CompilerTask { |
| } |
| return null; |
| } |
| + |
| + /// Returns a json-style map for describing what files that are loaded by a |
| + /// given deferred import. |
| + Map deferredMap() { |
|
floitsch
2015/01/05 14:10:38
has a getter name.
Either make it a getter, or cha
sigurdm
2015/01/05 15:23:08
Done.
|
| + JavaScriptBackend backend = compiler.backend; |
| + Map mapping = {}; |
| + _deferredImportDescriptions.keys.forEach((ast.Import import) { |
| + List<OutputUnit> outputUnits = hunksToLoad[importDeferName[import]]; |
| + ImportDescription description = _deferredImportDescriptions[import]; |
| + Map a = mapping.putIfAbsent(description.importingUri, () => {}); |
|
floitsch
2015/01/05 14:10:38
what's "a" ?
Type the map (both static and dynamic
sigurdm
2015/01/05 15:23:08
Fixed the name.
|
| + |
| + a[description.prefix] = outputUnits.map( |
| + (OutputUnit outputUnit) { |
| + return backend.emitter.oldEmitter.deferredPartFileName(outputUnit); |
|
floitsch
2015/01/05 14:10:38
Don't go through "oldEmitter".
The best is probabl
sigurdm
2015/01/05 15:23:08
Moved it to backend.
|
| + }).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; |
| +} |