Skip to content

Commit 0610742

Browse files
committed
syntax update #92
1 parent 21ff83b commit 0610742

File tree

20 files changed

+173404
-216
lines changed

20 files changed

+173404
-216
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Javascript module from cdn
9696

9797
<script type="module">
9898
99-
import {transform} from 'https://esm.sh/@tbela99/css-parser@1.1.1/web';
99+
import {transform} from 'https://esm.sh/@tbela99/css-parser@1.1.2/web';
100100
101101
102102
const css = `

dist/index-umd-web.js

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10748,7 +10748,7 @@
1074810748
syntax: "cover | contain | entry | exit | entry-crossing | exit-crossing"
1074910749
},
1075010750
"track-breadth": {
10751-
syntax: "<length-percentage> | <flex> | min-content | max-content | auto"
10751+
syntax: "<length-percentage> | <flex> | min-content | max-content | auto | <-non-standard-size>>"
1075210752
},
1075310753
"track-list": {
1075410754
syntax: "[ <line-names>? [ <track-size> | <track-repeat> ] ]+ <line-names>?"
@@ -13344,7 +13344,7 @@
1334413344
const allValues = getSyntaxConfig()["declarations" /* ValidationSyntaxGroupEnum.Declarations */].all.syntax.trim().split(/[\s|]+/g);
1334513345
function createContext(input) {
1334613346
const values = input.slice();
13347-
const result = values.slice();
13347+
const result = values.filter(token => token.typ != exports.EnumToken.CommentTokenType).slice();
1334813348
if (result.at(-1)?.typ == exports.EnumToken.WhitespaceTokenType) {
1334913349
result.pop();
1335013350
}
@@ -13579,9 +13579,9 @@
1357913579
}
1358013580
return {
1358113581
valid: success ? SyntaxValidationResult.Valid : SyntaxValidationResult.Drop,
13582-
node: context.current(),
13582+
node: context.peek(),
1358313583
syntax,
13584-
error: success ? '' : `could not match atLeastOnce: ${renderSyntax(syntax)}`,
13584+
error: success ? '' : `could not match syntax: ${renderSyntax(syntax)}`,
1358513585
context
1358613586
};
1358713587
}
@@ -13618,7 +13618,7 @@
1361813618
valid: SyntaxValidationResult.Drop,
1361913619
node: context.peek(),
1362013620
syntax,
13621-
error: `could not match list: ${renderSyntax(syntax)}`,
13621+
error: `could not match syntax: ${renderSyntax(syntax)}`,
1362213622
context
1362313623
};
1362413624
}
@@ -13650,7 +13650,7 @@
1365013650
}
1365113651
return {
1365213652
valid: success ? SyntaxValidationResult.Valid : SyntaxValidationResult.Drop,
13653-
node: context.current(),
13653+
node: context.peek(),
1365413654
syntax,
1365513655
error: '',
1365613656
context
@@ -13675,7 +13675,7 @@
1367513675
}
1367613676
return {
1367713677
valid: sucesss ? SyntaxValidationResult.Valid : SyntaxValidationResult.Drop,
13678-
node: context.current(),
13678+
node: context.peek(),
1367913679
syntax,
1368013680
error: sucesss ? '' : `expected ${renderSyntax(syntax)} ${syntax.occurence.min} to ${syntax.occurence.max} occurences, got ${counter}`,
1368113681
context
@@ -13699,7 +13699,7 @@
1369913699
}
1370013700
return {
1370113701
valid: SyntaxValidationResult.Drop,
13702-
node: context.current(),
13702+
node: context.peek(),
1370313703
syntax,
1370413704
error: `expected '${ValidationTokenEnum[syntax.typ].toLowerCase()}', got '${context.done() ? null : renderToken(context.peek())}'`,
1370513705
context
@@ -14158,9 +14158,9 @@
1415814158
}
1415914159
return matched[0] ?? {
1416014160
valid: SyntaxValidationResult.Drop,
14161-
node: context.current(),
14161+
node: context.peek(),
1416214162
syntax: null,
14163-
error: success ? '' : `could not match someOf: ${syntaxes.reduce((acc, curr) => acc + (acc.length > 0 ? ' | ' : '') + curr.reduce((acc, curr) => acc + renderSyntax(curr), ''), '')}`,
14163+
error: success ? '' : `could not match syntax: ${syntaxes.reduce((acc, curr) => acc + (acc.length > 0 ? ' | ' : '') + curr.reduce((acc, curr) => acc + renderSyntax(curr), ''), '')}`,
1416414164
context
1416514165
};
1416614166
}
@@ -14182,9 +14182,9 @@
1418214182
}
1418314183
return {
1418414184
valid: success ? SyntaxValidationResult.Valid : SyntaxValidationResult.Drop,
14185-
node: context.current(),
14185+
node: context.peek(),
1418614186
syntax: null,
14187-
error: success ? '' : `could not match anyOf: ${syntaxes.reduce((acc, curr) => acc + '[' + curr.reduce((acc, curr) => acc + renderSyntax(curr), '') + ']', '')}`,
14187+
error: success ? '' : `could not match syntax: ${syntaxes.reduce((acc, curr) => acc + '[' + curr.reduce((acc, curr) => acc + renderSyntax(curr), '') + ']', '')}`,
1418814188
context
1418914189
};
1419014190
}
@@ -14274,9 +14274,9 @@
1427414274
const success = syntax.length == 0;
1427514275
return {
1427614276
valid: success ? SyntaxValidationResult.Valid : SyntaxValidationResult.Drop,
14277-
node: context.current(),
14277+
node: context.peek(),
1427814278
syntax: syntax?.[0]?.[0] ?? null,
14279-
error: `could not match allOf: ${syntax.reduce((acc, curr) => acc + '[' + curr.reduce((acc, curr) => acc + renderSyntax(curr), '') + ']', '')}`,
14279+
error: `could not match syntax: ${syntax.reduce((acc, curr) => acc + '[' + curr.reduce((acc, curr) => acc + renderSyntax(curr), '') + ']', '')}`,
1428014280
context: success ? con : context
1428114281
};
1428214282
}
@@ -16359,7 +16359,6 @@
1635916359
}
1636016360
}
1636116361
catch (error) {
16362-
// console.error(error);
1636316362
// @ts-ignore
1636416363
errors.push({ action: 'ignore', message: 'doParse: ' + error.message, error });
1636516364
}
@@ -16632,7 +16631,6 @@
1663216631
node.loc = loc;
1663316632
node.loc.end = { ...map.get(delim).end };
1663416633
}
16635-
// if (options.validation) {
1663616634
let isValid = true;
1663716635
if (node.nam == 'else') {
1663816636
const prev = getLastNode(context);
@@ -16909,12 +16907,11 @@
1690916907
value: valid.valid == SyntaxValidationResult.Valid
1691016908
});
1691116909
if (valid.valid == SyntaxValidationResult.Drop) {
16912-
// console.error({result, valid});
16913-
// console.error(JSON.stringify({result, options, valid}, null, 1));
1691416910
errors.push({
1691516911
action: 'drop',
1691616912
message: valid.error,
1691716913
syntax: valid.syntax,
16914+
node: valid.node,
1691816915
location: map.get(valid.node) ?? valid.node?.loc ?? result.loc ?? location
1691916916
});
1692016917
if (!options.lenient) {
@@ -17075,10 +17072,7 @@
1707517072
break;
1707617073
}
1707717074
if (valueIndex == -1) {
17078-
// @ts-ignore
17079-
// value.chi[nameIndex].typ = EnumToken.MediaFeatureTokenType;
1708017075
continue;
17081-
// return tokens;
1708217076
}
1708317077
for (i = nameIndex + 1; i < value.chi.length; i++) {
1708417078
if ([
@@ -17209,7 +17203,6 @@
1720917203
break;
1721017204
}
1721117205
// @ts-ignore
17212-
// @ts-ignore
1721317206
delete value.val;
1721417207
}
1721517208
}
@@ -17498,7 +17491,6 @@
1749817491
}
1749917492
// @ts-ignore
1750017493
if (attr.chi.length > 1) {
17501-
/*(<AttrToken>t).chi =*/
1750217494
// @ts-ignore
1750317495
parseTokens(attr.chi, t.typ);
1750417496
}
@@ -17718,7 +17710,6 @@
1771817710
// @ts-ignore
1771917711
if (t.chi.length > 0) {
1772017712
if (t.typ == exports.EnumToken.PseudoClassFuncTokenType && t.val == ':is' && options.minify) {
17721-
//
1772217713
const count = t.chi.filter((t) => t.typ != exports.EnumToken.CommentTokenType).length;
1772317714
if (count == 1 ||
1772417715
(i == 0 &&
@@ -21037,12 +21028,32 @@
2103721028
if (!wrap) {
2103821029
wrap = selector.some((s) => s[0] != '&');
2103921030
}
21040-
let rule = selector.map(s => {
21041-
if (s[0] == '&') {
21042-
s.splice(0, 1, ...node.optimized.optimized);
21031+
let rule = null;
21032+
const optimized = node.optimized.optimized.slice();
21033+
if (optimized.length > 1) {
21034+
const check = optimized.at(-2);
21035+
if (!combinators.includes(check)) {
21036+
let last = optimized.pop();
21037+
wrap = false;
21038+
rule = optimized.join('') + `:is(${selector.map(s => {
21039+
if (s[0] == '&') {
21040+
s.splice(0, 1, last);
21041+
}
21042+
else {
21043+
s.unshift(last);
21044+
}
21045+
return s.join('');
21046+
}).join(',')})`;
2104321047
}
21044-
return s.join('');
21045-
}).join(',');
21048+
}
21049+
if (rule == null) {
21050+
rule = selector.map(s => {
21051+
if (s[0] == '&') {
21052+
s.splice(0, 1, ...node.optimized.optimized);
21053+
}
21054+
return s.join('');
21055+
}).join(',');
21056+
}
2104621057
// @ts-ignore
2104721058
let sel = wrap ? node.optimized.optimized.join('') + `:is(${rule})` : rule;
2104821059
if (rule.includes('&')) {

0 commit comments

Comments
 (0)