Ignore abstract methods when decorating class (#11345)
* Ignore abstract methods when decorating class * Address Nico's feedback * Add input/output test * Update test output to account for _nonIterableRest changes
This commit is contained in:
parent
6a00cbe0ab
commit
71e7a7b1e0
@ -128,7 +128,10 @@ export function buildDecoratedClass(ref, path, elements, file) {
|
|||||||
|
|
||||||
const classDecorators = takeDecorators(node);
|
const classDecorators = takeDecorators(node);
|
||||||
const definitions = t.arrayExpression(
|
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`
|
let replacement = template.expression.ast`
|
||||||
|
|||||||
@ -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"]
|
||||||
|
]
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user