@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,103 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const types = require('../../tokenizer/types.cjs');
|
|
4
|
+
|
|
5
|
+
function consumeRaw() {
|
|
6
|
+
return this.Raw(this.consumeUntilLeftCurlyBracketOrSemicolon, true);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function isDeclarationBlockAtrule() {
|
|
10
|
+
for (let offset = 1, type; type = this.lookupType(offset); offset++) {
|
|
11
|
+
if (type === types.RightCurlyBracket) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (type === types.LeftCurlyBracket ||
|
|
16
|
+
type === types.AtKeyword) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
const name = 'Atrule';
|
|
26
|
+
const walkContext = 'atrule';
|
|
27
|
+
const structure = {
|
|
28
|
+
name: String,
|
|
29
|
+
prelude: ['AtrulePrelude', 'Raw', null],
|
|
30
|
+
block: ['Block', null]
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function parse(isDeclaration = false) {
|
|
34
|
+
const start = this.tokenStart;
|
|
35
|
+
let name;
|
|
36
|
+
let nameLowerCase;
|
|
37
|
+
let prelude = null;
|
|
38
|
+
let block = null;
|
|
39
|
+
|
|
40
|
+
this.eat(types.AtKeyword);
|
|
41
|
+
|
|
42
|
+
name = this.substrToCursor(start + 1);
|
|
43
|
+
nameLowerCase = name.toLowerCase();
|
|
44
|
+
this.skipSC();
|
|
45
|
+
|
|
46
|
+
// parse prelude
|
|
47
|
+
if (this.eof === false &&
|
|
48
|
+
this.tokenType !== types.LeftCurlyBracket &&
|
|
49
|
+
this.tokenType !== types.Semicolon) {
|
|
50
|
+
if (this.parseAtrulePrelude) {
|
|
51
|
+
prelude = this.parseWithFallback(this.AtrulePrelude.bind(this, name, isDeclaration), consumeRaw);
|
|
52
|
+
} else {
|
|
53
|
+
prelude = consumeRaw.call(this, this.tokenIndex);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
this.skipSC();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
switch (this.tokenType) {
|
|
60
|
+
case types.Semicolon:
|
|
61
|
+
this.next();
|
|
62
|
+
break;
|
|
63
|
+
|
|
64
|
+
case types.LeftCurlyBracket:
|
|
65
|
+
if (hasOwnProperty.call(this.atrule, nameLowerCase) &&
|
|
66
|
+
typeof this.atrule[nameLowerCase].block === 'function') {
|
|
67
|
+
block = this.atrule[nameLowerCase].block.call(this, isDeclaration);
|
|
68
|
+
} else {
|
|
69
|
+
// TODO: should consume block content as Raw?
|
|
70
|
+
block = this.Block(isDeclarationBlockAtrule.call(this));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
type: 'Atrule',
|
|
78
|
+
loc: this.getLocation(start, this.tokenStart),
|
|
79
|
+
name,
|
|
80
|
+
prelude,
|
|
81
|
+
block
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function generate(node) {
|
|
86
|
+
this.token(types.AtKeyword, '@' + node.name);
|
|
87
|
+
|
|
88
|
+
if (node.prelude !== null) {
|
|
89
|
+
this.node(node.prelude);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (node.block) {
|
|
93
|
+
this.node(node.block);
|
|
94
|
+
} else {
|
|
95
|
+
this.token(types.Semicolon, ';');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
exports.generate = generate;
|
|
100
|
+
exports.name = name;
|
|
101
|
+
exports.parse = parse;
|
|
102
|
+
exports.structure = structure;
|
|
103
|
+
exports.walkContext = walkContext;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const types = require('../../tokenizer/types.cjs');
|
|
4
|
+
|
|
5
|
+
const name = 'AtrulePrelude';
|
|
6
|
+
const walkContext = 'atrulePrelude';
|
|
7
|
+
const structure = {
|
|
8
|
+
children: [[]]
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
function parse(name) {
|
|
12
|
+
let children = null;
|
|
13
|
+
|
|
14
|
+
if (name !== null) {
|
|
15
|
+
name = name.toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
this.skipSC();
|
|
19
|
+
|
|
20
|
+
if (hasOwnProperty.call(this.atrule, name) &&
|
|
21
|
+
typeof this.atrule[name].prelude === 'function') {
|
|
22
|
+
// custom consumer
|
|
23
|
+
children = this.atrule[name].prelude.call(this);
|
|
24
|
+
} else {
|
|
25
|
+
// default consumer
|
|
26
|
+
children = this.readSequence(this.scope.AtrulePrelude);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
this.skipSC();
|
|
30
|
+
|
|
31
|
+
if (this.eof !== true &&
|
|
32
|
+
this.tokenType !== types.LeftCurlyBracket &&
|
|
33
|
+
this.tokenType !== types.Semicolon) {
|
|
34
|
+
this.error('Semicolon or block is expected');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
type: 'AtrulePrelude',
|
|
39
|
+
loc: this.getLocationFromList(children),
|
|
40
|
+
children
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function generate(node) {
|
|
45
|
+
this.children(node);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
exports.generate = generate;
|
|
49
|
+
exports.name = name;
|
|
50
|
+
exports.parse = parse;
|
|
51
|
+
exports.structure = structure;
|
|
52
|
+
exports.walkContext = walkContext;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const types = require('../../tokenizer/types.cjs');
|
|
4
|
+
|
|
5
|
+
const DOLLARSIGN = 0x0024; // U+0024 DOLLAR SIGN ($)
|
|
6
|
+
const ASTERISK = 0x002A; // U+002A ASTERISK (*)
|
|
7
|
+
const EQUALSSIGN = 0x003D; // U+003D EQUALS SIGN (=)
|
|
8
|
+
const CIRCUMFLEXACCENT = 0x005E; // U+005E (^)
|
|
9
|
+
const VERTICALLINE = 0x007C; // U+007C VERTICAL LINE (|)
|
|
10
|
+
const TILDE = 0x007E; // U+007E TILDE (~)
|
|
11
|
+
|
|
12
|
+
function getAttributeName() {
|
|
13
|
+
if (this.eof) {
|
|
14
|
+
this.error('Unexpected end of input');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const start = this.tokenStart;
|
|
18
|
+
let expectIdent = false;
|
|
19
|
+
|
|
20
|
+
if (this.isDelim(ASTERISK)) {
|
|
21
|
+
expectIdent = true;
|
|
22
|
+
this.next();
|
|
23
|
+
} else if (!this.isDelim(VERTICALLINE)) {
|
|
24
|
+
this.eat(types.Ident);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (this.isDelim(VERTICALLINE)) {
|
|
28
|
+
if (this.charCodeAt(this.tokenStart + 1) !== EQUALSSIGN) {
|
|
29
|
+
this.next();
|
|
30
|
+
this.eat(types.Ident);
|
|
31
|
+
} else if (expectIdent) {
|
|
32
|
+
this.error('Identifier is expected', this.tokenEnd);
|
|
33
|
+
}
|
|
34
|
+
} else if (expectIdent) {
|
|
35
|
+
this.error('Vertical line is expected');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
type: 'Identifier',
|
|
40
|
+
loc: this.getLocation(start, this.tokenStart),
|
|
41
|
+
name: this.substrToCursor(start)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getOperator() {
|
|
46
|
+
const start = this.tokenStart;
|
|
47
|
+
const code = this.charCodeAt(start);
|
|
48
|
+
|
|
49
|
+
if (code !== EQUALSSIGN && // =
|
|
50
|
+
code !== TILDE && // ~=
|
|
51
|
+
code !== CIRCUMFLEXACCENT && // ^=
|
|
52
|
+
code !== DOLLARSIGN && // $=
|
|
53
|
+
code !== ASTERISK && // *=
|
|
54
|
+
code !== VERTICALLINE // |=
|
|
55
|
+
) {
|
|
56
|
+
this.error('Attribute selector (=, ~=, ^=, $=, *=, |=) is expected');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this.next();
|
|
60
|
+
|
|
61
|
+
if (code !== EQUALSSIGN) {
|
|
62
|
+
if (!this.isDelim(EQUALSSIGN)) {
|
|
63
|
+
this.error('Equal sign is expected');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
this.next();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return this.substrToCursor(start);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// '[' <wq-name> ']'
|
|
73
|
+
// '[' <wq-name> <attr-matcher> [ <string-token> | <ident-token> ] <attr-modifier>? ']'
|
|
74
|
+
const name = 'AttributeSelector';
|
|
75
|
+
const structure = {
|
|
76
|
+
name: 'Identifier',
|
|
77
|
+
matcher: [String, null],
|
|
78
|
+
value: ['String', 'Identifier', null],
|
|
79
|
+
flags: [String, null]
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
function parse() {
|
|
83
|
+
const start = this.tokenStart;
|
|
84
|
+
let name;
|
|
85
|
+
let matcher = null;
|
|
86
|
+
let value = null;
|
|
87
|
+
let flags = null;
|
|
88
|
+
|
|
89
|
+
this.eat(types.LeftSquareBracket);
|
|
90
|
+
this.skipSC();
|
|
91
|
+
|
|
92
|
+
name = getAttributeName.call(this);
|
|
93
|
+
this.skipSC();
|
|
94
|
+
|
|
95
|
+
if (this.tokenType !== types.RightSquareBracket) {
|
|
96
|
+
// avoid case `[name i]`
|
|
97
|
+
if (this.tokenType !== types.Ident) {
|
|
98
|
+
matcher = getOperator.call(this);
|
|
99
|
+
|
|
100
|
+
this.skipSC();
|
|
101
|
+
|
|
102
|
+
value = this.tokenType === types.String
|
|
103
|
+
? this.String()
|
|
104
|
+
: this.Identifier();
|
|
105
|
+
|
|
106
|
+
this.skipSC();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// attribute flags
|
|
110
|
+
if (this.tokenType === types.Ident) {
|
|
111
|
+
flags = this.consume(types.Ident);
|
|
112
|
+
|
|
113
|
+
this.skipSC();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
this.eat(types.RightSquareBracket);
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
type: 'AttributeSelector',
|
|
121
|
+
loc: this.getLocation(start, this.tokenStart),
|
|
122
|
+
name,
|
|
123
|
+
matcher,
|
|
124
|
+
value,
|
|
125
|
+
flags
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function generate(node) {
|
|
130
|
+
this.token(types.Delim, '[');
|
|
131
|
+
this.node(node.name);
|
|
132
|
+
|
|
133
|
+
if (node.matcher !== null) {
|
|
134
|
+
this.tokenize(node.matcher);
|
|
135
|
+
this.node(node.value);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (node.flags !== null) {
|
|
139
|
+
this.token(types.Ident, node.flags);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
this.token(types.Delim, ']');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
exports.generate = generate;
|
|
146
|
+
exports.name = name;
|
|
147
|
+
exports.parse = parse;
|
|
148
|
+
exports.structure = structure;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const types = require('../../tokenizer/types.cjs');
|
|
4
|
+
|
|
5
|
+
const AMPERSAND = 0x0026; // U+0026 AMPERSAND (&)
|
|
6
|
+
|
|
7
|
+
function consumeRaw() {
|
|
8
|
+
return this.Raw(null, true);
|
|
9
|
+
}
|
|
10
|
+
function consumeRule() {
|
|
11
|
+
return this.parseWithFallback(this.Rule, consumeRaw);
|
|
12
|
+
}
|
|
13
|
+
function consumeRawDeclaration() {
|
|
14
|
+
return this.Raw(this.consumeUntilSemicolonIncluded, true);
|
|
15
|
+
}
|
|
16
|
+
function consumeDeclaration() {
|
|
17
|
+
if (this.tokenType === types.Semicolon) {
|
|
18
|
+
return consumeRawDeclaration.call(this, this.tokenIndex);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const node = this.parseWithFallback(this.Declaration, consumeRawDeclaration);
|
|
22
|
+
|
|
23
|
+
if (this.tokenType === types.Semicolon) {
|
|
24
|
+
this.next();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return node;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const name = 'Block';
|
|
31
|
+
const walkContext = 'block';
|
|
32
|
+
const structure = {
|
|
33
|
+
children: [[
|
|
34
|
+
'Atrule',
|
|
35
|
+
'Rule',
|
|
36
|
+
'Declaration'
|
|
37
|
+
]]
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
function parse(isStyleBlock) {
|
|
41
|
+
const consumer = isStyleBlock ? consumeDeclaration : consumeRule;
|
|
42
|
+
const start = this.tokenStart;
|
|
43
|
+
let children = this.createList();
|
|
44
|
+
|
|
45
|
+
this.eat(types.LeftCurlyBracket);
|
|
46
|
+
|
|
47
|
+
scan:
|
|
48
|
+
while (!this.eof) {
|
|
49
|
+
switch (this.tokenType) {
|
|
50
|
+
case types.RightCurlyBracket:
|
|
51
|
+
break scan;
|
|
52
|
+
|
|
53
|
+
case types.WhiteSpace:
|
|
54
|
+
case types.Comment:
|
|
55
|
+
this.next();
|
|
56
|
+
break;
|
|
57
|
+
|
|
58
|
+
case types.AtKeyword:
|
|
59
|
+
children.push(this.parseWithFallback(this.Atrule.bind(this, isStyleBlock), consumeRaw));
|
|
60
|
+
break;
|
|
61
|
+
|
|
62
|
+
default:
|
|
63
|
+
if (isStyleBlock && this.isDelim(AMPERSAND)) {
|
|
64
|
+
children.push(consumeRule.call(this));
|
|
65
|
+
} else {
|
|
66
|
+
children.push(consumer.call(this));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!this.eof) {
|
|
72
|
+
this.eat(types.RightCurlyBracket);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
type: 'Block',
|
|
77
|
+
loc: this.getLocation(start, this.tokenStart),
|
|
78
|
+
children
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function generate(node) {
|
|
83
|
+
this.token(types.LeftCurlyBracket, '{');
|
|
84
|
+
this.children(node, prev => {
|
|
85
|
+
if (prev.type === 'Declaration') {
|
|
86
|
+
this.token(types.Semicolon, ';');
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
this.token(types.RightCurlyBracket, '}');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
exports.generate = generate;
|
|
93
|
+
exports.name = name;
|
|
94
|
+
exports.parse = parse;
|
|
95
|
+
exports.structure = structure;
|
|
96
|
+
exports.walkContext = walkContext;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const types = require('../../tokenizer/types.cjs');
|
|
4
|
+
|
|
5
|
+
const name = 'Brackets';
|
|
6
|
+
const structure = {
|
|
7
|
+
children: [[]]
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
function parse(readSequence, recognizer) {
|
|
11
|
+
const start = this.tokenStart;
|
|
12
|
+
let children = null;
|
|
13
|
+
|
|
14
|
+
this.eat(types.LeftSquareBracket);
|
|
15
|
+
|
|
16
|
+
children = readSequence.call(this, recognizer);
|
|
17
|
+
|
|
18
|
+
if (!this.eof) {
|
|
19
|
+
this.eat(types.RightSquareBracket);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
type: 'Brackets',
|
|
24
|
+
loc: this.getLocation(start, this.tokenStart),
|
|
25
|
+
children
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function generate(node) {
|
|
30
|
+
this.token(types.Delim, '[');
|
|
31
|
+
this.children(node);
|
|
32
|
+
this.token(types.Delim, ']');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
exports.generate = generate;
|
|
36
|
+
exports.name = name;
|
|
37
|
+
exports.parse = parse;
|
|
38
|
+
exports.structure = structure;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const types = require('../../tokenizer/types.cjs');
|
|
4
|
+
|
|
5
|
+
const name = 'CDC';
|
|
6
|
+
const structure = [];
|
|
7
|
+
|
|
8
|
+
function parse() {
|
|
9
|
+
const start = this.tokenStart;
|
|
10
|
+
|
|
11
|
+
this.eat(types.CDC); // -->
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
type: 'CDC',
|
|
15
|
+
loc: this.getLocation(start, this.tokenStart)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function generate() {
|
|
20
|
+
this.token(types.CDC, '-->');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.generate = generate;
|
|
24
|
+
exports.name = name;
|
|
25
|
+
exports.parse = parse;
|
|
26
|
+
exports.structure = structure;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const types = require('../../tokenizer/types.cjs');
|
|
4
|
+
|
|
5
|
+
const name = 'CDO';
|
|
6
|
+
const structure = [];
|
|
7
|
+
|
|
8
|
+
function parse() {
|
|
9
|
+
const start = this.tokenStart;
|
|
10
|
+
|
|
11
|
+
this.eat(types.CDO); // <!--
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
type: 'CDO',
|
|
15
|
+
loc: this.getLocation(start, this.tokenStart)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function generate() {
|
|
20
|
+
this.token(types.CDO, '<!--');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.generate = generate;
|
|
24
|
+
exports.name = name;
|
|
25
|
+
exports.parse = parse;
|
|
26
|
+
exports.structure = structure;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const types = require('../../tokenizer/types.cjs');
|
|
4
|
+
|
|
5
|
+
const FULLSTOP = 0x002E; // U+002E FULL STOP (.)
|
|
6
|
+
|
|
7
|
+
// '.' ident
|
|
8
|
+
const name = 'ClassSelector';
|
|
9
|
+
const structure = {
|
|
10
|
+
name: String
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function parse() {
|
|
14
|
+
this.eatDelim(FULLSTOP);
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
type: 'ClassSelector',
|
|
18
|
+
loc: this.getLocation(this.tokenStart - 1, this.tokenEnd),
|
|
19
|
+
name: this.consume(types.Ident)
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function generate(node) {
|
|
24
|
+
this.token(types.Delim, '.');
|
|
25
|
+
this.token(types.Ident, node.name);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
exports.generate = generate;
|
|
29
|
+
exports.name = name;
|
|
30
|
+
exports.parse = parse;
|
|
31
|
+
exports.structure = structure;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const types = require('../../tokenizer/types.cjs');
|
|
4
|
+
|
|
5
|
+
const PLUSSIGN = 0x002B; // U+002B PLUS SIGN (+)
|
|
6
|
+
const SOLIDUS = 0x002F; // U+002F SOLIDUS (/)
|
|
7
|
+
const GREATERTHANSIGN = 0x003E; // U+003E GREATER-THAN SIGN (>)
|
|
8
|
+
const TILDE = 0x007E; // U+007E TILDE (~)
|
|
9
|
+
|
|
10
|
+
const name = 'Combinator';
|
|
11
|
+
const structure = {
|
|
12
|
+
name: String
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// + | > | ~ | /deep/
|
|
16
|
+
function parse() {
|
|
17
|
+
const start = this.tokenStart;
|
|
18
|
+
let name;
|
|
19
|
+
|
|
20
|
+
switch (this.tokenType) {
|
|
21
|
+
case types.WhiteSpace:
|
|
22
|
+
name = ' ';
|
|
23
|
+
break;
|
|
24
|
+
|
|
25
|
+
case types.Delim:
|
|
26
|
+
switch (this.charCodeAt(this.tokenStart)) {
|
|
27
|
+
case GREATERTHANSIGN:
|
|
28
|
+
case PLUSSIGN:
|
|
29
|
+
case TILDE:
|
|
30
|
+
this.next();
|
|
31
|
+
break;
|
|
32
|
+
|
|
33
|
+
case SOLIDUS:
|
|
34
|
+
this.next();
|
|
35
|
+
this.eatIdent('deep');
|
|
36
|
+
this.eatDelim(SOLIDUS);
|
|
37
|
+
break;
|
|
38
|
+
|
|
39
|
+
default:
|
|
40
|
+
this.error('Combinator is expected');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
name = this.substrToCursor(start);
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
type: 'Combinator',
|
|
49
|
+
loc: this.getLocation(start, this.tokenStart),
|
|
50
|
+
name
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function generate(node) {
|
|
55
|
+
this.tokenize(node.name);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.generate = generate;
|
|
59
|
+
exports.name = name;
|
|
60
|
+
exports.parse = parse;
|
|
61
|
+
exports.structure = structure;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const types = require('../../tokenizer/types.cjs');
|
|
4
|
+
|
|
5
|
+
const ASTERISK = 0x002A; // U+002A ASTERISK (*)
|
|
6
|
+
const SOLIDUS = 0x002F; // U+002F SOLIDUS (/)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const name = 'Comment';
|
|
10
|
+
const structure = {
|
|
11
|
+
value: String
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function parse() {
|
|
15
|
+
const start = this.tokenStart;
|
|
16
|
+
let end = this.tokenEnd;
|
|
17
|
+
|
|
18
|
+
this.eat(types.Comment);
|
|
19
|
+
|
|
20
|
+
if ((end - start + 2) >= 2 &&
|
|
21
|
+
this.charCodeAt(end - 2) === ASTERISK &&
|
|
22
|
+
this.charCodeAt(end - 1) === SOLIDUS) {
|
|
23
|
+
end -= 2;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
type: 'Comment',
|
|
28
|
+
loc: this.getLocation(start, this.tokenStart),
|
|
29
|
+
value: this.substring(start + 2, end)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function generate(node) {
|
|
34
|
+
this.token(types.Comment, '/*' + node.value + '*/');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.generate = generate;
|
|
38
|
+
exports.name = name;
|
|
39
|
+
exports.parse = parse;
|
|
40
|
+
exports.structure = structure;
|