From 8614c75f1152f9a07d74efdc53b1d0e999c70382 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 20 Jul 2018 18:17:51 +0200 Subject: [PATCH] run inherit types tool on existing code --- lib/DelegatedModule.js | 5 +++++ lib/DependenciesBlock.js | 2 +- lib/DllModule.js | 6 ++++++ lib/ExternalModule.js | 6 ++++++ lib/Generator.js | 14 +++++++++++--- lib/Module.js | 5 +++++ lib/MultiModule.js | 6 ++++++ lib/NormalModule.js | 6 ++++++ lib/RuntimeTemplate.js | 12 ++++++++++++ lib/optimize/ConcatenatedModule.js | 5 +++++ lib/wasm/WebAssemblyGenerator.js | 18 ++++++++++++++++-- lib/wasm/WebAssemblyJavascriptGenerator.js | 18 ++++++++++++++++-- 12 files changed, 95 insertions(+), 8 deletions(-) diff --git a/lib/DelegatedModule.js b/lib/DelegatedModule.js index 09b6c1ebc..170ceca7a 100644 --- a/lib/DelegatedModule.js +++ b/lib/DelegatedModule.js @@ -12,6 +12,7 @@ const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDepende const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency"); /** @typedef {import("./dependencies/ModuleDependency")} ModuleDependency */ +/** @typedef {import("./util/createHash").Hash} Hash */ class DelegatedModule extends Module { constructor(sourceRequest, data, type, userRequest, originalRequest) { @@ -99,6 +100,10 @@ class DelegatedModule extends Module { return 42; } + /** + * @param {Hash} hash the hash used to track dependencies + * @returns {void} + */ updateHash(hash) { hash.update(this.type); hash.update(JSON.stringify(this.request)); diff --git a/lib/DependenciesBlock.js b/lib/DependenciesBlock.js index 144884fbb..142f3eacb 100644 --- a/lib/DependenciesBlock.js +++ b/lib/DependenciesBlock.js @@ -73,7 +73,7 @@ class DependenciesBlock { } /** - * @param {Hash} hash the hash used to track dependencies, from "crypto" module + * @param {Hash} hash the hash used to track dependencies * @returns {void} */ updateHash(hash) { diff --git a/lib/DllModule.js b/lib/DllModule.js index c0a45d731..0cd9cbcf8 100644 --- a/lib/DllModule.js +++ b/lib/DllModule.js @@ -7,6 +7,8 @@ const { RawSource } = require("webpack-sources"); const Module = require("./Module"); +/** @typedef {import("./util/createHash").Hash} Hash */ + class DllModule extends Module { constructor(context, dependencies, name, type) { super("javascript/dynamic", context); @@ -44,6 +46,10 @@ class DllModule extends Module { return 12; } + /** + * @param {Hash} hash the hash used to track dependencies + * @returns {void} + */ updateHash(hash) { hash.update("dll module"); hash.update(this.name || ""); diff --git a/lib/ExternalModule.js b/lib/ExternalModule.js index 98d1560b8..f306710e4 100644 --- a/lib/ExternalModule.js +++ b/lib/ExternalModule.js @@ -9,6 +9,8 @@ const Module = require("./Module"); const WebpackMissingModule = require("./dependencies/WebpackMissingModule"); const Template = require("./Template"); +/** @typedef {import("./util/createHash").Hash} Hash */ + class ExternalModule extends Module { constructor(request, type, userRequest) { super("javascript/dynamic", null); @@ -148,6 +150,10 @@ class ExternalModule extends Module { return 42; } + /** + * @param {Hash} hash the hash used to track dependencies + * @returns {void} + */ updateHash(hash) { hash.update(this.externalType); hash.update(JSON.stringify(this.request)); diff --git a/lib/Generator.js b/lib/Generator.js index 5c93506d4..655a9b1da 100644 --- a/lib/Generator.js +++ b/lib/Generator.js @@ -4,9 +4,10 @@ */ "use strict"; -/** @typedef {import("./Module")} Module */ +/** @typedef {import("./NormalModule")} NormalModule */ /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */ /** @typedef {import("webpack-sources").Source} Source */ +/** @typedef {import("./Dependency").DependencyTemplate} DependencyTemplate */ /** * @@ -18,8 +19,8 @@ class Generator { /** * @abstract - * @param {Module} module module for which the code should be generated - * @param {Map} dependencyTemplates mapping from dependencies to templates + * @param {NormalModule} module module for which the code should be generated + * @param {Map} dependencyTemplates mapping from dependencies to templates * @param {RuntimeTemplate} runtimeTemplate the runtime template * @param {string} type which kind of code should be generated * @returns {Source} generated code @@ -35,6 +36,13 @@ class ByTypeGenerator extends Generator { this.map = map; } + /** + * @param {NormalModule} module module for which the code should be generated + * @param {Map} dependencyTemplates mapping from dependencies to templates + * @param {RuntimeTemplate} runtimeTemplate the runtime template + * @param {string} type which kind of code should be generated + * @returns {Source} generated code + */ generate(module, dependencyTemplates, runtimeTemplate, type) { const generator = this.map[type]; if (!generator) { diff --git a/lib/Module.js b/lib/Module.js index 6af441559..7685740ab 100644 --- a/lib/Module.js +++ b/lib/Module.js @@ -14,6 +14,7 @@ const Template = require("./Template"); /** @typedef {import("./Chunk")} Chunk */ /** @typedef {import("./RequestShortener")} RequestShortener */ /** @typedef {import("./WebpackError")} WebpackError */ +/** @typedef {import("./util/createHash").Hash} Hash */ const EMPTY_RESOLVE_OPTIONS = {}; @@ -298,6 +299,10 @@ class Module extends DependenciesBlock { return true; } + /** + * @param {Hash} hash the hash used to track dependencies + * @returns {void} + */ updateHash(hash) { hash.update(`${this.id}`); hash.update(JSON.stringify(this.usedExports)); diff --git a/lib/MultiModule.js b/lib/MultiModule.js index 6aee82f66..c8e5d5757 100644 --- a/lib/MultiModule.js +++ b/lib/MultiModule.js @@ -8,6 +8,8 @@ const Module = require("./Module"); const Template = require("./Template"); const { RawSource } = require("webpack-sources"); +/** @typedef {import("./util/createHash").Hash} Hash */ + class MultiModule extends Module { constructor(context, dependencies, name) { super("javascript/dynamic", context); @@ -45,6 +47,10 @@ class MultiModule extends Module { return 16 + this.dependencies.length * 12; } + /** + * @param {Hash} hash the hash used to track dependencies + * @returns {void} + */ updateHash(hash) { hash.update("multi module"); hash.update(this.name || ""); diff --git a/lib/NormalModule.js b/lib/NormalModule.js index 9c5dff592..fdabc3000 100644 --- a/lib/NormalModule.js +++ b/lib/NormalModule.js @@ -24,6 +24,8 @@ const ModuleWarning = require("./ModuleWarning"); const createHash = require("./util/createHash"); const contextify = require("./util/identifier").contextify; +/** @typedef {import("./util/createHash").Hash} Hash */ + const asString = buf => { if (Buffer.isBuffer(buf)) { return buf.toString("utf-8"); @@ -527,6 +529,10 @@ class NormalModule extends Module { return this._source ? this._source.size() : -1; } + /** + * @param {Hash} hash the hash used to track dependencies + * @returns {void} + */ updateHash(hash) { hash.update(this._buildHash); super.updateHash(hash); diff --git a/lib/RuntimeTemplate.js b/lib/RuntimeTemplate.js index 5f06ed4af..613aed1c3 100644 --- a/lib/RuntimeTemplate.js +++ b/lib/RuntimeTemplate.js @@ -6,6 +6,8 @@ const Template = require("./Template"); +/** @typedef {import("./Module")} Module */ + module.exports = class RuntimeTemplate { constructor(outputOptions, requestShortener) { this.outputOptions = outputOptions || {}; @@ -188,6 +190,16 @@ module.exports = class RuntimeTemplate { return `${promise || "Promise.resolve()"}.then(${getModuleFunction})`; } + /** + * + * @param {Object} options options object + * @param {boolean=} options.update whether a new variable should be created or the existing one updated + * @param {Module} options.module the module + * @param {string} options.request the request that should be printed as comment + * @param {string} options.importVar name of the import variable + * @param {Module} options.originModule module in which the statement is emitted + * @returns {string} the import statement + */ importStatement({ update, module, request, importVar, originModule }) { if (!module) { return this.missingModuleStatement({ diff --git a/lib/optimize/ConcatenatedModule.js b/lib/optimize/ConcatenatedModule.js index 254ae090f..9e8586d2c 100644 --- a/lib/optimize/ConcatenatedModule.js +++ b/lib/optimize/ConcatenatedModule.js @@ -21,6 +21,7 @@ const createHash = require("../util/createHash"); /** @typedef {import("../Dependency")} Dependency */ /** @typedef {import("../Compilation")} Compilation */ +/** @typedef {import("../util/createHash").Hash} Hash */ /** * @typedef {Object} ConcatenationEntry @@ -1180,6 +1181,10 @@ class ConcatenatedModule extends Module { return nameWithNumber; } + /** + * @param {Hash} hash the hash used to track dependencies + * @returns {void} + */ updateHash(hash) { for (const info of this._orderedConcatenationList) { switch (info.type) { diff --git a/lib/wasm/WebAssemblyGenerator.js b/lib/wasm/WebAssemblyGenerator.js index beafd9c46..2a0395227 100644 --- a/lib/wasm/WebAssemblyGenerator.js +++ b/lib/wasm/WebAssemblyGenerator.js @@ -21,6 +21,10 @@ const WebAssemblyExportImportedDependency = require("../dependencies/WebAssembly /** @typedef {import("../Module")} Module */ /** @typedef {import("./WebAssemblyUtils").UsedWasmDependency} UsedWasmDependency */ +/** @typedef {import("../NormalModule")} NormalModule */ +/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */ +/** @typedef {import("webpack-sources").Source} Source */ +/** @typedef {import("../Dependency").DependencyTemplate} DependencyTemplate */ /** * @typedef {(ArrayBuffer) => ArrayBuffer} ArrayBufferTransform @@ -366,7 +370,14 @@ class WebAssemblyGenerator extends Generator { this.options = options; } - generate(module) { + /** + * @param {NormalModule} module module for which the code should be generated + * @param {Map} dependencyTemplates mapping from dependencies to templates + * @param {RuntimeTemplate} runtimeTemplate the runtime template + * @param {string} type which kind of code should be generated + * @returns {Source} generated code + */ + generate(module, dependencyTemplates, runtimeTemplate, type) { let bin = module.originalSource().source(); bin = preprocess(bin); @@ -398,7 +409,10 @@ class WebAssemblyGenerator extends Generator { const externalExports = new Set( module.dependencies .filter(d => d instanceof WebAssemblyExportImportedDependency) - .map(d => d.exportName) + .map(d => { + const wasmDep = /** @type {WebAssemblyExportImportedDependency} */ (d); + return wasmDep.exportName; + }) ); /** @type {t.Instruction[]} */ diff --git a/lib/wasm/WebAssemblyJavascriptGenerator.js b/lib/wasm/WebAssemblyJavascriptGenerator.js index 994036d36..b164a0292 100644 --- a/lib/wasm/WebAssemblyJavascriptGenerator.js +++ b/lib/wasm/WebAssemblyJavascriptGenerator.js @@ -10,8 +10,20 @@ const { RawSource } = require("webpack-sources"); const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency"); const WebAssemblyExportImportedDependency = require("../dependencies/WebAssemblyExportImportedDependency"); +/** @typedef {import("../NormalModule")} NormalModule */ +/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */ +/** @typedef {import("webpack-sources").Source} Source */ +/** @typedef {import("../Dependency").DependencyTemplate} DependencyTemplate */ + class WebAssemblyJavascriptGenerator extends Generator { - generate(module, dependencyTemplates, runtimeTemplate) { + /** + * @param {NormalModule} module module for which the code should be generated + * @param {Map} dependencyTemplates mapping from dependencies to templates + * @param {RuntimeTemplate} runtimeTemplate the runtime template + * @param {string} type which kind of code should be generated + * @returns {Source} generated code + */ + generate(module, dependencyTemplates, runtimeTemplate, type) { const initIdentifer = Array.isArray(module.usedExports) ? Template.numberToIdentifer(module.usedExports.length) : "__webpack_init__"; @@ -21,6 +33,7 @@ class WebAssemblyJavascriptGenerator extends Generator { const initParams = []; let index = 0; for (const dep of module.dependencies) { + const depAsAny = /** @type {any} */ (dep); if (dep.module) { let importData = importedModules.get(dep.module); if (importData === undefined) { @@ -29,7 +42,8 @@ class WebAssemblyJavascriptGenerator extends Generator { (importData = { importVar: `m${index}`, index, - request: dep.userRequest, + request: + "userRequest" in depAsAny ? depAsAny.userRequest : undefined, names: new Set(), reexports: [] })