-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: prevent hoisting of the undefined global
variable in browser.js
#1534
fix: prevent hoisting of the undefined global
variable in browser.js
#1534
Conversation
global
variable in browser.js
global
variable in browser.js
Because of JS hoisting `var global` to the top of the file, `typeof global` in `getGlobal()` will always be `undefined`. By using a different variable name like `globalObject`, we are able to read the "real" `typeof global` and get access to the global object that way.
@valeriangalliat This global var is also need to change? or add Line 395 in e218f8d
|
@LinusU @NotMoni @jimmywarting PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
🎉 This PR is included in version 2.6.8 🎉 The release is available on: Your semantic-release bot 📦🚀 |
in some aftermath i think we should instead have used the |
Purpose
Because of JS hoisting
var global
to the top of the file,typeof global
ingetGlobal()
will always beundefined
.This can be a problem when bundling this code and running it in an environment that doesn't have
self
ofwindow
defined but hasglobal
.In practice I ran into this issue after browserifying node-fetch and running the bundle in
node --experimental-fetch
(just to test).I can confirm after this fix I can browserify node-fetch and have it expose the global
fetch
function when run intonode --experimental-fetch
.Changes
By using a different variable name like
globalObject
, we are able to read the "real"typeof global
and get access to the global object that way.