@@ -489,13 +489,12 @@ function webpackContext(req) {
489
489
${ returnModuleObject }
490
490
}
491
491
function webpackContextResolve(req) {
492
- var id = map[req];
493
- if(!(id + 1)) { // check for number or string
492
+ if(!Object.prototype.hasOwnProperty.call(map, req)) {
494
493
var e = new Error("Cannot find module '" + req + "'");
495
494
e.code = 'MODULE_NOT_FOUND';
496
495
throw e;
497
496
}
498
- return id ;
497
+ return map[req] ;
499
498
}
500
499
webpackContext.keys = function webpackContextKeys() {
501
500
return Object.keys(map);
@@ -529,13 +528,12 @@ function webpackContext(req) {
529
528
${ returnModuleObject }
530
529
}
531
530
function webpackContextResolve(req) {
532
- var id = map[req];
533
- if(!(id + 1)) { // check for number or string
531
+ if(!Object.prototype.hasOwnProperty.call(map, req)) {
534
532
var e = new Error("Cannot find module '" + req + "'");
535
533
e.code = 'MODULE_NOT_FOUND';
536
534
throw e;
537
535
}
538
- return id ;
536
+ return map[req] ;
539
537
}
540
538
webpackContext.keys = function webpackContextKeys() {
541
539
return Object.keys(map);
@@ -573,13 +571,12 @@ function webpackAsyncContextResolve(req) {
573
571
// Here Promise.resolve().then() is used instead of new Promise() to prevent
574
572
// uncaught exception popping up in devtools
575
573
return Promise.resolve().then(function() {
576
- var id = map[req];
577
- if(!(id + 1)) { // check for number or string
574
+ if(!Object.prototype.hasOwnProperty.call(map, req)) {
578
575
var e = new Error("Cannot find module '" + req + "'");
579
576
e.code = 'MODULE_NOT_FOUND';
580
577
throw e;
581
578
}
582
- return id ;
579
+ return map[req] ;
583
580
});
584
581
}
585
582
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
@@ -615,13 +612,12 @@ function webpackAsyncContextResolve(req) {
615
612
// Here Promise.resolve().then() is used instead of new Promise() to prevent
616
613
// uncaught exception popping up in devtools
617
614
return Promise.resolve().then(function() {
618
- var id = map[req];
619
- if(!(id + 1)) { // check for number or string
615
+ if(!Object.prototype.hasOwnProperty.call(map, req)) {
620
616
var e = new Error("Cannot find module '" + req + "'");
621
617
e.code = 'MODULE_NOT_FOUND';
622
618
throw e;
623
619
}
624
- return id ;
620
+ return map[req] ;
625
621
});
626
622
}
627
623
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
@@ -665,13 +661,12 @@ function webpackAsyncContext(req) {
665
661
}
666
662
function webpackAsyncContextResolve(req) {
667
663
return ${ promise } .then(function() {
668
- var id = map[req];
669
- if(!(id + 1)) { // check for number or string
664
+ if(!Object.prototype.hasOwnProperty.call(map, req)) {
670
665
var e = new Error("Cannot find module '" + req + "'");
671
666
e.code = 'MODULE_NOT_FOUND';
672
667
throw e;
673
668
}
674
- return id ;
669
+ return map[req] ;
675
670
});
676
671
}
677
672
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
@@ -691,70 +686,102 @@ module.exports = webpackAsyncContext;`;
691
686
getLazySource ( blocks , id , chunkGraph ) {
692
687
const moduleGraph = chunkGraph . moduleGraph ;
693
688
let hasMultipleOrNoChunks = false ;
689
+ let hasNoChunk = true ;
694
690
const fakeMap = this . getFakeMap (
695
691
blocks . map ( b => b . dependencies [ 0 ] ) ,
696
692
chunkGraph
697
693
) ;
698
- const map = blocks
694
+ const hasFakeMap = typeof fakeMap === "object" ;
695
+ const items = blocks
699
696
. map ( block => {
700
697
const dependency = block . dependencies [ 0 ] ;
701
698
return {
702
699
dependency : dependency ,
703
700
module : moduleGraph . getModule ( dependency ) ,
704
701
block : block ,
705
- userRequest : dependency . userRequest
702
+ userRequest : dependency . userRequest ,
703
+ chunks : undefined
706
704
} ;
707
705
} )
708
- . filter ( item => item . module )
706
+ . filter ( item => item . module ) ;
707
+ for ( const item of items ) {
708
+ const chunkGroup = chunkGraph . getBlockChunkGroup ( item . block ) ;
709
+ const chunks = ( chunkGroup && chunkGroup . chunks ) || [ ] ;
710
+ item . chunks = chunks ;
711
+ if ( chunks . length > 0 ) {
712
+ hasNoChunk = false ;
713
+ }
714
+ if ( chunks . length !== 1 ) {
715
+ hasMultipleOrNoChunks = true ;
716
+ }
717
+ }
718
+ const shortMode = hasNoChunk && ! hasFakeMap ;
719
+ const map = items
709
720
. sort ( ( a , b ) => {
710
721
if ( a . userRequest === b . userRequest ) return 0 ;
711
722
return a . userRequest < b . userRequest ? - 1 : 1 ;
712
723
} )
713
724
. reduce ( ( map , item ) => {
714
- const chunkGroup = chunkGraph . getBlockChunkGroup ( item . block ) ;
715
- const chunks = ( chunkGroup && chunkGroup . chunks ) || [ ] ;
716
- if ( chunks . length !== 1 ) {
717
- hasMultipleOrNoChunks = true ;
718
- }
719
- const module = moduleGraph . getModule ( item . dependency ) ;
720
- const moduleId = chunkGraph . getModuleId ( module ) ;
721
- const arrayStart = [ moduleId ] ;
722
- if ( typeof fakeMap === "object" ) {
723
- arrayStart . push ( fakeMap [ moduleId ] ) ;
725
+ const moduleId = chunkGraph . getModuleId ( item . module ) ;
726
+ if ( shortMode ) {
727
+ map [ item . userRequest ] = moduleId ;
728
+ } else {
729
+ const arrayStart = [ moduleId ] ;
730
+ if ( hasFakeMap ) {
731
+ arrayStart . push ( fakeMap [ moduleId ] ) ;
732
+ }
733
+ map [ item . userRequest ] = arrayStart . concat (
734
+ item . chunks . map ( chunk => chunk . id )
735
+ ) ;
724
736
}
725
- map [ item . userRequest ] = arrayStart . concat (
726
- chunks . map ( chunk => chunk . id )
727
- ) ;
728
-
729
737
return map ;
730
738
} , Object . create ( null ) ) ;
731
739
732
- const chunksStartPosition = typeof fakeMap === "object" ? 2 : 1 ;
733
- const requestPrefix = hasMultipleOrNoChunks
740
+ const chunksStartPosition = hasFakeMap ? 2 : 1 ;
741
+ const requestPrefix = hasNoChunk
742
+ ? "Promise.resolve()"
743
+ : hasMultipleOrNoChunks
734
744
? `Promise.all(ids.slice(${ chunksStartPosition } ).map(${
735
745
RuntimeGlobals . ensureChunk
736
746
} ))`
737
747
: `${ RuntimeGlobals . ensureChunk } (ids[${ chunksStartPosition } ])` ;
738
748
const returnModuleObject = this . getReturnModuleObjectSource (
739
749
fakeMap ,
740
- "ids[1]"
750
+ shortMode ? "invalid" : "ids[1]"
741
751
) ;
742
752
743
- return `var map = ${ JSON . stringify ( map , null , "\t" ) } ;
753
+ const webpackAsyncContext =
754
+ requestPrefix === "Promise.resolve()"
755
+ ? `${ shortMode ? "" : "" }
744
756
function webpackAsyncContext(req) {
745
- var ids = map[req];
746
- if(!ids) {
757
+ return Promise.resolve().then(function() {
758
+ if(!Object.prototype.hasOwnProperty.call(map, req)) {
759
+ var e = new Error("Cannot find module '" + req + "'");
760
+ e.code = 'MODULE_NOT_FOUND';
761
+ throw e;
762
+ }
763
+
764
+ ${ shortMode ? "var id = map[req];" : "var ids = map[req], id = ids[0];" }
765
+ ${ returnModuleObject }
766
+ });
767
+ }`
768
+ : `function webpackAsyncContext(req) {
769
+ if(!Object.prototype.hasOwnProperty.call(map, req)) {
747
770
return Promise.resolve().then(function() {
748
771
var e = new Error("Cannot find module '" + req + "'");
749
772
e.code = 'MODULE_NOT_FOUND';
750
773
throw e;
751
774
});
752
775
}
776
+
777
+ var ids = map[req], id = ids[0];
753
778
return ${ requestPrefix } .then(function() {
754
- var id = ids[0];
755
779
${ returnModuleObject }
756
780
});
757
- }
781
+ }` ;
782
+
783
+ return `var map = ${ JSON . stringify ( map , null , "\t" ) } ;
784
+ ${ webpackAsyncContext }
758
785
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
759
786
return Object.keys(map);
760
787
};
0 commit comments