@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,18 @@
|
|
|
1
|
+
import { Ident } from '../../tokenizer/index.js';
|
|
2
|
+
|
|
3
|
+
export const name = 'Identifier';
|
|
4
|
+
export const structure = {
|
|
5
|
+
name: String
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function parse() {
|
|
9
|
+
return {
|
|
10
|
+
type: 'Identifier',
|
|
11
|
+
loc: this.getLocation(this.tokenStart, this.tokenEnd),
|
|
12
|
+
name: this.consume(Ident)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function generate(node) {
|
|
17
|
+
this.token(Ident, node.name);
|
|
18
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Ident, Delim } from '../../tokenizer/index.js';
|
|
2
|
+
|
|
3
|
+
const FULLSTOP = 0x002E; // U+002E FULL STOP (.)
|
|
4
|
+
|
|
5
|
+
export const name = 'Layer';
|
|
6
|
+
export const structure = {
|
|
7
|
+
name: String
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function parse() {
|
|
11
|
+
let tokenStart = this.tokenStart;
|
|
12
|
+
let name = this.consume(Ident);
|
|
13
|
+
|
|
14
|
+
while (this.isDelim(FULLSTOP)) {
|
|
15
|
+
this.eat(Delim);
|
|
16
|
+
name += '.' + this.consume(Ident);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
type: 'Layer',
|
|
21
|
+
loc: this.getLocation(tokenStart, this.tokenStart),
|
|
22
|
+
name
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function generate(node) {
|
|
27
|
+
this.tokenize(node.name);
|
|
28
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Comma } from '../../tokenizer/index.js';
|
|
2
|
+
|
|
3
|
+
export const name = 'LayerList';
|
|
4
|
+
export const structure = {
|
|
5
|
+
children: [[
|
|
6
|
+
'Layer'
|
|
7
|
+
]]
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function parse() {
|
|
11
|
+
const children = this.createList();
|
|
12
|
+
|
|
13
|
+
this.skipSC();
|
|
14
|
+
|
|
15
|
+
while (!this.eof) {
|
|
16
|
+
children.push(this.Layer());
|
|
17
|
+
|
|
18
|
+
if (this.lookupTypeNonSC(0) !== Comma) {
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
this.skipSC();
|
|
23
|
+
this.next();
|
|
24
|
+
this.skipSC();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
type: 'LayerList',
|
|
29
|
+
loc: this.getLocationFromList(children),
|
|
30
|
+
children
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function generate(node) {
|
|
35
|
+
this.children(node, () => this.token(Comma, ','));
|
|
36
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Comma,
|
|
3
|
+
EOF,
|
|
4
|
+
Ident,
|
|
5
|
+
LeftCurlyBracket,
|
|
6
|
+
LeftParenthesis,
|
|
7
|
+
Function as FunctionToken,
|
|
8
|
+
Semicolon
|
|
9
|
+
} from '../../tokenizer/index.js';
|
|
10
|
+
|
|
11
|
+
export const name = 'MediaQuery';
|
|
12
|
+
export const structure = {
|
|
13
|
+
modifier: [String, null],
|
|
14
|
+
mediaType: [String, null],
|
|
15
|
+
condition: ['Condition', null]
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function parse() {
|
|
19
|
+
const start = this.tokenStart;
|
|
20
|
+
let modifier = null;
|
|
21
|
+
let mediaType = null;
|
|
22
|
+
let condition = null;
|
|
23
|
+
|
|
24
|
+
this.skipSC();
|
|
25
|
+
|
|
26
|
+
if (this.tokenType === Ident && this.lookupTypeNonSC(1) !== LeftParenthesis) {
|
|
27
|
+
// [ not | only ]? <media-type>
|
|
28
|
+
const ident = this.consume(Ident);
|
|
29
|
+
const identLowerCase = ident.toLowerCase();
|
|
30
|
+
|
|
31
|
+
if (identLowerCase === 'not' || identLowerCase === 'only') {
|
|
32
|
+
this.skipSC();
|
|
33
|
+
modifier = identLowerCase;
|
|
34
|
+
mediaType = this.consume(Ident);
|
|
35
|
+
} else {
|
|
36
|
+
mediaType = ident;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
switch (this.lookupTypeNonSC(0)) {
|
|
40
|
+
case Ident: {
|
|
41
|
+
// and <media-condition-without-or>
|
|
42
|
+
this.skipSC();
|
|
43
|
+
this.eatIdent('and');
|
|
44
|
+
condition = this.Condition('media');
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
case LeftCurlyBracket:
|
|
49
|
+
case Semicolon:
|
|
50
|
+
case Comma:
|
|
51
|
+
case EOF:
|
|
52
|
+
break;
|
|
53
|
+
|
|
54
|
+
default:
|
|
55
|
+
this.error('Identifier or parenthesis is expected');
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
switch (this.tokenType) {
|
|
59
|
+
case Ident:
|
|
60
|
+
case LeftParenthesis:
|
|
61
|
+
case FunctionToken: {
|
|
62
|
+
// <media-condition>
|
|
63
|
+
condition = this.Condition('media');
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
case LeftCurlyBracket:
|
|
68
|
+
case Semicolon:
|
|
69
|
+
case EOF:
|
|
70
|
+
break;
|
|
71
|
+
|
|
72
|
+
default:
|
|
73
|
+
this.error('Identifier or parenthesis is expected');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
type: 'MediaQuery',
|
|
79
|
+
loc: this.getLocation(start, this.tokenStart),
|
|
80
|
+
modifier,
|
|
81
|
+
mediaType,
|
|
82
|
+
condition
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function generate(node) {
|
|
87
|
+
if (node.mediaType) {
|
|
88
|
+
if (node.modifier) {
|
|
89
|
+
this.token(Ident, node.modifier);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
this.token(Ident, node.mediaType);
|
|
93
|
+
|
|
94
|
+
if (node.condition) {
|
|
95
|
+
this.token(Ident, 'and');
|
|
96
|
+
this.node(node.condition);
|
|
97
|
+
}
|
|
98
|
+
} else if (node.condition) {
|
|
99
|
+
this.node(node.condition);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Comma } from '../../tokenizer/index.js';
|
|
2
|
+
|
|
3
|
+
export const name = 'MediaQueryList';
|
|
4
|
+
export const structure = {
|
|
5
|
+
children: [[
|
|
6
|
+
'MediaQuery'
|
|
7
|
+
]]
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function parse() {
|
|
11
|
+
const children = this.createList();
|
|
12
|
+
|
|
13
|
+
this.skipSC();
|
|
14
|
+
|
|
15
|
+
while (!this.eof) {
|
|
16
|
+
children.push(this.MediaQuery());
|
|
17
|
+
|
|
18
|
+
if (this.tokenType !== Comma) {
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
this.next();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
type: 'MediaQueryList',
|
|
27
|
+
loc: this.getLocationFromList(children),
|
|
28
|
+
children
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function generate(node) {
|
|
33
|
+
this.children(node, () => this.token(Comma, ','));
|
|
34
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Delim } from '../../tokenizer/index.js';
|
|
2
|
+
|
|
3
|
+
const AMPERSAND = 0x0026; // U+0026 AMPERSAND (&)
|
|
4
|
+
|
|
5
|
+
export const name = 'NestingSelector';
|
|
6
|
+
export const structure = {
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export function parse() {
|
|
10
|
+
const start = this.tokenStart;
|
|
11
|
+
|
|
12
|
+
this.eatDelim(AMPERSAND);
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
type: 'NestingSelector',
|
|
16
|
+
loc: this.getLocation(start, this.tokenStart)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function generate() {
|
|
21
|
+
this.token(Delim, '&');
|
|
22
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Ident } from '../../tokenizer/index.js';
|
|
2
|
+
|
|
3
|
+
export const name = 'Nth';
|
|
4
|
+
export const structure = {
|
|
5
|
+
nth: ['AnPlusB', 'Identifier'],
|
|
6
|
+
selector: ['SelectorList', null]
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export function parse() {
|
|
10
|
+
this.skipSC();
|
|
11
|
+
|
|
12
|
+
const start = this.tokenStart;
|
|
13
|
+
let end = start;
|
|
14
|
+
let selector = null;
|
|
15
|
+
let nth;
|
|
16
|
+
|
|
17
|
+
if (this.lookupValue(0, 'odd') || this.lookupValue(0, 'even')) {
|
|
18
|
+
nth = this.Identifier();
|
|
19
|
+
} else {
|
|
20
|
+
nth = this.AnPlusB();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
end = this.tokenStart;
|
|
24
|
+
this.skipSC();
|
|
25
|
+
|
|
26
|
+
if (this.lookupValue(0, 'of')) {
|
|
27
|
+
this.next();
|
|
28
|
+
|
|
29
|
+
selector = this.SelectorList();
|
|
30
|
+
end = this.tokenStart;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
type: 'Nth',
|
|
35
|
+
loc: this.getLocation(start, end),
|
|
36
|
+
nth,
|
|
37
|
+
selector
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function generate(node) {
|
|
42
|
+
this.node(node.nth);
|
|
43
|
+
if (node.selector !== null) {
|
|
44
|
+
this.token(Ident, 'of');
|
|
45
|
+
this.node(node.selector);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Number as NumberToken } from '../../tokenizer/index.js';
|
|
2
|
+
|
|
3
|
+
export const name = 'Number';
|
|
4
|
+
export const structure = {
|
|
5
|
+
value: String
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function parse() {
|
|
9
|
+
return {
|
|
10
|
+
type: 'Number',
|
|
11
|
+
loc: this.getLocation(this.tokenStart, this.tokenEnd),
|
|
12
|
+
value: this.consume(NumberToken)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function generate(node) {
|
|
17
|
+
this.token(NumberToken, node.value);
|
|
18
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// '/' | '*' | ',' | ':' | '+' | '-'
|
|
2
|
+
export const name = 'Operator';
|
|
3
|
+
export const structure = {
|
|
4
|
+
value: String
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export function parse() {
|
|
8
|
+
const start = this.tokenStart;
|
|
9
|
+
|
|
10
|
+
this.next();
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
type: 'Operator',
|
|
14
|
+
loc: this.getLocation(start, this.tokenStart),
|
|
15
|
+
value: this.substrToCursor(start)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function generate(node) {
|
|
20
|
+
this.tokenize(node.value);
|
|
21
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LeftParenthesis,
|
|
3
|
+
RightParenthesis
|
|
4
|
+
} from '../../tokenizer/index.js';
|
|
5
|
+
|
|
6
|
+
export const name = 'Parentheses';
|
|
7
|
+
export const structure = {
|
|
8
|
+
children: [[]]
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function parse(readSequence, recognizer) {
|
|
12
|
+
const start = this.tokenStart;
|
|
13
|
+
let children = null;
|
|
14
|
+
|
|
15
|
+
this.eat(LeftParenthesis);
|
|
16
|
+
|
|
17
|
+
children = readSequence.call(this, recognizer);
|
|
18
|
+
|
|
19
|
+
if (!this.eof) {
|
|
20
|
+
this.eat(RightParenthesis);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
type: 'Parentheses',
|
|
25
|
+
loc: this.getLocation(start, this.tokenStart),
|
|
26
|
+
children
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function generate(node) {
|
|
31
|
+
this.token(LeftParenthesis, '(');
|
|
32
|
+
this.children(node);
|
|
33
|
+
this.token(RightParenthesis, ')');
|
|
34
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Percentage } from '../../tokenizer/index.js';
|
|
2
|
+
|
|
3
|
+
export const name = 'Percentage';
|
|
4
|
+
export const structure = {
|
|
5
|
+
value: String
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function parse() {
|
|
9
|
+
return {
|
|
10
|
+
type: 'Percentage',
|
|
11
|
+
loc: this.getLocation(this.tokenStart, this.tokenEnd),
|
|
12
|
+
value: this.consumeNumber(Percentage)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function generate(node) {
|
|
17
|
+
this.token(Percentage, node.value + '%');
|
|
18
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Ident,
|
|
3
|
+
Function as FunctionToken,
|
|
4
|
+
Colon,
|
|
5
|
+
RightParenthesis
|
|
6
|
+
} from '../../tokenizer/index.js';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export const name = 'PseudoClassSelector';
|
|
10
|
+
export const walkContext = 'function';
|
|
11
|
+
export const structure = {
|
|
12
|
+
name: String,
|
|
13
|
+
children: [['Raw'], null]
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// : [ <ident> | <function-token> <any-value>? ) ]
|
|
17
|
+
export function parse() {
|
|
18
|
+
const start = this.tokenStart;
|
|
19
|
+
let children = null;
|
|
20
|
+
let name;
|
|
21
|
+
let nameLowerCase;
|
|
22
|
+
|
|
23
|
+
this.eat(Colon);
|
|
24
|
+
|
|
25
|
+
if (this.tokenType === FunctionToken) {
|
|
26
|
+
name = this.consumeFunctionName();
|
|
27
|
+
nameLowerCase = name.toLowerCase();
|
|
28
|
+
|
|
29
|
+
if (this.lookupNonWSType(0) == RightParenthesis) {
|
|
30
|
+
children = this.createList();
|
|
31
|
+
} else if (hasOwnProperty.call(this.pseudo, nameLowerCase)) {
|
|
32
|
+
this.skipSC();
|
|
33
|
+
children = this.pseudo[nameLowerCase].call(this);
|
|
34
|
+
this.skipSC();
|
|
35
|
+
} else {
|
|
36
|
+
children = this.createList();
|
|
37
|
+
children.push(
|
|
38
|
+
this.Raw(null, false)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
this.eat(RightParenthesis);
|
|
43
|
+
} else {
|
|
44
|
+
name = this.consume(Ident);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
type: 'PseudoClassSelector',
|
|
49
|
+
loc: this.getLocation(start, this.tokenStart),
|
|
50
|
+
name,
|
|
51
|
+
children
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function generate(node) {
|
|
56
|
+
this.token(Colon, ':');
|
|
57
|
+
|
|
58
|
+
if (node.children === null) {
|
|
59
|
+
this.token(Ident, node.name);
|
|
60
|
+
} else {
|
|
61
|
+
this.token(FunctionToken, node.name + '(');
|
|
62
|
+
this.children(node);
|
|
63
|
+
this.token(RightParenthesis, ')');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Ident,
|
|
3
|
+
Function as FunctionToken,
|
|
4
|
+
Colon,
|
|
5
|
+
RightParenthesis
|
|
6
|
+
} from '../../tokenizer/index.js';
|
|
7
|
+
|
|
8
|
+
export const name = 'PseudoElementSelector';
|
|
9
|
+
export const walkContext = 'function';
|
|
10
|
+
export const structure = {
|
|
11
|
+
name: String,
|
|
12
|
+
children: [['Raw'], null]
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// :: [ <ident> | <function-token> <any-value>? ) ]
|
|
16
|
+
export function parse() {
|
|
17
|
+
const start = this.tokenStart;
|
|
18
|
+
let children = null;
|
|
19
|
+
let name;
|
|
20
|
+
let nameLowerCase;
|
|
21
|
+
|
|
22
|
+
this.eat(Colon);
|
|
23
|
+
this.eat(Colon);
|
|
24
|
+
|
|
25
|
+
if (this.tokenType === FunctionToken) {
|
|
26
|
+
name = this.consumeFunctionName();
|
|
27
|
+
nameLowerCase = name.toLowerCase();
|
|
28
|
+
|
|
29
|
+
if (this.lookupNonWSType(0) == RightParenthesis) {
|
|
30
|
+
children = this.createList();
|
|
31
|
+
} else if (hasOwnProperty.call(this.pseudo, nameLowerCase)) {
|
|
32
|
+
this.skipSC();
|
|
33
|
+
children = this.pseudo[nameLowerCase].call(this);
|
|
34
|
+
this.skipSC();
|
|
35
|
+
} else {
|
|
36
|
+
children = this.createList();
|
|
37
|
+
children.push(
|
|
38
|
+
this.Raw(null, false)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
this.eat(RightParenthesis);
|
|
43
|
+
} else {
|
|
44
|
+
name = this.consume(Ident);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
type: 'PseudoElementSelector',
|
|
49
|
+
loc: this.getLocation(start, this.tokenStart),
|
|
50
|
+
name,
|
|
51
|
+
children
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function generate(node) {
|
|
56
|
+
this.token(Colon, ':');
|
|
57
|
+
this.token(Colon, ':');
|
|
58
|
+
|
|
59
|
+
if (node.children === null) {
|
|
60
|
+
this.token(Ident, node.name);
|
|
61
|
+
} else {
|
|
62
|
+
this.token(FunctionToken, node.name + '(');
|
|
63
|
+
this.children(node);
|
|
64
|
+
this.token(RightParenthesis, ')');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Delim,
|
|
3
|
+
Number as NumberToken,
|
|
4
|
+
Function as FunctionToken
|
|
5
|
+
} from '../../tokenizer/index.js';
|
|
6
|
+
|
|
7
|
+
const SOLIDUS = 0x002F; // U+002F SOLIDUS (/)
|
|
8
|
+
|
|
9
|
+
// Media Queries Level 3 defines terms of <ratio> as a positive (not zero or negative)
|
|
10
|
+
// integers (see https://drafts.csswg.org/mediaqueries-3/#values)
|
|
11
|
+
// However, Media Queries Level 4 removes any definition of values
|
|
12
|
+
// (see https://drafts.csswg.org/mediaqueries-4/#values) and refers to
|
|
13
|
+
// CSS Values and Units for detail. In CSS Values and Units Level 4 a <ratio>
|
|
14
|
+
// definition was added (see https://drafts.csswg.org/css-values-4/#ratios) which
|
|
15
|
+
// defines ratio as "<number [0,∞]> [ / <number [0,∞]> ]?" and based on it
|
|
16
|
+
// any constrains on terms were removed. Parser also doesn't test numbers
|
|
17
|
+
// in any way to make possible for linting and fixing them by the tools using CSSTree.
|
|
18
|
+
// An additional syntax examination may be applied by a lexer.
|
|
19
|
+
function consumeTerm() {
|
|
20
|
+
this.skipSC();
|
|
21
|
+
|
|
22
|
+
switch (this.tokenType) {
|
|
23
|
+
case NumberToken:
|
|
24
|
+
return this.Number();
|
|
25
|
+
|
|
26
|
+
case FunctionToken:
|
|
27
|
+
return this.Function(this.readSequence, this.scope.Value);
|
|
28
|
+
|
|
29
|
+
default:
|
|
30
|
+
this.error('Number of function is expected');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const name = 'Ratio';
|
|
35
|
+
export const structure = {
|
|
36
|
+
left: ['Number', 'Function'],
|
|
37
|
+
right: ['Number', 'Function', null]
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// <number [0,∞]> [ / <number [0,∞]> ]?
|
|
41
|
+
export function parse() {
|
|
42
|
+
const start = this.tokenStart;
|
|
43
|
+
const left = consumeTerm.call(this);
|
|
44
|
+
let right = null;
|
|
45
|
+
|
|
46
|
+
this.skipSC();
|
|
47
|
+
if (this.isDelim(SOLIDUS)) {
|
|
48
|
+
this.eatDelim(SOLIDUS);
|
|
49
|
+
right = consumeTerm.call(this);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
type: 'Ratio',
|
|
54
|
+
loc: this.getLocation(start, this.tokenStart),
|
|
55
|
+
left,
|
|
56
|
+
right
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function generate(node) {
|
|
61
|
+
this.node(node.left);
|
|
62
|
+
this.token(Delim, '/');
|
|
63
|
+
if (node.right) {
|
|
64
|
+
this.node(node.right);
|
|
65
|
+
} else {
|
|
66
|
+
this.node(NumberToken, 1);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { WhiteSpace } from '../../tokenizer/index.js';
|
|
2
|
+
|
|
3
|
+
function getOffsetExcludeWS() {
|
|
4
|
+
if (this.tokenIndex > 0) {
|
|
5
|
+
if (this.lookupType(-1) === WhiteSpace) {
|
|
6
|
+
return this.tokenIndex > 1
|
|
7
|
+
? this.getTokenStart(this.tokenIndex - 1)
|
|
8
|
+
: this.firstCharOffset;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return this.tokenStart;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const name = 'Raw';
|
|
16
|
+
export const structure = {
|
|
17
|
+
value: String
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function parse(consumeUntil, excludeWhiteSpace) {
|
|
21
|
+
const startOffset = this.getTokenStart(this.tokenIndex);
|
|
22
|
+
let endOffset;
|
|
23
|
+
|
|
24
|
+
this.skipUntilBalanced(this.tokenIndex, consumeUntil || this.consumeUntilBalanceEnd);
|
|
25
|
+
|
|
26
|
+
if (excludeWhiteSpace && this.tokenStart > startOffset) {
|
|
27
|
+
endOffset = getOffsetExcludeWS.call(this);
|
|
28
|
+
} else {
|
|
29
|
+
endOffset = this.tokenStart;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
type: 'Raw',
|
|
34
|
+
loc: this.getLocation(startOffset, endOffset),
|
|
35
|
+
value: this.substring(startOffset, endOffset)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function generate(node) {
|
|
40
|
+
this.tokenize(node.value);
|
|
41
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { LeftCurlyBracket } from '../../tokenizer/index.js';
|
|
2
|
+
|
|
3
|
+
function consumeRaw() {
|
|
4
|
+
return this.Raw(this.consumeUntilLeftCurlyBracket, true);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function consumePrelude() {
|
|
8
|
+
const prelude = this.SelectorList();
|
|
9
|
+
|
|
10
|
+
if (prelude.type !== 'Raw' &&
|
|
11
|
+
this.eof === false &&
|
|
12
|
+
this.tokenType !== LeftCurlyBracket) {
|
|
13
|
+
this.error();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return prelude;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const name = 'Rule';
|
|
20
|
+
export const walkContext = 'rule';
|
|
21
|
+
export const structure = {
|
|
22
|
+
prelude: ['SelectorList', 'Raw'],
|
|
23
|
+
block: ['Block']
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export function parse() {
|
|
27
|
+
const startToken = this.tokenIndex;
|
|
28
|
+
const startOffset = this.tokenStart;
|
|
29
|
+
let prelude;
|
|
30
|
+
let block;
|
|
31
|
+
|
|
32
|
+
if (this.parseRulePrelude) {
|
|
33
|
+
prelude = this.parseWithFallback(consumePrelude, consumeRaw);
|
|
34
|
+
} else {
|
|
35
|
+
prelude = consumeRaw.call(this, startToken);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
block = this.Block(true);
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
type: 'Rule',
|
|
42
|
+
loc: this.getLocation(startOffset, this.tokenStart),
|
|
43
|
+
prelude,
|
|
44
|
+
block
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export function generate(node) {
|
|
48
|
+
this.node(node.prelude);
|
|
49
|
+
this.node(node.block);
|
|
50
|
+
}
|
|
51
|
+
|