Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(define): prevent assignment #5515

Merged
merged 1 commit into from Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/playground/define/index.html
Expand Up @@ -11,6 +11,7 @@ <h1>Define</h1>
<p>spread array: <code class="spread-array"></code></p>

<script type="module">
const __VAR_NAME__ = true // ensure define doesn't replace var name
text('.exp', __EXP__)
text('.string', __STRING__)
text('.number', __NUMBER__)
Expand Down
1 change: 1 addition & 0 deletions packages/playground/define/vite.config.js
Expand Up @@ -15,6 +15,7 @@ module.exports = {
}
}
},
__VAR_NAME__: false,
'process.env.SOMEVAR': '"SOMEVAR"'
}
}
3 changes: 2 additions & 1 deletion packages/vite/src/node/plugins/define.ts
Expand Up @@ -67,7 +67,8 @@ export function definePlugin(config: ResolvedConfig): Plugin {
return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&')
})
.join('|') +
')\\b',
// prevent trailing assignments
')\\b(?!\\s*?=[^=])',
'g'
)

Expand Down