function test(x) { class F { [x] = 1; constructor() {} } x = 'deadbeef'; expect(new F().foo).toBe(1); x = 'wrong'; expect(new F().foo).toBe(1); } test('foo');