@jesscss/css-parser 1.0.6-alpha.0 → 2.0.0-alpha.1

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.
Files changed (52) hide show
  1. package/lib/advancedActionsParser.d.ts +60 -0
  2. package/lib/advancedActionsParser.js +203 -0
  3. package/lib/advancedActionsParser.js.map +1 -0
  4. package/lib/cssActionsParser.d.ts +155 -0
  5. package/lib/cssActionsParser.js +376 -0
  6. package/lib/cssActionsParser.js.map +1 -0
  7. package/lib/cssErrorMessageProvider.d.ts +14 -0
  8. package/lib/cssErrorMessageProvider.js +40 -0
  9. package/lib/cssErrorMessageProvider.js.map +1 -0
  10. package/lib/cssParser.d.ts +36 -103
  11. package/lib/cssParser.js +75 -58
  12. package/lib/cssParser.js.map +1 -0
  13. package/lib/cssTokens.d.ts +539 -5
  14. package/lib/cssTokens.js +488 -232
  15. package/lib/cssTokens.js.map +1 -0
  16. package/lib/index.d.ts +8 -16
  17. package/lib/index.js +9 -41
  18. package/lib/index.js.map +1 -0
  19. package/lib/productions.d.ts +273 -0
  20. package/lib/productions.js +3499 -0
  21. package/lib/productions.js.map +1 -0
  22. package/lib/test/ast-serialize.test.d.ts +1 -0
  23. package/lib/test/ast-serialize.test.js +157 -0
  24. package/lib/test/ast-serialize.test.js.map +1 -0
  25. package/lib/test/container.test.d.ts +1 -0
  26. package/lib/test/container.test.js +369 -0
  27. package/lib/test/container.test.js.map +1 -0
  28. package/lib/test/css-files.test.d.ts +1 -0
  29. package/lib/test/css-files.test.js +21 -0
  30. package/lib/test/css-files.test.js.map +1 -0
  31. package/lib/test/less-output.test.d.ts +1 -0
  32. package/lib/test/less-output.test.js +52 -0
  33. package/lib/test/less-output.test.js.map +1 -0
  34. package/lib/util/cst.d.ts +7 -2
  35. package/lib/util/cst.js +5 -9
  36. package/lib/util/cst.js.map +1 -0
  37. package/lib/util/index.d.ts +19 -13
  38. package/lib/util/index.js +98 -87
  39. package/lib/util/index.js.map +1 -0
  40. package/package.json +43 -20
  41. package/lib/productions/atRules.d.ts +0 -2
  42. package/lib/productions/atRules.js +0 -196
  43. package/lib/productions/blocks.d.ts +0 -2
  44. package/lib/productions/blocks.js +0 -181
  45. package/lib/productions/declarations.d.ts +0 -14
  46. package/lib/productions/declarations.js +0 -59
  47. package/lib/productions/root.d.ts +0 -2
  48. package/lib/productions/root.js +0 -49
  49. package/lib/productions/selectors.d.ts +0 -2
  50. package/lib/productions/selectors.js +0 -223
  51. package/lib/productions/values.d.ts +0 -2
  52. package/lib/productions/values.js +0 -114
@@ -1,14 +0,0 @@
1
- import type { CssParser, CstNode, IToken } from '../cssParser';
2
- export interface Declaration extends CstNode {
3
- name: 'declaration';
4
- children: [
5
- name: IToken,
6
- postNameWs: IToken,
7
- assign: IToken,
8
- preValueWs: IToken,
9
- value: CstNode,
10
- important: CstNode,
11
- semi: IToken
12
- ];
13
- }
14
- export default function (this: CssParser, $: CssParser): void;
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function default_1($) {
4
- /**
5
- * e.g.
6
- * color: red
7
- */
8
- $.declaration = $.RULE('declaration', () => ({
9
- name: 'declaration',
10
- children: [
11
- $.SUBRULE($.property),
12
- $._(0),
13
- $.CONSUME($.T.Assign),
14
- $._(1),
15
- $.SUBRULE($.expressionList),
16
- $.OPTION(() => ({
17
- name: 'important',
18
- children: [
19
- $.CONSUME($.T.Important),
20
- $._(2)
21
- ]
22
- })),
23
- $.OPTION2(() => $.CONSUME($.T.SemiColon))
24
- ]
25
- }));
26
- /**
27
- * e.g.
28
- * --color: { ;red }
29
- */
30
- $.customDeclaration = $.RULE('customDeclaration', () => ({
31
- name: 'declaration',
32
- children: [
33
- $.SUBRULE($.customProperty),
34
- $._(0),
35
- $.CONSUME($.T.Assign),
36
- $._(1),
37
- $.SUBRULE($.customValue),
38
- /** !important can be part of customValue */
39
- undefined,
40
- $.OPTION(() => $.CONSUME($.T.SemiColon))
41
- ]
42
- }));
43
- /** "color" in "color: red" */
44
- $.property = $.RULE('property', () => ({
45
- name: 'property',
46
- children: $.OR([
47
- { ALT: () => [$.CONSUME($.T.Ident)] },
48
- {
49
- /** Legacy - remove? */
50
- ALT: () => [
51
- $.CONSUME($.T.Star),
52
- $.CONSUME2($.T.Ident)
53
- ]
54
- }
55
- ])
56
- }));
57
- $.customProperty = $.RULE('customProperty', () => $.CONSUME($.T.CustomProperty));
58
- }
59
- exports.default = default_1;
@@ -1,2 +0,0 @@
1
- import type { CssParser } from '../cssParser';
2
- export default function (this: CssParser, $: CssParser): void;
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const chevrotain_1 = require("chevrotain");
4
- function default_1($) {
5
- /** Optional whitespace */
6
- $._ = function (idx = 0, options) {
7
- // +10 to avoid conflicts with other OPTION in the calling rule.
8
- return $.option(idx + 10, () => $.consume(idx + 10, $.T.WS, options));
9
- };
10
- /** Stylesheet */
11
- $.root = $.RULE('root', () => ({
12
- name: 'root',
13
- children: $.SUBRULE($.primary)
14
- }));
15
- /** List of rules */
16
- $.primary = $.RULE('primary', () => {
17
- const rules = [];
18
- $.MANY(() => rules.push($.SUBRULE($.rule)));
19
- const ws = $._();
20
- if (ws) {
21
- rules.push(ws);
22
- }
23
- return rules;
24
- });
25
- /** Rule with leading ws / comments */
26
- $.rule = $.RULE('rule', () => {
27
- const children = [$._()];
28
- const rule = $.OR([
29
- { ALT: () => $.SUBRULE($.atRule) },
30
- { ALT: () => $.SUBRULE($.customDeclaration) },
31
- {
32
- GATE: $.BACKTRACK($.testQualifiedRule),
33
- ALT: () => $.SUBRULE($.qualifiedRule)
34
- },
35
- { ALT: () => $.SUBRULE($.declaration) },
36
- /** Capture any isolated / redundant semi-colons */
37
- { ALT: () => $.CONSUME($.T.SemiColon) },
38
- { ALT: () => chevrotain_1.EMPTY_ALT }
39
- ]);
40
- if (rule !== chevrotain_1.EMPTY_ALT) {
41
- children.push(rule);
42
- }
43
- return {
44
- name: 'rule',
45
- children
46
- };
47
- });
48
- }
49
- exports.default = default_1;
@@ -1,2 +0,0 @@
1
- import type { CssParser } from '../cssParser';
2
- export default function (this: CssParser, $: CssParser): void;
@@ -1,223 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function default_1($) {
4
- /** A comma-separated list of selectors */
5
- $.selectorList = $.RULE('selectorList', () => {
6
- const children = [
7
- $.SUBRULE($.complexSelector)
8
- ];
9
- $.MANY(() => {
10
- children.push({
11
- name: 'delimiter',
12
- children: [
13
- $.CONSUME($.T.Comma),
14
- $._(1)
15
- ]
16
- }, $.SUBRULE2($.complexSelector));
17
- });
18
- return {
19
- name: 'selectorList',
20
- children
21
- };
22
- });
23
- /**
24
- * "A complex selector is a sequence of one or more compound selectors
25
- * separated by combinators. It represents a set of simultaneous
26
- * conditions on a set of elements in the particular relationships
27
- * described by its combinators."
28
- *
29
- * For simplicity, this is returned as a stream of selectors
30
- * and combinators.
31
- *
32
- * @see https://www.w3.org/TR/selectors-4/#structure
33
- */
34
- $.complexSelector = $.RULE('complexSelector', () => {
35
- const children = [
36
- $.SUBRULE($.compoundSelector)
37
- ];
38
- $.MANY(() => children.push($.SUBRULE($.combinatorSelector)));
39
- children.push($._());
40
- return {
41
- name: 'complexSelector',
42
- children
43
- };
44
- });
45
- /**
46
- * A combinator, then a compound selector
47
- * e.g. `> div.class`
48
- */
49
- $.combinatorSelector = $.RULE('combinatorSelector', () => ({
50
- name: 'combinatorSelector',
51
- children: $.OR([
52
- {
53
- ALT: () => [
54
- /**
55
- * Combinator with optional whitespace
56
- */
57
- {
58
- name: 'combinator',
59
- children: [
60
- undefined,
61
- $.CONSUME($.T.Combinator),
62
- $.OPTION(() => $.CONSUME($.T.WS))
63
- ]
64
- },
65
- $.SUBRULE2($.compoundSelector)
66
- ]
67
- },
68
- {
69
- /**
70
- * Whitespace with optional combinator,
71
- * (or we treat as trailing ws)
72
- */
73
- ALT: () => {
74
- const children = [
75
- $.CONSUME2($.T.WS)
76
- ];
77
- let sel;
78
- $.OPTION2(() => {
79
- $.OPTION3(() => {
80
- children.push($.CONSUME2($.T.Combinator));
81
- $.OPTION4(() => children.push($.CONSUME3($.T.WS)));
82
- });
83
- sel = $.SUBRULE3($.compoundSelector);
84
- });
85
- if (sel) {
86
- return [
87
- {
88
- name: 'combinator',
89
- children: children.length === 1 ? [undefined, children[0]] : children
90
- },
91
- sel
92
- ];
93
- }
94
- return children;
95
- }
96
- }
97
- ])
98
- }));
99
- /**
100
- * "A compound selector is a sequence of simple selectors that are not separated by a combinator,
101
- * and represents a set of simultaneous conditions on a single element. If it contains a type
102
- * selector or universal selector, that selector must come first in the sequence."
103
- *
104
- * @see https://www.w3.org/TR/selectors-4/#structure
105
- */
106
- $.compoundSelector = $.RULE('compoundSelector', () => ({
107
- name: 'compoundSelector',
108
- children: $.OR([
109
- { ALT: () => [$.CONSUME($.T.Star)] },
110
- {
111
- ALT: () => {
112
- const children = [];
113
- $.AT_LEAST_ONE(() => children.push($.SUBRULE($.simpleSelector)));
114
- return children;
115
- }
116
- }
117
- ])
118
- }));
119
- /**
120
- * "A simple selector is a single condition on an element. A type selector,
121
- * universal selector, attribute selector, class selector, ID selector,
122
- * or pseudo-class is a simple selector."
123
- *
124
- * @see https://www.w3.org/TR/selectors-4/#structure
125
- */
126
- $.simpleSelector = $.RULE('simpleSelector', () => $.OR([
127
- { ALT: () => $.SUBRULE($.pseudoSelector) },
128
- { ALT: () => $.SUBRULE($.attrSelector) },
129
- { ALT: () => $.SUBRULE($.nameSelector) },
130
- /** Used in keyframes as a selector */
131
- { ALT: () => $.CONSUME($.T.Dimension) }
132
- ]));
133
- /** e.g. `:pseudo` | `::pseudo` | `:pseudo()` */
134
- $.pseudoSelector = $.RULE('pseudoSelector', () => {
135
- const pseudoName = [$.CONSUME($.T.Colon)];
136
- $.OPTION(() => pseudoName.push($.CONSUME2($.T.Colon)));
137
- const getName = () => ({
138
- name: 'pseudoName',
139
- children: pseudoName
140
- });
141
- let args;
142
- let R;
143
- $.OR2([
144
- {
145
- ALT: () => {
146
- pseudoName.push($.CONSUME($.T.Ident));
147
- /** Handle functions parsed as idents (like `not`) */
148
- $.OPTION2(() => {
149
- pseudoName.push($.CONSUME($.T.LParen));
150
- args = $.SUBRULE($.expressionList),
151
- R = $.CONSUME($.T.RParen);
152
- });
153
- }
154
- },
155
- {
156
- /** e.g. :pseudo(...) */
157
- ALT: () => {
158
- pseudoName.push($.CONSUME($.T.Function));
159
- args = $.SUBRULE2($.expressionList),
160
- R = $.CONSUME2($.T.RParen);
161
- }
162
- }
163
- ]);
164
- return {
165
- name: 'pseudoSelector',
166
- children: [
167
- getName(),
168
- args,
169
- R
170
- ]
171
- };
172
- });
173
- /** e.g. [id^="bar"] [*|ns|="foo"] */
174
- $.attrSelector = $.RULE('attrSelector', () => {
175
- const attr = [];
176
- const L = $.CONSUME($.T.LSquare);
177
- let eq, value;
178
- $.OR([
179
- { ALT: () => {
180
- $.OPTION(() => attr.push($.CONSUME($.T.Star)));
181
- attr.push($.CONSUME($.T.Pipe), $.SUBRULE($.attrIdent));
182
- } },
183
- { ALT: () => {
184
- attr.push($.SUBRULE2($.attrIdent));
185
- $.OPTION2(() => {
186
- attr.push($.CONSUME2($.T.Pipe), $.SUBRULE3($.attrIdent));
187
- });
188
- } }
189
- ]);
190
- $.OPTION4(() => {
191
- eq = $.OR2([
192
- { ALT: () => $.CONSUME($.T.Eq) },
193
- { ALT: () => $.CONSUME($.T.AttrMatch) }
194
- ]);
195
- value = $.OR3([
196
- { ALT: () => $.SUBRULE4($.attrIdent) },
197
- { ALT: () => $.CONSUME3($.T.Dimension) },
198
- { ALT: () => $.CONSUME($.T.StringLiteral) }
199
- ]);
200
- });
201
- const R = $.CONSUME($.T.RSquare);
202
- return {
203
- name: 'attrSelector',
204
- children: [
205
- L,
206
- {
207
- name: 'attr',
208
- children: attr
209
- },
210
- eq,
211
- value,
212
- R
213
- ]
214
- };
215
- });
216
- /** Separated out for Less overriding */
217
- $.attrIdent = $.RULE('attrIdent', () => $.CONSUME($.T.Ident));
218
- $.nameSelector = $.RULE('nameSelector', () => $.OR([
219
- { ALT: () => $.CONSUME($.T.Selector) },
220
- { ALT: () => $.CONSUME($.T.Ident) }
221
- ]));
222
- }
223
- exports.default = default_1;
@@ -1,2 +0,0 @@
1
- import type { CssParser } from '../cssParser';
2
- export default function (this: CssParser, $: CssParser): void;
@@ -1,114 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function default_1($) {
4
- /**
5
- * A custom property's (or unknown at-rule's) outer value
6
- */
7
- $.customValue = $.RULE('customValue', () => {
8
- const children = [];
9
- $.MANY(() => children.push($.OR([
10
- { ALT: () => $.SUBRULE($.anyToken) },
11
- { ALT: () => $.SUBRULE($.extraTokens) },
12
- { ALT: () => $.SUBRULE($.customBlock) }
13
- ])));
14
- return {
15
- name: 'customValue',
16
- children
17
- };
18
- });
19
- $.customPrelude = $.RULE('customPrelude', () => {
20
- const children = [];
21
- $.MANY(() => children.push($.OR([
22
- { ALT: () => $.SUBRULE($.anyToken) },
23
- { ALT: () => $.SUBRULE($.extraTokens) },
24
- { ALT: () => $.SUBRULE($.customPreludeBlock) }
25
- ])));
26
- return {
27
- name: 'customPrelude',
28
- children
29
- };
30
- });
31
- /**
32
- * A custom value within a block
33
- */
34
- $.customValueOrSemi = $.RULE('customValueOrSemi', () => {
35
- const children = [];
36
- $.MANY(() => children.push($.OR([
37
- { ALT: () => $.CONSUME($.T.SemiColon) },
38
- { ALT: () => $.SUBRULE($.anyToken) },
39
- { ALT: () => $.SUBRULE($.extraTokens) },
40
- { ALT: () => $.SUBRULE($.customBlock) }
41
- ])));
42
- return {
43
- name: 'customValue',
44
- children
45
- };
46
- });
47
- /**
48
- * Expressions separated by commas
49
- * e.g. `one, two, three`
50
- */
51
- $.expressionList = $.RULE('expressionList', () => {
52
- const children = [$.SUBRULE($.expression)];
53
- $.MANY(() => {
54
- children.push($.CONSUME($.T.Comma), $.SUBRULE2($.expression));
55
- });
56
- if (children.length === 1) {
57
- return children[0];
58
- }
59
- return {
60
- name: 'expressionList',
61
- children
62
- };
63
- });
64
- /**
65
- * An expression contains values and spaces
66
- */
67
- $.expression = $.RULE('expression', () => {
68
- const children = [];
69
- $.MANY(() => children.push($.SUBRULE($.value)));
70
- if (children.length === 1) {
71
- return children[0];
72
- }
73
- return {
74
- name: 'expression',
75
- children
76
- };
77
- });
78
- /**
79
- * According to a reading of the spec, whitespace is a valid
80
- * value in a CSS list, e.g. in the custom properties spec,
81
- * `--custom: ;` has a value of ' '
82
- *
83
- * However, a property's grammar may discard whitespace between values.
84
- * e.g. for `color: black`, the value in the browser will resolve to `black`
85
- * and not ` black`. The CSS spec is rather hand-wavy about whitespace,
86
- * sometimes mentioning it specifically, sometimes not representing it
87
- * in grammar even though it's expected to be present.
88
- *
89
- * Strictly speaking, though, a property's value begins _immediately_
90
- * following a ':' and ends at ';' (or until automatically closed by
91
- * '}', ']', ')' or the end of a file).
92
- */
93
- $.value = $.RULE('value', () => $.OR([
94
- { ALT: () => $.SUBRULE($.block) },
95
- { ALT: () => $.SUBRULE($.anyToken) }
96
- ]));
97
- $.anyToken = $.RULE('anyToken', () => $.OR([
98
- { ALT: () => $.CONSUME($.T.Value) },
99
- /** Can be in a var() function */
100
- { ALT: () => $.CONSUME($.T.CustomProperty) },
101
- { ALT: () => $.CONSUME($.T.Colon) },
102
- { ALT: () => $.CONSUME($.T.WS) }
103
- ]));
104
- /**
105
- * Extra tokens in a custom property. Should include any
106
- * and every token possible, including unknown tokens.
107
- */
108
- $.extraTokens = $.RULE('extraTokens', () => $.OR([
109
- { ALT: () => $.CONSUME($.T.AtName) },
110
- { ALT: () => $.CONSUME($.T.Comma) },
111
- { ALT: () => $.CONSUME($.T.Important) }
112
- ]));
113
- }
114
- exports.default = default_1;