mirror of https://github.com/webpack/webpack.git
Merge pull request #7813 from webpack/refactor/freeze_hooks
Freeze hooks to prevent deopts
This commit is contained in:
commit
2e82dbb63c
|
|
@ -26,7 +26,7 @@ const { SyncWaterfallHook, SyncHook } = require("tapable");
|
|||
module.exports = class ChunkTemplate {
|
||||
constructor(outputOptions) {
|
||||
this.outputOptions = outputOptions || {};
|
||||
this.hooks = {
|
||||
this.hooks = Object.freeze({
|
||||
/** @type {SyncWaterfallHook<TODO[], RenderManifestOptions>} */
|
||||
renderManifest: new SyncWaterfallHook(["result", "options"]),
|
||||
modules: new SyncWaterfallHook([
|
||||
|
|
@ -44,7 +44,7 @@ module.exports = class ChunkTemplate {
|
|||
renderWithEntry: new SyncWaterfallHook(["source", "chunk"]),
|
||||
hash: new SyncHook(["hash"]),
|
||||
hashForChunk: new SyncHook(["hash", "chunk"])
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ class Compilation {
|
|||
* @param {Compiler} compiler the compiler which created the compilation
|
||||
*/
|
||||
constructor(compiler) {
|
||||
this.hooks = {
|
||||
this.hooks = Object.freeze({
|
||||
/** @type {SyncHook<Module>} */
|
||||
buildModule: new SyncHook(["module"]),
|
||||
/** @type {SyncHook<Module>} */
|
||||
|
|
@ -377,7 +377,7 @@ class Compilation {
|
|||
// TODO move them for webpack 5
|
||||
/** @type {SyncHook<object, Module>} */
|
||||
normalModuleLoader: new SyncHook(["loaderContext", "module"])
|
||||
};
|
||||
});
|
||||
/** @type {string=} */
|
||||
this.name = undefined;
|
||||
/** @type {Compiler} */
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ const { makePathsRelative } = require("./util/identifier");
|
|||
|
||||
class Compiler {
|
||||
constructor(context) {
|
||||
this.hooks = {
|
||||
this.hooks = Object.freeze({
|
||||
/** @type {SyncBailHook<Compilation>} */
|
||||
shouldEmit: new SyncBailHook(["compilation"]),
|
||||
/** @type {AsyncSeriesHook<Stats>} */
|
||||
|
|
@ -100,7 +100,7 @@ class Compiler {
|
|||
afterResolvers: new SyncHook(["compiler"]),
|
||||
/** @type {SyncBailHook<string, EntryOptions>} */
|
||||
entryOption: new SyncBailHook(["context", "entry"])
|
||||
};
|
||||
});
|
||||
|
||||
/** @type {string=} */
|
||||
this.name = undefined;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ const EMPTY_RESOLVE_OPTIONS = {};
|
|||
|
||||
module.exports = class ContextModuleFactory {
|
||||
constructor(resolverFactory) {
|
||||
this.hooks = {
|
||||
this.hooks = Object.freeze({
|
||||
/** @type {AsyncSeriesWaterfallHook<TODO>} */
|
||||
beforeResolve: new AsyncSeriesWaterfallHook(["data"]),
|
||||
/** @type {AsyncSeriesWaterfallHook<TODO>} */
|
||||
|
|
@ -27,7 +27,7 @@ module.exports = class ContextModuleFactory {
|
|||
contextModuleFiles: new SyncWaterfallHook(["files"]),
|
||||
/** @type {SyncWaterfallHook<TODO[]>} */
|
||||
alternatives: new AsyncSeriesWaterfallHook(["modules"])
|
||||
};
|
||||
});
|
||||
this.resolverFactory = resolverFactory;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ const DllModule = require("./DllModule");
|
|||
|
||||
class DllModuleFactory {
|
||||
constructor() {
|
||||
this.hooks = {};
|
||||
this.hooks = Object.freeze({});
|
||||
}
|
||||
create(data, callback) {
|
||||
const dependency = data.dependencies[0];
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ const Template = require("./Template");
|
|||
module.exports = class HotUpdateChunkTemplate {
|
||||
constructor(outputOptions) {
|
||||
this.outputOptions = outputOptions || {};
|
||||
this.hooks = {
|
||||
this.hooks = Object.freeze({
|
||||
modules: new SyncWaterfallHook([
|
||||
"source",
|
||||
"modules",
|
||||
|
|
@ -30,7 +30,7 @@ module.exports = class HotUpdateChunkTemplate {
|
|||
"dependencyTemplates"
|
||||
]),
|
||||
hash: new SyncHook(["hash"])
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
render(
|
||||
|
|
|
|||
|
|
@ -43,7 +43,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"])),
|
||||
|
|
@ -97,7 +97,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;
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ module.exports = class MainTemplate {
|
|||
constructor(outputOptions) {
|
||||
/** @type {TODO?} */
|
||||
this.outputOptions = outputOptions || {};
|
||||
this.hooks = {
|
||||
this.hooks = Object.freeze({
|
||||
/** @type {SyncWaterfallHook<TODO[], RenderManifestOptions>} */
|
||||
renderManifest: new SyncWaterfallHook(["result", "options"]),
|
||||
modules: new SyncWaterfallHook([
|
||||
|
|
@ -124,7 +124,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 = [];
|
||||
|
|
|
|||
|
|
@ -14,7 +14,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",
|
||||
|
|
@ -40,7 +40,7 @@ module.exports = class ModuleTemplate {
|
|||
"dependencyTemplates"
|
||||
]),
|
||||
hash: new SyncHook(["hash"])
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -13,13 +13,13 @@ const MultiWatching = require("./MultiWatching");
|
|||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ const MultiModule = require("./MultiModule");
|
|||
|
||||
module.exports = class MultiModuleFactory {
|
||||
constructor() {
|
||||
this.hooks = {};
|
||||
this.hooks = Object.freeze({});
|
||||
}
|
||||
|
||||
create(data, callback) {
|
||||
|
|
|
|||
|
|
@ -60,7 +60,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"]),
|
||||
|
|
@ -75,7 +75,7 @@ class NormalModuleFactory {
|
|||
generator: new HookMap(
|
||||
() => new SyncHook(["generator", "generatorOptions"])
|
||||
)
|
||||
};
|
||||
});
|
||||
this.resolverFactory = resolverFactory;
|
||||
this.ruleSet = new RuleSet(options.defaultRules.concat(options.rules));
|
||||
this.cachePredicate =
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ const { HookMap, SyncHook, SyncWaterfallHook } = require("tapable");
|
|||
|
||||
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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ const decoderOpts = {
|
|||
|
||||
class WebAssemblyParser {
|
||||
constructor(options) {
|
||||
this.hooks = {};
|
||||
this.hooks = Object.freeze({});
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue