@eslint/css-tree 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +194 -0
- package/cjs/convertor/create.cjs +32 -0
- package/cjs/convertor/index.cjs +8 -0
- package/cjs/data-patch.cjs +7 -0
- package/cjs/data.cjs +120 -0
- package/cjs/definition-syntax/SyntaxError.cjs +16 -0
- package/cjs/definition-syntax/generate.cjs +139 -0
- package/cjs/definition-syntax/index.cjs +13 -0
- package/cjs/definition-syntax/parse.cjs +556 -0
- package/cjs/definition-syntax/scanner.cjs +113 -0
- package/cjs/definition-syntax/walk.cjs +57 -0
- package/cjs/generator/create.cjs +102 -0
- package/cjs/generator/index.cjs +8 -0
- package/cjs/generator/sourceMap.cjs +96 -0
- package/cjs/generator/token-before.cjs +170 -0
- package/cjs/index.cjs +65 -0
- package/cjs/lexer/Lexer.cjs +517 -0
- package/cjs/lexer/error.cjs +128 -0
- package/cjs/lexer/generic-an-plus-b.cjs +235 -0
- package/cjs/lexer/generic-const.cjs +12 -0
- package/cjs/lexer/generic-urange.cjs +149 -0
- package/cjs/lexer/generic.cjs +589 -0
- package/cjs/lexer/index.cjs +7 -0
- package/cjs/lexer/match-graph.cjs +530 -0
- package/cjs/lexer/match.cjs +632 -0
- package/cjs/lexer/prepare-tokens.cjs +54 -0
- package/cjs/lexer/search.cjs +65 -0
- package/cjs/lexer/structure.cjs +173 -0
- package/cjs/lexer/trace.cjs +73 -0
- package/cjs/lexer/units.cjs +38 -0
- package/cjs/parser/SyntaxError.cjs +74 -0
- package/cjs/parser/create.cjs +378 -0
- package/cjs/parser/index.cjs +8 -0
- package/cjs/parser/parse-selector.cjs +8 -0
- package/cjs/parser/sequence.cjs +47 -0
- package/cjs/syntax/atrule/container.cjs +32 -0
- package/cjs/syntax/atrule/font-face.cjs +12 -0
- package/cjs/syntax/atrule/import.cjs +101 -0
- package/cjs/syntax/atrule/index.cjs +27 -0
- package/cjs/syntax/atrule/layer.cjs +16 -0
- package/cjs/syntax/atrule/media.cjs +16 -0
- package/cjs/syntax/atrule/nest.cjs +16 -0
- package/cjs/syntax/atrule/page.cjs +16 -0
- package/cjs/syntax/atrule/scope.cjs +16 -0
- package/cjs/syntax/atrule/starting-style.cjs +12 -0
- package/cjs/syntax/atrule/supports.cjs +16 -0
- package/cjs/syntax/config/generator.cjs +9 -0
- package/cjs/syntax/config/lexer.cjs +14 -0
- package/cjs/syntax/config/mix.cjs +126 -0
- package/cjs/syntax/config/parser-selector.cjs +19 -0
- package/cjs/syntax/config/parser.cjs +49 -0
- package/cjs/syntax/config/walker.cjs +9 -0
- package/cjs/syntax/create.cjs +58 -0
- package/cjs/syntax/function/expression.cjs +11 -0
- package/cjs/syntax/function/var.cjs +43 -0
- package/cjs/syntax/index.cjs +14 -0
- package/cjs/syntax/node/AnPlusB.cjs +293 -0
- package/cjs/syntax/node/Atrule.cjs +103 -0
- package/cjs/syntax/node/AtrulePrelude.cjs +52 -0
- package/cjs/syntax/node/AttributeSelector.cjs +148 -0
- package/cjs/syntax/node/Block.cjs +96 -0
- package/cjs/syntax/node/Brackets.cjs +38 -0
- package/cjs/syntax/node/CDC.cjs +26 -0
- package/cjs/syntax/node/CDO.cjs +26 -0
- package/cjs/syntax/node/ClassSelector.cjs +31 -0
- package/cjs/syntax/node/Combinator.cjs +61 -0
- package/cjs/syntax/node/Comment.cjs +40 -0
- package/cjs/syntax/node/Condition.cjs +120 -0
- package/cjs/syntax/node/Declaration.cjs +166 -0
- package/cjs/syntax/node/DeclarationList.cjs +62 -0
- package/cjs/syntax/node/Dimension.cjs +30 -0
- package/cjs/syntax/node/Feature.cjs +101 -0
- package/cjs/syntax/node/FeatureFunction.cjs +67 -0
- package/cjs/syntax/node/FeatureRange.cjs +133 -0
- package/cjs/syntax/node/Function.cjs +45 -0
- package/cjs/syntax/node/GeneralEnclosed.cjs +68 -0
- package/cjs/syntax/node/Hash.cjs +30 -0
- package/cjs/syntax/node/IdSelector.cjs +33 -0
- package/cjs/syntax/node/Identifier.cjs +25 -0
- package/cjs/syntax/node/Layer.cjs +35 -0
- package/cjs/syntax/node/LayerList.cjs +43 -0
- package/cjs/syntax/node/MediaQuery.cjs +100 -0
- package/cjs/syntax/node/MediaQueryList.cjs +41 -0
- package/cjs/syntax/node/NestingSelector.cjs +29 -0
- package/cjs/syntax/node/Nth.cjs +54 -0
- package/cjs/syntax/node/Number.cjs +25 -0
- package/cjs/syntax/node/Operator.cjs +28 -0
- package/cjs/syntax/node/Parentheses.cjs +38 -0
- package/cjs/syntax/node/Percentage.cjs +25 -0
- package/cjs/syntax/node/PseudoClassSelector.cjs +67 -0
- package/cjs/syntax/node/PseudoElementSelector.cjs +69 -0
- package/cjs/syntax/node/Ratio.cjs +71 -0
- package/cjs/syntax/node/Raw.cjs +48 -0
- package/cjs/syntax/node/Rule.cjs +58 -0
- package/cjs/syntax/node/Scope.cjs +69 -0
- package/cjs/syntax/node/Selector.cjs +38 -0
- package/cjs/syntax/node/SelectorList.cjs +43 -0
- package/cjs/syntax/node/String.cjs +26 -0
- package/cjs/syntax/node/StyleSheet.cjs +83 -0
- package/cjs/syntax/node/SupportsDeclaration.cjs +38 -0
- package/cjs/syntax/node/TypeSelector.cjs +59 -0
- package/cjs/syntax/node/UnicodeRange.cjs +158 -0
- package/cjs/syntax/node/Url.cjs +54 -0
- package/cjs/syntax/node/Value.cjs +26 -0
- package/cjs/syntax/node/WhiteSpace.cjs +34 -0
- package/cjs/syntax/node/index-generate.cjs +103 -0
- package/cjs/syntax/node/index-parse-selector.cjs +39 -0
- package/cjs/syntax/node/index-parse.cjs +103 -0
- package/cjs/syntax/node/index.cjs +103 -0
- package/cjs/syntax/pseudo/index.cjs +60 -0
- package/cjs/syntax/pseudo/lang.cjs +37 -0
- package/cjs/syntax/scope/atrulePrelude.cjs +9 -0
- package/cjs/syntax/scope/default.cjs +76 -0
- package/cjs/syntax/scope/index.cjs +11 -0
- package/cjs/syntax/scope/selector.cjs +88 -0
- package/cjs/syntax/scope/value.cjs +29 -0
- package/cjs/tokenizer/OffsetToLocation.cjs +91 -0
- package/cjs/tokenizer/TokenStream.cjs +358 -0
- package/cjs/tokenizer/adopt-buffer.cjs +13 -0
- package/cjs/tokenizer/char-code-definitions.cjs +236 -0
- package/cjs/tokenizer/index.cjs +554 -0
- package/cjs/tokenizer/names.cjs +32 -0
- package/cjs/tokenizer/types.cjs +57 -0
- package/cjs/tokenizer/utils.cjs +261 -0
- package/cjs/utils/List.cjs +473 -0
- package/cjs/utils/clone.cjs +25 -0
- package/cjs/utils/create-custom-error.cjs +18 -0
- package/cjs/utils/ident.cjs +102 -0
- package/cjs/utils/index.cjs +20 -0
- package/cjs/utils/names.cjs +113 -0
- package/cjs/utils/string.cjs +99 -0
- package/cjs/utils/url.cjs +108 -0
- package/cjs/version.cjs +5 -0
- package/cjs/walker/create.cjs +291 -0
- package/cjs/walker/index.cjs +8 -0
- package/data/patch.json +874 -0
- package/dist/csstree.esm.js +12 -0
- package/dist/csstree.js +12 -0
- package/dist/data.cjs +1341 -0
- package/dist/data.js +1341 -0
- package/dist/version.cjs +1 -0
- package/dist/version.js +1 -0
- package/lib/convertor/create.js +28 -0
- package/lib/convertor/index.js +4 -0
- package/lib/data-patch.js +6 -0
- package/lib/data.js +118 -0
- package/lib/definition-syntax/SyntaxError.js +12 -0
- package/lib/definition-syntax/generate.js +135 -0
- package/lib/definition-syntax/index.js +4 -0
- package/lib/definition-syntax/parse.js +552 -0
- package/lib/definition-syntax/scanner.js +109 -0
- package/lib/definition-syntax/walk.js +53 -0
- package/lib/generator/create.js +97 -0
- package/lib/generator/index.js +4 -0
- package/lib/generator/sourceMap.js +92 -0
- package/lib/generator/token-before.js +182 -0
- package/lib/index.d.ts +3016 -0
- package/lib/index.js +30 -0
- package/lib/lexer/Lexer.js +511 -0
- package/lib/lexer/error.js +123 -0
- package/lib/lexer/generic-an-plus-b.js +238 -0
- package/lib/lexer/generic-const.js +8 -0
- package/lib/lexer/generic-urange.js +151 -0
- package/lib/lexer/generic.js +622 -0
- package/lib/lexer/index.js +1 -0
- package/lib/lexer/match-graph.js +527 -0
- package/lib/lexer/match.js +630 -0
- package/lib/lexer/prepare-tokens.js +50 -0
- package/lib/lexer/search.js +61 -0
- package/lib/lexer/structure.js +169 -0
- package/lib/lexer/trace.js +66 -0
- package/lib/lexer/units.js +27 -0
- package/lib/parser/SyntaxError.js +70 -0
- package/lib/parser/create.js +388 -0
- package/lib/parser/index.js +4 -0
- package/lib/parser/parse-selector.js +4 -0
- package/lib/parser/sequence.js +43 -0
- package/lib/syntax/atrule/container.js +28 -0
- package/lib/syntax/atrule/font-face.js +8 -0
- package/lib/syntax/atrule/import.js +104 -0
- package/lib/syntax/atrule/index.js +23 -0
- package/lib/syntax/atrule/layer.js +12 -0
- package/lib/syntax/atrule/media.js +12 -0
- package/lib/syntax/atrule/nest.js +12 -0
- package/lib/syntax/atrule/page.js +12 -0
- package/lib/syntax/atrule/scope.js +12 -0
- package/lib/syntax/atrule/starting-style.js +8 -0
- package/lib/syntax/atrule/supports.js +12 -0
- package/lib/syntax/config/generator.js +5 -0
- package/lib/syntax/config/lexer.js +10 -0
- package/lib/syntax/config/mix.js +122 -0
- package/lib/syntax/config/parser-selector.js +15 -0
- package/lib/syntax/config/parser.js +45 -0
- package/lib/syntax/config/walker.js +5 -0
- package/lib/syntax/create.js +55 -0
- package/lib/syntax/function/expression.js +7 -0
- package/lib/syntax/function/var.js +39 -0
- package/lib/syntax/index.js +10 -0
- package/lib/syntax/node/AnPlusB.js +292 -0
- package/lib/syntax/node/Atrule.js +100 -0
- package/lib/syntax/node/AtrulePrelude.js +47 -0
- package/lib/syntax/node/AttributeSelector.js +147 -0
- package/lib/syntax/node/Block.js +95 -0
- package/lib/syntax/node/Brackets.js +35 -0
- package/lib/syntax/node/CDC.js +19 -0
- package/lib/syntax/node/CDO.js +19 -0
- package/lib/syntax/node/ClassSelector.js +24 -0
- package/lib/syntax/node/Combinator.js +54 -0
- package/lib/syntax/node/Comment.js +33 -0
- package/lib/syntax/node/Condition.js +123 -0
- package/lib/syntax/node/Declaration.js +165 -0
- package/lib/syntax/node/DeclarationList.js +62 -0
- package/lib/syntax/node/Dimension.js +23 -0
- package/lib/syntax/node/Feature.js +103 -0
- package/lib/syntax/node/FeatureFunction.js +63 -0
- package/lib/syntax/node/FeatureRange.js +133 -0
- package/lib/syntax/node/Function.js +41 -0
- package/lib/syntax/node/GeneralEnclosed.js +66 -0
- package/lib/syntax/node/Hash.js +23 -0
- package/lib/syntax/node/IdSelector.js +26 -0
- package/lib/syntax/node/Identifier.js +18 -0
- package/lib/syntax/node/Layer.js +28 -0
- package/lib/syntax/node/LayerList.js +36 -0
- package/lib/syntax/node/MediaQuery.js +102 -0
- package/lib/syntax/node/MediaQueryList.js +34 -0
- package/lib/syntax/node/NestingSelector.js +22 -0
- package/lib/syntax/node/Nth.js +47 -0
- package/lib/syntax/node/Number.js +18 -0
- package/lib/syntax/node/Operator.js +21 -0
- package/lib/syntax/node/Parentheses.js +34 -0
- package/lib/syntax/node/Percentage.js +18 -0
- package/lib/syntax/node/PseudoClassSelector.js +65 -0
- package/lib/syntax/node/PseudoElementSelector.js +66 -0
- package/lib/syntax/node/Ratio.js +68 -0
- package/lib/syntax/node/Raw.js +41 -0
- package/lib/syntax/node/Rule.js +51 -0
- package/lib/syntax/node/Scope.js +66 -0
- package/lib/syntax/node/Selector.js +31 -0
- package/lib/syntax/node/SelectorList.js +35 -0
- package/lib/syntax/node/String.js +19 -0
- package/lib/syntax/node/StyleSheet.js +82 -0
- package/lib/syntax/node/SupportsDeclaration.js +34 -0
- package/lib/syntax/node/TypeSelector.js +52 -0
- package/lib/syntax/node/UnicodeRange.js +156 -0
- package/lib/syntax/node/Url.js +52 -0
- package/lib/syntax/node/Value.js +19 -0
- package/lib/syntax/node/WhiteSpace.js +27 -0
- package/lib/syntax/node/index-generate.js +49 -0
- package/lib/syntax/node/index-parse-selector.js +17 -0
- package/lib/syntax/node/index-parse.js +49 -0
- package/lib/syntax/node/index.js +49 -0
- package/lib/syntax/pseudo/index.js +56 -0
- package/lib/syntax/pseudo/lang.js +33 -0
- package/lib/syntax/scope/atrulePrelude.js +5 -0
- package/lib/syntax/scope/default.js +85 -0
- package/lib/syntax/scope/index.js +3 -0
- package/lib/syntax/scope/selector.js +94 -0
- package/lib/syntax/scope/value.js +25 -0
- package/lib/tokenizer/OffsetToLocation.js +87 -0
- package/lib/tokenizer/TokenStream.js +366 -0
- package/lib/tokenizer/adopt-buffer.js +9 -0
- package/lib/tokenizer/char-code-definitions.js +212 -0
- package/lib/tokenizer/index.js +513 -0
- package/lib/tokenizer/names.js +28 -0
- package/lib/tokenizer/types.js +28 -0
- package/lib/tokenizer/utils.js +254 -0
- package/lib/utils/List.js +469 -0
- package/lib/utils/clone.js +21 -0
- package/lib/utils/create-custom-error.js +14 -0
- package/lib/utils/ident.js +101 -0
- package/lib/utils/index.js +6 -0
- package/lib/utils/names.js +106 -0
- package/lib/utils/string.js +99 -0
- package/lib/utils/url.js +108 -0
- package/lib/version.js +5 -0
- package/lib/walker/create.js +287 -0
- package/lib/walker/index.js +4 -0
- package/package.json +133 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { List } from '../utils/List.js';
|
|
2
|
+
|
|
3
|
+
function getFirstMatchNode(matchNode) {
|
|
4
|
+
if ('node' in matchNode) {
|
|
5
|
+
return matchNode.node;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return getFirstMatchNode(matchNode.match[0]);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function getLastMatchNode(matchNode) {
|
|
12
|
+
if ('node' in matchNode) {
|
|
13
|
+
return matchNode.node;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return getLastMatchNode(matchNode.match[matchNode.match.length - 1]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function matchFragments(lexer, ast, match, type, name) {
|
|
20
|
+
function findFragments(matchNode) {
|
|
21
|
+
if (matchNode.syntax !== null &&
|
|
22
|
+
matchNode.syntax.type === type &&
|
|
23
|
+
matchNode.syntax.name === name) {
|
|
24
|
+
const start = getFirstMatchNode(matchNode);
|
|
25
|
+
const end = getLastMatchNode(matchNode);
|
|
26
|
+
|
|
27
|
+
lexer.syntax.walk(ast, function(node, item, list) {
|
|
28
|
+
if (node === start) {
|
|
29
|
+
const nodes = new List();
|
|
30
|
+
|
|
31
|
+
do {
|
|
32
|
+
nodes.appendData(item.data);
|
|
33
|
+
|
|
34
|
+
if (item.data === end) {
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
item = item.next;
|
|
39
|
+
} while (item !== null);
|
|
40
|
+
|
|
41
|
+
fragments.push({
|
|
42
|
+
parent: list,
|
|
43
|
+
nodes
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (Array.isArray(matchNode.match)) {
|
|
50
|
+
matchNode.match.forEach(findFragments);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const fragments = [];
|
|
55
|
+
|
|
56
|
+
if (match.matched !== null) {
|
|
57
|
+
findFragments(match.matched);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return fragments;
|
|
61
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { List } from '../utils/List.js';
|
|
2
|
+
|
|
3
|
+
const { hasOwnProperty } = Object.prototype;
|
|
4
|
+
|
|
5
|
+
function isValidNumber(value) {
|
|
6
|
+
// Number.isInteger(value) && value >= 0
|
|
7
|
+
return (
|
|
8
|
+
typeof value === 'number' &&
|
|
9
|
+
isFinite(value) &&
|
|
10
|
+
Math.floor(value) === value &&
|
|
11
|
+
value >= 0
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function isValidLocation(loc) {
|
|
16
|
+
return (
|
|
17
|
+
Boolean(loc) &&
|
|
18
|
+
isValidNumber(loc.offset) &&
|
|
19
|
+
isValidNumber(loc.line) &&
|
|
20
|
+
isValidNumber(loc.column)
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function createNodeStructureChecker(type, fields) {
|
|
25
|
+
return function checkNode(node, warn) {
|
|
26
|
+
if (!node || node.constructor !== Object) {
|
|
27
|
+
return warn(node, 'Type of node should be an Object');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
for (let key in node) {
|
|
31
|
+
let valid = true;
|
|
32
|
+
|
|
33
|
+
if (hasOwnProperty.call(node, key) === false) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (key === 'type') {
|
|
38
|
+
if (node.type !== type) {
|
|
39
|
+
warn(node, 'Wrong node type `' + node.type + '`, expected `' + type + '`');
|
|
40
|
+
}
|
|
41
|
+
} else if (key === 'loc') {
|
|
42
|
+
if (node.loc === null) {
|
|
43
|
+
continue;
|
|
44
|
+
} else if (node.loc && node.loc.constructor === Object) {
|
|
45
|
+
if (typeof node.loc.source !== 'string') {
|
|
46
|
+
key += '.source';
|
|
47
|
+
} else if (!isValidLocation(node.loc.start)) {
|
|
48
|
+
key += '.start';
|
|
49
|
+
} else if (!isValidLocation(node.loc.end)) {
|
|
50
|
+
key += '.end';
|
|
51
|
+
} else {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
valid = false;
|
|
57
|
+
} else if (fields.hasOwnProperty(key)) {
|
|
58
|
+
valid = false;
|
|
59
|
+
|
|
60
|
+
for (let i = 0; !valid && i < fields[key].length; i++) {
|
|
61
|
+
const fieldType = fields[key][i];
|
|
62
|
+
|
|
63
|
+
switch (fieldType) {
|
|
64
|
+
case String:
|
|
65
|
+
valid = typeof node[key] === 'string';
|
|
66
|
+
break;
|
|
67
|
+
|
|
68
|
+
case Boolean:
|
|
69
|
+
valid = typeof node[key] === 'boolean';
|
|
70
|
+
break;
|
|
71
|
+
|
|
72
|
+
case null:
|
|
73
|
+
valid = node[key] === null;
|
|
74
|
+
break;
|
|
75
|
+
|
|
76
|
+
default:
|
|
77
|
+
if (typeof fieldType === 'string') {
|
|
78
|
+
valid = node[key] && node[key].type === fieldType;
|
|
79
|
+
} else if (Array.isArray(fieldType)) {
|
|
80
|
+
valid = node[key] instanceof List;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
warn(node, 'Unknown field `' + key + '` for ' + type + ' node type');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (!valid) {
|
|
89
|
+
warn(node, 'Bad value for `' + type + '.' + key + '`');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
for (const key in fields) {
|
|
94
|
+
if (hasOwnProperty.call(fields, key) &&
|
|
95
|
+
hasOwnProperty.call(node, key) === false) {
|
|
96
|
+
warn(node, 'Field `' + type + '.' + key + '` is missed');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function genTypesList(fieldTypes, path) {
|
|
103
|
+
const docsTypes = [];
|
|
104
|
+
|
|
105
|
+
for (let i = 0; i < fieldTypes.length; i++) {
|
|
106
|
+
const fieldType = fieldTypes[i];
|
|
107
|
+
if (fieldType === String || fieldType === Boolean) {
|
|
108
|
+
docsTypes.push(fieldType.name.toLowerCase());
|
|
109
|
+
} else if (fieldType === null) {
|
|
110
|
+
docsTypes.push('null');
|
|
111
|
+
} else if (typeof fieldType === 'string') {
|
|
112
|
+
docsTypes.push(fieldType);
|
|
113
|
+
} else if (Array.isArray(fieldType)) {
|
|
114
|
+
docsTypes.push('List<' + (genTypesList(fieldType, path) || 'any') + '>'); // TODO: use type enum
|
|
115
|
+
} else {
|
|
116
|
+
throw new Error('Wrong value `' + fieldType + '` in `' + path + '` structure definition');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return docsTypes.join(' | ');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function processStructure(name, nodeType) {
|
|
124
|
+
const structure = nodeType.structure;
|
|
125
|
+
const fields = {
|
|
126
|
+
type: String,
|
|
127
|
+
loc: true
|
|
128
|
+
};
|
|
129
|
+
const docs = {
|
|
130
|
+
type: '"' + name + '"'
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
for (const key in structure) {
|
|
134
|
+
if (hasOwnProperty.call(structure, key) === false) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const fieldTypes = fields[key] = Array.isArray(structure[key])
|
|
139
|
+
? structure[key].slice()
|
|
140
|
+
: [structure[key]];
|
|
141
|
+
|
|
142
|
+
docs[key] = genTypesList(fieldTypes, name + '.' + key);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
docs,
|
|
147
|
+
check: createNodeStructureChecker(name, fields)
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function getStructureFromConfig(config) {
|
|
152
|
+
const structure = {};
|
|
153
|
+
|
|
154
|
+
if (config.node) {
|
|
155
|
+
for (const name in config.node) {
|
|
156
|
+
if (hasOwnProperty.call(config.node, name)) {
|
|
157
|
+
const nodeType = config.node[name];
|
|
158
|
+
|
|
159
|
+
if (nodeType.structure) {
|
|
160
|
+
structure[name] = processStructure(name, nodeType);
|
|
161
|
+
} else {
|
|
162
|
+
throw new Error('Missed `structure` field in `' + name + '` node type definition');
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return structure;
|
|
169
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export function getTrace(node) {
|
|
2
|
+
function shouldPutToTrace(syntax) {
|
|
3
|
+
if (syntax === null) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
return (
|
|
8
|
+
syntax.type === 'Type' ||
|
|
9
|
+
syntax.type === 'Property' ||
|
|
10
|
+
syntax.type === 'Keyword'
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function hasMatch(matchNode) {
|
|
15
|
+
if (Array.isArray(matchNode.match)) {
|
|
16
|
+
// use for-loop for better perfomance
|
|
17
|
+
for (let i = 0; i < matchNode.match.length; i++) {
|
|
18
|
+
if (hasMatch(matchNode.match[i])) {
|
|
19
|
+
if (shouldPutToTrace(matchNode.syntax)) {
|
|
20
|
+
result.unshift(matchNode.syntax);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
} else if (matchNode.node === node) {
|
|
27
|
+
result = shouldPutToTrace(matchNode.syntax)
|
|
28
|
+
? [matchNode.syntax]
|
|
29
|
+
: [];
|
|
30
|
+
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let result = null;
|
|
38
|
+
|
|
39
|
+
if (this.matched !== null) {
|
|
40
|
+
hasMatch(this.matched);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function isType(node, type) {
|
|
47
|
+
return testNode(this, node, match => match.type === 'Type' && match.name === type);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function isProperty(node, property) {
|
|
51
|
+
return testNode(this, node, match => match.type === 'Property' && match.name === property);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function isKeyword(node) {
|
|
55
|
+
return testNode(this, node, match => match.type === 'Keyword');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function testNode(match, node, fn) {
|
|
59
|
+
const trace = getTrace.call(match, node);
|
|
60
|
+
|
|
61
|
+
if (trace === null) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return trace.some(fn);
|
|
66
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export const length = [
|
|
2
|
+
// absolute length units https://www.w3.org/TR/css-values-3/#lengths
|
|
3
|
+
'cm', 'mm', 'q', 'in', 'pt', 'pc', 'px',
|
|
4
|
+
// font-relative length units https://drafts.csswg.org/css-values-4/#font-relative-lengths
|
|
5
|
+
'em', 'rem',
|
|
6
|
+
'ex', 'rex',
|
|
7
|
+
'cap', 'rcap',
|
|
8
|
+
'ch', 'rch',
|
|
9
|
+
'ic', 'ric',
|
|
10
|
+
'lh', 'rlh',
|
|
11
|
+
// viewport-percentage lengths https://drafts.csswg.org/css-values-4/#viewport-relative-lengths
|
|
12
|
+
'vw', 'svw', 'lvw', 'dvw',
|
|
13
|
+
'vh', 'svh', 'lvh', 'dvh',
|
|
14
|
+
'vi', 'svi', 'lvi', 'dvi',
|
|
15
|
+
'vb', 'svb', 'lvb', 'dvb',
|
|
16
|
+
'vmin', 'svmin', 'lvmin', 'dvmin',
|
|
17
|
+
'vmax', 'svmax', 'lvmax', 'dvmax',
|
|
18
|
+
// container relative lengths https://drafts.csswg.org/css-contain-3/#container-lengths
|
|
19
|
+
'cqw', 'cqh', 'cqi', 'cqb', 'cqmin', 'cqmax'
|
|
20
|
+
];
|
|
21
|
+
export const angle = ['deg', 'grad', 'rad', 'turn']; // https://www.w3.org/TR/css-values-3/#angles
|
|
22
|
+
export const time = ['s', 'ms']; // https://www.w3.org/TR/css-values-3/#time
|
|
23
|
+
export const frequency = ['hz', 'khz']; // https://www.w3.org/TR/css-values-3/#frequency
|
|
24
|
+
export const resolution = ['dpi', 'dpcm', 'dppx', 'x']; // https://www.w3.org/TR/css-values-3/#resolution
|
|
25
|
+
export const flex = ['fr']; // https://drafts.csswg.org/css-grid/#fr-unit
|
|
26
|
+
export const decibel = ['db']; // https://www.w3.org/TR/css3-speech/#mixing-props-voice-volume
|
|
27
|
+
export const semitones = ['st']; // https://www.w3.org/TR/css3-speech/#voice-props-voice-pitch
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createCustomError } from '../utils/create-custom-error.js';
|
|
2
|
+
|
|
3
|
+
const MAX_LINE_LENGTH = 100;
|
|
4
|
+
const OFFSET_CORRECTION = 60;
|
|
5
|
+
const TAB_REPLACEMENT = ' ';
|
|
6
|
+
|
|
7
|
+
function sourceFragment({ source, line, column, baseLine, baseColumn }, extraLines) {
|
|
8
|
+
function processLines(start, end) {
|
|
9
|
+
return lines
|
|
10
|
+
.slice(start, end)
|
|
11
|
+
.map((line, idx) =>
|
|
12
|
+
String(start + idx + 1).padStart(maxNumLength) + ' |' + line
|
|
13
|
+
).join('\n');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const prelines = '\n'.repeat(Math.max(baseLine - 1, 0));
|
|
17
|
+
const precolumns = ' '.repeat(Math.max(baseColumn - 1, 0));
|
|
18
|
+
const lines = (prelines + precolumns + source).split(/\r\n?|\n|\f/);
|
|
19
|
+
const startLine = Math.max(1, line - extraLines) - 1;
|
|
20
|
+
const endLine = Math.min(line + extraLines, lines.length + 1);
|
|
21
|
+
const maxNumLength = Math.max(4, String(endLine).length) + 1;
|
|
22
|
+
let cutLeft = 0;
|
|
23
|
+
|
|
24
|
+
// column correction according to replaced tab before column
|
|
25
|
+
column += (TAB_REPLACEMENT.length - 1) * (lines[line - 1].substr(0, column - 1).match(/\t/g) || []).length;
|
|
26
|
+
|
|
27
|
+
if (column > MAX_LINE_LENGTH) {
|
|
28
|
+
cutLeft = column - OFFSET_CORRECTION + 3;
|
|
29
|
+
column = OFFSET_CORRECTION - 2;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for (let i = startLine; i <= endLine; i++) {
|
|
33
|
+
if (i >= 0 && i < lines.length) {
|
|
34
|
+
lines[i] = lines[i].replace(/\t/g, TAB_REPLACEMENT);
|
|
35
|
+
lines[i] =
|
|
36
|
+
(cutLeft > 0 && lines[i].length > cutLeft ? '\u2026' : '') +
|
|
37
|
+
lines[i].substr(cutLeft, MAX_LINE_LENGTH - 2) +
|
|
38
|
+
(lines[i].length > cutLeft + MAX_LINE_LENGTH - 1 ? '\u2026' : '');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return [
|
|
43
|
+
processLines(startLine, line),
|
|
44
|
+
new Array(column + maxNumLength + 2).join('-') + '^',
|
|
45
|
+
processLines(line, endLine)
|
|
46
|
+
].filter(Boolean)
|
|
47
|
+
.join('\n')
|
|
48
|
+
.replace(/^(\s+\d+\s+\|\n)+/, '')
|
|
49
|
+
.replace(/\n(\s+\d+\s+\|)+$/, '');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function SyntaxError(message, source, offset, line, column, baseLine = 1, baseColumn = 1) {
|
|
53
|
+
const error = Object.assign(createCustomError('SyntaxError', message), {
|
|
54
|
+
source,
|
|
55
|
+
offset,
|
|
56
|
+
line,
|
|
57
|
+
column,
|
|
58
|
+
sourceFragment(extraLines) {
|
|
59
|
+
return sourceFragment({ source, line, column, baseLine, baseColumn }, isNaN(extraLines) ? 0 : extraLines);
|
|
60
|
+
},
|
|
61
|
+
get formattedMessage() {
|
|
62
|
+
return (
|
|
63
|
+
`Parse error: ${message}\n` +
|
|
64
|
+
sourceFragment({ source, line, column, baseLine, baseColumn }, 2)
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return error;
|
|
70
|
+
}
|