@@ -121,23 +121,63 @@ function createHook (meta) {
121121
122122 const iitmURL = new URL ( 'lib/register.js' , meta . url ) . toString ( )
123123 async function getSource ( url , context , parentGetSource ) {
124+ const imports = [ ]
125+ const namespaceIds = [ ]
126+
124127 if ( hasIitm ( url ) ) {
125128 const realUrl = deleteIitm ( url )
126129 const exportNames = await getExports ( realUrl , context , parentGetSource )
130+ const isExportAllLine = / ^ \* f r o m /
131+ const setters = [ ]
132+ for ( const n of exportNames ) {
133+ if ( isExportAllLine . test ( n ) === true ) {
134+ // Encountered a `export * from 'module'` line. Thus, we need to
135+ // get all exports from the specified module and shim them into the
136+ // current module.
137+ const [ _ , modFile ] = n . split ( '* from ' )
138+ const modName = Buffer . from ( modFile , 'hex' ) + Date . now ( )
139+ const modUrl = new URL ( modFile , url ) . toString ( )
140+ const innerExports = await getExports ( modUrl , context , parentGetSource )
141+ const innerSetters = [ ]
142+
143+ for ( const _n of innerExports ) {
144+ innerSetters . push ( `
145+ let $${ _n } = _.${ _n }
146+ export { $${ _n } as ${ _n } }
147+ set.${ _n } = (v) => {
148+ $${ _n } = v
149+ return true
150+ }
151+ ` )
152+ }
153+
154+ imports . push ( `import * as $${ modName } from ${ JSON . stringify ( modUrl ) } ` )
155+ namespaceIds . push ( `$${ modName } ` )
156+ setters . push ( innerSetters . join ( '\n' ) )
157+ continue
158+ }
159+
160+ setters . push ( `
161+ let $${ n } = _.${ n }
162+ export { $${ n } as ${ n } }
163+ set.${ n } = (v) => {
164+ $${ n } = v
165+ return true
166+ }
167+ ` )
168+ }
169+
127170 return {
128171 source : `
129172import { register } from '${ iitmURL } '
130173import * as namespace from ${ JSON . stringify ( url ) }
174+ ${ imports . join ( '\n' ) }
175+
176+ const _ = Object.assign({}, ...[namespace, ${ namespaceIds . join ( ', ' ) } ])
131177const set = {}
132- ${ exportNames . map ( ( n ) => `
133- let $${ n } = namespace.${ n }
134- export { $${ n } as ${ n } }
135- set.${ n } = (v) => {
136- $${ n } = v
137- return true
138- }
139- ` ) . join ( '\n' ) }
140- register(${ JSON . stringify ( realUrl ) } , namespace, set, ${ JSON . stringify ( specifiers . get ( realUrl ) ) } )
178+
179+ ${ setters . join ( '\n' ) }
180+ register(${ JSON . stringify ( realUrl ) } , _, set, ${ JSON . stringify ( specifiers . get ( realUrl ) ) } )
141181`
142182 }
143183 }
0 commit comments