Skip to content

Commit

Permalink
refactor(transformer): apply properties/events rename
Browse files Browse the repository at this point in the history
  • Loading branch information
tbosch committed Oct 1, 2015
1 parent e533a81 commit 61ba63c
Show file tree
Hide file tree
Showing 34 changed files with 91 additions and 91 deletions.
Expand Up @@ -72,7 +72,7 @@ Future<String> createNgSettersAndGetters(
NgDeps ngDeps = await NgDeps.parse(reader, entryPoint);

String code = ngDeps.code;
var setters = _generateSetters(_createPropertiesMap(ngDeps));
var setters = _generateSetters(_createInputPropertiesMap(ngDeps));

ngDeps.registeredTypes.forEach((t) {
final fromAnnotation = new _ExtractQueryFieldsFromAnnotation();
Expand All @@ -99,7 +99,7 @@ Future<String> createNgSettersAndGetters(

// TODO(kegluneq): De-dupe from template_compiler/generator.dart, #3589.

/// Consumes the map generated by {@link _createPropertiesMap} to codegen
/// Consumes the map generated by {@link _createInputPropertiesMap} to codegen
/// setters.
List<String> _generateSetters(Map<String, String> bindMap) {
var setters = [];
Expand All @@ -116,18 +116,18 @@ List<String> _generateSetters(Map<String, String> bindMap) {
return setters;
}

/// Collapses all `properties` in {@link ngDeps} into a map where the keys are
/// the bind properties and the values are either the one and only type
/// 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> _createPropertiesMap(NgDeps ngDeps) {
var visitor = new ExtractNamedExpressionVisitor('properties');
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 `properties` is specified.
// details on how `inputs` is specified.
var prop;
var idx = config.indexOf(':');
if (idx > 0) {
Expand Down
Expand Up @@ -137,8 +137,8 @@ class _DirectiveMetadataVisitor extends Object
String _selector;
String _exportAs;
ChangeDetectionStrategy _changeDetection;
List<String> _properties;
List<String> _events;
List<String> _inputs;
List<String> _outputs;
Map<String, String> _host;
List<LifecycleHooks> _lifecycleHooks;
CompileTemplateMetadata _template;
Expand All @@ -153,8 +153,8 @@ class _DirectiveMetadataVisitor extends Object
_selector = '';
_exportAs = null;
_changeDetection = ChangeDetectionStrategy.Default;
_properties = <String>[];
_events = <String>[];
_inputs = <String>[];
_outputs = <String>[];
_host = <String, String>{};
_lifecycleHooks = null;
_template = null;
Expand All @@ -169,8 +169,8 @@ class _DirectiveMetadataVisitor extends Object
selector: _selector,
exportAs: _exportAs,
changeDetection: _changeDetection,
properties: _properties,
events: _events,
inputs: _inputs,
outputs: _outputs,
host: _host,
lifecycleHooks: _lifecycleHooks,
template: _template);
Expand Down Expand Up @@ -232,7 +232,7 @@ class _DirectiveMetadataVisitor extends Object
case 'selector':
_populateSelector(node.expression);
break;
case 'properties':
case 'inputs':
_populateProperties(node.expression);
break;
case 'host':
Expand All @@ -244,7 +244,7 @@ class _DirectiveMetadataVisitor extends Object
case 'changeDetection':
_populateChangeDetection(node.expression);
break;
case 'events':
case 'outputs':
_populateEvents(node.expression);
break;
}
Expand All @@ -264,9 +264,9 @@ class _DirectiveMetadataVisitor extends Object
}
}

void _populateProperties(Expression propertiesValue) {
void _populateProperties(Expression inputsValue) {
_checkMeta();
_populateList(propertiesValue, _properties, 'Directive#properties');
_populateList(inputsValue, _inputs, 'Directive#inputs');
}

void _populateHost(Expression hostValue) {
Expand All @@ -279,9 +279,9 @@ class _DirectiveMetadataVisitor extends Object
_exportAs = _expressionToString(exportAsValue, 'Directive#exportAs');
}

void _populateEvents(Expression eventsValue) {
void _populateEvents(Expression outputsValue) {
_checkMeta();
_populateList(eventsValue, _events, 'Directive#events');
_populateList(outputsValue, _outputs, 'Directive#outputs');
}

void _populateChangeDetection(Expression value) {
Expand Down
Expand Up @@ -15,7 +15,7 @@ class Processor implements CodegenModel {
final Set<ReflectiveAccessor> methodNames = new Set<ReflectiveAccessor>();

void process(CompileDirectiveMetadata meta) {
meta.events.keys.forEach((eventName) {
meta.outputs.keys.forEach((eventName) {
getterNames.add(new ReflectiveAccessor(eventName));
});
}
Expand Down
Expand Up @@ -14,7 +14,7 @@ main() => allTests();
void allTests() {
var reader = new TestAssetReader();

it('should generate a setter for a `properties` property in an annotation.',
it('should generate a setter for an `inputs` property in an annotation.',
() async {
var inputPath = 'bind_generator/basic_bind_files/bar.ng_deps.dart';
var expected = formatter.format(
Expand All @@ -27,7 +27,7 @@ void allTests() {

it(
'should generate a single setter when multiple annotations bind to the '
'same property.', () async {
'same `inputs` property.', () async {
var inputPath =
'bind_generator/duplicate_bind_name_files/soup.ng_deps.dart';
var expected = formatter.format(readFile(
Expand Down
Expand Up @@ -14,8 +14,8 @@ final ngFor = {
"moduleUrl": "asset:angular2/lib/src/core/directives/ng_for.dart"
},
"changeDetection": null,
"properties": {"ngForOf": "ngForOf"},
"events": {},
"inputs": {"ngForOf": "ngForOf"},
"outputs": {},
"hostListeners": {},
"hostProperties": {},
"hostAttributes": {},
Expand Down
Expand Up @@ -13,8 +13,8 @@
"moduleUrl": "asset:angular2/test/transform/directive_metadata_linker/absolute_export_files/bar.dart"
},
"changeDetection": 5,
"properties": {},
"events": {},
"inputs": {},
"outputs": {},
"hostListeners": {},
"hostProperties": {},
"hostAttributes": {},
Expand Down
Expand Up @@ -14,8 +14,8 @@
"moduleUrl": "asset:angular2/test/transform/directive_metadata_linker/absolute_export_files/foo.dart"
},
"changeDetection": 5,
"properties": {},
"events": {},
"inputs": {},
"outputs": {},
"hostListeners": {},
"hostProperties": {},
"hostAttributes": {},
Expand Down
Expand Up @@ -14,8 +14,8 @@
"moduleUrl": "asset:angular2/test/transform/directive_metadata_linker/export_cycle_files/bar.dart"
},
"changeDetection": 5,
"properties": {},
"events": {},
"inputs": {},
"outputs": {},
"hostListeners": {},
"hostProperties": {},
"hostAttributes": {},
Expand Down
Expand Up @@ -14,8 +14,8 @@
"moduleUrl": "asset:angular2/test/transform/directive_metadata_linker/export_cycle_files/baz.dart"
},
"changeDetection": 5,
"properties": {},
"events": {},
"inputs": {},
"outputs": {},
"hostListeners": {},
"hostProperties": {},
"hostAttributes": {},
Expand Down
Expand Up @@ -14,8 +14,8 @@
"moduleUrl": "asset:angular2/test/transform/directive_metadata_linker/export_cycle_files/foo.dart"
},
"changeDetection": 5,
"properties": {},
"events": {},
"inputs": {},
"outputs": {},
"hostListeners": {},
"hostProperties": {},
"hostAttributes": {},
Expand Down
Expand Up @@ -13,8 +13,8 @@
"moduleUrl": "asset:angular2/test/transform/directive_metadata_linker/export_cycle_files/bar.dart"
},
"changeDetection": 5,
"properties": {},
"events": {},
"inputs": {},
"outputs": {},
"hostListeners": {},
"hostProperties": {},
"hostAttributes": {},
Expand Down
Expand Up @@ -14,8 +14,8 @@
"moduleUrl": "asset:angular2/test/transform/directive_metadata_linker/export_cycle_files/foo.dart"
},
"changeDetection": 5,
"properties": {},
"events": {},
"inputs": {},
"outputs": {},
"hostListeners": {},
"hostProperties": {},
"hostAttributes": {},
Expand Down
Expand Up @@ -14,8 +14,8 @@
"moduleUrl": "asset:angular2/test/transform/directive_metadata_linker/recursive_export_files/bar.dart"
},
"changeDetection": 5,
"properties": {},
"events": {},
"inputs": {},
"outputs": {},
"hostListeners": {},
"hostProperties": {},
"hostAttributes": {},
Expand Down
Expand Up @@ -13,8 +13,8 @@
"moduleUrl": "asset:angular2/test/transform/directive_metadata_linker/recursive_export_files/baz.dart"
},
"changeDetection": 5,
"properties": {},
"events": {},
"inputs": {},
"outputs": {},
"hostListeners": {},
"hostProperties": {},
"hostAttributes": {},
Expand Down
Expand Up @@ -14,8 +14,8 @@
"moduleUrl": "asset:angular2/test/transform/directive_metadata_linker/recursive_export_files/foo.dart"
},
"changeDetection": 5,
"properties": {},
"events": {},
"inputs": {},
"outputs": {},
"hostListeners": {},
"hostProperties": {},
"hostAttributes": {},
Expand Down
Expand Up @@ -335,10 +335,10 @@ void allTests() {
expect(component.exportAs).toEqual('ComponentExportAsValue');
expect(component.changeDetection)
.toEqual(ChangeDetectionStrategy.CheckAlways);
expect(component.properties).toContain('aProperty');
expect(component.properties['aProperty']).toEqual('aProperty');
expect(component.events).toContain('anEvent');
expect(component.events['anEvent']).toEqual('anEvent');
expect(component.inputs).toContain('aProperty');
expect(component.inputs['aProperty']).toEqual('aProperty');
expect(component.outputs).toContain('anEvent');
expect(component.outputs['anEvent']).toEqual('anEvent');
expect(component.hostAttributes).toContain('hostKey');
expect(component.hostAttributes['hostKey']).toEqual('hostValue');

Expand All @@ -347,11 +347,11 @@ void allTests() {
expect(directive.selector).toEqual('unusual-directive');
expect(directive.isComponent).toBeFalse();
expect(directive.exportAs).toEqual('DirectiveExportAsValue');
expect(directive.properties).toContain('aDirectiveProperty');
expect(directive.properties['aDirectiveProperty'])
expect(directive.inputs).toContain('aDirectiveProperty');
expect(directive.inputs['aDirectiveProperty'])
.toEqual('aDirectiveProperty');
expect(directive.events).toContain('aDirectiveEvent');
expect(directive.events['aDirectiveEvent']).toEqual('aDirectiveEvent');
expect(directive.outputs).toContain('aDirectiveEvent');
expect(directive.outputs['aDirectiveEvent']).toEqual('aDirectiveEvent');
expect(directive.hostAttributes).toContain('directiveHostKey');
expect(directive.hostAttributes['directiveHostKey'])
.toEqual('directiveHostValue');
Expand Down
Expand Up @@ -7,16 +7,16 @@ import 'package:angular2/angular2.dart'
selector: 'unusual-comp',
exportAs: 'ComponentExportAsValue',
changeDetection: ChangeDetectionStrategy.CheckAlways,
properties: const ['aProperty'],
inputs: const ['aProperty'],
host: const {'hostKey': 'hostValue'},
events: const ['anEvent'])
outputs: const ['anEvent'])
@View(templateUrl: 'template.html')
class UnusualComp {}

@Directive(
selector: 'unusual-directive',
exportAs: 'DirectiveExportAsValue',
properties: const ['aDirectiveProperty'],
inputs: const ['aDirectiveProperty'],
host: const {'directiveHostKey': 'directiveHostValue'},
events: const ['aDirectiveEvent'])
outputs: const ['aDirectiveEvent'])
class UnusualDirective {}
Expand Up @@ -103,7 +103,7 @@ void allTests() {
'two_annotations_files/expected/bar.ng_deps.dart'
}),
new IntegrationTestConfig(
'should generate getters for events defined on a Component.',
'should generate getters for output events defined on a Component.',
inputs: {
'a|web/index.dart': 'event_getter_files/index.dart',
'a|web/bar.dart': 'event_getter_files/bar.dart'
Expand Down
Expand Up @@ -2,7 +2,7 @@ library bar;

import 'package:angular2/src/core/metadata.dart';

@Component(selector: '[soup]', events: ['eventName1', 'eventName2: propName2'])
@Component(selector: '[soup]', outputs: ['eventName1', 'eventName2: propName2'])
@View(template: '')
class MyComponent {
MyComponent();
Expand Down
Expand Up @@ -16,7 +16,7 @@ void initReflector() {
MyComponent,
new _ngRef.ReflectionInfo(const [
const Component(
events: ['eventName1', 'eventName2: propName2'],
outputs: ['eventName1', 'eventName2: propName2'],
selector: '[soup]'),
const View(template: ''),
_templates.HostMyComponentTemplate
Expand Down
Expand Up @@ -13,8 +13,8 @@
"moduleUrl": "asset:template_compiler/lib/directive_aliases_files/hello1.dart"
},
"changeDetection": 5,
"properties": {},
"events": {},
"inputs": {},
"outputs": {},
"hostListeners": {},
"hostProperties": {},
"hostAttributes": {},
Expand Down Expand Up @@ -42,8 +42,8 @@
"moduleUrl": "asset:template_compiler/lib/directive_aliases_files/hello1.dart"
},
"changeDetection": 5,
"properties": {},
"events": {},
"inputs": {},
"outputs": {},
"hostListeners": {},
"hostProperties": {},
"hostAttributes": {},
Expand Down
Expand Up @@ -13,8 +13,8 @@
"moduleUrl": "asset:template_compiler/lib/directive_aliases_files/hello1.dart"
},
"changeDetection": 5,
"properties": {},
"events": {},
"inputs": {},
"outputs": {},
"hostListeners": {},
"hostProperties": {},
"hostAttributes": {},
Expand Down Expand Up @@ -42,8 +42,8 @@
"moduleUrl": "asset:template_compiler/lib/directive_aliases_files/hello1.dart"
},
"changeDetection": 5,
"properties": {},
"events": {},
"inputs": {},
"outputs": {},
"hostListeners": {},
"hostProperties": {},
"hostAttributes": {},
Expand Down
Expand Up @@ -14,7 +14,7 @@ void initReflector(reflector) {
..registerType(
HelloCmp,
new ReflectionInfo(const [
const Component(selector: 'hello-app', events: const ['eventName']),
const Component(selector: 'hello-app', outputs: const ['eventName']),
const View(template: '<button>go</button>'),
_templates.HostHelloCmpTemplate
], const [
Expand Down

0 comments on commit 61ba63c

Please sign in to comment.