add presentational dependencies which are cheaper, but allow only templating

This commit is contained in:
Tobias Koppers 2019-10-30 06:40:40 +01:00
parent 951792b8eb
commit a877cd51d1
29 changed files with 154 additions and 116 deletions

View File

@ -126,7 +126,7 @@ class CommonJsStuffPlugin {
RuntimeGlobals.module RuntimeGlobals.module
]); ]);
dep.loc = expr.loc; dep.loc = expr.loc;
module.addDependency(dep); module.addPresentationalDependency(dep);
return true; return true;
} }
return toConstantDependency( return toConstantDependency(
@ -167,7 +167,7 @@ class CommonJsStuffPlugin {
: RuntimeGlobals.nodeModuleDecorator : RuntimeGlobals.nodeModuleDecorator
); );
dep.loc = expr.loc; dep.loc = expr.loc;
parser.state.module.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return true; return true;
}); });
}; };

View File

@ -46,7 +46,7 @@ class CompatibilityPlugin {
if (second.asBool() !== true) return; if (second.asBool() !== true) return;
const dep = new ConstDependency("require", expr.callee.range); const dep = new ConstDependency("require", expr.callee.range);
dep.loc = expr.loc; dep.loc = expr.loc;
if (parser.state.current.dependencies.length > 1) { if (parser.state.current.dependencies.length > 0) {
const last = const last =
parser.state.current.dependencies[ parser.state.current.dependencies[
parser.state.current.dependencies.length - 1 parser.state.current.dependencies.length - 1
@ -60,7 +60,7 @@ class CompatibilityPlugin {
) )
parser.state.current.dependencies.pop(); parser.state.current.dependencies.pop();
} }
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return true; return true;
}); });
}); });
@ -81,7 +81,7 @@ class CompatibilityPlugin {
}__`; }__`;
const dep = new ConstDependency(newName, statement.id.range); const dep = new ConstDependency(newName, statement.id.range);
dep.loc = statement.id.loc; dep.loc = statement.id.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
parser.tagVariable( parser.tagVariable(
statement.id.name, statement.id.name,
nestedWebpackRequireTag, nestedWebpackRequireTag,
@ -96,7 +96,7 @@ class CompatibilityPlugin {
const newName = `__nested_webpack_require_${pattern.range[0]}__`; const newName = `__nested_webpack_require_${pattern.range[0]}__`;
const dep = new ConstDependency(newName, pattern.range); const dep = new ConstDependency(newName, pattern.range);
dep.loc = pattern.loc; dep.loc = pattern.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
parser.tagVariable( parser.tagVariable(
pattern.name, pattern.name,
nestedWebpackRequireTag, nestedWebpackRequireTag,
@ -110,7 +110,7 @@ class CompatibilityPlugin {
const newName = parser.currentTagData; const newName = parser.currentTagData;
const dep = new ConstDependency(newName, expr.range); const dep = new ConstDependency(newName, expr.range);
dep.loc = expr.loc; dep.loc = expr.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return true; return true;
}); });
}; };

View File

@ -137,7 +137,7 @@ class ConstPlugin {
if (statement.test.type !== "Literal") { if (statement.test.type !== "Literal") {
const dep = new ConstDependency(`${bool}`, param.range); const dep = new ConstDependency(`${bool}`, param.range);
dep.loc = statement.loc; dep.loc = statement.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
} }
const branchToRemove = bool const branchToRemove = bool
? statement.alternate ? statement.alternate
@ -193,7 +193,7 @@ class ConstPlugin {
branchToRemove.range branchToRemove.range
); );
dep.loc = branchToRemove.loc; dep.loc = branchToRemove.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
} }
return bool; return bool;
} }
@ -207,7 +207,7 @@ class ConstPlugin {
if (expression.test.type !== "Literal") { if (expression.test.type !== "Literal") {
const dep = new ConstDependency(` ${bool}`, param.range); const dep = new ConstDependency(` ${bool}`, param.range);
dep.loc = expression.loc; dep.loc = expression.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
} }
// Expressions do not hoist. // Expressions do not hoist.
// It is safe to remove the dead branch. // It is safe to remove the dead branch.
@ -228,7 +228,7 @@ class ConstPlugin {
branchToRemove.range branchToRemove.range
); );
dep.loc = branchToRemove.loc; dep.loc = branchToRemove.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return bool; return bool;
} }
} }
@ -301,7 +301,7 @@ class ConstPlugin {
// //
const dep = new ConstDependency(` ${bool}`, param.range); const dep = new ConstDependency(` ${bool}`, param.range);
dep.loc = expression.loc; dep.loc = expression.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
} else { } else {
parser.walkExpression(expression.left); parser.walkExpression(expression.left);
} }
@ -311,7 +311,7 @@ class ConstPlugin {
expression.right.range expression.right.range
); );
dep.loc = expression.loc; dep.loc = expression.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
} }
return keepRight; return keepRight;
} }
@ -336,7 +336,7 @@ class ConstPlugin {
"__resourceQuery" "__resourceQuery"
); );
dep.loc = expr.loc; dep.loc = expr.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return true; return true;
}); });
}; };

View File

@ -61,30 +61,12 @@ class DependenciesBlock {
* @returns {void} * @returns {void}
*/ */
updateHash(hash, chunkGraph) { updateHash(hash, chunkGraph) {
for (const dep of this.dependencies) dep.updateHash(hash, chunkGraph); for (const dep of this.dependencies) {
for (const block of this.blocks) block.updateHash(hash, chunkGraph); dep.updateHash(hash, chunkGraph);
}
/**
* @param {DependencyFilterFunction} filter filter function for dependencies, gets passed all dependency ties from current instance
* @returns {boolean} returns boolean for filter
*/
hasDependencies(filter) {
if (filter) {
for (const dep of this.dependencies) {
if (filter(dep)) return true;
}
} else {
if (this.dependencies.length > 0) {
return true;
}
} }
for (const block of this.blocks) { for (const block of this.blocks) {
if (block.hasDependencies(filter)) return true; block.updateHash(hash, chunkGraph);
} }
return false;
} }
serialize({ write }) { serialize({ write }) {

View File

@ -49,7 +49,7 @@ class ExportsInfoApiPlugin {
.tap("ExportsInfoApiPlugin", expr => { .tap("ExportsInfoApiPlugin", expr => {
const dep = new ConstDependency("true", expr.range); const dep = new ConstDependency("true", expr.range);
dep.loc = expr.loc; dep.loc = expr.loc;
parser.state.module.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return true; return true;
}); });
}; };

View File

@ -116,6 +116,8 @@ class Module extends DependenciesBlock {
this.buildMeta = undefined; this.buildMeta = undefined;
/** @type {object} */ /** @type {object} */
this.buildInfo = undefined; this.buildInfo = undefined;
/** @type {Dependency[]} */
this.presentationalDependencies = [];
} }
// TODO remove in webpack 6 // TODO remove in webpack 6
@ -323,6 +325,15 @@ class Module extends DependenciesBlock {
return (this.buildInfo && this.buildInfo.moduleArgument) || "module"; return (this.buildInfo && this.buildInfo.moduleArgument) || "module";
} }
/**
* @param {Dependency} presentationalDependency dependency being tied to module.
* This is a Dependency without edge in the module graph. It's only for presentation.
* @returns {void}
*/
addPresentationalDependency(presentationalDependency) {
this.presentationalDependencies.push(presentationalDependency);
}
/** /**
* @param {ModuleGraph} moduleGraph the module graph * @param {ModuleGraph} moduleGraph the module graph
* @returns {boolean} true, if the module is optional * @returns {boolean} true, if the module is optional
@ -483,6 +494,9 @@ class Module extends DependenciesBlock {
hash.update(exportInfo.used + ""); hash.update(exportInfo.used + "");
hash.update(exportInfo.usedName + ""); hash.update(exportInfo.usedName + "");
} }
for (const dep of this.presentationalDependencies) {
dep.updateHash(hash, chunkGraph);
}
super.updateHash(hash, chunkGraph); super.updateHash(hash, chunkGraph);
} }
@ -659,6 +673,7 @@ class Module extends DependenciesBlock {
write(this.errors); write(this.errors);
write(this.buildMeta); write(this.buildMeta);
write(this.buildInfo); write(this.buildInfo);
write(this.presentationalDependencies);
super.serialize(context); super.serialize(context);
} }
@ -673,6 +688,7 @@ class Module extends DependenciesBlock {
this.errors = read(); this.errors = read();
this.buildMeta = read(); this.buildMeta = read();
this.buildInfo = read(); this.buildInfo = read();
this.presentationalDependencies = read();
super.deserialize(context); super.deserialize(context);
} }
} }

View File

@ -51,7 +51,7 @@ class NodeStuffPlugin {
expressionName expressionName
); );
dep.loc = expr.loc; dep.loc = expr.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return true; return true;
}); });
}; };

View File

@ -559,6 +559,7 @@ class NormalModule extends Module {
this.errors.length = 0; this.errors.length = 0;
this.warnings.length = 0; this.warnings.length = 0;
this.dependencies.length = 0; this.dependencies.length = 0;
this.presentationalDependencies.length = 0;
this.blocks.length = 0; this.blocks.length = 0;
this.buildMeta = {}; this.buildMeta = {};
this.buildInfo = { this.buildInfo = {

View File

@ -32,7 +32,7 @@ class UseStrictPlugin {
// @see https://github.com/webpack/webpack/issues/1970 // @see https://github.com/webpack/webpack/issues/1970
const dep = new ConstDependency("", firstNode.range); const dep = new ConstDependency("", firstNode.range);
dep.loc = firstNode.loc; dep.loc = firstNode.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
parser.state.module.buildInfo.strict = true; parser.state.module.buildInfo.strict = true;
} }
}); });

View File

@ -80,7 +80,7 @@ class AMDDefineDependencyParserPlugin {
localModule.flagUsed(); localModule.flagUsed();
dep = new LocalModuleDependency(localModule, undefined, false); dep = new LocalModuleDependency(localModule, undefined, false);
dep.loc = expr.loc; dep.loc = expr.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
} else { } else {
dep = this.newRequireItemDependency(request); dep = this.newRequireItemDependency(request);
dep.loc = expr.loc; dep.loc = expr.loc;
@ -92,7 +92,7 @@ class AMDDefineDependencyParserPlugin {
const dep = this.newRequireArrayDependency(deps, param.range); const dep = this.newRequireArrayDependency(deps, param.range);
dep.loc = expr.loc; dep.loc = expr.loc;
dep.optional = !!parser.scope.inTry; dep.optional = !!parser.scope.inTry;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return true; return true;
} }
} }
@ -126,10 +126,12 @@ class AMDDefineDependencyParserPlugin {
dep = new LocalModuleDependency(localModule, param.range, false); dep = new LocalModuleDependency(localModule, param.range, false);
} else { } else {
dep = this.newRequireItemDependency(param.string, param.range); dep = this.newRequireItemDependency(param.string, param.range);
dep.optional = !!parser.scope.inTry;
parser.state.current.addDependency(dep);
return true;
} }
dep.loc = expr.loc; dep.loc = expr.loc;
dep.optional = !!parser.scope.inTry; parser.state.module.addPresentationalDependency(dep);
parser.state.current.addDependency(dep);
return true; return true;
} }
} }
@ -311,7 +313,7 @@ class AMDDefineDependencyParserPlugin {
if (namedModule) { if (namedModule) {
dep.localModule = addLocalModule(parser.state, namedModule); dep.localModule = addLocalModule(parser.state, namedModule);
} }
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return true; return true;
} }

View File

@ -168,7 +168,7 @@ class AMDPlugin {
[RuntimeGlobals.amdDefine] [RuntimeGlobals.amdDefine]
); );
dep.loc = expr.loc; dep.loc = expr.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return true; return true;
}); });
parser.hooks.typeof parser.hooks.typeof
@ -188,7 +188,7 @@ class AMDPlugin {
[RuntimeGlobals.amdDefine] [RuntimeGlobals.amdDefine]
); );
dep.loc = expr.loc; dep.loc = expr.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return false; return false;
}); });
parser.hooks.typeof parser.hooks.typeof

View File

@ -5,14 +5,15 @@
"use strict"; "use strict";
const Dependency = require("../Dependency");
const DependencyTemplate = require("../DependencyTemplate"); const DependencyTemplate = require("../DependencyTemplate");
const makeSerializable = require("../util/makeSerializable"); const makeSerializable = require("../util/makeSerializable");
const NullDependency = require("./NullDependency");
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */ /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
/** @typedef {import("../Dependency")} Dependency */
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */ /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
class AMDRequireArrayDependency extends Dependency { class AMDRequireArrayDependency extends NullDependency {
constructor(depsArray, range) { constructor(depsArray, range) {
super(); super();

View File

@ -80,7 +80,7 @@ class AMDRequireDependenciesBlockParserPlugin {
localModule.flagUsed(); localModule.flagUsed();
dep = new LocalModuleDependency(localModule, undefined, false); dep = new LocalModuleDependency(localModule, undefined, false);
dep.loc = expr.loc; dep.loc = expr.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
} else { } else {
dep = this.newRequireItemDependency(request); dep = this.newRequireItemDependency(request);
dep.loc = expr.loc; dep.loc = expr.loc;
@ -92,7 +92,7 @@ class AMDRequireDependenciesBlockParserPlugin {
const dep = this.newRequireArrayDependency(deps, param.range); const dep = this.newRequireArrayDependency(deps, param.range);
dep.loc = expr.loc; dep.loc = expr.loc;
dep.optional = !!parser.scope.inTry; dep.optional = !!parser.scope.inTry;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return true; return true;
} }
} }
@ -128,10 +128,13 @@ class AMDRequireDependenciesBlockParserPlugin {
dep = new LocalModuleDependency(localModule, param.range, false); dep = new LocalModuleDependency(localModule, param.range, false);
} else { } else {
dep = this.newRequireItemDependency(param.string, param.range); dep = this.newRequireItemDependency(param.string, param.range);
dep.loc = expr.loc;
dep.optional = !!parser.scope.inTry;
parser.state.current.addDependency(dep);
return true;
} }
dep.loc = expr.loc; dep.loc = expr.loc;
dep.optional = !!parser.scope.inTry; parser.state.module.addPresentationalDependency(dep);
parser.state.current.addDependency(dep);
return true; return true;
} }
} }
@ -217,7 +220,7 @@ class AMDRequireDependenciesBlockParserPlugin {
}); });
if (!result) { if (!result) {
const dep = new UnsupportedDependency("unsupported", expr.range); const dep = new UnsupportedDependency("unsupported", expr.range);
old.addDependency(dep); old.addPresentationalDependency(dep);
if (parser.state.module) { if (parser.state.module) {
parser.state.module.errors.push( parser.state.module.errors.push(
new UnsupportedFeatureWarning( new UnsupportedFeatureWarning(

View File

@ -121,7 +121,7 @@ class CommonJsPlugin {
// to not leak to global "require", we need to define a local require here. // to not leak to global "require", we need to define a local require here.
const dep = new ConstDependency("var require;", 0); const dep = new ConstDependency("var require;", 0);
dep.loc = expr.loc; dep.loc = expr.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return true; return true;
}); });
parser.hooks.canRename parser.hooks.canRename
@ -131,7 +131,7 @@ class CommonJsPlugin {
// To avoid "not defined" error, replace the value with undefined // To avoid "not defined" error, replace the value with undefined
const dep = new ConstDependency("undefined", expr.range); const dep = new ConstDependency("undefined", expr.range);
dep.loc = expr.loc; dep.loc = expr.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return false; return false;
}); });
parser.hooks.typeof parser.hooks.typeof

View File

@ -85,19 +85,16 @@ class CommonJsRequireDependencyParserPlugin {
const param = parser.evaluateExpression(expr.arguments[0]); const param = parser.evaluateExpression(expr.arguments[0]);
if (param.isConditional()) { if (param.isConditional()) {
let isExpression = false; let isExpression = false;
const prevLength = parser.state.current.dependencies.length;
const dep = new RequireHeaderDependency(expr.callee.range);
dep.loc = expr.loc;
parser.state.current.addDependency(dep);
for (const p of param.options) { for (const p of param.options) {
const result = processItem(expr, p); const result = processItem(expr, p);
if (result === undefined) { if (result === undefined) {
isExpression = true; isExpression = true;
} }
} }
if (isExpression) { if (!isExpression) {
parser.state.current.dependencies.length = prevLength; const dep = new RequireHeaderDependency(expr.callee.range);
} else { dep.loc = expr.loc;
parser.state.module.addPresentationalDependency(dep);
return true; return true;
} }
} }
@ -108,7 +105,7 @@ class CommonJsRequireDependencyParserPlugin {
localModule.flagUsed(); localModule.flagUsed();
const dep = new LocalModuleDependency(localModule, expr.range, callNew); const dep = new LocalModuleDependency(localModule, expr.range, callNew);
dep.loc = expr.loc; dep.loc = expr.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return true; return true;
} else { } else {
const result = processItem(expr, param); const result = processItem(expr, param);
@ -117,7 +114,7 @@ class CommonJsRequireDependencyParserPlugin {
} else { } else {
const dep = new RequireHeaderDependency(expr.callee.range); const dep = new RequireHeaderDependency(expr.callee.range);
dep.loc = expr.loc; dep.loc = expr.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
} }
return true; return true;
} }

View File

@ -47,7 +47,7 @@ module.exports = class HarmonyDetectionParserPlugin {
}, },
index: -3 index: -3
}; };
module.addDependency(compatDep); module.addPresentationalDependency(compatDep);
parser.state.harmonyModule = true; parser.state.harmonyModule = true;
parser.scope.isStrict = true; parser.scope.isStrict = true;
module.buildMeta.exportsType = "namespace"; module.buildMeta.exportsType = "namespace";

View File

@ -33,7 +33,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
); );
dep.loc = Object.create(statement.loc); dep.loc = Object.create(statement.loc);
dep.loc.index = -1; dep.loc.index = -1;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return true; return true;
} }
); );
@ -45,7 +45,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
const clearDep = new ConstDependency("", statement.range); const clearDep = new ConstDependency("", statement.range);
clearDep.loc = Object.create(statement.loc); clearDep.loc = Object.create(statement.loc);
clearDep.loc.index = -1; clearDep.loc.index = -1;
parser.state.current.addDependency(clearDep); parser.state.module.addPresentationalDependency(clearDep);
const sideEffectDep = new HarmonyImportSideEffectDependency( const sideEffectDep = new HarmonyImportSideEffectDependency(
source, source,
parser.state.lastHarmonyImportOrder parser.state.lastHarmonyImportOrder

View File

@ -43,7 +43,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
(parser.state.lastHarmonyImportOrder || 0) + 1; (parser.state.lastHarmonyImportOrder || 0) + 1;
const clearDep = new ConstDependency("", statement.range); const clearDep = new ConstDependency("", statement.range);
clearDep.loc = statement.loc; clearDep.loc = statement.loc;
parser.state.module.addDependency(clearDep); parser.state.module.addPresentationalDependency(clearDep);
const sideEffectDep = new HarmonyImportSideEffectDependency( const sideEffectDep = new HarmonyImportSideEffectDependency(
source, source,
parser.state.lastHarmonyImportOrder parser.state.lastHarmonyImportOrder

View File

@ -18,7 +18,7 @@ class HarmonyTopLevelThisParserPlugin {
if (isHarmony) { if (isHarmony) {
const dep = new ConstDependency("undefined", node.range, null); const dep = new ConstDependency("undefined", node.range, null);
dep.loc = node.loc; dep.loc = node.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
} }
}); });
} }

View File

@ -28,12 +28,12 @@ class NullDependency extends Dependency {
*/ */
updateHash(hash, chunkGraph) {} updateHash(hash, chunkGraph) {}
serialize(context) { serialize({ write }) {
// do nothing write(this.loc);
} }
deserialize(context) { deserialize({ read }) {
// do nothing this.loc = read();
} }
} }

View File

@ -30,7 +30,7 @@ class RequireResolveDependencyParserPlugin {
} }
const dep = new RequireResolveHeaderDependency(expr.callee.range); const dep = new RequireResolveHeaderDependency(expr.callee.range);
dep.loc = expr.loc; dep.loc = expr.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return true; return true;
} else { } else {
const result = processItem(expr, param, weak); const result = processItem(expr, param, weak);
@ -39,7 +39,7 @@ class RequireResolveDependencyParserPlugin {
} }
const dep = new RequireResolveHeaderDependency(expr.callee.range); const dep = new RequireResolveHeaderDependency(expr.callee.range);
dep.loc = expr.loc; dep.loc = expr.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return true; return true;
} }
}; };

View File

@ -91,7 +91,7 @@ class SystemPlugin {
RuntimeGlobals.system RuntimeGlobals.system
]); ]);
dep.loc = expr.loc; dep.loc = expr.loc;
parser.state.module.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return true; return true;
}); });

View File

@ -85,7 +85,7 @@ class JavascriptGenerator extends Generator {
const source = new ReplaceSource(originalSource); const source = new ReplaceSource(originalSource);
const initFragments = []; const initFragments = [];
this.sourceBlock(module, module, initFragments, source, generateContext); this.sourceModule(module, initFragments, source, generateContext);
if (initFragments.length > 0) { if (initFragments.length > 0) {
// Sort fragments by position. If 2 fragments have the same position, // Sort fragments by position. If 2 fragments have the same position,
@ -130,6 +130,45 @@ class JavascriptGenerator extends Generator {
} }
} }
/**
* @param {Module} module the module to generate
* @param {InitFragment[]} initFragments mutable list of init fragments
* @param {ReplaceSource} source the current replace source which can be modified
* @param {GenerateContext} generateContext the generateContext
* @returns {void}
*/
sourceModule(module, initFragments, source, generateContext) {
for (const dependency of module.dependencies) {
this.sourceDependency(
module,
dependency,
initFragments,
source,
generateContext
);
}
for (const dependency of module.presentationalDependencies) {
this.sourceDependency(
module,
dependency,
initFragments,
source,
generateContext
);
}
for (const childBlock of module.blocks) {
this.sourceBlock(
module,
childBlock,
initFragments,
source,
generateContext
);
}
}
/** /**
* @param {Module} module the module to generate * @param {Module} module the module to generate
* @param {DependenciesBlock} block the dependencies block which will be processed * @param {DependenciesBlock} block the dependencies block which will be processed

View File

@ -13,7 +13,7 @@ exports.toConstantDependency = (parser, value, runtimeRequirements) => {
return function constDependency(expr) { return function constDependency(expr) {
const dep = new ConstDependency(value, expr.range, runtimeRequirements); const dep = new ConstDependency(value, expr.range, runtimeRequirements);
dep.loc = expr.loc; dep.loc = expr.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
return true; return true;
}; };
}; };
@ -50,7 +50,7 @@ exports.expressionIsUnsupported = (parser, message) => {
return function unsupportedExpression(expr) { return function unsupportedExpression(expr) {
const dep = new ConstDependency("(void 0)", expr.range, null); const dep = new ConstDependency("(void 0)", expr.range, null);
dep.loc = expr.loc; dep.loc = expr.loc;
parser.state.current.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
if (!parser.state.module) return; if (!parser.state.module) return;
parser.state.module.warnings.push( parser.state.module.warnings.push(
new UnsupportedFeatureWarning(message, expr.loc) new UnsupportedFeatureWarning(message, expr.loc)

View File

@ -51,7 +51,7 @@ module.exports = class NodeSourcePlugin {
[RuntimeGlobals.global] [RuntimeGlobals.global]
); );
dep.loc = expr.loc; dep.loc = expr.loc;
parser.state.module.addDependency(dep); parser.state.module.addPresentationalDependency(dep);
}); });
} }
}; };

View File

@ -577,6 +577,7 @@ class ConcatenatedModule extends Module {
// Graph // Graph
this.dependencies = []; this.dependencies = [];
this.presentationalDependencies = [];
this.warnings = []; this.warnings = [];
this.errors = []; this.errors = [];
@ -597,6 +598,13 @@ class ConcatenatedModule extends Module {
)) { )) {
this.dependencies.push(d); this.dependencies.push(d);
} }
for (const d of m.presentationalDependencies.filter(
dep =>
!(dep instanceof HarmonyImportDependency) ||
!modules.has(compilation.moduleGraph.getModule(dep))
)) {
this.presentationalDependencies.push(d);
}
// populate file dependencies // populate file dependencies
if (m.buildInfo.fileDependencies) { if (m.buildInfo.fileDependencies) {
this.buildInfo.fileDependencies.addAll(m.buildInfo.fileDependencies); this.buildInfo.fileDependencies.addAll(m.buildInfo.fileDependencies);

View File

@ -113,7 +113,7 @@ class ModuleConcatenationPlugin {
if ( if (
!module.buildMeta || !module.buildMeta ||
module.buildMeta.exportsType !== "namespace" || module.buildMeta.exportsType !== "namespace" ||
!module.dependencies.some( !module.presentationalDependencies.some(
d => d instanceof HarmonyCompatibilityDependency d => d instanceof HarmonyCompatibilityDependency
) )
) { ) {

View File

@ -1,7 +1,6 @@
"use strict"; "use strict";
const NormalModule = require("../lib/NormalModule"); const NormalModule = require("../lib/NormalModule");
const NullDependency = require("../lib/dependencies/NullDependency");
const SourceMapSource = require("webpack-sources").SourceMapSource; const SourceMapSource = require("webpack-sources").SourceMapSource;
const OriginalSource = require("webpack-sources").OriginalSource; const OriginalSource = require("webpack-sources").OriginalSource;
const RawSource = require("webpack-sources").RawSource; const RawSource = require("webpack-sources").RawSource;
@ -180,16 +179,6 @@ describe("NormalModule", () => {
}); });
}); });
describe("#hasDependencies", () => {
it("returns true if has dependencies", () => {
normalModule.addDependency(new NullDependency());
expect(normalModule.hasDependencies()).toBe(true);
});
it("returns false if has dependencies", () => {
expect(normalModule.hasDependencies()).toBe(false);
});
});
describe("#applyNoParseRule", () => { describe("#applyNoParseRule", () => {
let rule; let rule;
let content; let content;

View File

@ -131,7 +131,7 @@ chunk 6e33027b71300dfeba9c.js 899 bytes [rendered]
`; `;
exports[`StatsTestCases should print correct stats for asset 1`] = ` exports[`StatsTestCases should print correct stats for asset 1`] = `
"Hash: c4ecc4ac09c06c7d509b "Hash: dadbda930e31fde61024
Time: Xms Time: Xms
Built at: 1970-04-20 12:42:42 Built at: 1970-04-20 12:42:42
Asset Size Asset Size
@ -447,7 +447,7 @@ Child all:
`; `;
exports[`StatsTestCases should print correct stats for chunk-module-id-range 1`] = ` exports[`StatsTestCases should print correct stats for chunk-module-id-range 1`] = `
"Hash: a800a9ba396856feaf95 "Hash: e10aafeb076eef8f2bd1
Time: Xms Time: Xms
Built at: 1970-04-20 12:42:42 Built at: 1970-04-20 12:42:42
PublicPath: (none) PublicPath: (none)
@ -515,7 +515,7 @@ chunk 996.bundle.js 22 bytes <{179}> [rendered]
`; `;
exports[`StatsTestCases should print correct stats for chunks-development 1`] = ` exports[`StatsTestCases should print correct stats for chunks-development 1`] = `
"Hash: d20813bc827ce6429e48 "Hash: 2a11303e167e5005439e
Time: Xms Time: Xms
Built at: 1970-04-20 12:42:42 Built at: 1970-04-20 12:42:42
PublicPath: (none) PublicPath: (none)
@ -635,26 +635,26 @@ Entrypoint entry-1 = vendor-1.js entry-1.js
`; `;
exports[`StatsTestCases should print correct stats for commons-plugin-issue-4980 1`] = ` exports[`StatsTestCases should print correct stats for commons-plugin-issue-4980 1`] = `
"Hash: 0322711dda6b150ea64813be0c2c5ac4f1ee233a "Hash: 11c5088030cef384e47e64484202182c974f95ad
Child Child
Hash: 0322711dda6b150ea648 Hash: 11c5088030cef384e47e
Time: Xms Time: Xms
Built at: 1970-04-20 12:42:42 Built at: 1970-04-20 12:42:42
Asset Size Asset Size
app.b82161e9590d9f4a5710.js 5.81 KiB [emitted] [immutable] [name: app] app.d6fd64d04ea003e46dd3.js 5.81 KiB [emitted] [immutable] [name: app]
vendor.4101ce64a32446c20561.js 615 bytes [emitted] [immutable] [name: vendor] [id hint: vendor] vendor.4101ce64a32446c20561.js 615 bytes [emitted] [immutable] [name: vendor] [id hint: vendor]
Entrypoint app = vendor.4101ce64a32446c20561.js app.b82161e9590d9f4a5710.js Entrypoint app = vendor.4101ce64a32446c20561.js app.d6fd64d04ea003e46dd3.js
./entry-1.js + 2 modules 190 bytes [built] ./entry-1.js + 2 modules 190 bytes [built]
./constants.js 87 bytes [built] ./constants.js 87 bytes [built]
+ 2 hidden modules + 2 hidden modules
Child Child
Hash: 13be0c2c5ac4f1ee233a Hash: 64484202182c974f95ad
Time: Xms Time: Xms
Built at: 1970-04-20 12:42:42 Built at: 1970-04-20 12:42:42
Asset Size Asset Size
app.58ab2273685a00b61215.js 5.82 KiB [emitted] [immutable] [name: app] app.627c1e16b9b5fb645153.js 5.82 KiB [emitted] [immutable] [name: app]
vendor.4101ce64a32446c20561.js 615 bytes [emitted] [immutable] [name: vendor] [id hint: vendor] vendor.4101ce64a32446c20561.js 615 bytes [emitted] [immutable] [name: vendor] [id hint: vendor]
Entrypoint app = vendor.4101ce64a32446c20561.js app.58ab2273685a00b61215.js Entrypoint app = vendor.4101ce64a32446c20561.js app.627c1e16b9b5fb645153.js
./entry-2.js + 2 modules 197 bytes [built] ./entry-2.js + 2 modules 197 bytes [built]
./constants.js 87 bytes [built] ./constants.js 87 bytes [built]
+ 2 hidden modules" + 2 hidden modules"
@ -678,9 +678,9 @@ exports[`StatsTestCases should print correct stats for concat-and-sideeffects 1`
`; `;
exports[`StatsTestCases should print correct stats for define-plugin 1`] = ` exports[`StatsTestCases should print correct stats for define-plugin 1`] = `
"Hash: b25ebe7b7b295232a01a9a8d6feecff6652bf00eff7e4a0e0f4379e59b2f "Hash: 2ecfff95a59c6f113f4caba827c90e84dff35788e10eff264a44ee9769ee
Child Child
Hash: b25ebe7b7b295232a01a Hash: 2ecfff95a59c6f113f4c
Time: Xms Time: Xms
Built at: 1970-04-20 12:42:42 Built at: 1970-04-20 12:42:42
Asset Size Asset Size
@ -688,7 +688,7 @@ Child
Entrypoint main = main.js Entrypoint main = main.js
./index.js 24 bytes [built] ./index.js 24 bytes [built]
Child Child
Hash: 9a8d6feecff6652bf00e Hash: aba827c90e84dff35788
Time: Xms Time: Xms
Built at: 1970-04-20 12:42:42 Built at: 1970-04-20 12:42:42
Asset Size Asset Size
@ -696,7 +696,7 @@ Child
Entrypoint main = main.js Entrypoint main = main.js
./index.js 24 bytes [built] ./index.js 24 bytes [built]
Child Child
Hash: ff7e4a0e0f4379e59b2f Hash: e10eff264a44ee9769ee
Time: Xms Time: Xms
Built at: 1970-04-20 12:42:42 Built at: 1970-04-20 12:42:42
Asset Size Asset Size
@ -729,7 +729,7 @@ Unexpected end of JSON input while parsing near ''
`; `;
exports[`StatsTestCases should print correct stats for exclude-with-loader 1`] = ` exports[`StatsTestCases should print correct stats for exclude-with-loader 1`] = `
"Hash: 573a41a01a055998604c "Hash: 044cc6bde1cac542bb22
Time: Xms Time: Xms
Built at: 1970-04-20 12:42:42 Built at: 1970-04-20 12:42:42
Asset Size Asset Size
@ -1379,7 +1379,7 @@ Entrypoint main = main.js
`; `;
exports[`StatsTestCases should print correct stats for module-assets 1`] = ` exports[`StatsTestCases should print correct stats for module-assets 1`] = `
"Hash: 800a7c66f127dad910e9 "Hash: 76c6284536c6eaf93eee
Time: Xms Time: Xms
Built at: 1970-04-20 12:42:42 Built at: 1970-04-20 12:42:42
Asset Size Asset Size
@ -1530,7 +1530,7 @@ If you don't want to include a polyfill, you can use an empty module like this:
`; `;
exports[`StatsTestCases should print correct stats for module-reasons 1`] = ` exports[`StatsTestCases should print correct stats for module-reasons 1`] = `
"Hash: bb6f434427ef3617b391 "Hash: b6469c24aa4c7dbb128f
Time: Xms Time: Xms
Built at: 1970-04-20 12:42:42 Built at: 1970-04-20 12:42:42
Asset Size Asset Size
@ -2463,7 +2463,7 @@ Entrypoint e2 = runtime.js e2.js"
`; `;
exports[`StatsTestCases should print correct stats for scope-hoisting-bailouts 1`] = ` exports[`StatsTestCases should print correct stats for scope-hoisting-bailouts 1`] = `
"Hash: 2850abf0834f38d62af2 "Hash: afd1db97faf25e43672d
Time: Xms Time: Xms
Built at: 1970-04-20 12:42:42 Built at: 1970-04-20 12:42:42
Entrypoint index = index.js Entrypoint index = index.js
@ -2493,9 +2493,9 @@ external \\"external\\" 42 bytes [built]
`; `;
exports[`StatsTestCases should print correct stats for scope-hoisting-multi 1`] = ` exports[`StatsTestCases should print correct stats for scope-hoisting-multi 1`] = `
"Hash: 95f50af5185d282dcfbaf2c6d907d9d0df616dd7 "Hash: 36ff61b79bdd38770761a5ce538ce4ef736da453
Child Child
Hash: 95f50af5185d282dcfba Hash: 36ff61b79bdd38770761
Time: Xms Time: Xms
Built at: 1970-04-20 12:42:42 Built at: 1970-04-20 12:42:42
Entrypoint first = vendor.js first.js Entrypoint first = vendor.js first.js
@ -2513,7 +2513,7 @@ Child
./common_lazy_shared.js 25 bytes [built] ./common_lazy_shared.js 25 bytes [built]
+ 10 hidden modules + 10 hidden modules
Child Child
Hash: f2c6d907d9d0df616dd7 Hash: a5ce538ce4ef736da453
Time: Xms Time: Xms
Built at: 1970-04-20 12:42:42 Built at: 1970-04-20 12:42:42
Entrypoint first = vendor.js first.js Entrypoint first = vendor.js first.js
@ -2540,7 +2540,7 @@ Child
`; `;
exports[`StatsTestCases should print correct stats for side-effects-issue-7428 1`] = ` exports[`StatsTestCases should print correct stats for side-effects-issue-7428 1`] = `
"Hash: ee17dcba81fb391501b7 "Hash: 511b75a49bce32fdac1f
Time: Xms Time: Xms
Built at: 1970-04-20 12:42:42 Built at: 1970-04-20 12:42:42
Asset Size Asset Size
@ -2591,7 +2591,7 @@ Entrypoint main = main.js
`; `;
exports[`StatsTestCases should print correct stats for side-effects-simple-unused 1`] = ` exports[`StatsTestCases should print correct stats for side-effects-simple-unused 1`] = `
"Hash: 97eddf49297c8cbcd004 "Hash: 5410fc291f7069e82143
Time: Xms Time: Xms
Built at: 1970-04-20 12:42:42 Built at: 1970-04-20 12:42:42
Asset Size Asset Size
@ -3624,7 +3624,7 @@ chunk default/async-a.js (async-a) 134 bytes <{179}> [rendered]
`; `;
exports[`StatsTestCases should print correct stats for tree-shaking 1`] = ` exports[`StatsTestCases should print correct stats for tree-shaking 1`] = `
"Hash: 555c0be8eff50e0d063c "Hash: 2332981f69bd5553a2d4
Time: Xms Time: Xms
Built at: 1970-04-20 12:42:42 Built at: 1970-04-20 12:42:42
Asset Size Asset Size
@ -3691,7 +3691,7 @@ WARNING in Terser Plugin: Dropping unused function someUnRemoteUsedFunction5 [./
`; `;
exports[`StatsTestCases should print correct stats for wasm-explorer-examples-sync 1`] = ` exports[`StatsTestCases should print correct stats for wasm-explorer-examples-sync 1`] = `
"Hash: 2c3fdc9668c0d61e8c09 "Hash: 86e17ac033d009dc7bfc
Time: Xms Time: Xms
Built at: 1970-04-20 12:42:42 Built at: 1970-04-20 12:42:42
Asset Size Asset Size