-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly transform enum values, rewrite enum implementation (#621)
Fixes #620 The previous enum implementation was a bit tangled, handling several different cases in one big `while` loop. This PR refactors the code into three distinct cases: string enum members, calculated/constant enum members, and autoincrementing enum members, and the transform details are handled separately for each. Each case still needs to think about the case where we save a variable and the case where we don't, but hopefully the whole thing is more understandable now, and certainly better-documented. This refactor makes it much easier to fix #620, where we weren't actually passing the RHS expressions to the root transformer for their own transforms. In particular, that meant that imported values weren't transformed correctly. To fix, we now apply the enum transform in a purely left-to-right way rather than needing to save and re-emit a region of code. As part of the refactor, I also changed the emitted code so that when autoincrementing a previous value, we always reference it rather than copying the entire expression. This should reduce cases where we need to copy a large range of code, which is generally questionable in Sucrase.
- Loading branch information
1 parent
2b50eef
commit aee2a87
Showing
2 changed files
with
213 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters