Skip to content

Commit

Permalink
Add env replacer based on VisitMut (#9852)
Browse files Browse the repository at this point in the history
* Add visitor env replacer

This is aimed at improving moving SWC usage to visit for all parcel
use-cases as we are facing memory errors due to stack-overflow. Errors
include segmentation faults and bus errors.

This is part of #9828. Adds exhaustive tests for the folder.

The next commit will remove the fold implementation and demonstrate
tests pass for the visit implementation as well.

The following behaviours of the fold implementation should be revised in
the future as they likely are unwanted:

* `process.browser = ...` assignment expressions are replaced with
  `process.browser = true`, which is not a safe replacement
* expression replacements `const x = ({ x } = process.env);` are
  supported but insert an extra trailing object `const x = (x = 'asdf', {});
* when `replace_env` replacement is off the transformer still replaces
  several cases that aren't the base declarations case

Overall could simplify this so that less cases are supported, and then
shift it to be a generalised inline variable replacement implementation.

Currently this implementation is quite large to handle things that
aren't necessarily needed or wanted.

* Update transformer to use the VisitMut impl.

This replaces the Fold env replacer with a VisitMut implementation.

All tests pass on this new version with no real change. A case was added
for the `delete process.env.value` behaviour.

* Reword comment about process.browser = ... replacement

---------

Co-authored-by: pyamada (RDE) <[email protected]>
  • Loading branch information
yamadapc and pyamada-atlassian authored Jul 17, 2024
1 parent 3668e97 commit e0793ae
Show file tree
Hide file tree
Showing 4 changed files with 467 additions and 55 deletions.
Loading

0 comments on commit e0793ae

Please sign in to comment.