* Export from import. * @template GenerateContext * @param {object} options options * @param {ModuleGraph} options.moduleGraph the module graph * @param {ChunkGraph} options.chunkGraph the chunk graph * @param {Module} options.module the module * @param {string} options.request the reque
({
moduleGraph,
chunkGraph,
module,
request,
exportName,
originModule,
asiSafe,
isCall,
callContext,
defaultInterop,
importVar,
initFragments,
runtime,
runtimeRequirements,
dependency,
mangleableNamespace = false
})
| 1163 | * @returns {string} expression |
| 1164 | */ |
| 1165 | exportFromImport({ |
| 1166 | moduleGraph, |
| 1167 | chunkGraph, |
| 1168 | module, |
| 1169 | request, |
| 1170 | exportName, |
| 1171 | originModule, |
| 1172 | asiSafe, |
| 1173 | isCall, |
| 1174 | callContext, |
| 1175 | defaultInterop, |
| 1176 | importVar, |
| 1177 | initFragments, |
| 1178 | runtime, |
| 1179 | runtimeRequirements, |
| 1180 | dependency, |
| 1181 | mangleableNamespace = false |
| 1182 | }) { |
| 1183 | if (!module) { |
| 1184 | return this.missingModule({ |
| 1185 | request |
| 1186 | }); |
| 1187 | } |
| 1188 | if (!Array.isArray(exportName)) { |
| 1189 | exportName = exportName ? [exportName] : []; |
| 1190 | } |
| 1191 | const exportsType = module.getExportsType( |
| 1192 | moduleGraph, |
| 1193 | /** @type {BuildMeta} */ |
| 1194 | (originModule.buildMeta).strictHarmonyModule |
| 1195 | ); |
| 1196 | |
| 1197 | const isModuleDeferred = |
| 1198 | (dependency instanceof getHarmonyImportDependency() || |
| 1199 | dependency instanceof getImportDependency()) && |
| 1200 | ImportPhaseUtils.isDefer(dependency.phase) && |
| 1201 | !(/** @type {BuildMeta} */ (module.buildMeta).async); |
| 1202 | |
| 1203 | if (defaultInterop) { |
| 1204 | // when the defaultInterop is used (when a ESM imports a CJS module), |
| 1205 | if (exportName.length > 0 && exportName[0] === "default") { |
| 1206 | if (isModuleDeferred && exportsType !== "namespace") { |
| 1207 | const exportsInfo = moduleGraph.getExportsInfo(module); |
| 1208 | const name = exportName.slice(1); |
| 1209 | const used = exportsInfo.getUsedName(name, runtime); |
| 1210 | if (!used) { |
| 1211 | const comment = Template.toNormalComment( |
| 1212 | `unused export ${propertyAccess(exportName)}` |
| 1213 | ); |
| 1214 | return `${comment} undefined`; |
| 1215 | } |
| 1216 | if (used instanceof InlinedUsedName) { |
| 1217 | throw new Error( |
| 1218 | "Can't inline the exports of defer imported module" |
| 1219 | ); |
| 1220 | } |
| 1221 | const access = `${importVar}.a${propertyAccess(Array.isArray(used) ? used : [used])}`; |
| 1222 | if (isCall || asiSafe === undefined) { |
no test coverage detected