Skip to content
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

Merged
merged 1 commit into from
Jun 21, 2024
Merged

Conversation

MonicaOlejniczak
Copy link
Contributor

@MonicaOlejniczak MonicaOlejniczak commented Jun 20, 2024

↪️ Pull Request

When running parcel without scope hoisting, global references are not passed through correctly in the DevPackager module. This results in runtime errors when any code directly uses global. without any checks of its existence since var global = arguments[3] is always undefined. These changes amend the pass through of the global object, so that arguments[3] exists under a privately namespaced variable to prevent collisions with other constants named global.

🚨 Test instructions

yarn test:integration

@MonicaOlejniczak MonicaOlejniczak merged commit aad507e into v2 Jun 21, 2024
17 checks passed
@MonicaOlejniczak MonicaOlejniczak deleted the molejniczak/global-dev branch June 21, 2024 00:24
@@ -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' +
Copy link
Member

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?

Copy link
Contributor Author

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 :)

Copy link
Member

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.

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants