Skip to content

Commit

Permalink
fix: compile svelte.xxx.js/ts files in Svelte 5
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm committed Jun 6, 2024
1 parent 1e01360 commit 295cf0b
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# rollup-plugin-svelte changelog

## 7.2.2

- Svelte 5: Compile `.svelte.xxx.js/ts` files

## 7.2.1

- Silence Svelte 5 version of unused CSS warning code if `emitCss` is `false`
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const plugin_options = new Set([
'preprocess',
]);

const svelte_module_regex = /\.svelte(\.[^./\\]+)*\.(js|ts)$/;

This comment has been minimized.

Copy link
@dominikg

dominikg Jun 6, 2024

Member

Do we need support for query strings in module ids here? v-p-s splits the id on ? before running the filter https://github.com/sveltejs/vite-plugin-svelte/blob/45a43a4084499559a2e7a08b2403729e835fa06a/packages/vite-plugin-svelte/src/utils/id.js#L25


let warned = false;

/**
Expand Down Expand Up @@ -130,7 +132,7 @@ module.exports = function (options = {}) {
async transform(code, id) {
if (!filter(id)) return null;

if (majorVersion > 4 && (id.endsWith('.svelte.js') || id.endsWith('.svelte.ts'))) {
if (majorVersion > 4 && svelte_module_regex.test(id)) {
const compiled = svelte.compileModule(code, {
filename: id,
dev: compilerOptions.dev,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "7.2.1",
"version": "7.2.2",
"name": "rollup-plugin-svelte",
"description": "Compile Svelte components with Rollup",
"repository": "sveltejs/rollup-plugin-svelte",
Expand Down
1 change: 1 addition & 0 deletions test/filename-test2/src/main.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { counter } from './runes.svelte.js';
export { counter2 } from './runes.svelte.foo.ts';
2 changes: 2 additions & 0 deletions test/filename-test2/src/runes.svelte.foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @ts-nocheck
export const counter2 = $state({ value: 0 });
4 changes: 3 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@ test('handles filenames that happen to contain ".svelte"', async () => {
});

// Needs Svelte 5
test.skip('handles ".svelte.ts/js" files', async () => {
test('handles ".svelte.ts/js" files', async () => {
if (!isSvelte5Plus) return;

sander.rimrafSync('test/filename-test2/dist');
sander.mkdirSync('test/filename-test2/dist');

Expand Down

0 comments on commit 295cf0b

Please sign in to comment.