[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
+5 -2
View File
@@ -15,13 +15,16 @@ export function processSheet(str: string): string {
function generateSelector(stackIndex: number, parentSelector?: string) {
const parts: string[] = [];
for (const selector of selectorStack[stackIndex]) {
let part = parentSelector && parentSelector + ' ' + selector || selector;
let part = (parentSelector && parentSelector + " " + selector) || selector;
if (part.includes("&")) {
part = selector.replace(/&/g, parentSelector || "");
}
if (stackIndex < selectorStack.length - 1) {
part = generateSelector(stackIndex + 1, part);
}
parts.push(part);
}
return parts.join(', ');
return parts.join(", ");
}
function generateRules() {
if (rules.length) {