@@ -36,28 +36,8 @@ const Dependency = require("../graph/Dependency");
3636 */
3737
3838/**
39- * Collects the export names a dependency group requests from its target.
40- * @param {Dependency[] } dependencies dependency group resolving to one module
41- * @returns {Set<string> | true } requested export names, true for all
42- */
43- function getForwardedIds ( dependencies ) {
44- /** @type {Set<string> } */
45- const ids = new Set ( ) ;
46- for ( const dependency of dependencies ) {
47- // TODO in the next major release: remove
48- // It may be missing on custom dependency types not extending the base Dependency
49- if ( ! ( "getForwardId" in dependency ) ) continue ;
50-
51- const id = dependency . getForwardId ( ) ;
52- if ( id === true ) return true ;
53- if ( id !== null ) ids . add ( id ) ;
54- }
55- return ids ;
56- }
57-
58- /**
59- * Tracks the deferred dependencies of a side-effect-free barrel module and
60- * keeps the export forwarding needed after those dependencies are resolved.
39+ * Tracks the deferred (not yet factorized/built) dependencies of a
40+ * side-effect-free barrel module and which export names resolve to them.
6141 */
6242class LazyBarrelInfo {
6343 constructor ( ) {
@@ -450,10 +430,18 @@ class LazyBarrelController {
450430 const modules = this . _modules ;
451431 const state = modules . get ( module ) ;
452432
453- const getRequestedIds = ( ) => {
454- const directIds = getForwardedIds ( dependencies ) ;
455- if ( directIds !== true && directIds . size !== 0 ) return directIds ;
433+ /**
434+ * @returns {Set<string> | true } requested export names, true for all
435+ */
436+ const getForwardedIds = ( ) => {
437+ /** @type {Set<string> } */
438+ const ids = new Set ( ) ;
456439 for ( const dependency of dependencies ) {
440+ // TODO in the next major release: remove
441+ // It may be missing on custom dependency types not extending the base Dependency
442+ if ( ! ( "getForwardId" in dependency ) ) continue ;
443+
444+ // star re-export: forward the barrel's names, merged with named re-exports of the same request
457445 if (
458446 "getLazyUntil" in dependency &&
459447 dependency . getLazyUntil ( ) === Dependency . LAZY_UNTIL_FALLBACK
@@ -463,15 +451,20 @@ class LazyBarrelController {
463451 const parentState =
464452 parent === undefined ? undefined : modules . get ( parent ) ;
465453 if ( parentState !== undefined ) {
466- return parentState . forwardedIds ;
454+ if ( parentState . forwardedIds === true ) return true ;
455+ for ( const id of parentState . forwardedIds ) ids . add ( id ) ;
456+ continue ;
467457 }
468458 }
459+ const id = dependency . getForwardId ( ) ;
460+ if ( id === true ) return true ;
461+ if ( id !== null ) ids . add ( id ) ;
469462 }
470- if ( directIds === true || directIds . size !== 0 ) return directIds ;
471- return directIds ;
463+ return ids ;
472464 } ;
465+ const forwardedIds = getForwardedIds ( ) ;
466+
473467 if ( state === undefined ) {
474- const forwardedIds = getRequestedIds ( ) ;
475468 if ( forwardedIds !== true && forwardedIds . size === 0 ) return ;
476469 modules . set ( module , {
477470 forwardedIds,
@@ -480,7 +473,6 @@ class LazyBarrelController {
480473 return ;
481474 }
482475
483- const forwardedIds = getRequestedIds ( ) ;
484476 if ( forwardedIds !== true && forwardedIds . size === 0 ) return ;
485477 if ( state . forwardedIds !== true ) {
486478 if ( forwardedIds === true ) state . forwardedIds = true ;
0 commit comments