fix(static_reflector): report methods with decorators in `propMetadata` as well
This was the behavior of our regular reflector as well, although the method name does not imply this. Fixes #10308 Closes #10318
This commit is contained in:
parent
58d9e7fc5a
commit
367f0fd142
|
@ -94,7 +94,8 @@ export class StaticReflector implements ReflectorReader {
|
||||||
let classMetadata = this.getTypeMetadata(type);
|
let classMetadata = this.getTypeMetadata(type);
|
||||||
let members = classMetadata ? classMetadata['members'] : {};
|
let members = classMetadata ? classMetadata['members'] : {};
|
||||||
propMetadata = mapStringMap(members, (propData, propName) => {
|
propMetadata = mapStringMap(members, (propData, propName) => {
|
||||||
let prop = (<any[]>propData).find(a => a['__symbolic'] == 'property');
|
let prop = (<any[]>propData)
|
||||||
|
.find(a => a['__symbolic'] == 'property' || a['__symbolic'] == 'method');
|
||||||
if (prop && prop['decorators']) {
|
if (prop && prop['decorators']) {
|
||||||
return this.simplify(type, prop['decorators']);
|
return this.simplify(type, prop['decorators']);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {StaticReflector, StaticReflectorHost, StaticSymbol} from '@angular/compiler-cli/src/static_reflector';
|
import {StaticReflector, StaticReflectorHost, StaticSymbol} from '@angular/compiler-cli/src/static_reflector';
|
||||||
import {animate, group, keyframes, sequence, state, style, transition, trigger} from '@angular/core';
|
import {HostListenerMetadata, animate, group, keyframes, sequence, state, style, transition, trigger} from '@angular/core';
|
||||||
import {beforeEach, ddescribe, describe, expect, iit, it} from '@angular/core/testing/testing_internal';
|
import {beforeEach, ddescribe, describe, expect, iit, it} from '@angular/core/testing/testing_internal';
|
||||||
import {ListWrapper} from '@angular/facade/src/collection';
|
import {ListWrapper} from '@angular/facade/src/collection';
|
||||||
import {isBlank} from '@angular/facade/src/lang';
|
import {isBlank} from '@angular/facade/src/lang';
|
||||||
|
@ -15,6 +15,7 @@ import {MetadataCollector} from '@angular/tsc-wrapped';
|
||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// This matches .ts files but not .d.ts files.
|
// This matches .ts files but not .d.ts files.
|
||||||
const TS_EXT = /(^.|(?!\.d)..)\.ts$/;
|
const TS_EXT = /(^.|(?!\.d)..)\.ts$/;
|
||||||
|
|
||||||
|
@ -94,6 +95,7 @@ describe('StaticReflector', () => {
|
||||||
host.findDeclaration('src/app/hero-detail.component', 'HeroDetailComponent');
|
host.findDeclaration('src/app/hero-detail.component', 'HeroDetailComponent');
|
||||||
let props = reflector.propMetadata(HeroDetailComponent);
|
let props = reflector.propMetadata(HeroDetailComponent);
|
||||||
expect(props['hero']).toBeTruthy();
|
expect(props['hero']).toBeTruthy();
|
||||||
|
expect(props['onMouseOver']).toEqual([new HostListenerMetadata('mouseover', ['$event'])]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get an empty object from propMetadata for an unknown class', () => {
|
it('should get an empty object from propMetadata for an unknown class', () => {
|
||||||
|
@ -684,7 +686,28 @@ class MockReflectorHost implements StaticReflectorHost {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
'onMouseOver': [
|
||||||
|
{
|
||||||
|
'__symbolic': 'method',
|
||||||
|
'decorators': [
|
||||||
|
{
|
||||||
|
'__symbolic': 'call',
|
||||||
|
'expression': {
|
||||||
|
'__symbolic': 'reference',
|
||||||
|
'module': 'angular2/src/core/metadata',
|
||||||
|
'name': 'HostListener'
|
||||||
|
},
|
||||||
|
'arguments': [
|
||||||
|
'mouseover',
|
||||||
|
[
|
||||||
|
'$event'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,9 @@ class ClassWithDecorators {
|
||||||
@PropDecorator('p3')
|
@PropDecorator('p3')
|
||||||
set c(value: any /** TODO #9100 */) {}
|
set c(value: any /** TODO #9100 */) {}
|
||||||
|
|
||||||
|
@PropDecorator('p4')
|
||||||
|
someMethod() {}
|
||||||
|
|
||||||
constructor(@ParamDecorator('a') a: AType, @ParamDecorator('b') b: AType) {
|
constructor(@ParamDecorator('a') a: AType, @ParamDecorator('b') b: AType) {
|
||||||
this.a = a;
|
this.a = a;
|
||||||
this.b = b;
|
this.b = b;
|
||||||
|
@ -178,6 +181,7 @@ export function main() {
|
||||||
var p = reflector.propMetadata(ClassWithDecorators);
|
var p = reflector.propMetadata(ClassWithDecorators);
|
||||||
expect(p['a']).toEqual([propDecorator('p1'), propDecorator('p2')]);
|
expect(p['a']).toEqual([propDecorator('p1'), propDecorator('p2')]);
|
||||||
expect(p['c']).toEqual([propDecorator('p3')]);
|
expect(p['c']).toEqual([propDecorator('p3')]);
|
||||||
|
expect(p['someMethod']).toEqual([propDecorator('p4')]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return registered meta if available', () => {
|
it('should return registered meta if available', () => {
|
||||||
|
|
Loading…
Reference in New Issue