vite
vite copied to clipboard
fix: don't escape dash in define regex
Description
fix #9964
Additional context
What is the purpose of this pull request?
- [x] Bug fix
- [ ] New Feature
- [ ] Documentation update
- [ ] Other
Before submitting the PR, please make sure you do the following
- [x] Read the Contributing Guidelines.
- [x] Read the Pull Request Guidelines and follow the Commit Convention.
- [x] Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
- [x] Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g.
fixes #123
). - [x] Ideally, include relevant tests that fail without this PR but pass with it.
As you explained in https://github.com/vitejs/vite/issues/9964#issuecomment-1235534424, the define
feature needs to work both during build and dev. So we can't allow dashes if they are only going to work during build. I think your recommendations in #9964 were on point, and we should keep define
as is.
👍🏻👍🏻
I still think that constructing an invalid Regex isn't really sound though. What do you think about fixing the Regex so it doesn't throw an obscure error anymore, but printing a warning if a define key contains a character that can't be part of a variable/identifier?
@jonaskuske that sounds like a great improvement 👍🏼