Skip to content
This repository was archived by the owner on Sep 9, 2021. It is now read-only.

Commit 15cf407

Browse files
authored
fix: set a name to exported function (#299)
1 parent 464bf30 commit 15cf407

8 files changed

+35
-34
lines changed

src/utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function workerGenerator(loaderContext, workerFilename, workerSource, options) {
4848

4949
const esModule =
5050
typeof options.esModule !== 'undefined' ? options.esModule : true;
51+
const fnName = `${workerConstructor}_fn`;
5152

5253
if (options.inline) {
5354
const InlineWorkerPath = stringifyRequest(
@@ -72,7 +73,7 @@ ${
7273
7374
${
7475
esModule ? 'export default' : 'module.exports ='
75-
} function() {\n return worker(${JSON.stringify(
76+
} function ${fnName}() {\n return worker(${JSON.stringify(
7677
workerSource
7778
)}, ${JSON.stringify(workerConstructor)}, ${JSON.stringify(
7879
workerOptions
@@ -81,7 +82,7 @@ ${
8182

8283
return `${
8384
esModule ? 'export default' : 'module.exports ='
84-
} function() {\n return new ${workerConstructor}(__webpack_public_path__ + ${JSON.stringify(
85+
} function ${fnName}() {\n return new ${workerConstructor}(__webpack_public_path__ + ${JSON.stringify(
8586
workerFilename
8687
)}${workerOptions ? `, ${JSON.stringify(workerOptions)}` : ''});\n}\n`;
8788
}

test/__snapshots__/chunkFilename-option.test.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`"name" option should chunkFilename suffix be inserted before query parameters: errors 1`] = `Array []`;
44

55
exports[`"name" option should chunkFilename suffix be inserted before query parameters: module 1`] = `
6-
"export default function() {
6+
"export default function Worker_fn() {
77
return new Worker(__webpack_public_path__ + \\"worker.worker.js\\");
88
}
99
"
@@ -18,7 +18,7 @@ exports[`"name" option should chunkFilename suffix be inserted before query para
1818
exports[`"name" option should work ("string"): errors 1`] = `Array []`;
1919

2020
exports[`"name" option should work ("string"): module 1`] = `
21-
"export default function() {
21+
"export default function Worker_fn() {
2222
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
2323
}
2424
"
@@ -31,7 +31,7 @@ exports[`"name" option should work ("string"): warnings 1`] = `Array []`;
3131
exports[`"name" option should work and respect the "output.chunkFilename" default value option: errors 1`] = `Array []`;
3232

3333
exports[`"name" option should work and respect the "output.chunkFilename" default value option: module 1`] = `
34-
"export default function() {
34+
"export default function Worker_fn() {
3535
return new Worker(__webpack_public_path__ + \\"worker.worker.js\\");
3636
}
3737
"
@@ -44,7 +44,7 @@ exports[`"name" option should work and respect the "output.chunkFilename" defaul
4444
exports[`"name" option should work and respect the "output.chunkFilename" option ("string"): errors 1`] = `Array []`;
4545

4646
exports[`"name" option should work and respect the "output.chunkFilename" option ("string"): module 1`] = `
47-
"export default function() {
47+
"export default function Worker_fn() {
4848
return new Worker(__webpack_public_path__ + \\"worker.worker.js\\");
4949
}
5050
"

test/__snapshots__/esModule-option.test.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`"esModule" option should work and generate ES module syntax by default: errors 1`] = `Array []`;
44

55
exports[`"esModule" option should work and generate ES module syntax by default: module 1`] = `
6-
"export default function() {
6+
"export default function Worker_fn() {
77
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
88
}
99
"
@@ -14,7 +14,7 @@ exports[`"esModule" option should work and generate ES module syntax by default:
1414
exports[`"esModule" option should work with "false" value: errors 1`] = `Array []`;
1515

1616
exports[`"esModule" option should work with "false" value: module 1`] = `
17-
"module.exports = function() {
17+
"module.exports = function Worker_fn() {
1818
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
1919
}
2020
"
@@ -27,7 +27,7 @@ exports[`"esModule" option should work with "false" value: warnings 1`] = `Array
2727
exports[`"esModule" option should work with "true" value: errors 1`] = `Array []`;
2828

2929
exports[`"esModule" option should work with "true" value: module 1`] = `
30-
"export default function() {
30+
"export default function Worker_fn() {
3131
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
3232
}
3333
"

test/__snapshots__/filename-options.test.js.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`"filename" option should work ("function"): errors 1`] = `Array []`;
44

55
exports[`"filename" option should work ("function"): module 1`] = `
6-
"export default function() {
6+
"export default function Worker_fn() {
77
return new Worker(__webpack_public_path__ + \\"worker.custom.worker.js\\");
88
}
99
"
@@ -16,7 +16,7 @@ exports[`"filename" option should work ("function"): warnings 1`] = `Array []`;
1616
exports[`"filename" option should work ("string"): errors 1`] = `Array []`;
1717

1818
exports[`"filename" option should work ("string"): module 1`] = `
19-
"export default function() {
19+
"export default function Worker_fn() {
2020
return new Worker(__webpack_public_path__ + \\"worker.custom.worker.js\\");
2121
}
2222
"
@@ -29,7 +29,7 @@ exports[`"filename" option should work ("string"): warnings 1`] = `Array []`;
2929
exports[`"filename" option should work and respect the "output.filename" default value option: errors 1`] = `Array []`;
3030

3131
exports[`"filename" option should work and respect the "output.filename" default value option: module 1`] = `
32-
"export default function() {
32+
"export default function Worker_fn() {
3333
return new Worker(__webpack_public_path__ + \\"worker.worker.js\\");
3434
}
3535
"
@@ -42,7 +42,7 @@ exports[`"filename" option should work and respect the "output.filename" default
4242
exports[`"filename" option should work and respect the "output.filename" option ("function"): errors 1`] = `Array []`;
4343

4444
exports[`"filename" option should work and respect the "output.filename" option ("function"): module 1`] = `
45-
"export default function() {
45+
"export default function Worker_fn() {
4646
return new Worker(__webpack_public_path__ + \\"worker.custom.worker.js\\");
4747
}
4848
"
@@ -55,7 +55,7 @@ exports[`"filename" option should work and respect the "output.filename" option
5555
exports[`"filename" option should work and respect the "output.filename" option ("string"): errors 1`] = `Array []`;
5656

5757
exports[`"filename" option should work and respect the "output.filename" option ("string"): module 1`] = `
58-
"export default function() {
58+
"export default function Worker_fn() {
5959
return new Worker(__webpack_public_path__ + \\"worker.custom.worker.js\\");
6060
}
6161
"

test/__snapshots__/inline-option.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`"inline" option should not work by default: errors 1`] = `Array []`;
44

55
exports[`"inline" option should not work by default: module 1`] = `
6-
"export default function() {
6+
"export default function Worker_fn() {
77
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
88
}
99
"

test/__snapshots__/loader.test.js.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`worker-loader should work and have the same base file name as the source files: errors 1`] = `Array []`;
44

55
exports[`worker-loader should work and have the same base file name as the source files: module 1`] = `
6-
"export default function() {
6+
"export default function Worker_fn() {
77
return new Worker(__webpack_public_path__ + \\"TypeDetection.worker.js\\");
88
}
99
"
@@ -16,7 +16,7 @@ exports[`worker-loader should work and have the same base file name as the sourc
1616
exports[`worker-loader should work and respect the "devtool" option ("false" value): errors 1`] = `Array []`;
1717

1818
exports[`worker-loader should work and respect the "devtool" option ("false" value): module 1`] = `
19-
"export default function() {
19+
"export default function Worker_fn() {
2020
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
2121
}
2222
"
@@ -29,7 +29,7 @@ exports[`worker-loader should work and respect the "devtool" option ("false" val
2929
exports[`worker-loader should work and respect the "devtool" option ("source-map" value): errors 1`] = `Array []`;
3030

3131
exports[`worker-loader should work and respect the "devtool" option ("source-map" value): module 1`] = `
32-
"export default function() {
32+
"export default function Worker_fn() {
3333
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
3434
}
3535
"
@@ -42,7 +42,7 @@ exports[`worker-loader should work and respect the "devtool" option ("source-map
4242
exports[`worker-loader should work with "externals": errors 1`] = `Array []`;
4343

4444
exports[`worker-loader should work with "externals": module 1`] = `
45-
"export default function() {
45+
"export default function Worker_fn() {
4646
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
4747
}
4848
"
@@ -55,7 +55,7 @@ exports[`worker-loader should work with "externals": warnings 1`] = `Array []`;
5555
exports[`worker-loader should work with WASM: errors 1`] = `Array []`;
5656

5757
exports[`worker-loader should work with WASM: module 1`] = `
58-
"export default function() {
58+
"export default function Worker_fn() {
5959
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
6060
}
6161
"
@@ -68,7 +68,7 @@ exports[`worker-loader should work with WASM: warnings 1`] = `Array []`;
6868
exports[`worker-loader should work with async chunks: errors 1`] = `Array []`;
6969

7070
exports[`worker-loader should work with async chunks: module 1`] = `
71-
"export default function() {
71+
"export default function Worker_fn() {
7272
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
7373
}
7474
"
@@ -81,7 +81,7 @@ exports[`worker-loader should work with async chunks: warnings 1`] = `Array []`;
8181
exports[`worker-loader should work with inline syntax: errors 1`] = `Array []`;
8282

8383
exports[`worker-loader should work with inline syntax: module 1`] = `
84-
"export default function() {
84+
"export default function Worker_fn() {
8585
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
8686
}
8787
"
@@ -94,7 +94,7 @@ exports[`worker-loader should work with inline syntax: warnings 1`] = `Array []`
9494
exports[`worker-loader should work: errors 1`] = `Array []`;
9595

9696
exports[`worker-loader should work: module 1`] = `
97-
"export default function() {
97+
"export default function Worker_fn() {
9898
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
9999
}
100100
"

test/__snapshots__/publicPath.test.js.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ exports[`"publicPath" option should work and respect "filename" and "chunkFilena
55
exports[`"publicPath" option should work and respect "filename" and "chunkFilename" option values: errors 2`] = `Array []`;
66

77
exports[`"publicPath" option should work and respect "filename" and "chunkFilename" option values: module 1`] = `
8-
"export default function() {
8+
"export default function Worker_fn() {
99
return new Worker(__webpack_public_path__ + \\"other-static/js/worker.bundle.worker.js\\");
1010
}
1111
"
1212
`;
1313

1414
exports[`"publicPath" option should work and respect "filename" and "chunkFilename" option values: module 2`] = `
15-
"export default function() {
15+
"export default function Worker_fn() {
1616
return new Worker(__webpack_public_path__ + \\"other-static/js/worker.worker.js\\");
1717
}
1818
"
@@ -29,7 +29,7 @@ exports[`"publicPath" option should work and respect "filename" and "chunkFilena
2929
exports[`"publicPath" option should work and respect the "output.publicPath" option default value: errors 1`] = `Array []`;
3030

3131
exports[`"publicPath" option should work and respect the "output.publicPath" option default value: module 1`] = `
32-
"export default function() {
32+
"export default function Worker_fn() {
3333
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
3434
}
3535
"
@@ -42,7 +42,7 @@ exports[`"publicPath" option should work and respect the "output.publicPath" opt
4242
exports[`"publicPath" option should work and respect the "output.publicPath" option value ("function"): errors 1`] = `Array []`;
4343

4444
exports[`"publicPath" option should work and respect the "output.publicPath" option value ("function"): module 1`] = `
45-
"export default function() {
45+
"export default function Worker_fn() {
4646
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
4747
}
4848
"
@@ -55,7 +55,7 @@ exports[`"publicPath" option should work and respect the "output.publicPath" opt
5555
exports[`"publicPath" option should work and respect the "output.publicPath" option value ("string"): errors 1`] = `Array []`;
5656

5757
exports[`"publicPath" option should work and respect the "output.publicPath" option value ("string"): module 1`] = `
58-
"export default function() {
58+
"export default function Worker_fn() {
5959
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
6060
}
6161
"
@@ -68,7 +68,7 @@ exports[`"publicPath" option should work and respect the "output.publicPath" opt
6868
exports[`"publicPath" option should work and respect the "publicPath" option ("function"): errors 1`] = `Array []`;
6969

7070
exports[`"publicPath" option should work and respect the "publicPath" option ("function"): module 1`] = `
71-
"export default function() {
71+
"export default function Worker_fn() {
7272
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
7373
}
7474
"
@@ -81,7 +81,7 @@ exports[`"publicPath" option should work and respect the "publicPath" option ("f
8181
exports[`"publicPath" option should work and respect the "publicPath" option ("string"): errors 1`] = `Array []`;
8282

8383
exports[`"publicPath" option should work and respect the "publicPath" option ("string"): module 1`] = `
84-
"export default function() {
84+
"export default function Worker_fn() {
8585
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
8686
}
8787
"
@@ -94,7 +94,7 @@ exports[`"publicPath" option should work and respect the "publicPath" option ("s
9494
exports[`"publicPath" option should work and use "__webpack_public_path__" by default: errors 1`] = `Array []`;
9595

9696
exports[`"publicPath" option should work and use "__webpack_public_path__" by default: module 1`] = `
97-
"export default function() {
97+
"export default function Worker_fn() {
9898
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
9999
}
100100
"

test/__snapshots__/worker-option.test.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ exports[`"workerType" option should support the "Worker" object value for inline
1515
exports[`"workerType" option should support the "Worker" object value: errors 1`] = `Array []`;
1616

1717
exports[`"workerType" option should support the "Worker" object value: module 1`] = `
18-
"export default function() {
18+
"export default function Worker_fn() {
1919
return new Worker(__webpack_public_path__ + \\"test.worker.js\\", {\\"type\\":\\"classic\\",\\"name\\":\\"worker-name\\"});
2020
}
2121
"
@@ -28,7 +28,7 @@ exports[`"workerType" option should support the "Worker" object value: warnings
2828
exports[`"workerType" option should support the "Worker" string value: errors 1`] = `Array []`;
2929

3030
exports[`"workerType" option should support the "Worker" string value: module 1`] = `
31-
"export default function() {
31+
"export default function Worker_fn() {
3232
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
3333
}
3434
"
@@ -41,7 +41,7 @@ exports[`"workerType" option should support the "Worker" string value: warnings
4141
exports[`"workerType" option should use "Worker" by default: errors 1`] = `Array []`;
4242

4343
exports[`"workerType" option should use "Worker" by default: module 1`] = `
44-
"export default function() {
44+
"export default function Worker_fn() {
4545
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
4646
}
4747
"

0 commit comments

Comments
 (0)