Compare commits

..

5 Commits

Author SHA1 Message Date
paoloricciuti
77c1728ab1 Merge branch 'main' into js-api-and-cli 2025-12-19 18:26:58 +01:00
paoloricciuti
83e9d6583a Merge branch 'main' into js-api-and-cli 2025-12-18 20:21:42 +01:00
paoloricciuti
5d8a85c2e3 fix: move to catalog 2025-12-18 19:27:36 +01:00
paoloricciuti
eac75d3629 fix: types exports 2025-12-18 19:23:25 +01:00
paoloricciuti
59abf83bdb feat: expose tools as JS api + cli 2025-12-18 18:43:53 +01:00
7 changed files with 12 additions and 37 deletions

View File

@@ -1,5 +0,0 @@
---
'@sveltejs/mcp': patch
---
fix: add suggestion for snippets declared in script tag

View File

@@ -0,0 +1,5 @@
---
'@sveltejs/mcp': patch
---
feat: expose tools as JS api + cli

View File

@@ -53,18 +53,6 @@ describe('svelte-autofixer tool', () => {
);
});
it('should add suggestions for snippets declared in script tag', async () => {
const content = await autofixer_tool_call(`<script>
{#snippet my_snippet()}
some content
{/snippet}
</script>`);
expect(content.issues.length).toBeGreaterThan(0);
expect(content.suggestions).toContain(
"The code can't be compiled because a Javascript parse error. The error suggests you have a `{#snippet ...}` block inside the `<script>` tag. Snippets are template syntax and should be declared in the markup section of the component, not in the script. Move the snippet outside of the `<script>` tag. Snippets declared in the markup can also be accessed in the script tag in case you need them.",
);
});
it('should error out if async is true with a version less than 5', async () => {
const content = await autofixer_tool_call(
`<script>

View File

@@ -75,21 +75,14 @@ export async function svelte_autofixer_handler({
await add_eslint_issues(content, code, +desired_svelte_version, filename, async);
} catch (e: unknown) {
const error = e as Error & { start?: { line: number; column: number }; frame?: string };
const error = e as Error & { start?: { line: number; column: number } };
content.issues.push(
`${error.message} at line ${error.start?.line}, column ${error.start?.column}`,
);
if (error.message.includes('js_parse_error')) {
// Check if the error frame contains template syntax that was incorrectly placed in the script tag
if (error.frame?.includes('{#snippet')) {
content.suggestions.push(
"The code can't be compiled because a Javascript parse error. The error suggests you have a `{#snippet ...}` block inside the `<script>` tag. Snippets are template syntax and should be declared in the markup section of the component, not in the script. Move the snippet outside of the `<script>` tag. Snippets declared in the markup can also be accessed in the script tag in case you need them.",
);
} else {
content.suggestions.push(
"The code can't be compiled because a Javascript parse error. In case you are using runes like this `$state variable_name = 3;` or `$derived variable_name = 3 * count` that's not how runes are used. You need to use them as function calls without importing them: `const variable_name = $state(3)` and `const variable_name = $derived(3 * count)`.",
);
}
content.suggestions.push(
"The code can't be compiled because a Javascript parse error. In case you are using runes like this `$state variable_name = 3;` or `$derived variable_name = 3 * count` that's not how runes are used. You need to use them as function calls without importing them: `const variable_name = $state(3)` and `const variable_name = $derived(3 * count)`.",
);
} else if (error.message.includes('css_expected_identifier')) {
content.suggestions.push(
"The code can't be compiled because a valid CSS identifier is expected. This sometimes means you are trying to use a variable in CSS like this: `color: {my_color}` but Svelte doesn't support that. You can use inline CSS variables for that `<div style:--color={my_color}></div>` and then use the variable as usual in CSS with `color: var(--color)`.",

View File

@@ -1,11 +1,5 @@
# @sveltejs/mcp
## 0.1.16
### Patch Changes
- feat: expose tools as JS api + cli ([#128](https://github.com/sveltejs/mcp/pull/128))
## 0.1.15
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@sveltejs/mcp",
"version": "0.1.16",
"version": "0.1.15",
"type": "module",
"license": "MIT",
"mcpName": "dev.svelte/mcp",

View File

@@ -9,7 +9,7 @@
"subfolder": "packages/mcp-stdio",
"source": "github"
},
"version": "0.1.16",
"version": "0.1.15",
"websiteUrl": "https://svelte.dev/docs/mcp/overview",
"icons": [
{
@@ -25,7 +25,7 @@
{
"registryType": "npm",
"identifier": "@sveltejs/mcp",
"version": "0.1.16",
"version": "0.1.15",
"runtimeHint": "npx",
"transport": {
"type": "stdio"