Skip to content

Commit

Permalink
fix: resolve self-references
Browse files Browse the repository at this point in the history
  • Loading branch information
kripod committed Aug 1, 2020
1 parent b532f7a commit f0ba93f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/example-gatsby/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ export default function IndexPage(): JSX.Element {
>
Conditional rule precedence management test #2, should be green
</p>

<div className={css({ selectors: { "& + &": { color: "green" } } })} />
<p className={css({ selectors: { "& + &": { color: "green" } } })}>
Self-referencing selector test, should be green
</p>
</React.StrictMode>
);
}
6 changes: 5 additions & 1 deletion packages/otion/src/createInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ export function createInstance(): OtionInstance {
cssTextHead.slice(0, classSelectorStartIndex) +
scopeSelector +
(classSelectorStartIndex != null
? `${cssTextHead.slice(classSelectorStartIndex)}{`
? `${
cssTextHead
.slice(classSelectorStartIndex)
.replace(/&/g, scopeSelector) // Resolve references
}{`
: "{")
}${declarations}}${cssTextTail}`,
nextRuleIndexesByPrecedenceGroup[precedence],
Expand Down

0 comments on commit f0ba93f

Please sign in to comment.