@@ -71,7 +71,7 @@ const makeSerializable = require("./util/makeSerializable");
71
71
* @property {string= } exportsArgument
72
72
* @property {boolean= } strict
73
73
* @property {string= } moduleConcatenationBailout
74
- * @property {("default" | "namespace" | "flagged")= } exportsType
74
+ * @property {("default" | "namespace" | "flagged" | "dynamic" )= } exportsType
75
75
* @property {(false | "redirect" | "redirect-warn")= } defaultObject
76
76
* @property {boolean= } strictHarmonyModule
77
77
* @property {boolean= } async
@@ -263,6 +263,10 @@ class Module extends DependenciesBlock {
263
263
) . getUsedExports ( this , undefined ) ;
264
264
}
265
265
266
+ /**
267
+ * @deprecated
268
+ * @returns {(string | OptimizationBailoutFunction)[] } list
269
+ */
266
270
get optimizationBailout ( ) {
267
271
return ModuleGraph . getModuleGraphForModule (
268
272
this ,
@@ -372,14 +376,15 @@ class Module extends DependenciesBlock {
372
376
}
373
377
374
378
/**
379
+ * @param {ModuleGraph } moduleGraph the module graph
375
380
* @param {boolean } strict the importing module is strict
376
381
* @returns {"namespace" | "default-only" | "default-with-named" | "dynamic" } export type
377
382
* "namespace": Exports is already a namespace object. namespace = exports.
378
383
* "dynamic": Check at runtime if __esModule is set. When set: namespace = { ...exports, default: exports }. When not set: namespace = { default: exports }.
379
384
* "default-only": Provide a namespace object with only default export. namespace = { default: exports }
380
385
* "default-with-named": Provide a namespace object with named and default export. namespace = { ...exports, default: exports }
381
386
*/
382
- getExportsType ( strict ) {
387
+ getExportsType ( moduleGraph , strict ) {
383
388
switch ( this . buildMeta && this . buildMeta . exportsType ) {
384
389
case "flagged" :
385
390
return strict ? "default-only" : "namespace" ;
@@ -393,6 +398,44 @@ class Module extends DependenciesBlock {
393
398
default :
394
399
return "default-only" ;
395
400
}
401
+ case "dynamic" : {
402
+ if ( strict ) return "default-only" ;
403
+ // Try to figure out value of __esModule by following reexports
404
+ const handleDefault = ( ) => {
405
+ switch ( this . buildMeta . defaultObject ) {
406
+ case "redirect" :
407
+ case "redirect-warn" :
408
+ return "default-with-named" ;
409
+ default :
410
+ return "default-only" ;
411
+ }
412
+ } ;
413
+ const exportInfo = moduleGraph . getExportInfo ( this , "__esModule" ) ;
414
+ if ( exportInfo . provided === false ) {
415
+ return handleDefault ( ) ;
416
+ }
417
+ const target = exportInfo . getTarget ( moduleGraph ) ;
418
+ if (
419
+ ! target ||
420
+ ! target . export ||
421
+ target . export . length !== 1 ||
422
+ target . export [ 0 ] !== "__esModule"
423
+ ) {
424
+ return "dynamic" ;
425
+ }
426
+ switch (
427
+ target . module . buildMeta &&
428
+ target . module . buildMeta . exportsType
429
+ ) {
430
+ case "flagged" :
431
+ case "namespace" :
432
+ return "namespace" ;
433
+ case "default" :
434
+ return handleDefault ( ) ;
435
+ default :
436
+ return "dynamic" ;
437
+ }
438
+ }
396
439
default :
397
440
return strict ? "default-only" : "dynamic" ;
398
441
}
0 commit comments