Skip to content

feat: Add expression formatting in CSS strings for components #29763

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

janosh
Copy link
Contributor

@janosh janosh commented Jun 16, 2025

closes #26999

new function format_expressions_in_text handles JS expressions in text, allowing for temporary placeholders during formatting of component files. The format_html function preprocesses expressions before markup parsing and restores them after formatting.

tested for Svelte and Vue files:

  • new badly_formatted.vue and its fixed counterpart
  • updated existing Svelte test file to include dynamic style

janosh added 2 commits June 16, 2025 08:35
new function `format_expressions_in_text` handles JS expressions in text, allowing for temporary placeholders during formatting of component files. The `format_html` function preprocesses expressions before markup parsing and restores them after formatting.
…new formatting test for Vue

- new `badly_formatted.vue` and its fixed counterpart
- updated existing Svelte test file to include dynamic style
@CLAassistant
Copy link

CLAassistant commented Jun 16, 2025

CLA assistant check
All committers have signed the CLA.

@janosh janosh changed the title Add expression formatting in CSS strings for components feat: Add expression formatting in CSS strings for components Jun 16, 2025
Comment on lines +481 to +482
"svelte" | "astro" => (r"\{([^{}]+)\}", "{", "}"),
"vue" => (r"\{\{([^{}]+)\}\}", "{{", "}}"),
Copy link
Member

@dsherret dsherret Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems very error prone to do (ex. it would format within comments). Probably it should be handled by markup_fmt instead and it can call out to format these expressions with the appropriate formatter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fmt(svelte): formatter error on dynamic style in svelte
3 participants