[IMP] styles: handle & selector

This commit adds the support of the & selector.
This selector is useful to join a subrule with a parent selector.

example:

button {
  &:hover {
    background-color: red;
  }
}

will give

button:hover {
  background-color: red;
}
This commit is contained in:
mcm-odoo
2020-01-09 09:35:48 +01:00
committed by Géry Debongnie
parent 4a0d04e4ae
commit 74bd119bf5
3 changed files with 76 additions and 2 deletions
+25
View File
@@ -142,4 +142,29 @@ describe("styles and component", () => {
color: red;
}`);
});
test("handle & selector", async () => {
let sheet = processSheet(`.btn {
&.danger {
color: red;
}
}`);
expect(sheet).toBe(`.btn.danger {
color: red;
}`);
sheet = processSheet(`.some-class {
&.btn {
.other-class ~ & {
color: red;
}
}
}`);
expect(sheet).toBe(`.other-class ~ .some-class.btn {
color: red;
}`);
});
});