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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ const mixedTemplate = html\`<div><h1>Title</h1></div>\`;
const mixedDocs = md\`#Documentation
This is **important**.\`;

// Multi-line with blank lines - should preserve blank lines without trailing whitespace
const multilineCSS = css\`
.foo {
color: red;
}

.bar {
color: blue;
}
\`;

const multilineGQL = gql\`
type Foo {
name: String!
}

type Bar {
value: Int!
}
\`;

// Empty - Regular template literals retain newlines and spaces, but embedded ones are condensed
const empty = css\`\`;
const empty2 = styled\`
Expand Down Expand Up @@ -58,6 +79,27 @@ const mixedDocs = md\`
This is **important**.
\`;

// Multi-line with blank lines - should preserve blank lines without trailing whitespace
const multilineCSS = css\`
.foo {
color: red;
}

.bar {
color: blue;
}
\`;

const multilineGQL = gql\`
type Foo {
name: String!
}

type Bar {
value: Int!
}
\`;

// Empty - Regular template literals retain newlines and spaces, but embedded ones are condensed
const empty = css\`\`;
const empty2 = styled\`\`;
Expand Down
21 changes: 21 additions & 0 deletions apps/oxfmt/test/cli/embedded_languages/fixtures/mixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@ const mixedTemplate = html`<div><h1>Title</h1></div>`;
const mixedDocs = md`#Documentation
This is **important**.`;

// Multi-line with blank lines - should preserve blank lines without trailing whitespace
const multilineCSS = css`
.foo {
color: red;
}
.bar {
color: blue;
}
`;

const multilineGQL = gql`
type Foo {
name: String!
}
type Bar {
value: Int!
}
`;

// Empty - Regular template literals retain newlines and spaces, but embedded ones are condensed
const empty = css``;
const empty2 = styled`
Expand Down
6 changes: 5 additions & 1 deletion crates/oxc_formatter/src/print/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,11 @@ fn format_embedded_template<'a>(
let format_content = format_with(|f: &mut Formatter<'_, 'a>| {
let content = f.context().allocator().alloc_str(&formatted);
for line in content.split('\n') {
write!(f, [text(line), hard_line_break()]);
if line.is_empty() {
write!(f, [empty_line()]);
} else {
write!(f, [text(line), hard_line_break()]);
}
}
});

Expand Down
Loading