Skip to content
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

🐛 BUG: Multiline string attributes inside attribute with invalid TSX identifier cause compiler to generate invalid code #961

Open
Princesseuh opened this issue Feb 4, 2024 · 1 comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: tsx Related to the TSX output (scope)

Comments

@Princesseuh
Copy link
Member

What version of @astrojs/compiler are you using?

2.5.2

What package manager are you using?

pnpm

What operating system are you using?

macOS

Describe the Bug

Title is a mouthful, TL;DR, the following valid HTML:

<div
    :class="{
    'bg-zinc-50 ring-1 ring-zinc-200 dark:bg-black/20 dark:ring-zinc-800': tab == 'preview',
    'bg-black': tab != 'preview'
  }"
>
</div>

generates the following invalid TSX, due to the multiline attirbute:

<div {...{":class":"{
    'bg-zinc-50 ring-1 ring-zinc-200 dark:bg-black/20 dark:ring-zinc-800': tab == 'preview',
    'bg-black': tab != 'preview'
  }"}} >
</div>

Using a valid identifier however works (TSX doesn't allow : at the beginning of attributes)

Link to Minimal Reproducible Example

https://live-astro-compiler.vercel.app/?editor-state=WzMxLDEzOSw4LDAsMTAwLDk5LDE5MSwxMDEsMiwzLDIwNSwxNDYsODEsMTA3LDE5NCw0OCwxNiwxOTksMTkxLDc0LDE1MSwxNTEsMTkwLDE2OCwyMzUsMTAsMTk0LDQwLDU4LDE2LDE5OSwxOTgsOTYsMTUsMTk1LDE4NiwyMDUsMTM1LDE5MCw5MiwxNDcsODMsMTM4LDEwNSw4Miw0NiwxNjksMTMwLDIyNiwxMTksMjIzLDE4MSwxMTcsODYsMjMwLDIzLDg4LDk0LDE0NiwyNTIsMjQzLDE4NywxMjcsNDYsMTUxLDU5LDEwLDg5LDE5LDE2MSwyNDEsMTE1LDkxLDg2LDEzMyw3MCwyNTAsNjYsMTE0LDEzMyw1MywzNCwxNywyNDEsMTA0LDYwLDEzOCwxOTcs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SwyOSwxMDYsMTQ4LDMwLDIxMywyNDIsMjE1LDEwMCw5LDU3LDIyMywyMTUsNTQsMjI0LDIxMywxMDUsMTg2LDE4NiwyMTAsNzksNjMsNSwxMjAsMTgzLDk1LDE5NCwyLDAsMF0%3D

@Princesseuh Princesseuh added feat: tsx Related to the TSX output (scope) - P3: minor bug An edge case that only affects very specific usage (priority) labels Feb 4, 2024
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Feb 4, 2024
@Princesseuh Princesseuh removed the needs triage Issue needs to be triaged label Feb 4, 2024
@ekfuhrmann
Copy link

Just want to add that this seems to effect multiline Alpine.js attributes as was discussed in this Support issue on Discord.

There is a workaround, at least in the context of Alpine.js, that you can wrap the multiline string with a backtick, and then work without any TS errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: tsx Related to the TSX output (scope)
Projects
None yet
Development

No branches or pull requests

2 participants