diff --git a/lib/ChunkTemplate.js b/lib/ChunkTemplate.js index 247e001a0..e4b866a65 100644 --- a/lib/ChunkTemplate.js +++ b/lib/ChunkTemplate.js @@ -25,7 +25,7 @@ const { SyncWaterfallHook, SyncHook } = require("tapable"); module.exports = class ChunkTemplate { constructor(outputOptions) { this.outputOptions = outputOptions || {}; - this.hooks = { + this.hooks = Object.freeze({ /** @type {SyncWaterfallHook} */ renderManifest: new SyncWaterfallHook(["result", "options"]), modules: new SyncWaterfallHook([ @@ -43,7 +43,7 @@ module.exports = class ChunkTemplate { renderWithEntry: new SyncWaterfallHook(["source", "chunk"]), hash: new SyncHook(["hash"]), hashForChunk: new SyncHook(["hash", "chunk"]) - }; + }); } /** diff --git a/lib/Compilation.js b/lib/Compilation.js index e80f849e5..dce4f2bee 100644 --- a/lib/Compilation.js +++ b/lib/Compilation.js @@ -209,7 +209,7 @@ class Compilation { * @param {Compiler} compiler the compiler which created the compilation */ constructor(compiler) { - this.hooks = { + this.hooks = Object.freeze({ /** @type {SyncHook} */ buildModule: new SyncHook(["module"]), /** @type {SyncHook} */ @@ -376,7 +376,7 @@ class Compilation { // TODO move them for webpack 5 /** @type {SyncHook} */ normalModuleLoader: new SyncHook(["loaderContext", "module"]) - }; + }); /** @type {string=} */ this.name = undefined; /** @type {Compiler} */ diff --git a/lib/Compiler.js b/lib/Compiler.js index ce50df711..32ab520e9 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -44,7 +44,7 @@ const ConcurrentCompilationError = require("./ConcurrentCompilationError"); class Compiler { constructor(context) { - this.hooks = { + this.hooks = Object.freeze({ /** @type {SyncBailHook} */ shouldEmit: new SyncBailHook(["compilation"]), /** @type {AsyncSeriesHook} */ @@ -99,7 +99,7 @@ class Compiler { afterResolvers: new SyncHook(["compiler"]), /** @type {SyncBailHook} */ entryOption: new SyncBailHook(["context", "entry"]) - }; + }); /** @type {string=} */ this.name = undefined; diff --git a/lib/ContextModuleFactory.js b/lib/ContextModuleFactory.js index 9234d935b..65643060a 100644 --- a/lib/ContextModuleFactory.js +++ b/lib/ContextModuleFactory.js @@ -17,7 +17,7 @@ const EMPTY_RESOLVE_OPTIONS = {}; module.exports = class ContextModuleFactory { constructor(resolverFactory) { - this.hooks = { + this.hooks = Object.freeze({ /** @type {AsyncSeriesWaterfallHook} */ beforeResolve: new AsyncSeriesWaterfallHook(["data"]), /** @type {AsyncSeriesWaterfallHook} */ @@ -26,7 +26,7 @@ module.exports = class ContextModuleFactory { contextModuleFiles: new SyncWaterfallHook(["files"]), /** @type {SyncWaterfallHook} */ alternatives: new AsyncSeriesWaterfallHook(["modules"]) - }; + }); this.resolverFactory = resolverFactory; } diff --git a/lib/DllModuleFactory.js b/lib/DllModuleFactory.js index 5ad89a1c5..c49780820 100644 --- a/lib/DllModuleFactory.js +++ b/lib/DllModuleFactory.js @@ -8,7 +8,7 @@ const DllModule = require("./DllModule"); class DllModuleFactory { constructor() { - this.hooks = {}; + this.hooks = Object.freeze({}); } create(data, callback) { const dependency = data.dependencies[0]; diff --git a/lib/HotUpdateChunkTemplate.js b/lib/HotUpdateChunkTemplate.js index 3f3151c2b..2047a89c4 100644 --- a/lib/HotUpdateChunkTemplate.js +++ b/lib/HotUpdateChunkTemplate.js @@ -11,7 +11,7 @@ const { SyncWaterfallHook, SyncHook } = require("tapable"); module.exports = class HotUpdateChunkTemplate { constructor(outputOptions) { this.outputOptions = outputOptions || {}; - this.hooks = { + this.hooks = Object.freeze({ modules: new SyncWaterfallHook([ "source", "modules", @@ -29,7 +29,7 @@ module.exports = class HotUpdateChunkTemplate { "dependencyTemplates" ]), hash: new SyncHook(["hash"]) - }; + }); } render( diff --git a/lib/JavascriptParser.js b/lib/JavascriptParser.js index 57ddee6fd..e46b06790 100644 --- a/lib/JavascriptParser.js +++ b/lib/JavascriptParser.js @@ -42,7 +42,7 @@ const EMPTY_COMMENT_OPTIONS = { class JavascriptParser { constructor(options, sourceType = "auto") { - this.hooks = { + this.hooks = Object.freeze({ evaluateTypeof: new HookMap(() => new SyncBailHook(["expression"])), evaluate: new HookMap(() => new SyncBailHook(["expression"])), evaluateIdentifier: new HookMap(() => new SyncBailHook(["expression"])), @@ -96,7 +96,7 @@ class JavascriptParser { expressionAnyMember: new HookMap(() => new SyncBailHook(["expression"])), expressionConditionalOperator: new SyncBailHook(["expression"]), program: new SyncBailHook(["ast", "comments"]) - }; + }); this.options = options; this.sourceType = sourceType; this.scope = undefined; diff --git a/lib/MainTemplate.js b/lib/MainTemplate.js index 0a6f674d1..79db72ac2 100644 --- a/lib/MainTemplate.js +++ b/lib/MainTemplate.js @@ -56,7 +56,7 @@ module.exports = class MainTemplate { constructor(outputOptions) { /** @type {TODO?} */ this.outputOptions = outputOptions || {}; - this.hooks = { + this.hooks = Object.freeze({ /** @type {SyncWaterfallHook} */ renderManifest: new SyncWaterfallHook(["result", "options"]), modules: new SyncWaterfallHook([ @@ -123,7 +123,7 @@ module.exports = class MainTemplate { // TODO this should be moved somewhere else // It's weird here hotBootstrap: new SyncWaterfallHook(["source", "chunk", "hash"]) - }; + }); this.hooks.startup.tap("MainTemplate", (source, chunk, hash) => { /** @type {string[]} */ const buf = []; diff --git a/lib/ModuleTemplate.js b/lib/ModuleTemplate.js index 7096f1e7e..dd4a19f61 100644 --- a/lib/ModuleTemplate.js +++ b/lib/ModuleTemplate.js @@ -13,7 +13,7 @@ module.exports = class ModuleTemplate { constructor(runtimeTemplate, type) { this.runtimeTemplate = runtimeTemplate; this.type = type; - this.hooks = { + this.hooks = Object.freeze({ content: new SyncWaterfallHook([ "source", "module", @@ -39,7 +39,7 @@ module.exports = class ModuleTemplate { "dependencyTemplates" ]), hash: new SyncHook(["hash"]) - }; + }); } /** diff --git a/lib/MultiCompiler.js b/lib/MultiCompiler.js index 5315c8f36..ee0a287f5 100644 --- a/lib/MultiCompiler.js +++ b/lib/MultiCompiler.js @@ -12,13 +12,13 @@ const ConcurrentCompilationError = require("./ConcurrentCompilationError"); module.exports = class MultiCompiler { constructor(compilers) { - this.hooks = { + this.hooks = Object.freeze({ done: new SyncHook(["stats"]), invalid: new MultiHook(compilers.map(c => c.hooks.invalid)), run: new MultiHook(compilers.map(c => c.hooks.run)), watchClose: new SyncHook([]), watchRun: new MultiHook(compilers.map(c => c.hooks.watchRun)) - }; + }); if (!Array.isArray(compilers)) { compilers = Object.keys(compilers).map(name => { compilers[name].name = name; diff --git a/lib/MultiModuleFactory.js b/lib/MultiModuleFactory.js index 10dd9b8e4..a5ccca272 100644 --- a/lib/MultiModuleFactory.js +++ b/lib/MultiModuleFactory.js @@ -8,7 +8,7 @@ const MultiModule = require("./MultiModule"); module.exports = class MultiModuleFactory { constructor() { - this.hooks = {}; + this.hooks = Object.freeze({}); } create(data, callback) { diff --git a/lib/NormalModuleFactory.js b/lib/NormalModuleFactory.js index 4f5bf2602..321a0aaa9 100644 --- a/lib/NormalModuleFactory.js +++ b/lib/NormalModuleFactory.js @@ -59,7 +59,7 @@ const dependencyCache = new WeakMap(); class NormalModuleFactory { constructor(context, resolverFactory, options) { - this.hooks = { + this.hooks = Object.freeze({ resolver: new SyncWaterfallHook(["resolver"]), factory: new SyncWaterfallHook(["factory"]), beforeResolve: new AsyncSeriesWaterfallHook(["data"]), @@ -74,7 +74,7 @@ class NormalModuleFactory { generator: new HookMap( () => new SyncHook(["generator", "generatorOptions"]) ) - }; + }); this.resolverFactory = resolverFactory; this.ruleSet = new RuleSet(options.defaultRules.concat(options.rules)); this.cachePredicate = diff --git a/lib/ResolverFactory.js b/lib/ResolverFactory.js index b9a039612..c0f23c01c 100644 --- a/lib/ResolverFactory.js +++ b/lib/ResolverFactory.js @@ -9,12 +9,12 @@ const Factory = require("enhanced-resolve").ResolverFactory; module.exports = class ResolverFactory { constructor() { - this.hooks = { + this.hooks = Object.freeze({ resolveOptions: new HookMap( () => new SyncWaterfallHook(["resolveOptions"]) ), resolver: new HookMap(() => new SyncHook(["resolver", "resolveOptions"])) - }; + }); this.cache1 = new WeakMap(); this.cache2 = new Map(); } diff --git a/lib/wasm/WebAssemblyParser.js b/lib/wasm/WebAssemblyParser.js index 8a57941fd..4307e64b6 100644 --- a/lib/wasm/WebAssemblyParser.js +++ b/lib/wasm/WebAssemblyParser.js @@ -60,7 +60,7 @@ const decoderOpts = { class WebAssemblyParser { constructor(options) { - this.hooks = {}; + this.hooks = Object.freeze({}); this.options = options; }