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();