babel-plugin-transform-decorators-legacy
babel-plugin-transform-decorators-legacy copied to clipboard
Cannot decorate Symbol expression members
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)?
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)
...