Skip to content

Commit

Permalink
chore: improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Apr 21, 2023
1 parent 02590bf commit 4f6dc32
Show file tree
Hide file tree
Showing 54 changed files with 423 additions and 4 deletions.
8 changes: 8 additions & 0 deletions lib/Dependency.js
Expand Up @@ -17,6 +17,8 @@ const memoize = require("./util/memoize");
/** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
/** @typedef {import("./WebpackError")} WebpackError */
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
/** @typedef {import("./util/Hash")} Hash */
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */

Expand Down Expand Up @@ -292,6 +294,9 @@ class Dependency {
return getIgnoredModule();
}

/**
* @param {ObjectSerializerContext} context context
*/
serialize({ write }) {
write(this.weak);
write(this.optional);
Expand All @@ -303,6 +308,9 @@ class Dependency {
write(this._locN);
}

/**
* @param {ObjectDeserializerContext} context context
*/
deserialize({ read }) {
this.weak = read();
this.optional = read();
Expand Down
3 changes: 3 additions & 0 deletions lib/ExportsInfo.js
Expand Up @@ -752,6 +752,9 @@ class ExportsInfo {
);
}

/**
* @param {{ otherProvided: any, otherCanMangleProvide: any, otherTerminalBinding: any, exports: any }} data data
*/
restoreProvided({
otherProvided,
otherCanMangleProvide,
Expand Down
9 changes: 9 additions & 0 deletions lib/container/ContainerExposedDependency.js
Expand Up @@ -8,6 +8,9 @@
const ModuleDependency = require("../dependencies/ModuleDependency");
const makeSerializable = require("../util/makeSerializable");

/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */

class ContainerExposedDependency extends ModuleDependency {
/**
* @param {string} exposedName public name
Expand All @@ -33,11 +36,17 @@ class ContainerExposedDependency extends ModuleDependency {
return `exposed dependency ${this.exposedName}=${this.request}`;
}

/**
* @param {ObjectSerializerContext} context context
*/
serialize(context) {
context.write(this.exposedName);
super.serialize(context);
}

/**
* @param {ObjectDeserializerContext} context context
*/
deserialize(context) {
this.exposedName = context.read();
super.deserialize(context);
Expand Down
6 changes: 6 additions & 0 deletions lib/container/FallbackDependency.js
Expand Up @@ -8,6 +8,9 @@
const Dependency = require("../Dependency");
const makeSerializable = require("../util/makeSerializable");

/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */

class FallbackDependency extends Dependency {
constructor(requests) {
super();
Expand All @@ -29,6 +32,9 @@ class FallbackDependency extends Dependency {
return "esm";
}

/**
* @param {ObjectSerializerContext} context context
*/
serialize(context) {
const { write } = context;
write(this.requests);
Expand Down
8 changes: 8 additions & 0 deletions lib/dependencies/AMDDefineDependency.js
Expand Up @@ -12,6 +12,8 @@ const NullDependency = require("./NullDependency");
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
/** @typedef {import("../Dependency")} Dependency */
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */

/** @type {Record<string, { definition: string, content: string, requests: string[] }>} */
const DEFINITIONS = {
Expand Down Expand Up @@ -119,6 +121,9 @@ class AMDDefineDependency extends NullDependency {
return "amd define";
}

/**
* @param {ObjectSerializerContext} context context
*/
serialize(context) {
const { write } = context;
write(this.range);
Expand All @@ -130,6 +135,9 @@ class AMDDefineDependency extends NullDependency {
super.serialize(context);
}

/**
* @param {ObjectDeserializerContext} context context
*/
deserialize(context) {
const { read } = context;
this.range = read();
Expand Down
8 changes: 8 additions & 0 deletions lib/dependencies/AMDRequireArrayDependency.js
Expand Up @@ -12,6 +12,8 @@ const NullDependency = require("./NullDependency");
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
/** @typedef {import("../Dependency")} Dependency */
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */

class AMDRequireArrayDependency extends NullDependency {
constructor(depsArray, range) {
Expand All @@ -29,6 +31,9 @@ class AMDRequireArrayDependency extends NullDependency {
return "amd";
}

/**
* @param {ObjectSerializerContext} context context
*/
serialize(context) {
const { write } = context;

Expand All @@ -38,6 +43,9 @@ class AMDRequireArrayDependency extends NullDependency {
super.serialize(context);
}

/**
* @param {ObjectDeserializerContext} context context
*/
deserialize(context) {
const { read } = context;

Expand Down
9 changes: 9 additions & 0 deletions lib/dependencies/AMDRequireContextDependency.js
Expand Up @@ -8,6 +8,9 @@
const makeSerializable = require("../util/makeSerializable");
const ContextDependency = require("./ContextDependency");

/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */

class AMDRequireContextDependency extends ContextDependency {
constructor(options, range, valueRange) {
super(options);
Expand All @@ -24,6 +27,9 @@ class AMDRequireContextDependency extends ContextDependency {
return "amd";
}

/**
* @param {ObjectSerializerContext} context context
*/
serialize(context) {
const { write } = context;

Expand All @@ -33,6 +39,9 @@ class AMDRequireContextDependency extends ContextDependency {
super.serialize(context);
}

/**
* @param {ObjectDeserializerContext} context context
*/
deserialize(context) {
const { read } = context;

Expand Down
8 changes: 8 additions & 0 deletions lib/dependencies/AMDRequireDependency.js
Expand Up @@ -13,6 +13,8 @@ const NullDependency = require("./NullDependency");
/** @typedef {import("../AsyncDependenciesBlock")} AsyncDependenciesBlock */
/** @typedef {import("../Dependency")} Dependency */
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */

class AMDRequireDependency extends NullDependency {
constructor(outerRange, arrayRange, functionRange, errorCallbackRange) {
Expand All @@ -30,6 +32,9 @@ class AMDRequireDependency extends NullDependency {
return "amd";
}

/**
* @param {ObjectSerializerContext} context context
*/
serialize(context) {
const { write } = context;

Expand All @@ -43,6 +48,9 @@ class AMDRequireDependency extends NullDependency {
super.serialize(context);
}

/**
* @param {ObjectDeserializerContext} context context
*/
deserialize(context) {
const { read } = context;

Expand Down
8 changes: 8 additions & 0 deletions lib/dependencies/CachedConstDependency.js
Expand Up @@ -18,6 +18,8 @@ const NullDependency = require("./NullDependency");
/** @typedef {import("../DependencyTemplates")} DependencyTemplates */
/** @typedef {import("../ModuleGraph")} ModuleGraph */
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
/** @typedef {import("../util/Hash")} Hash */

class CachedConstDependency extends NullDependency {
Expand All @@ -42,6 +44,9 @@ class CachedConstDependency extends NullDependency {
hash.update(this._hashUpdate);
}

/**
* @param {ObjectSerializerContext} context context
*/
serialize(context) {
const { write } = context;

Expand All @@ -52,6 +57,9 @@ class CachedConstDependency extends NullDependency {
super.serialize(context);
}

/**
* @param {ObjectDeserializerContext} context context
*/
deserialize(context) {
const { read } = context;

Expand Down
8 changes: 8 additions & 0 deletions lib/dependencies/CommonJsExportRequireDependency.js
Expand Up @@ -22,6 +22,8 @@ const processExportInfo = require("./processExportInfo");
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
/** @typedef {import("../Module")} Module */
/** @typedef {import("../ModuleGraph")} ModuleGraph */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */

const idsSymbol = Symbol("CommonJsExportRequireDependency.ids");
Expand Down Expand Up @@ -270,6 +272,9 @@ class CommonJsExportRequireDependency extends ModuleDependency {
return { exports, checked };
}

/**
* @param {ObjectSerializerContext} context context
*/
serialize(context) {
const { write } = context;
write(this.asiSafe);
Expand All @@ -282,6 +287,9 @@ class CommonJsExportRequireDependency extends ModuleDependency {
super.serialize(context);
}

/**
* @param {ObjectDeserializerContext} context context
*/
deserialize(context) {
const { read } = context;
this.asiSafe = read();
Expand Down
8 changes: 8 additions & 0 deletions lib/dependencies/CommonJsExportsDependency.js
Expand Up @@ -16,6 +16,8 @@ const NullDependency = require("./NullDependency");
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
/** @typedef {import("../ModuleGraph")} ModuleGraph */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */

const EMPTY_OBJECT = {};

Expand Down Expand Up @@ -53,6 +55,9 @@ class CommonJsExportsDependency extends NullDependency {
};
}

/**
* @param {ObjectSerializerContext} context context
*/
serialize(context) {
const { write } = context;
write(this.range);
Expand All @@ -62,6 +67,9 @@ class CommonJsExportsDependency extends NullDependency {
super.serialize(context);
}

/**
* @param {ObjectDeserializerContext} context context
*/
deserialize(context) {
const { read } = context;
this.range = read();
Expand Down
8 changes: 8 additions & 0 deletions lib/dependencies/CommonJsFullRequireDependency.js
Expand Up @@ -16,6 +16,8 @@ const ModuleDependency = require("./ModuleDependency");
/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
/** @typedef {import("../ModuleGraph")} ModuleGraph */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */

class CommonJsFullRequireDependency extends ModuleDependency {
Expand Down Expand Up @@ -51,6 +53,9 @@ class CommonJsFullRequireDependency extends ModuleDependency {
return [this.names];
}

/**
* @param {ObjectSerializerContext} context context
*/
serialize(context) {
const { write } = context;
write(this.names);
Expand All @@ -59,6 +64,9 @@ class CommonJsFullRequireDependency extends ModuleDependency {
super.serialize(context);
}

/**
* @param {ObjectDeserializerContext} context context
*/
deserialize(context) {
const { read } = context;
this.names = read();
Expand Down
9 changes: 9 additions & 0 deletions lib/dependencies/CommonJsRequireContextDependency.js
Expand Up @@ -9,6 +9,9 @@ const makeSerializable = require("../util/makeSerializable");
const ContextDependency = require("./ContextDependency");
const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");

/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */

class CommonJsRequireContextDependency extends ContextDependency {
constructor(options, range, valueRange, inShorthand, context) {
super(options, context);
Expand All @@ -23,6 +26,9 @@ class CommonJsRequireContextDependency extends ContextDependency {
return "cjs require context";
}

/**
* @param {ObjectSerializerContext} context context
*/
serialize(context) {
const { write } = context;

Expand All @@ -33,6 +39,9 @@ class CommonJsRequireContextDependency extends ContextDependency {
super.serialize(context);
}

/**
* @param {ObjectDeserializerContext} context context
*/
deserialize(context) {
const { read } = context;

Expand Down
8 changes: 8 additions & 0 deletions lib/dependencies/CommonJsSelfReferenceDependency.js
Expand Up @@ -17,6 +17,8 @@ const NullDependency = require("./NullDependency");
/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
/** @typedef {import("../ModuleGraph")} ModuleGraph */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */

class CommonJsSelfReferenceDependency extends NullDependency {
Expand Down Expand Up @@ -53,6 +55,9 @@ class CommonJsSelfReferenceDependency extends NullDependency {
return [this.call ? this.names.slice(0, -1) : this.names];
}

/**
* @param {ObjectSerializerContext} context context
*/
serialize(context) {
const { write } = context;
write(this.range);
Expand All @@ -62,6 +67,9 @@ class CommonJsSelfReferenceDependency extends NullDependency {
super.serialize(context);
}

/**
* @param {ObjectDeserializerContext} context context
*/
deserialize(context) {
const { read } = context;
this.range = read();
Expand Down

0 comments on commit 4f6dc32

Please sign in to comment.