babel-plugin-transform-decorators-legacy icon indicating copy to clipboard operation
babel-plugin-transform-decorators-legacy copied to clipboard

Cannot decorate Symbol expression members

Open jka6502 opened this issue 8 years ago • 1 comments

Using a decorator on a Symbol class member throws:

function C(target, property, descriptor) {
   return descriptor;
}

const B = Symbol();

class A {

   @C
   [B] = null;

}

The following error, in the above case:

                       return decorator(target, property, desc) || desc;
                               ^

TypeError: decorator is not a function

Is this intended to work?

I see in the current decorators spec (2.1.1 - 1. Let propKey be the result of evaluating propertyName), this will work once that reaches implementation, but is there a specific reason not to for the legacy transform (would it break existing modules, was it explicitly disallowed in the original proposal)?

jka6502 avatar Feb 20 '17 19:02 jka6502

Just to clarify, the above example is using transform-class-properties too - but attempting to decorate a Symbol expression 'named' method also errors - though not the same error - in that case, the error appears to be thrown from the babel parser, rather than the plugin.

function B(target, property, descriptor) {}

const C = Symbol();

class A {

	@B
	[C]() {}

}

throws:

SyntaxError: .../file.js: Unexpected token (14:7)
  12 |
  13 |  @B
> 14 |  [C]() {}
  15 |
  16 | }
 at Parser.pp.raise (...node_modules/babylon/lib/parser/location.js:22:13)
 at Parser.pp.unexpected (...node_modules/babylon/lib/parser/util.js:89:8)
 at Parser.pp.parseIdentifier(...node_modules/babylon/lib/parser/expression.js:1053:10)
 at Parser.pp.parsePropertyName (...node_modules/babylon/lib/parser/expression.js:858:117)
...

jka6502 avatar Feb 21 '17 00:02 jka6502