feat(dart/transform): Add a parser for .ng_deps.dart
files and use.
Use the parser in `BindGenerator` This checkin also removes types from `registerSetters` calls since they can cause runtime failures (see #886). We will resolve this by generating change detector classes in the future.
This commit is contained in:
@ -5,6 +5,8 @@ import 'dart:convert';
|
||||
|
||||
import 'package:barback/barback.dart';
|
||||
|
||||
/// A class that allows fetching code using [AssetId]s without all the
|
||||
/// additional baggage of a [Transform].
|
||||
abstract class AssetReader {
|
||||
Future<String> readAsString(AssetId id, {Encoding encoding});
|
||||
Future<bool> hasInput(AssetId id);
|
||||
|
@ -13,16 +13,22 @@ import 'registered_type.dart';
|
||||
|
||||
export 'registered_type.dart';
|
||||
|
||||
/// A parser that reads `.ng_deps.dart` files (represented by [AssetId]s into
|
||||
/// easier to manage [NgDeps] files.
|
||||
class Parser {
|
||||
final AssetReader _reader;
|
||||
final _ParseNgDepsVisitor _visitor = new _ParseNgDepsVisitor();
|
||||
|
||||
Parser(AssetReader this._reader);
|
||||
|
||||
/// Parses the `.ng_deps.dart` file represented by `id` and all of the `
|
||||
/// .ng_deps.dart` files that it imports.
|
||||
Future<List<NgDeps>> parseRecursive(AssetId id) async {
|
||||
return _recurse(id);
|
||||
}
|
||||
|
||||
/// Parses only the `.ng_deps.dart` file represented by `id`.
|
||||
/// See also [parseRecursive].
|
||||
Future<NgDeps> parse(AssetId id) async {
|
||||
if (!(await _reader.hasInput(id))) return null;
|
||||
var ngDeps = new NgDeps(await _reader.readAsString(id));
|
||||
@ -56,6 +62,7 @@ class Parser {
|
||||
}
|
||||
}
|
||||
|
||||
/// The contents of a `.ng_deps.dart` file.
|
||||
class NgDeps {
|
||||
final String code;
|
||||
final List<ImportDirective> imports = [];
|
||||
|
@ -3,13 +3,17 @@ library angular2.src.transform.common.registered_type;
|
||||
import 'package:analyzer/analyzer.dart';
|
||||
import 'package:angular2/src/transform/common/names.dart';
|
||||
|
||||
/// Represents a call to `Reflector#registerType` generated by
|
||||
/// `DirectiveProcessor`.
|
||||
/// A call to `Reflector#registerType` generated by `DirectiveProcessor`.
|
||||
class RegisteredType {
|
||||
/// The type registered by this call.
|
||||
final Identifier typeName;
|
||||
/// The actual call to `Reflector#registerType`.
|
||||
final MethodInvocation registerMethod;
|
||||
/// The factory method registered.
|
||||
final Expression factory;
|
||||
/// The parameters registered.
|
||||
final Expression parameters;
|
||||
/// The annotations registered.
|
||||
final Expression annotations;
|
||||
|
||||
RegisteredType._(this.typeName, this.registerMethod, this.factory,
|
||||
|
Reference in New Issue
Block a user