Skip to content

Commit

Permalink
chore: add comments and ssome small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Jun 7, 2024
1 parent 7fec90a commit 23e9193
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,15 @@ function _scopePathMatchesParentScopes(scopePath: ScopeStack | null, parentScope
return true;
}

// Starting with the deepest parent scope, look for a match in the scope path.
for (let index = 0; index < parentScopes.length; index++) {
let scopePattern = parentScopes[index];
let scopeMustMatch = false;

// Check for a child combinator (a parent-child relationship)
if (scopePattern === '>') {
if (index === parentScopes.length - 1) {
// Invalid use of child combinator
return false;
}
scopePattern = parentScopes[++index];
Expand All @@ -184,12 +186,14 @@ function _scopePathMatchesParentScopes(scopePath: ScopeStack | null, parentScope
break;
}
if (scopeMustMatch) {
// If a child combinator was used, the parent scope must match.
return false;
}
scopePath = scopePath.parent
scopePath = scopePath.parent;
}

if (!scopePath) {
// No more potential matches
return false;
}
scopePath = scopePath.parent;
Expand Down Expand Up @@ -550,11 +554,11 @@ export class ThemeTrieElement {
// When sorting by scope name specificity, it's safe to treat a longer parent
// scope as more specific. If both rules' parent scopes match a given scope
// path, the longer parent scope will always be more specific.
const parentScopeLengthDelta =
const parentScopeLengthDiff =
b.parentScopes[bParentIndex].length - a.parentScopes[aParentIndex].length;

if (parentScopeLengthDelta !== 0) {
return parentScopeLengthDelta;
if (parentScopeLengthDiff !== 0) {
return parentScopeLengthDiff;
}

aParentIndex++;
Expand Down

0 comments on commit 23e9193

Please sign in to comment.