Skip to content

Commit

Permalink
chore(web): make getters enumerable
Browse files Browse the repository at this point in the history
Ref microsoft/TypeScript#32264 (comment)

We need getters for the ActiveLayout classes to be enumerable so that we
can copy them across in the polyfill functions.
  • Loading branch information
mcdurdin committed May 9, 2022
1 parent 21744d0 commit 907d4ac
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions common/core/web/keyboard-processor/src/keyboards/activeLayout.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
namespace com.keyman.keyboards {
type KeyDistribution = text.KeyDistribution;

// TS 3.9 changed behavior of getters to make them
// non-enumerable by default. This broke our 'polyfill'
// functions which depended on enumeration to copy the
// relevant props over.
// https://github.com/microsoft/TypeScript/pull/32264#issuecomment-677718191
function Enumerable(
target: unknown,
propertyKey: string,
descriptor: PropertyDescriptor
) {
descriptor.enumerable = true;
};

export class ActiveKey implements LayoutKey {

Expand Down Expand Up @@ -52,6 +64,7 @@ namespace com.keyman.keyboards {
*
* Is used to determine the keycode for input events, rule-matching, and keystroke processing.
*/
@Enumerable
public get baseKeyID(): string {
if(typeof this.id === 'undefined') {
return undefined;
Expand All @@ -78,6 +91,7 @@ namespace com.keyman.keyboards {
*
* Useful when the active layer of an input-event is already known.
*/
@Enumerable
public get coreID(): string {
if(typeof this.id === 'undefined') {
return undefined;
Expand Down Expand Up @@ -110,6 +124,7 @@ namespace com.keyman.keyboards {
*
* Useful when only the active keyboard is known about an input event.
*/
@Enumerable
public get elementID(): string {
if(typeof this.id === 'undefined') {
return undefined;
Expand Down

0 comments on commit 907d4ac

Please sign in to comment.