feat: allow any JS identifier in define, not ASCII-only#5972
Merged
patak-cat merged 12 commits intovitejs:mainfrom May 5, 2022
Merged
feat: allow any JS identifier in define, not ASCII-only#5972patak-cat merged 12 commits intovitejs:mainfrom
patak-cat merged 12 commits intovitejs:mainfrom
Conversation
trailing dots in replacements are not supported in dev, just prod and only used internally for import.meta.env. (in dev it's handled by importAnalysisPlugin)
Shinigami92
suggested changes
Dec 7, 2021
Shinigami92
previously approved these changes
Dec 8, 2021
aleclarson
previously approved these changes
Mar 16, 2022
Contributor
Author
|
Rebased and updated to include the exclusion of (trailing) assignments shipped in 2.8: #5515 |
Contributor
Author
|
Greatly simplified the RegExp and fixed the bug where equality operators following an env var would break the replacement. (e.g. Tests pass now, and I think this is ready to be merged? |
bc6e44b to
a12f327
Compare
patak-cat
previously approved these changes
Apr 11, 2022
Member
|
LGTM, let's wait for other approvals. And IMO we should merge this one as part of the 3.0 beta, just to play safe. |
bluwy
reviewed
Apr 11, 2022
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
patak-cat
approved these changes
Apr 11, 2022
bluwy
approved these changes
Apr 12, 2022
aleclarson
approved these changes
Apr 14, 2022
9 tasks
7 tasks
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
defineplugin uses RegExp\bboundaries to make sure that it only replaces standalone identifiers (only_PROD_, not_PROD_USE_DEVTOOLS_). But\bonly works with ASCII characters and also not with$, so it doesn't work reliably and worse, there can be false positives leading to broken code:This PR updates the RegExp to work with any valid JS identifier, so
$and Unicode letters can be included. I also added a couple more tests, both for the newly added$and Unicode functionality as well as for previously untested functionality:_OTHER_CONST_CONTAINING_PRODUCTION_)someApiResponse._PRODUCTION_)fix #5956
Additional context
Because the usage of
\bfor replacements was mentioned in the docs and therefore specced, this technically is a new feature and not a bugfix.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).