codesandbox / codesandbox-client

An online IDE for rapid web development
https://codesandbox.io
Other
12.96k stars 2.26k forks source link

fix: converting write ref with esm to cjs #8422

Closed CompuIves closed 2 months ago

CompuIves commented 2 months ago

Important fix. Our quick esm->cjs converter doesn't handle write + read references well. When there's code like:

  character = position > 0 ? charat(characters, --position) : 0

It converts --position to --exports.position. That's wrong, because now the local variable does not get changed. We can solve this by resolving the ast node higher, and change it to:

  exports.character = character = position > 0 ? charat(characters, exports.position = exports.position = --position) : 0;

But right now we cannot do that. Because of that, we throw an error and rely on the slower converter (babel) to convert esm to cjs. That will solve an infinite loop problem that people using emotion are seeing, which crashes the whole browser..

codesandbox[bot] commented 2 months ago

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview