Merge pull request #9547 from webpack/perf/lazy-set
Performance improvements
This commit is contained in:
commit
a27ee5f04a
|
@ -9,7 +9,6 @@ const {
|
|||
toConstantDependency,
|
||||
evaluateToString
|
||||
} = require("./JavascriptParserHelpers");
|
||||
const NullFactory = require("./NullFactory");
|
||||
const RuntimeGlobals = require("./RuntimeGlobals");
|
||||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
const ChunkNameRuntimeModule = require("./runtime/ChunkNameRuntimeModule");
|
||||
|
@ -82,7 +81,6 @@ class APIPlugin {
|
|||
compiler.hooks.compilation.tap(
|
||||
"APIPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(
|
||||
ConstDependency,
|
||||
new ConstDependency.Template()
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
|
||||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
|
||||
const NullFactory = require("./NullFactory");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./JavascriptParser")} JavascriptParser */
|
||||
|
||||
|
@ -22,7 +20,6 @@ class CompatibilityPlugin {
|
|||
compiler.hooks.compilation.tap(
|
||||
"CompatibilityPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(
|
||||
ConstDependency,
|
||||
new ConstDependency.Template()
|
||||
|
|
|
@ -43,6 +43,7 @@ const { Logger, LogType } = require("./logging/Logger");
|
|||
const StatsFactory = require("./stats/StatsFactory");
|
||||
const StatsPrinter = require("./stats/StatsPrinter");
|
||||
const AsyncQueue = require("./util/AsyncQueue");
|
||||
const LazySet = require("./util/LazySet");
|
||||
const {
|
||||
compareLocations,
|
||||
concatComparators,
|
||||
|
@ -189,18 +190,6 @@ const byNameOrHash = concatComparators(
|
|||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {Set<T>} set set to add items to
|
||||
* @param {Set<T>} otherSet set to add items from
|
||||
* @returns {void}
|
||||
*/
|
||||
const addAllToSet = (set, otherSet) => {
|
||||
for (const item of otherSet) {
|
||||
set.add(item);
|
||||
}
|
||||
};
|
||||
|
||||
class Compilation {
|
||||
/**
|
||||
* Creates an instance of Compilation.
|
||||
|
@ -540,12 +529,12 @@ class Compilation {
|
|||
this._rebuildingModules = new Map();
|
||||
/** @type {Set<string>} */
|
||||
this.emittedAssets = new Set();
|
||||
/** @type {Set<string>} */
|
||||
this.fileDependencies = new Set();
|
||||
/** @type {Set<string>} */
|
||||
this.contextDependencies = new Set();
|
||||
/** @type {Set<string>} */
|
||||
this.missingDependencies = new Set();
|
||||
/** @type {LazySet<string>} */
|
||||
this.fileDependencies = new LazySet();
|
||||
/** @type {LazySet<string>} */
|
||||
this.contextDependencies = new LazySet();
|
||||
/** @type {LazySet<string>} */
|
||||
this.missingDependencies = new LazySet();
|
||||
}
|
||||
|
||||
getStats() {
|
||||
|
@ -824,10 +813,13 @@ class Compilation {
|
|||
_processModuleDependencies(module, callback) {
|
||||
const dependencies = new Map();
|
||||
|
||||
const sortedDependencies = [];
|
||||
|
||||
let currentBlock = module;
|
||||
|
||||
let factoryCacheKey;
|
||||
let factoryCacheValue;
|
||||
let factoryCacheValue2;
|
||||
let listCacheKey;
|
||||
let listCacheValue;
|
||||
|
||||
|
@ -837,6 +829,7 @@ class Compilation {
|
|||
if (resourceIdent) {
|
||||
const constructor = dep.constructor;
|
||||
let innerMap;
|
||||
let factory;
|
||||
if (factoryCacheKey === constructor) {
|
||||
innerMap = factoryCacheValue;
|
||||
if (listCacheKey === resourceIdent) {
|
||||
|
@ -844,7 +837,7 @@ class Compilation {
|
|||
return;
|
||||
}
|
||||
} else {
|
||||
const factory = this.dependencyFactories.get(dep.constructor);
|
||||
factory = this.dependencyFactories.get(dep.constructor);
|
||||
if (factory === undefined) {
|
||||
throw new Error(
|
||||
`No module factory available for dependency type: ${dep.constructor.name}`
|
||||
|
@ -856,9 +849,17 @@ class Compilation {
|
|||
}
|
||||
factoryCacheKey = constructor;
|
||||
factoryCacheValue = innerMap;
|
||||
factoryCacheValue2 = factory;
|
||||
}
|
||||
let list = innerMap.get(resourceIdent);
|
||||
if (list === undefined) innerMap.set(resourceIdent, (list = []));
|
||||
if (list === undefined) {
|
||||
innerMap.set(resourceIdent, (list = []));
|
||||
sortedDependencies.push({
|
||||
factory: factoryCacheValue2,
|
||||
dependencies: list,
|
||||
originModule: module
|
||||
});
|
||||
}
|
||||
list.push(dep);
|
||||
listCacheKey = resourceIdent;
|
||||
listCacheValue = list;
|
||||
|
@ -881,18 +882,6 @@ class Compilation {
|
|||
return callback(e);
|
||||
}
|
||||
|
||||
const sortedDependencies = [];
|
||||
|
||||
for (const [factory, innerMap] of dependencies) {
|
||||
for (const dependencies of innerMap.values()) {
|
||||
sortedDependencies.push({
|
||||
factory,
|
||||
dependencies,
|
||||
originModule: module
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (sortedDependencies.length === 0) {
|
||||
callback();
|
||||
return;
|
||||
|
@ -982,12 +971,10 @@ class Compilation {
|
|||
moduleGraph.setResolvedModule(originModule, dependency, module);
|
||||
}
|
||||
|
||||
if (moduleGraph.getIssuer(module) === undefined) {
|
||||
moduleGraph.setIssuer(
|
||||
module,
|
||||
originModule !== undefined ? originModule : null
|
||||
);
|
||||
}
|
||||
moduleGraph.setIssuerIfUnset(
|
||||
module,
|
||||
originModule !== undefined ? originModule : null
|
||||
);
|
||||
if (module !== newModule) {
|
||||
if (currentProfile !== undefined) {
|
||||
const otherProfile = moduleGraph.getProfile(module);
|
||||
|
@ -1078,13 +1065,13 @@ class Compilation {
|
|||
missingDependencies
|
||||
} = result;
|
||||
if (fileDependencies) {
|
||||
addAllToSet(this.fileDependencies, fileDependencies);
|
||||
this.fileDependencies.addAll(fileDependencies);
|
||||
}
|
||||
if (contextDependencies) {
|
||||
addAllToSet(this.contextDependencies, contextDependencies);
|
||||
this.contextDependencies.addAll(contextDependencies);
|
||||
}
|
||||
if (missingDependencies) {
|
||||
addAllToSet(this.missingDependencies, missingDependencies);
|
||||
this.missingDependencies.addAll(missingDependencies);
|
||||
}
|
||||
}
|
||||
if (err) {
|
||||
|
@ -1847,9 +1834,9 @@ class Compilation {
|
|||
) {
|
||||
const child = this.children[indexChildren];
|
||||
|
||||
addAllToSet(this.fileDependencies, child.fileDependencies);
|
||||
addAllToSet(this.contextDependencies, child.contextDependencies);
|
||||
addAllToSet(this.missingDependencies, child.missingDependencies);
|
||||
this.fileDependencies.addAll(child.fileDependencies);
|
||||
this.contextDependencies.addAll(child.contextDependencies);
|
||||
this.missingDependencies.addAll(child.missingDependencies);
|
||||
}
|
||||
|
||||
for (const module of this.modules) {
|
||||
|
@ -1857,13 +1844,13 @@ class Compilation {
|
|||
const contextDependencies = module.buildInfo.contextDependencies;
|
||||
const missingDependencies = module.buildInfo.missingDependencies;
|
||||
if (fileDependencies) {
|
||||
addAllToSet(this.fileDependencies, fileDependencies);
|
||||
this.fileDependencies.addAll(fileDependencies);
|
||||
}
|
||||
if (contextDependencies) {
|
||||
addAllToSet(this.contextDependencies, contextDependencies);
|
||||
this.contextDependencies.addAll(contextDependencies);
|
||||
}
|
||||
if (missingDependencies) {
|
||||
addAllToSet(this.missingDependencies, missingDependencies);
|
||||
this.missingDependencies.addAll(missingDependencies);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
"use strict";
|
||||
|
||||
const { evaluateToString } = require("./JavascriptParserHelpers");
|
||||
const NullFactory = require("./NullFactory");
|
||||
const CachedConstDependency = require("./dependencies/CachedConstDependency");
|
||||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
|
||||
|
@ -120,16 +119,11 @@ class ConstPlugin {
|
|||
compiler.hooks.compilation.tap(
|
||||
"ConstPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(
|
||||
ConstDependency,
|
||||
new ConstDependency.Template()
|
||||
);
|
||||
|
||||
compilation.dependencyFactories.set(
|
||||
CachedConstDependency,
|
||||
new NullFactory()
|
||||
);
|
||||
compilation.dependencyTemplates.set(
|
||||
CachedConstDependency,
|
||||
new CachedConstDependency.Template()
|
||||
|
|
|
@ -11,7 +11,6 @@ const {
|
|||
evaluateToString,
|
||||
toConstantDependency
|
||||
} = require("./JavascriptParserHelpers");
|
||||
const NullFactory = require("./NullFactory");
|
||||
const RuntimeGlobals = require("./RuntimeGlobals");
|
||||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
|
||||
|
@ -106,7 +105,6 @@ class DefinePlugin {
|
|||
compiler.hooks.compilation.tap(
|
||||
"DefinePlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(
|
||||
ConstDependency,
|
||||
new ConstDependency.Template()
|
||||
|
|
|
@ -6,9 +6,7 @@
|
|||
"use strict";
|
||||
|
||||
const DelegatedModuleFactoryPlugin = require("./DelegatedModuleFactoryPlugin");
|
||||
const NullFactory = require("./NullFactory");
|
||||
const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
|
||||
const StaticExportsDependency = require("./dependencies/StaticExportsDependency");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
|
@ -30,10 +28,6 @@ class DelegatedPlugin {
|
|||
DelegatedSourceDependency,
|
||||
normalModuleFactory
|
||||
);
|
||||
compilation.dependencyFactories.set(
|
||||
StaticExportsDependency,
|
||||
new NullFactory()
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -8,10 +8,8 @@
|
|||
const parseJson = require("json-parse-better-errors");
|
||||
const DelegatedModuleFactoryPlugin = require("./DelegatedModuleFactoryPlugin");
|
||||
const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
|
||||
const NullFactory = require("./NullFactory");
|
||||
const WebpackError = require("./WebpackError");
|
||||
const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
|
||||
const StaticExportsDependency = require("./dependencies/StaticExportsDependency");
|
||||
const makePathsRelative = require("./util/identifier").makePathsRelative;
|
||||
|
||||
const validateOptions = require("schema-utils");
|
||||
|
@ -39,10 +37,6 @@ class DllReferencePlugin {
|
|||
DelegatedSourceDependency,
|
||||
normalModuleFactory
|
||||
);
|
||||
compilation.dependencyFactories.set(
|
||||
StaticExportsDependency,
|
||||
new NullFactory()
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ const {
|
|||
toConstantDependency
|
||||
} = require("./JavascriptParserHelpers");
|
||||
const NormalModule = require("./NormalModule");
|
||||
const NullFactory = require("./NullFactory");
|
||||
const RuntimeGlobals = require("./RuntimeGlobals");
|
||||
const ModuleHotAcceptDependency = require("./dependencies/ModuleHotAcceptDependency");
|
||||
const ModuleHotDeclineDependency = require("./dependencies/ModuleHotDeclineDependency");
|
||||
|
@ -207,10 +206,6 @@ class HotModuleReplacementPlugin {
|
|||
new ModuleHotDeclineDependency.Template()
|
||||
);
|
||||
|
||||
compilation.dependencyFactories.set(
|
||||
ModuleHotDependency,
|
||||
new NullFactory()
|
||||
);
|
||||
compilation.dependencyTemplates.set(
|
||||
ModuleHotDependency,
|
||||
new ModuleHotDependency.Template()
|
||||
|
|
|
@ -75,11 +75,22 @@ class ExportsInfo {
|
|||
}
|
||||
|
||||
_sortExports() {
|
||||
const newMap = new Map();
|
||||
for (const name of Array.from(this._exports.keys()).sort()) {
|
||||
newMap.set(name, this._exports.get(name));
|
||||
const exports = this._exports;
|
||||
if (exports.size > 1) {
|
||||
const entriesInOrder = Array.from(exports.values());
|
||||
if (
|
||||
entriesInOrder.length !== 2 ||
|
||||
entriesInOrder[0].name > entriesInOrder[1].name
|
||||
) {
|
||||
entriesInOrder.sort((a, b) => {
|
||||
return a.name < b.name ? -1 : 1;
|
||||
});
|
||||
exports.clear();
|
||||
for (const entry of entriesInOrder) {
|
||||
exports.set(entry.name, entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
this._exports = newMap;
|
||||
this._exportsAreOrdered = true;
|
||||
}
|
||||
|
||||
|
@ -357,6 +368,10 @@ class ExportsInfo {
|
|||
if (info === undefined) info = this._otherExportsInfo;
|
||||
const x = info.getUsedName(name[0]);
|
||||
if (!x) return false;
|
||||
if (name.length === 1) {
|
||||
if (x === name[0]) return name;
|
||||
return [x];
|
||||
}
|
||||
if (info.exportsInfo) {
|
||||
const nested = info.exportsInfo.getUsedName(name.slice(1));
|
||||
if (!nested) return false;
|
||||
|
@ -590,6 +605,14 @@ class ModuleGraph {
|
|||
this._originMap = new Map();
|
||||
/** @type {Map<any, Object>} */
|
||||
this._metaMap = new Map();
|
||||
|
||||
// Caching
|
||||
this._cacheModuleGraphModuleKey1 = undefined;
|
||||
this._cacheModuleGraphModuleValue1 = undefined;
|
||||
this._cacheModuleGraphModuleKey2 = undefined;
|
||||
this._cacheModuleGraphModuleValue2 = undefined;
|
||||
this._cacheModuleGraphDependencyKey = undefined;
|
||||
this._cacheModuleGraphDependencyValue = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -597,11 +620,19 @@ class ModuleGraph {
|
|||
* @returns {ModuleGraphModule} the internal module
|
||||
*/
|
||||
_getModuleGraphModule(module) {
|
||||
if (this._cacheModuleGraphModuleKey1 === module)
|
||||
return this._cacheModuleGraphModuleValue1;
|
||||
if (this._cacheModuleGraphModuleKey2 === module)
|
||||
return this._cacheModuleGraphModuleValue2;
|
||||
let mgm = this._moduleMap.get(module);
|
||||
if (mgm === undefined) {
|
||||
mgm = new ModuleGraphModule();
|
||||
this._moduleMap.set(module, mgm);
|
||||
}
|
||||
this._cacheModuleGraphModuleKey2 = this._cacheModuleGraphModuleKey1;
|
||||
this._cacheModuleGraphModuleValue2 = this._cacheModuleGraphModuleValue1;
|
||||
this._cacheModuleGraphModuleKey1 = module;
|
||||
this._cacheModuleGraphModuleValue1 = mgm;
|
||||
return mgm;
|
||||
}
|
||||
|
||||
|
@ -610,11 +641,15 @@ class ModuleGraph {
|
|||
* @returns {ModuleGraphDependency} the internal dependency
|
||||
*/
|
||||
_getModuleGraphDependency(dependency) {
|
||||
if (this._cacheModuleGraphDependencyKey === dependency)
|
||||
return this._cacheModuleGraphDependencyValue;
|
||||
let mgd = this._dependencyMap.get(dependency);
|
||||
if (mgd === undefined) {
|
||||
mgd = new ModuleGraphDependency();
|
||||
this._dependencyMap.set(dependency, mgd);
|
||||
}
|
||||
this._cacheModuleGraphDependencyKey = dependency;
|
||||
this._cacheModuleGraphDependencyValue = mgd;
|
||||
return mgd;
|
||||
}
|
||||
|
||||
|
@ -876,6 +911,16 @@ class ModuleGraph {
|
|||
mgm.issuer = issuer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} module the module
|
||||
* @param {Module | null} issuer the issuer module
|
||||
* @returns {void}
|
||||
*/
|
||||
setIssuerIfUnset(module, issuer) {
|
||||
const mgm = this._getModuleGraphModule(module);
|
||||
if (mgm.issuer === undefined) mgm.issuer = issuer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} module the module
|
||||
* @returns {(string | OptimizationBailoutFunction)[]} optimization bailouts
|
||||
|
|
|
@ -21,6 +21,7 @@ const BasicEffectRulePlugin = require("./rules/BasicEffectRulePlugin");
|
|||
const BasicMatcherRulePlugin = require("./rules/BasicMatcherRulePlugin");
|
||||
const RuleSetCompiler = require("./rules/RuleSetCompiler");
|
||||
const UseEffectRulePlugin = require("./rules/UseEffectRulePlugin");
|
||||
const LazySet = require("./util/LazySet");
|
||||
const { cachedCleverMerge } = require("./util/cleverMerge");
|
||||
const { join } = require("./util/fs");
|
||||
|
||||
|
@ -36,9 +37,9 @@ const { join } = require("./util/fs");
|
|||
* @property {string} request
|
||||
* @property {ModuleDependency[]} dependencies
|
||||
* @property {Object} createData
|
||||
* @property {Set<string>} fileDependencies
|
||||
* @property {Set<string>} missingDependencies
|
||||
* @property {Set<string>} contextDependencies
|
||||
* @property {LazySet<string>} fileDependencies
|
||||
* @property {LazySet<string>} missingDependencies
|
||||
* @property {LazySet<string>} contextDependencies
|
||||
*/
|
||||
|
||||
const EMPTY_RESOLVE_OPTIONS = {};
|
||||
|
@ -497,9 +498,9 @@ class NormalModuleFactory extends ModuleFactory {
|
|||
const dependency = dependencies[0];
|
||||
const request = dependency.request;
|
||||
const contextInfo = data.contextInfo;
|
||||
const fileDependencies = new Set();
|
||||
const missingDependencies = new Set();
|
||||
const contextDependencies = new Set();
|
||||
const fileDependencies = new LazySet();
|
||||
const missingDependencies = new LazySet();
|
||||
const contextDependencies = new LazySet();
|
||||
/** @type {ResolveData} */
|
||||
const resolveData = {
|
||||
contextInfo,
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
"use strict";
|
||||
|
||||
const { approve } = require("./JavascriptParserHelpers");
|
||||
const NullFactory = require("./NullFactory");
|
||||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
const ProvidedDependency = require("./dependencies/ProvidedDependency");
|
||||
|
||||
|
@ -29,7 +28,6 @@ class ProvidePlugin {
|
|||
compiler.hooks.compilation.tap(
|
||||
"ProvidePlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(
|
||||
ConstDependency,
|
||||
new ConstDependency.Template()
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
"use strict";
|
||||
|
||||
const { toConstantDependency } = require("./JavascriptParserHelpers");
|
||||
const NullFactory = require("./NullFactory");
|
||||
const RuntimeGlobals = require("./RuntimeGlobals");
|
||||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
|
||||
|
@ -22,7 +21,6 @@ module.exports = class RequireJsStuffPlugin {
|
|||
compiler.hooks.compilation.tap(
|
||||
"RequireJsStuffPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(
|
||||
ConstDependency,
|
||||
new ConstDependency.Template()
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
/** @typedef {import("../Compiler")} Compiler */
|
||||
/** @typedef {import("../FileSystemInfo")} FileSystemInfo */
|
||||
/** @typedef {import("../FileSystemInfo").Snapshot} Snapshot */
|
||||
/** @template T @typedef {import("../util/LazySet")<T>} LazySet<T> */
|
||||
|
||||
/**
|
||||
* @typedef {Object} CacheEntry
|
||||
|
@ -19,6 +20,22 @@
|
|||
* @property {Snapshot} snapshot
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {Set<T> | LazySet<T>} set set to add items to
|
||||
* @param {Set<T>} otherSet set to add items from
|
||||
* @returns {void}
|
||||
*/
|
||||
const addAllToSet = (set, otherSet) => {
|
||||
if ("addAll" in set) {
|
||||
set.addAll(otherSet);
|
||||
} else {
|
||||
for (const item of otherSet) {
|
||||
set.add(item);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} request a request
|
||||
* @returns {string} stringified version
|
||||
|
@ -193,19 +210,22 @@ class ResolverCachePlugin {
|
|||
}
|
||||
cachedResolves++;
|
||||
if (resolveContext.missingDependencies) {
|
||||
for (const item of cacheEntry.missingDependencies) {
|
||||
resolveContext.missingDependencies.add(item);
|
||||
}
|
||||
addAllToSet(
|
||||
resolveContext.missingDependencies,
|
||||
cacheEntry.missingDependencies
|
||||
);
|
||||
}
|
||||
if (resolveContext.fileDependencies) {
|
||||
for (const item of cacheEntry.fileDependencies) {
|
||||
resolveContext.fileDependencies.add(item);
|
||||
}
|
||||
addAllToSet(
|
||||
resolveContext.fileDependencies,
|
||||
cacheEntry.fileDependencies
|
||||
);
|
||||
}
|
||||
if (resolveContext.contextDependencies) {
|
||||
for (const item of cacheEntry.contextDependencies) {
|
||||
resolveContext.contextDependencies.add(item);
|
||||
}
|
||||
addAllToSet(
|
||||
resolveContext.contextDependencies,
|
||||
cacheEntry.contextDependencies
|
||||
);
|
||||
}
|
||||
callback(null, cacheEntry.result);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ const {
|
|||
evaluateToString,
|
||||
toConstantDependency
|
||||
} = require("../JavascriptParserHelpers");
|
||||
const NullFactory = require("../NullFactory");
|
||||
const RuntimeGlobals = require("../RuntimeGlobals");
|
||||
|
||||
const AMDDefineDependency = require("./AMDDefineDependency");
|
||||
|
@ -52,10 +51,6 @@ class AMDPlugin {
|
|||
compiler.hooks.compilation.tap(
|
||||
"AMDPlugin",
|
||||
(compilation, { contextModuleFactory, normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(
|
||||
AMDRequireDependency,
|
||||
new NullFactory()
|
||||
);
|
||||
compilation.dependencyTemplates.set(
|
||||
AMDRequireDependency,
|
||||
new AMDRequireDependency.Template()
|
||||
|
@ -70,10 +65,6 @@ class AMDPlugin {
|
|||
new AMDRequireItemDependency.Template()
|
||||
);
|
||||
|
||||
compilation.dependencyFactories.set(
|
||||
AMDRequireArrayDependency,
|
||||
new NullFactory()
|
||||
);
|
||||
compilation.dependencyTemplates.set(
|
||||
AMDRequireArrayDependency,
|
||||
new AMDRequireArrayDependency.Template()
|
||||
|
@ -88,28 +79,16 @@ class AMDPlugin {
|
|||
new AMDRequireContextDependency.Template()
|
||||
);
|
||||
|
||||
compilation.dependencyFactories.set(
|
||||
AMDDefineDependency,
|
||||
new NullFactory()
|
||||
);
|
||||
compilation.dependencyTemplates.set(
|
||||
AMDDefineDependency,
|
||||
new AMDDefineDependency.Template()
|
||||
);
|
||||
|
||||
compilation.dependencyFactories.set(
|
||||
UnsupportedDependency,
|
||||
new NullFactory()
|
||||
);
|
||||
compilation.dependencyTemplates.set(
|
||||
UnsupportedDependency,
|
||||
new UnsupportedDependency.Template()
|
||||
);
|
||||
|
||||
compilation.dependencyFactories.set(
|
||||
LocalModuleDependency,
|
||||
new NullFactory()
|
||||
);
|
||||
compilation.dependencyTemplates.set(
|
||||
LocalModuleDependency,
|
||||
new LocalModuleDependency.Template()
|
||||
|
|
|
@ -13,8 +13,6 @@ const RequireResolveContextDependency = require("./RequireResolveContextDependen
|
|||
const RequireResolveDependency = require("./RequireResolveDependency");
|
||||
const RequireResolveHeaderDependency = require("./RequireResolveHeaderDependency");
|
||||
|
||||
const NullFactory = require("../NullFactory");
|
||||
|
||||
const CommonJsRequireDependencyParserPlugin = require("./CommonJsRequireDependencyParserPlugin");
|
||||
const RequireResolveDependencyParserPlugin = require("./RequireResolveDependencyParserPlugin");
|
||||
|
||||
|
@ -72,19 +70,11 @@ class CommonJsPlugin {
|
|||
new RequireResolveContextDependency.Template()
|
||||
);
|
||||
|
||||
compilation.dependencyFactories.set(
|
||||
RequireResolveHeaderDependency,
|
||||
new NullFactory()
|
||||
);
|
||||
compilation.dependencyTemplates.set(
|
||||
RequireResolveHeaderDependency,
|
||||
new RequireResolveHeaderDependency.Template()
|
||||
);
|
||||
|
||||
compilation.dependencyFactories.set(
|
||||
RequireHeaderDependency,
|
||||
new NullFactory()
|
||||
);
|
||||
compilation.dependencyTemplates.set(
|
||||
RequireHeaderDependency,
|
||||
new RequireHeaderDependency.Template()
|
||||
|
|
|
@ -66,13 +66,15 @@ class ContextDependency extends Dependency {
|
|||
* @returns {WebpackError[]} warnings
|
||||
*/
|
||||
getWarnings(moduleGraph) {
|
||||
let warnings = super.getWarnings(moduleGraph) || [];
|
||||
let warnings = super.getWarnings(moduleGraph);
|
||||
|
||||
if (this.critical) {
|
||||
if (!warnings) warnings = [];
|
||||
warnings.push(new CriticalDependencyWarning(this.critical));
|
||||
}
|
||||
|
||||
if (this.hadGlobalOrStickyRegExp) {
|
||||
if (!warnings) warnings = [];
|
||||
warnings.push(
|
||||
new CriticalDependencyWarning(
|
||||
"Contexts can't use RegExps with the 'g' or 'y' flags."
|
||||
|
|
|
@ -492,7 +492,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|||
this.strictExportPresence ||
|
||||
moduleGraph.getParentModule(this).buildMeta.strictHarmonyModule
|
||||
) {
|
||||
return [];
|
||||
return null;
|
||||
}
|
||||
|
||||
return this._getErrors(moduleGraph);
|
||||
|
@ -511,7 +511,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|||
return this._getErrors(moduleGraph);
|
||||
}
|
||||
|
||||
return [];
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -96,7 +96,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|||
this.strictExportPresence ||
|
||||
moduleGraph.getParentModule(this).buildMeta.strictHarmonyModule
|
||||
) {
|
||||
return [];
|
||||
return null;
|
||||
}
|
||||
return this._getErrors(moduleGraph);
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|||
) {
|
||||
return this._getErrors(moduleGraph);
|
||||
}
|
||||
return [];
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,8 +15,6 @@ const HarmonyExportSpecifierDependency = require("./HarmonyExportSpecifierDepend
|
|||
const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
|
||||
const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
|
||||
|
||||
const NullFactory = require("../NullFactory");
|
||||
|
||||
const HarmonyDetectionParserPlugin = require("./HarmonyDetectionParserPlugin");
|
||||
const HarmonyExportDependencyParserPlugin = require("./HarmonyExportDependencyParserPlugin");
|
||||
const HarmonyImportDependencyParserPlugin = require("./HarmonyImportDependencyParserPlugin");
|
||||
|
@ -37,10 +35,6 @@ class HarmonyModulesPlugin {
|
|||
compiler.hooks.compilation.tap(
|
||||
"HarmonyModulesPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(
|
||||
HarmonyCompatibilityDependency,
|
||||
new NullFactory()
|
||||
);
|
||||
compilation.dependencyTemplates.set(
|
||||
HarmonyCompatibilityDependency,
|
||||
new HarmonyCompatibilityDependency.Template()
|
||||
|
@ -64,28 +58,16 @@ class HarmonyModulesPlugin {
|
|||
new HarmonyImportSpecifierDependency.Template()
|
||||
);
|
||||
|
||||
compilation.dependencyFactories.set(
|
||||
HarmonyExportHeaderDependency,
|
||||
new NullFactory()
|
||||
);
|
||||
compilation.dependencyTemplates.set(
|
||||
HarmonyExportHeaderDependency,
|
||||
new HarmonyExportHeaderDependency.Template()
|
||||
);
|
||||
|
||||
compilation.dependencyFactories.set(
|
||||
HarmonyExportExpressionDependency,
|
||||
new NullFactory()
|
||||
);
|
||||
compilation.dependencyTemplates.set(
|
||||
HarmonyExportExpressionDependency,
|
||||
new HarmonyExportExpressionDependency.Template()
|
||||
);
|
||||
|
||||
compilation.dependencyFactories.set(
|
||||
HarmonyExportSpecifierDependency,
|
||||
new NullFactory()
|
||||
);
|
||||
compilation.dependencyTemplates.set(
|
||||
HarmonyExportSpecifierDependency,
|
||||
new HarmonyExportSpecifierDependency.Template()
|
||||
|
@ -100,10 +82,6 @@ class HarmonyModulesPlugin {
|
|||
new HarmonyExportImportedSpecifierDependency.Template()
|
||||
);
|
||||
|
||||
compilation.dependencyFactories.set(
|
||||
HarmonyAcceptDependency,
|
||||
new NullFactory()
|
||||
);
|
||||
compilation.dependencyTemplates.set(
|
||||
HarmonyAcceptDependency,
|
||||
new HarmonyAcceptDependency.Template()
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
const RequireEnsureDependency = require("./RequireEnsureDependency");
|
||||
const RequireEnsureItemDependency = require("./RequireEnsureItemDependency");
|
||||
|
||||
const NullFactory = require("../NullFactory");
|
||||
|
||||
const RequireEnsureDependenciesBlockParserPlugin = require("./RequireEnsureDependenciesBlockParserPlugin");
|
||||
|
||||
const {
|
||||
|
@ -31,10 +29,6 @@ class RequireEnsurePlugin {
|
|||
new RequireEnsureItemDependency.Template()
|
||||
);
|
||||
|
||||
compilation.dependencyFactories.set(
|
||||
RequireEnsureDependency,
|
||||
new NullFactory()
|
||||
);
|
||||
compilation.dependencyTemplates.set(
|
||||
RequireEnsureDependency,
|
||||
new RequireEnsureDependency.Template()
|
||||
|
|
|
@ -22,6 +22,7 @@ const HarmonyExportSpecifierDependency = require("../dependencies/HarmonyExportS
|
|||
const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
|
||||
const HarmonyImportSideEffectDependency = require("../dependencies/HarmonyImportSideEffectDependency");
|
||||
const HarmonyImportSpecifierDependency = require("../dependencies/HarmonyImportSpecifierDependency");
|
||||
const LazySet = require("../util/LazySet");
|
||||
const createHash = require("../util/createHash");
|
||||
const contextify = require("../util/identifier").contextify;
|
||||
const propertyAccess = require("../util/propertyAccess");
|
||||
|
@ -477,8 +478,9 @@ class ConcatenatedModule extends Module {
|
|||
cacheable: modulesArray.every(m => m.buildInfo.cacheable),
|
||||
moduleArgument: rootModule.buildInfo.moduleArgument,
|
||||
exportsArgument: rootModule.buildInfo.exportsArgument,
|
||||
fileDependencies: new Set(),
|
||||
contextDependencies: new Set(),
|
||||
fileDependencies: new LazySet(),
|
||||
contextDependencies: new LazySet(),
|
||||
missingDependencies: new LazySet(),
|
||||
assets: undefined
|
||||
};
|
||||
this.buildMeta = rootModule.buildMeta;
|
||||
|
@ -510,15 +512,19 @@ class ConcatenatedModule extends Module {
|
|||
}
|
||||
// populate file dependencies
|
||||
if (m.buildInfo.fileDependencies) {
|
||||
for (const file of m.buildInfo.fileDependencies) {
|
||||
this.buildInfo.fileDependencies.add(file);
|
||||
}
|
||||
this.buildInfo.fileDependencies.addAll(m.buildInfo.fileDependencies);
|
||||
}
|
||||
// populate context dependencies
|
||||
if (m.buildInfo.contextDependencies) {
|
||||
for (const context of m.buildInfo.contextDependencies) {
|
||||
this.buildInfo.contextDependencies.add(context);
|
||||
}
|
||||
this.buildInfo.contextDependencies.addAll(
|
||||
m.buildInfo.contextDependencies
|
||||
);
|
||||
}
|
||||
// populate missing dependencies
|
||||
if (m.buildInfo.missingDependencies) {
|
||||
this.buildInfo.missingDependencies.addAll(
|
||||
m.buildInfo.missingDependencies
|
||||
);
|
||||
}
|
||||
// populate warnings
|
||||
for (const warning of m.warnings) {
|
||||
|
|
|
@ -0,0 +1,151 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {Set<T>} targetSet set where items should be added
|
||||
* @param {Set<Iterable<T> | LazySet<T>>} toMerge iterables or lazy set to be merged
|
||||
*/
|
||||
const merge = (targetSet, toMerge) => {
|
||||
for (const set of toMerge) {
|
||||
if (set instanceof LazySet) {
|
||||
for (const item of set._set) {
|
||||
targetSet.add(item);
|
||||
}
|
||||
if (set._needMerge) {
|
||||
merge(targetSet, set._toMerge);
|
||||
}
|
||||
} else {
|
||||
for (const item of set) {
|
||||
targetSet.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Like Set but with an addAll method to eventually add items from another iterable.
|
||||
* Access methods make sure that all delayed operations are executed.
|
||||
* Iteration methods deopts to normal Set performance until clear is called again (because of the chance of modifications during iteration).
|
||||
* @template T
|
||||
*/
|
||||
class LazySet {
|
||||
/**
|
||||
* @param {Iterable<T>=} iterable init interable
|
||||
*/
|
||||
constructor(iterable) {
|
||||
/** @type {Set<T>} */
|
||||
this._set = new Set(iterable);
|
||||
/** @type {Set<Iterable<T> | LazySet<T>>} */
|
||||
this._toMerge = new Set();
|
||||
this._needMerge = false;
|
||||
this._deopt = false;
|
||||
}
|
||||
|
||||
_merge() {
|
||||
merge(this._set, this._toMerge);
|
||||
this._toMerge.clear();
|
||||
this._needMerge = false;
|
||||
}
|
||||
|
||||
get size() {
|
||||
if (this._needMerge) this._merge();
|
||||
return this._set.size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {T} item an item
|
||||
* @returns {this} itself
|
||||
*/
|
||||
add(item) {
|
||||
this._set.add(item);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Iterable<T> | LazySet<T>} iterable a immutable iterable or another immutable LazySet which will eventually be merged into the Set
|
||||
* @returns {this} itself
|
||||
*/
|
||||
addAll(iterable) {
|
||||
if (this._deopt) {
|
||||
const _set = this._set;
|
||||
for (const item of iterable) {
|
||||
_set.add(item);
|
||||
}
|
||||
} else {
|
||||
this._toMerge.add(iterable);
|
||||
this._needMerge = true;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
clear() {
|
||||
this._set.clear();
|
||||
this._toMerge.clear();
|
||||
this._needMerge = false;
|
||||
this._deopt = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {T} value an item
|
||||
* @returns {boolean} true, if the value was in the Set before
|
||||
*/
|
||||
delete(value) {
|
||||
if (this._needMerge) this._merge();
|
||||
return this._set.delete(value);
|
||||
}
|
||||
|
||||
entries() {
|
||||
this._deopt = true;
|
||||
if (this._needMerge) this._merge();
|
||||
return this._set.entries();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {function(T, T, Set<T>): void} callbackFn function called for each entry
|
||||
* @param {any} thisArg this argument for the callbackFn
|
||||
* @returns {void}
|
||||
*/
|
||||
forEach(callbackFn, thisArg) {
|
||||
this._deopt = true;
|
||||
if (this._needMerge) this._merge();
|
||||
this._set.forEach(callbackFn, thisArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {T} item an item
|
||||
* @returns {boolean} true, when the item is in the Set
|
||||
*/
|
||||
has(item) {
|
||||
if (this._needMerge) this._merge();
|
||||
return this._set.has(item);
|
||||
}
|
||||
|
||||
keys() {
|
||||
this._deopt = true;
|
||||
if (this._needMerge) this._merge();
|
||||
return this._set.keys();
|
||||
}
|
||||
|
||||
values() {
|
||||
this._deopt = true;
|
||||
if (this._needMerge) this._merge();
|
||||
return this._set.values();
|
||||
}
|
||||
|
||||
[Symbol.iterator]() {
|
||||
this._deopt = true;
|
||||
if (this._needMerge) this._merge();
|
||||
return this._set[Symbol.iterator]();
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
return "LazySet";
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LazySet;
|
Loading…
Reference in New Issue