forked from sveltejs/svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
css_tree_parse.js
98 lines (85 loc) · 2.14 KB
/
css_tree_parse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// @ts-nocheck
import { fork } from 'css-tree';
import { String, Url, Function, Ident, Semicolon } from 'css-tree/tokenizer';
import * as node from './node/index.js';
/**
* Extends `css-tree` for container query support by forking and adding new nodes and at-rule support for `@container`.
*
* The new nodes are located in `./node`.
*/
const cqSyntax = fork({
atrule: {
// extend or override at-rule dictionary
container: {
parse: {
prelude() {
return this.createSingleNodeList(this.ContainerQuery());
},
block(isStyleBlock = false) {
return this.Block(isStyleBlock);
}
}
},
// TODO: Wait until css-tree supports layer() or supports() for import and remove this
import: {
parse: {
prelude() {
const children = this.createList();
this.skipSC();
switch (this.tokenType) {
case String:
children.push(this.String());
break;
case Url:
case Function:
children.push(this.Url());
break;
}
this.skipSC();
if (
this.tokenType === Function &&
this.cmpStr(this.tokenStart, this.tokenEnd, 'layer(')
) {
children.push(
this.Function(() => {
const children = this.createList();
this.skipSC();
children.push(this.LayerName());
this.skipSC();
return children;
}, this.scope.AtrulePrelude)
);
} else if (
this.tokenType === Ident &&
this.cmpStr(this.tokenStart, this.tokenEnd, 'layer')
) {
children.push(this.Identifier());
}
this.skipSC();
if (
this.tokenType === Function &&
this.cmpStr(this.tokenStart, this.tokenEnd, 'supports(')
) {
children.push(
this.Function(() => {
const children = this.createList();
this.skipSC();
children.push(this.SupportsCondition());
this.skipSC();
return children;
}, this.scope.AtrulePrelude)
);
}
this.skipSC();
if (this.tokenType !== Semicolon) {
children.push(this.MediaQueryList());
}
return children;
},
block: null
}
}
},
node
});
export const parse = cqSyntax.parse;