Skip to content

Commit 2d97de8

Browse files
committed
update doc #112
1 parent 11c8dea commit 2d97de8

File tree

250 files changed

+13058
-10695
lines changed

Some content is hidden

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

250 files changed

+13058
-10695
lines changed

dist/index-umd-web.js

Lines changed: 166 additions & 69 deletions
Large diffs are not rendered by default.

dist/index.cjs

Lines changed: 166 additions & 69 deletions
Large diffs are not rendered by default.

dist/index.d.ts

Lines changed: 150 additions & 134 deletions
Large diffs are not rendered by default.

dist/lib/ast/features/transform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { minifyTransformFunctions, eqMatrix } from '../transform/minify.js';
1313
import { FeatureWalkMode } from './type.js';
1414

1515
class TransformCssFeature {
16-
accept = new Set([EnumToken.RuleNodeType, EnumToken.AtRuleNodeType]);
16+
accept = new Set([EnumToken.RuleNodeType, EnumToken.KeyFramesRuleNodeType]);
1717
get ordering() {
1818
return 4;
1919
}

dist/lib/ast/types.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,26 @@ var ValidationLevel;
1919
* disable validation
2020
*/
2121
ValidationLevel[ValidationLevel["None"] = 0] = "None";
22+
/**
23+
* validate selectors
24+
*/
25+
ValidationLevel[ValidationLevel["Selector"] = 1] = "Selector";
26+
/**
27+
* validate at-rules
28+
*/
29+
ValidationLevel[ValidationLevel["AtRule"] = 2] = "AtRule";
30+
/**
31+
* validate declarations
32+
*/
33+
ValidationLevel[ValidationLevel["Declaration"] = 4] = "Declaration";
2234
/**
2335
* validate selectors and at-rules
2436
*/
25-
ValidationLevel[ValidationLevel["Default"] = 1] = "Default";
37+
ValidationLevel[ValidationLevel["Default"] = 3] = "Default";
2638
/**
2739
* validate selectors, at-rules and declarations
2840
*/
29-
ValidationLevel[ValidationLevel["All"] = 2] = "All"; // selectors + at-rules + declarations
41+
ValidationLevel[ValidationLevel["All"] = 7] = "All"; // selectors + at-rules + declarations
3042
})(ValidationLevel || (ValidationLevel = {}));
3143
/**
3244
* enum of all token types

dist/lib/parser/declaration/list.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ class PropertyList {
2626
}
2727
add(...declarations) {
2828
for (const declaration of declarations) {
29-
if (declaration.typ != EnumToken.DeclarationNodeType || (Array.isArray(this.options.removeDuplicateDeclarations) ? this.options.removeDuplicateDeclarations.includes(declaration.nam) : !this.options.removeDuplicateDeclarations)) {
29+
if (declaration.typ != EnumToken.DeclarationNodeType ||
30+
(typeof this.options.removeDuplicateDeclarations === 'string' && this.options.removeDuplicateDeclarations === declaration.nam.toLowerCase()) ||
31+
(Array.isArray(this.options.removeDuplicateDeclarations) ? this.options.removeDuplicateDeclarations.includes(declaration.nam) : !this.options.removeDuplicateDeclarations)) {
3032
this.declarations.set(Number(Math.random().toString().slice(2)).toString(36), declaration);
3133
continue;
3234
}

dist/lib/parser/parse.js

Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ async function doParse(iter, options = {}) {
154154
const preVisitorsHandlersMap = new Map;
155155
const visitorsHandlersMap = new Map;
156156
const postVisitorsHandlersMap = new Map;
157-
// const allValuesHandlers = new Map as Map<EnumToken, Array<GenericVisitorHandler<Token>>>;
158157
const rawTokens = [];
159158
const imports = [];
160159
let item;
@@ -240,42 +239,6 @@ async function doParse(iter, options = {}) {
240239
errors.push({ action: 'ignore', message: `doParse: visitor.${key} is not a valid key name` });
241240
}
242241
}
243-
// if (preValuesHandlers.size > 0) {
244-
//
245-
// for (const [key, value] of preValuesHandlers) {
246-
//
247-
// if (!allValuesHandlers.has(key)) {
248-
//
249-
// allValuesHandlers.set(key, []);
250-
// }
251-
//
252-
// allValuesHandlers.get(key)!.push(...value);
253-
// }
254-
// }
255-
// if (valuesHandlers.size > 0) {
256-
//
257-
// for (const [key, value] of valuesHandlers) {
258-
//
259-
// if (!allValuesHandlers.has(key)) {
260-
//
261-
// allValuesHandlers.set(key, []);
262-
// }
263-
//
264-
// allValuesHandlers.get(key)!.push(...value);
265-
// }
266-
// }
267-
// if (postValuesHandlers.size > 0) {
268-
//
269-
// for (const [key, value] of postValuesHandlers) {
270-
//
271-
// if (!postValuesHandlers.has(key)) {
272-
//
273-
// allValuesHandlers.set(key, []);
274-
// }
275-
//
276-
// allValuesHandlers.get(key)!.push(...value);
277-
// }
278-
// }
279242
}
280243
while (item = isAsync ? (await iter.next()).value : iter.next().value) {
281244
stats.bytesIn = item.bytesIn;
@@ -435,6 +398,8 @@ async function doParse(iter, options = {}) {
435398
if (options.expandNestingRules) {
436399
ast = expand(ast);
437400
}
401+
let replacement;
402+
let callable;
438403
for (const result of walk(ast)) {
439404
if (valuesHandlers.size > 0 || preVisitorsHandlersMap.size > 0 || visitorsHandlersMap.size > 0 || postVisitorsHandlersMap.size > 0) {
440405
if ((result.node.typ == EnumToken.DeclarationNodeType &&
@@ -455,14 +420,13 @@ async function doParse(iter, options = {}) {
455420
// @ts-ignore
456421
handlers.push(...postVisitorsHandlersMap.get(key));
457422
}
458-
let callable;
459423
let node = result.node;
460424
for (const handler of handlers) {
461425
callable = typeof handler == 'function' ? handler : handler[normalizeVisitorKeyName(node.typ == EnumToken.DeclarationNodeType || node.typ == EnumToken.AtRuleNodeType ? node.nam : node.val)];
462426
if (callable == null) {
463427
continue;
464428
}
465-
let replacement = callable(node, result.parent);
429+
replacement = callable(node, result.parent);
466430
if (replacement == null) {
467431
continue;
468432
}
@@ -500,8 +464,7 @@ async function doParse(iter, options = {}) {
500464
}
501465
let node = result.node;
502466
for (const callable of handlers) {
503-
// @ts-ignore
504-
let replacement = callable(node, result.parent);
467+
replacement = callable(node, result.parent);
505468
if (replacement == null) {
506469
continue;
507470
}
@@ -526,13 +489,12 @@ async function doParse(iter, options = {}) {
526489
}
527490
}
528491
else if (valuesHandlers.size > 0) {
529-
let callable;
530492
let node = null;
531493
node = result.node;
532494
if (valuesHandlers.has(node.typ)) {
533495
for (const valueHandler of valuesHandlers.get(node.typ)) {
534496
callable = valueHandler;
535-
let replacement = callable(node, result.parent);
497+
replacement = callable(node, result.parent);
536498
if (replacement == null) {
537499
continue;
538500
}
@@ -828,7 +790,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens, stats
828790
}
829791
const isAllowed = isNodeAllowedInContext(node, context);
830792
// @ts-ignore
831-
const valid = options.validation == ValidationLevel.None ? {
793+
const valid = (options.validation & ValidationLevel.AtRule) == 0 ? {
832794
valid: SyntaxValidationResult.Valid,
833795
error: '',
834796
node,
@@ -964,12 +926,11 @@ function parseNode(results, context, options, errors, src, map, rawTokens, stats
964926
value: loc,
965927
enumerable: options.sourcemap !== false
966928
});
967-
// @ts-ignore
968929
context.chi.push(node);
969930
Object.defineProperty(node, 'parent', { ...definedPropertySettings, value: context });
970931
const isAllowed = isNodeAllowedInContext(node, context);
971932
// @ts-ignore
972-
const valid = options.validation == ValidationLevel.None ? {
933+
const valid = (options.validation & ValidationLevel.Selector) == 0 ? {
973934
valid: SyntaxValidationResult.Valid,
974935
error: null
975936
} : !isAllowed ? {
@@ -1084,7 +1045,11 @@ function parseNode(results, context, options, errors, src, map, rawTokens, stats
10841045
nam,
10851046
val: []
10861047
};
1087-
Object.defineProperty(node, 'loc', { ...definedPropertySettings, value: location, enumerable: options.sourcemap !== false });
1048+
Object.defineProperty(node, 'loc', {
1049+
...definedPropertySettings,
1050+
value: location,
1051+
enumerable: options.sourcemap !== false
1052+
});
10881053
context.chi.push(node);
10891054
stats.nodesCount++;
10901055
}
@@ -1110,7 +1075,11 @@ function parseNode(results, context, options, errors, src, map, rawTokens, stats
11101075
nam,
11111076
val: value
11121077
};
1113-
Object.defineProperty(node, 'loc', { ...definedPropertySettings, value: location, enumerable: options.sourcemap !== false });
1078+
Object.defineProperty(node, 'loc', {
1079+
...definedPropertySettings,
1080+
value: location,
1081+
enumerable: options.sourcemap !== false
1082+
});
11141083
node.loc.end = { ...map.get(delim).end };
11151084
// do not allow declarations in style sheets
11161085
if (context.typ == EnumToken.StyleSheetNodeType && options.lenient) {
@@ -1122,7 +1091,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens, stats
11221091
const result = parseDeclarationNode(node, errors, location);
11231092
Object.defineProperty(result, 'parent', { ...definedPropertySettings, value: context });
11241093
if (result != null) {
1125-
if (options.validation == ValidationLevel.All) {
1094+
if (options.validation & ValidationLevel.Declaration) {
11261095
const isAllowed = isNodeAllowedInContext(node, context);
11271096
// @ts-ignore
11281097
const valid = !isAllowed ? {
@@ -1471,7 +1440,11 @@ function parseString(src, options = { location: false }) {
14711440
return acc;
14721441
}
14731442
const token = getTokenType(t.token, t.hint);
1474-
Object.defineProperty(token, 'loc', { ...definedPropertySettings, value: { sta: t.sta }, enumerable: options.location !== false });
1443+
Object.defineProperty(token, 'loc', {
1444+
...definedPropertySettings,
1445+
value: { sta: t.sta },
1446+
enumerable: options.location !== false
1447+
});
14751448
acc.push(token);
14761449
return acc;
14771450
}, []));

dist/lib/syntax/syntax.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ function isColor(token) {
528528
}
529529
if (token.typ == EnumToken.IdenTokenType) {
530530
// named color
531-
return token.val.toLowerCase() in COLORS_NAMES;
531+
return token.val.toLowerCase() in COLORS_NAMES || 'currentcolor' === token.val.toLowerCase() || 'transparent' === token.val.toLowerCase();
532532
}
533533
let isLegacySyntax = false;
534534
if (token.typ == EnumToken.FunctionTokenType) {
@@ -581,8 +581,13 @@ function isColor(token) {
581581
return false;
582582
}
583583
}
584-
if (children[i].typ == EnumToken.FunctionTokenType && !mathFuncs.includes(children[i].val)) {
585-
return false;
584+
if (children[i].typ == EnumToken.FunctionTokenType) {
585+
if ('var' == children[i].val.toLowerCase()) {
586+
continue;
587+
}
588+
if (!mathFuncs.includes(children[i].val)) {
589+
return false;
590+
}
586591
}
587592
}
588593
if (children.length == 4 || (isRelative && children.length == 6)) {

dist/lib/validation/at-rules/container.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ import { splitTokenList } from '../utils/list.js';
1111

1212
const validateContainerScrollStateFeature = validateContainerSizeFeature;
1313
function validateAtRuleContainer(atRule, options, root) {
14+
if (!Array.isArray(atRule.chi)) {
15+
// @ts-ignore
16+
return {
17+
valid: SyntaxValidationResult.Drop,
18+
matches: [],
19+
node: atRule,
20+
syntax: '@' + atRule.nam,
21+
error: 'expected supports body',
22+
tokens: []
23+
};
24+
}
1425
// media-query-list
1526
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
1627
// @ts-ignore

dist/lib/validation/at-rules/counter-style.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ import '../../syntax/color/utils/constants.js';
88
import '../../renderer/sourcemap/lib/encode.js';
99

1010
function validateAtRuleCounterStyle(atRule, options, root) {
11+
if (!Array.isArray(atRule.chi)) {
12+
// @ts-ignore
13+
return {
14+
valid: SyntaxValidationResult.Drop,
15+
matches: [],
16+
node: atRule,
17+
syntax: '@' + atRule.nam,
18+
error: 'expected supports body',
19+
tokens: []
20+
};
21+
}
1122
// media-query-list
1223
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
1324
// @ts-ignore

0 commit comments

Comments
 (0)