loganfsmyth / babel-plugin-transform-decorators-legacy

A plugin for Babel 6 that (mostly) replicates the old decorator behavior from Babel 5
MIT License
817 stars 57 forks source link

Wrong? target with class functions decorators #42

Closed mcasimir closed 8 years ago

mcasimir commented 8 years ago

For class functions decorators the target argument is not an actual reference to the real class but a reference to an instance, sounds weird to me. Is it correct/intended?

let assert = require('assert');
let fnTarget = null;
let fnTargetConstructor = null;

function fnDec(target, methodName, descriptor) {
  fnTarget = target;
  fnTargetConstructor = target.constructor;
  return descriptor;
}

class A {
  @fnDec
  doSomething() {}
}

assert(fnTarget !== A);
assert(fnTargetConstructor === A);

My package.json:

    "babel-core": "^6.11.4",
    "babel-plugin-transform-decorators-legacy": "1.3.4"

My .babelrc:

{
  "plugins": [
    "transform-decorators-legacy"
  ]
}
loganfsmyth commented 8 years ago

fnTarget === A.prototype :)

mcasimir commented 8 years ago

I see.. now it makes much more sense :). Sorry for the silly report. Thanks!

loganfsmyth commented 8 years ago

No problem. If you had static doSomething(){} it would be what you thought, but then your other one would be wrong.