Skip to content

Commit 75d02f0

Browse files
committed
fix: don't call callback twice, masking potential errors
related to #238
1 parent 5fdc8b5 commit 75d02f0

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# svelte-loader changelog
22

3+
## 3.2.4
4+
5+
* Don't call `callback` twice, masking potential errors
6+
37
## 3.2.3
48

59
* Svelte 5: Don't compile `.svelte/.../.xxx.js/ts` files

index.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,29 @@ module.exports = function(source, map) {
8888
const handleWarning = warning => this.emitWarning(new Error(warning));
8989

9090
if (getMajor() >= 5 && svelte_module_regex.test(this.resourcePath)) {
91+
let js, warnings;
92+
9193
try {
92-
const { js, warnings } = svelte.compileModule(
94+
({ js, warnings } = svelte.compileModule(
9395
source,
9496
{ filename: this.resourcePath, dev: compileOptions.dev, generate: compileOptions.generate }
95-
);
97+
));
9698

9799
warnings.forEach(
98100
options.onwarn
99101
? warning => options.onwarn(warning, handleWarning)
100102
: handleWarning
101103
);
102-
103-
callback(null, js.code, js.map);
104104
} catch (err) {
105105
// wrap error to provide correct
106106
// context when logging to console
107107
callback(new Error(`${err.name}: ${err.toString()}`));
108108
}
109109

110+
// outside try-catch - if this fails and we catch it,
111+
// calling callback again will mask the error with a "already called" error
112+
callback(null, js.code, js.map);
113+
110114
return;
111115
}
112116

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svelte-loader",
3-
"version": "3.2.3",
3+
"version": "3.2.4",
44
"author": "Nico Rehwaldt <[email protected]>",
55
"description": "A webpack loader for svelte",
66
"license": "MIT",

0 commit comments

Comments
 (0)