Skip to content
Merged
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
7 changes: 7 additions & 0 deletions src/__tests__/exceptions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
throws("unclosed pseudo class", "a:");
throws("unclosed attribute selector", '[name="james"][href');

for (const selector of [".", "a.", ".a..b", "#a.", ":not(.)", "a > ."]) {
throws(`empty class name in ${selector}`, selector, "Expected a class name.");
}
for (const selector of ["#", "a#", "#a#", ".a#", ":is(#)", "a, #"]) {
throws(`empty ID in ${selector}`, selector, "Expected an id.");
}

// Constructs left open at end of input. These threw a raw TypeError before
// `attribute`, `namespace` and `parentheses` guarded against running out of
// tokens. Asserted by message rather than by type: the default
Expand Down Expand Up @@ -75,10 +82,10 @@
throws("bad syntax (2)", "! .body");

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

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

View workflow job for this annotation

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

eslint(no-useless-escape)

Unnecessary escape character ';'

Check warning on line 85 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 85 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 85 in src/__tests__/exceptions.mjs

View workflow job for this annotation

GitHub Actions / test (windows-latest, latest)

eslint(no-useless-escape)

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

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

View workflow job for this annotation

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

eslint(no-useless-escape)

Unnecessary escape character '/'

Check warning on line 88 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 88 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 88 in src/__tests__/exceptions.mjs

View workflow job for this annotation

GitHub Actions / test (windows-latest, latest)

eslint(no-useless-escape)

Unnecessary escape character '/'
"Unexpected '/'. Escaping special characters with \\ may help.",
);
throws(
Expand Down
6 changes: 6 additions & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1154,13 +1154,19 @@ export default class Parser {
const sourceIndex = current[TOKEN.START_POS] + indices[i];
const source = getSource(current[1], current[2] + ind, current[3], current[2] + (index - 1));
if (classIndexes.has(ind)) {
if (value.length === 1) {
return this.expected("class name", sourceIndex);
}
let classNameOpts = {
value: value.slice(1),
source,
sourceIndex,
};
node = new ClassName(unescapeProp(classNameOpts, "value"));
} else if (idIndexes.has(ind)) {
if (value.length === 1) {
return this.expected("id", sourceIndex);
}
let idOpts = {
value: value.slice(1),
source,
Expand Down
Loading