Skip to content

Commit 831682e

Browse files
committed
at-rule validation and selector #47
1 parent 12c6cf8 commit 831682e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+9833
-3438
lines changed

dist/index-umd-web.js

Lines changed: 3202 additions & 1423 deletions
Large diffs are not rendered by default.

dist/index.cjs

Lines changed: 3202 additions & 1423 deletions
Large diffs are not rendered by default.

dist/index.d.ts

Lines changed: 114 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -38,59 +38,66 @@ declare enum EnumToken {
3838
WhitespaceTokenType = 36,
3939
IncludeMatchTokenType = 37,
4040
DashMatchTokenType = 38,
41-
LtTokenType = 39,
42-
LteTokenType = 40,
43-
GtTokenType = 41,
44-
GteTokenType = 42,
45-
PseudoClassTokenType = 43,
46-
PseudoClassFuncTokenType = 44,
47-
DelimTokenType = 45,
48-
UrlTokenTokenType = 46,
49-
EOFTokenType = 47,
50-
ImportantTokenType = 48,
51-
ColorTokenType = 49,
52-
AttrTokenType = 50,
53-
BadCommentTokenType = 51,
54-
BadCdoTokenType = 52,
55-
BadUrlTokenType = 53,
56-
BadStringTokenType = 54,
57-
BinaryExpressionTokenType = 55,
58-
UnaryExpressionTokenType = 56,
59-
FlexTokenType = 57,
60-
ListToken = 58,
61-
Add = 59,
62-
Mul = 60,
63-
Div = 61,
64-
Sub = 62,
65-
ColumnCombinatorTokenType = 63,
66-
ContainMatchTokenType = 64,
67-
StartMatchTokenType = 65,
68-
EndMatchTokenType = 66,
69-
MatchExpressionTokenType = 67,
70-
NameSpaceAttributeTokenType = 68,
71-
FractionTokenType = 69,
72-
IdenListTokenType = 70,
73-
GridTemplateFuncTokenType = 71,
74-
KeyFrameRuleNodeType = 72,
75-
ClassSelectorTokenType = 73,
76-
UniversalSelectorTokenType = 74,
77-
ChildCombinatorTokenType = 75,
78-
DescendantCombinatorTokenType = 76,// whitespace
79-
NextSiblingCombinatorTokenType = 77,
80-
SubsequentSiblingCombinatorTokenType = 78,
81-
NestingSelectorTokenType = 79,
82-
InvalidRuleTokenType = 80,
83-
InvalidClassSelectorTokenType = 81,
84-
InvalidAttrTokenType = 82,
85-
InvalidAtRuleTokenType = 83,
86-
MediaQueryConditionTokenType = 84,
41+
EqualMatchTokenType = 39,
42+
LtTokenType = 40,
43+
LteTokenType = 41,
44+
GtTokenType = 42,
45+
GteTokenType = 43,
46+
PseudoClassTokenType = 44,
47+
PseudoClassFuncTokenType = 45,
48+
DelimTokenType = 46,
49+
UrlTokenTokenType = 47,
50+
EOFTokenType = 48,
51+
ImportantTokenType = 49,
52+
ColorTokenType = 50,
53+
AttrTokenType = 51,
54+
BadCommentTokenType = 52,
55+
BadCdoTokenType = 53,
56+
BadUrlTokenType = 54,
57+
BadStringTokenType = 55,
58+
BinaryExpressionTokenType = 56,
59+
UnaryExpressionTokenType = 57,
60+
FlexTokenType = 58,
61+
ListToken = 59,
62+
Add = 60,
63+
Mul = 61,
64+
Div = 62,
65+
Sub = 63,
66+
ColumnCombinatorTokenType = 64,
67+
ContainMatchTokenType = 65,
68+
StartMatchTokenType = 66,
69+
EndMatchTokenType = 67,
70+
MatchExpressionTokenType = 68,
71+
NameSpaceAttributeTokenType = 69,
72+
FractionTokenType = 70,
73+
IdenListTokenType = 71,
74+
GridTemplateFuncTokenType = 72,
75+
KeyFrameRuleNodeType = 73,
76+
ClassSelectorTokenType = 74,
77+
UniversalSelectorTokenType = 75,
78+
ChildCombinatorTokenType = 76,// >
79+
DescendantCombinatorTokenType = 77,// whitespace
80+
NextSiblingCombinatorTokenType = 78,// +
81+
SubsequentSiblingCombinatorTokenType = 79,// ~
82+
NestingSelectorTokenType = 80,// &
83+
InvalidRuleTokenType = 81,
84+
InvalidClassSelectorTokenType = 82,
85+
InvalidAttrTokenType = 83,
86+
InvalidAtRuleTokenType = 84,
87+
MediaQueryConditionTokenType = 85,
88+
MediaFeatureTokenType = 86,
89+
MediaFeatureOnlyTokenType = 87,
90+
MediaFeatureNotTokenType = 88,
91+
MediaFeatureAndTokenType = 89,
92+
MediaFeatureOrTokenType = 90,
93+
PseudoPageTokenType = 91,
8794
Time = 25,
8895
Iden = 7,
89-
EOF = 47,
96+
EOF = 48,
9097
Hash = 28,
91-
Flex = 57,
98+
Flex = 58,
9299
Angle = 24,
93-
Color = 49,
100+
Color = 50,
94101
Comma = 9,
95102
String = 20,
96103
Length = 23,
@@ -103,9 +110,9 @@ declare enum EnumToken {
103110
Frequency = 26,
104111
Resolution = 27,
105112
Whitespace = 36,
106-
IdenList = 70,
113+
IdenList = 71,
107114
DashedIden = 8,
108-
GridTemplateFunc = 71,
115+
GridTemplateFunc = 72,
109116
ImageFunc = 19,
110117
CommentNodeType = 0,
111118
CDOCOMMNodeType = 1,
@@ -126,7 +133,7 @@ declare function walkValues(values: Token[], root?: AstNode | Token | null, filt
126133
event: WalkerValueEvent$1;
127134
fn?: WalkerValueFilter;
128135
type?: EnumToken | EnumToken[] | ((token: Token) => boolean);
129-
}): Generator<WalkAttributesResult>;
136+
}, reverse?: boolean): Generator<WalkAttributesResult>;
130137

131138
declare function expand(ast: AstNode): AstNode;
132139

@@ -412,6 +419,12 @@ export declare interface DashMatchToken extends BaseToken {
412419
// val: '|=';
413420
}
414421

422+
export declare interface EqualMatchToken extends BaseToken {
423+
424+
typ: EnumToken.EqualMatchTokenType;
425+
// val: '|=';
426+
}
427+
415428
export declare interface StartMatchToken extends BaseToken {
416429

417430
typ: EnumToken.StartMatchTokenType;
@@ -461,6 +474,12 @@ export declare interface PseudoClassToken extends BaseToken {
461474
val: string;
462475
}
463476

477+
export declare interface PseudoPageToken extends BaseToken {
478+
479+
typ: EnumToken.PseudoPageTokenType;
480+
val: string;
481+
}
482+
464483
export declare interface PseudoClassFunctionToken extends BaseToken {
465484

466485
typ: EnumToken.PseudoClassFuncTokenType;
@@ -542,11 +561,45 @@ export declare interface ChildCombinatorToken extends BaseToken {
542561
typ: EnumToken.ChildCombinatorTokenType
543562
}
544563

564+
export declare interface MediaFeatureToken extends BaseToken {
565+
566+
typ: EnumToken.MediaFeatureTokenType,
567+
val: string;
568+
}
569+
570+
export declare interface MediaFeatureOnlyToken extends BaseToken {
571+
572+
typ: EnumToken.MediaFeatureOnlyTokenType,
573+
val: Token;
574+
}
575+
576+
export declare interface MediaFeatureNotToken extends BaseToken {
577+
578+
typ: EnumToken.MediaFeatureNotTokenType,
579+
val: Token;
580+
}
581+
582+
export declare interface MediaFeatureNotToken extends BaseToken {
583+
584+
typ: EnumToken.MediaFeatureNotTokenType,
585+
val: Token;
586+
}
587+
588+
export declare interface MediaFeatureAndToken extends BaseToken {
589+
590+
typ: EnumToken.MediaFeatureAndTokenType;
591+
}
592+
593+
export declare interface MediaFeatureOrToken extends BaseToken {
594+
595+
typ: EnumToken.MediaFeatureOrTokenType;
596+
}
597+
545598
export declare interface MediaQueryConditionToken extends BaseToken {
546599

547600
typ: EnumToken.MediaQueryConditionTokenType,
548601
l: Token,
549-
op: EnumToken.GtTokenType | EnumToken.LtTokenType | EnumToken.GteTokenType | EnumToken.LteTokenType,
602+
op: ColonToken | GreaterThanToken | LessThanToken | GreaterThanOrEqualToken | LessThanOrEqualToken,
550603
r: Token[]
551604
}
552605

@@ -610,7 +663,7 @@ export declare interface BinaryExpressionToken extends BaseToken {
610663
export declare interface MatchExpressionToken extends BaseToken {
611664

612665
typ: EnumToken.MatchExpressionTokenType
613-
op: DelimToken | DashMatchToken | StartMatchToken | ContainMatchToken | EndMatchToken | IncludeMatchToken;
666+
op: EqualMatchToken | DashMatchToken | StartMatchToken | ContainMatchToken | EndMatchToken | IncludeMatchToken;
614667
l: Token;
615668
r: Token;
616669
attr?: 'i' | 's';
@@ -662,6 +715,11 @@ export declare type Token =
662715
| NestingSelectorToken
663716
|
664717
MediaQueryConditionToken
718+
| MediaFeatureToken
719+
| MediaFeatureNotToken
720+
| MediaFeatureOnlyToken
721+
| MediaFeatureAndToken
722+
| MediaFeatureOrToken
665723
| AstDeclaration
666724
|
667725
NumberToken
@@ -708,13 +766,15 @@ export declare type Token =
708766
| NameSpaceAttributeToken
709767
|
710768
DashMatchToken
769+
| EqualMatchToken
711770
| LessThanToken
712771
| LessThanOrEqualToken
713772
| GreaterThanToken
714773
| GreaterThanOrEqualToken
715774
|
716775
ListToken
717776
| PseudoClassToken
777+
| PseudoPageToken
718778
| PseudoClassFunctionToken
719779
| DelimToken
720780
| BinaryExpressionToken

dist/lib/ast/expand.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,6 @@ function expandRule(node, parent) {
143143
}
144144
}
145145
}
146-
// if (selectors.length == 2){
147-
// console.error(matchSelectors([[selectors[0]]], [[selectors[1]]]));
148-
// }
149-
// console.error({selectors: selectors.reduce((a: string[][], curr: string[][]) => , [] as string[][])});
150146
rule.sel = selectors.reduce((acc, curr) => curr.length == 0 ? acc : acc + (acc.length > 0 ? ',' : '') + curr, '');
151147
}
152148
ast.chi.splice(i--, 1);
@@ -201,9 +197,6 @@ function expandRule(node, parent) {
201197
function replaceCompound(input, replace) {
202198
const tokens = parseString(input);
203199
let replacement = null;
204-
//parseString(replace);
205-
// console.error({ tokens, replace, input});
206-
// console.error(new Error('bar bar'));
207200
for (const t of walkValues(tokens)) {
208201
if (t.value.typ == EnumToken.LiteralTokenType) {
209202
if (t.value.val == '&') {
@@ -221,7 +214,6 @@ function replaceCompound(input, replace) {
221214
continue;
222215
}
223216
const rule = splitRule(replace);
224-
// console.error({rule});
225217
t.value.val = rule.length > 1 ? ':is(' + replace + ')' : replace;
226218
}
227219
else if (t.value.val.length > 1 && t.value.val.charAt(0) == '&') {

dist/lib/ast/features/calc.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { EnumToken } from '../types.js';
22
import { walkValues, WalkerValueEvent } from '../walk.js';
33
import { evaluate } from '../math/expression.js';
4-
import { mathFuncs } from '../../renderer/color/utils/constants.js';
5-
import '../minify.js';
6-
import '../../parser/parse.js';
74
import { renderToken } from '../../renderer/render.js';
8-
import '../../parser/utils/config.js';
5+
import { mathFuncs } from '../../syntax/syntax.js';
96

107
class ComputeCalcExpressionFeature {
118
static get ordering() {

dist/lib/ast/features/prefix.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import '../../parser/parse.js';
88
import '../../renderer/color/utils/constants.js';
99
import '../../renderer/sourcemap/lib/encode.js';
1010
import '../../parser/utils/config.js';
11+
import '../../validation/syntaxes/complex-selector.js';
1112

1213
const config = getSyntaxConfig();
1314
class ComputePrefixFeature {
@@ -94,6 +95,13 @@ function matchToken(token, matches) {
9495
}
9596
break;
9697
case ValidationTokenEnum.PipeToken:
98+
for (let j = 0; j < matches[i].chi.length; j++) {
99+
result = matchToken(token, matches[i].chi[j]);
100+
if (result != null) {
101+
return result;
102+
}
103+
}
104+
break;
97105
case ValidationTokenEnum.ColumnToken:
98106
case ValidationTokenEnum.AmpersandToken:
99107
result = matchToken(token, matches[i].l);

dist/lib/ast/math/expression.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { EnumToken } from '../types.js';
22
import { compute, rem } from './math.js';
33
import { reduceNumber } from '../../renderer/render.js';
4-
import { mathFuncs } from '../../renderer/color/utils/constants.js';
5-
import '../minify.js';
6-
import '../walk.js';
7-
import '../../parser/parse.js';
8-
import '../../parser/utils/config.js';
4+
import { mathFuncs } from '../../syntax/syntax.js';
95

106
/**
117
* evaluate an array of tokens

dist/lib/ast/minify.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { walkValues } from './walk.js';
44
import { replaceCompound } from './expand.js';
55
import { isWhiteSpace, isIdent, isFunction, isIdentStart } from '../syntax/syntax.js';
66
import '../parser/utils/config.js';
7-
import '../renderer/color/utils/constants.js';
87
import { eq } from '../parser/utils/eq.js';
98
import { renderToken, doRender } from '../renderer/render.js';
109
import * as index from './features/index.js';

0 commit comments

Comments
 (0)