Skip to content

Commit 82b0228

Browse files
authored
test(optimizer): add test for cjs interop with namespace imports (#20457)
1 parent a1aff22 commit 82b0228

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

playground/optimize-deps/cjs-dynamic.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
}
2323

2424
const cjsFromCJS = await import('@vitejs/test-dep-cjs-compiled-from-cjs')
25-
if (typeof cjsFromCJS.default === 'function') {
25+
if (
26+
typeof cjsFromCJS.default === 'function' &&
27+
typeof cjsFromCJS !== 'function' &&
28+
cjsFromCJS.bar === 'bar'
29+
) {
2630
text('.cjs-dynamic-dep-cjs-compiled-from-cjs', 'ok')
2731
}
2832

playground/optimize-deps/cjs.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Socket } from 'phoenix'
77
import clip from 'clipboard'
88
import cjsFromESM from '@vitejs/test-dep-cjs-compiled-from-esm'
99
import cjsFromCJS from '@vitejs/test-dep-cjs-compiled-from-cjs'
10+
import * as cjsFromCJSNamespace from '@vitejs/test-dep-cjs-compiled-from-cjs'
1011

1112
// Test exporting a name that was already imported
1213
export { useState } from 'react'
@@ -25,7 +26,11 @@ if (typeof cjsFromESM === 'function') {
2526
text('.cjs-dep-cjs-compiled-from-esm', 'ok')
2627
}
2728

28-
if (typeof cjsFromCJS === 'function') {
29+
if (
30+
typeof cjsFromCJS === 'function' &&
31+
typeof cjsFromCJSNamespace !== 'function' &&
32+
cjsFromCJSNamespace.bar === 'bar'
33+
) {
2934
text('.cjs-dep-cjs-compiled-from-cjs', 'ok')
3035
}
3136

playground/optimize-deps/dep-cjs-compiled-from-cjs/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
function foo() {
33
return 'foo'
44
}
5+
foo.bar = 'bar'
56
module.exports = foo

0 commit comments

Comments
 (0)