From 367f0fd1426b9623bf594c0f7f77a57b473c56a5 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Wed, 27 Jul 2016 02:05:07 -0700 Subject: [PATCH] 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 --- .../compiler-cli/src/static_reflector.ts | 3 ++- .../test/static_reflector_spec.ts | 27 +++++++++++++++++-- .../core/test/reflection/reflector_spec.ts | 4 +++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/modules/@angular/compiler-cli/src/static_reflector.ts b/modules/@angular/compiler-cli/src/static_reflector.ts index 3f6163e06d..c338e6fe44 100644 --- a/modules/@angular/compiler-cli/src/static_reflector.ts +++ b/modules/@angular/compiler-cli/src/static_reflector.ts @@ -94,7 +94,8 @@ export class StaticReflector implements ReflectorReader { let classMetadata = this.getTypeMetadata(type); let members = classMetadata ? classMetadata['members'] : {}; propMetadata = mapStringMap(members, (propData, propName) => { - let prop = (propData).find(a => a['__symbolic'] == 'property'); + let prop = (propData) + .find(a => a['__symbolic'] == 'property' || a['__symbolic'] == 'method'); if (prop && prop['decorators']) { return this.simplify(type, prop['decorators']); } else { diff --git a/modules/@angular/compiler-cli/test/static_reflector_spec.ts b/modules/@angular/compiler-cli/test/static_reflector_spec.ts index 7423647405..3d1985c85d 100644 --- a/modules/@angular/compiler-cli/test/static_reflector_spec.ts +++ b/modules/@angular/compiler-cli/test/static_reflector_spec.ts @@ -7,7 +7,7 @@ */ 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 {ListWrapper} from '@angular/facade/src/collection'; import {isBlank} from '@angular/facade/src/lang'; @@ -15,6 +15,7 @@ import {MetadataCollector} from '@angular/tsc-wrapped'; import * as ts from 'typescript'; + // This matches .ts files but not .d.ts files. const TS_EXT = /(^.|(?!\.d)..)\.ts$/; @@ -94,6 +95,7 @@ describe('StaticReflector', () => { host.findDeclaration('src/app/hero-detail.component', 'HeroDetailComponent'); let props = reflector.propMetadata(HeroDetailComponent); expect(props['hero']).toBeTruthy(); + expect(props['onMouseOver']).toEqual([new HostListenerMetadata('mouseover', ['$event'])]); }); 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' + ] + ] + } + ] + } + ] } } } diff --git a/modules/@angular/core/test/reflection/reflector_spec.ts b/modules/@angular/core/test/reflection/reflector_spec.ts index 5fe65baefe..e9179f65ed 100644 --- a/modules/@angular/core/test/reflection/reflector_spec.ts +++ b/modules/@angular/core/test/reflection/reflector_spec.ts @@ -28,6 +28,9 @@ class ClassWithDecorators { @PropDecorator('p3') set c(value: any /** TODO #9100 */) {} + @PropDecorator('p4') + someMethod() {} + constructor(@ParamDecorator('a') a: AType, @ParamDecorator('b') b: AType) { this.a = a; this.b = b; @@ -178,6 +181,7 @@ export function main() { var p = reflector.propMetadata(ClassWithDecorators); expect(p['a']).toEqual([propDecorator('p1'), propDecorator('p2')]); expect(p['c']).toEqual([propDecorator('p3')]); + expect(p['someMethod']).toEqual([propDecorator('p4')]); }); it('should return registered meta if available', () => {