Skip to content

Commit

Permalink
Ignore abstract methods when decorating class (#11345)
Browse files Browse the repository at this point in the history
* Ignore abstract methods when decorating class

* Address Nico's feedback

* Add input/output test

* Update test output to account for _nonIterableRest changes
  • Loading branch information
oliverdunk committed Mar 28, 2020
1 parent 6a00cbe commit 71e7a7b
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 1 deletion.
Expand Up @@ -128,7 +128,10 @@ export function buildDecoratedClass(ref, path, elements, file) {

const classDecorators = takeDecorators(node);
const definitions = t.arrayExpression(
elements.map(extractElementDescriptor.bind(file, node.id, superId)),
elements
// Ignore TypeScript's abstract methods (see #10514)
.filter(element => !element.node.abstract)
.map(extractElementDescriptor.bind(file, node.id, superId)),
);

let replacement = template.expression.ast`
Expand Down
@@ -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);
@@ -0,0 +1,26 @@
function decorate(value: boolean) {
return function(
target: any,
propertyKey: string,
descriptor: PropertyDescriptor
) {};
}

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

abstract myMethod(): void;
}

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

myMethod(): void {

}
}

const b = new B();
@@ -0,0 +1,9 @@
{
"presets": [
["typescript"]
],
"plugins": [
["proposal-decorators", { "decoratorsBeforeExport": true }],
["proposal-class-properties"]
]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 71e7a7b

Please sign in to comment.