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

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
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

index.js

Lines changed: 3 additions & 1 deletion
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,

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
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 <git_nikku@nixis.de>",
55
"description": "A webpack loader for svelte",
66
"license": "MIT",

test/fixtures/file.svelte.foo.ts

Lines changed: 2 additions & 0 deletions
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

test/loader.spec.js

Lines changed: 14 additions & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy