refactor: avoid unnecessary the `defer` property for dependency (#19893)

This commit is contained in:
Alexander Akait 2025-09-10 01:43:17 +03:00 committed by GitHub
parent 930785fb00
commit 95ce962897
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 9 additions and 9 deletions

View File

@ -107,9 +107,6 @@ class Dependency {
this.weak = false;
// TODO check if this can be moved into ModuleDependency
/** @type {boolean | undefined} */
this.defer = false;
// TODO check if this can be moved into ModuleDependency
/** @type {boolean | undefined} */
this.optional = false;
this._locSL = 0;
this._locSC = 0;
@ -317,7 +314,6 @@ class Dependency {
write(this._locEC);
write(this._locI);
write(this._locN);
write(this.defer);
}
/**
@ -332,7 +328,6 @@ class Dependency {
this._locEC = read();
this._locI = read();
this._locN = read();
this.defer = read();
}
}

View File

@ -13,6 +13,7 @@ const { forEachRuntime } = require("./util/runtime");
/** @typedef {import("./Dependency")} Dependency */
/** @typedef {import("./Dependency").RuntimeSpec} RuntimeSpec */
/** @typedef {import("./Dependency").ExportsSpecExcludeExports} ExportsSpecExcludeExports */
/** @typedef {import("./dependencies/HarmonyImportDependency")} HarmonyImportDependency */
/** @typedef {import("./Module")} Module */
/** @typedef {import("./ModuleGraph")} ModuleGraph */
/** @typedef {import("./ModuleGraphConnection")} ModuleGraphConnection */
@ -1341,7 +1342,9 @@ class ExportInfo {
module: rawTarget.connection.module,
export: rawTarget.export,
deferred: Boolean(
rawTarget.connection.dependency && rawTarget.connection.dependency.defer
rawTarget.connection.dependency &&
/** @type {HarmonyImportDependency} */
(rawTarget.connection.dependency).defer
)
};
for (;;) {

View File

@ -120,7 +120,7 @@ HarmonyAcceptDependency.Template = class HarmonyAcceptDependencyTemplate extends
for (const d of module.dependencies) {
if (deferDependency && noDeferredDependency) break;
if (isRelatedHarmonyImportDependency(dependency, d)) {
if (d.defer) {
if (/** @type {HarmonyImportDependency} */ (d).defer) {
deferDependency = /** @type {HarmonyImportDependency} */ (d);
} else {
noDeferredDependency = /** @type {HarmonyImportDependency} */ (d);

View File

@ -280,6 +280,7 @@ class HarmonyImportDependency extends ModuleDependency {
const { write } = context;
write(this.sourceOrder);
write(this.assertions);
write(this.defer);
super.serialize(context);
}
@ -290,6 +291,7 @@ class HarmonyImportDependency extends ModuleDependency {
const { read } = context;
this.sourceOrder = read();
this.assertions = read();
this.defer = read();
super.deserialize(context);
}
}

View File

@ -1860,7 +1860,7 @@ ${defineGetters}`
if (deferEnabled) {
for (const dep of info.module.dependencies) {
if (
!dep.defer &&
!(/** @type {HarmonyImportDependency} */ (dep).defer) &&
dep instanceof HarmonyImportSideEffectDependency
) {
const referredModule = moduleGraph.getModule(dep);

2
types.d.ts vendored
View File

@ -3825,7 +3825,6 @@ declare interface DependenciesBlockLike {
declare class Dependency {
constructor();
weak: boolean;
defer?: boolean;
optional?: boolean;
get type(): string;
get category(): string;
@ -6098,6 +6097,7 @@ declare class HarmonyImportDependency extends ModuleDependency {
defer?: boolean
);
sourceOrder: number;
defer?: boolean;
getImportVar(moduleGraph: ModuleGraph): string;
getModuleExports(__0: DependencyTemplateContext): string;
getImportStatement(