Skip to content

Commit

Permalink
feat(define): prevent assignment (vitejs#5515)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Dec 28, 2021
1 parent ac3f434 commit 6d4ee18
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/playground/define/index.html
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 6d4ee18

Please sign in to comment.