Skip to content

Commit

Permalink
Ignore abstract methods when decorating class
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverdunk committed Mar 27, 2020
1 parent 779f00b commit 16cf27a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ export function buildDecoratedClass(ref, path, elements, file) {

const classDecorators = takeDecorators(node);
const definitions = t.arrayExpression(
elements.map(extractElementDescriptor.bind(file, node.id, superId)),
elements
.filter(element => !element.node.abstract)
.map(extractElementDescriptor.bind(file, node.id, superId)),
);

let replacement = template.expression.ast`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function decorate(value: boolean) {
return function(
target: any,
propertyKey: string,
descriptor: PropertyDescriptor
) {};
}

abstract class A {
@decorate(false)
private decoratedMember: boolean;

abstract myMethod(): number;
}

class B extends A {
constructor() {
super();
}

myMethod(): number {
return 5;
}
}

const b = new B();
expect(b.myMethod()).toBe(5);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"presets": [
["typescript"]
],
"plugins": [
["proposal-decorators", { "decoratorsBeforeExport": true }],
["proposal-class-properties"]
]
}

0 comments on commit 16cf27a

Please sign in to comment.