Skip to content

fix: multiline component attributes#37

Merged
Princesseuh merged 3 commits into
feat/rustfrom
fix/multiline-component-attribute
May 21, 2026
Merged

fix: multiline component attributes#37
Princesseuh merged 3 commits into
feat/rustfrom
fix/multiline-component-attribute

Conversation

@Princesseuh
Copy link
Copy Markdown
Member

@Princesseuh Princesseuh commented May 19, 2026

Changes

Fixes an Unterminated string literal error when a quoted attribute on a component contains literal newlines — e.g. a multi-line class="" produced by prettier-plugin-classnames.

Component attributes are emitted into a JS props object ({ "class": "..." }). A raw \n inside that string literal is invalid JS and breaks the generated module.

  • Add escape_newlines helper in printer/escape.rs, mirroring the Go compiler's escapeNewlines (\n\n, \r\r).
  • Apply it alongside escape_double_quotes in the two component props-object paths in components.rs: the scoped-class merge and the general quoted-attribute case. Matches the Go compiler's single use of escapeNewlines in printAttributesToObject.

Testing

  • Unit tests for escape_newlines (LF, CR, CRLF, multi-line class, no-op).
  • New snapshot fixture multiline_class_attribute_on_component.astro covering the motivating case.

Docs

Bug fix only, no docs needed.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 19, 2026

🦋 Changeset detected

Latest commit: 4856182

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@astrojs/compiler-binding Patch
@astrojs/compiler-rs Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Princesseuh Princesseuh marked this pull request as ready for review May 21, 2026 10:36
@Princesseuh Princesseuh merged commit f4adcce into feat/rust May 21, 2026
6 checks passed
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.

1 participant