Set correct methods name

This commit is contained in:
Nicolò Ribaudo 2018-09-24 14:58:57 +02:00
parent 38397ce11f
commit d35563ee1a
4 changed files with 43 additions and 1 deletions

View File

@ -1236,6 +1236,8 @@ helpers.decorate = helper("7.1.5")`
function _createElementDescriptor(
def /*: ElementDefinition */,
) /*: ElementDescriptor */ {
var key = toPropertyKey(def.key);
var descriptor /*: PropertyDescriptor */;
if (def.kind === "method") {
descriptor = {
@ -1244,6 +1246,10 @@ helpers.decorate = helper("7.1.5")`
configurable: true,
enumerable: false,
};
Object.defineProperty(def.value, "name", {
value: typeof key === "symbol" ? "" : key,
configurable: true,
});
} else if (def.kind === "get") {
descriptor = { get: def.value, configurable: true, enumerable: false };
} else if (def.kind === "set") {
@ -1254,7 +1260,7 @@ helpers.decorate = helper("7.1.5")`
var element /*: ElementDescriptor */ = {
kind: def.kind === "field" ? "field" : "method",
key: def.key,
key: key,
placement: def.static
? "static"
: def.kind === "field"

View File

@ -0,0 +1,8 @@
function decorator() {}
@decorator
class Foo {
method() {}
}
expect(Foo.prototype.method.name).toBe("method");

View File

@ -0,0 +1,12 @@
{
"plugins": [
["proposal-decorators", { "decoratorsBeforeExport": false }],
"proposal-class-properties",
[
"external-helpers",
{
"helperVersion": "7.1.5"
}
]
]
}

View File

@ -0,0 +1,16 @@
let calls = 0;
const baz = {
[Symbol.toPrimitive]() {
calls++;
return "baz";
}
}
function dec() {}
@dec
class A {
[baz]() {}
}
expect(calls).toBe(1);