feat(transformers): implement initializing deferred libraries

Implement deferred libraries to work with dependency injection and other
angular codegen. This is done by not initializing the library in the parent
ng_deps file when it is declared as deferred, rewriting the import and,
chaining a future that initializes the library in any files that are using
deferred libraries which need angular codegen.
This commit is contained in:
Ted Sander
2015-07-17 13:07:31 -07:00
parent 2f08ed8d3e
commit 5cc84ed4bb
46 changed files with 459 additions and 2 deletions
@@ -93,7 +93,9 @@ class CreateNgDepsVisitor extends Object with SimpleAstVisitor<Object> {
void _maybeWriteImport() {
if (_wroteBaseLibImport) return;
_wroteBaseLibImport = true;
writer.print('''import '${path.basename(assetId.path)}';''');
var origDartFile = path.basename(assetId.path);
writer.print('''import '$origDartFile';''');
writer.print('''export '$origDartFile';''');
writer.print("import '$_REFLECTOR_IMPORT' as $_REF_PREFIX;");
}
@@ -106,6 +108,11 @@ class CreateNgDepsVisitor extends Object with SimpleAstVisitor<Object> {
Object visitImportDirective(ImportDirective node) {
_maybeWriteImport();
_updateUsesNonLangLibs(node);
// Ignore deferred imports here so as to not load the deferred libraries
// code in the current library causing much of the code to not be
// deferred. Instead `DeferredRewriter` will rewrite the code as to load
// `ng_deps` in a deferred way.
if (node.deferredKeyword != null) return null;
return node.accept(_copyVisitor);
}