Skip to content

Commit

Permalink
Set correct methods name
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Nov 2, 2018
1 parent 38397ce commit d35563e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/babel-helpers/src/helpers.js
Expand Up @@ -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 = {
Expand All @@ -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") {
Expand All @@ -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"
Expand Down
@@ -0,0 +1,8 @@
function decorator() {}

@decorator
class Foo {
method() {}
}

expect(Foo.prototype.method.name).toBe("method");
@@ -0,0 +1,12 @@
{
"plugins": [
["proposal-decorators", { "decoratorsBeforeExport": false }],
"proposal-class-properties",
[
"external-helpers",
{
"helperVersion": "7.1.5"
}
]
]
}
@@ -0,0 +1,16 @@
let calls = 0;
const baz = {
[Symbol.toPrimitive]() {
calls++;
return "baz";
}
}

function dec() {}

@dec
class A {
[baz]() {}
}

expect(calls).toBe(1);

0 comments on commit d35563e

Please sign in to comment.