fix: support import.meta.env reassignment#10123
Open
DaveT1991 wants to merge 3 commits intovitest-dev:mainfrom
Open
fix: support import.meta.env reassignment#10123DaveT1991 wants to merge 3 commits intovitest-dev:mainfrom
DaveT1991 wants to merge 3 commits intovitest-dev:mainfrom
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
…r in tests acorn-walk's ancestor() visitor signature is (node, state, ancestors) — the previous code used (node, ancestors) so ancestors was actually receiving the state arg (undefined at runtime), causing a crash when accessing ancestors.length and TypeScript errors about unknown types. The direct `import.meta.env = ...` assignments in tests are read-only per TypeScript's ImportMeta, but vitest's MetaEnvReplacerPlugin rewrites them at runtime. Added // @ts-expect-error to suppress the compile-time error in all three test files.
|
Hello @DaveT1991. Your PR has been labeled If you're a real person behind this contribution, please:
If you believe this was flagged by mistake, leave a comment. These measures help us reduce maintenance burden and keep the team's work efficient. See our AI contributions policy for more context. |
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.
Fixes #10091
import.meta.env = ...currently gets rewritten into a non-assignable expression, which causes a parse error before the test file can run.This change handles direct
import.meta.env = ...assignments as a dedicated AST rewrite while keeping the existing proxy-based rewrite for otherimport.meta.envaccess. That lets whole-object reassignment parse correctly and still keeps property reads/writes aligned with Vitest's worker env proxy.Changes:
import.meta.env = ...assignments to merge object values into the worker env proxy and return the proxy objectimport.meta.envaccess rewrite for non-assignment casesimport.meta.envreassignment in:test/core/test/env.test.tstest/core/test/env-jsdom.test.tstest/browser/test/env.test.tsVerification:
pnpm exec eslint packages/vitest/src/node/plugins/metaEnvReplacer.ts test/core/test/env.test.ts test/core/test/env-jsdom.test.ts test/browser/test/env.test.tspnpm exec vitest run test/env.test.ts test/env-jsdom.test.tsI added the browser regression test, but I wasn't able to run the browser-side verification locally because this workspace picks up a parent PostCSS config that requires
autoprefixeroutside the Vitest repo checkout.