From f6c9253036a7d309109a3e7be17945240369fe5c Mon Sep 17 00:00:00 2001 From: Alexey Erhskov Date: Tue, 8 Oct 2024 17:34:13 +0300 Subject: [PATCH] fix empty comments at rule copy --- .../src/utils/has-empty-child-nodes.ts | 7 +++- .../tests/no-changes.test.ts | 38 +++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 packages/postcss-logical-fallback/tests/no-changes.test.ts diff --git a/packages/postcss-logical-fallback/src/utils/has-empty-child-nodes.ts b/packages/postcss-logical-fallback/src/utils/has-empty-child-nodes.ts index d73d109..9a8bf0b 100644 --- a/packages/postcss-logical-fallback/src/utils/has-empty-child-nodes.ts +++ b/packages/postcss-logical-fallback/src/utils/has-empty-child-nodes.ts @@ -1,3 +1,6 @@ -import {Container} from "postcss"; +import { Container } from 'postcss'; -export const hasEmptyChildNodes = ({nodes}: Container) => !nodes || nodes.length === 0 +export const hasEmptyChildNodes = ({ nodes }: Container) => { + const significantNodes = nodes.filter((node) => node.type !== 'comment'); + return !significantNodes || significantNodes.length === 0; +}; diff --git a/packages/postcss-logical-fallback/tests/no-changes.test.ts b/packages/postcss-logical-fallback/tests/no-changes.test.ts new file mode 100644 index 0000000..237746d --- /dev/null +++ b/packages/postcss-logical-fallback/tests/no-changes.test.ts @@ -0,0 +1,38 @@ +import { test } from 'uvu'; +import { run } from './run'; + +test('should not copy comments', async () => { + await run( + `body { + /* stylelint-disable-next-line plugin/no-unsupported-browser-features */ + min-height: 100vh; + padding: 2rem; + }`, + `body { + /* stylelint-disable-next-line plugin/no-unsupported-browser-features */ + min-height: 100vh; + padding: 2rem; + }`, + ); + + await run( + `.class { + /* + multiline + comment + */ + min-height: 100vh; + padding: 2rem; + }`, + `.class { + /* + multiline + comment + */ + min-height: 100vh; + padding: 2rem; + }`, + ); +}); + +test.run();