Skip to content

Commit

Permalink
incorrectly expand nesting rules #38
Browse files Browse the repository at this point in the history
  • Loading branch information
tbela99 committed Jul 5, 2024
1 parent 75cbc4e commit accfe69
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## V0.5.4

- [x] incorrectly expand css nesting rules

## V0.5.3

- [x] incorrectly expand css nesting rules
Expand Down
16 changes: 11 additions & 5 deletions dist/index-umd-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -7201,11 +7201,17 @@
const rule = ast.chi[i];
if (!rule.sel.includes('&')) {
const selRule = splitRule(rule.sel);
selRule.forEach(arr => combinators.includes(arr[0].charAt(0)) ? arr.unshift(ast.sel) : arr.unshift(ast.sel, ' '));
rule.sel = selRule.reduce((acc, curr) => {
acc.push(curr.join(''));
return acc;
}, []).join(',');
if (selRule.length > 1) {
const r = ':is(' + selRule.map(a => a.join('')).join(',') + ')';
rule.sel = splitRule(ast.sel).reduce((a, b) => a.concat([b.join('') + r]), []).join(',');
}
else {
selRule.forEach(arr => combinators.includes(arr[0].charAt(0)) ? arr.unshift(ast.sel) : arr.unshift(ast.sel, ' '));
rule.sel = selRule.reduce((acc, curr) => {
acc.push(curr.join(''));
return acc;
}, []).join(',');
}
}
else {
rule.sel = replaceCompound(rule.sel, ast.sel);
Expand Down
16 changes: 11 additions & 5 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7199,11 +7199,17 @@ function expandRule(node) {
const rule = ast.chi[i];
if (!rule.sel.includes('&')) {
const selRule = splitRule(rule.sel);
selRule.forEach(arr => combinators.includes(arr[0].charAt(0)) ? arr.unshift(ast.sel) : arr.unshift(ast.sel, ' '));
rule.sel = selRule.reduce((acc, curr) => {
acc.push(curr.join(''));
return acc;
}, []).join(',');
if (selRule.length > 1) {
const r = ':is(' + selRule.map(a => a.join('')).join(',') + ')';
rule.sel = splitRule(ast.sel).reduce((a, b) => a.concat([b.join('') + r]), []).join(',');
}
else {
selRule.forEach(arr => combinators.includes(arr[0].charAt(0)) ? arr.unshift(ast.sel) : arr.unshift(ast.sel, ' '));
rule.sel = selRule.reduce((acc, curr) => {
acc.push(curr.join(''));
return acc;
}, []).join(',');
}
}
else {
rule.sel = replaceCompound(rule.sel, ast.sel);
Expand Down
16 changes: 11 additions & 5 deletions dist/lib/ast/expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,17 @@ function expandRule(node) {
const rule = ast.chi[i];
if (!rule.sel.includes('&')) {
const selRule = splitRule(rule.sel);
selRule.forEach(arr => combinators.includes(arr[0].charAt(0)) ? arr.unshift(ast.sel) : arr.unshift(ast.sel, ' '));
rule.sel = selRule.reduce((acc, curr) => {
acc.push(curr.join(''));
return acc;
}, []).join(',');
if (selRule.length > 1) {
const r = ':is(' + selRule.map(a => a.join('')).join(',') + ')';
rule.sel = splitRule(ast.sel).reduce((a, b) => a.concat([b.join('') + r]), []).join(',');
}
else {
selRule.forEach(arr => combinators.includes(arr[0].charAt(0)) ? arr.unshift(ast.sel) : arr.unshift(ast.sel, ' '));
rule.sel = selRule.reduce((acc, curr) => {
acc.push(curr.join(''));
return acc;
}, []).join(',');
}
}
else {
rule.sel = replaceCompound(rule.sel, ast.sel);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tbela99/css-parser",
"description": "CSS parser for node and the browser",
"version": "0.5.3",
"version": "0.5.4",
"exports": {
".": "./dist/node/index.js",
"./umd": "./dist/index-umd-web.js",
Expand Down

0 comments on commit accfe69

Please sign in to comment.