From 493dd8045a71053d58ac05aec3578363645467be Mon Sep 17 00:00:00 2001 From: Matthew Lieder Date: Tue, 24 Oct 2023 14:04:14 -0500 Subject: [PATCH] #1140@patch: Fix Node 18.18.2+ support in global-registrator. --- packages/global-registrator/src/GlobalRegistrator.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/global-registrator/src/GlobalRegistrator.ts b/packages/global-registrator/src/GlobalRegistrator.ts index db03c78c7..0a0c2329d 100644 --- a/packages/global-registrator/src/GlobalRegistrator.ts +++ b/packages/global-registrator/src/GlobalRegistrator.ts @@ -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]; } } @@ -56,3 +60,7 @@ export default class GlobalRegistrator { this.registered = null; } } + +function isClassLikeName(name: string): boolean { + return name[0] === name[0].toUpperCase(); +}