Skip to content

Commit

Permalink
fix: respect decl newlines for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
idoros committed Jun 12, 2024
1 parent a7facdc commit 61e5422
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/code-formatter/src/format-css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ function formatAst(ast: AnyNode, index: number, options: FormatOptions) {
} else if (betweenNode.postSpace.includes('\n' /* don't use NL */) && valueHasNewline) {
newBetween += betweenNode.preComments.join(``);
hasNewLineBeforeValue = true;
newBetween += ':' + afterComments + NL;
const independentCommentSpace = afterComments
? NL + indent.repeat(indentLevel + 1)
: '';
newBetween += ':' + independentCommentSpace + afterComments + NL;
} else {
newBetween += betweenNode.preComments.join(``);
newBetween += ': ' + afterComments;
Expand Down
31 changes: 31 additions & 0 deletions packages/code-formatter/test/formatter-experimental.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,37 @@ describe('formatter - experimental', () => {
`,
});
});
it('should respect newlines for comments', () => {
testFormatCss({
deindent: true,
source: `
.root {
prop1:
/*start standalone line*/
AAA,
/*inline before*/ BBB /*inline after*/
CCC
/*middle standalone line*/
DDD
/*end standalone line*/
;
}
`,
expect: `
.root {
prop1:
/*start standalone line*/
AAA,
/*inline before*/ BBB /*inline after*/
CCC
/*middle standalone line*/
DDD
/*end standalone line*/;
}
`,
});
});
it('should respect newline', () => {
testFormatCss({
deindent: true,
Expand Down

0 comments on commit 61e5422

Please sign in to comment.