Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Feb 22, 2024
1 parent a1f46a9 commit 6ab9bda
Show file tree
Hide file tree
Showing 29 changed files with 650 additions and 233 deletions.
9 changes: 6 additions & 3 deletions declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ declare module "@webassemblyjs/ast" {
): void;
export class NodePath<T> {
node: T;
remove(): void;
}
export class Node {}
export class Identifier extends Node {
Expand All @@ -148,6 +149,7 @@ declare module "@webassemblyjs/ast" {
valtype?: string;
id?: Identifier;
signature?: Signature;
mutability: string;
}
export class ModuleImport extends Node {
module: string;
Expand All @@ -171,6 +173,7 @@ declare module "@webassemblyjs/ast" {
export class FloatLiteral extends Node {}
export class GlobalType extends Node {
valtype: string;
mutability: string;
}
export class Global extends Node {
init: Instruction[];
Expand Down Expand Up @@ -214,9 +217,9 @@ declare module "@webassemblyjs/ast" {
init: Node[]
): ObjectInstruction;
export function signature(params: FuncParam[], results: string[]): Signature;
export function func(initFuncId, signature: Signature, funcBody): Func;
export function func(initFuncId: Identifier, signature: Signature, funcBody: Instruction[]): Func;
export function typeInstruction(
id: Identifier,
id: Identifier | undefined,
functype: Signature
): TypeInstruction;
export function indexInFuncSection(index: Index): IndexInFuncSection;
Expand All @@ -229,7 +232,7 @@ declare module "@webassemblyjs/ast" {
index: Index
): ModuleExportDescr;

export function getSectionMetadata(ast: any, section: string);
export function getSectionMetadata(ast: any, section: string): { vectorOfSize: { value: number } };
export class FuncSignature {
args: string[];
result: string[];
Expand Down
6 changes: 6 additions & 0 deletions lib/Cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ const {
* @returns {void}
*/

/**
* @param {number} times times
* @param {function(Error=): void} callback callback
* @returns {function(Error=): void} callback
*/
const needCalls = (times, callback) => {
return err => {
if (--times === 0) {
Expand Down Expand Up @@ -71,6 +76,7 @@ class Cache {
* @returns {void}
*/
get(identifier, etag, callback) {
/** @type {GotHandler[]} */
const gotHandlers = [];
this.hooks.get.callAsync(identifier, etag, gotHandlers, (err, result) => {
if (err) {
Expand Down
56 changes: 45 additions & 11 deletions lib/Compilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const { isSourceEqual } = require("./util/source");
/** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
/** @typedef {import("./ModuleFactory")} ModuleFactory */
/** @typedef {import("./ModuleGraphConnection")} ModuleGraphConnection */
/** @typedef {import("./ModuleFactory").ModuleFactoryCreateDataContextInfo} ModuleFactoryCreateDataContextInfo */
/** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
/** @typedef {import("./RequestShortener")} RequestShortener */
Expand All @@ -113,9 +114,13 @@ const { isSourceEqual } = require("./util/source");
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsError} StatsError */
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModule} StatsModule */
/** @typedef {import("./util/Hash")} Hash */
/** @template T @typedef {import("./util/deprecation").FakeHook<T>} FakeHook<T> */
/**
* @template T
* @typedef {import("./util/deprecation").FakeHook<T>} FakeHook<T>
*/
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */

/** @typedef {WeakMap<Dependency, Module>} References */
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
/**
* @callback Callback
* @param {(WebpackError | null)=} err
Expand Down Expand Up @@ -824,7 +829,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
/** @type {AsyncSeriesHook<[CompilationAssets]>} */
processAdditionalAssets: new AsyncSeriesHook(["assets"]),

/** @type {SyncBailHook<[], boolean>} */
/** @type {SyncBailHook<[], boolean | undefined>} */
needAdditionalSeal: new SyncBailHook([]),
/** @type {AsyncSeriesHook<[]>} */
afterSeal: new AsyncSeriesHook([]),
Expand Down Expand Up @@ -878,7 +883,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
});
/** @type {string=} */
this.name = undefined;
/** @type {number | undefined} */
this.startTime = undefined;
/** @type {number | undefined} */
this.endTime = undefined;
/** @type {Compiler} */
this.compiler = compiler;
Expand Down Expand Up @@ -1345,6 +1352,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
* @returns {void}
*/
_buildModule(module, callback) {
/** @type {ModuleProfile | undefined} */
const currentProfile = this.profile
? this.moduleGraph.getProfile(module)
: undefined;
Expand Down Expand Up @@ -1375,7 +1383,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
this.options,
this,
this.resolverFactory.get("normal", module.resolveOptions),
this.inputFileSystem,
/** @type {InputFileSystem} */ (this.inputFileSystem),
err => {
if (currentProfile !== undefined) {
currentProfile.markBuildingEnd();
Expand Down Expand Up @@ -1418,6 +1426,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
* @returns {void}
*/
processModuleDependenciesNonRecursive(module) {
/**
* @param {DependenciesBlock} block block
*/
const processDependenciesBlock = block => {
if (block.dependencies) {
let i = 0;
Expand Down Expand Up @@ -1494,6 +1505,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
if (--inProgressTransitive === 0) onTransitiveTasksFinished();
};

/**
* @param {WebpackError=} err error
* @returns {void}
*/
const onTransitiveTasksFinished = err => {
if (err) return callback(err);
this.processDependenciesQueue.decreaseParallelism();
Expand Down Expand Up @@ -2264,6 +2279,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
});
}

/**
* @private
* @param {Module[]} modules modules
*/
_computeAffectedModules(modules) {
const moduleMemCacheCache = this.compiler.moduleMemCaches;
if (!moduleMemCacheCache) return;
Expand All @@ -2280,8 +2299,12 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
let statReferencesChanged = 0;
let statWithoutBuild = 0;

/**
* @param {Module} module module
* @returns {References | undefined} references
*/
const computeReferences = module => {
/** @type {WeakMap<Dependency, Module>} */
/** @type {References | undefined} */
let references = undefined;
for (const connection of moduleGraph.getOutgoingConnections(module)) {
const d = connection.dependency;
Expand All @@ -2295,7 +2318,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si

/**
* @param {Module} module the module
* @param {WeakMap<Dependency, Module>} references references
* @param {References | undefined} references references
* @returns {boolean} true, when the references differ
*/
const compareReferences = (module, references) => {
Expand Down Expand Up @@ -2367,6 +2390,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
}
}

/**
* @param {readonly ModuleGraphConnection[]} connections connections
* @returns {symbol|boolean} result
*/
const reduceAffectType = connections => {
let affected = false;
for (const { dependency } of connections) {
Expand Down Expand Up @@ -2897,12 +2924,12 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
Entrypoints that depend on other entrypoints do not have their own runtime.
They will use the runtime(s) from referenced entrypoints instead.
Remove the 'runtime' option from the entrypoint.`);
const entry = this.entrypoints.get(name);
const entry = /** @type {Entrypoint} */ (this.entrypoints.get(name));
err.chunk = entry.getEntrypointChunk();
this.errors.push(err);
}
if (dependOn) {
const entry = this.entrypoints.get(name);
const entry = /** @type {Entrypoint} */ (this.entrypoints.get(name));
const referencedChunks = entry
.getEntrypointChunk()
.getAllReferencedChunks();
Expand Down Expand Up @@ -2930,7 +2957,7 @@ Remove the 'runtime' option from the entrypoint.`);
connectChunkGroupParentAndChild(dependency, entry);
}
} else if (runtime) {
const entry = this.entrypoints.get(name);
const entry = /** @type {Entrypoint} */ (this.entrypoints.get(name));
let chunk = this.namedChunks.get(runtime);
if (chunk) {
if (!runtimeChunks.has(chunk)) {
Expand All @@ -2941,7 +2968,9 @@ Did you mean to use 'dependOn: ${JSON.stringify(
runtime
)}' instead to allow using entrypoint '${name}' within the runtime of entrypoint '${runtime}'? For this '${runtime}' must always be loaded when '${name}' is used.
Or do you want to use the entrypoints '${name}' and '${runtime}' independently on the same page with a shared runtime? In this case give them both the same value for the 'runtime' option. It must be a name not already used by an entrypoint.`);
const entryChunk = entry.getEntrypointChunk();
const entryChunk =
/** @type {Chunk} */
(entry.getEntrypointChunk());
err.chunk = entryChunk;
this.errors.push(err);
entry.setRuntimeChunk(entryChunk);
Expand Down Expand Up @@ -4589,6 +4618,10 @@ This prevents using hashes of each other and should be avoided.`);
let assetInfo;

let inTry = true;
/**
* @param {Error} err error
* @returns {void}
*/
const errorAndCallback = err => {
const filename =
file ||
Expand Down Expand Up @@ -5101,7 +5134,8 @@ This prevents using hashes of each other and should be avoided.`);
chunk
)) {
__webpack_require_module__(
moduleArgumentsMap.get(runtimeModule)
/** @type {ExecuteModuleArgument} */
(moduleArgumentsMap.get(runtimeModule))
);
}
exports = __webpack_require__(module.identifier());
Expand Down

0 comments on commit 6ab9bda

Please sign in to comment.