Skip to content

Commit c0aee08

Browse files
committed
add missing files #47
1 parent 831682e commit c0aee08

24 files changed

+1907
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { ValidationLevel, EnumToken } from '../../ast/types.js';
2+
import '../../ast/minify.js';
3+
import '../../ast/walk.js';
4+
import '../../parser/parse.js';
5+
import '../../renderer/color/utils/constants.js';
6+
import '../../renderer/sourcemap/lib/encode.js';
7+
import '../../parser/utils/config.js';
8+
9+
function validateAtRuleCounterStyle(atRule, options, root) {
10+
// media-query-list
11+
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
12+
return {
13+
valid: ValidationLevel.Drop,
14+
matches: [],
15+
node: atRule,
16+
syntax: '@counter-style',
17+
error: 'expected media query list',
18+
tokens: []
19+
};
20+
}
21+
const tokens = atRule.tokens.filter((t) => ![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType].includes(t.typ));
22+
if (tokens.length == 0) {
23+
return {
24+
valid: ValidationLevel.Valid,
25+
matches: [],
26+
node: atRule,
27+
syntax: '@counter-style',
28+
error: 'expected counter style name',
29+
tokens
30+
};
31+
}
32+
if (tokens.length > 1) {
33+
return {
34+
valid: ValidationLevel.Drop,
35+
matches: [],
36+
node: tokens[1] ?? atRule,
37+
syntax: '@counter-style',
38+
error: 'unexpected token',
39+
tokens
40+
};
41+
}
42+
if (![EnumToken.IdenTokenType, EnumToken.DashedIdenTokenType].includes(tokens[0].typ)) {
43+
return {
44+
valid: ValidationLevel.Drop,
45+
matches: [],
46+
node: tokens[0],
47+
syntax: '@counter-style',
48+
error: 'expected counter style name',
49+
tokens
50+
};
51+
}
52+
if (!('chi' in atRule)) {
53+
return {
54+
valid: ValidationLevel.Drop,
55+
matches: [],
56+
node: atRule,
57+
syntax: '@counter-style',
58+
error: 'expected counter style body',
59+
tokens
60+
};
61+
}
62+
return {
63+
valid: ValidationLevel.Valid,
64+
matches: [],
65+
node: atRule,
66+
syntax: '@counter-style',
67+
error: '',
68+
tokens
69+
};
70+
}
71+
72+
export { validateAtRuleCounterStyle };
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { ValidationLevel, EnumToken } from '../../ast/types.js';
2+
import '../../ast/minify.js';
3+
import '../../ast/walk.js';
4+
import '../../parser/parse.js';
5+
import '../../renderer/color/utils/constants.js';
6+
import '../../renderer/sourcemap/lib/encode.js';
7+
import '../../parser/utils/config.js';
8+
import { consumeWhitespace } from '../utils/whitespace.js';
9+
import { validateURL } from '../syntaxes/url.js';
10+
11+
function validateAtRuleDocument(atRule, options, root) {
12+
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
13+
return {
14+
valid: ValidationLevel.Drop,
15+
matches: [],
16+
node: atRule,
17+
syntax: '@document',
18+
error: 'expecting at-rule prelude',
19+
tokens: []
20+
};
21+
}
22+
const tokens = atRule.tokens.slice();
23+
let result = null;
24+
consumeWhitespace(tokens);
25+
if (tokens.length == 0) {
26+
return {
27+
valid: ValidationLevel.Drop,
28+
matches: [],
29+
node: atRule,
30+
syntax: '@document',
31+
error: 'expecting at-rule prelude',
32+
tokens
33+
};
34+
}
35+
if (tokens[0].typ == EnumToken.CommaTokenType) {
36+
return {
37+
valid: ValidationLevel.Drop,
38+
matches: [],
39+
node: tokens[0],
40+
syntax: '@document',
41+
error: 'unexpected token',
42+
tokens
43+
};
44+
}
45+
while (tokens.length > 0) {
46+
if (tokens[0].typ == EnumToken.CommentTokenType) {
47+
tokens.shift();
48+
consumeWhitespace(tokens);
49+
}
50+
result = validateURL(tokens[0]);
51+
if (result.valid == ValidationLevel.Valid) {
52+
tokens.shift();
53+
consumeWhitespace(tokens);
54+
continue;
55+
}
56+
if (tokens[0].typ == EnumToken.FunctionTokenType) {
57+
if (!['url-prefix', 'domain', 'media-document', 'regexp'].some((t) => t.localeCompare(tokens[0].val, undefined, { sensitivity: 'base' }) == 0)) {
58+
return {
59+
valid: ValidationLevel.Drop,
60+
matches: [],
61+
node: tokens[0],
62+
syntax: '@document',
63+
error: 'unexpected token',
64+
tokens
65+
};
66+
}
67+
const children = tokens[0].chi.slice();
68+
consumeWhitespace(children);
69+
if (children.length == 0) {
70+
return {
71+
valid: ValidationLevel.Drop,
72+
matches: [],
73+
node: tokens[0],
74+
syntax: '@document',
75+
error: 'expecting string argument',
76+
tokens
77+
};
78+
}
79+
if (children[0].typ == EnumToken.StringTokenType) {
80+
children.shift();
81+
consumeWhitespace(children);
82+
}
83+
if (children.length > 0) {
84+
return {
85+
valid: ValidationLevel.Drop,
86+
matches: [],
87+
node: children[0],
88+
syntax: '@document',
89+
error: 'unexpected token',
90+
tokens
91+
};
92+
}
93+
tokens.shift();
94+
consumeWhitespace(tokens);
95+
}
96+
}
97+
return {
98+
valid: ValidationLevel.Valid,
99+
matches: [],
100+
node: atRule,
101+
syntax: '@document',
102+
error: '',
103+
tokens
104+
};
105+
}
106+
107+
export { validateAtRuleDocument };
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { ValidationLevel } from '../../ast/types.js';
2+
import '../../ast/minify.js';
3+
import '../../ast/walk.js';
4+
import '../../parser/parse.js';
5+
import '../../renderer/color/utils/constants.js';
6+
import '../../renderer/sourcemap/lib/encode.js';
7+
import '../../parser/utils/config.js';
8+
import { validateFamilyName } from '../syntaxes/family-name.js';
9+
import '../syntaxes/complex-selector.js';
10+
11+
function validateAtRuleFontFeatureValues(atRule, options, root) {
12+
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
13+
return {
14+
valid: ValidationLevel.Drop,
15+
matches: [],
16+
node: null,
17+
syntax: '@' + atRule.nam,
18+
error: 'expected at-rule prelude',
19+
tokens: []
20+
};
21+
}
22+
const result = validateFamilyName(atRule.tokens, atRule);
23+
if (result.valid == ValidationLevel.Drop) {
24+
return result;
25+
}
26+
if (!('chi' in atRule)) {
27+
return {
28+
valid: ValidationLevel.Drop,
29+
matches: [],
30+
node: atRule,
31+
syntax: '@' + atRule.nam,
32+
error: 'expected at-rule body',
33+
tokens: []
34+
};
35+
}
36+
return {
37+
valid: ValidationLevel.Valid,
38+
matches: [],
39+
node: atRule,
40+
syntax: '@' + atRule.nam,
41+
error: '',
42+
tokens: []
43+
};
44+
}
45+
46+
export { validateAtRuleFontFeatureValues };

0 commit comments

Comments
 (0)