refactor(dart/transform): Remove unnecessary getter/setter codegen
Currently the transformer generates all getters and setters even when creating pre-generated change detectors, which remove the need for them. Generate getters and setters via the model provided by `ProtoViewDto`, which contains enough information to allow omitting unnecessary getters and setters from code output. Allow generating getters, setters, and method names which are Dart pseudo keywords. Closes #3489
This commit is contained in:
@ -7,6 +7,7 @@ import 'package:angular2/src/transform/common/asset_reader.dart';
|
||||
import 'package:angular2/src/transform/common/logging.dart';
|
||||
import 'package:angular2/src/transform/template_compiler/generator.dart';
|
||||
import 'package:dart_style/dart_style.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:guinness/guinness.dart';
|
||||
|
||||
import '../common/read_file.dart';
|
||||
@ -31,7 +32,7 @@ void changeDetectorTests() {
|
||||
// TODO(tbosch): This is just a temporary test that makes sure that the dart server and
|
||||
// dart browser is in sync. Change this to "not contains notifyBinding"
|
||||
// when https://github.com/angular/angular/issues/3019 is solved.
|
||||
it('shouldn always notifyDispatcher for template variables', () async {
|
||||
it('should not always notifyDispatcher for template variables', () async {
|
||||
var inputPath = 'template_compiler/ng_for_files/hello.ng_deps.dart';
|
||||
var output = await (process(new AssetId('a', inputPath)));
|
||||
expect(output).toContain('notifyDispatcher');
|
||||
@ -90,7 +91,7 @@ void noChangeDetectorTests() {
|
||||
_formatThenExpectEquals(output, expected);
|
||||
});
|
||||
|
||||
it('should not generated duplicate getters/setters', () async {
|
||||
it('should not generate duplicate getters/setters', () async {
|
||||
var inputPath = 'template_compiler/duplicate_files/hello.ng_deps.dart';
|
||||
var expected = readFile(
|
||||
'template_compiler/duplicate_files/expected/hello.ng_deps.dart');
|
||||
@ -144,6 +145,15 @@ void noChangeDetectorTests() {
|
||||
output = await process(new AssetId('a', inputPath));
|
||||
_formatThenExpectEquals(output, expected);
|
||||
});
|
||||
|
||||
it('should generate all expected getters, setters, & methods.', () async {
|
||||
var base = 'template_compiler/registrations_files';
|
||||
var inputPath = path.join(base, 'registrations.ng_deps.dart');
|
||||
var expected =
|
||||
readFile(path.join(base, 'expected/registrations.ng_deps.dart'));
|
||||
var output = await process(new AssetId('a', inputPath));
|
||||
_formatThenExpectEquals(output, expected);
|
||||
});
|
||||
}
|
||||
|
||||
void _formatThenExpectEquals(String actual, String expected) {
|
||||
|
@ -17,6 +17,5 @@ void initReflector(reflector) {
|
||||
], const [
|
||||
const []
|
||||
], () => new HelloCmp()))
|
||||
..registerGetters({'greeting': (o) => o.greeting})
|
||||
..registerSetters({'greeting': (o, v) => o.greeting = v});
|
||||
..registerGetters({'greeting': (o) => o.greeting});
|
||||
}
|
||||
|
@ -18,6 +18,5 @@ void initReflector(reflector) {
|
||||
const []
|
||||
], () => new HelloCmp()))
|
||||
..registerGetters({'b': (o) => o.b, 'greeting': (o) => o.greeting})
|
||||
..registerSetters(
|
||||
{'b': (o, v) => o.b = v, 'greeting': (o, v) => o.greeting = v});
|
||||
..registerSetters({'a': (o, v) => o.a = v});
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ void initReflector(reflector) {
|
||||
HelloCmp,
|
||||
new ReflectionInfo(const [
|
||||
const Component(selector: 'hello-app'),
|
||||
const View(template: '<button (click)=\"action()\">go</button>')
|
||||
const View(template: '<button (click)="action()">go</button>')
|
||||
], const [
|
||||
const []
|
||||
], () => new HelloCmp()))
|
||||
|
@ -13,7 +13,7 @@ void initReflector(reflector) {
|
||||
HelloCmp,
|
||||
new ReflectionInfo(const [
|
||||
const Component(selector: 'hello-app'),
|
||||
const View(template: '<button (click)=\"action()\">go</button>')
|
||||
const View(template: '<button (click)="action()">go</button>')
|
||||
], const [
|
||||
const []
|
||||
], () => new HelloCmp()));
|
||||
|
@ -0,0 +1,98 @@
|
||||
{
|
||||
"DependencyCmp": {
|
||||
"kind": "type",
|
||||
"value": {
|
||||
"id": "DependencyCmp",
|
||||
"selector": "dependency",
|
||||
"compileChildren": true,
|
||||
"hostProperties": {},
|
||||
"hostListeners": {},
|
||||
"hostActions": {},
|
||||
"hostAttributes": {},
|
||||
"properties": null,
|
||||
"readAttributes": null,
|
||||
"type": null,
|
||||
"exportAs": null,
|
||||
"callOnDestroy": null,
|
||||
"callOnCheck": null,
|
||||
"callOnInit": null,
|
||||
"callOnChange": null,
|
||||
"callOnAllChangesDone": null,
|
||||
"events": ["dependencyEventName"],
|
||||
"changeDetection": null,
|
||||
"version": 1
|
||||
}
|
||||
},
|
||||
"DirectiveProps": {
|
||||
"kind": "type",
|
||||
"value": {
|
||||
"id": "DirectiveProps",
|
||||
"selector": "[dir-props]",
|
||||
"compileChildren": true,
|
||||
"hostProperties": {"hprop": "hprop"},
|
||||
"hostListeners": {},
|
||||
"hostActions": {},
|
||||
"hostAttributes": {},
|
||||
"properties": ["prop"],
|
||||
"readAttributes": null,
|
||||
"type": null,
|
||||
"exportAs": null,
|
||||
"callOnDestroy": null,
|
||||
"callOnCheck": null,
|
||||
"callOnInit": null,
|
||||
"callOnChange": null,
|
||||
"callOnAllChangesDone": null,
|
||||
"events": null,
|
||||
"changeDetection": null,
|
||||
"version": 1
|
||||
}
|
||||
},
|
||||
"DirectiveEvents": {
|
||||
"kind": "type",
|
||||
"value": {
|
||||
"id": "DirectiveEvents",
|
||||
"selector": "[dir-events]",
|
||||
"compileChildren": true,
|
||||
"hostProperties": {},
|
||||
"hostListeners": {"subevent": "doAThing()"},
|
||||
"hostActions": {},
|
||||
"hostAttributes": {},
|
||||
"properties": [],
|
||||
"readAttributes": null,
|
||||
"type": null,
|
||||
"exportAs": null,
|
||||
"callOnDestroy": null,
|
||||
"callOnCheck": null,
|
||||
"callOnInit": null,
|
||||
"callOnChange": null,
|
||||
"callOnAllChangesDone": null,
|
||||
"events": null,
|
||||
"changeDetection": null,
|
||||
"version": 1
|
||||
}
|
||||
},
|
||||
"NgFor": {
|
||||
"kind": "type",
|
||||
"value": {
|
||||
"id": "NgFor",
|
||||
"selector": "[ng-for][ng-for-of]",
|
||||
"compileChildren": true,
|
||||
"hostProperties": {},
|
||||
"hostListeners": {},
|
||||
"hostActions": {},
|
||||
"hostAttributes": {},
|
||||
"properties": ["ngForOf"],
|
||||
"readAttributes": null,
|
||||
"type": null,
|
||||
"exportAs": null,
|
||||
"callOnDestroy": null,
|
||||
"callOnCheck": true,
|
||||
"callOnInit": null,
|
||||
"callOnChange": null,
|
||||
"callOnAllChangesDone": null,
|
||||
"events": null,
|
||||
"changeDetection": null,
|
||||
"version": 1
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
library examples.hello_world.index_common_dart.ng_deps.dart;
|
||||
|
||||
import 'dependency.dart';
|
||||
import 'dependency.ng_deps.dart' as i0;
|
||||
import 'hello.dart';
|
||||
import 'package:angular2/angular2.dart'
|
||||
show Component, Directive, View, NgElement;
|
||||
|
||||
var _visited = false;
|
||||
void initReflector(reflector) {
|
||||
if (_visited) return;
|
||||
_visited = true;
|
||||
reflector
|
||||
..registerType(
|
||||
TextBindingsCmp,
|
||||
new ReflectionInfo(const [
|
||||
const Component(selector: 'text'),
|
||||
const View(template: '{{textBindings}}')
|
||||
], const [
|
||||
const []
|
||||
], () => new TextBindingsCmp()))
|
||||
..registerType(
|
||||
PropertyBindingsCmp,
|
||||
new ReflectionInfo(const [
|
||||
const Component(selector: 'props'),
|
||||
const View(template: '<div [prop-name]="propValue"></div>')
|
||||
], const [
|
||||
const []
|
||||
], () => new PropertyBindingsCmp()))
|
||||
..registerType(
|
||||
EventsCmp,
|
||||
new ReflectionInfo(const [
|
||||
const Component(selector: 'events', events: const ['eventName']),
|
||||
const View(template: 'Hi')
|
||||
], const [
|
||||
const []
|
||||
], () => new EventsCmp()))
|
||||
..registerType(
|
||||
SubEventsCmp,
|
||||
new ReflectionInfo(const [
|
||||
const Component(selector: 'sub-events'),
|
||||
const View(
|
||||
template: '<dependency></dependency>',
|
||||
directives: const [DependencyCmp])
|
||||
], const [
|
||||
const []
|
||||
], () => new SubEventsCmp()))
|
||||
..registerType(
|
||||
TemplateEventsCmp,
|
||||
new ReflectionInfo(const [
|
||||
const Component(selector: 'template-events'),
|
||||
const View(template: '<div (mouseover)="onMouseOver()"></div>')
|
||||
], const [
|
||||
const []
|
||||
], () => new TemplateEventsCmp()))
|
||||
..registerType(
|
||||
DirectivePropsCmp,
|
||||
new ReflectionInfo(const [
|
||||
const Component(selector: 'directive-props-cmp'),
|
||||
const View(
|
||||
template: '<div dir-props prop="somevalue">',
|
||||
directives: const [DirectiveProps])
|
||||
], const [
|
||||
const []
|
||||
], () => new DirectivePropsCmp()))
|
||||
..registerType(
|
||||
DirectiveEventsCmp,
|
||||
new ReflectionInfo(const [
|
||||
const Component(selector: 'directive-events-cmp'),
|
||||
const View(
|
||||
template: '<div dir-events (subevent)="field = 10;">',
|
||||
directives: const [DirectiveEvents])
|
||||
], const [
|
||||
const []
|
||||
], () => new DirectiveEventsCmp()))
|
||||
..registerType(
|
||||
RecursiveCmp,
|
||||
new ReflectionInfo(const [
|
||||
const Component(selector: 'recursive-cmp'),
|
||||
const View(
|
||||
template:
|
||||
'<li *ng-for="#thing of things" [recursive-prop]="thing"><div>test</div></li>',
|
||||
directives: const [NgFor])
|
||||
], const [
|
||||
const []
|
||||
], () => new RecursiveCmp()))
|
||||
..registerGetters({
|
||||
'eventName': (o) => o.eventName,
|
||||
'hprop': (o) => o.hprop,
|
||||
'propValue': (o) => o.propValue,
|
||||
'textBindings': (o) => o.textBindings,
|
||||
'thing': (o) => o.thing,
|
||||
'things': (o) => o.things
|
||||
})
|
||||
..registerSetters({
|
||||
'field': (o, v) => o.field = v,
|
||||
'hprop': (o, v) => o.hprop = v,
|
||||
'ngForOf': (o, v) => o.ngForOf = v,
|
||||
'prop': (o, v) => o.prop = v,
|
||||
'propName': (o, v) => o.propName = v,
|
||||
'recursiveProp': (o, v) => o.recursiveProp = v
|
||||
})
|
||||
..registerMethods({
|
||||
'doAThing': (o, List args) => Function.apply(o.doAThing, args),
|
||||
'onMouseOver': (o, List args) => Function.apply(o.onMouseOver, args)
|
||||
});
|
||||
i0.initReflector();
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
library examples.hello_world.index_common_dart.ng_deps.dart;
|
||||
|
||||
import 'dependency.dart';
|
||||
import 'dependency.ng_deps.dart' as i0;
|
||||
import 'hello.dart';
|
||||
import 'package:angular2/angular2.dart'
|
||||
show Component, Directive, View, NgElement;
|
||||
|
||||
var _visited = false;
|
||||
void initReflector(reflector) {
|
||||
if (_visited) return;
|
||||
_visited = true;
|
||||
reflector
|
||||
..registerType(
|
||||
TextBindingsCmp,
|
||||
new ReflectionInfo(const [
|
||||
const Component(selector: 'text'),
|
||||
const View(template: '{{textBindings}}')
|
||||
], const [
|
||||
const []
|
||||
], () => new TextBindingsCmp()))
|
||||
..registerType(
|
||||
PropertyBindingsCmp,
|
||||
new ReflectionInfo(const [
|
||||
const Component(selector: 'props'),
|
||||
const View(template: '<div [prop-name]="propValue"></div>')
|
||||
], const [
|
||||
const []
|
||||
], () => new PropertyBindingsCmp()))
|
||||
..registerType(
|
||||
EventsCmp,
|
||||
new ReflectionInfo(const [
|
||||
const Component(selector: 'events', events: const ['eventName']),
|
||||
const View(template: 'Hi')
|
||||
], const [
|
||||
const []
|
||||
], () => new EventsCmp()))
|
||||
..registerType(
|
||||
SubEventsCmp,
|
||||
new ReflectionInfo(const [
|
||||
const Component(selector: 'sub-events'),
|
||||
const View(
|
||||
template: '<dependency></dependency>',
|
||||
directives: const [DependencyCmp])
|
||||
], const [
|
||||
const []
|
||||
], () => new SubEventsCmp()))
|
||||
..registerType(
|
||||
TemplateEventsCmp,
|
||||
new ReflectionInfo(const [
|
||||
const Component(selector: 'template-events'),
|
||||
const View(template: '<div (mouseover)="onMouseOver()"></div>')
|
||||
], const [
|
||||
const []
|
||||
], () => new TemplateEventsCmp()))
|
||||
..registerType(
|
||||
DirectivePropsCmp,
|
||||
new ReflectionInfo(const [
|
||||
const Component(selector: 'directive-props-cmp'),
|
||||
const View(
|
||||
template: '<div dir-props prop="somevalue">',
|
||||
directives: const [DirectiveProps])
|
||||
], const [
|
||||
const []
|
||||
], () => new DirectivePropsCmp()))
|
||||
..registerType(
|
||||
DirectiveEventsCmp,
|
||||
new ReflectionInfo(const [
|
||||
const Component(selector: 'directive-events-cmp'),
|
||||
const View(
|
||||
template: '<div dir-events (subevent)="field = 10;">',
|
||||
directives: const [DirectiveEvents])
|
||||
], const [
|
||||
const []
|
||||
], () => new DirectiveEventsCmp()))
|
||||
..registerType(
|
||||
RecursiveCmp,
|
||||
new ReflectionInfo(const [
|
||||
const Component(selector: 'recursive-cmp'),
|
||||
const View(
|
||||
template:
|
||||
'<li *ng-for="#thing of things" [recursive-prop]="thing"><div>test</div></li>',
|
||||
directives: const [NgFor])
|
||||
], const [
|
||||
const []
|
||||
], () => new RecursiveCmp()));
|
||||
i0.initReflector();
|
||||
}
|
@ -0,0 +1,194 @@
|
||||
{
|
||||
"TextBindingsCmp": {
|
||||
"kind": "type",
|
||||
"value": {
|
||||
"id": "TextBindingsCmp",
|
||||
"selector": "text",
|
||||
"compileChildren": true,
|
||||
"hostProperties": {},
|
||||
"hostListeners": {},
|
||||
"hostActions": {},
|
||||
"hostAttributes": {},
|
||||
"properties": null,
|
||||
"readAttributes": null,
|
||||
"type": null,
|
||||
"exportAs": null,
|
||||
"callOnDestroy": null,
|
||||
"callOnCheck": null,
|
||||
"callOnInit": null,
|
||||
"callOnChange": null,
|
||||
"callOnAllChangesDone": null,
|
||||
"events": null,
|
||||
"changeDetection": null,
|
||||
"version": 1
|
||||
}
|
||||
},
|
||||
"PropertyBindingsCmp": {
|
||||
"kind": "type",
|
||||
"value": {
|
||||
"id": "PropertyBindingsCmp",
|
||||
"selector": "props",
|
||||
"compileChildren": true,
|
||||
"hostProperties": {},
|
||||
"hostListeners": {},
|
||||
"hostActions": {},
|
||||
"hostAttributes": {},
|
||||
"properties": [],
|
||||
"readAttributes": [],
|
||||
"type": 0,
|
||||
"exportAs": null,
|
||||
"callOnDestroy": false,
|
||||
"callOnCheck": false,
|
||||
"callOnInit": false,
|
||||
"callOnChange": false,
|
||||
"callOnAllChangesDone": false,
|
||||
"events": [],
|
||||
"changeDetection": null,
|
||||
"version": 1
|
||||
}
|
||||
},
|
||||
"EventsCmp": {
|
||||
"kind": "type",
|
||||
"value": {
|
||||
"id": "EventsCmp",
|
||||
"selector": "events",
|
||||
"compileChildren": true,
|
||||
"hostProperties": {},
|
||||
"hostListeners": {},
|
||||
"hostActions": {},
|
||||
"hostAttributes": {},
|
||||
"properties": [],
|
||||
"readAttributes": [],
|
||||
"type": 1,
|
||||
"exportAs": null,
|
||||
"callOnDestroy": false,
|
||||
"callOnCheck": false,
|
||||
"callOnInit": false,
|
||||
"callOnChange": false,
|
||||
"callOnAllChangesDone": false,
|
||||
"events": ["eventName"],
|
||||
"changeDetection": null,
|
||||
"version": 1
|
||||
}
|
||||
},
|
||||
"SubEventsCmp": {
|
||||
"kind": "type",
|
||||
"value": {
|
||||
"id": "SubEventsCmp",
|
||||
"selector": "events",
|
||||
"compileChildren": true,
|
||||
"hostProperties": {},
|
||||
"hostListeners": {},
|
||||
"hostActions": {},
|
||||
"hostAttributes": {},
|
||||
"properties": [],
|
||||
"readAttributes": [],
|
||||
"type": 1,
|
||||
"exportAs": null,
|
||||
"callOnDestroy": false,
|
||||
"callOnCheck": false,
|
||||
"callOnInit": false,
|
||||
"callOnChange": false,
|
||||
"callOnAllChangesDone": false,
|
||||
"events": [],
|
||||
"changeDetection": null,
|
||||
"version": 1
|
||||
}
|
||||
},
|
||||
"TemplateEventsCmp": {
|
||||
"kind": "type",
|
||||
"value": {
|
||||
"id": "TemplateEventsCmp",
|
||||
"selector": "template-events",
|
||||
"compileChildren": true,
|
||||
"hostProperties": {},
|
||||
"hostListeners": {},
|
||||
"hostActions": {},
|
||||
"hostAttributes": {},
|
||||
"properties": [],
|
||||
"readAttributes": [],
|
||||
"type": 1,
|
||||
"exportAs": null,
|
||||
"callOnDestroy": false,
|
||||
"callOnCheck": false,
|
||||
"callOnInit": false,
|
||||
"callOnChange": false,
|
||||
"callOnAllChangesDone": false,
|
||||
"events": [],
|
||||
"changeDetection": null,
|
||||
"version": 1
|
||||
}
|
||||
},
|
||||
"DirectivePropsCmp": {
|
||||
"kind": "type",
|
||||
"value": {
|
||||
"id": "DirectivePropsCmp",
|
||||
"selector": "directive-props-cmp",
|
||||
"compileChildren": true,
|
||||
"hostProperties": {},
|
||||
"hostListeners": {},
|
||||
"hostActions": {},
|
||||
"hostAttributes": {},
|
||||
"properties": [],
|
||||
"readAttributes": [],
|
||||
"type": 1,
|
||||
"exportAs": null,
|
||||
"callOnDestroy": false,
|
||||
"callOnCheck": false,
|
||||
"callOnInit": false,
|
||||
"callOnChange": false,
|
||||
"callOnAllChangesDone": false,
|
||||
"events": [],
|
||||
"changeDetection": null,
|
||||
"version": 1
|
||||
}
|
||||
},
|
||||
"DirectiveEventsCmp": {
|
||||
"kind": "type",
|
||||
"value": {
|
||||
"id": "DirectiveEventsCmp",
|
||||
"selector": "directive-events-cmp",
|
||||
"compileChildren": true,
|
||||
"hostProperties": {},
|
||||
"hostListeners": {},
|
||||
"hostActions": {},
|
||||
"hostAttributes": {},
|
||||
"properties": [],
|
||||
"readAttributes": [],
|
||||
"type": 1,
|
||||
"exportAs": null,
|
||||
"callOnDestroy": false,
|
||||
"callOnCheck": false,
|
||||
"callOnInit": false,
|
||||
"callOnChange": false,
|
||||
"callOnAllChangesDone": false,
|
||||
"events": [],
|
||||
"changeDetection": null,
|
||||
"version": 1
|
||||
}
|
||||
},
|
||||
"RecursiveCmp": {
|
||||
"kind": "type",
|
||||
"value": {
|
||||
"id": "RecursiveCmp",
|
||||
"selector": "recursive-cmp",
|
||||
"compileChildren": true,
|
||||
"hostProperties": {},
|
||||
"hostListeners": {},
|
||||
"hostActions": {},
|
||||
"hostAttributes": {},
|
||||
"properties": [],
|
||||
"readAttributes": [],
|
||||
"type": 1,
|
||||
"exportAs": null,
|
||||
"callOnDestroy": false,
|
||||
"callOnCheck": false,
|
||||
"callOnInit": false,
|
||||
"callOnChange": false,
|
||||
"callOnAllChangesDone": false,
|
||||
"events": [],
|
||||
"changeDetection": null,
|
||||
"version": 1
|
||||
}
|
||||
}
|
||||
}
|
@ -17,6 +17,5 @@ void initReflector(reflector) {
|
||||
], const [
|
||||
const []
|
||||
], () => new HelloCmp()))
|
||||
..registerGetters({'greeting': (o) => o.greeting})
|
||||
..registerSetters({'greeting': (o, v) => o.greeting = v});
|
||||
..registerGetters({'greeting': (o) => o.greeting});
|
||||
}
|
||||
|
@ -17,6 +17,5 @@ void initReflector(reflector) {
|
||||
], const [
|
||||
const []
|
||||
], () => new GoodbyeCmp()))
|
||||
..registerGetters({'name': (o) => o.name})
|
||||
..registerSetters({'name': (o, v) => o.name = v});
|
||||
..registerGetters({'name': (o) => o.name});
|
||||
}
|
||||
|
@ -17,6 +17,5 @@ void initReflector(reflector) {
|
||||
], const [
|
||||
const []
|
||||
], () => new MyApp()))
|
||||
..registerGetters({'name': (o) => o.name})
|
||||
..registerSetters({'name': (o, v) => o.name = v});
|
||||
..registerGetters({'name': (o) => o.name});
|
||||
}
|
||||
|
Reference in New Issue
Block a user