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
This commit is contained in:
Tim Blasi 2015-10-13 16:01:07 -07:00
parent 563a76304a
commit e9c4c61986
6 changed files with 73 additions and 51 deletions

View File

@ -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<Object> {
var loadLibraryInvocations = new List<MethodInvocation>();
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<Object> {
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.

View File

@ -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,

View File

@ -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()));
}

View File

@ -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
}
}
}
}

View File

@ -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()));
}

View File

@ -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
}
}
}
}