Skip to content

Commit 752b59f

Browse files
committed
fix validation bug and add missing syntaxes #87
1 parent a35592e commit 752b59f

File tree

13 files changed

+88
-135
lines changed

13 files changed

+88
-135
lines changed

dist/index-umd-web.js

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4295,6 +4295,8 @@
42954295
// https://developer.mozilla.org/en-US/docs/Web/CSS/WebKit_Extensions
42964296
// https://developer.mozilla.org/en-US/docs/Web/CSS/Mozilla_Extensions
42974297
const pseudoAliasMap = {
4298+
'-moz-center': 'center',
4299+
'-webkit-center': 'center',
42984300
'-ms-grid-columns': 'grid-template-columns',
42994301
'-ms-grid-rows': 'grid-template-rows',
43004302
'-ms-grid-row': 'grid-row-start',
@@ -4307,6 +4309,7 @@
43074309
'::-ms-input-placeholder': '::placeholder',
43084310
':-moz-any()': ':is',
43094311
'-moz-user-modify': 'user-modify',
4312+
'-webkit-match-parent': 'match-parent',
43104313
'-moz-background-clip': 'background-clip',
43114314
'-moz-background-origin': 'background-origin',
43124315
'-ms-input-placeholder': 'placeholder',
@@ -4463,6 +4466,7 @@
44634466
'-webkit-min-logical-height',
44644467
'-webkit-min-logical-width',
44654468
'-webkit-nbsp-mode',
4469+
'-webkit-match-parent',
44664470
'-webkit-perspective-origin-x',
44674471
'-webkit-perspective-origin-y',
44684472
'-webkit-rtl-ordering',
@@ -9015,7 +9019,7 @@
90159019
syntax: "auto | fixed"
90169020
},
90179021
"text-align": {
9018-
syntax: "start | end | left | right | center | justify | match-parent"
9022+
syntax: "start | end | left | right | center | justify | match-parent | <-non-standard-text-align>"
90199023
},
90209024
"text-align-last": {
90219025
syntax: "auto | start | end | left | right | center | justify"
@@ -9246,7 +9250,7 @@
92469250
syntax: "auto | grayscale"
92479251
},
92489252
"-moz-user-select": {
9249-
syntax: "none | text | all | -moz-none"
9253+
syntax: "none | text | all | -moz-none | auto | element | elements | text | toggle"
92509254
},
92519255
"-ms-flex-align": {
92529256
syntax: "start | end | center | baseline | stretch"
@@ -11012,6 +11016,9 @@
1101211016
},
1101311017
"inset-area": {
1101411018
syntax: "[ [ left | center | right | span-left | span-right | x-start | x-end | span-x-start | span-x-end | x-self-start | x-self-end | span-x-self-start | span-x-self-end | span-all ] || [ top | center | bottom | span-top | span-bottom | y-start | y-end | span-y-start | span-y-end | y-self-start | y-self-end | span-y-self-start | span-y-self-end | span-all ] | [ block-start | center | block-end | span-block-start | span-block-end | span-all ] || [ inline-start | center | inline-end | span-inline-start | span-inline-end | span-all ] | [ self-block-start | self-block-end | span-self-block-start | span-self-block-end | span-all ] || [ self-inline-start | self-inline-end | span-self-inline-start | span-self-inline-end | span-all ] | [ start | center | end | span-start | span-end | span-all ]{1,2} | [ self-start | center | self-end | span-self-start | span-self-end | span-all ]{1,2} ]"
11019+
},
11020+
"-non-standard-text-align": {
11021+
syntax: "| -moz-center | -webkit-center | -webkit-match-parent"
1101511022
}
1101611023
};
1101711024
var selectors = {
@@ -11835,7 +11842,6 @@
1183511842
let items = [];
1183611843
let match = 0;
1183711844
while ((item = iterator.next()) && !item.done) {
11838-
// console.error(JSON.stringify({match, val: item.value,func}, null, 1));
1183911845
switch (item.value.typ) {
1184011846
case ValidationTokenEnum.OpenParenthesis:
1184111847
if (match > 0) {
@@ -12526,9 +12532,9 @@
1252612532
const type = getTokenType(match[3]);
1252712533
return Object.defineProperty({
1252812534
typ: ValidationTokenEnum.PropertyType,
12529-
val: type.val,
12535+
val: match[1],
1253012536
unit: exports.EnumToken[type.typ],
12531-
range: [+type.val, match[4] == '\u221e' ? Infinity : +match[4]]
12537+
range: [+type.val, match[4] == '\u221e' ? null : +match[4]]
1253212538
}, 'pos', { ...objectProperties, value: pos });
1253312539
}
1253412540
return Object.defineProperty({
@@ -12599,7 +12605,7 @@
1259912605
case ValidationTokenEnum.Bracket:
1260012606
return '[' + token.chi.reduce((acc, curr) => acc + renderSyntax(curr), '') + ']' + renderAttributes(token);
1260112607
case ValidationTokenEnum.PropertyType:
12602-
return '<' + token.val + '>' + renderAttributes(token);
12608+
return '<' + token.val + (Array.isArray(token.range) ? `[${token?.range?.[0]}, ${token?.range?.[1] ?? '\u221e'}]` : '') + '>' + renderAttributes(token);
1260312609
case ValidationTokenEnum.DeclarationType:
1260412610
return "<'" + token.val + "'>" + renderAttributes(token);
1260512611
case ValidationTokenEnum.Number:
@@ -13423,6 +13429,7 @@
1342313429
break;
1342413430
}
1342513431
ast = getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, node.nam);
13432+
// console.error({ast: ast.reduce((acc, curr) => acc + renderSyntax(curr), '')});
1342613433
if (ast != null) {
1342713434
let token = null;
1342813435
const values = node.val.slice();
@@ -13442,6 +13449,7 @@
1344213449
}
1344313450
}
1344413451
result = doEvaluateSyntax(ast, createContext(values), { ...options, visited: new WeakMap() });
13452+
// console.error(JSON.stringify({ast, values, result}, null, 1));
1344513453
if (result.valid == SyntaxValidationResult.Valid && !result.context.done()) {
1344613454
let token = null;
1344713455
while ((token = result.context.next()) != null) {
@@ -13500,8 +13508,6 @@
1350013508
let i = 0;
1350113509
let result;
1350213510
let token = null;
13503-
// console.error(`>> doEvaluateSyntax: ${syntaxes.reduce((acc, curr) => acc + renderSyntax(curr), '')}`, context.peek());
13504-
// console.error(new Error('doEvaluateSyntax'));
1350513511
for (; i < syntaxes.length; i++) {
1350613512
syntax = syntaxes[i];
1350713513
if (context.done()) {
@@ -13511,7 +13517,6 @@
1351113517
break;
1351213518
}
1351313519
token = context.peek();
13514-
// console.error(`>> doEvaluateSyntax: ${ renderSyntax(syntax)}`, context.peek());
1351513520
if (syntax.typ == ValidationTokenEnum.Whitespace) {
1351613521
if (context.peek()?.typ == exports.EnumToken.WhitespaceTokenType) {
1351713522
context.next();
@@ -13545,7 +13550,6 @@
1354513550
clearVisited(token, syntax, 'doEvaluateSyntax', options);
1354613551
}
1354713552
}
13548-
// console.error(`>> doEvaluateSyntax: ${ renderSyntax(syntax)}\nvalid:${result.valid == SyntaxValidationResult.Valid ? 'valid' : 'invalid'}\n`, context.peek());
1354913553
if (result.valid == SyntaxValidationResult.Drop) {
1355013554
if (syntax.isOptional) {
1355113555
continue;
@@ -13554,7 +13558,8 @@
1355413558
}
1355513559
context.update(result.context);
1355613560
}
13557-
return {
13561+
// @ts-ignore
13562+
return result ?? {
1355813563
valid: SyntaxValidationResult.Valid,
1355913564
node: null,
1356013565
syntax: syntaxes[i - 1],
@@ -13619,13 +13624,11 @@
1361913624
context
1362013625
};
1362113626
}
13622-
// console.error(`>> matchList: ${tokens.reduce((acc, curr, index) => acc + (index > 0 ? ' ' : '') + renderToken(curr), '')}`);
1362313627
result = doEvaluateSyntax([syntax], createContext(tokens), {
1362413628
...options,
1362513629
isList: false,
1362613630
occurence: false
1362713631
});
13628-
// console.error(`>> matchList: ${tokens.reduce((acc, curr, index) => acc + (index > 0 ? ' ' : '') + renderToken(curr), '')}\n>> result: ${result.valid == SyntaxValidationResult.Valid ? 'valid' : 'invalid'}\n${JSON.stringify(result, null, 1)}`);
1362913632
if (result.valid == SyntaxValidationResult.Valid) {
1363013633
context = con.clone();
1363113634
count++;
@@ -13684,7 +13687,6 @@
1368413687
let success = false;
1368513688
let result;
1368613689
let token = context.peek();
13687-
// console.error(`>> match: ${renderSyntax(syntax)}`);
1368813690
switch (syntax.typ) {
1368913691
case ValidationTokenEnum.PipeToken:
1369013692
return someOf(syntax.chi, context, options);
@@ -13699,7 +13701,7 @@
1369913701
}
1370013702
return {
1370113703
valid: SyntaxValidationResult.Drop,
13702-
node: context.next(),
13704+
node: context.current(),
1370313705
syntax,
1370413706
error: `expected '${ValidationTokenEnum[syntax.typ].toLowerCase()}', got '${context.done() ? null : renderToken(context.peek())}'`,
1370513707
context
@@ -13734,7 +13736,7 @@
1373413736
}
1373513737
switch (syntax.typ) {
1373613738
case ValidationTokenEnum.Keyword:
13737-
success = (token.typ == exports.EnumToken.IdenTokenType || token.typ == exports.EnumToken.DashedIdenTokenType) &&
13739+
success = (token.typ == exports.EnumToken.IdenTokenType || token.typ == exports.EnumToken.DashedIdenTokenType || isIdentColor(token)) &&
1373813740
(token.val == syntax.val ||
1373913741
syntax.val.localeCompare(token.val, undefined, { sensitivity: 'base' }) == 0 ||
1374013742
// config.declarations.all
@@ -13970,8 +13972,8 @@
1397013972
case 'number':
1397113973
case 'number-token':
1397213974
success = token.typ == exports.EnumToken.NumberTokenType;
13973-
if ('range' in syntax) {
13974-
success = success && +token.val >= +syntax.range[0] && +token.val <= +syntax.range[1];
13975+
if (success && 'range' in syntax) {
13976+
success = +token.val >= +syntax.range[0] && (syntax.range[1] == null || +token.val <= +syntax.range[1]);
1397513977
}
1397613978
break;
1397713979
case 'angle':
@@ -14062,7 +14064,6 @@
1406214064
context.next();
1406314065
}
1406414066
result = doEvaluateSyntax(syntaxes[i], context.clone(), options);
14065-
// console.error(JSON.stringify({result, syntax: syntaxes[i], context, slice: context.slice()}, null, 1));
1406614067
if (result.valid == SyntaxValidationResult.Valid) {
1406714068
success = true;
1406814069
if (result.context.done()) {
@@ -14075,7 +14076,6 @@
1407514076
// pick the best match
1407614077
matched.sort((a, b) => a.context.done() ? -1 : b.context.done() ? 1 : b.context.index - a.context.index);
1407714078
}
14078-
// console.error(JSON.stringify({matched, context, slice: context.slice(), syntaxes}, null, 1));
1407914079
return matched[0] ?? {
1408014080
valid: SyntaxValidationResult.Drop,
1408114081
node: context.current(),
@@ -14148,13 +14148,8 @@
1414814148
const con = createContext(tokens);
1414914149
let cp;
1415014150
let j;
14151-
// console.error(`>> allOf:syntax: ${syntax.reduce((acc, curr, index) => acc + (index > 0 ? ' && ' : '') + curr.reduce((acc, curr) => acc + renderSyntax(curr), ''), '')}`);
14152-
// console.error(`>> allOf:tokens: ${con.slice<Token>().reduce((acc, curr, index) => acc + (index > 0 ? ' ' : '') + renderToken(curr), '')}`);
14153-
// console.error(`>> allOf:tokens:slice: ${context.slice<Token>().reduce((acc, curr, index) => acc + (index > 0 ? ' ' : '') + renderToken(curr), '')}`);
1415414151
for (i = 0; i < syntax.length; i++) {
14155-
// console.error(`>> allOf:${i}:${syntax[i].reduce((acc, curr) => acc + renderSyntax(curr), '')}:current()`, con.current());
1415614152
if (syntax[i].length == 1 && syntax[i][0].isOptional) {
14157-
// syntax[i][0 = structuredClone(syntax[i][0]);
1415814153
syntax[i][0].isOptional = false;
1415914154
j = 0;
1416014155
cp = con.clone();
@@ -14163,7 +14158,6 @@
1416314158
syntax[i][0].isOptional = true;
1416414159
syntax.splice(i, 1);
1416514160
i = -1;
14166-
// console.error(`>> allOf:done:peek: `, con.peek());
1416714161
continue;
1416814162
}
1416914163
while (!cp.done()) {
@@ -14184,12 +14178,8 @@
1418414178
}
1418514179
syntax[i][0].isOptional = true;
1418614180
// @ts-ignore
14187-
// console.error(`>> allOf:result valid: `, result?.valid == SyntaxValidationResult.Valid, con.current<Token>());
14188-
// @ts-ignore
1418914181
if (result?.valid == SyntaxValidationResult.Valid) {
1419014182
syntax.splice(i, 1);
14191-
// console.error(`>> allOf:syntaxes: ${syntax.reduce((acc, curr, index) => acc + (index > 0 ? ' && ' : '') + curr.reduce((acc, curr) => acc + renderSyntax(curr), ''), '')}`);
14192-
// console.error(`>> allOf:context:`, JSON.stringify(con, null, 1));
1419314183
i = -1;
1419414184
}
1419514185
continue;

0 commit comments

Comments
 (0)