Skip to content

Commit

Permalink
fix: self exported module call stack error (#1221)
Browse files Browse the repository at this point in the history
* fix: self exported module call stack error

* remove warning
  • Loading branch information
pikax committed May 1, 2022
1 parent a944a91 commit 4956713
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Expand Up @@ -5,3 +5,4 @@ node_modules
*.d.ts
coverage
!.vitepress
test/core/src/self
5 changes: 5 additions & 0 deletions packages/vite-node/src/client.ts
Expand Up @@ -253,6 +253,11 @@ 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)
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)
})

0 comments on commit 4956713

Please sign in to comment.