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

fix: self exported module call stack error #1221

Merged
merged 2 commits into from May 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 .eslintignore
Expand Up @@ -5,3 +5,4 @@ node_modules
*.d.ts
coverage
!.vitepress
test/core/src/self
7 changes: 7 additions & 0 deletions packages/vite-node/src/client.ts
Expand Up @@ -253,6 +253,13 @@ function proxyMethod(name: 'get' | 'set' | 'has' | 'deleteProperty', tryDefault:
}

function exportAll(exports: any, sourceModule: any) {
// #1120 when a module exports itself it causes
// call stack error
if (exports === sourceModule) {
// eslint-disable-next-line no-console
console.warn('[vite-node] module is being self exported', sourceModule)
pikax marked this conversation as resolved.
Show resolved Hide resolved
return
}
// eslint-disable-next-line no-restricted-syntax
for (const key in sourceModule) {
if (key !== 'default') {
Expand Down
5 changes: 5 additions & 0 deletions test/core/src/self/foo.ts
@@ -0,0 +1,5 @@
/* eslint-disable */

export function foo(): true {
return true;
}
4 changes: 4 additions & 0 deletions test/core/src/self/index.ts
@@ -0,0 +1,4 @@
/* eslint-disable */

export * from './foo';
export * from './index'; // <-- wrong
7 changes: 7 additions & 0 deletions test/core/test/self.test.ts
@@ -0,0 +1,7 @@
import { expect, it } from 'vitest'
import { foo } from '../src/self'

// #1220 self export module
it('self export', () => {
expect(foo()).toBe(true)
})