Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Sep 3, 2025

The CSS parser was failing to correctly parse nested rules that begin with element selectors in DeclarationList context. Consider:

/* This didn't work - p was treated as a property, not a selector */
main {
   color: blue;
   p {
      margin-top: 0;
   }
}

The issue was in the DeclarationList.js parser which only recognized & (nesting selector) as the start of a nested rule. Any other selector like p, div:hover, .class, etc. would be incorrectly parsed as a malformed declaration and converted to Raw content.

Changes made:

  1. Enhanced selector detection: Updated DeclarationList.js to use comprehensive isSelectorStart() logic instead of just checking for &

  2. Improved lookahead logic: Added sophisticated token lookahead in isElementSelectorStart() to distinguish between:

    • Properties: p: value; or p: value
    • Element selectors: p { ... }
    • Pseudo-class selectors: div:hover { ... }
  3. Fixed EOF handling: Properly handle end-of-input cases to ensure p:v (without semicolon) is correctly parsed as a declaration, not a selector

  4. Updated test fixtures: Modified existing test cases to reflect the correct parsing behavior

Before:

// Parsing "color: blue; p { margin: 0; }" in DeclarationList context
{
  children: [
    { type: "Declaration", property: "color", ... },
    { type: "Raw", value: "p { margin: 0; }" }  // ❌ Raw content
  ]
}

After:

// Parsing "color: blue; p { margin: 0; }" in DeclarationList context  
{
  children: [
    { type: "Declaration", property: "color", ... },
    { type: "Rule", prelude: { /* p selector */ }, ... }  // ✅ Proper Rule
  ]
}

The fix now correctly handles all selector types in nested contexts while preserving proper distinction between properties and selectors.

Fixes #84.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@eslint-github-bot
Copy link

Hi @Copilot!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

@eslint-github-bot
Copy link

Hi @Copilot!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

@eslint-github-bot
Copy link

Hi @Copilot!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

2 similar comments
@eslint-github-bot
Copy link

Hi @Copilot!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

@eslint-github-bot
Copy link

Hi @Copilot!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

@eslint-github-bot
Copy link

Hi @Copilot!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

2 similar comments
@eslint-github-bot
Copy link

Hi @Copilot!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

@eslint-github-bot
Copy link

Hi @Copilot!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

@Copilot Copilot AI changed the title [WIP] Nested element selector doesn't parse correctly Fix nested element selector parsing in DeclarationList context Sep 3, 2025
@Copilot Copilot AI requested a review from nzakas September 3, 2025 15:06
Copilot finished work on behalf of nzakas September 3, 2025 15:06
@eslint-github-bot
Copy link

Hi @Copilot!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nested element selector doesn't parse correctly

2 participants