@@ -46,6 +46,7 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
4646 * ModuleRenderContext
4747 * } from "../javascript/JavascriptModulesPlugin"
4848 */
49+ /** @import { ImportAttributes } from "../javascript/JavascriptParser" */
4950/** @import { RuntimeSpec } from "../util/runtime" */
5051/**
5152 * @import {
@@ -124,6 +125,18 @@ const definesOnlyNativeExports = (module, moduleGraph) => {
124125const toExportName = ( name ) =>
125126 SAFE_IDENTIFIER . test ( name ) ? name : JSON . stringify ( name ) ;
126127
128+ /**
129+ * Renders the import attributes of a reexport in the syntax the author wrote,
130+ * since a legacy `assert` clause and a `with` clause are not interchangeable.
131+ * @param {ImportAttributes | undefined } attributes the import attributes
132+ * @returns {string } the attributes clause, empty when there are none
133+ */
134+ const toAttributesClause = ( attributes ) => {
135+ if ( ! attributes ) return "" ;
136+ const { _isLegacyAssert : isLegacyAssert , ...values } = attributes ;
137+ return ` ${ isLegacyAssert ? "assert" : "with" } ${ JSON . stringify ( values ) } ` ;
138+ } ;
139+
127140/**
128141 * Whether the export name can also be used as the declared binding name.
129142 * @param {string } name export name
@@ -473,7 +486,7 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
473486 ) {
474487 const result = new ConcatSource ( source ) ;
475488 /** @type {Set<string> } */
476- const moduleRequests = new Set ( ) ;
489+ const externalReexports = new Set ( ) ;
477490 /** @type {Map<string, string | InlinedUsedName> } */
478491 const unknownProvidedExports = new Map ( ) ;
479492 /** @type {Set<Module> } */
@@ -509,10 +522,16 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
509522 const request = importedModule . getResolvedRequest ( ) ;
510523 // A property path is reported by `_checkStarReexportedExternals`,
511524 // and an absent one by the external's own build
512- if ( typeof request === "string" ) {
513- moduleRequests . add ( request ) ;
514- } else if ( Array . isArray ( request ) && request . length === 1 ) {
515- moduleRequests . add ( request [ 0 ] ) ;
525+ const specifier =
526+ typeof request === "string"
527+ ? request
528+ : Array . isArray ( request ) && request . length === 1
529+ ? request [ 0 ]
530+ : undefined ;
531+ if ( specifier !== undefined ) {
532+ externalReexports . add (
533+ `export * from ${ toJsStringLiteral ( specifier ) } ${ toAttributesClause ( dep . attributes ) } ;\n`
534+ ) ;
516535 }
517536 } else if ( ! visitedReexportModules . has ( importedModule ) ) {
518537 visitedReexportModules . add ( importedModule ) ;
@@ -542,8 +561,8 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
542561
543562 resolveDynamicStarReexport ( module , false ) ;
544563
545- for ( const request of moduleRequests ) {
546- result . add ( `export * from ${ toJsStringLiteral ( request ) } ;\n` ) ;
564+ for ( const reexport of externalReexports ) {
565+ result . add ( reexport ) ;
547566 }
548567
549568 for ( const [ origin , used ] of unknownProvidedExports ) {
0 commit comments