Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #12442 from webpack/bugfix/12244
  • Loading branch information
sokra committed Jan 18, 2021
2 parents dfe9cd3 + e9183f9 commit f28abd8
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 64 deletions.
7 changes: 4 additions & 3 deletions lib/javascript/JavascriptModulesPlugin.js
Expand Up @@ -848,6 +848,7 @@ class JavascriptModulesPlugin {
buf.push("");
}

const maybeReturn = returnExportsFromRuntime ? "return " : "";
if (!runtimeRequirements.has(RuntimeGlobals.startupNoDefault)) {
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) {
/** @type {string[]} */
Expand Down Expand Up @@ -933,7 +934,7 @@ class JavascriptModulesPlugin {
);
buf.push("");
startup.push("// run startup");
startup.push(`return ${RuntimeGlobals.startup}();`);
startup.push(`${maybeReturn}${RuntimeGlobals.startup}();`);
} else if (runtimeRequirements.has(RuntimeGlobals.startupOnlyBefore)) {
buf.push("// the startup function");
buf.push(
Expand All @@ -951,7 +952,7 @@ class JavascriptModulesPlugin {
startup.push("// startup");
startup.push(Template.asString(buf2));
afterStartup.push("// run runtime startup");
afterStartup.push(`return ${RuntimeGlobals.startup}();`);
afterStartup.push(`${maybeReturn}${RuntimeGlobals.startup}();`);
} else {
startup.push("// startup");
startup.push(Template.asString(buf2));
Expand Down Expand Up @@ -980,7 +981,7 @@ class JavascriptModulesPlugin {
`${RuntimeGlobals.startup} = ${runtimeTemplate.emptyFunction()}`
);
startup.push("// run startup");
startup.push(`return ${RuntimeGlobals.startup}();`);
startup.push(`${maybeReturn}${RuntimeGlobals.startup}();`);
}
return result;
}
Expand Down
17 changes: 14 additions & 3 deletions test/ConfigTestCases.template.js
Expand Up @@ -5,6 +5,7 @@ const fs = require("graceful-fs");
const vm = require("vm");
const { URL } = require("url");
const rimraf = require("rimraf");
const TerserPlugin = require("terser-webpack-plugin");
const checkArrayExpectation = require("./checkArrayExpectation");
const createLazyTestEnv = require("./helpers/createLazyTestEnv");
const deprecationTracking = require("./helpers/deprecationTracking");
Expand Down Expand Up @@ -71,6 +72,13 @@ const describeCases = config => {
if (!options.optimization) options.optimization = {};
if (options.optimization.minimize === undefined)
options.optimization.minimize = false;
if (options.optimization.minimizer === undefined) {
options.optimization.minimizer = [
new TerserPlugin({
parallel: false
})
];
}
if (!options.entry) options.entry = "./index.js";
if (!options.target) options.target = "async-node";
if (!options.output) options.output = {};
Expand Down Expand Up @@ -350,14 +358,17 @@ const describeCases = config => {
if (testConfig.moduleScope) {
testConfig.moduleScope(moduleScope);
}
const args = Object.keys(moduleScope).join(", ");
const args = Object.keys(moduleScope);
const argValues = args.map(arg => moduleScope[arg]);
if (!runInNewContext)
content = `Object.assign(global, _globalAssign); ${content}`;
const code = `(function({${args}}) {${content}\n})`;
const code = `(function(${args.join(
", "
)}) {${content}\n})`;
const fn = runInNewContext
? vm.runInNewContext(code, globalContext, p)
: vm.runInThisContext(code, p);
fn.call(m.exports, moduleScope);
fn.call(m.exports, ...argValues);

//restore state
document.currentScript = oldCurrentScript;
Expand Down

0 comments on commit f28abd8

Please sign in to comment.