-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 dev packager global reference #9814
Conversation
5e3cc89
to
9115b1b
Compare
9115b1b
to
a54c7c7
Compare
a54c7c7
to
85a1306
Compare
@@ -116,7 +116,7 @@ export class DevPackager { | |||
let output = code || ''; | |||
wrapped += | |||
JSON.stringify(this.bundleGraph.getAssetPublicId(asset)) + | |||
':[function(require,module,exports) {\n' + | |||
':[function(require,module,exports,__globalThis) {\n' + |
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.
Where will that __globalThis
be referenced?
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.
It is referenced here
I should have added it to the description, my bad :)
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.
that's referenced via arguments[3]
though. Wouldn't this mean that if someone declared let __globalThis
in their code they'd get an error stating that it is already defined? Doesn't look like this variable is used directly.
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.
Yes, that's correct. I opted for __globalThis
since __global
is more likely to be defined. I'd prefer to use globalThis
directly instead of specifying an argument since it's well supported, but it would be inconsistent with the parcel runtime.
↪️ Pull Request
When running parcel without scope hoisting,
global
references are not passed through correctly in theDevPackager
module. This results in runtime errors when any code directly usesglobal.
without any checks of its existence sincevar global = arguments[3]
is always undefined. These changes amend the pass through of the global object, so thatarguments[3]
exists under a privately namespaced variable to prevent collisions with other constants named global.🚨 Test instructions
yarn test:integration