/
cjs.js
42 lines (35 loc) · 1.02 KB
/
cjs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// test importing both default and named exports from a CommonJS module
// React is the ultimate test of this because its dynamic exports assignments
// are not statically detectable by @rollup/plugin-commonjs.
import React, { useState } from 'react'
import ReactDOM from 'react-dom/client'
import { Socket } from 'phoenix'
import clip from 'clipboard'
// Test exporting a name that was already imported
export { useState } from 'react'
export { useState as anotherNameForUseState } from 'react'
export { default as React } from 'react'
if (typeof clip === 'function') {
text('.cjs-clipboard', 'ok')
}
if (typeof Socket === 'function') {
text('.cjs-phoenix', 'ok')
}
function App() {
const [count, setCount] = useState(0)
return React.createElement(
'button',
{
onClick() {
setCount(count + 1)
}
},
`count is ${count}`
)
}
ReactDOM.createRoot(document.querySelector('.cjs')).render(
React.createElement(App)
)
function text(el, text) {
document.querySelector(el).textContent = text
}