fix some cases where undefined modules are used

This commit is contained in:
Tobias Koppers 2021-09-28 17:25:31 +02:00
parent daa2c3808e
commit 9e4c259cce
3 changed files with 26 additions and 19 deletions

View File

@ -340,15 +340,17 @@ CommonJsExportRequireDependency.Template = class CommonJsExportRequireDependency
weak: dep.weak, weak: dep.weak,
runtimeRequirements runtimeRequirements
}); });
const ids = dep.getIds(moduleGraph); if (importedModule) {
const usedImported = moduleGraph const ids = dep.getIds(moduleGraph);
.getExportsInfo(importedModule) const usedImported = moduleGraph
.getUsedName(ids, runtime); .getExportsInfo(importedModule)
if (usedImported) { .getUsedName(ids, runtime);
const comment = equals(usedImported, ids) if (usedImported) {
? "" const comment = equals(usedImported, ids)
: Template.toNormalComment(propertyAccess(ids)) + " "; ? ""
requireExpr += `${comment}${propertyAccess(usedImported)}`; : Template.toNormalComment(propertyAccess(ids)) + " ";
requireExpr += `${comment}${propertyAccess(usedImported)}`;
}
} }
switch (type) { switch (type) {

View File

@ -108,15 +108,17 @@ CommonJsFullRequireDependency.Template = class CommonJsFullRequireDependencyTemp
weak: dep.weak, weak: dep.weak,
runtimeRequirements runtimeRequirements
}); });
const ids = dep.names; if (importedModule) {
const usedImported = moduleGraph const ids = dep.names;
.getExportsInfo(importedModule) const usedImported = moduleGraph
.getUsedName(ids, runtime); .getExportsInfo(importedModule)
if (usedImported) { .getUsedName(ids, runtime);
const comment = equals(usedImported, ids) if (usedImported) {
? "" const comment = equals(usedImported, ids)
: Template.toNormalComment(propertyAccess(ids)) + " "; ? ""
requireExpr += `${comment}${propertyAccess(usedImported)}`; : Template.toNormalComment(propertyAccess(ids)) + " ";
requireExpr += `${comment}${propertyAccess(usedImported)}`;
}
} }
source.replace(dep.range[0], dep.range[1] - 1, requireExpr); source.replace(dep.range[0], dep.range[1] - 1, requireExpr);
} }

View File

@ -282,7 +282,10 @@ HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends
} }
const importStatement = dep.getImportStatement(false, templateContext); const importStatement = dep.getImportStatement(false, templateContext);
if (templateContext.moduleGraph.isAsync(referencedModule)) { if (
referencedModule &&
templateContext.moduleGraph.isAsync(referencedModule)
) {
templateContext.initFragments.push( templateContext.initFragments.push(
new ConditionalInitFragment( new ConditionalInitFragment(
importStatement[0], importStatement[0],