Skip to content

Commit

Permalink
Disable support for anything other than class and method
Browse files Browse the repository at this point in the history
For now, getters, setters, fields and accessors are not going to be supported.
  • Loading branch information
aedart committed May 6, 2023
1 parent 7b35e39 commit 65843e7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/support/src/reflections/reflect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ const registry: WeakMap<object, [ Key, WeakRef<object> ]> = new WeakMap<object,
export function reflect()
{
return meta((target: object, context: Context, owner: object) => {

// TODO: Disable support for context.kind that is not a "class" or a "method"...

// For now, only classes and methods are supported... A future version could perhaps extend the functionality
// to offer support for getters, setters, ...etc.
if (!['class', 'method'].includes(context.kind)) {
throw new TypeError(`@reflect() does not support "${context.kind}" (only "class" and "method" are supported)`);
}

// Create a key for given target
const key: Key = [ META_REFLECTIONS, context.kind, context.name ?? 'undefined'];
Expand Down
24 changes: 24 additions & 0 deletions tests/browser/packages/support/reflections/misc-reflection.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { reflect } from "@aedart/support/reflections";

describe('@aedart/support/reflections', () => {

describe('misc', () => {

it('fails when attempting to reflect unsupported class elements', () => {

const callback = function() {

class A {
@reflect()
foo = 'bar';
}

return new A();
}

expect(callback)
.withContext('Should not support reflect on unsupported class element')
.toThrowError(TypeError);
});
});
});

0 comments on commit 65843e7

Please sign in to comment.