javascript-decorators
javascript-decorators copied to clipboard
The use of comma seems inconsistent between use cases
These cases are tested with babel
For a class decorator, it MUST NOT ends with a comma:
@foo
class Foo {}
// This is NOT OK
@foo;
class Foo {}
For a class method / property decorator, it CAN ends with a comma:
// Both are OK
class Foo {
@foo
foo() {}
@foo;
bar() {}
@foo
tom = 0;
@foo;
jack = 1;
}
For an object method decorator, it MUST NOT ends with a comma:
var bar = {
@foo
foo() {}
// This is NOT OK
@foo;
bar() {}
}
Why don't we allow comma in all cases so the syntax could be consistent, I think ending with a comma is more safe
No worries but ;
is a semicolon, ,
is a comma
This is likely a deliberate decision. Semicolon terminators imply a statement list and the execution of decorators is different in that it's more analogous to function calls.
It's just weird to have different syntax between class method and plain object method, for classes we could add a semicolon after decorator to eliminate syntax conflicts like class Foo { @foo['foo' + 'bar']() { ... } }
, however this could also happen in object methods which doesn't allow semicolons after decorator
Close, invalid? Weird stuff here, definitely.
For clarification, it might be that the babel parser just ignores the extra semicolon and will apply the decorator just the same. So this might be an issue with babel rather?