镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/__tests__/classes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,22 @@ test("class selector with escaping (36)", ".not-pseudo\\:\\:focus", (t, tree) =>
t.deepEqual(tree.nodes[0].nodes[0].type, "class");
t.deepEqual(tree.nodes[0].nodes[0].raws.value, "not-pseudo\\:\\:focus");
});

test("class prefix selector", ".foo-*", (t, tree) => {
t.deepEqual(tree.nodes[0].nodes[0].type, "class");
t.deepEqual(tree.nodes[0].nodes[0].value, "foo-*");
});

test("class prefix selector with tag", "div.foo-*", (t, tree) => {
t.deepEqual(tree.nodes[0].nodes[0].type, "tag");
t.deepEqual(tree.nodes[0].nodes[0].value, "div");
t.deepEqual(tree.nodes[0].nodes[1].type, "class");
t.deepEqual(tree.nodes[0].nodes[1].value, "foo-*");
});

test("multiple class prefix selectors", ".foo-*.bar-*", (t, tree) => {
t.deepEqual(tree.nodes[0].nodes[0].type, "class");
t.deepEqual(tree.nodes[0].nodes[0].value, "foo-*");
t.deepEqual(tree.nodes[0].nodes[1].type, "class");
t.deepEqual(tree.nodes[0].nodes[1].value, "bar-*");
});
Comment on lines +278 to +295
13 changes: 12 additions & 1 deletion src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,17 @@ export default class Parser {
}
nextToken = this.nextToken;
}
// Support class prefix selectors like .foo-*
const wordStartToken = this.currToken;
if (
nextToken &&
nextToken[TOKEN.TYPE] === tokens.asterisk &&
word.endsWith("-") &&
word.indexOf(".") !== -1
) {
this.position++;
word += "*";
}
const hasClass = indexesOf(word, ".").filter((i) => {
// Allow escaped dot within class name
const escapedDot = word[i - 1] === "\\";
Expand All @@ -959,7 +970,7 @@ export default class Parser {
return firstCallback.call(this, value, indices.length);
}
let node;
const current = this.currToken;
const current = wordStartToken;
const sourceIndex = current[TOKEN.START_POS] + indices[i];
const source = getSource(current[1], current[2] + ind, current[3], current[2] + (index - 1));
if (~hasClass.indexOf(ind)) {
Expand Down
Loading