vite icon indicating copy to clipboard operation
vite copied to clipboard

fix: don't escape dash in define regex

Open jonaskuske opened this issue 1 year ago • 3 comments

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.

jonaskuske avatar Sep 04 '22 14:09 jonaskuske

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.

patak-dev avatar Sep 05 '22 21:09 patak-dev

👍🏻👍🏻

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 avatar Sep 06 '22 00:09 jonaskuske

@jonaskuske that sounds like a great improvement 👍🏼

patak-dev avatar Sep 06 '22 20:09 patak-dev