Open sirisian opened 3 years ago
Investigate alternative syntax in the decorator proposal.
Using overloading:
function test(value, context) {
}
function test(a:string) {
return (value, context) => {
}
}
class A {
@test
@test('test')
a
}
I've never been convinced that decorators should be syntactically differently when they're called. Utilizing function overloading we can rewrite the proposal to just use:
function test(value, context) {
}
function test(a:string, value, context) {
}
class A {
@test
@test('test')
a
}
This makes it must simpler to overload based on the member type.
function test(a:string, value:uint32, context) {
console.log('attribute on uint32');
}
function test(a:string, value, context) {
console.log('attribute on another type. If this isn't allowed by a library we could complain here');
}
class A {
@test('test')
a:uint32
@test('test')
b:string
}
Include examples for every possible decorator. From the decorator proposal: https://github.com/tc39/proposal-decorators
Do I need kind
at all if each decorator context has a type that is a global object?
ClassDecorator
ClassFieldDecorator
ClassGetterDecorator
ClassSetterDecorator
ClassMethodDecorator
In the extensions: https://github.com/tc39/proposal-decorators/blob/master/EXTENSIONS.md
FunctionDecorator
ParameterDecorator
LetDecorator
ConstDecorator
ObjectDecorator
ObjectPropertyDecorator or is it Field?
BlockDecorator
InitializerDecorator
The additional decorators with types are:
ReturnDecorator
function f():@f Example {}
Operator decorators
class A {
@f
operator+(rhs) {
}
}
EnumDecorator
// TODO
TupleDecorator and RecordDecorator
// TODO
Should be able to create a compact example with all of these. I've written some here also: https://github.com/sirisian/ecmascript-types/issues/65
WIP:
@f
class A {
@f
a:uint32 @f = 5
@f
#b:uint32 @f = 5
@f
get c():@f uint32 {
}
@f
set c(@f value:uint32) {
}
@f
d(@f a:uint32):@f uint32 {
}
@f
operator+(@f rhs):@f uint32 {
}
}
@f
let a @f = 5;
@f
let b @f = 5;
const c @f = @f {
@f
a: 1
};
Investigate syntax and convert a few use cases to using types. I don't foresee any issues.
I do remember thinking function overloading or something akin to template specialization from C++ could simplify their implementation. I need to think about that more. Something about having all the if (kind == '...') checks being replaced by function overloading.