From f6c9253036a7d309109a3e7be17945240369fe5c Mon Sep 17 00:00:00 2001 From: Alexey Erhskov Date: Tue, 8 Oct 2024 17:34:13 +0300 Subject: [PATCH 1/2] 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(); From c5b9e188304dbdcb16b0febd87fe34ce7b6f74ed Mon Sep 17 00:00:00 2001 From: Alexey Erhskov Date: Tue, 8 Oct 2024 17:58:41 +0300 Subject: [PATCH 2/2] up version --- packages/postcss-logical-fallback/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/postcss-logical-fallback/package.json b/packages/postcss-logical-fallback/package.json index 070dbb9..57b94b0 100644 --- a/packages/postcss-logical-fallback/package.json +++ b/packages/postcss-logical-fallback/package.json @@ -1,6 +1,6 @@ { "name": "postcss-logical-fallback", - "version": "1.0.1", + "version": "1.0.2", "description": "PostCSS plugin for logical fallback props", "main": "index.js", "files": [