Skip to content

Commit

Permalink
#1140@patch: Fix Node 18.18.2+ support in global-registrator.
Browse files Browse the repository at this point in the history
  • Loading branch information
IGx89 committed Oct 24, 2023
1 parent 729953c commit 493dd80
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/global-registrator/src/GlobalRegistrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export default class GlobalRegistrator {
if (global[key] !== window[key] && !IGNORE_LIST.includes(key)) {
this.registered[key] =
global[key] !== window[key] && global[key] !== undefined ? global[key] : null;
global[key] = typeof window[key] === 'function' ? window[key].bind(global) : window[key];

// Only bind functions that aren't used as classes, since bound functions can't be extended.
const bind = typeof window[key] === 'function' && !isClassLikeName(key);

global[key] = bind ? window[key].bind(global) : window[key];
}
}

Expand Down Expand Up @@ -56,3 +60,7 @@ export default class GlobalRegistrator {
this.registered = null;
}
}

function isClassLikeName(name: string): boolean {
return name[0] === name[0].toUpperCase();
}

0 comments on commit 493dd80

Please sign in to comment.