| 1 |
function dec(_v, context) { |
| 2 |
return function (v) { |
| 3 |
this[context.name + 'Context'] = context; |
| 4 |
return (v || 1) + 1; |
| 5 |
} |
| 6 |
} |
| 7 |
|
| 8 |
class Foo { |
| 9 |
@dec |
| 10 |
static a; |
| 11 |
|
| 12 |
@dec |
| 13 |
static b = 123; |
| 14 |
|
| 15 |
@dec |
| 16 |
static ['c'] = 456; |
| 17 |
} |
| 18 |
|
| 19 |
const aContext = Foo['aContext']; |
| 20 |
const bContext = Foo['bContext']; |
| 21 |
const cContext = Foo['cContext']; |
| 22 |
|
| 23 |
expect(Foo.a).toBe(2); |
| 24 |
Foo.a = 123; |
| 25 |
expect(Foo.a).toBe(123); |
| 26 |
expect(aContext.name).toBe('a'); |
| 27 |
expect(aContext.kind).toBe('field'); |
| 28 |
expect(aContext.isStatic).toBe(true); |
| 29 |
expect(aContext.isPrivate).toBe(false); |
| 30 |
expect(typeof aContext.addInitializer).toBe('undefined'); |
| 31 |
expect(typeof aContext.setMetadata).toBe('function'); |
| 32 |
expect(typeof aContext.getMetadata).toBe('function'); |
| 33 |
expect(Foo.hasOwnProperty('a')).toBe(true); |
| 34 |
|
| 35 |
expect(Foo.b).toBe(124); |
| 36 |
Foo.b = 123; |
| 37 |
expect(Foo.b).toBe(123); |
| 38 |
expect(bContext.name).toBe('b'); |
| 39 |
expect(bContext.kind).toBe('field'); |
| 40 |
expect(bContext.isStatic).toBe(true); |
| 41 |
expect(bContext.isPrivate).toBe(false); |
| 42 |
expect(typeof bContext.addInitializer).toBe('undefined'); |
| 43 |
expect(typeof bContext.setMetadata).toBe('function'); |
| 44 |
expect(typeof bContext.getMetadata).toBe('function'); |
| 45 |
expect(Foo.hasOwnProperty('b')).toBe(true); |
| 46 |
|
| 47 |
expect(Foo.c).toBe(457); |
| 48 |
Foo.c = 456; |
| 49 |
expect(Foo.c).toBe(456); |
| 50 |
expect(cContext.name).toBe('c'); |
| 51 |
expect(cContext.kind).toBe('field'); |
| 52 |
expect(cContext.isStatic).toBe(true); |
| 53 |
expect(cContext.isPrivate).toBe(false); |
| 54 |
expect(typeof cContext.addInitializer).toBe('undefined'); |
| 55 |
expect(typeof cContext.setMetadata).toBe('function'); |
| 56 |
expect(typeof cContext.getMetadata).toBe('function'); |
| 57 |
expect(Foo.hasOwnProperty('c')).toBe(true); |