| 1 |
function dec(get, context) { |
| 2 |
context.addInitializer(function() { |
| 3 |
this[context.name + 'Context'] = context; |
| 4 |
}); |
| 5 |
|
| 6 |
return function () { |
| 7 |
return get.call(this) + 1; |
| 8 |
} |
| 9 |
} |
| 10 |
|
| 11 |
class Foo { |
| 12 |
value = 1; |
| 13 |
|
| 14 |
@dec |
| 15 |
get a() { |
| 16 |
return this.value; |
| 17 |
} |
| 18 |
|
| 19 |
@dec |
| 20 |
get ['b']() { |
| 21 |
return this.value; |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
let foo = new Foo(); |
| 26 |
|
| 27 |
const aContext = foo['aContext']; |
| 28 |
const bContext = foo['bContext']; |
| 29 |
|
| 30 |
expect(foo.a).toBe(2); |
| 31 |
expect(foo.b).toBe(2); |
| 32 |
foo.value = 123; |
| 33 |
expect(foo.a).toBe(124); |
| 34 |
expect(foo.b).toBe(124); |
| 35 |
|
| 36 |
expect(aContext.name).toBe('a'); |
| 37 |
expect(aContext.kind).toBe('getter'); |
| 38 |
expect(aContext.isStatic).toBe(false); |
| 39 |
expect(aContext.isPrivate).toBe(false); |
| 40 |
expect(typeof aContext.addInitializer).toBe('function'); |
| 41 |
expect(typeof aContext.setMetadata).toBe('function'); |
| 42 |
expect(typeof aContext.getMetadata).toBe('function'); |
| 43 |
|
| 44 |
expect(bContext.name).toBe('b'); |
| 45 |
expect(bContext.kind).toBe('getter'); |
| 46 |
expect(bContext.isStatic).toBe(false); |
| 47 |
expect(bContext.isPrivate).toBe(false); |
| 48 |
expect(typeof bContext.addInitializer).toBe('function'); |
| 49 |
expect(typeof bContext.setMetadata).toBe('function'); |
| 50 |
expect(typeof bContext.getMetadata).toBe('function'); |