Skip to content

Commit 562db6a

Browse files
committed
fix: compile .svelte.xxx.js/ts modules in Svelte 5
sveltejs/svelte#11536
1 parent 495600b commit 562db6a

File tree

6 files changed

+26
-5
lines changed

6 files changed

+26
-5
lines changed

Diff for: CHANGELOG.md

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

3+
## 3.2.2
4+
5+
* Svelte 5: Also compile `.svelte.xxx.js/ts` files
6+
37
## 3.2.1
48

59
* Handle sourcemaps being falsy

Diff for: index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ function getMajor() {
6363
return Number(svelte.VERSION.split('.')[0]);
6464
}
6565

66+
const svelte_module_regex = /\.svelte(\.[^.]+)*\.(js|ts)$/
67+
6668
module.exports = function(source, map) {
6769
this.cacheable();
6870

@@ -85,7 +87,7 @@ module.exports = function(source, map) {
8587
};
8688
const handleWarning = warning => this.emitWarning(new Error(warning));
8789

88-
if (getMajor() >= 5 && (this.resourcePath.endsWith('.svelte.js') || this.resourcePath.endsWith('.svelte.ts'))) {
90+
if (getMajor() >= 5 && svelte_module_regex.test(this.resourcePath)) {
8991
try {
9092
const { js, warnings } = svelte.compileModule(
9193
source,

Diff for: package-lock.json

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

Diff for: 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.1",
3+
"version": "3.2.2",
44
"author": "Nico Rehwaldt <[email protected]>",
55
"description": "A webpack loader for svelte",
66
"license": "MIT",

Diff for: test/fixtures/file.svelte.foo.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @ts-nocheck
2+
export const count = $state({ value: 0 }); // eslint-disable-line no-undef

Diff for: test/loader.spec.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ describe('loader', () => {
465465
if (!isSvelte5Plus) return;
466466

467467
it(
468-
'should compile .svelte.js/ts',
468+
'should compile .svelte.js',
469469
testLoader(
470470
'test/fixtures/file.svelte.js',
471471
function(err, code, map) {
@@ -476,6 +476,19 @@ describe('loader', () => {
476476
{}
477477
)
478478
);
479+
480+
it(
481+
'should compile .svelte.foo.ts',
482+
testLoader(
483+
'test/fixtures/file.svelte.foo.ts',
484+
function(err, code, map) {
485+
expect(err).not.to.exist;
486+
487+
expect(code).not.to.contain('$state');
488+
},
489+
{}
490+
)
491+
);
479492
});
480493
});
481494

0 commit comments

Comments
 (0)