Skip to content

Commit

Permalink
fix: allow equality operators after env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaskuske committed Apr 10, 2022
1 parent 145c1df commit 0d391f0
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions packages/vite/src/node/plugins/define.ts
Expand Up @@ -68,21 +68,17 @@ export function definePlugin(config: ResolvedConfig): Plugin {
const replacementsKeys = Object.keys(replacements)
const pattern = replacementsKeys.length
? new RegExp(
// Do not allow preceding '.', but do allow preceding '...' for spread operations
'(?<!(?<!\\.\\.)\\.)' +
// Must follow beginning of a line or a char that can't be part of an identifier
'(?<=^|[^\\p{L}\\p{N}_$])(' +
// Mustn't be preceded by a char that can be part of an identifier
//or a '.' that isn't part of a spread operator
'(?<![\\p{L}\\p{N}_$]|(?<!\\.\\.)\\.)(' +
replacementsKeys
.map((str) => {
return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&')
})
.join('|') +
// Replacement key must be followed by:
// - end of a line
// - a char that can't be part of an identifier and isn't whitespace or an assignment
// - whitespace, as long as it's not followed by an assignment
// - anything following a dot (handles cases where replacement includes a trailing dot)
')(?=$|[^\\p{L}\\p{N}_$\\s=]|(\\s+[^=\\s])|(?<=\\.).)',
// Mustn't be followed by a char that can be part of an identifier
// or an assignment (but allow equality operators)
')(?![\\p{L}\\p{N}_$]|\\s*?=[^=])',
'gu'
)
: null
Expand Down

0 comments on commit 0d391f0

Please sign in to comment.