Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

Commit edfbcc1

Browse files
committed
'>>>' and '/deep/' no longer share a token
This allows csslib to preserve the original combinator choice when printing an AST.
1 parent 5b15917 commit edfbcc1

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

lib/parser.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ class _Parser {
12481248
_eat(TokenKind.GREATER);
12491249
if (_maybeEat(TokenKind.GREATER)) {
12501250
_eat(TokenKind.GREATER);
1251-
combinatorType = TokenKind.COMBINATOR_DEEP;
1251+
combinatorType = TokenKind.COMBINATOR_SHADOW_PIERCING_DESCENDANT;
12521252
} else {
12531253
combinatorType = TokenKind.COMBINATOR_GREATER;
12541254
}

lib/src/tokenkind.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ class TokenKind {
100100
static const int COMBINATOR_PLUS = 515; // + combinator
101101
static const int COMBINATOR_GREATER = 516; // > combinator
102102
static const int COMBINATOR_TILDE = 517; // ~ combinator
103-
static const int COMBINATOR_DEEP = 518; // /deep/ or >>> combinator
103+
static const int COMBINATOR_SHADOW_PIERCING_DESCENDANT = 518; // >>>
104+
static const int COMBINATOR_DEEP = 519; // /deep/ (aliases >>>)
104105

105-
static const int UNARY_OP_NONE = 519; // No unary operator present.
106+
static const int UNARY_OP_NONE = 520; // No unary operator present.
106107

107108
// Attribute match types:
108109
static const int INCLUDES = 530; // '~='

lib/src/tree.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,15 @@ class SimpleSelectorSequence extends TreeNode {
121121
bool get isCombinatorDescendant =>
122122
combinator == TokenKind.COMBINATOR_DESCENDANT;
123123
bool get isCombinatorDeep => combinator == TokenKind.COMBINATOR_DEEP;
124+
bool get isCombinatorShadowPiercingDescendant =>
125+
combinator == TokenKind.COMBINATOR_SHADOW_PIERCING_DESCENDANT;
124126

125127
String get _combinatorToString {
126128
switch (combinator) {
127-
case TokenKind.COMBINATOR_DEEP:
129+
case TokenKind.COMBINATOR_SHADOW_PIERCING_DESCENDANT:
128130
return ' >>> ';
131+
case TokenKind.COMBINATOR_DEEP:
132+
return ' /deep/ ';
129133
case TokenKind.COMBINATOR_DESCENDANT:
130134
return ' ';
131135
case TokenKind.COMBINATOR_GREATER:

lib/src/tree_printer.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,10 @@ class _TreePrinter extends Visitor {
271271
output.writeValue('combinator', ">");
272272
} else if (node.isCombinatorTilde) {
273273
output.writeValue('combinator', "~");
274-
} else if (node.isCombinatorDeep) {
274+
} else if (node.isCombinatorShadowPiercingDescendant) {
275275
output.writeValue('combinator', '>>>');
276+
} else if (node.isCombinatorDeep) {
277+
output.writeValue('combinator', '/deep/');
276278
} else {
277279
output.writeValue('combinator', "ERROR UNKNOWN");
278280
}

test/selector_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void testSelectorSuccesses() {
6161

6262
selectorAst = selector('.a /deep/ .b', errors: errors..clear());
6363
expect(errors.isEmpty, true, reason: errors.toString());
64-
expect(compactOuptut(selectorAst), '.a >>> .b');
64+
expect(compactOuptut(selectorAst), '.a /deep/ .b');
6565

6666
selectorAst = selector('.x >>> .y', errors: errors..clear());
6767
expect(errors.isEmpty, true, reason: errors.toString());

0 commit comments

Comments
 (0)