From 363723fc84f7b8477592e0105aeb331ec9a017af Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 14 Aug 2017 05:01:11 +0200 Subject: node_modules --- node_modules/webpack/lib/NormalModule.js | 53 +++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 11 deletions(-) (limited to 'node_modules/webpack/lib/NormalModule.js') 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; } -- cgit v1.2.3