Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SuperPat45 opened this issue Aug 28, 2024 · 3 comments
Open

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

SuperPat45 opened this issue Aug 28, 2024 · 3 comments
Labels

Comments

@SuperPat45
Copy link

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
@SuperPat45 SuperPat45 added the bug label Aug 28, 2024
Copy link

dosubot bot commented Aug 28, 2024

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.

@matthew-dean
Copy link
Member

Related to: #4268

@puckowski
Copy link
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
Labels
Projects
None yet
Development

No branches or pull requests

3 participants