feat: refactoring project
This commit is contained in:
60
node_modules/webpack/lib/dependencies/HarmonyImportSpecifierDependency.js
generated
vendored
60
node_modules/webpack/lib/dependencies/HarmonyImportSpecifierDependency.js
generated
vendored
@@ -42,7 +42,7 @@ const { ExportPresenceModes } = HarmonyImportDependency;
|
||||
|
||||
class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
||||
/**
|
||||
* @param {TODO} request request
|
||||
* @param {string} request request
|
||||
* @param {number} sourceOrder source order
|
||||
* @param {string[]} ids ids
|
||||
* @param {string} name name
|
||||
@@ -67,7 +67,6 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
||||
this.range = range;
|
||||
this.idRanges = idRanges;
|
||||
this.exportPresenceMode = exportPresenceMode;
|
||||
/** @type {boolean | undefined} */
|
||||
this.namespaceObjectAsContext = false;
|
||||
this.call = undefined;
|
||||
this.directImport = undefined;
|
||||
@@ -105,7 +104,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
||||
getIds(moduleGraph) {
|
||||
const meta = moduleGraph.getMetaIfExisting(this);
|
||||
if (meta === undefined) return this.ids;
|
||||
const ids = meta[idsSymbol];
|
||||
const ids = meta[/** @type {keyof object} */ (idsSymbol)];
|
||||
return ids !== undefined ? ids : this.ids;
|
||||
}
|
||||
|
||||
@@ -115,7 +114,8 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
||||
* @returns {void}
|
||||
*/
|
||||
setIds(moduleGraph, ids) {
|
||||
moduleGraph.getMeta(this)[idsSymbol] = ids;
|
||||
/** @type {TODO} */
|
||||
(moduleGraph.getMeta(this))[idsSymbol] = ids;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,7 +149,9 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
||||
if (ids.length === 0) return this._getReferencedExportsInDestructuring();
|
||||
let namespaceObjectAsContext = this.namespaceObjectAsContext;
|
||||
if (ids[0] === "default") {
|
||||
const selfModule = moduleGraph.getParentModule(this);
|
||||
const selfModule =
|
||||
/** @type {Module} */
|
||||
(moduleGraph.getParentModule(this));
|
||||
const importedModule =
|
||||
/** @type {Module} */
|
||||
(moduleGraph.getModule(this));
|
||||
@@ -196,9 +198,8 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
||||
refs.push(ids ? ids.concat([id]) : [id]);
|
||||
}
|
||||
return refs;
|
||||
} else {
|
||||
return ids ? [ids] : Dependency.EXPORTS_OBJECT_REFERENCED;
|
||||
}
|
||||
return ids ? [ids] : Dependency.EXPORTS_OBJECT_REFERENCED;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,9 +209,12 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
||||
_getEffectiveExportPresenceLevel(moduleGraph) {
|
||||
if (this.exportPresenceMode !== ExportPresenceModes.AUTO)
|
||||
return this.exportPresenceMode;
|
||||
const buildMeta = /** @type {BuildMeta} */ (
|
||||
moduleGraph.getParentModule(this).buildMeta
|
||||
);
|
||||
const buildMeta =
|
||||
/** @type {BuildMeta} */
|
||||
(
|
||||
/** @type {Module} */
|
||||
(moduleGraph.getParentModule(this)).buildMeta
|
||||
);
|
||||
return buildMeta.strictHarmonyModule
|
||||
? ExportPresenceModes.ERROR
|
||||
: ExportPresenceModes.WARN;
|
||||
@@ -344,14 +348,36 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
||||
}
|
||||
|
||||
if (dep.referencedPropertiesInDestructuring) {
|
||||
const prefixedIds = ids[0] === "default" ? ids.slice(1) : ids;
|
||||
for (let {
|
||||
let prefixedIds = ids;
|
||||
|
||||
if (ids[0] === "default") {
|
||||
const selfModule =
|
||||
/** @type {Module} */
|
||||
(moduleGraph.getParentModule(dep));
|
||||
const importedModule =
|
||||
/** @type {Module} */
|
||||
(moduleGraph.getModule(dep));
|
||||
const exportsType = importedModule.getExportsType(
|
||||
moduleGraph,
|
||||
/** @type {BuildMeta} */
|
||||
(selfModule.buildMeta).strictHarmonyModule
|
||||
);
|
||||
if (
|
||||
(exportsType === "default-only" ||
|
||||
exportsType === "default-with-named") &&
|
||||
ids.length >= 1
|
||||
) {
|
||||
prefixedIds = ids.slice(1);
|
||||
}
|
||||
}
|
||||
|
||||
for (const {
|
||||
id,
|
||||
shorthand,
|
||||
range
|
||||
} of dep.referencedPropertiesInDestructuring) {
|
||||
const concatedIds = prefixedIds.concat([id]);
|
||||
const module = moduleGraph.getModule(dep);
|
||||
const module = /** @type {Module} */ (moduleGraph.getModule(dep));
|
||||
const used = moduleGraph
|
||||
.getExportsInfo(module)
|
||||
.getUsedName(concatedIds, runtime);
|
||||
@@ -360,11 +386,13 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
||||
const name = concatedIds[concatedIds.length - 1];
|
||||
if (newName === name) continue;
|
||||
|
||||
const comment = Template.toNormalComment(name) + " ";
|
||||
const comment = `${Template.toNormalComment(name)} `;
|
||||
const key = comment + JSON.stringify(newName);
|
||||
source.replace(
|
||||
range[0],
|
||||
range[1] - 1,
|
||||
/** @type {Range} */
|
||||
(range)[0],
|
||||
/** @type {Range} */
|
||||
(range)[1] - 1,
|
||||
shorthand ? `${key}: ${name}` : `${key}`
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user