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

Non-static assignments to require are broken #5591

Closed
devongovett opened this issue Jan 5, 2021 · 1 comment · Fixed by #6230
Closed

Non-static assignments to require are broken #5591

devongovett opened this issue Jan 5, 2021 · 1 comment · Fixed by #6230

Comments

@devongovett
Copy link
Member

🐛 bug report

This code:

let x = require('./other');
x['fo' + 'o'] = 4;
output = require('./other').foo;

produces this:

(function () {
  // ASSET: src/other.js
  var $9bb2a74c22793326fe949cf11616aca2$exports = {};
  var $9bb2a74c22793326fe949cf11616aca2$export$foo = 2;
  $9bb2a74c22793326fe949cf11616aca2$exports.foo = $9bb2a74c22793326fe949cf11616aca2$export$foo;
  $9bb2a74c22793326fe949cf11616aca2$exports['fo' + 'o'] = 4;
  output = $9bb2a74c22793326fe949cf11616aca2$export$foo;
})();

The expected result is 4, but this will result in 2.

Fixing this will require tracking non-static assignments and bailing on resolving directly to variables instead of member expressions. The linker could replace static variable accesses with member expressions again if there is metadata indicating that a non-static assignment occurred (stored by the hoister).

Software Version(s)
Parcel ac5f1c1
Node
npm/Yarn
Operating System
@devongovett
Copy link
Member Author

Hmm actually tracking this may be very difficult especially if the require result is assigned to the value of another variable or passed into a function. We may need to bail in any cases where the require is accessed non-statically, not just on assignments.

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

Successfully merging a pull request may close this issue.

1 participant