Skip to content
Merged
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
10 changes: 10 additions & 0 deletions .changeset/plain-turkeys-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@biomejs/biome": patch
---

Fixed [#9589](https://github.com/biomejs/biome/issues/9589). Now Biome correctly parses object expressions inside props and directives. The following code doesn't emit errors anymore:

```astro
<style is:global define:vars={{ bgLight: light }}>
<Component name={{ first, name }} />
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- should not generate diagnostics-->
---
import { SectionRow } from "./Section.astro"
const foregroundColor = "rgb(221 243 228)";
const backgroundColor = "rgb(24 121 78)";
const message = "Astro is awesome!";
---
<SectionRow
title="A section title."
description="<p>A section description.</p>"
screenshot={{
path: "img-path-name",
alt: message,
}}
/>

<style define:vars={{ textColor: foregroundColor, backgroundColor }}>
h1 {
background-color: var(--backgroundColor);
color: var(--textColor);
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
expression: valid_issue_9589.astro
---
# Input
```astro
<!-- should not generate diagnostics-->
---
import { SectionRow } from "./Section.astro"
const foregroundColor = "rgb(221 243 228)";
const backgroundColor = "rgb(24 121 78)";
const message = "Astro is awesome!";
---
<SectionRow
title="A section title."
description="<p>A section description.</p>"
screenshot={{
path: "img-path-name",
alt: message,
}}
/>

<style define:vars={{ textColor: foregroundColor, backgroundColor }}>
h1 {
background-color: var(--backgroundColor);
color: var(--textColor);
}
</style>

```
6 changes: 4 additions & 2 deletions crates/biome_service/src/embed/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ pub(crate) enum EmbedCandidate {
TextExpression { content: EmbedContent },

/// A directive attribute value containing JS.
/// Vue: `@click="handler()"`, `:prop="value"`, `v-if="cond"`
/// Svelte: `on:click={handler}`, `bind:value={x}`
/// - Vue: `@click="handler()"`, `:prop="value"`, `v-if="cond"`
/// - Svelte: `on:click={handler}`, `bind:value={x}`
/// - Astro: `define:vars={{ x }}`,
///
/// Built from `HtmlAttributeInitializerClause` by the HTML handler.
Directive {
content: EmbedContent,
Expand Down
29 changes: 19 additions & 10 deletions crates/biome_service/src/file_handlers/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,17 +1182,26 @@ fn parse_matched_embed(
if let Some(efs) = embedded_file_source {
js_source = efs;
}
if ctx.host_file_source.is_svelte() {
js_source = js_source
.with_embedding_kind(EmbeddingKind::Svelte { is_source: false });
} else if ctx.host_file_source.is_vue() {
js_source = js_source.with_embedding_kind(EmbeddingKind::Vue {
setup: false,
is_source: false,
event_handler: *is_event_handler,
allow_statements: false,
});
match ctx.host_file_source.variant() {
HtmlVariant::Standard(_) => {}
HtmlVariant::Astro => {
js_source = js_source
.with_embedding_kind(EmbeddingKind::Astro { frontmatter: false });
}
HtmlVariant::Vue => {
js_source = js_source.with_embedding_kind(EmbeddingKind::Vue {
setup: false,
is_source: false,
event_handler: *is_event_handler,
allow_statements: false,
});
}
HtmlVariant::Svelte => {
js_source = js_source
.with_embedding_kind(EmbeddingKind::Svelte { is_source: false });
}
}

false
}
_ => false,
Expand Down
Loading