| 1 |
function dec(fn, context) { |
| 2 |
context.addInitializer(function() { |
| 3 |
this[context.name + 'Context'] = context; |
| 4 |
}); |
| 5 |
|
| 6 |
return function () { |
| 7 |
return fn.call(this) + 1; |
| 8 |
} |
| 9 |
} |
| 10 |
|
| 11 |
class Foo { |
| 12 |
static value = 1; |
| 13 |
|
| 14 |
@dec |
| 15 |
static #a() { |
| 16 |
return this.value; |
| 17 |
} |
| 18 |
|
| 19 |
static callA() { |
| 20 |
return this.#a(); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
const aContext = Foo['#aContext']; |
| 25 |
|
| 26 |
|
| 27 |
expect(aContext.access.get.call(Foo).call(Foo)).toBe(2); |
| 28 |
expect(Foo.callA()).toBe(2); |
| 29 |
Foo.value = 123; |
| 30 |
expect(aContext.access.get.call(Foo).call(Foo)).toBe(124); |
| 31 |
expect(Foo.callA()).toBe(124); |
| 32 |
|
| 33 |
expect(aContext.name).toBe('#a'); |
| 34 |
expect(aContext.kind).toBe('method'); |
| 35 |
expect(aContext.static).toBe(true); |
| 36 |
expect(aContext.private).toBe(true); |
| 37 |
expect(typeof aContext.addInitializer).toBe('function'); |