Skip to content

Commit

Permalink
Merge pull request #1142 from IGx89/bugfix/1140-global-registrator-no…
Browse files Browse the repository at this point in the history
…de-18

#1140@patch: Fix Node 18.18.2+ support in global-registrator.
  • Loading branch information
capricorn86 authored Oct 26, 2023
2 parents 729953c + 493dd80 commit 0fd9229
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 0fd9229

Please sign in to comment.