aboutsummaryrefslogtreecommitdiff
path: root/node_modules/webpack/lib/NormalModule.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-08-14 05:01:11 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-08-14 05:02:09 +0200
commit363723fc84f7b8477592e0105aeb331ec9a017af (patch)
tree29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/webpack/lib/NormalModule.js
parent5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff)
node_modules
Diffstat (limited to 'node_modules/webpack/lib/NormalModule.js')
-rw-r--r--node_modules/webpack/lib/NormalModule.js53
1 files changed, 42 insertions, 11 deletions
diff --git a/node_modules/webpack/lib/NormalModule.js b/node_modules/webpack/lib/NormalModule.js
index b3dda7e5a..d150fc767 100644
--- a/node_modules/webpack/lib/NormalModule.js
+++ b/node_modules/webpack/lib/NormalModule.js
@@ -54,6 +54,8 @@ class NonErrorEmittedError extends WebpackError {
}
}
+const dependencyTemplatesHashMap = new WeakMap();
+
class NormalModule extends Module {
constructor(request, userRequest, rawRequest, loaders, resource, parser) {
@@ -224,6 +226,10 @@ class NormalModule extends Module {
if(typeof rule === "string") {
return content.indexOf(rule) === 0;
}
+
+ if(typeof rule === "function") {
+ return rule(content);
+ }
// we assume rule is a regexp
return rule.test(content);
}
@@ -301,9 +307,11 @@ class NormalModule extends Module {
});
}
- getHashDigest() {
+ getHashDigest(dependencyTemplates) {
+ let dtHash = dependencyTemplatesHashMap.get("hash");
const hash = crypto.createHash("md5");
this.updateHash(hash);
+ hash.update(`${dtHash}`);
return hash.digest("hex");
}
@@ -384,9 +392,16 @@ class NormalModule extends Module {
* These will contain the variable name and its expression.
* The name will be added as a paramter in a IIFE the expression as its value.
*/
- const vars = block.variables.map((variable) => this.sourceVariables(
- variable, availableVars, dependencyTemplates, outputOptions, requestShortener))
- .filter(Boolean);
+ const vars = block.variables.reduce((result, value) => {
+ const variable = this.sourceVariables(
+ value, availableVars, dependencyTemplates, outputOptions, requestShortener);
+
+ if(variable) {
+ result.push(variable);
+ }
+
+ return result;
+ }, []);
/**
* if we actually have variables
@@ -412,15 +427,22 @@ class NormalModule extends Module {
const injectionVariableChunks = this.splitVariablesInUniqueNamedChunks(vars);
// create all the beginnings of IIFEs
- const functionWrapperStarts = injectionVariableChunks.map((variableChunk) => variableChunk.map(variable => variable.name))
- .map(names => this.variableInjectionFunctionWrapperStartCode(names));
+ const functionWrapperStarts = injectionVariableChunks.map((variableChunk) => {
+ return this.variableInjectionFunctionWrapperStartCode(
+ variableChunk.map(variable => variable.name)
+ );
+ });
// and all the ends
- const functionWrapperEnds = injectionVariableChunks.map((variableChunk) => variableChunk.map(variable => variable.expression))
- .map(expressions => this.variableInjectionFunctionWrapperEndCode(expressions, block));
+ const functionWrapperEnds = injectionVariableChunks.map((variableChunk) => {
+ return this.variableInjectionFunctionWrapperEndCode(
+ variableChunk.map(variable => variable.expression), block
+ );
+ });
// join them to one big string
const varStartCode = functionWrapperStarts.join("");
+
// reverse the ends first before joining them, as the last added must be the inner most
const varEndCode = functionWrapperEnds.reverse().join("");
@@ -432,12 +454,21 @@ class NormalModule extends Module {
source.insert(end + 0.5, "\n/* WEBPACK VAR INJECTION */" + varEndCode);
}
}
- block.blocks.forEach((block) => this.sourceBlock(
- block, availableVars.concat(vars), dependencyTemplates, source, outputOptions, requestShortener));
+
+ block.blocks.forEach((block) =>
+ this.sourceBlock(
+ block,
+ availableVars.concat(vars),
+ dependencyTemplates,
+ source,
+ outputOptions,
+ requestShortener
+ )
+ );
}
source(dependencyTemplates, outputOptions, requestShortener) {
- const hashDigest = this.getHashDigest();
+ const hashDigest = this.getHashDigest(dependencyTemplates);
if(this._cachedSource && this._cachedSource.hash === hashDigest) {
return this._cachedSource.source;
}