Skip to content

Commit

Permalink
fix(types): fix some types
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Mar 21, 2024
2 parents ca234aa + 7b4775c commit 8ef7f91
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 94 deletions.
2 changes: 1 addition & 1 deletion lib/Compilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
/** @type {SyncHook<[Chunk, string]>} */
chunkAsset: new SyncHook(["chunk", "filename"]),

/** @type {SyncWaterfallHook<[string, object, AssetInfo]>} */
/** @type {SyncWaterfallHook<[string, object, AssetInfo | undefined]>} */
assetPath: new SyncWaterfallHook(["path", "options", "assetInfo"]),

/** @type {SyncBailHook<[], boolean>} */
Expand Down
2 changes: 1 addition & 1 deletion lib/Dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const memoize = require("./util/memoize");
* @property {number=} index
*/

/** @typedef {SyntheticDependencyLocation|RealDependencyLocation} DependencyLocation */
/** @typedef {SyntheticDependencyLocation | RealDependencyLocation} DependencyLocation */

/**
* @typedef {Object} ExportSpec
Expand Down
11 changes: 11 additions & 0 deletions lib/EvalDevToolModulePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const RuntimeGlobals = require("./RuntimeGlobals");
const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");

/** @typedef {import("webpack-sources").Source} Source */
/** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputOptions */
/** @typedef {import("./Compiler")} Compiler */

/** @type {WeakMap<Source, Source>} */
Expand All @@ -27,7 +28,17 @@ const devtoolWarning = new RawSource(`/*
*/
`);

/**
* @typedef {Object} EvalDevToolModulePluginOptions
* @property {OutputOptions["devtoolNamespace"]=} namespace namespace
* @property {string=} sourceUrlComment source url comment
* @property {OutputOptions["devtoolModuleFilenameTemplate"]=} moduleFilenameTemplate module filename template
*/

class EvalDevToolModulePlugin {
/**
* @param {EvalDevToolModulePluginOptions=} options options
*/
constructor(options) {
this.namespace = options.namespace || "";
this.sourceUrlComment = options.sourceUrlComment || "\n//# sourceURL=[url]";
Expand Down
4 changes: 4 additions & 0 deletions lib/ExportsInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ class ExportsInfo {
this._exportsAreOrdered = true;
}

/**
* @param {ExportsInfo | undefined} exportsInfo exports info
* @returns {boolean} result
*/
setRedirectNamedTo(exportsInfo) {
if (this._redirectTo === exportsInfo) return false;
this._redirectTo = exportsInfo;
Expand Down
4 changes: 3 additions & 1 deletion lib/ExternalModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,11 @@ const getSourceForDefaultCase = (optional, request, runtimeTemplate) => {
};
};

/** @typedef {Record<string, string | string[]>} RequestRecord */

class ExternalModule extends Module {
/**
* @param {string | string[] | Record<string, string | string[]>} request request
* @param {string | string[] | RequestRecord} request request
* @param {string} type type
* @param {string} userRequest user request
* @param {DependencyMeta=} dependencyMeta dependency meta
Expand Down
28 changes: 21 additions & 7 deletions lib/FlagDependencyExportsPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const Queue = require("./util/Queue");
/** @typedef {import("./Dependency").ExportsSpec} ExportsSpec */
/** @typedef {import("./ExportsInfo")} ExportsInfo */
/** @typedef {import("./Module")} Module */
/** @typedef {import("./Module").BuildInfo} BuildInfo */

const PLUGIN_NAME = "FlagDependencyExportsPlugin";
const PLUGIN_LOGGER_NAME = `webpack.${PLUGIN_NAME}`;
Expand Down Expand Up @@ -63,7 +64,10 @@ class FlagDependencyExportsPlugin {
}
}
// If the module has no hash, it's uncacheable
if (typeof module.buildInfo.hash !== "string") {
if (
typeof (/** @type {BuildInfo} */ (module.buildInfo).hash) !==
"string"
) {
statFlaggedUncached++;
// Enqueue uncacheable module for determining the exports
queue.enqueue(module);
Expand All @@ -79,7 +83,8 @@ class FlagDependencyExportsPlugin {
}
cache.get(
module.identifier(),
module.buildInfo.hash,
/** @type {BuildInfo} */
(module.buildInfo).hash,
(err, result) => {
if (err) return callback(err);

Expand Down Expand Up @@ -234,7 +239,10 @@ class FlagDependencyExportsPlugin {
if (exports) {
const nestedExportsInfo =
exportInfo.createNestedExportsInfo();
mergeExports(nestedExportsInfo, exports);
mergeExports(
/** @type {ExportsInfo} */ (nestedExportsInfo),
exports
);
}

if (
Expand Down Expand Up @@ -272,7 +280,8 @@ class FlagDependencyExportsPlugin {

if (exportInfo.exportsInfoOwned) {
if (
exportInfo.exportsInfo.setRedirectNamedTo(
/** @type {ExportsInfo} */
(exportInfo.exportsInfo).setRedirectNamedTo(
targetExportsInfo
)
) {
Expand Down Expand Up @@ -312,7 +321,7 @@ class FlagDependencyExportsPlugin {

logger.time("figure out provided exports");
while (queue.length > 0) {
module = queue.dequeue();
module = /** @type {Module} */ (queue.dequeue());

statQueueItemsProcessed++;

Expand Down Expand Up @@ -356,7 +365,11 @@ class FlagDependencyExportsPlugin {
asyncLib.each(
modulesToStore,
(module, callback) => {
if (typeof module.buildInfo.hash !== "string") {
if (
typeof (
/** @type {BuildInfo} */ (module.buildInfo).hash
) !== "string"
) {
// not cacheable
return callback();
}
Expand All @@ -370,7 +383,8 @@ class FlagDependencyExportsPlugin {
}
cache.store(
module.identifier(),
module.buildInfo.hash,
/** @type {BuildInfo} */
(module.buildInfo).hash,
cachedData,
callback
);
Expand Down
Loading

0 comments on commit 8ef7f91

Please sign in to comment.