Skip to content

Commit 9b5d4cd

Browse files
committed
fix: correct acorn-walk ancestor visitor signature and ts-expect-error 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.
1 parent 0bd2550 commit 9b5d4cd

File tree

4 files changed

+4
-1
lines changed

4 files changed

+4
-1
lines changed

packages/vitest/src/node/plugins/metaEnvReplacer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function MetaEnvReplacerPlugin(): Plugin {
3636
const assignmentRanges: Array<{ start: number; end: number }> = []
3737

3838
walkAst(ast as any, {
39-
MemberExpression(node, ancestors) {
39+
MemberExpression(node, _state, ancestors) {
4040
if (!isImportMetaEnv(node)) {
4141
return
4242
}

test/browser/test/env.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ test('can reassign import.meta.env directly', () => {
1515

1616
delete import.meta.env[key]
1717

18+
// @ts-expect-error -- vitest rewrites this assignment at runtime via MetaEnvReplacerPlugin
1819
import.meta.env = import.meta.env || {}
1920
import.meta.env[key] = 'true'
2021

test/core/test/env-jsdom.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ test('can reassign import.meta.env directly', () => {
2929

3030
delete process.env[key]
3131

32+
// @ts-expect-error -- vitest rewrites this assignment at runtime via MetaEnvReplacerPlugin
3233
import.meta.env = import.meta.env || {}
3334
import.meta.env[key] = 'true'
3435

test/core/test/env.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ test('can reassign import.meta.env directly', () => {
2727

2828
delete process.env[key]
2929

30+
// @ts-expect-error -- vitest rewrites this assignment at runtime via MetaEnvReplacerPlugin
3031
import.meta.env = import.meta.env || {}
3132
import.meta.env[key] = 'true'
3233

0 commit comments

Comments
 (0)