Skip to content

fix: report a parser error for a ( with nothing after it - #381

Open
bardrop wants to merge 1 commit into
postcss:mainfrom
bardrop-oss:fix/unclosed-paren-at-end
Open

bardrop wants to merge 1 commit into
postcss:mainfrom
bardrop-oss:fix/unclosed-paren-at-end

Conversation

@bardrop

@bardrop bardrop commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

What was wrong

#330 fixed a( at end of input, but a ( with nothing after it at the start or right after a pseudo still threw a raw TypeError instead of the parser's own error:

parser().astSync("(");     // TypeError: Cannot read properties of undefined (reading '1')
parser().astSync(":not("); // TypeError: Cannot read properties of undefined (reading '1')
parser().astSync("a:b(");  // TypeError: Cannot read properties of undefined (reading '1')

Expected: Error: Expected a closing parenthesis., the same as for a(.

In the pseudo branch, parentheses() reads this.tokens[this.position] to start the new selector, and that token does not exist. In the other branch, parenEnd stays undefined and getSource(parenEnd[...]) throws.

This is the "an unclosed ( at the start or after a pseudo throws a TypeError" entry in property/known.mjs.

The fix

In parentheses(), if no token follows the (, report "closing parenthesis" at the opening token before building any node.

Tests

  • exceptions.mjs: 4 new cases ((, :not(, a:hover(, a, (), checked by message. Before the fix: 44 pass, 4 fail. After: 48 pass.
  • Removed the now stale entry from property/known.mjs. With the entry removed and without the fix, the property suite fails with 231 unexpected failures (4 of 5 pass). With the fix: 5 of 5 pass.
  • npm test (lint, typecheck, coverage, property tests): 1145 tests pass, 5 property tests pass.

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.

1 participant