From e9c4c6198615dfde5d195680e8512eb45430ab3d Mon Sep 17 00:00:00 2001 From: Tim Blasi Date: Tue, 13 Oct 2015 16:01:07 -0700 Subject: [PATCH] refactor(dart/transform): Have DeferredRewriter run in parallel Previously, `DeferredRewriter` checked for the existence of `.ng_deps.dart` files to determine which deferred libraries it needed to rewrite, requiring that those assets exist at the time it was run. Update to check for `.ng_meta.json` files instead, which exist after the `DirectiveProcessor` phase. This allows the `DeferredRewriter` (which only processes *.dart files) to run in parallel with `TemplateComplier` (which only processes *.ng_meta.json files) and `StylesheetCompiler` (which only processes *.css files). Have DeferredRewriter to check existence of .ng_meta.json assets rather than .ng_deps.dart assets --- .../transform/deferred_rewriter/rewriter.dart | 12 ++++--- .../lib/src/transform/transformer.dart | 4 +-- .../hello.ng_deps.dart | 22 ------------- .../hello.ng_meta.json | 32 +++++++++++++++++++ .../hello.ng_deps.dart | 22 ------------- .../hello.ng_meta.json | 32 +++++++++++++++++++ 6 files changed, 73 insertions(+), 51 deletions(-) delete mode 100644 modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/hello.ng_deps.dart create mode 100644 modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/hello.ng_meta.json delete mode 100644 modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/hello.ng_deps.dart create mode 100644 modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/hello.ng_meta.json diff --git a/modules_dart/transform/lib/src/transform/deferred_rewriter/rewriter.dart b/modules_dart/transform/lib/src/transform/deferred_rewriter/rewriter.dart index d439e86020..4cfbcb9135 100644 --- a/modules_dart/transform/lib/src/transform/deferred_rewriter/rewriter.dart +++ b/modules_dart/transform/lib/src/transform/deferred_rewriter/rewriter.dart @@ -7,8 +7,8 @@ import 'package:analyzer/src/generated/ast.dart'; import 'package:angular2/src/transform/common/asset_reader.dart'; import 'package:angular2/src/transform/common/logging.dart'; import 'package:angular2/src/transform/common/names.dart'; +import 'package:angular2/src/transform/common/url_resolver.dart'; import 'package:barback/barback.dart'; -import 'package:code_transformers/assets.dart'; import 'package:quiver/iterables.dart' as it; class Rewriter { @@ -77,6 +77,7 @@ class _FindDeferredLibraries extends Object with RecursiveAstVisitor { var loadLibraryInvocations = new List(); final AssetReader _reader; final AssetId _entryPoint; + final _urlResolver = const TransformerUrlResolver(); _FindDeferredLibraries(this._reader, this._entryPoint); @@ -109,16 +110,17 @@ class _FindDeferredLibraries extends Object with RecursiveAstVisitor { return true; } - // Remove all deferredImports that do not have a ng_dep file + // Remove all deferredImports that do not have an associated ng_meta file // then remove all loadLibrary invocations that are not in the set of // prefixes that are left. Future cull() async { + var baseUri = toAssetUri(_entryPoint); + // Determine whether a deferred import has ng_deps. var hasInputs = await Future.wait(deferredImports .map((import) => stringLiteralToString(import.uri)) - .map((uri) => toDepsExtension(uri)) - .map((depsUri) => uriToAssetId(_entryPoint, depsUri, logger, null, - errorOnAbsolute: false)) + .map((uri) => toMetaExtension(uri)) + .map((metaUri) => fromUri(_urlResolver.resolve(baseUri, metaUri))) .map((asset) => _reader.hasInput(asset))); // Filter out any deferred imports that do not have ng_deps. diff --git a/modules_dart/transform/lib/src/transform/transformer.dart b/modules_dart/transform/lib/src/transform/transformer.dart index f204889f1b..4aea0b03c3 100644 --- a/modules_dart/transform/lib/src/transform/transformer.dart +++ b/modules_dart/transform/lib/src/transform/transformer.dart @@ -36,10 +36,10 @@ class AngularTransformerGroup extends TransformerGroup { [new DirectiveProcessor(options)], [new DirectiveMetadataLinker()], [ - new TemplateCompiler(options), + new DeferredRewriter(options), new StylesheetCompiler(), + new TemplateCompiler(options) ], - [new DeferredRewriter(options)] ]; } return new AngularTransformerGroup._(phases, diff --git a/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/hello.ng_deps.dart b/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/hello.ng_deps.dart deleted file mode 100644 index 9301c5915d..0000000000 --- a/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/hello.ng_deps.dart +++ /dev/null @@ -1,22 +0,0 @@ -library playground.src.hello_world.absolute_url_expression_files.ng_deps.dart; - -import 'hello.dart'; -export 'hello.dart'; -import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; -import 'package:angular2/angular2.dart' - show bootstrap, Component, Directive, View, NgElement; - -var _visited = false; -void initReflector() { - if (_visited) return; - _visited = true; - _ngRef.reflector - ..registerType( - HelloCmp, - new _ngRef.ReflectionInfo(const [ - const Component(selector: 'hello-app'), - const View( - template: r'''{{greeting}}''', - templateUrl: r'package:other_package/template.html') - ], const [], () => new HelloCmp())); -} diff --git a/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/hello.ng_meta.json b/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/hello.ng_meta.json new file mode 100644 index 0000000000..5368afb25e --- /dev/null +++ b/modules_dart/transform/test/transform/deferred_rewriter/complex_deferred_example/hello.ng_meta.json @@ -0,0 +1,32 @@ +{ + "HelloCmp": + { + "kind": "type", + "value": { + "isComponent": true, + "dynamicLoadable": true, + "selector":"hello-app", + "exportAs": null, + "type": { + "id": 1, + "name": "HelloCmp", + "moduleUrl": "asset:angular2/test/transform/deferred_rewriter/complex_deferred_example/hello.dart" + }, + "changeDetection": 5, + "inputs": {}, + "outputs": {}, + "hostListeners": {}, + "hostProperties": {}, + "hostAttributes": {}, + "lifecycleHooks": [], + "template": { + "encapsulation": 0, + "template": "Hi", + "templateUrl": "package:other_package/template.html", + "styles": null, + "styleUrls": null, + "ngContentSelectors": null + } + } + } +} \ No newline at end of file diff --git a/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/hello.ng_deps.dart b/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/hello.ng_deps.dart deleted file mode 100644 index 3c3c3991c4..0000000000 --- a/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/hello.ng_deps.dart +++ /dev/null @@ -1,22 +0,0 @@ -library playground.src.hello_world.absolute_url_expression_files.ng_deps.dart; - -import 'hello.dart'; -export 'hello.dart'; -import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef; -import 'package:angular2/angular2.dart' - show bootstrap, Component, Directive, View, NgElement; - -var _visited = false; -void initReflector() { - if (_visited) return; - _visited = true; - _ngRef.reflector - ..registerType( - HelloCmp, - new _ngRef.RegistrationInfo(const [ - const Component(selector: 'hello-app'), - const View( - template: r'''{{greeting}}''', - templateUrl: r'package:other_package/template.html') - ], const [], () => new HelloCmp())); -} diff --git a/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/hello.ng_meta.json b/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/hello.ng_meta.json new file mode 100644 index 0000000000..a4b890a104 --- /dev/null +++ b/modules_dart/transform/test/transform/deferred_rewriter/simple_deferred_example/hello.ng_meta.json @@ -0,0 +1,32 @@ +{ + "HelloCmp": + { + "kind": "type", + "value": { + "isComponent": true, + "dynamicLoadable": true, + "selector":"hello-app", + "exportAs": null, + "type": { + "id": 1, + "name": "HelloCmp", + "moduleUrl": "asset:angular2/test/transform/deferred_rewriter/simple_deferred_example/hello.dart" + }, + "changeDetection": 5, + "inputs": {}, + "outputs": {}, + "hostListeners": {}, + "hostProperties": {}, + "hostAttributes": {}, + "lifecycleHooks": [], + "template": { + "encapsulation": 0, + "template": "Hi", + "templateUrl": "package:other_package/template.html", + "styles": null, + "styleUrls": null, + "ngContentSelectors": null + } + } + } +} \ No newline at end of file