Skip to content

Commit

Permalink
fix: hydrating ident name of complex rules
Browse files Browse the repository at this point in the history
  • Loading branch information
kripod committed Jul 26, 2020
1 parent 6eb6633 commit 958d8a0
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions packages/otion/src/createInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
PSEUDO_CLASS_PRECEDENCE_GROUP_COUNT,
} from "./pseudos";

const MAX_CLASS_NAME_LENGTH = 9;
export const PRECEDENCE_GROUP_COUNT = 72;

function toHyphenLower(match: string): string {
Expand Down Expand Up @@ -119,12 +118,9 @@ export function createInstance(): OtionInstance {
function hydrateScopedSubtree(cssRule: CSSRule): void {
if (cssRule.type === 1 /* CSSRule.STYLE_RULE */) {
const { selectorText } = cssRule as CSSStyleRule;
const index = selectorText.indexOf(".", 2);
ruleIndexesByIdentName.set(
// Remove leading `.` from class selector
selectorText.slice(1, index < 0 ? MAX_CLASS_NAME_LENGTH : index),
ruleIndexesByIdentName.size,
);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const identName = /[0-9a-z]/.exec(selectorText.slice(2 /* "._" */))![0];
ruleIndexesByIdentName.set(identName, ruleIndexesByIdentName.size);
} else {
hydrateScopedSubtree((cssRule as CSSGroupingRule).cssRules[0]);
}
Expand Down

0 comments on commit 958d8a0

Please sign in to comment.