Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/__tests__/exceptions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
"a(",
"Expected a closing parenthesis.",
);
// A `(` with nothing after it, at the start or right after a pseudo, still
// threw a raw TypeError: there was no token to start the new node at.
for (const selector of ["(", ":not(", "a:hover(", "a, ("]) {
throws(
`unclosed parenthesis with nothing after it in ${selector}`,
selector,
"Expected a closing parenthesis.",
);
}

// An attribute selector whose last token before `]` is one of `* $ ^ ~ |`.
// The `attribute` token loop looked ahead to `next` without checking it
Expand Down Expand Up @@ -82,10 +91,10 @@
throws("bad syntax (2)", "! .body");

throws("missing backslash for semicolon", ".;");
throws("missing backslash for semicolon (2)", ".\;");

Check warning on line 94 in src/__tests__/exceptions.mjs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, latest)

eslint(no-useless-escape)

Unnecessary escape character ';'

Check warning on line 94 in src/__tests__/exceptions.mjs

View workflow job for this annotation

GitHub Actions / test (windows-latest, lts/*)

eslint(no-useless-escape)

Unnecessary escape character ';'

Check warning on line 94 in src/__tests__/exceptions.mjs

View workflow job for this annotation

GitHub Actions / test (windows-latest, latest)

eslint(no-useless-escape)

Unnecessary escape character ';'

Check warning on line 94 in src/__tests__/exceptions.mjs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, lts/*)

eslint(no-useless-escape)

Unnecessary escape character ';'
throws(
"unexpected / foo",
"-Option\/root",

Check warning on line 97 in src/__tests__/exceptions.mjs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, latest)

eslint(no-useless-escape)

Unnecessary escape character '/'

Check warning on line 97 in src/__tests__/exceptions.mjs

View workflow job for this annotation

GitHub Actions / test (windows-latest, lts/*)

eslint(no-useless-escape)

Unnecessary escape character '/'

Check warning on line 97 in src/__tests__/exceptions.mjs

View workflow job for this annotation

GitHub Actions / test (windows-latest, latest)

eslint(no-useless-escape)

Unnecessary escape character '/'

Check warning on line 97 in src/__tests__/exceptions.mjs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, lts/*)

eslint(no-useless-escape)

Unnecessary escape character '/'
"Unexpected '/'. Escaping special characters with \\ may help.",
);
throws(
Expand Down
6 changes: 0 additions & 6 deletions src/__tests__/property/known.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,4 @@ export const KNOWN = [
note: "an attribute namespace of `&` prints as `[&|x]`, which does not parse",
match: (f) => f.case === "attribute namespace setter" && f.value === "&",
},
{
property: "invalid input throws a parser error",
tracking: "not filed yet",
note: "an unclosed `(` at the start or after a pseudo throws a TypeError",
match: (f) => f.error.startsWith("TypeError") && f.input.includes("("),
},
];
4 changes: 4 additions & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,10 @@ export default class Parser {
let unbalanced = 1;
let openingToken = this.currToken;
this.position++;
if (!this.currToken) {
// Nothing follows the `(`, so there is no token to start a node at.
return this.expected("closing parenthesis", openingToken[TOKEN.START_POS]);
}
if (last && last.type === types.PSEUDO) {
const selector = new Selector({
source: { start: tokenStart(this.tokens[this.position]) },
Expand Down
Loading