From ac0441530f63eac50ded89c0f70575e766c62bca Mon Sep 17 00:00:00 2001 From: Victorien Elvinger Date: Fri, 12 Jan 2024 21:42:34 +0100 Subject: [PATCH] fix(js_formatter): fix #1511 --- CHANGELOG.md | 2 + crates/biome_formatter/src/buffer.rs | 4 -- .../tests/specs/ts/issue1511.ts | 3 ++ .../tests/specs/ts/issue1511.ts.snap | 43 +++++++++++++++++++ .../src/content/docs/internals/changelog.mdx | 2 + 5 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 crates/biome_js_formatter/tests/specs/ts/issue1511.ts create mode 100644 crates/biome_js_formatter/tests/specs/ts/issue1511.ts.snap diff --git a/CHANGELOG.md b/CHANGELOG.md index 348d64aca7ae..446f2b547362 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,8 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom - Fix [#1172](https://github.com/biomejs/biome/issues/1172). Fix placement of line comment after function expression parentheses, they are now attached to first statement in body. Contributed by @kalleep +- Fix [#1511](https://github.com/biomejs/biome/issues/1511) that made the JavaScript formatter crash. COntributed @Conaclos + ### JavaScript APIs ### Linter diff --git a/crates/biome_formatter/src/buffer.rs b/crates/biome_formatter/src/buffer.rs index 420990336ca7..5012067d2c96 100644 --- a/crates/biome_formatter/src/buffer.rs +++ b/crates/biome_formatter/src/buffer.rs @@ -557,10 +557,6 @@ fn clean_interned( Some((mut cleaned, rest)) => { let mut is_in_expanded_conditional_content = false; for element in rest { - if is_in_expanded_conditional_content { - continue; - } - let element = match element { FormatElement::Tag(Tag::StartConditionalContent(condition)) if condition.mode == PrintMode::Expanded => diff --git a/crates/biome_js_formatter/tests/specs/ts/issue1511.ts b/crates/biome_js_formatter/tests/specs/ts/issue1511.ts new file mode 100644 index 000000000000..5ea570eb2e82 --- /dev/null +++ b/crates/biome_js_formatter/tests/specs/ts/issue1511.ts @@ -0,0 +1,3 @@ +call(a, function (b: () => t1 | t2) {}); + +call(a, (b: () => t1 | t2) => {}); diff --git a/crates/biome_js_formatter/tests/specs/ts/issue1511.ts.snap b/crates/biome_js_formatter/tests/specs/ts/issue1511.ts.snap new file mode 100644 index 000000000000..c39f8cb433b1 --- /dev/null +++ b/crates/biome_js_formatter/tests/specs/ts/issue1511.ts.snap @@ -0,0 +1,43 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: ts/issue1511.ts +--- + +# Input + +```ts +call(a, function (b: () => t1 | t2) {}); + +call(a, (b: () => t1 | t2) => {}); + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +JSX quote style: Double Quotes +Quote properties: As needed +Trailing comma: All +Semicolons: Always +Arrow parentheses: Always +Bracket spacing: true +Bracket same line: false +----- + +```ts +call(a, function (b: () => t1 | t2) {}); + +call(a, (b: () => t1 | t2) => {}); +``` + + diff --git a/website/src/content/docs/internals/changelog.mdx b/website/src/content/docs/internals/changelog.mdx index 729bddb5ee72..e54748385ded 100644 --- a/website/src/content/docs/internals/changelog.mdx +++ b/website/src/content/docs/internals/changelog.mdx @@ -38,6 +38,8 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom - Fix [#1172](https://github.com/biomejs/biome/issues/1172). Fix placement of line comment after function expression parentheses, they are now attached to first statement in body. Contributed by @kalleep +- Fix [#1511](https://github.com/biomejs/biome/issues/1511) that made the JavaScript formatter crash. COntributed @Conaclos + ### JavaScript APIs ### Linter