@tbela99/css-parser 1.8.2 → 2.0.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.
- package/CHANGELOG.md +66 -0
- package/README.md +129 -31
- package/dist/index-umd-web.js +27383 -24083
- package/dist/index.d.ts +2737 -2200
- package/dist/package.json.js +2 -2
- package/dist/src/data/properties.json.js +1 -1
- package/dist/src/data/validation.json.js +1 -1
- package/dist/src/lib/ast/arena-node.js +548 -0
- package/dist/src/lib/ast/arena.js +3198 -0
- package/dist/src/lib/ast/cache.js +333 -0
- package/dist/src/lib/ast/features/calc.js +85 -76
- package/dist/src/lib/ast/features/if.js +155 -115
- package/dist/src/lib/ast/features/index.js +1 -1
- package/dist/src/lib/ast/features/inlinecssvariables.js +77 -84
- package/dist/src/lib/ast/features/prefix.js +184 -183
- package/dist/src/lib/ast/features/shorthand.js +40 -46
- package/dist/src/lib/ast/features/transform.js +24 -24
- package/dist/src/lib/ast/features/type.js +1 -1
- package/dist/src/lib/ast/math/expression.js +458 -543
- package/dist/src/lib/ast/math/math.js +19 -41
- package/dist/src/lib/ast/minify.js +590 -647
- package/dist/src/lib/ast/transform/compute.js +82 -85
- package/dist/src/lib/ast/transform/matrix.js +21 -38
- package/dist/src/lib/ast/transform/minify.js +82 -193
- package/dist/src/lib/ast/transform/perspective.js +2 -3
- package/dist/src/lib/ast/transform/rotate.js +1 -1
- package/dist/src/lib/ast/transform/scale.js +1 -1
- package/dist/src/lib/ast/transform/skew.js +1 -1
- package/dist/src/lib/ast/transform/translate.js +1 -1
- package/dist/src/lib/ast/transform/utils.js +2 -2
- package/dist/src/lib/ast/types.js +263 -258
- package/dist/src/lib/ast/walk.js +246 -610
- package/dist/src/lib/fs/resolve.js +1 -1
- package/dist/src/lib/parser/declaration/list.js +223 -139
- package/dist/src/lib/parser/declaration/map.js +251 -238
- package/dist/src/lib/parser/declaration/set.js +74 -66
- package/dist/src/lib/parser/linesmap.js +1 -1
- package/dist/src/lib/parser/parse.js +1379 -1658
- package/dist/src/lib/parser/source.js +7 -4
- package/dist/src/lib/parser/tokenize.js +406 -199
- package/dist/src/lib/parser/utils/angle.js +11 -13
- package/dist/src/lib/parser/utils/at-rule-container.js +183 -168
- package/dist/src/lib/parser/utils/at-rule-font-feature-values.js +5 -5
- package/dist/src/lib/parser/utils/at-rule-generic.js +31 -24
- package/dist/src/lib/parser/utils/at-rule-import.js +44 -44
- package/dist/src/lib/parser/utils/at-rule-media.js +216 -205
- package/dist/src/lib/parser/utils/at-rule-support.js +83 -88
- package/dist/src/lib/parser/utils/at-rule-when-else.js +47 -47
- package/dist/src/lib/parser/utils/at-rule.js +5 -5
- package/dist/src/lib/parser/utils/base64.js +2 -2
- package/dist/src/lib/parser/utils/cache.js +1 -1
- package/dist/src/lib/parser/utils/config.js +1 -1
- package/dist/src/lib/parser/utils/declaration.js +233 -234
- package/dist/src/lib/parser/utils/eq.js +50 -3
- package/dist/src/lib/parser/utils/hash.js +2 -35
- package/dist/src/lib/parser/utils/selector.js +309 -387
- package/dist/src/lib/parser/utils/text.js +18 -4
- package/dist/src/lib/parser/utils/token.js +16 -69
- package/dist/src/lib/parser/utils/type.js +37 -24
- package/dist/src/lib/printer/render.js +965 -511
- package/dist/src/lib/printer/sourcemap/lib/codec.js +1 -1
- package/dist/src/lib/printer/sourcemap/sourcemap.js +1 -1
- package/dist/src/lib/syntax/color/a98rgb.js +1 -1
- package/dist/src/lib/syntax/color/alpha.js +36 -37
- package/dist/src/lib/syntax/color/cmyk.js +35 -52
- package/dist/src/lib/syntax/color/color-mix.js +96 -132
- package/dist/src/lib/syntax/color/color.js +222 -231
- package/dist/src/lib/syntax/color/hex.js +45 -55
- package/dist/src/lib/syntax/color/hsl.js +54 -62
- package/dist/src/lib/syntax/color/hwb.js +60 -68
- package/dist/src/lib/syntax/color/lab.js +59 -67
- package/dist/src/lib/syntax/color/lch.js +59 -67
- package/dist/src/lib/syntax/color/oklab.js +60 -68
- package/dist/src/lib/syntax/color/oklch.js +60 -67
- package/dist/src/lib/syntax/color/p3.js +1 -1
- package/dist/src/lib/syntax/color/prophotorgb.js +1 -1
- package/dist/src/lib/syntax/color/rec2020.js +1 -1
- package/dist/src/lib/syntax/color/relative-color.js +94 -144
- package/dist/src/lib/syntax/color/rgb.js +54 -57
- package/dist/src/lib/syntax/color/srgb.js +55 -53
- package/dist/src/lib/syntax/color/utils/color-type.js +13 -10
- package/dist/src/lib/syntax/color/utils/colorspace.js +11 -11
- package/dist/src/lib/syntax/color/utils/components.js +19 -20
- package/dist/src/lib/syntax/color/utils/distance.js +15 -13
- package/dist/src/lib/syntax/color/utils/make-color.js +15 -19
- package/dist/src/lib/syntax/color/utils/matrix.js +2 -2
- package/dist/src/lib/syntax/color/xyz.js +1 -1
- package/dist/src/lib/syntax/color/xyzd50.js +1 -1
- package/dist/src/lib/syntax/constants.js +2 -16
- package/dist/src/lib/syntax/syntax.js +301 -407
- package/dist/src/lib/validation/config.js +1 -1
- package/dist/src/lib/validation/match.js +959 -723
- package/dist/src/lib/validation/parser/parse.js +230 -112
- package/dist/src/lib/validation/parser/typedef.js +1 -1
- package/dist/src/lib/validation/utils/list.js +27 -12
- package/dist/src/node.js +12 -72
- package/dist/src/types.js +1 -1
- package/dist/src/utils/sync.js +9 -6
- package/dist/src/web.js +11 -73
- package/package.json +9 -10
- package/dist/index.cjs +0 -35870
- package/dist/src/lib/ast/clone.js +0 -51
- package/dist/src/lib/ast/expand.js +0 -311
- package/dist/src/lib/ast/find.js +0 -192
- package/dist/src/lib/ast/node.js +0 -59
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version:
|
|
5
|
+
Version: 2.0.1
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { PropertySet } from './set.js';
|
|
@@ -11,12 +11,69 @@ import { PropertyMap } from './map.js';
|
|
|
11
11
|
import { EnumAstNodeStatus, EnumToken } from '../../ast/types.js';
|
|
12
12
|
import { getParsedSyntax } from '../../validation/config.js';
|
|
13
13
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
14
|
+
import { isValidDeclarationValue } from '../../validation/match.js';
|
|
15
|
+
import { equalsIgnoreCase, lowercase } from '../utils/text.js';
|
|
16
|
+
import { StructuralMemo } from '../../ast/cache.js';
|
|
17
|
+
import { parseString } from '../parse.js';
|
|
18
18
|
|
|
19
19
|
const config = getConfig();
|
|
20
|
+
/**
|
|
21
|
+
* Results shared by the property lists of a minification, valid for the arena they were computed for:
|
|
22
|
+
* - the keys of the declarations that are not merged by name (invalid declarations, custom properties, comments, ...):
|
|
23
|
+
* identical declarations have the same key
|
|
24
|
+
* - the tokens of the default values of the shorthand properties: each value is parsed once, the tokens are cloned
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
class DeclarationMemo {
|
|
29
|
+
/**
|
|
30
|
+
* An instance is kept alive: the hidden class of the instances would otherwise be collected by a full garbage
|
|
31
|
+
* collection when no instance is alive, and the optimized code that depends on it discarded (deoptimized)
|
|
32
|
+
*/
|
|
33
|
+
static shape = new DeclarationMemo();
|
|
34
|
+
/**
|
|
35
|
+
* key by structure. same equality as the structural signature: 0 and -0 are equal
|
|
36
|
+
*/
|
|
37
|
+
keys = new StructuralMemo(true);
|
|
38
|
+
/**
|
|
39
|
+
* parsed values: detached tokens that are cloned, never attached to the tree
|
|
40
|
+
*/
|
|
41
|
+
parsed = new Map();
|
|
42
|
+
/**
|
|
43
|
+
* tokens of a value, see {@link parseString}. the value is parsed once, the tokens are cloned
|
|
44
|
+
* @param arena
|
|
45
|
+
* @param value
|
|
46
|
+
*/
|
|
47
|
+
parse(arena, value) {
|
|
48
|
+
let template = this.parsed.get(value);
|
|
49
|
+
if (template === undefined) {
|
|
50
|
+
template = parseString(arena, value);
|
|
51
|
+
this.parsed.set(value, template);
|
|
52
|
+
}
|
|
53
|
+
const tokens = new Array(template.length);
|
|
54
|
+
for (let i = 0; i < template.length; i++) {
|
|
55
|
+
tokens[i] = arena.clone(template[i], true);
|
|
56
|
+
}
|
|
57
|
+
return tokens;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* unique key of the structure of a node (type, name, values, tokens and children). identical nodes have the same key
|
|
61
|
+
* @param arena
|
|
62
|
+
* @param node
|
|
63
|
+
*/
|
|
64
|
+
key(arena, node) {
|
|
65
|
+
const slot = this.keys.token(arena, node);
|
|
66
|
+
// inlined: this.keys.get(slot)
|
|
67
|
+
let key = this.keys.values[slot];
|
|
68
|
+
if (key === undefined) {
|
|
69
|
+
// not a property name
|
|
70
|
+
key = "\0" + slot;
|
|
71
|
+
// inlined: this.keys.set(slot, key)
|
|
72
|
+
this.keys.values[slot] = key;
|
|
73
|
+
}
|
|
74
|
+
return key;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
20
77
|
/**
|
|
21
78
|
* Represents a list of property declarations, compute shorthand and remove duplicate declarations.
|
|
22
79
|
*/
|
|
@@ -29,155 +86,181 @@ class PropertyList {
|
|
|
29
86
|
* declarations
|
|
30
87
|
*/
|
|
31
88
|
declarations;
|
|
89
|
+
/**
|
|
90
|
+
* arena the declarations are stored in
|
|
91
|
+
*/
|
|
92
|
+
arena;
|
|
93
|
+
/**
|
|
94
|
+
* keys shared by the lists that use the same arena
|
|
95
|
+
*/
|
|
96
|
+
memo;
|
|
32
97
|
/**
|
|
33
98
|
*
|
|
99
|
+
* @param arena
|
|
34
100
|
* @param options
|
|
101
|
+
* @param memo keys shared by the lists that use the same arena
|
|
35
102
|
*/
|
|
36
|
-
constructor(options = {}) {
|
|
103
|
+
constructor(arena, options = {}, memo = null) {
|
|
104
|
+
this.arena = arena;
|
|
37
105
|
this.options = options;
|
|
38
106
|
this.declarations = new Map();
|
|
107
|
+
this.memo = memo ?? new DeclarationMemo();
|
|
39
108
|
}
|
|
40
109
|
/**
|
|
41
110
|
* add declarations
|
|
42
|
-
* @param declarations
|
|
111
|
+
* @param declarations node ids
|
|
43
112
|
* @returns
|
|
44
113
|
*/
|
|
45
114
|
add(declarations) {
|
|
115
|
+
for (const declaration of declarations) {
|
|
116
|
+
this.addDeclaration(declaration);
|
|
117
|
+
}
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* add a declaration
|
|
122
|
+
* @param declaration node id
|
|
123
|
+
*/
|
|
124
|
+
addDeclaration(declaration) {
|
|
46
125
|
let name;
|
|
47
126
|
let syntaxRules = null;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
127
|
+
const arena = this.arena;
|
|
128
|
+
name =
|
|
129
|
+
arena.dataTypes[declaration] != EnumToken.DeclarationNodeType
|
|
130
|
+
? null
|
|
131
|
+
: arena.strings[arena.name[declaration]];
|
|
132
|
+
// do not compute shorthand for invalid declarations
|
|
133
|
+
if (name == null) {
|
|
134
|
+
this.declarations.set(this.memo.key(arena, declaration), declaration);
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
// @functiom / result
|
|
138
|
+
if (arena.flags[declaration] & EnumAstNodeStatus.Unknown && equalsIgnoreCase("result", name)) {
|
|
139
|
+
this.declarations.set(name, declaration);
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
if (arena.flags[declaration] &
|
|
143
|
+
(EnumAstNodeStatus.Invalid | EnumAstNodeStatus.Unknown | EnumAstNodeStatus.ValidationFailed) ||
|
|
144
|
+
equalsIgnoreCase("composes", name) ||
|
|
145
|
+
(typeof this.options.removeDuplicateDeclarations === "string" &&
|
|
146
|
+
this.options.removeDuplicateDeclarations === name) ||
|
|
147
|
+
(Array.isArray(this.options.removeDuplicateDeclarations)
|
|
148
|
+
? this.options.removeDuplicateDeclarations.includes(name)
|
|
149
|
+
: !this.options.removeDuplicateDeclarations)) {
|
|
150
|
+
const key = this.memo.key(arena, declaration);
|
|
151
|
+
if (this.declarations.has(key)) {
|
|
152
|
+
this.declarations.delete(key);
|
|
55
153
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
154
|
+
this.declarations.set(key, declaration);
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
if (!this.options.computeShorthand) {
|
|
158
|
+
this.declarations.set(name, declaration);
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
if (arena.flags[declaration] & EnumAstNodeStatus.Unvalidated) {
|
|
162
|
+
syntaxRules = getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, lowercase(name));
|
|
163
|
+
if (syntaxRules != null) {
|
|
164
|
+
arena.flags[declaration] |=
|
|
165
|
+
(isValidDeclarationValue(arena, syntaxRules, declaration, this.options)
|
|
166
|
+
? EnumAstNodeStatus.Validated
|
|
167
|
+
: EnumAstNodeStatus.ValidationFailed) & ~EnumAstNodeStatus.Unvalidated;
|
|
60
168
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
169
|
+
}
|
|
170
|
+
// do not compute shorthand for invalid declarations
|
|
171
|
+
if (!(arena.flags[declaration] & EnumAstNodeStatus.Validated)) {
|
|
172
|
+
this.declarations.set(this.memo.key(arena, declaration), declaration);
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
let propertyName = name;
|
|
176
|
+
let shortHandType;
|
|
177
|
+
let shorthand = null;
|
|
178
|
+
if (propertyName in config.properties) {
|
|
179
|
+
// @ts-ignore
|
|
180
|
+
if ("map" in config.properties[propertyName]) {
|
|
181
|
+
shortHandType = "map";
|
|
182
|
+
// @ts-ignore
|
|
183
|
+
shorthand = config.properties[propertyName].map;
|
|
76
184
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
185
|
+
else {
|
|
186
|
+
shortHandType = "set";
|
|
187
|
+
// @ts-ignore
|
|
188
|
+
shorthand = config.properties[propertyName].shorthand;
|
|
80
189
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
190
|
+
}
|
|
191
|
+
else if (propertyName in config.map) {
|
|
192
|
+
shortHandType = "map";
|
|
193
|
+
// @ts-ignore
|
|
194
|
+
shorthand = config.map[propertyName].shorthand;
|
|
195
|
+
}
|
|
196
|
+
else if (propertyName in config.property) {
|
|
197
|
+
shortHandType = "single";
|
|
198
|
+
// @ts-ignore
|
|
199
|
+
shorthand = config.property[propertyName];
|
|
200
|
+
}
|
|
201
|
+
if (this.declarations.has(shorthand)) {
|
|
202
|
+
let existing = this.declarations.get(shorthand);
|
|
203
|
+
if (existing instanceof PropertySet || existing instanceof PropertyMap) {
|
|
204
|
+
existing = existing.declarations.get(name);
|
|
89
205
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
206
|
+
if (existing != null &&
|
|
207
|
+
typeof existing == "number" &&
|
|
208
|
+
arena.flags[existing] & EnumAstNodeStatus.ImportantDeclaration &&
|
|
209
|
+
arena.flags[declaration] & ~EnumAstNodeStatus.ImportantDeclaration) {
|
|
210
|
+
return this;
|
|
94
211
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
else {
|
|
106
|
-
shortHandType = "set";
|
|
212
|
+
}
|
|
213
|
+
// @ts-ignore
|
|
214
|
+
if (shortHandType == "map") {
|
|
215
|
+
let owner = this;
|
|
216
|
+
const mapName =
|
|
217
|
+
// @ts-ignore
|
|
218
|
+
config.map[propertyName]?.map ?? config.map[shorthand]?.properties?.[propertyName]?.map;
|
|
219
|
+
if (typeof mapName === "string") {
|
|
220
|
+
if (!this.declarations.has(mapName)) {
|
|
221
|
+
this.declarations.set(mapName,
|
|
107
222
|
// @ts-ignore
|
|
108
|
-
|
|
223
|
+
new PropertyMap(arena, config.map[mapName], this.memo));
|
|
109
224
|
}
|
|
225
|
+
owner = this.declarations.get(mapName);
|
|
110
226
|
}
|
|
111
|
-
else if (
|
|
112
|
-
shortHandType = "map";
|
|
227
|
+
else if (!this.declarations.has(shorthand)) {
|
|
113
228
|
// @ts-ignore
|
|
114
|
-
shorthand
|
|
229
|
+
this.declarations.set(shorthand, new PropertyMap(arena, config.map[shorthand], this.memo));
|
|
115
230
|
}
|
|
116
|
-
|
|
117
|
-
shortHandType = "single";
|
|
231
|
+
if (owner == this) {
|
|
118
232
|
// @ts-ignore
|
|
119
|
-
shorthand
|
|
120
|
-
}
|
|
121
|
-
if (this.declarations.has(shorthand)) {
|
|
122
|
-
let existing = this.declarations.get(shorthand);
|
|
123
|
-
if (existing instanceof PropertySet || existing instanceof PropertyMap) {
|
|
124
|
-
existing = existing.declarations.get(declaration.nam);
|
|
125
|
-
}
|
|
126
|
-
if (existing?.[STATE] & EnumAstNodeStatus.ImportantDeclaration &&
|
|
127
|
-
declaration[STATE] & ~EnumAstNodeStatus.ImportantDeclaration) {
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
233
|
+
owner.declarations.get(shorthand).add(declaration);
|
|
130
234
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const mapName =
|
|
135
|
-
// @ts-ignore
|
|
136
|
-
config.map[propertyName]?.map ?? config.map[shorthand]?.properties?.[propertyName]?.map;
|
|
137
|
-
if (typeof mapName === "string") {
|
|
138
|
-
if (!this.declarations.has(mapName)) {
|
|
139
|
-
// @ts-ignore
|
|
140
|
-
this.declarations.set(mapName, new PropertyMap(config.map[mapName]));
|
|
141
|
-
}
|
|
142
|
-
owner = this.declarations.get(mapName);
|
|
143
|
-
}
|
|
144
|
-
else if (!this.declarations.has(shorthand)) {
|
|
145
|
-
// @ts-ignore
|
|
146
|
-
this.declarations.set(shorthand, new PropertyMap(config.map[shorthand]));
|
|
147
|
-
}
|
|
148
|
-
if (owner == this) {
|
|
149
|
-
// @ts-ignore
|
|
150
|
-
owner.declarations.get(shorthand).add(declaration);
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
if (!owner.declarations.has(shorthand)) {
|
|
154
|
-
// @ts-ignore
|
|
155
|
-
owner.declarations.set(shorthand, new PropertyMap(config.map[shorthand]));
|
|
156
|
-
}
|
|
235
|
+
else {
|
|
236
|
+
if (!owner.declarations.has(shorthand)) {
|
|
237
|
+
owner.declarations.set(shorthand,
|
|
157
238
|
// @ts-ignore
|
|
158
|
-
|
|
239
|
+
new PropertyMap(arena, config.map[shorthand], this.memo));
|
|
159
240
|
}
|
|
241
|
+
// @ts-ignore
|
|
242
|
+
owner.declarations.get(shorthand).add(declaration);
|
|
160
243
|
}
|
|
244
|
+
}
|
|
245
|
+
// @ts-ignore
|
|
246
|
+
else if (shortHandType == "set") {
|
|
161
247
|
// @ts-ignore
|
|
162
|
-
|
|
248
|
+
if (!this.declarations.has(shorthand)) {
|
|
163
249
|
// @ts-ignore
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
// @ts-ignore
|
|
168
|
-
shorthand,
|
|
169
|
-
// @ts-ignore
|
|
170
|
-
new PropertySet(config.properties[shorthand]));
|
|
171
|
-
}
|
|
250
|
+
this.declarations.set(
|
|
251
|
+
// @ts-ignore
|
|
252
|
+
shorthand,
|
|
172
253
|
// @ts-ignore
|
|
173
|
-
|
|
254
|
+
new PropertySet(arena, config.properties[shorthand]));
|
|
174
255
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
256
|
+
// @ts-ignore
|
|
257
|
+
this.declarations.get(shorthand).add(declaration);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
if (shorthand != null) {
|
|
261
|
+
this.mapValues(declaration, shorthand);
|
|
180
262
|
}
|
|
263
|
+
this.declarations.set(propertyName, declaration);
|
|
181
264
|
}
|
|
182
265
|
return this;
|
|
183
266
|
}
|
|
@@ -188,26 +271,29 @@ class PropertyList {
|
|
|
188
271
|
*/
|
|
189
272
|
mapValues(declaration, mapping) {
|
|
190
273
|
let name;
|
|
191
|
-
|
|
274
|
+
const arena = this.arena;
|
|
275
|
+
const declarationValues = arena.tokens(declaration);
|
|
276
|
+
let values = declarationValues;
|
|
192
277
|
if (mapping.pattern != null) {
|
|
193
278
|
// match pattern
|
|
194
279
|
for (const patterns of mapping.pattern) {
|
|
195
|
-
const set = new Set(values.filter((v) => v
|
|
280
|
+
const set = new Set(values.filter((v) => arena.dataTypes[v] !== EnumToken.CommentTokenType &&
|
|
281
|
+
arena.dataTypes[v] !== EnumToken.WhitespaceTokenType));
|
|
196
282
|
const val = [];
|
|
197
283
|
for (const pattern of patterns) {
|
|
198
284
|
switch (pattern) {
|
|
199
285
|
case "<length>":
|
|
200
286
|
for (const v of set) {
|
|
201
|
-
if (v
|
|
202
|
-
(v
|
|
287
|
+
if (arena.dataTypes[v] === EnumToken.LengthTokenType ||
|
|
288
|
+
(arena.dataTypes[v] === EnumToken.NumberTokenType && arena.numericValue[v] === 0)) {
|
|
203
289
|
val.push(v);
|
|
204
290
|
set.delete(v);
|
|
205
291
|
}
|
|
206
292
|
}
|
|
207
293
|
default: {
|
|
208
294
|
for (const v of set) {
|
|
209
|
-
if (v
|
|
210
|
-
const value = v.
|
|
295
|
+
if (arena.dataTypes[v] === EnumToken.IdenTokenType) {
|
|
296
|
+
const value = arena.strings[arena.stringValue[v]].toLowerCase();
|
|
211
297
|
if (value === pattern || new RegExp(`(^|\|)${pattern}(\||$)`).test(value)) {
|
|
212
298
|
val.push(v);
|
|
213
299
|
set.delete(v);
|
|
@@ -220,7 +306,7 @@ class PropertyList {
|
|
|
220
306
|
if (set.size === 0) {
|
|
221
307
|
values = val.reduce((acc, curr) => {
|
|
222
308
|
if (acc.length > 0) {
|
|
223
|
-
acc.push(
|
|
309
|
+
acc.push(arena.createToken(EnumToken.WhitespaceTokenType));
|
|
224
310
|
}
|
|
225
311
|
acc.push(curr);
|
|
226
312
|
return acc;
|
|
@@ -229,20 +315,17 @@ class PropertyList {
|
|
|
229
315
|
}
|
|
230
316
|
}
|
|
231
317
|
}
|
|
232
|
-
for (const val of
|
|
233
|
-
if (val
|
|
234
|
-
name =
|
|
318
|
+
for (const val of declarationValues) {
|
|
319
|
+
if (arena.dataTypes[val] === EnumToken.IdenTokenType) {
|
|
320
|
+
name = arena.strings[arena.stringValue[val]].toLowerCase();
|
|
235
321
|
if (mapping.mapping[name] != null) {
|
|
236
|
-
|
|
237
|
-
|
|
322
|
+
const typ = EnumToken[mapping.mapping[name].typ];
|
|
323
|
+
arena.resetToken(val, typ, mapping.mapping[name].val);
|
|
238
324
|
}
|
|
239
325
|
}
|
|
240
326
|
}
|
|
241
|
-
if (values !=
|
|
242
|
-
declaration
|
|
243
|
-
for (const v of values) {
|
|
244
|
-
declaration.val.push(v);
|
|
245
|
-
}
|
|
327
|
+
if (values != declarationValues) {
|
|
328
|
+
arena.setTokenList(declaration, values);
|
|
246
329
|
}
|
|
247
330
|
}
|
|
248
331
|
/**
|
|
@@ -260,13 +343,14 @@ class PropertyList {
|
|
|
260
343
|
value.value instanceof PropertySet ||
|
|
261
344
|
value.value instanceof PropertyMap) {
|
|
262
345
|
if (value.value instanceof PropertySet || value.value instanceof PropertyMap) {
|
|
263
|
-
iterators
|
|
346
|
+
// stack of the parent iterators
|
|
347
|
+
iterators.push(iterator);
|
|
264
348
|
// @ts-ignore
|
|
265
349
|
iterator = value.value[Symbol.iterator]();
|
|
266
350
|
value = iterator.next();
|
|
267
351
|
}
|
|
268
352
|
if (value.done && iterators.length > 0) {
|
|
269
|
-
iterator = iterators.
|
|
353
|
+
iterator = iterators.pop();
|
|
270
354
|
value = iterator.next();
|
|
271
355
|
}
|
|
272
356
|
}
|
|
@@ -276,4 +360,4 @@ class PropertyList {
|
|
|
276
360
|
}
|
|
277
361
|
}
|
|
278
362
|
|
|
279
|
-
export { PropertyList };
|
|
363
|
+
export { DeclarationMemo, PropertyList };
|