Skip to content

Fix: CSS - Work comma selector with nested selectors#195

Merged
github-actions[bot] merged 1 commit intomainfrom
comma-selector
Apr 22, 2025
Merged

Fix: CSS - Work comma selector with nested selectors#195
github-actions[bot] merged 1 commit intomainfrom
comma-selector

Conversation

@black7375
Copy link
Contributor

@black7375 black7375 commented Apr 22, 2025

Description

Support comma selector for global style.

Related Issue

Summary by CodeRabbit

  • New Features
    • Added support for global styles with nested selectors containing commas, allowing more complex CSS selector groupings.
  • Tests
    • Introduced new test cases to verify correct handling of comma-separated nested selectors.

Additional context

Checklist

@changeset-bot
Copy link

changeset-bot bot commented Apr 22, 2025

🦋 Changeset detected

Latest commit: 98a9c93

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@mincho-js/transform-to-vanilla Patch
@mincho-js/css Patch
@mincho-js/vite Patch
@mincho-js/react Patch
react-babel Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Apr 22, 2025

Walkthrough

The changes introduce enhanced support for handling nested CSS selectors that include comma-separated parent selectors in the @mincho-js/transform-to-vanilla package. The nestedSelectorKey function is updated to correctly expand and process selectors when multiple parent selectors are present, ensuring proper transformation of complex CSS structures. Corresponding tests are added and updated to verify this behavior, particularly focusing on scenarios where selectors and pseudo-classes are combined with commas. The update is documented in a changeset.

Changes

Files/Paths Change Summary
.changeset/full-bottles-join.md Adds a changeset documenting the patch update for support of global styles with nested selectors containing commas.
packages/transform-to-vanilla/src/transform-keys/complex-selectors.ts Updates nestedSelectorKey to handle multiple parent selectors separated by commas; adds and updates tests for this new behavior.
packages/transform-to-vanilla/src/transform-object/index.ts Adds a new test case for transformStyle to verify correct transformation of nested selectors with comma-separated parent selectors.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant transformStyle
    participant nestedSelectorKey

    User->>transformStyle: Provide style object with comma-separated selectors
    transformStyle->>nestedSelectorKey: Expand nested selectors with parentSelector (may contain commas)
    nestedSelectorKey->>nestedSelectorKey: Split parentSelector by comma, replace & in key for each
    nestedSelectorKey-->>transformStyle: Return expanded selector string
    transformStyle-->>User: Output transformed selectors with correct nesting and comma handling
Loading

Suggested labels

bug

Poem

A bunny hopped through CSS land,
Where commas in selectors now expand.
Nested rules once tangled and tight,
Now split and joined just right.
With tests to guide each careful hop,
Our styles transform—no need to stop!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

yarn install v1.22.22
[1/4] Resolving packages...
error Couldn't find any versions for "eslint-config-custom" that matches "workspace:^"
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Contributor

Triggered from #195 by @​black7375.

Checking if we can fast forward main (3a681f0) to comma-selector (98a9c93).

Target branch (main):

commit 3a681f0bedeb9ad959bb5e38f6c8d1cc6533f291 (HEAD -> main, tag: @mincho-js/transform-to-vanilla@0.2.0, tag: @mincho-js/react@0.1.0, tag: @mincho-js/integration@0.1.0, tag: @mincho-js/esbuild@0.1.0, tag: @mincho-js/debug-log@1.1.0, tag: @mincho-js/css@0.2.0, tag: @mincho-js/css-additional-types@0.1.0, tag: @mincho-js/babel@0.1.0, origin/main)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Sun Apr 20 08:48:23 2025 +0900

    Chore: Bump packages

Pull request (comma-selector):

commit 98a9c9335f84407717cd5fd7d62ce6c6070af284 (pull_request/comma-selector)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Wed Apr 23 02:42:15 2025 +0900

    Fix: CSS - Work comma selector with nested selectors

It is possible to fast forward main (3a681f0) to comma-selector (98a9c93). If you have write access to the target repository, you can add a comment with /fast-forward to fast forward main to comma-selector.

@black7375 black7375 added the bug Something isn't working label Apr 22, 2025
@black7375 black7375 self-assigned this Apr 22, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
.changeset/full-bottles-join.md (1)

1-6: Clear and concise changeset description.

The changeset effectively communicates the feature addition of supporting global styles with nested selectors that contain commas.

Consider using a heading instead of bold formatting for the feature title to follow standard Markdown conventions:

-**Nested Selector with commas**
+## Nested Selector with commas
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

5-5: Emphasis used instead of a heading
null

(MD036, no-emphasis-as-heading)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a681f0 and 98a9c93.

📒 Files selected for processing (3)
  • .changeset/full-bottles-join.md (1 hunks)
  • packages/transform-to-vanilla/src/transform-keys/complex-selectors.ts (2 hunks)
  • packages/transform-to-vanilla/src/transform-object/index.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/transform-to-vanilla/src/transform-object/index.ts (1)
packages/css/src/index.ts (1)
  • StyleRule (56-56)
packages/transform-to-vanilla/src/transform-keys/complex-selectors.ts (2)
packages/transform-to-vanilla/src/transform-object/index.ts (2)
  • TransformContext (58-68)
  • initTransformContext (69-82)
packages/transform-to-vanilla/src/index.ts (2)
  • TransformContext (4-4)
  • initTransformContext (3-3)
🪛 markdownlint-cli2 (0.17.2)
.changeset/full-bottles-join.md

5-5: Emphasis used instead of a heading
null

(MD036, no-emphasis-as-heading)

🔇 Additional comments (3)
packages/transform-to-vanilla/src/transform-keys/complex-selectors.ts (2)

19-29: Well-implemented fix for handling comma-separated selectors.

The updated implementation correctly handles nested selectors with comma-separated parent selectors by splitting them, processing each individual selector, and then rejoining them. This ensures that when using selectors like "a, b" with a key like "&:hover", the result will be "a:hover, b:hover" instead of "a, b:hover".


76-90: Thorough test cases for comma-separated selectors.

The test cases cover all important scenarios:

  1. Simple pseudo-class appending
  2. Complex pseudo-class with negation
  3. Contextual selectors with attribute selectors

This comprehensive testing ensures the implementation works correctly with various selector combinations.

packages/transform-to-vanilla/src/transform-object/index.ts (1)

1016-1036: Good integration test for nested selectors with commas.

This test case properly verifies that the style transformation system correctly handles comma-separated parent selectors in nested style objects. It confirms that:

  1. The base style correctly applies to the joined selector string
  2. Nested pseudo-classes are correctly appended to each individual selector

The test appropriately complements the changes made to the nestedSelectorKey function.

@black7375
Copy link
Contributor Author

/fast-forward

@github-actions
Copy link
Contributor

Triggered from #195 (comment) by @​black7375.

Trying to fast forward main (3a681f0) to comma-selector (98a9c93).

Target branch (main):

commit 3a681f0bedeb9ad959bb5e38f6c8d1cc6533f291 (HEAD -> main, tag: @mincho-js/transform-to-vanilla@0.2.0, tag: @mincho-js/react@0.1.0, tag: @mincho-js/integration@0.1.0, tag: @mincho-js/esbuild@0.1.0, tag: @mincho-js/debug-log@1.1.0, tag: @mincho-js/css@0.2.0, tag: @mincho-js/css-additional-types@0.1.0, tag: @mincho-js/babel@0.1.0, origin/main)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Sun Apr 20 08:48:23 2025 +0900

    Chore: Bump packages

Pull request (comma-selector):

commit 98a9c9335f84407717cd5fd7d62ce6c6070af284 (pull_request/comma-selector)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Wed Apr 23 02:42:15 2025 +0900

    Fix: CSS - Work comma selector with nested selectors

Fast forwarding main (3a681f0) to comma-selector (98a9c93).

$ git push origin 98a9c9335f84407717cd5fd7d62ce6c6070af284:main
To https://github.com/mincho-js/mincho.git
   3a681f0..98a9c93  98a9c9335f84407717cd5fd7d62ce6c6070af284 -> main

@github-actions github-actions bot merged commit 98a9c93 into main Apr 22, 2025
9 checks passed
@github-actions github-actions bot deleted the comma-selector branch April 22, 2025 17:47
@github-actions github-actions bot mentioned this pull request Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant