Skip to content

Commit

Permalink
feat: precedence management without class repeats
Browse files Browse the repository at this point in the history
  • Loading branch information
kripod committed Jul 21, 2020
1 parent af109c7 commit 16acfbc
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/otion/src/createInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function createInstance(): OtionInstance {
let prefix: (property: string, value: string) => string;
let insertedIdentNames: Set<string>;

const lastRuleIndexesByPrecedenceGroup = new Uint16Array(
const nextRuleIndexesByPrecedenceGroup = new Uint16Array(
PRECEDENCE_GROUP_COUNT,
);

Expand Down Expand Up @@ -212,7 +212,7 @@ export function createInstance(): OtionInstance {
)) ||
1;

const scopeSelector = `.${className}`.repeat(precedence);
const scopeSelector = `.${className}`;
injector.insert(
`${
cssTextHead.slice(0, classSelectorStartIndex) +
Expand All @@ -221,8 +221,13 @@ export function createInstance(): OtionInstance {
? `${cssTextHead.slice(classSelectorStartIndex)}{`
: "{")
}${declarations}}${cssTextTail}`,
insertedIdentNames.size,
nextRuleIndexesByPrecedenceGroup[precedence],
);

for (let i = precedence; i <= PRECEDENCE_GROUP_COUNT; ++i) {
++nextRuleIndexesByPrecedenceGroup[i];
}

insertedIdentNames.add(className);
}

Expand Down

0 comments on commit 16acfbc

Please sign in to comment.