Skip to content

Commit 40fb434

Browse files
committed
fix: rendering nested selectors with combinators, closes #27
1 parent 6bfaa90 commit 40fb434

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"build": "rm -Rf dist && tsc -p tsconfig.json && tsc -p tsconfig.mjs.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json && echo '{\"type\": \"module\"}' > dist/mjs/package.json",
6666
"build:docs": "rm -Rf docs && typedoc --excludeInternal --excludeExternals --disableSources --plugin typedoc-plugin-markdown --entryDocument ../README.md --out docs src/index.ts && ts-node tools/cleanup-docs.ts",
6767
"test": "jest test",
68+
"test:watch": "jest --watch test",
6869
"test:dist": "TEST_DIST=cjs npm run test",
6970
"lint": "eslint src/**.ts",
7071
"lint:fix": "eslint --fix src/**.ts",

src/render.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ export function render(entity: AstSelector | AstRule): string {
5454
}
5555
if (entity.type === 'Rule') {
5656
let result = '';
57-
const {tag, ids, classNames, attributes, pseudoClasses, pseudoElement, nestedRule} = entity;
57+
const {tag, ids, classNames, attributes, pseudoClasses, pseudoElement, combinator, nestedRule} = entity;
58+
if (combinator) {
59+
result += `${combinator} `;
60+
}
5861
if (tag) {
5962
const namespace = tag.namespace;
6063
if (namespace) {
@@ -129,9 +132,6 @@ export function render(entity: AstSelector | AstRule): string {
129132
result += `::${escapeIdentifier(pseudoElement)}`;
130133
}
131134
if (nestedRule) {
132-
if (nestedRule.combinator) {
133-
result += ` ${nestedRule.combinator}`;
134-
}
135135
result += ` ${render(nestedRule)}`;
136136
}
137137
return result;

test/render.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const testCases = {
4646
'tag1:has(.class)': 'tag1:has(.class)',
4747
'tag1:has(.class,.class2)': 'tag1:has(.class, .class2)',
4848
'tag1:has(.class:has(.subcls),.class2)': 'tag1:has(.class:has(.subcls), .class2)',
49+
'tag1:has(> div)': 'tag1:has(> div)',
4950
'tag1:current(.class:has(.subcls),.class2)': 'tag1:current(.class:has(.subcls), .class2)',
5051
'tag1:current': 'tag1:current',
5152
'*': '*',

0 commit comments

Comments
 (0)