@@ -380,13 +380,12 @@ function webpackContext(req) {
380
380
${ returnModuleObject }
381
381
}
382
382
function webpackContextResolve(req) {
383
- var id = map[req];
384
- if(!(id + 1)) { // check for number or string
383
+ if(!__webpack_require__.o(map, req)) {
385
384
var e = new Error("Cannot find module '" + req + "'");
386
385
e.code = 'MODULE_NOT_FOUND';
387
386
throw e;
388
387
}
389
- return id ;
388
+ return map[req] ;
390
389
}
391
390
webpackContext.keys = function webpackContextKeys() {
392
391
return Object.keys(map);
@@ -414,13 +413,12 @@ function webpackContext(req) {
414
413
${ returnModuleObject }
415
414
}
416
415
function webpackContextResolve(req) {
417
- var id = map[req];
418
- if(!(id + 1)) { // check for number or string
416
+ if(!__webpack_require__.o(map, req)) {
419
417
var e = new Error("Cannot find module '" + req + "'");
420
418
e.code = 'MODULE_NOT_FOUND';
421
419
throw e;
422
420
}
423
- return id ;
421
+ return map[req] ;
424
422
}
425
423
webpackContext.keys = function webpackContextKeys() {
426
424
return Object.keys(map);
@@ -452,13 +450,12 @@ function webpackAsyncContextResolve(req) {
452
450
// Here Promise.resolve().then() is used instead of new Promise() to prevent
453
451
// uncaught exception popping up in devtools
454
452
return Promise.resolve().then(function() {
455
- var id = map[req];
456
- if(!(id + 1)) { // check for number or string
453
+ if(!__webpack_require__.o(map, req)) {
457
454
var e = new Error("Cannot find module '" + req + "'");
458
455
e.code = 'MODULE_NOT_FOUND';
459
456
throw e;
460
457
}
461
- return id ;
458
+ return map[req] ;
462
459
});
463
460
}
464
461
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
@@ -488,13 +485,12 @@ function webpackAsyncContextResolve(req) {
488
485
// Here Promise.resolve().then() is used instead of new Promise() to prevent
489
486
// uncaught exception popping up in devtools
490
487
return Promise.resolve().then(function() {
491
- var id = map[req];
492
- if(!(id + 1)) { // check for number or string
488
+ if(!__webpack_require__.o(map, req)) {
493
489
var e = new Error("Cannot find module '" + req + "'");
494
490
e.code = 'MODULE_NOT_FOUND';
495
491
throw e;
496
492
}
497
- return id ;
493
+ return map[req] ;
498
494
});
499
495
}
500
496
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
@@ -527,13 +523,12 @@ function webpackAsyncContext(req) {
527
523
}
528
524
function webpackAsyncContextResolve(req) {
529
525
return ${ promise } .then(function() {
530
- var id = map[req];
531
- if(!(id + 1)) { // check for number or string
526
+ if(!__webpack_require__.o(map, req)) {
532
527
var e = new Error("Cannot find module '" + req + "'");
533
528
e.code = 'MODULE_NOT_FOUND';
534
529
throw e;
535
530
}
536
- return id ;
531
+ return map[req] ;
537
532
});
538
533
}
539
534
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
@@ -546,59 +541,92 @@ module.exports = webpackAsyncContext;`;
546
541
547
542
getLazySource ( blocks , id ) {
548
543
let hasMultipleOrNoChunks = false ;
544
+ let hasNoChunk = true ;
549
545
const fakeMap = this . getFakeMap ( blocks . map ( b => b . dependencies [ 0 ] ) ) ;
546
+ const hasFakeMap = typeof fakeMap === "object" ;
550
547
const map = blocks
551
548
. filter ( block => block . dependencies [ 0 ] . module )
552
- . map ( block => ( {
553
- dependency : block . dependencies [ 0 ] ,
554
- block : block ,
555
- userRequest : block . dependencies [ 0 ] . userRequest
556
- } ) )
549
+ . map ( block => {
550
+ const chunks = block . chunkGroup ? block . chunkGroup . chunks : [ ] ;
551
+ if ( chunks . length > 0 ) {
552
+ hasNoChunk = false ;
553
+ }
554
+ if ( chunks . length !== 1 ) {
555
+ hasMultipleOrNoChunks = true ;
556
+ }
557
+ return {
558
+ dependency : block . dependencies [ 0 ] ,
559
+ block : block ,
560
+ userRequest : block . dependencies [ 0 ] . userRequest ,
561
+ chunks
562
+ } ;
563
+ } )
557
564
. sort ( ( a , b ) => {
558
565
if ( a . userRequest === b . userRequest ) return 0 ;
559
566
return a . userRequest < b . userRequest ? - 1 : 1 ;
560
567
} )
561
568
. reduce ( ( map , item ) => {
562
- const chunks =
563
- ( item . block . chunkGroup && item . block . chunkGroup . chunks ) || [ ] ;
564
- if ( chunks . length !== 1 ) {
565
- hasMultipleOrNoChunks = true ;
566
- }
567
- const arrayStart = [ item . dependency . module . id ] ;
568
- if ( typeof fakeMap === "object" ) {
569
- arrayStart . push ( fakeMap [ item . dependency . module . id ] ) ;
569
+ const chunks = item . chunks ;
570
+
571
+ if ( hasNoChunk && ! hasFakeMap ) {
572
+ map [ item . userRequest ] = item . dependency . module . id ;
573
+ } else {
574
+ const arrayStart = [ item . dependency . module . id ] ;
575
+ if ( typeof fakeMap === "object" ) {
576
+ arrayStart . push ( fakeMap [ item . dependency . module . id ] ) ;
577
+ }
578
+ map [ item . userRequest ] = arrayStart . concat (
579
+ chunks . map ( chunk => chunk . id )
580
+ ) ;
570
581
}
571
- map [ item . userRequest ] = arrayStart . concat (
572
- chunks . map ( chunk => chunk . id )
573
- ) ;
574
582
575
583
return map ;
576
584
} , Object . create ( null ) ) ;
577
585
578
- const chunksStartPosition = typeof fakeMap === "object" ? 2 : 1 ;
579
- const requestPrefix = hasMultipleOrNoChunks
586
+ const shortMode = hasNoChunk && ! hasFakeMap ;
587
+ const chunksStartPosition = hasFakeMap ? 2 : 1 ;
588
+ const requestPrefix = hasNoChunk
589
+ ? "Promise.resolve()"
590
+ : hasMultipleOrNoChunks
580
591
? `Promise.all(ids.slice(${ chunksStartPosition } ).map(__webpack_require__.e))`
581
592
: `__webpack_require__.e(ids[${ chunksStartPosition } ])` ;
582
593
const returnModuleObject = this . getReturnModuleObjectSource (
583
594
fakeMap ,
584
- "ids[1]"
595
+ shortMode ? "invalid" : "ids[1]"
585
596
) ;
586
597
587
- return `var map = ${ JSON . stringify ( map , null , "\t" ) } ;
598
+ const webpackAsyncContext =
599
+ requestPrefix === "Promise.resolve()"
600
+ ? `${ shortMode ? "" : "" }
588
601
function webpackAsyncContext(req) {
589
- var ids = map[req];
590
- if(!ids) {
602
+ return Promise.resolve().then(function() {
603
+ if(!__webpack_require__.o(map, req)) {
604
+ var e = new Error("Cannot find module '" + req + "'");
605
+ e.code = 'MODULE_NOT_FOUND';
606
+ throw e;
607
+ }
608
+
609
+ ${ shortMode ? "var id = map[req];" : "var ids = map[req], id = ids[0];" }
610
+ ${ returnModuleObject }
611
+ });
612
+ }`
613
+ : `function webpackAsyncContext(req) {
614
+ if(!__webpack_require__.o(map, req)) {
591
615
return Promise.resolve().then(function() {
592
616
var e = new Error("Cannot find module '" + req + "'");
593
617
e.code = 'MODULE_NOT_FOUND';
594
618
throw e;
595
619
});
596
620
}
621
+
622
+ var ids = map[req], id = ids[0];
597
623
return ${ requestPrefix } .then(function() {
598
- var id = ids[0];
599
624
${ returnModuleObject }
600
625
});
601
- }
626
+ }` ;
627
+
628
+ return `var map = ${ JSON . stringify ( map , null , "\t" ) } ;
629
+ ${ webpackAsyncContext }
602
630
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
603
631
return Object.keys(map);
604
632
};
0 commit comments