Skip to content

ParseError with :is() or :matches() containing :has() #4278

Closed

Description

@SuperPat45

To reproduce:

:is(:not(:has(>.foo)), :has(>.foo.bar)) {
    overflow: clip;
}

Current behavior:

Throw a:
ParseError: Missing closing ')'

Expected behavior:

No exception has the number of close parenthesis is correct
Environment information:

  • less version: 4.2.0
  • nodejs version: 20.17
  • operating system: windows

Activity

  1. dosubot commented on Aug 28, 2024

    @dosubot

    Hey @SuperPat45! I'm here to help you with any bugs, questions, or contributions you have while waiting for a human maintainer. Let's tackle this issue together!

    To resolve the ParseError "Missing closing ')'" when using :is() or :matches() containing :has() in the given CSS code with less version 4.2.0 on Windows, you need to ensure that the Less parser correctly handles nested parentheses. The provided chunker.js code is responsible for parsing the input and tracking parentheses levels.

    The error occurs because the parser does not correctly handle the nested structure of :is() or :matches() containing :has(). To fix this, you need to modify the parser to correctly track and match nested parentheses.

    Here is the corrected CSS code:

    :is(:not(:has(>.foo)), :has(>.foo.bar)) {
        overflow: clip;
    }

    And here is the relevant part of the chunker.js code that needs to be modified to handle nested parentheses correctly:

    case 40: // (
        parenLevel++;
        lastOpeningParen = chunkerCurrentIndex;
        continue;
    case 41: // )
        if (--parenLevel < 0) {
            return fail('missing opening `(`', chunkerCurrentIndex);
        }
        continue;

    Ensure that the parenLevel is correctly incremented and decremented for each opening and closing parenthesis. This will help the parser to correctly match nested parentheses and avoid the "Missing closing ')'" error [1].

    To continue talking to Dosu, mention @dosu.

  2. matthew-dean commented on Aug 28, 2024

    @matthew-dean
    Member

    Related to: #4268

  3. puckowski commented on Nov 26, 2024

    @puckowski
    Contributor

    I submitted a PR #4290

    The following Less

    @num: 3;
    :nth-child(@{num}) {
      selector: interpolated;
    }
    
    
    a:is(.b, :is(.c)) {
      color: blue;
    }
    
    :is(:not(:has(>.foo)), :has(>.foo.bar)) {
      overflow: clip;
    }

    becomes:

    :nth-child(3) {
      selector: interpolated;
    }
    a:is(.b, :is(.c)) {
      color: blue;
    }
    :is(:not(:has(>.foo)), :has(>.foo.bar)) {
      overflow: clip;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions