Skip to content

Commit

Permalink
feat: support native classes
Browse files Browse the repository at this point in the history
  • Loading branch information
draconisNoctis committed Mar 5, 2019
1 parent 2426156 commit 83c124f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/reflection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ describe('Reflection', () => {

describe('getAllClassMethods', () => {
it('should return all class methods', () => {
expect(Reflection.getAllClassMethods(A)).to.be.eql([ 'methodA' ]);
expect(Reflection.getAllClassMethods(B)).to.be.eql([ 'methodB', 'methodA' ]);
expect(Reflection.getAllClassMethods(A)).to.be.eql([ 'methodA', 'toString', 'valueOf' ]);
expect(Reflection.getAllClassMethods(B)).to.be.eql([ 'methodB', 'methodA', 'toString', 'valueOf' ]);
});
});

Expand Down
14 changes: 13 additions & 1 deletion src/reflection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { Type } from '@angular/core';
import { unique } from './utils';

export const REFLECTION_PROPERTY_BLACKLIST = new Set([
'__defineGetter__',
'__defineSetter__',
'hasOwnProperty',
'__lookupGetter__',
'__lookupSetter__',
'isPrototypeOf',
'propertyIsEnumerable',
'__proto__',
'toLocaleString'
]);

/**
* @hidden
*/
Expand All @@ -20,7 +32,7 @@ export class Reflection {
static getOwnClassMethods(cls : Type<any>) : string[] {
const methods : string[] = [];

for(const method of Object.keys(cls.prototype)) {
for(const method of Object.keys(Object.getOwnPropertyDescriptors(cls.prototype)).filter(key => !REFLECTION_PROPERTY_BLACKLIST.has(key))) {
if('constructor' === method) continue;
methods.push(method);
}
Expand Down

0 comments on commit 83c124f

Please sign in to comment.