Skip to content

Commit

Permalink
allow empty expression
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane committed Feb 18, 2024
1 parent 56bb90f commit e0a4f9e
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions dprint_plugin/tests/integration/basic.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ function generateHtml(data:unknown) {
{#if Math.random( )>0.5}...{:else if Date.now( )>0 }...{/if}

{#key 1+2}s{/key}

<button class="{}" on:click={}>{}{/**/}</button>
1 change: 1 addition & 0 deletions dprint_plugin/tests/integration/basic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ function greet(msg:string){alert(msg)}
<template #default="{item:value}:{item:Record<string,number>}"></template>

<button @click="e=>console.log(e)"></button>
<button :class="" @click="">{{}}{{/**/}}</button>
</template>
2 changes: 2 additions & 0 deletions dprint_plugin/tests/integration/biome/basic.svelte.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ function generateHtml(data: unknown) {

{#key 1 + 2}s{/key}

<button class={} on:click={}>{}{/**/}</button>

1 change: 1 addition & 0 deletions dprint_plugin/tests/integration/biome/basic.vue.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ function greet(msg: string) {
></template>
<button @click="(e) => console.log(e)"></button>
<button :class="" @click="">{{ }}{{ /**/ }}</button>
</template>

2 changes: 2 additions & 0 deletions dprint_plugin/tests/integration/dprint_ts/basic.svelte.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ function generateHtml(data: unknown) {

{#key 1 + 2}s{/key}

<button class={} on:click={}>{}{/**/}</button>

1 change: 1 addition & 0 deletions dprint_plugin/tests/integration/dprint_ts/basic.vue.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ function greet(msg: string) {
></template>
<button @click="e => console.log(e)"></button>
<button :class="" @click="">{{ }}{{ /**/ }}</button>
</template>

8 changes: 5 additions & 3 deletions markup_fmt/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ where
// Trim original code before sending it to the external formatter.
// This makes sure the code will be trimmed
// though external formatter isn't available.
let wrapped = format!("let e = {}", code.trim());
let wrapped = format!("<>{{{}}}</>", code.trim());
let formatted = self.format_with_external_formatter(
Path::new("expr.ts"),
Path::new("expr.tsx"),
&wrapped,
self.print_width
.saturating_sub(self.indent_level)
Expand All @@ -104,8 +104,10 @@ where
let formatted =
formatted.trim_end_matches(|c: char| c.is_ascii_whitespace() || c == ';');
formatted
.strip_prefix("let e =")
.strip_prefix("<>{")
.and_then(|s| s.strip_suffix("}</>"))
.unwrap_or(formatted)
.trim_end_matches(|c: char| c.is_ascii_whitespace() || c == ';')
.trim_start()
.to_owned()
}
Expand Down

0 comments on commit e0a4f9e

Please sign in to comment.