8000 chore: rework `content` updates by AdrianGonz97 · Pull Request #75 · sveltejs/cli · GitHub
[go: up one dir, main page]

Skip to content

chore: rework content updates #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Oct 11, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix indents
  • Loading branch information
AdrianGonz97 committed Oct 9, 2024
commit d7739ad015b213041f616ca8bfc6b715908cf152
13 changes: 10 additions & 3 deletions packages/core/tooling/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export function parseSvelte(source: string): {
ms.appendLeft(0, script);
} else {
const { start, end } = locations(source, scriptSource);
ms.overwrite(start, end, code.script);
const formatted = indent(code.script, ms.getIndentString());
ms.overwrite(start, end, formatted);
}
}
if (code.css !== undefined) {
Expand All @@ -83,7 +84,8 @@ export function parseSvelte(source: string): {
ms.append(style);
} else {
const { start, end } = locations(source, cssSource);
ms.overwrite(start, end, code.css);
const formatted = indent(code.css, ms.getIndentString());
ms.overwrite(start, end, formatted);
}
}
if (code.template !== undefined) {
Expand All @@ -105,8 +107,13 @@ export function parseSvelte(source: string): {
};
}

function locations(source: string, search: string) {
function locations(source: string, search: string): { start: number; end: number } {
const start = source.indexOf(search);
const end = start + search.length;
return { start, end };
}

function indent(content: string, indent: string): string {
const indented = indent + content.split('\n').join(`\n${indent}`);
return `\n${indented}\n`;
}
0