feat(dart/transform): Add a di transformer

Add a transformer for `di` which generates `.ng_deps.dart` files for all
`.dart` files it is run on. These `.ng_deps.dart` files register
metadata for any `@Injectable` classes.

Fix unit tests for changes introduced by the di transformer.

When using `pub (build|serve) --mode=ngstatic`, we will also generate
getters and setters, parse templates, and remove import of `dart:mirrors`
in the Angular transform. Because this is still relatively immature, we
use the mode to keep it opt-in for now.

Closes #700
This commit is contained in:
Tim Blasi
2015-03-19 14:10:28 -07:00
parent 788461b7e2
commit 09948f4403
39 changed files with 147 additions and 73 deletions

View File

@ -16,9 +16,7 @@ import 'linker.dart';
/// `setupReflection` call the necessary `setupReflection` method in all
/// dependencies.
class DirectiveLinker extends Transformer {
final TransformerOptions options;
DirectiveLinker(this.options);
DirectiveLinker();
@override
bool isPrimary(AssetId id) => id.path.endsWith(DEPS_EXTENSION);
@ -28,10 +26,11 @@ class DirectiveLinker extends Transformer {
log.init(transform);
try {
var reader = new AssetReader.fromTransform(transform);
var assetId = transform.primaryInput.id;
var transformedCode =
await linkNgDeps(new AssetReader.fromTransform(transform), assetId);
var formattedCode = formatter.format(transformedCode, uri: assetId.path);
var assetPath = assetId.path;
var transformedCode = await linkNgDeps(reader, assetId);
var formattedCode = formatter.format(transformedCode, uri: assetPath);
transform.addOutput(new Asset.fromString(assetId, formattedCode));
} catch (ex, stackTrace) {
log.logger.error('Linking ng directives failed.\n'