Skip to content

Conversation

@Q16solver
Copy link
Contributor

Closes #752

parent.parent.type === AST_NODE_TYPES.Program
) {
// The call is already in a top-level position, where it should be.
// The call is in a valid top-level position.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct for vi.mock() and vi.doUnmock(), though... These should definitely not be valid as far as I'm aware:

const foo = vi.mock('foo')
const bar = await vi.unmock('bar')

(fun fact - using this code actually currently causes a parse error when executing vitest due to the runtime substitution leaving stuff dangling after the = sign!)

So I think one would want to special case the behavior just around vi.hoisted() for this issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I've added a special case around this now

Copy link
Member

@veritem veritem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@veritem veritem merged commit ecd4253 into vitest-dev:main Sep 6, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vitest/hoisted-apis-on-top false positives

3 participants