Skip to content

Commit

Permalink
feat(vue): revert css match (#3528)
Browse files Browse the repository at this point in the history
* feat(vue): revert css match

* feat(vue): block PseudoClassSelector dynamic
  • Loading branch information
zealotchen0 authored Sep 25, 2023
1 parent 19b99ac commit c797576
Showing 1 changed file with 17 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class PseudoClassSelector extends SimpleSelector {
super();
this.specificity = 0x00000100;
this.rarity = 0;
this.dynamic = true;
this.dynamic = false;
this.cssPseudoClass = cssPseudoClass;
}

Expand Down Expand Up @@ -457,48 +457,33 @@ class SiblingGroup {
class Selector extends SelectorCore {
constructor(selectors) {
super();
const supportedCombinator = [undefined, ' ', '>', '+', '~'];
let siblingGroup = [];
let lastGroup = [];
const supportedCombinator = [undefined, ' ', '>', '+'];
let siblingGroup;
let lastGroup;
const groups = [];
const selectorList = [...selectors];
const length = selectorList.length - 1;
this.specificity = 0;
this.dynamic = false;

for (let i = length; i >= 0; i--) {
const sel = selectorList[i];
selectors.reverse().forEach((sel) => {
if (supportedCombinator.indexOf(sel.combinator) === -1) {
console.error(`Unsupported combinator "${sel.combinator}".`);
throw new Error(`Unsupported combinator "${sel.combinator}".`);
}

if (sel.combinator === undefined || sel.combinator === ' ') {
groups.push(lastGroup = [(siblingGroup = [])]);
groups.push(lastGroup = [siblingGroup = []]);
}
if (sel.combinator === '>') {
lastGroup.push((siblingGroup = []));
}

this.specificity += sel.specificity;

if (sel.dynamic) {
this.dynamic = true;
lastGroup.push(siblingGroup = []);
}

siblingGroup.push(sel);
}

this.groups = groups.map(g => new ChildGroup(g.map(sg => new SiblingGroup(sg))));
this.last = selectorList[length];
});
this.groups = groups.map(g => new Selector.ChildGroup(g.map(sg => new Selector.SiblingGroup(sg))));
this.last = selectors[0];
this.specificity = selectors.reduce((sum, sel) => sel.specificity + sum, 0);
this.dynamic = selectors.some(sel => sel.dynamic);
}

toString() {
return this.selectors.join('');
}

match(node) {
if (!node) return false;
return this.groups.every((group, i) => {
if (i === 0) {
node = group.match(node);
Expand Down Expand Up @@ -547,7 +532,7 @@ class Selector extends SelectorCore {
return false;
});

// Calculating the right bounds for each selector won't save much
// Calculating the right bounds for each selectors won't save much
if (!mayMatch) {
return false;
}
Expand All @@ -562,12 +547,12 @@ class Selector extends SelectorCore {
continue;
}
const bound = bounds[i];
let node = bound.left;
let leftBound = bound.left;
do {
if (group.mayMatch(node)) {
group.trackChanges(node, map);
if (group.mayMatch(leftBound)) {
group.trackChanges(leftBound, map);
}
} while ((node !== bound.right) && (node = node.parentNode));
} while ((leftBound !== bound.right) && (leftBound = node.parentNode));
}

return mayMatch;
Expand Down

0 comments on commit c797576

Please sign in to comment.