refactor(dart/transform): Generate inputs
setters in TemplateCompiler
step
Move generation of setters for `inputs` from `BindGenerator` into `TemplateCompiler`.
This commit is contained in:
@ -8,8 +8,6 @@ import 'package:angular2/src/transform/common/ng_deps.dart';
|
||||
import 'package:angular2/src/transform/common/property_utils.dart' as prop;
|
||||
import 'package:barback/barback.dart';
|
||||
|
||||
import 'visitor.dart';
|
||||
|
||||
class _ExtractQueryFieldsFromAnnotation extends Object
|
||||
with RecursiveAstVisitor<Object> {
|
||||
final ConstantEvaluator _evaluator = new ConstantEvaluator();
|
||||
@ -73,7 +71,7 @@ Future<String> createNgSettersAndGetters(
|
||||
NgDeps ngDeps = await NgDeps.parse(reader, entryPoint);
|
||||
|
||||
String code = ngDeps.code;
|
||||
var setters = _generateSetters(_createInputPropertiesMap(ngDeps));
|
||||
var setters = [];
|
||||
|
||||
ngDeps.registeredTypes.forEach((t) {
|
||||
final fromAnnotation = new _ExtractQueryFieldsFromAnnotation();
|
||||
@ -116,32 +114,3 @@ List<String> _generateSetters(Map<String, String> bindMap) {
|
||||
});
|
||||
return setters;
|
||||
}
|
||||
|
||||
/// Collapses all `inputs` in {@link ngDeps} into a map where the keys are
|
||||
/// the bind inputs and the values are either the one and only type
|
||||
/// binding to that property or the empty string.
|
||||
Map<String, String> _createInputPropertiesMap(NgDeps ngDeps) {
|
||||
var visitor = new ExtractNamedExpressionVisitor('inputs');
|
||||
var bindMap = {};
|
||||
ngDeps.registeredTypes.forEach((RegisteredType t) {
|
||||
visitor.bindConfig.clear();
|
||||
t.annotations.accept(visitor);
|
||||
visitor.bindConfig.forEach((String config) {
|
||||
// See comments for `Directive` in annotations_impl/annotations.ts for
|
||||
// details on how `inputs` is specified.
|
||||
var prop;
|
||||
var idx = config.indexOf(':');
|
||||
if (idx > 0) {
|
||||
prop = config.substring(0, idx).trim();
|
||||
} else {
|
||||
prop = config;
|
||||
}
|
||||
if (bindMap.containsKey(prop)) {
|
||||
bindMap[prop] = '';
|
||||
} else {
|
||||
bindMap[prop] = '${t.typeName}';
|
||||
}
|
||||
});
|
||||
});
|
||||
return bindMap;
|
||||
}
|
||||
|
@ -1,30 +0,0 @@
|
||||
library angular2.transform.bind_generator.visitor;
|
||||
|
||||
import 'package:analyzer/analyzer.dart';
|
||||
import 'package:angular2/src/transform/common/logging.dart';
|
||||
|
||||
/// Visitor responsible for crawling the "annotations" value in a
|
||||
/// `registerType` call and pulling out the properties of any "bind"
|
||||
/// values found.
|
||||
class ExtractNamedExpressionVisitor extends Object
|
||||
with RecursiveAstVisitor<Object> {
|
||||
final ConstantEvaluator _evaluator = new ConstantEvaluator();
|
||||
final List<String> bindConfig = [];
|
||||
final String nameToExtract;
|
||||
|
||||
ExtractNamedExpressionVisitor(this.nameToExtract);
|
||||
|
||||
@override
|
||||
Object visitNamedExpression(NamedExpression node) {
|
||||
if ('${node.name.label}' == nameToExtract) {
|
||||
var evaluated = node.expression.accept(_evaluator);
|
||||
if (evaluated is List) {
|
||||
bindConfig.addAll(evaluated);
|
||||
} else {
|
||||
logger.error('`$nameToExtract` currently only supports List values');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return super.visitNamedExpression(node);
|
||||
}
|
||||
}
|
@ -15,8 +15,15 @@ class Processor implements CodegenModel {
|
||||
final Set<ReflectiveAccessor> methodNames = new Set<ReflectiveAccessor>();
|
||||
|
||||
void process(CompileDirectiveMetadata meta) {
|
||||
meta.outputs.keys.forEach((eventName) {
|
||||
getterNames.add(new ReflectiveAccessor(eventName));
|
||||
});
|
||||
if (meta.outputs != null) {
|
||||
meta.outputs.keys.forEach((eventName) {
|
||||
getterNames.add(new ReflectiveAccessor(eventName));
|
||||
});
|
||||
}
|
||||
if (meta.inputs != null) {
|
||||
meta.inputs.keys.forEach((inputName) {
|
||||
setterNames.add(new ReflectiveAccessor(inputName));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user