| 1 |
function dec(value, context) { |
| 2 |
context.addInitializer(function() { |
| 3 |
this[context.name + '_' + context.kind + 'Context'] = context; |
| 4 |
}); |
| 5 |
|
| 6 |
if (context.kind === 'getter') { |
| 7 |
return function () { |
| 8 |
return value.call(this) + 1; |
| 9 |
} |
| 10 |
} else { |
| 11 |
return function (v) { |
| 12 |
return value.call(this, v + 1); |
| 13 |
} |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
class Foo { |
| 18 |
static value = 1; |
| 19 |
|
| 20 |
@dec |
| 21 |
static get a() { |
| 22 |
return this.value; |
| 23 |
} |
| 24 |
|
| 25 |
@dec |
| 26 |
static set a(v) { |
| 27 |
this.value = v; |
| 28 |
} |
| 29 |
|
| 30 |
@dec |
| 31 |
static get ['b']() { |
| 32 |
return this.value; |
| 33 |
} |
| 34 |
|
| 35 |
@dec |
| 36 |
static set ['b'](v) { |
| 37 |
this.value = v; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
const a_getterContext = Foo['a_getterContext']; |
| 42 |
const a_setterContext = Foo['a_setterContext']; |
| 43 |
|
| 44 |
const b_getterContext = Foo['b_getterContext']; |
| 45 |
const b_setterContext = Foo['b_setterContext']; |
| 46 |
|
| 47 |
expect(Foo.a).toBe(2); |
| 48 |
expect(Foo.b).toBe(2); |
| 49 |
expect(a_getterContext.access.get.call(Foo)).toBe(2); |
| 50 |
expect(b_getterContext.access.get.call(Foo)).toBe(2); |
| 51 |
Foo.a = 123; |
| 52 |
expect(Foo.a).toBe(125); |
| 53 |
expect(Foo.b).toBe(125); |
| 54 |
expect(a_getterContext.access.get.call(Foo)).toBe(125); |
| 55 |
expect(b_getterContext.access.get.call(Foo)).toBe(125); |
| 56 |
Foo.b = 456; |
| 57 |
expect(Foo.a).toBe(458); |
| 58 |
expect(Foo.b).toBe(458); |
| 59 |
expect(a_getterContext.access.get.call(Foo)).toBe(458); |
| 60 |
expect(b_getterContext.access.get.call(Foo)).toBe(458); |
| 61 |
a_setterContext.access.set.call(Foo, 789); |
| 62 |
expect(Foo.a).toBe(791); |
| 63 |
expect(Foo.b).toBe(791); |
| 64 |
expect(a_getterContext.access.get.call(Foo)).toBe(791); |
| 65 |
expect(b_getterContext.access.get.call(Foo)).toBe(791); |
| 66 |
|
| 67 |
expect(a_getterContext.name).toBe('a'); |
| 68 |
expect(a_getterContext.kind).toBe('getter'); |
| 69 |
expect(a_getterContext.static).toBe(true); |
| 70 |
expect(a_getterContext.private).toBe(false); |
| 71 |
expect(typeof a_getterContext.addInitializer).toBe('function'); |
| 72 |
|
| 73 |
expect(a_setterContext.name).toBe('a'); |
| 74 |
expect(a_setterContext.kind).toBe('setter'); |
| 75 |
expect(a_setterContext.static).toBe(true); |
| 76 |
expect(a_setterContext.private).toBe(false); |
| 77 |
expect(typeof a_setterContext.addInitializer).toBe('function'); |
| 78 |
|
| 79 |
expect(b_getterContext.name).toBe('b'); |
| 80 |
expect(b_getterContext.kind).toBe('getter'); |
| 81 |
expect(b_getterContext.static).toBe(true); |
| 82 |
expect(b_getterContext.private).toBe(false); |
| 83 |
expect(typeof b_getterContext.addInitializer).toBe('function'); |
| 84 |
|
| 85 |
expect(b_setterContext.name).toBe('b'); |
| 86 |
expect(b_setterContext.kind).toBe('setter'); |
| 87 |
expect(b_setterContext.static).toBe(true); |
| 88 |
expect(b_setterContext.private).toBe(false); |
| 89 |
expect(typeof b_setterContext.addInitializer).toBe('function'); |
| 90 |
|