diff --git a/eslint.config.js b/eslint.config.js index c2096cc4d..abf7421d4 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -112,6 +112,7 @@ module.exports = [ "object-shorthand": "error", "no-else-return": "error", "no-lonely-if": "error", + "no-undef-init": "error", "n/no-missing-require": ["error", { allowModules: ["webpack"] }], "n/no-unsupported-features/node-builtins": [ "error", @@ -182,6 +183,7 @@ module.exports = [ rules: { "prefer-const": "off", "object-shorthand": "off", + "no-undef-init": "off", "n/exports-style": "off" } }, @@ -231,5 +233,11 @@ module.exports = [ rules: { "n/no-missing-require": "off" } + }, + { + files: ["lib/util/semver.js"], + rules: { + "n/exports-style": "off" + } } ]; diff --git a/lib/CleanPlugin.js b/lib/CleanPlugin.js index 175bf5ca0..5c15b3282 100644 --- a/lib/CleanPlugin.js +++ b/lib/CleanPlugin.js @@ -7,7 +7,7 @@ const asyncLib = require("neo-async"); const { SyncBailHook } = require("tapable"); -const Compilation = require("../lib/Compilation"); +const Compilation = require("./Compilation"); const createSchemaValidation = require("./util/create-schema-validation"); const { join } = require("./util/fs"); const processAsyncTree = require("./util/processAsyncTree"); diff --git a/lib/Compilation.js b/lib/Compilation.js index 5559f6e6c..d6dc5f524 100644 --- a/lib/Compilation.js +++ b/lib/Compilation.js @@ -448,7 +448,7 @@ class Compilation { * @returns {CompilationAssets} new assets */ const popNewAssets = assets => { - let newAssets = undefined; + let newAssets; for (const file of Object.keys(assets)) { if (savedAssets.has(file)) continue; if (newAssets === undefined) { @@ -1960,7 +1960,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si callback ) { // Check for cycles when build is trigger inside another build - let creatingModuleDuringBuildSet = undefined; + let creatingModuleDuringBuildSet; if (checkCycle && this.buildQueue.isProcessing(originModule)) { // Track build dependency creatingModuleDuringBuildSet = @@ -2361,7 +2361,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si */ const computeReferences = module => { /** @type {References | undefined} */ - let references = undefined; + let references; for (const connection of moduleGraph.getOutgoingConnections(module)) { const d = connection.dependency; const m = connection.module; @@ -2530,9 +2530,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si const computeReferences = module => { const id = chunkGraph.getModuleId(module); /** @type {Map | undefined} */ - let modules = undefined; + let modules; /** @type {(string | number | null)[] | undefined} */ - let blocks = undefined; + let blocks; const outgoing = moduleGraph.getOutgoingConnectionsByModule(module); if (outgoing !== undefined) { for (const m of outgoing.keys()) { @@ -3328,7 +3328,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o /** @type {WebpackError[]} */ const errors = []; /** @type {NotCodeGeneratedModules | undefined} */ - let notCodeGeneratedModules = undefined; + let notCodeGeneratedModules; const runIteration = () => { /** @type {CodeGenerationJobs} */ let delayedJobs = []; diff --git a/lib/Compiler.js b/lib/Compiler.js index efbd18528..25d46840d 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -14,7 +14,7 @@ const { AsyncSeriesHook } = require("tapable"); const { SizeOnlySource } = require("webpack-sources"); -const webpack = require("./"); +const webpack = require("."); const Cache = require("./Cache"); const CacheFacade = require("./CacheFacade"); const ChunkGraph = require("./ChunkGraph"); diff --git a/lib/ExternalModule.js b/lib/ExternalModule.js index 6dcd6b716..5fbe58ba7 100644 --- a/lib/ExternalModule.js +++ b/lib/ExternalModule.js @@ -846,7 +846,7 @@ class ExternalModule extends Module { if (sourceData.init) sourceString = `${sourceData.init}\n${sourceString}`; - let data = undefined; + let data; if (sourceData.chunkInitFragments) { data = new Map(); data.set("chunkInitFragments", sourceData.chunkInitFragments); diff --git a/lib/FileSystemInfo.js b/lib/FileSystemInfo.js index f110751f3..bd486192e 100644 --- a/lib/FileSystemInfo.js +++ b/lib/FileSystemInfo.js @@ -573,7 +573,7 @@ class SnapshotOptimization { }; /** @type {SnapshotOptimizationEntry | undefined} */ - let newOptimizationEntry = undefined; + let newOptimizationEntry; const capturedFilesSize = capturedFiles.size; @@ -2501,7 +2501,7 @@ class FileSystemInfo { */ _checkSnapshotValidNoCache(snapshot, callback) { /** @type {number | undefined} */ - let startTime = undefined; + let startTime; if (snapshot.hasStartTime()) { startTime = snapshot.startTime; } @@ -3181,7 +3181,7 @@ class FileSystemInfo { }); }, reduce: (files, tsEntries) => { - let symlinks = undefined; + let symlinks; const hash = createHash(this._hashFunction); @@ -3306,7 +3306,7 @@ class FileSystemInfo { * @returns {ContextHash} reduced hash */ reduce: (files, fileHashes) => { - let symlinks = undefined; + let symlinks; const hash = createHash(this._hashFunction); for (const file of files) hash.update(file); @@ -3437,7 +3437,7 @@ class FileSystemInfo { * @returns {ContextTimestampAndHash} tsh */ reduce: (files, results) => { - let symlinks = undefined; + let symlinks; const tsHash = createHash(this._hashFunction); const hash = createHash(this._hashFunction); diff --git a/lib/FlagAllModulesAsUsedPlugin.js b/lib/FlagAllModulesAsUsedPlugin.js index a7a3625d3..eb3ee4cf4 100644 --- a/lib/FlagAllModulesAsUsedPlugin.js +++ b/lib/FlagAllModulesAsUsedPlugin.js @@ -30,7 +30,7 @@ class FlagAllModulesAsUsedPlugin { const moduleGraph = compilation.moduleGraph; compilation.hooks.optimizeDependencies.tap(PLUGIN_NAME, modules => { /** @type {RuntimeSpec} */ - let runtime = undefined; + let runtime; for (const [name, { options }] of compilation.entries) { runtime = mergeRuntimeOwned( runtime, diff --git a/lib/FlagDependencyExportsPlugin.js b/lib/FlagDependencyExportsPlugin.js index 830b3f1d0..d2cd77fda 100644 --- a/lib/FlagDependencyExportsPlugin.js +++ b/lib/FlagDependencyExportsPlugin.js @@ -189,9 +189,9 @@ class FlagDependencyExportsPlugin { let name; let canMangle = globalCanMangle; let terminalBinding = globalTerminalBinding; - let exports = undefined; + let exports; let from = globalFrom; - let fromExport = undefined; + let fromExport; let priority = globalPriority; let hidden = false; if (typeof exportNameOrSpec === "string") { @@ -261,7 +261,7 @@ class FlagDependencyExportsPlugin { // Recalculate target exportsInfo const target = exportInfo.getTarget(moduleGraph); - let targetExportsInfo = undefined; + let targetExportsInfo; if (target) { const targetModuleExportsInfo = moduleGraph.getExportsInfo(target.module); diff --git a/lib/FlagDependencyUsagePlugin.js b/lib/FlagDependencyUsagePlugin.js index 3b6424052..247dbf905 100644 --- a/lib/FlagDependencyUsagePlugin.js +++ b/lib/FlagDependencyUsagePlugin.js @@ -308,7 +308,7 @@ class FlagDependencyUsagePlugin { } }; /** @type {RuntimeSpec} */ - let globalRuntime = undefined; + let globalRuntime; for (const [ entryName, { dependencies: deps, includeDependencies: includeDeps, options } diff --git a/lib/ModuleBuildError.js b/lib/ModuleBuildError.js index a24cfda1b..edeb86109 100644 --- a/lib/ModuleBuildError.js +++ b/lib/ModuleBuildError.js @@ -19,7 +19,7 @@ class ModuleBuildError extends WebpackError { */ constructor(err, { from = null } = {}) { let message = "Module build failed"; - let details = undefined; + let details; if (from) { message += ` (from ${from}):\n`; diff --git a/lib/ModuleGraph.js b/lib/ModuleGraph.js index 64e7daa7d..b6cda609c 100644 --- a/lib/ModuleGraph.js +++ b/lib/ModuleGraph.js @@ -36,7 +36,7 @@ const getConnectionsByOriginModule = set => { /** @type {Module | 0} */ let lastModule = 0; /** @type {ModuleGraphConnection[] | undefined} */ - let lastList = undefined; + let lastList; for (const connection of set) { const { originModule } = connection; if (lastModule === originModule) { @@ -67,7 +67,7 @@ const getConnectionsByModule = set => { /** @type {Module | 0} */ let lastModule = 0; /** @type {ModuleGraphConnection[] | undefined} */ - let lastList = undefined; + let lastList; for (const connection of set) { const { module } = connection; if (lastModule === module) { diff --git a/lib/ModuleParseError.js b/lib/ModuleParseError.js index 5ffbeb851..98adea393 100644 --- a/lib/ModuleParseError.js +++ b/lib/ModuleParseError.js @@ -22,7 +22,7 @@ class ModuleParseError extends WebpackError { */ constructor(source, err, loaders, type) { let message = "Module parse failed: " + (err && err.message); - let loc = undefined; + let loc; if ( ((Buffer.isBuffer(source) && source.slice(0, 4).equals(WASM_HEADER)) || diff --git a/lib/NormalModule.js b/lib/NormalModule.js index 83a39e6b4..010c6cdb0 100644 --- a/lib/NormalModule.js +++ b/lib/NormalModule.js @@ -1138,7 +1138,7 @@ class NormalModule extends Module { // add warning for all non-absolute paths in fileDependencies, etc // This makes it easier to find problems with watching and/or caching /** @type {undefined | Set} */ - let nonAbsoluteDependencies = undefined; + let nonAbsoluteDependencies; /** * @param {LazySet} deps deps */ diff --git a/lib/NormalModuleFactory.js b/lib/NormalModuleFactory.js index b621b3d20..58c8db125 100644 --- a/lib/NormalModuleFactory.js +++ b/lib/NormalModuleFactory.js @@ -426,7 +426,7 @@ class NormalModuleFactory extends ModuleFactory { const loaderResolver = this.getResolver("loader"); /** @type {ResourceData | undefined} */ - let matchResourceData = undefined; + let matchResourceData; /** @type {string} */ let unresolvedResource; /** @type {ParsedLoaderRequest[]} */ diff --git a/lib/Watching.js b/lib/Watching.js index b5c1a9b8c..44cc7c765 100644 --- a/lib/Watching.js +++ b/lib/Watching.js @@ -255,7 +255,7 @@ class Watching { (compilation && compilation.getLogger("webpack.Watching")); /** @type {Stats | undefined} */ - let stats = undefined; + let stats; /** * @param {Error} err error diff --git a/lib/asset/AssetModulesPlugin.js b/lib/asset/AssetModulesPlugin.js index f77fc8288..5a49989d3 100644 --- a/lib/asset/AssetModulesPlugin.js +++ b/lib/asset/AssetModulesPlugin.js @@ -137,7 +137,7 @@ class AssetModulesPlugin { .tap(plugin, generatorOptions => { validateGeneratorOptions[type](generatorOptions); - let dataUrl = undefined; + let dataUrl; if (type !== ASSET_MODULE_TYPE_RESOURCE) { dataUrl = generatorOptions.dataUrl; if (!dataUrl || typeof dataUrl === "object") { @@ -149,9 +149,9 @@ class AssetModulesPlugin { } } - let filename = undefined; - let publicPath = undefined; - let outputPath = undefined; + let filename; + let publicPath; + let outputPath; if (type !== ASSET_MODULE_TYPE_INLINE) { filename = generatorOptions.filename; publicPath = generatorOptions.publicPath; diff --git a/lib/cache/IdleFileCachePlugin.js b/lib/cache/IdleFileCachePlugin.js index 4fe7e9e5a..083ded64c 100644 --- a/lib/cache/IdleFileCachePlugin.js +++ b/lib/cache/IdleFileCachePlugin.js @@ -175,7 +175,7 @@ class IdleFileCachePlugin { } }; /** @type {ReturnType | undefined} */ - let idleTimer = undefined; + let idleTimer; compiler.cache.hooks.beginIdle.tap( { name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK }, () => { diff --git a/lib/cache/PackFileCacheStrategy.js b/lib/cache/PackFileCacheStrategy.js index 4666b7f8e..d7e8f69d5 100644 --- a/lib/cache/PackFileCacheStrategy.js +++ b/lib/cache/PackFileCacheStrategy.js @@ -527,7 +527,7 @@ class Pack { */ _gcOldestContent() { /** @type {PackItemInfo | undefined} */ - let oldest = undefined; + let oldest; for (const info of this.itemInfo.values()) { if (oldest === undefined || info.lastAccess < oldest.lastAccess) { oldest = info; diff --git a/lib/config/defaults.js b/lib/config/defaults.js index e5e54b446..05f53b708 100644 --- a/lib/config/defaults.js +++ b/lib/config/defaults.js @@ -124,7 +124,7 @@ const A = (obj, prop, factory) => { obj[prop] = factory(); } else if (Array.isArray(value)) { /** @type {any[] | undefined} */ - let newArray = undefined; + let newArray; for (let i = 0; i < value.length; i++) { const item = value[i]; if (item === "...") { diff --git a/lib/css/CssModulesPlugin.js b/lib/css/CssModulesPlugin.js index c4db8ad3d..185e8db30 100644 --- a/lib/css/CssModulesPlugin.js +++ b/lib/css/CssModulesPlugin.js @@ -508,7 +508,7 @@ class CssModulesPlugin { } /** @type {Module} */ let selectedModule = list[list.length - 1]; - let hasFailed = undefined; + let hasFailed; outer: for (;;) { for (const { list, set } of modulesByChunkGroup) { if (list.length === 0) continue; diff --git a/lib/css/CssParser.js b/lib/css/CssParser.js index 594db2325..297918abb 100644 --- a/lib/css/CssParser.js +++ b/lib/css/CssParser.js @@ -201,13 +201,13 @@ class CssParser extends Parser { /** @type {boolean} */ let allowImportAtRule = true; /** @type {"local" | "global" | undefined} */ - let modeData = undefined; + let modeData; /** @type {[number, number] | undefined} */ - let lastIdentifier = undefined; + let lastIdentifier; /** @type [string, number, number][] */ const balanced = []; /** @type {undefined | { start: number, url?: string, urlStart?: number, urlEnd?: number, layer?: string, layerStart?: number, layerEnd?: number, supports?: string, supportsStart?: number, supportsEnd?: number, inSupports?:boolean, media?: string }} */ - let importData = undefined; + let importData; /** @type {boolean} */ let inAnimationProperty = false; /** @type {boolean} */ diff --git a/lib/debug/ProfilingPlugin.js b/lib/debug/ProfilingPlugin.js index b45ed78ba..f76e51eec 100644 --- a/lib/debug/ProfilingPlugin.js +++ b/lib/debug/ProfilingPlugin.js @@ -36,7 +36,7 @@ const validate = createSchemaValidation( ); /** @type {Inspector | undefined} */ -let inspector = undefined; +let inspector; try { // eslint-disable-next-line n/no-unsupported-features/node-builtins diff --git a/lib/dependencies/CommonJsDependencyHelpers.js b/lib/dependencies/CommonJsDependencyHelpers.js index e7dffa4d1..0cd457ee7 100644 --- a/lib/dependencies/CommonJsDependencyHelpers.js +++ b/lib/dependencies/CommonJsDependencyHelpers.js @@ -22,7 +22,7 @@ module.exports.handleDependencyBase = ( module, runtimeRequirements ) => { - let base = undefined; + let base; let type; switch (depBase) { case "exports": diff --git a/lib/dependencies/CommonJsSelfReferenceDependency.js b/lib/dependencies/CommonJsSelfReferenceDependency.js index 2aef8cec7..892ae2164 100644 --- a/lib/dependencies/CommonJsSelfReferenceDependency.js +++ b/lib/dependencies/CommonJsSelfReferenceDependency.js @@ -120,7 +120,7 @@ CommonJsSelfReferenceDependency.Template = class CommonJsSelfReferenceDependency ); } - let base = undefined; + let base; switch (dep.base) { case "exports": runtimeRequirements.add(RuntimeGlobals.exports); diff --git a/lib/dependencies/HarmonyExportImportedSpecifierDependency.js b/lib/dependencies/HarmonyExportImportedSpecifierDependency.js index 1b211436b..bc6a3e633 100644 --- a/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +++ b/lib/dependencies/HarmonyExportImportedSpecifierDependency.js @@ -444,7 +444,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency { const ignoredExports = new Set(["default", ...this.activeExports]); - let hiddenExports = undefined; + let hiddenExports; const otherStarExports = this._discoverActiveExportsFromOtherStarExports(moduleGraph); if (otherStarExports !== undefined) { diff --git a/lib/javascript/JavascriptParser.js b/lib/javascript/JavascriptParser.js index 05bafbe8c..4009a8f24 100644 --- a/lib/javascript/JavascriptParser.js +++ b/lib/javascript/JavascriptParser.js @@ -1210,9 +1210,9 @@ class JavascriptParser extends Parser { */ const tapEvaluateWithVariableInfo = (exprType, getInfo) => { /** @type {Expression | undefined} */ - let cachedExpression = undefined; + let cachedExpression; /** @type {GetInfoResult | undefined} */ - let cachedInfo = undefined; + let cachedInfo; this.hooks.evaluate.for(exprType).tap("JavascriptParser", expr => { const expression = /** @type {MemberExpression} */ (expr); diff --git a/lib/javascript/StartupHelpers.js b/lib/javascript/StartupHelpers.js index ef5f502b8..3f9224e5b 100644 --- a/lib/javascript/StartupHelpers.js +++ b/lib/javascript/StartupHelpers.js @@ -71,8 +71,8 @@ module.exports.generateEntryStartup = ( } }; - let currentChunks = undefined; - let currentModuleIds = undefined; + let currentChunks; + let currentModuleIds; for (const [module, entrypoint] of entries) { const runtimeChunk = diff --git a/lib/node/nodeConsole.js b/lib/node/nodeConsole.js index e4f517fc0..f3d03dae3 100644 --- a/lib/node/nodeConsole.js +++ b/lib/node/nodeConsole.js @@ -19,7 +19,7 @@ const truncateArgs = require("../logging/truncateArgs"); */ module.exports = ({ colors, appendOnly, stream }) => { /** @type {string[] | undefined} */ - let currentStatusMessage = undefined; + let currentStatusMessage; let hasStatusMessage = false; let currentIndent = ""; let currentCollapsed = 0; diff --git a/lib/optimize/FlagIncludedChunksPlugin.js b/lib/optimize/FlagIncludedChunksPlugin.js index 38367f207..685eb8411 100644 --- a/lib/optimize/FlagIncludedChunksPlugin.js +++ b/lib/optimize/FlagIncludedChunksPlugin.js @@ -74,7 +74,7 @@ class FlagIncludedChunksPlugin { const chunkAModulesCount = chunkGraph.getNumberOfChunkModules(chunkA); if (chunkAModulesCount === 0) continue; - let bestModule = undefined; + let bestModule; for (const module of chunkGraph.getChunkModulesIterable(chunkA)) { if ( bestModule === undefined || diff --git a/lib/optimize/ModuleConcatenationPlugin.js b/lib/optimize/ModuleConcatenationPlugin.js index 62fb07f4f..c726ccda4 100644 --- a/lib/optimize/ModuleConcatenationPlugin.js +++ b/lib/optimize/ModuleConcatenationPlugin.js @@ -278,7 +278,7 @@ class ModuleConcatenationPlugin { // TODO reconsider that when it's only used in a different runtime if (usedAsInner.has(currentRoot)) continue; - let chunkRuntime = undefined; + let chunkRuntime; for (const r of chunkGraph.getModuleRuntimes(currentRoot)) { chunkRuntime = mergeRuntimeOwned(chunkRuntime, r); } @@ -675,7 +675,7 @@ class ModuleConcatenationPlugin { if (chunkGraph.getNumberOfModuleChunks(originModule) === 0) continue; // We don't care for connections from other runtimes - let originRuntime = undefined; + let originRuntime; for (const r of chunkGraph.getModuleRuntimes(originModule)) { originRuntime = mergeRuntimeOwned(originRuntime, r); } diff --git a/lib/schemes/HttpUriPlugin.js b/lib/schemes/HttpUriPlugin.js index 83d0232c7..b41cc4db3 100644 --- a/lib/schemes/HttpUriPlugin.js +++ b/lib/schemes/HttpUriPlugin.js @@ -60,7 +60,7 @@ const proxyFetch = (request, proxy) => (url, options, callback) => { }; /** @type {(() => void)[] | undefined} */ -let inProgressWrite = undefined; +let inProgressWrite; const validate = createSchemaValidation( require("../../schemas/plugins/schemes/HttpUriPlugin.check.js"), @@ -239,11 +239,11 @@ class Lockfile { const cachedWithoutKey = fn => { let inFlight = false; /** @type {Error | undefined} */ - let cachedError = undefined; + let cachedError; /** @type {R | undefined} */ - let cachedResult = undefined; + let cachedResult; /** @type {(function(Error=, R=): void)[] | undefined} */ - let cachedCallbacks = undefined; + let cachedCallbacks; return callback => { if (inFlight) { if (cachedResult !== undefined) return callback(null, cachedResult); @@ -481,7 +481,7 @@ class HttpUriPlugin { ); /** @type {Map | undefined} */ - let lockfileUpdates = undefined; + let lockfileUpdates; /** * @param {Lockfile} lockfile lockfile instance diff --git a/lib/serialization/FileMiddleware.js b/lib/serialization/FileMiddleware.js index e1cbdc9c4..940d78f41 100644 --- a/lib/serialization/FileMiddleware.js +++ b/lib/serialization/FileMiddleware.js @@ -105,7 +105,7 @@ const serialize = async ( /** @type {WeakMap>} */ const resultToLazy = new WeakMap(); /** @type {Buffer[]} */ - let lastBuffers = undefined; + let lastBuffers; for (const item of await data) { if (typeof item === "function") { if (!SerializerMiddleware.isLazy(item)) diff --git a/lib/stats/DefaultStatsFactoryPlugin.js b/lib/stats/DefaultStatsFactoryPlugin.js index 2673777be..1ba194796 100644 --- a/lib/stats/DefaultStatsFactoryPlugin.js +++ b/lib/stats/DefaultStatsFactoryPlugin.js @@ -589,7 +589,7 @@ const SIMPLE_EXTRACTORS = { if (depthInCollapsedGroup > 0) depthInCollapsedGroup--; continue; } - let message = undefined; + let message; if (entry.type === LogType.time) { message = `${entry.args[0]}: ${ entry.args[1] * 1000 + entry.args[2] / 1000000 @@ -1689,9 +1689,9 @@ const spaceLimited = ( }; } /** @type {any[] | undefined} */ - let children = undefined; + let children; /** @type {number | undefined} */ - let filteredChildren = undefined; + let filteredChildren; // This are the groups, which take 1+ lines each const groups = []; // The sizes of the groups are stored in groupSizes diff --git a/lib/util/ParallelismFactorCalculator.js b/lib/util/ParallelismFactorCalculator.js index 415ff3681..d7725b7bf 100644 --- a/lib/util/ParallelismFactorCalculator.js +++ b/lib/util/ParallelismFactorCalculator.js @@ -5,7 +5,7 @@ "use strict"; -const binarySearchBounds = require("../util/binarySearchBounds"); +const binarySearchBounds = require("./binarySearchBounds"); /** @typedef {function(number): void} Callback */ diff --git a/lib/util/TupleSet.js b/lib/util/TupleSet.js index bfc9327c7..eae29083f 100644 --- a/lib/util/TupleSet.js +++ b/lib/util/TupleSet.js @@ -103,7 +103,7 @@ class TupleSet { [Symbol.iterator]() { const iteratorStack = []; const tuple = []; - let currentSetIterator = undefined; + let currentSetIterator; const next = it => { const result = it.next(); diff --git a/lib/util/createHash.js b/lib/util/createHash.js index 0732f81d1..561fe0d3f 100644 --- a/lib/util/createHash.js +++ b/lib/util/createHash.js @@ -133,13 +133,13 @@ class DebugHash extends Hash { } /** @type {typeof import("crypto") | undefined} */ -let crypto = undefined; +let crypto; /** @type {typeof import("./hash/xxhash64") | undefined} */ -let createXXHash64 = undefined; +let createXXHash64; /** @type {typeof import("./hash/md4") | undefined} */ -let createMd4 = undefined; +let createMd4; /** @type {typeof import("./hash/BatchedHash") | undefined} */ -let BatchedHash = undefined; +let BatchedHash; /** * Creates a hash by name or function diff --git a/lib/util/deterministicGrouping.js b/lib/util/deterministicGrouping.js index a91f71956..79882ab4c 100644 --- a/lib/util/deterministicGrouping.js +++ b/lib/util/deterministicGrouping.js @@ -259,7 +259,7 @@ const getSimilarities = nodes => { // calculate similarities between lexically adjacent nodes /** @type {number[]} */ const similarities = []; - let last = undefined; + let last; for (const node of nodes) { if (last !== undefined) { similarities.push(similarity(last.key, node.key)); diff --git a/lib/util/memoize.js b/lib/util/memoize.js index 535884302..3f446d71c 100644 --- a/lib/util/memoize.js +++ b/lib/util/memoize.js @@ -14,7 +14,7 @@ const memoize = fn => { let cache = false; /** @type {T | undefined} */ - let result = undefined; + let result; return () => { if (cache) { return /** @type {T} */ (result); diff --git a/lib/util/propertyAccess.js b/lib/util/propertyAccess.js index 50712a612..9555ba0fb 100644 --- a/lib/util/propertyAccess.js +++ b/lib/util/propertyAccess.js @@ -5,10 +5,7 @@ "use strict"; -const { - SAFE_IDENTIFIER, - RESERVED_IDENTIFIER -} = require("../util/propertyName"); +const { SAFE_IDENTIFIER, RESERVED_IDENTIFIER } = require("./propertyName"); /** * @param {ArrayLike} properties properties diff --git a/lib/util/runtime.js b/lib/util/runtime.js index d34022d1c..4315840b1 100644 --- a/lib/util/runtime.js +++ b/lib/util/runtime.js @@ -31,7 +31,7 @@ module.exports.getEntryRuntime = (compilation, name, options) => { } if (dependOn) { /** @type {RuntimeSpec} */ - let result = undefined; + let result; const queue = new Set(dependOn); for (const name of queue) { const dep = compilation.entries.get(name); @@ -396,7 +396,7 @@ module.exports.filterRuntime = (runtime, filter) => { if (typeof runtime === "string") return filter(runtime); let some = false; let every = true; - let result = undefined; + let result; for (const r of runtime) { const v = filter(r); if (v) { diff --git a/lib/util/semver.js b/lib/util/semver.js index 3fa517b78..2bf0ea2bc 100644 --- a/lib/util/semver.js +++ b/lib/util/semver.js @@ -452,19 +452,15 @@ module.exports.stringifyHoley = json => { }; //#region runtime code: parseVersion -module.exports.parseVersionRuntimeCode = runtimeTemplate => +exports.parseVersionRuntimeCode = runtimeTemplate => `var parseVersion = ${runtimeTemplate.basicFunction("str", [ "// see webpack/lib/util/semver.js for original code", - `var p=${ - runtimeTemplate.supportsArrowFunction() ? "p=>" : "function(p)" - }{return p.split(".").map((${ - runtimeTemplate.supportsArrowFunction() ? "p=>" : "function(p)" - }{return+p==p?+p:p}))},n=/^([^-+]+)?(?:-([^+]+))?(?:\\+(.+))?$/.exec(str),r=n[1]?p(n[1]):[];return n[2]&&(r.length++,r.push.apply(r,p(n[2]))),n[3]&&(r.push([]),r.push.apply(r,p(n[3]))),r;` + `var p=${runtimeTemplate.supportsArrowFunction() ? "p=>" : "function(p)"}{return p.split(".").map((${runtimeTemplate.supportsArrowFunction() ? "p=>" : "function(p)"}{return+p==p?+p:p}))},n=/^([^-+]+)?(?:-([^+]+))?(?:\\+(.+))?$/.exec(str),r=n[1]?p(n[1]):[];return n[2]&&(r.length++,r.push.apply(r,p(n[2]))),n[3]&&(r.push([]),r.push.apply(r,p(n[3]))),r;` ])}`; //#endregion //#region runtime code: versionLt -module.exports.versionLtRuntimeCode = runtimeTemplate => +exports.versionLtRuntimeCode = runtimeTemplate => `var versionLt = ${runtimeTemplate.basicFunction("a, b", [ "// see webpack/lib/util/semver.js for original code", 'a=parseVersion(a),b=parseVersion(b);for(var r=0;;){if(r>=a.length)return r=b.length)return"u"==n;var t=b[r],f=(typeof t)[0];if(n!=f)return"o"==n&&"n"==f||("s"==f||"u"==n);if("o"!=n&&"u"!=n&&e!=t)return e //#endregion //#region runtime code: rangeToString -module.exports.rangeToStringRuntimeCode = runtimeTemplate => +exports.rangeToStringRuntimeCode = runtimeTemplate => `var rangeToString = ${runtimeTemplate.basicFunction("range", [ "// see webpack/lib/util/semver.js for original code", 'var r=range[0],n="";if(1===range.length)return"*";if(r+.5){n+=0==r?">=":-1==r?"<":1==r?"^":2==r?"~":r>0?"=":"!=";for(var e=1,a=1;a0?".":"")+(e=2,t)}return n}var g=[];for(a=1;a //#endregion //#region runtime code: satisfy -module.exports.satisfyRuntimeCode = runtimeTemplate => +exports.satisfyRuntimeCode = runtimeTemplate => `var satisfy = ${runtimeTemplate.basicFunction("range, version", [ "// see webpack/lib/util/semver.js for original code", 'if(0 in range){version=parseVersion(version);var e=range[0],r=e<0;r&&(e=-e-1);for(var n=0,i=1,a=!0;;i++,n++){var f,s,g=i=version.length||"o"==(s=(typeof(f=version[n]))[0]))return!a||("u"==g?i>e&&!r:""==g!=r);if("u"==s){if(!a||"u"!=g)return!1}else if(a)if(g==s)if(i<=e){if(f!=range[i])return!1}else{if(r?f>range[i]:f { const results = []; for (;;) { /** @type {Group | undefined} */ - let bestGroup = undefined; + let bestGroup; let bestGroupSize = -1; - let bestGroupItems = undefined; - let bestGroupOptions = undefined; + let bestGroupItems; + let bestGroupOptions; for (const [group, state] of groupMap) { const { items, used } = state; let options = state.options; diff --git a/test/helpers/FakeDocument.js b/test/helpers/FakeDocument.js index 15a94b051..8895c5dd6 100644 --- a/test/helpers/FakeDocument.js +++ b/test/helpers/FakeDocument.js @@ -187,7 +187,7 @@ class FakeSheet { const walkCssTokens = require("../../lib/css/walkCssTokens"); const rules = []; let currentRule = { getPropertyValue }; - let selector = undefined; + let selector; let last = 0; const processDeclaration = str => { const colon = str.indexOf(":"); diff --git a/test/helpers/deprecationTracking.js b/test/helpers/deprecationTracking.js index 39d248663..4bee75d15 100644 --- a/test/helpers/deprecationTracking.js +++ b/test/helpers/deprecationTracking.js @@ -7,7 +7,7 @@ const util = require("util"); -let interception = undefined; +let interception; const originalDeprecate = util.deprecate; util.deprecate = (fn, message, code) => {