Skip to content

Commit 9c7ba24

Browse files
committed
Update docs for descendant combinators.
1 parent 2a00f62 commit 9c7ba24

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

API.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,13 @@ no semantic meaning:
308308
h1 , h2 {}
309309
```
310310

311-
However, *combinating* spaces will form a `combinator` node:
311+
For descendent selectors, the value is always a single space.
312312

313313
```css
314314
h1 h2 {}
315315
```
316316

317-
A `combinator` node may only have the `spaces` property set if the combinator
318-
value is a non-whitespace character, such as `+`, `~` or `>`. Otherwise, the
319-
combinator value will contain all of the spaces between selectors.
317+
Additional whitespace is found in either the `node.spaces.before` and `node.spaces.after` depending on the presence of comments or other whitespace characters. If the actual whitespace does not start or end with a single space, the node's raw value is set to the actual space(s) found in the source.
320318

321319
### `node.source`
322320

@@ -587,7 +585,7 @@ support parsing of legacy CSS hacks.
587585

588586
## Selector nodes
589587

590-
A selector node represents a single compound selector. For example, this
588+
A selector node represents a single complex selector. For example, this
591589
selector string `h1 h2 h3, [href] > p`, is represented as two selector nodes.
592590
It has no special functionality of its own.
593591

src/__tests__/combinators.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ test('ending in comment has no trailing combinator', ".bar /* comment 3 */", (t,
128128
let nodeTypes = tree.nodes[0].map(n => n.type);
129129
t.deepEqual(nodeTypes, ["class"]);
130130
});
131+
test('The combinating space is not a space character', ".bar\n.baz", (t, tree) => {
132+
let nodeTypes = tree.nodes[0].map(n => n.type);
133+
t.deepEqual(nodeTypes, ["class", "combinator", "class"]);
134+
t.deepEqual(tree.nodes[0].nodes[1].value, ' ', 'should have a combinator');
135+
t.deepEqual(tree.nodes[0].nodes[1].raws.value, '\n', 'should have a raw combinator value');
136+
});
131137
test('with spaces and a comment has only one combinator', ".bar /* comment 3 */ > .foo", (t, tree) => {
132138
let nodeTypes = tree.nodes[0].map(n => n.type);
133139
t.deepEqual(nodeTypes, ["class", "combinator", "class"]);

0 commit comments

Comments
 (0)