Skip to content

Commit

Permalink
Merge pull request #15551 from webpack/fix/issue-15545
Browse files Browse the repository at this point in the history
support arrow function in umd
  • Loading branch information
sokra committed Mar 28, 2022
2 parents 84aa5cf + 806ee08 commit 5d8a971
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/library/UmdLibraryPlugin.js
Expand Up @@ -310,9 +310,11 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
: " var a = factory();\n") +
" for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n" +
" }\n") +
`})(${
runtimeTemplate.outputOptions.globalObject
}, function(${externalsArguments(externals)}) {\nreturn `,
`})(${runtimeTemplate.outputOptions.globalObject}, ${
runtimeTemplate.supportsArrowFunction()
? `(${externalsArguments(externals)}) =>`
: `function(${externalsArguments(externals)})`
} {\nreturn `,
"webpack/universalModuleDefinition"
),
source,
Expand Down
7 changes: 6 additions & 1 deletion test/ConfigTestCases.template.js
Expand Up @@ -619,7 +619,12 @@ const describeCases = config => {
const fn = runInNewContext
? vm.runInNewContext(code, globalContext, p)
: vm.runInThisContext(code, p);
fn.call(m.exports, ...argValues);
fn.call(
testConfig.nonEsmThis
? testConfig.nonEsmThis(module)
: m.exports,
...argValues
);
document.currentScript = oldCurrentScript;
return m.exports;
}
Expand Down
5 changes: 5 additions & 0 deletions test/configCases/umd/issue-15545/index.js
@@ -0,0 +1,5 @@
it("should compile and run", () => {
expect(hello()).toBe("hello");
});

export function hello() { return "hello"; }
9 changes: 9 additions & 0 deletions test/configCases/umd/issue-15545/test.config.js
@@ -0,0 +1,9 @@
const CONTEXT = {};
module.exports = {
nonEsmThis(module) {
return CONTEXT;
},
findBundle() {
return ["./runtime.js", "./main.js"];
}
};
19 changes: 19 additions & 0 deletions test/configCases/umd/issue-15545/webpack.config.js
@@ -0,0 +1,19 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
mode: "production",
entry: {
main: "./index.js"
},
output: {
filename: "[name].js",
library: "MyLibrary",
libraryTarget: "umd",
chunkLoading: "jsonp",
chunkFormat: "array-push",
globalObject: "this"
},
optimization: {
minimize: false,
runtimeChunk: "single"
}
};

0 comments on commit 5d8a971

Please sign in to comment.