Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/migrate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@types/node": "^20.14.8",
"@types/prompts": "^2.4.9",
"@types/semver": "^7.7.1",
"svelte": "^5.45.10"
"svelte": "^5.48.0"
},
"keywords": [
"migration",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@
%sveltekit.head%
</head>

<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
<body data-sveltekit-preload-data="hover"><div style="display: contents">%sveltekit.body%</div></body>
</html>
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<script></script>

<div>
<p>This is a Svelte component without script block</p>
</div>
<div><p>This is a Svelte component without script block</p></div>
9 changes: 6 additions & 3 deletions packages/sv/lib/core/tooling/css/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { SvelteAst } from '../index.ts';

export function addRule(
node: SvelteAst.CSS.StyleSheet,
node: SvelteAst.CSS.StyleSheetRules,
options: { selector: string }
): SvelteAst.CSS.Rule {
// we do not check for existing rules here, as the selector AST from svelte is really complex
Expand Down Expand Up @@ -73,7 +73,10 @@ export function addDeclaration(
}
}

export function addImports(node: SvelteAst.CSS.StyleSheet, options: { imports: string[] }): void {
export function addImports(
node: SvelteAst.CSS.StyleSheetRules,
options: { imports: string[] }
): void {
let lastImportIndex = -1;

// Find the last existing @import to insert after it
Expand Down Expand Up @@ -113,7 +116,7 @@ export function addImports(node: SvelteAst.CSS.StyleSheet, options: { imports: s
}

export function addAtRule(
node: SvelteAst.CSS.StyleSheet,
node: SvelteAst.CSS.StyleSheetRules,
options: { name: string; params: string; append: boolean }
): SvelteAst.CSS.Atrule {
const atRules = node.children.filter((x) => x.type === 'Atrule');
Expand Down
14 changes: 9 additions & 5 deletions packages/sv/lib/core/tooling/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { print as esrapPrint } from 'esrap';
import ts from 'esrap/languages/ts';
import type { BaseNode } from 'estree';
import * as fleece from 'silver-fleece';
import { type AST as SvelteAst, parse as svelteParse, print as sveltePrint } from 'svelte/compiler';
import {
type AST as SvelteAst,
parse as svelteParse,
print as sveltePrint,
parseCss as svelteParseCss
} from 'svelte/compiler';
import * as yaml from 'yaml';
import * as toml from 'smol-toml';
import { ensureScript } from './svelte/index.ts';
Expand Down Expand Up @@ -62,12 +67,11 @@ export function serializeScript(
return code;
}

export function parseCss(content: string): SvelteAst.CSS.StyleSheet {
const ast = parseSvelte(`<style>${content}</style>`);
return ast.css!;
export function parseCss(content: string): SvelteAst.CSS.StyleSheetRules {
return svelteParseCss(content);
}

export function serializeCss(ast: SvelteAst.CSS.StyleSheet): string {
export function serializeCss(ast: SvelteAst.CSS.StyleSheetRules): string {
// `svelte` can print the stylesheet directly. But this adds the style tags (<style>) that we do not want here.
// `svelte` is unable to print an array of rules (ast.children) directly, therefore we concatenate the printed rules manually.

Expand Down
4 changes: 3 additions & 1 deletion packages/sv/lib/core/tooling/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export function parseScript(source: string): {
return { ast, comments, source, generateCode };
}

export function parseCss(source: string): { ast: utils.SvelteAst.CSS.StyleSheet } & ParseBase {
export function parseCss(
source: string
): { ast: Omit<utils.SvelteAst.CSS.StyleSheet, 'attributes' | 'content'> } & ParseBase {
const ast = utils.parseCss(source);
const generateCode = () => utils.serializeCss(ast);

Expand Down
2 changes: 1 addition & 1 deletion packages/sv/lib/create/templates/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@sveltejs/adapter-auto": "^4.0.0",
"@sveltejs/kit": "^2.22.0",
"@sveltejs/vite-plugin-svelte": "^6.0.0",
"svelte": "^5.25.0",
"svelte": "^5.48.0",
"typescript": "^5.3.3",
"vite": "^7.0.4"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"silver-fleece": "^1.2.1",
"smol-toml": "^1.5.2",
"sucrase": "^3.35.1",
"svelte": "^5.47.1",
"svelte": "https://pkg.pr.new/svelte@17654",
"tar-fs": "^3.1.1",
"tiny-glob": "^0.2.9",
"tinyexec": "^1.0.2",
Expand Down
55 changes: 11 additions & 44 deletions pnpm-lock.yaml

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

Loading