Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add env replacer based on VisitMut (#9852)
* 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