@@ -9,6 +9,7 @@ const AwaitDependenciesInitFragment = require("../../async-modules/AwaitDependen
99const isGeneratorLowered = require ( "../../async-modules/isGeneratorLowered" ) ;
1010const ESMLinkingError = require ( "../../errors/ESMLinkingError" ) ;
1111const Dependency = require ( "../../graph/Dependency" ) ;
12+ const LazyBarrels = require ( "../../optimize/LazyBarrels" ) ;
1213const ConditionalInitFragment = require ( "../../template/ConditionalInitFragment" ) ;
1314const InitFragment = require ( "../../template/InitFragment" ) ;
1415const Template = require ( "../../template/Template" ) ;
@@ -22,7 +23,7 @@ const ModuleDependency = require("../core/ModuleDependency");
2223 * JavascriptParserOptions
2324 * } from "../../../declarations/WebpackOptions"
2425 */
25- /** @import { ReferencedExports, DependencyKinds } from "../../graph/Dependency" */
26+ /** @import { ReferencedExports, DependencyKinds, LazyRole } from "../../graph/Dependency" */
2627/** @import { DependencyTemplateContext } from "../../template/DependencyTemplate" */
2728/** @import ExportsInfo from "../../graph/ExportsInfo" */
2829/** @import Module, { BuildMeta } from "../../module/Module" */
@@ -100,29 +101,22 @@ const getNonOptionalPart = (members, membersOptionals) => {
100101/**
101102 * Export names a lazy barrel still defers, so they are missing from its provided
102103 * exports without being absent from the module.
104+ * @param {ModuleGraph } moduleGraph the module graph
103105 * @param {Module } module the imported module
104106 * @returns {Set<string> | true | undefined } deferred names, true when a deferred star re-export may provide any name, undefined when none
105107 */
106- const getDeferredExports = ( module ) => {
108+ const getDeferredExports = ( moduleGraph , module ) => {
107109 const factoryMeta = module . factoryMeta ;
108110 if ( factoryMeta === undefined || ! factoryMeta . sideEffectFree ) return ;
109111 /** @type {Set<string> | undefined } */
110112 let names ;
111113 for ( const dep of module . dependencies ) {
112- // TODO in the next major release: remove
113- // These may be missing on custom dependency types not extending the base Dependency
114- if (
115- typeof dep . getLazyUntil !== "function" ||
116- typeof dep . isLazy !== "function"
117- ) {
118- continue ;
119- }
120- if ( ! dep . isLazy ( ) ) continue ;
121- const until = dep . getLazyUntil ( ) ;
122- if ( until === Dependency . LAZY_UNTIL_FALLBACK ) return true ;
123- if ( until !== Dependency . LAZY_UNTIL_ID ) continue ;
114+ if ( ! LazyBarrels . isLazy ( moduleGraph , dep ) ) continue ;
115+ const role = dep . lazyRole ;
116+ if ( role === Dependency . LAZY_STAR_REEXPORT ) return true ;
117+ if ( role !== Dependency . LAZY_NAMED_REEXPORT ) continue ;
124118 if ( names === undefined ) names = new Set ( ) ;
125- names . add ( /** @type {string } */ ( dep . getLazyName ( ) ) ) ;
119+ names . add ( /** @type {string } */ ( dep . lazyName ) ) ;
126120 }
127121 return names ;
128122} ;
@@ -146,28 +140,18 @@ class ESMImportDependency extends ModuleDependency {
146140 this . phase = phase ;
147141 /** @type {ImportAttributes | undefined } */
148142 this . attributes = attributes ;
149- /** @type {boolean } */
150- this . _lazyMake = false ;
151143 }
152144
153145 get category ( ) {
154146 return "esm" ;
155147 }
156148
157149 /**
158- * Whether the lazy barrel currently defers creating this dependency's target module (lazy barrel optimization).
159- * @returns {boolean } true while deferred, otherwise false
160- */
161- isLazy ( ) {
162- return this . _lazyMake ;
163- }
164-
165- /**
166- * Sets whether the lazy barrel defers creating this dependency's target module (lazy barrel optimization).
167- * @param {boolean } value true to defer, false to create it now
150+ * Returns how this dependency may be deferred when its parent module is side-effect-free (lazy barrel optimization).
151+ * @returns {LazyRole | null } lazy classification, null when it must be processed eagerly
168152 */
169- setLazy ( value ) {
170- this . _lazyMake = value ;
153+ get lazyRole ( ) {
154+ return Dependency . LAZY_IMPORT_DECLARATION ;
171155 }
172156
173157 /**
@@ -318,7 +302,7 @@ class ESMImportDependency extends ModuleDependency {
318302 ( exportsType !== "default-with-named" || ids [ 0 ] !== "default" ) &&
319303 moduleGraph . isExportProvided ( importedModule , ids ) === false
320304 ) {
321- const deferredExports = getDeferredExports ( importedModule ) ;
305+ const deferredExports = getDeferredExports ( moduleGraph , importedModule ) ;
322306
323307 if (
324308 deferredExports !== true &&
@@ -459,7 +443,7 @@ ESMImportDependency.Template = class ESMImportDependencyTemplate extends (
459443
460444 const connection = moduleGraph . getConnection ( dep ) ;
461445 // deferred by lazy barrel: never resolved, must not render a missing module
462- if ( connection === undefined && dep . isLazy ( ) ) {
446+ if ( connection === undefined && LazyBarrels . isLazy ( moduleGraph , dep ) ) {
463447 return ;
464448 }
465449 if ( connection && ! connection . isTargetActive ( runtime ) ) return ;
0 commit comments