@@ -225,44 +225,56 @@ class ContextModule extends Module {
225225 }
226226
227227 getFakeMap ( dependencies ) {
228- if ( ! this . options . namespaceObject ) return false ;
228+ if ( ! this . options . namespaceObject ) return 1 ;
229229 // if we filter first we get a new array
230230 // therefor we dont need to create a clone of dependencies explicitly
231231 // therefore the order of this is !important!
232232 let hasNonHarmony = false ;
233- let hasHarmony = false ;
233+ let hasNamespace = false ;
234+ let hasNamed = false ;
234235 const fakeMap = dependencies
235236 . filter ( dependency => dependency . module )
236237 . sort ( ( a , b ) => {
237238 return b . module . id - a . module . id ;
238239 } ) . reduce ( ( map , dep ) => {
239- const harmonyModule = dep . module . buildMeta && dep . module . buildMeta . harmonyModule ;
240- if ( ! harmonyModule ) hasNonHarmony = true ;
241- if ( harmonyModule ) hasHarmony = true ;
242- map [ dep . module . id ] = harmonyModule ? 1 : 0 ;
240+ const exportsType = dep . module . buildMeta && dep . module . buildMeta . exportsType ;
241+ if ( ! exportsType ) hasNonHarmony = true ;
242+ if ( exportsType === "namespace" ) hasNamespace = true ;
243+ if ( exportsType === "named" ) hasNamed = true ;
244+ map [ dep . module . id ] = {
245+ namespace : 1 ,
246+ named : 2
247+ } [ exportsType ] || 0 ;
243248 return map ;
244249 } , Object . create ( null ) ) ;
245- if ( hasHarmony && ! hasNonHarmony ) return false ;
246- if ( ! hasHarmony && hasNonHarmony ) return true ;
250+ if ( ! hasNamespace && hasNonHarmony && ! hasNamed ) return 0 ;
251+ if ( hasNamespace && ! hasNonHarmony && ! hasNamed ) return 1 ;
252+ if ( ! hasNamespace && ! hasNonHarmony && hasNamed ) return 2 ;
253+ if ( ! hasNamespace && ! hasNonHarmony && ! hasNamed ) return 1 ;
247254 return fakeMap ;
248255 }
249256
250- getModuleObjectSource ( fakeMap , fakeMapDataExpression = "fakeMap[id]" ) {
257+ getReturnModuleObjectSource ( fakeMap , fakeMapDataExpression = "fakeMap[id]" ) {
251258 const strict = this . options . namespaceObject === "strict" ;
252- if ( strict ) {
253- if ( fakeMap === true ) return "/* fake namespace object */ { \"default\": module }" ;
254- if ( fakeMap ) return `${ fakeMapDataExpression } ? module : /* fake namespace object */ { "default": module }` ;
255- } else {
256- if ( fakeMap === true ) return "typeof module === \"object\" && module && module.__esModule ? module : /* fake namespace object */ { \"default\": module };" ;
257- if ( fakeMap ) return `${ fakeMapDataExpression } || typeof module === "object" && module && module.__esModule ? module : /* fake namespace object */ { "default": module };` ;
258- }
259- return "module" ;
259+ const getReturn = type => {
260+ if ( type === 1 ) return "module" ;
261+ if ( type === 2 ) return "Object.assign({/* fake namespace object */}, module, { \"default\": module })" ;
262+ if ( type === 0 ) {
263+ if ( strict ) {
264+ return "/* fake namespace object */ { \"default\": module }" ;
265+ } else {
266+ return "(typeof module === \"object\" && module && module.__esModule ? module : /* fake namespace object */ { \"default\": module })" ;
267+ }
268+ }
269+ } ;
270+ if ( typeof fakeMap === "number" ) return `return ${ getReturn ( fakeMap ) } ;` ;
271+ return `return ${ fakeMapDataExpression } === 1 ? ${ getReturn ( 1 ) } : ${ fakeMapDataExpression } ? ${ getReturn ( 2 ) } : ${ getReturn ( 0 ) } ;` ;
260272 }
261273
262274 getSyncSource ( dependencies , id ) {
263275 const map = this . getUserRequestMap ( dependencies ) ;
264276 const fakeMap = this . getFakeMap ( dependencies ) ;
265- const returnModuleObject = `return ${ this . getModuleObjectSource ( fakeMap ) } ;` ;
277+ const returnModuleObject = `${ this . getReturnModuleObjectSource ( fakeMap ) } ;` ;
266278
267279 return `var map = ${ JSON . stringify ( map , null , "\t" ) } ;
268280${ typeof fakeMap === "object" ? `var fakeMap = ${ JSON . stringify ( fakeMap , null , "\t" ) } ;` : "" }
@@ -292,7 +304,7 @@ webpackContext.id = ${JSON.stringify(id)};`;
292304 getWeakSyncSource ( dependencies , id ) {
293305 const map = this . getUserRequestMap ( dependencies ) ;
294306 const fakeMap = this . getFakeMap ( dependencies ) ;
295- const returnModuleObject = `return ${ this . getModuleObjectSource ( fakeMap ) } ;` ;
307+ const returnModuleObject = `${ this . getReturnModuleObjectSource ( fakeMap ) } ;` ;
296308
297309 return `var map = ${ JSON . stringify ( map , null , "\t" ) } ;
298310${ typeof fakeMap === "object" ? `var fakeMap = ${ JSON . stringify ( fakeMap , null , "\t" ) } ;` : "" }
@@ -327,7 +339,7 @@ module.exports = webpackContext;`;
327339 getAsyncWeakSource ( dependencies , id ) {
328340 const map = this . getUserRequestMap ( dependencies ) ;
329341 const fakeMap = this . getFakeMap ( dependencies ) ;
330- const returnModuleObject = `return ${ this . getModuleObjectSource ( fakeMap ) } ;` ;
342+ const returnModuleObject = `${ this . getReturnModuleObjectSource ( fakeMap ) } ;` ;
331343
332344 return `var map = ${ JSON . stringify ( map , null , "\t" ) } ;
333345${ typeof fakeMap === "object" ? `var fakeMap = ${ JSON . stringify ( fakeMap , null , "\t" ) } ;` : "" }
@@ -367,10 +379,10 @@ module.exports = webpackAsyncContext;`;
367379 getEagerSource ( dependencies , id ) {
368380 const map = this . getUserRequestMap ( dependencies ) ;
369381 const fakeMap = this . getFakeMap ( dependencies ) ;
370- const thenFunction = fakeMap ?
382+ const thenFunction = fakeMap !== 1 ?
371383 `function(id) {
372384 var module = __webpack_require__(id);
373- return ${ this . getModuleObjectSource ( fakeMap ) } ;
385+ ${ this . getReturnModuleObjectSource ( fakeMap ) } ;
374386}` :
375387 "__webpack_require__" ;
376388 return `var map = ${ JSON . stringify ( map , null , "\t" ) } ;
@@ -407,10 +419,10 @@ module.exports = webpackAsyncContext;`;
407419 } ) ;
408420 const map = this . getUserRequestMap ( dependencies ) ;
409421 const fakeMap = this . getFakeMap ( dependencies ) ;
410- const thenFunction = fakeMap ?
422+ const thenFunction = fakeMap !== 1 ?
411423 `function(id) {
412424 var module = __webpack_require__(id);
413- return ${ this . getModuleObjectSource ( fakeMap ) } ;
425+ ${ this . getReturnModuleObjectSource ( fakeMap ) } ;
414426 }` :
415427 "__webpack_require__" ;
416428
@@ -469,7 +481,7 @@ module.exports = webpackAsyncContext;`;
469481 const requestPrefix = hasMultipleOrNoChunks ?
470482 `Promise.all(ids.slice(${ chunksStartPosition } ).map(__webpack_require__.e))` :
471483 `__webpack_require__.e(ids[${ chunksStartPosition } ])` ;
472- const returnModuleObject = `return ${ this . getModuleObjectSource ( fakeMap , "ids[1]" ) } ;` ;
484+ const returnModuleObject = `${ this . getReturnModuleObjectSource ( fakeMap , "ids[1]" ) } ;` ;
473485
474486 return `var map = ${ JSON . stringify ( map , null , "\t" ) } ;
475487function webpackAsyncContext(req) {
0 commit comments