@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,27 +2,74 @@
|
|
|
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
|
-
import {
|
|
8
|
+
import { eqToken } from '../utils/eq.js';
|
|
9
9
|
import { getConfig } from '../utils/config.js';
|
|
10
10
|
import { matchType } from '../utils/type.js';
|
|
11
11
|
import { EnumToken } from '../../ast/types.js';
|
|
12
12
|
import { renderValue } from '../../printer/render.js';
|
|
13
13
|
import { parseString } from '../parse.js';
|
|
14
14
|
import { PropertySet } from './set.js';
|
|
15
|
-
import { PROPERTYNAME } from '../../syntax/constants.js';
|
|
16
|
-
import { cloneNode } from '../../ast/clone.js';
|
|
17
15
|
|
|
18
16
|
const propertiesConfig = getConfig();
|
|
17
|
+
/**
|
|
18
|
+
* token type of a configuration token
|
|
19
|
+
* @param config
|
|
20
|
+
*/
|
|
21
|
+
function configType(config) {
|
|
22
|
+
return EnumToken[config.typ];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* create a token from the shorthand configuration
|
|
26
|
+
* @param arena
|
|
27
|
+
* @param config
|
|
28
|
+
*/
|
|
29
|
+
function configToken(arena, config) {
|
|
30
|
+
if (config == null) {
|
|
31
|
+
return arena.createToken(EnumToken.WhitespaceTokenType);
|
|
32
|
+
}
|
|
33
|
+
return arena.createToken(configType(config), config.val);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* true if the token matches the configuration token
|
|
37
|
+
* @param arena
|
|
38
|
+
* @param token
|
|
39
|
+
* @param config
|
|
40
|
+
*/
|
|
41
|
+
function matchConfigToken(arena, token, config) {
|
|
42
|
+
return (config != null &&
|
|
43
|
+
arena.dataTypes[token] == configType(config) &&
|
|
44
|
+
(config.val == null || arena.strings[arena.stringValue[token]] == config.val));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* map of declarations that can be merged into a single shorthand declaration.
|
|
48
|
+
* declarations are arena node ids
|
|
49
|
+
*/
|
|
19
50
|
class PropertyMap {
|
|
20
51
|
declarations;
|
|
21
52
|
config;
|
|
53
|
+
arena;
|
|
22
54
|
requiredCount;
|
|
23
55
|
pattern;
|
|
24
|
-
|
|
56
|
+
/**
|
|
57
|
+
* longhand property name of the matched tokens
|
|
58
|
+
*/
|
|
59
|
+
propertyNames = new Map();
|
|
60
|
+
/**
|
|
61
|
+
* results shared by the lists of a minification: the default values are parsed once
|
|
62
|
+
*/
|
|
63
|
+
memo;
|
|
64
|
+
/**
|
|
65
|
+
* @param arena
|
|
66
|
+
* @param config
|
|
67
|
+
* @param memo results shared by the lists of a minification
|
|
68
|
+
*/
|
|
69
|
+
constructor(arena, config, memo = null) {
|
|
70
|
+
this.memo = memo;
|
|
25
71
|
const values = Object.values(config.properties);
|
|
72
|
+
this.arena = arena;
|
|
26
73
|
this.requiredCount =
|
|
27
74
|
values.reduce((acc, curr) => (curr.required ? ++acc : acc), 0) ||
|
|
28
75
|
values.length;
|
|
@@ -30,50 +77,47 @@ class PropertyMap {
|
|
|
30
77
|
this.declarations = new Map();
|
|
31
78
|
this.pattern = config.pattern.split(/\s/);
|
|
32
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* tokens of a value (default values of the properties, ...)
|
|
82
|
+
* @param value
|
|
83
|
+
*/
|
|
84
|
+
parse(value) {
|
|
85
|
+
return this.memo == null ? parseString(this.arena, value) : this.memo.parse(this.arena, value);
|
|
86
|
+
}
|
|
33
87
|
add(declaration) {
|
|
34
|
-
|
|
88
|
+
const arena = this.arena;
|
|
89
|
+
const nam = arena.strings[arena.name[declaration]];
|
|
90
|
+
if (nam == this.config.shorthand) {
|
|
35
91
|
this.declarations.clear();
|
|
36
|
-
this.declarations.set(
|
|
92
|
+
this.declarations.set(nam, declaration);
|
|
37
93
|
this.matchTypes(declaration);
|
|
38
94
|
}
|
|
39
95
|
else {
|
|
40
|
-
const separator = this.config.separator
|
|
41
|
-
? {
|
|
42
|
-
...this.config.separator,
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
typ: EnumToken[this.config.separator.typ],
|
|
45
|
-
}
|
|
46
|
-
: null;
|
|
96
|
+
const separator = this.config.separator ?? null;
|
|
47
97
|
// expand shorthand
|
|
48
98
|
if (this.declarations.has(this.config.shorthand)) {
|
|
49
99
|
const tokens = {};
|
|
50
100
|
const values = [];
|
|
51
101
|
const val = [[]];
|
|
52
|
-
for (const curr of this.declarations.get(this.config.shorthand)
|
|
53
|
-
|
|
54
|
-
// @ts-ignore
|
|
55
|
-
if (separator != null && separator.typ == curr.typ && separator.val == curr.val) {
|
|
102
|
+
for (const curr of arena.tokens(this.declarations.get(this.config.shorthand))) {
|
|
103
|
+
if (matchConfigToken(arena, curr, separator)) {
|
|
56
104
|
val.push([]);
|
|
57
105
|
continue;
|
|
58
106
|
}
|
|
59
|
-
|
|
60
|
-
val.at(-1).push(curr);
|
|
107
|
+
val[val.length - 1].push(curr);
|
|
61
108
|
}
|
|
62
109
|
for (let current = 0; current < val.length; current++) {
|
|
63
110
|
values.push(...this.pattern.reduce((acc, property) => {
|
|
64
111
|
// let current: number = 0;
|
|
65
112
|
const props = this.config.properties[property];
|
|
66
113
|
for (let i = 0; i < acc.length; i++) {
|
|
67
|
-
if (acc[i]
|
|
68
|
-
acc[i]
|
|
114
|
+
if (arena.dataTypes[acc[i]] == EnumToken.CommentTokenType ||
|
|
115
|
+
arena.dataTypes[acc[i]] == EnumToken.WhitespaceTokenType) {
|
|
69
116
|
acc.splice(i, 1);
|
|
70
117
|
i--;
|
|
71
118
|
continue;
|
|
72
119
|
}
|
|
73
|
-
if (
|
|
74
|
-
// @ts-ignore
|
|
75
|
-
acc[i][PROPERTYNAME] == property ||
|
|
76
|
-
matchType(acc[i], props)) {
|
|
120
|
+
if (this.propertyNames.get(acc[i]) == property || matchType(arena, acc[i], props)) {
|
|
77
121
|
if ("prefix" in props && props.previous != null && !(props.previous in tokens)) {
|
|
78
122
|
return acc;
|
|
79
123
|
}
|
|
@@ -85,21 +129,16 @@ class PropertyMap {
|
|
|
85
129
|
tokens[property].push([acc[i]]);
|
|
86
130
|
}
|
|
87
131
|
else {
|
|
88
|
-
tokens[property][current].push(
|
|
132
|
+
tokens[property][current].push(arena.createToken(EnumToken.WhitespaceTokenType), acc[i]);
|
|
89
133
|
}
|
|
90
134
|
}
|
|
91
135
|
acc.splice(i, 1);
|
|
92
136
|
i--;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// @ts-ignore
|
|
99
|
-
acc[i].val == this.config.properties[property].prefix.val) {
|
|
100
|
-
acc.splice(i, 1);
|
|
101
|
-
i--;
|
|
102
|
-
}
|
|
137
|
+
if ("prefix" in props &&
|
|
138
|
+
i >= 0 &&
|
|
139
|
+
matchConfigToken(arena, acc[i], props.prefix)) {
|
|
140
|
+
acc.splice(i, 1);
|
|
141
|
+
i--;
|
|
103
142
|
}
|
|
104
143
|
if (props.multiple) {
|
|
105
144
|
continue;
|
|
@@ -117,7 +156,8 @@ class PropertyMap {
|
|
|
117
156
|
}
|
|
118
157
|
// default
|
|
119
158
|
if (props.default.length > 0) {
|
|
120
|
-
|
|
159
|
+
// inlined: this.parse(props.default[0])
|
|
160
|
+
const defaults = this.memo == null ? parseString(this.arena, props.default[0]) : this.memo.parse(this.arena, props.default[0]);
|
|
121
161
|
if (!(property in tokens)) {
|
|
122
162
|
tokens[property] = [[...defaults]];
|
|
123
163
|
}
|
|
@@ -129,9 +169,7 @@ class PropertyMap {
|
|
|
129
169
|
}
|
|
130
170
|
}
|
|
131
171
|
else {
|
|
132
|
-
tokens[property][current].push(
|
|
133
|
-
typ: EnumToken.WhitespaceTokenType,
|
|
134
|
-
});
|
|
172
|
+
tokens[property][current].push(arena.createToken(EnumToken.WhitespaceTokenType));
|
|
135
173
|
for (let i = 0; i < defaults.length; i++) {
|
|
136
174
|
tokens[property][current].push(defaults[i]);
|
|
137
175
|
}
|
|
@@ -143,32 +181,29 @@ class PropertyMap {
|
|
|
143
181
|
}
|
|
144
182
|
if (values.length == 0) {
|
|
145
183
|
this.declarations = Object.entries(tokens).reduce((acc, curr) => {
|
|
146
|
-
acc.set(curr[0], {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
return acc;
|
|
157
|
-
}, []),
|
|
158
|
-
});
|
|
184
|
+
acc.set(curr[0], arena.createDeclaration(EnumToken.DeclarationNodeType, curr[0], curr[1].reduce((acc, curr) => {
|
|
185
|
+
if (acc.length > 0) {
|
|
186
|
+
acc.push(configToken(arena, separator));
|
|
187
|
+
}
|
|
188
|
+
for (let i = 0; i < curr.length; i++) {
|
|
189
|
+
acc.push(this.take(curr[i]));
|
|
190
|
+
}
|
|
191
|
+
return acc;
|
|
192
|
+
}, []), null, null));
|
|
159
193
|
return acc;
|
|
160
194
|
}, new Map());
|
|
161
195
|
}
|
|
162
196
|
}
|
|
163
197
|
// @ts-ignore
|
|
164
|
-
const config = propertiesConfig.properties[
|
|
165
|
-
let property =
|
|
198
|
+
const config = propertiesConfig.properties[nam];
|
|
199
|
+
let property = nam;
|
|
166
200
|
if (config != null) {
|
|
167
201
|
property = config.shorthand;
|
|
168
202
|
let value = this.declarations.get(property);
|
|
169
203
|
if (!(value instanceof PropertySet)) {
|
|
204
|
+
this.declarations.set(property,
|
|
170
205
|
// @ts-ignore
|
|
171
|
-
|
|
206
|
+
new PropertySet(arena, propertiesConfig.properties[config.shorthand]));
|
|
172
207
|
// Token[]
|
|
173
208
|
if (value != null) {
|
|
174
209
|
// @ts-ignore
|
|
@@ -178,12 +213,13 @@ class PropertyMap {
|
|
|
178
213
|
this.declarations.get(property).add(declaration);
|
|
179
214
|
}
|
|
180
215
|
else {
|
|
181
|
-
this.declarations.set(
|
|
216
|
+
this.declarations.set(nam, declaration);
|
|
182
217
|
}
|
|
183
218
|
}
|
|
184
219
|
return this;
|
|
185
220
|
}
|
|
186
221
|
[Symbol.iterator]() {
|
|
222
|
+
const arena = this.arena;
|
|
187
223
|
const propertiesMapping = { ...this.config.properties };
|
|
188
224
|
const patterns = this.config.pattern.split(" ");
|
|
189
225
|
let hasMapping = false;
|
|
@@ -202,26 +238,27 @@ class PropertyMap {
|
|
|
202
238
|
const mapped = {};
|
|
203
239
|
let key;
|
|
204
240
|
for (const value of declarations.values()) {
|
|
205
|
-
key = value.nam;
|
|
206
241
|
if (value instanceof PropertyMap) {
|
|
207
242
|
for (const [k, v] of value.declarations) {
|
|
208
243
|
if (k == value.config.shorthand) {
|
|
244
|
+
const values = arena.tokens(v);
|
|
209
245
|
for (const [key] of Object.entries(value.config.properties)) {
|
|
210
|
-
mapped[key] =
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (key ==
|
|
214
|
-
if (
|
|
215
|
-
|
|
216
|
-
typ: EnumToken.WhitespaceTokenType,
|
|
217
|
-
});
|
|
246
|
+
mapped[key] = arena.clone(v);
|
|
247
|
+
const mappedValues = [];
|
|
248
|
+
for (let i = 0; i < values.length; i++) {
|
|
249
|
+
if (key == value.propertyNames.get(values[i])) {
|
|
250
|
+
if (mappedValues.length > 0) {
|
|
251
|
+
mappedValues.push(arena.createToken(EnumToken.WhitespaceTokenType));
|
|
218
252
|
}
|
|
219
|
-
|
|
253
|
+
mappedValues.push(value.take(values[i]));
|
|
220
254
|
}
|
|
221
255
|
}
|
|
222
|
-
if (
|
|
223
|
-
|
|
256
|
+
if (mappedValues.length == 0) {
|
|
257
|
+
mappedValues.push(
|
|
258
|
+
// inlined: this.parse((value as PropertyMap).config.properties[key].default[0])
|
|
259
|
+
...(this.memo == null ? parseString(this.arena, value.config.properties[key].default[0]) : this.memo.parse(this.arena, value.config.properties[key].default[0])));
|
|
224
260
|
}
|
|
261
|
+
arena.setTokenList(mapped[key], mappedValues);
|
|
225
262
|
}
|
|
226
263
|
}
|
|
227
264
|
else {
|
|
@@ -230,6 +267,9 @@ class PropertyMap {
|
|
|
230
267
|
}
|
|
231
268
|
}
|
|
232
269
|
else {
|
|
270
|
+
// a property set has no name
|
|
271
|
+
key =
|
|
272
|
+
value instanceof PropertySet ? "undefined" : arena.strings[arena.name[value]];
|
|
233
273
|
mapped[key] = value;
|
|
234
274
|
}
|
|
235
275
|
}
|
|
@@ -273,30 +313,18 @@ class PropertyMap {
|
|
|
273
313
|
let map = new Map();
|
|
274
314
|
let value = [];
|
|
275
315
|
let values = [];
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const sep = this.config.separator == null
|
|
280
|
-
? null
|
|
281
|
-
: {
|
|
282
|
-
...this.config.separator,
|
|
283
|
-
typ: EnumToken[this.config.separator.typ],
|
|
284
|
-
};
|
|
285
|
-
// @ts-ignore
|
|
286
|
-
const separator = this.config.separator
|
|
287
|
-
? renderValue({
|
|
288
|
-
...this.config.separator,
|
|
289
|
-
typ: EnumToken[this.config.separator.typ],
|
|
290
|
-
})
|
|
291
|
-
: ",";
|
|
316
|
+
const sep = this.config.separator ?? null;
|
|
317
|
+
const typ = sep == null ? EnumToken.CommaTokenType : configType(sep);
|
|
318
|
+
const separator = sep == null ? "," : (sep.val ?? "");
|
|
292
319
|
this.matchTypes(declaration);
|
|
293
320
|
values.push(value);
|
|
294
|
-
|
|
295
|
-
|
|
321
|
+
const declarationValues = arena.tokens(declaration);
|
|
322
|
+
for (i = 0; i < declarationValues.length; i++) {
|
|
323
|
+
t = declarationValues[i];
|
|
296
324
|
if (!cache.has(t)) {
|
|
297
|
-
cache.set(t, renderValue(t, { minify: true }));
|
|
325
|
+
cache.set(t, renderValue(arena, t, { minify: true }));
|
|
298
326
|
}
|
|
299
|
-
if (t
|
|
327
|
+
if (arena.dataTypes[t] == typ && separator == cache.get(t)) {
|
|
300
328
|
this.removeDefaults(map, value);
|
|
301
329
|
value = [];
|
|
302
330
|
values.push(value);
|
|
@@ -304,40 +332,40 @@ class PropertyMap {
|
|
|
304
332
|
continue;
|
|
305
333
|
}
|
|
306
334
|
value.push(t);
|
|
307
|
-
|
|
308
|
-
if (
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
// @ts-ignore
|
|
312
|
-
map.set(t[PROPERTYNAME], { t: [t], value: [cache.get(t)] });
|
|
335
|
+
const propertyName = this.propertyNames.get(t);
|
|
336
|
+
if (propertyName != null) {
|
|
337
|
+
if (!map.has(propertyName)) {
|
|
338
|
+
map.set(propertyName, { t: [t], value: [cache.get(t)] });
|
|
313
339
|
}
|
|
314
340
|
else {
|
|
315
|
-
|
|
316
|
-
const v = map.get(t[PROPERTYNAME]);
|
|
341
|
+
const v = map.get(propertyName);
|
|
317
342
|
v.t.push(t);
|
|
318
343
|
v.value.push(cache.get(t));
|
|
319
344
|
}
|
|
320
345
|
}
|
|
321
346
|
}
|
|
322
347
|
this.removeDefaults(map, value);
|
|
323
|
-
|
|
348
|
+
const result = values.reduce((acc, curr) => {
|
|
324
349
|
if (sep != null && acc.length > 0) {
|
|
325
|
-
acc.push(
|
|
350
|
+
acc.push(configToken(arena, sep));
|
|
326
351
|
}
|
|
327
352
|
for (const cr of curr) {
|
|
328
|
-
if (cr
|
|
353
|
+
if (arena.dataTypes[cr] == EnumToken.WhitespaceTokenType &&
|
|
354
|
+
acc.length > 0 &&
|
|
355
|
+
arena.dataTypes[acc[acc.length - 1]] == EnumToken.WhitespaceTokenType) {
|
|
329
356
|
continue;
|
|
330
357
|
}
|
|
331
358
|
acc.push(cr);
|
|
332
359
|
}
|
|
333
360
|
return acc;
|
|
334
361
|
}, []);
|
|
335
|
-
while (
|
|
336
|
-
|
|
362
|
+
while (result.length > 0 && arena.dataTypes[result[result.length - 1]] == EnumToken.WhitespaceTokenType) {
|
|
363
|
+
result.pop();
|
|
337
364
|
}
|
|
338
|
-
while (
|
|
339
|
-
|
|
365
|
+
while (result.length > 0 && arena.dataTypes[result[0]] == EnumToken.WhitespaceTokenType) {
|
|
366
|
+
result.shift();
|
|
340
367
|
}
|
|
368
|
+
arena.setTokenList(declaration, result);
|
|
341
369
|
return declaration;
|
|
342
370
|
};
|
|
343
371
|
const values = [...declarations.values()].reduce((acc, curr) => {
|
|
@@ -356,27 +384,23 @@ class PropertyMap {
|
|
|
356
384
|
const filtered = [];
|
|
357
385
|
for (const declaration of values) {
|
|
358
386
|
dec = removeDefaults(declaration);
|
|
359
|
-
for (const t of dec
|
|
360
|
-
if (t
|
|
387
|
+
for (const t of arena.tokens(dec)) {
|
|
388
|
+
if (arena.dataTypes[t] == EnumToken.ImportantTokenType) {
|
|
361
389
|
isImportant = true;
|
|
362
390
|
}
|
|
363
391
|
if (filtered.length == 0 &&
|
|
364
|
-
t
|
|
365
|
-
t
|
|
392
|
+
arena.dataTypes[t] != EnumToken.WhitespaceTokenType &&
|
|
393
|
+
arena.dataTypes[t] != EnumToken.ImportantTokenType) {
|
|
366
394
|
filtered.push(dec);
|
|
367
395
|
}
|
|
368
396
|
}
|
|
369
397
|
}
|
|
370
398
|
if (filtered.length == 0 && this.config.default.length > 0) {
|
|
371
|
-
filtered.push(
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
val: parseString(this.config.default[0]),
|
|
375
|
-
});
|
|
399
|
+
filtered.push(arena.createDeclaration(EnumToken.DeclarationNodeType, this.config.shorthand,
|
|
400
|
+
// inlined: this.parse(this.config.default[0])
|
|
401
|
+
this.memo == null ? parseString(this.arena, this.config.default[0]) : this.memo.parse(this.arena, this.config.default[0]), null, null));
|
|
376
402
|
if (isImportant) {
|
|
377
|
-
filtered[0].
|
|
378
|
-
typ: EnumToken.ImportantTokenType,
|
|
379
|
-
});
|
|
403
|
+
arena.appendToken(filtered[0], arena.createToken(EnumToken.ImportantTokenType));
|
|
380
404
|
}
|
|
381
405
|
}
|
|
382
406
|
return (filtered.length > 0 ? filtered : values)[Symbol.iterator]();
|
|
@@ -385,20 +409,22 @@ class PropertyMap {
|
|
|
385
409
|
if (declaration instanceof PropertySet || declaration instanceof PropertyMap) {
|
|
386
410
|
continue;
|
|
387
411
|
}
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
: (propertiesMapping[declaration.nam] ?? this.config);
|
|
412
|
+
const nam = arena.strings[arena.name[declaration]];
|
|
413
|
+
const config = nam == this.config.shorthand ? this.config : (propertiesMapping[nam] ?? this.config);
|
|
391
414
|
if (!("mapping" in config)) {
|
|
392
415
|
continue;
|
|
393
416
|
}
|
|
417
|
+
const declarationValues = arena.tokens(declaration);
|
|
394
418
|
// @ts-ignore
|
|
395
419
|
for (const [key, val] of Object.entries(config.mapping)) {
|
|
396
|
-
|
|
397
|
-
|
|
420
|
+
// inlined: this.parse(key)
|
|
421
|
+
const keys = this.memo == null ? parseString(this.arena, key) : this.memo.parse(this.arena, key);
|
|
422
|
+
if (keys.length != declarationValues.length) {
|
|
398
423
|
continue;
|
|
399
424
|
}
|
|
400
|
-
if (
|
|
401
|
-
|
|
425
|
+
if (keys.every((k, index) => eqToken(arena, k, declarationValues[index]))) {
|
|
426
|
+
// inlined: this.parse(val as string)
|
|
427
|
+
arena.setTokenList(declaration, this.memo == null ? parseString(this.arena, val) : this.memo.parse(this.arena, val));
|
|
402
428
|
break;
|
|
403
429
|
}
|
|
404
430
|
}
|
|
@@ -409,13 +435,7 @@ class PropertyMap {
|
|
|
409
435
|
else {
|
|
410
436
|
let count = 0;
|
|
411
437
|
let match;
|
|
412
|
-
const separator = this.config.separator
|
|
413
|
-
? {
|
|
414
|
-
...this.config.separator,
|
|
415
|
-
// @ts-ignore
|
|
416
|
-
typ: EnumToken[this.config.separator.typ],
|
|
417
|
-
}
|
|
418
|
-
: null;
|
|
438
|
+
const separator = this.config.separator ?? null;
|
|
419
439
|
const tokens = {};
|
|
420
440
|
// @ts-ignore
|
|
421
441
|
Object.entries(propertiesMapping).reduce((acc, curr) => {
|
|
@@ -428,38 +448,34 @@ class PropertyMap {
|
|
|
428
448
|
let current = 0;
|
|
429
449
|
const props = propertiesMapping[curr[0]];
|
|
430
450
|
const properties = (declarations.get(curr[0]));
|
|
431
|
-
for (const declaration of properties instanceof PropertySet ||
|
|
451
|
+
for (const declaration of properties instanceof PropertySet ||
|
|
452
|
+
properties instanceof PropertyMap
|
|
432
453
|
? [...properties].flat()
|
|
433
454
|
: [properties]) {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
// @ts-ignore
|
|
437
|
-
if (separator != null && separator.typ == val.typ && separator.val == val.val) {
|
|
455
|
+
for (const val of arena.tokens(declaration)) {
|
|
456
|
+
if (matchConfigToken(arena, val, separator)) {
|
|
438
457
|
current++;
|
|
439
458
|
if (tokens[curr[0]].length == current) {
|
|
440
459
|
tokens[curr[0]].push([]);
|
|
441
460
|
}
|
|
442
461
|
continue;
|
|
443
462
|
}
|
|
444
|
-
|
|
463
|
+
const valType = arena.dataTypes[val];
|
|
464
|
+
if (valType == EnumToken.WhitespaceTokenType || valType == EnumToken.CommentTokenType) {
|
|
445
465
|
continue;
|
|
446
466
|
}
|
|
447
|
-
// @ts-ignore
|
|
448
467
|
if (props.multiple &&
|
|
449
468
|
props.separator != null &&
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
(val.typ === EnumToken.CommaTokenType || props.separator.val == val.val)) {
|
|
469
|
+
configType(props.separator) === valType &&
|
|
470
|
+
(valType === EnumToken.CommaTokenType ||
|
|
471
|
+
props.separator.val == arena.strings[arena.stringValue[val]])) {
|
|
454
472
|
continue;
|
|
455
473
|
}
|
|
456
|
-
|
|
457
|
-
match = val.typ == EnumToken.CommentTokenType || matchType(val, curr[1]);
|
|
474
|
+
match = matchType(arena, val, curr[1]);
|
|
458
475
|
if (isShorthand) {
|
|
459
476
|
isShorthand = match;
|
|
460
477
|
}
|
|
461
|
-
|
|
462
|
-
if (val[PROPERTYNAME] == property || match) {
|
|
478
|
+
if (this.propertyNames.get(val) == property || match) {
|
|
463
479
|
if (!(curr[0] in tokens)) {
|
|
464
480
|
tokens[curr[0]] = [[]];
|
|
465
481
|
}
|
|
@@ -499,18 +515,16 @@ class PropertyMap {
|
|
|
499
515
|
result.push(...tokens[patterns[1]][0].slice(j));
|
|
500
516
|
}
|
|
501
517
|
const separator = this.config.properties[patterns[2]]?.prefix;
|
|
502
|
-
result.push(
|
|
503
|
-
// @ts-ignore
|
|
504
|
-
{ ...separator, typ: EnumToken[separator.typ] }, ...tokens[patterns[2]][0].reduce((acc, curr) => {
|
|
518
|
+
result.push(configToken(arena, separator), ...tokens[patterns[2]][0].reduce((acc, curr) => {
|
|
505
519
|
if (acc.length > 0) {
|
|
506
|
-
acc.push(
|
|
520
|
+
acc.push(arena.createToken(EnumToken.WhitespaceTokenType));
|
|
507
521
|
}
|
|
508
522
|
acc.push(curr);
|
|
509
523
|
return acc;
|
|
510
524
|
}, []));
|
|
511
|
-
const declaration =
|
|
512
|
-
declaration
|
|
513
|
-
declaration.
|
|
525
|
+
const declaration = arena.clone(declarations.get(patterns[0]));
|
|
526
|
+
arena.name[declaration] = arena.internString(this.config.shorthand);
|
|
527
|
+
arena.setTokenList(declaration, result.map((t) => this.take(t)));
|
|
514
528
|
return [declaration][Symbol.iterator]();
|
|
515
529
|
}
|
|
516
530
|
count++;
|
|
@@ -521,40 +535,36 @@ class PropertyMap {
|
|
|
521
535
|
}) ||
|
|
522
536
|
// @ts-ignore
|
|
523
537
|
!Object.values(tokens).every((v) =>
|
|
524
|
-
//
|
|
525
|
-
|
|
538
|
+
// `v` holds token groups: only single token groups were type checked by the former
|
|
539
|
+
// `arena.dataTypes[group]` lookup (the group is converted to a string key)
|
|
540
|
+
v.filter((t) => t.length != 1 || arena.dataTypes[t[0]] != EnumToken.CommentTokenType).length === count)) {
|
|
526
541
|
// @ts-ignore
|
|
527
542
|
iterable = declarations.values();
|
|
528
543
|
}
|
|
529
544
|
else if (hasMapping) {
|
|
530
545
|
if (patterns.length == Object.keys(tokens).length) {
|
|
531
|
-
const declaration =
|
|
532
|
-
|
|
546
|
+
const declaration = arena.clone(declarations.get(patterns[0]));
|
|
547
|
+
const declarationValues = arena.tokens(declaration);
|
|
548
|
+
arena.name[declaration] = arena.internString(this.config.shorthand);
|
|
533
549
|
for (let i = 0; i < patterns.length; i++) {
|
|
534
|
-
if (
|
|
535
|
-
|
|
536
|
-
// @ts-ignore
|
|
537
|
-
this.config.separator != null
|
|
538
|
-
? {
|
|
539
|
-
...this.config.separator,
|
|
540
|
-
typ: EnumToken[this.config.separator.typ],
|
|
541
|
-
}
|
|
542
|
-
: { typ: EnumToken.WhitespaceTokenType });
|
|
550
|
+
if (declarationValues.length > 0) {
|
|
551
|
+
declarationValues.push(configToken(arena, separator));
|
|
543
552
|
}
|
|
544
|
-
|
|
553
|
+
declarationValues.push(...tokens[patterns[i]].reduce((acc, curr) => {
|
|
545
554
|
if (acc.length > 0) {
|
|
546
|
-
acc.push(
|
|
555
|
+
acc.push(arena.createToken(EnumToken.WhitespaceTokenType));
|
|
547
556
|
}
|
|
548
557
|
acc.push(...curr.reduce((acc, curr) => {
|
|
549
558
|
if (acc.length > 0) {
|
|
550
|
-
acc.push(
|
|
559
|
+
acc.push(arena.createToken(EnumToken.WhitespaceTokenType));
|
|
551
560
|
}
|
|
552
|
-
acc.push(curr);
|
|
561
|
+
acc.push(this.take(curr));
|
|
553
562
|
return acc;
|
|
554
563
|
}, []));
|
|
555
564
|
return acc;
|
|
556
565
|
}, []));
|
|
557
566
|
}
|
|
567
|
+
arena.setTokenList(declaration, declarationValues);
|
|
558
568
|
return [declaration][Symbol.iterator]();
|
|
559
569
|
}
|
|
560
570
|
iterable = declarations.values();
|
|
@@ -587,9 +597,9 @@ class PropertyMap {
|
|
|
587
597
|
// return acc;
|
|
588
598
|
// },
|
|
589
599
|
// <Token[]>[],
|
|
590
|
-
//
|
|
600
|
+
//);
|
|
591
601
|
if (props.default.includes(curr[1][i]
|
|
592
|
-
.reduce((acc, curr) => acc + renderValue(curr) + " ", "")
|
|
602
|
+
.reduce((acc, curr) => acc + renderValue(arena, curr) + " ", "")
|
|
593
603
|
.trimEnd())) {
|
|
594
604
|
if (!propertiesMapping[curr[0]].required) {
|
|
595
605
|
continue;
|
|
@@ -603,9 +613,9 @@ class PropertyMap {
|
|
|
603
613
|
EnumToken.WhitespaceTokenType,
|
|
604
614
|
EnumToken.CommentTokenType,
|
|
605
615
|
EnumToken.IdenTokenType,
|
|
606
|
-
].includes(v
|
|
607
|
-
(v
|
|
608
|
-
!propertiesMapping[curr[0]].default.includes(v
|
|
616
|
+
].includes(arena.dataTypes[v]) ||
|
|
617
|
+
(arena.dataTypes[v] == EnumToken.IdenTokenType &&
|
|
618
|
+
!propertiesMapping[curr[0]].default.includes(arena.strings[arena.stringValue[v]]))) {
|
|
609
619
|
doFilterDefault = false;
|
|
610
620
|
break;
|
|
611
621
|
}
|
|
@@ -613,13 +623,13 @@ class PropertyMap {
|
|
|
613
623
|
}
|
|
614
624
|
// remove default values
|
|
615
625
|
const filtered = values.filter((val) => {
|
|
616
|
-
if (val
|
|
617
|
-
val
|
|
626
|
+
if (arena.dataTypes[val] == EnumToken.WhitespaceTokenType ||
|
|
627
|
+
arena.dataTypes[val] == EnumToken.CommentTokenType) {
|
|
618
628
|
return false;
|
|
619
629
|
}
|
|
620
630
|
return (!doFilterDefault ||
|
|
621
|
-
!(val
|
|
622
|
-
props.default.includes(
|
|
631
|
+
!(arena.dataTypes[val] == EnumToken.IdenTokenType &&
|
|
632
|
+
props.default.includes(arena.strings[arena.stringValue[val]])));
|
|
623
633
|
});
|
|
624
634
|
if (filtered.length > 0 ||
|
|
625
635
|
!(this.requiredCount == requiredCount && propertiesMapping[curr[0]].required)) {
|
|
@@ -633,36 +643,30 @@ class PropertyMap {
|
|
|
633
643
|
values.length <= props.constraints.mapping.max) {
|
|
634
644
|
let i = values.length;
|
|
635
645
|
while (i--) {
|
|
636
|
-
if (values[i]
|
|
646
|
+
if (arena.dataTypes[values[i]] == EnumToken.IdenTokenType &&
|
|
637
647
|
// @ts-expect-error
|
|
638
|
-
values[i]
|
|
639
|
-
//
|
|
640
|
-
values.splice(i, 1, ...
|
|
648
|
+
arena.strings[arena.stringValue[values[i]]] in props.mapping) {
|
|
649
|
+
// inlined: this.parse(props.mapping[arena.strings[arena.stringValue[values[i]]]])
|
|
650
|
+
values.splice(i, 1, ...(this.memo == null
|
|
651
|
+
? // @ts-ignore
|
|
652
|
+
parseString(this.arena, props.mapping[arena.strings[arena.stringValue[values[i]]]])
|
|
653
|
+
: // @ts-ignore
|
|
654
|
+
this.memo.parse(this.arena, props.mapping[arena.strings[arena.stringValue[values[i]]]])));
|
|
641
655
|
}
|
|
642
656
|
}
|
|
643
657
|
}
|
|
644
658
|
}
|
|
645
659
|
if ("prefix" in props) {
|
|
646
|
-
|
|
647
|
-
acc[i].push({ ...props.prefix, typ: EnumToken[props.prefix.typ] });
|
|
660
|
+
acc[i].push(configToken(arena, props.prefix));
|
|
648
661
|
}
|
|
649
662
|
else if (acc[i].length > 0) {
|
|
650
|
-
|
|
651
|
-
acc[i].push({ typ: EnumToken.WhitespaceTokenType });
|
|
663
|
+
acc[i].push(arena.createToken(EnumToken.WhitespaceTokenType));
|
|
652
664
|
}
|
|
653
665
|
for (const v of values.reduce((acc, curr) => {
|
|
654
666
|
if (acc.length > 0) {
|
|
655
|
-
|
|
656
|
-
acc.push({
|
|
657
|
-
...((props.separator && {
|
|
658
|
-
...props.separator,
|
|
659
|
-
// @ts-ignore
|
|
660
|
-
typ: EnumToken[props.separator.typ],
|
|
661
|
-
}) ?? { typ: EnumToken.WhitespaceTokenType }),
|
|
662
|
-
});
|
|
667
|
+
acc.push(configToken(arena, props.separator));
|
|
663
668
|
}
|
|
664
|
-
|
|
665
|
-
acc.push(curr);
|
|
669
|
+
acc.push(this.take(curr));
|
|
666
670
|
return acc;
|
|
667
671
|
}, [])) {
|
|
668
672
|
acc[i].push(v);
|
|
@@ -673,12 +677,14 @@ class PropertyMap {
|
|
|
673
677
|
}, [])
|
|
674
678
|
.reduce((acc, curr) => {
|
|
675
679
|
if (acc.length > 0) {
|
|
676
|
-
acc.push(
|
|
680
|
+
acc.push(configToken(arena, separator));
|
|
677
681
|
}
|
|
678
682
|
if (curr.length == 0 && this.config.default.length > 0) {
|
|
679
|
-
curr.push(
|
|
683
|
+
curr.push(
|
|
684
|
+
// inlined: this.parse(this.config.default[0])
|
|
685
|
+
...(this.memo == null ? parseString(this.arena, this.config.default[0]) : this.memo.parse(this.arena, this.config.default[0])).reduce((acc, curr) => {
|
|
680
686
|
if (acc.length > 0) {
|
|
681
|
-
acc.push(
|
|
687
|
+
acc.push(arena.createToken(EnumToken.WhitespaceTokenType));
|
|
682
688
|
}
|
|
683
689
|
acc.push(curr);
|
|
684
690
|
return acc;
|
|
@@ -691,36 +697,28 @@ class PropertyMap {
|
|
|
691
697
|
}, []);
|
|
692
698
|
if (this.config.mapping != null) {
|
|
693
699
|
const val = values.reduce((acc, curr) => acc +
|
|
694
|
-
renderValue(curr, {
|
|
700
|
+
renderValue(arena, curr, {
|
|
695
701
|
removeComments: true,
|
|
696
702
|
minify: true,
|
|
697
703
|
}), "");
|
|
698
704
|
if (val in this.config.mapping) {
|
|
699
705
|
values.length = 0;
|
|
700
|
-
values.push(
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
val: this.config.mapping[val],
|
|
706
|
-
});
|
|
706
|
+
values.push(arena.createToken(['"', "'"].includes(val.charAt(0))
|
|
707
|
+
? EnumToken.StringTokenType
|
|
708
|
+
: EnumToken.IdenTokenType,
|
|
709
|
+
// @ts-ignore
|
|
710
|
+
this.config.mapping[val]));
|
|
707
711
|
}
|
|
708
712
|
}
|
|
709
|
-
// @ts-ignore
|
|
710
713
|
if (values.length == 1 &&
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
this.config.default.
|
|
714
|
-
this.config.default[0]
|
|
715
|
-
|
|
716
|
-
values = parseString(this.config.default[0]);
|
|
714
|
+
arena.stringValue[values[0]] != 0 &&
|
|
715
|
+
this.config.default.includes(arena.strings[arena.stringValue[values[0]]].toLowerCase()) &&
|
|
716
|
+
this.config.default[0] != arena.strings[arena.stringValue[values[0]]].toLowerCase()) {
|
|
717
|
+
// inlined: this.parse(this.config.default[0])
|
|
718
|
+
values = this.memo == null ? parseString(this.arena, this.config.default[0]) : this.memo.parse(this.arena, this.config.default[0]);
|
|
717
719
|
}
|
|
718
720
|
iterable = [
|
|
719
|
-
|
|
720
|
-
typ: EnumToken.DeclarationNodeType,
|
|
721
|
-
nam: this.config.shorthand,
|
|
722
|
-
val: values,
|
|
723
|
-
},
|
|
721
|
+
arena.createDeclaration(EnumToken.DeclarationNodeType, this.config.shorthand, values, null, null),
|
|
724
722
|
][Symbol.iterator]();
|
|
725
723
|
}
|
|
726
724
|
}
|
|
@@ -753,14 +751,31 @@ class PropertyMap {
|
|
|
753
751
|
},
|
|
754
752
|
};
|
|
755
753
|
}
|
|
754
|
+
/**
|
|
755
|
+
* detach a token from its declaration: tokens are cloned when they are still attached to a declaration
|
|
756
|
+
* @param token
|
|
757
|
+
*/
|
|
758
|
+
take(token) {
|
|
759
|
+
if (this.arena.parents[token] == 0) {
|
|
760
|
+
return token;
|
|
761
|
+
}
|
|
762
|
+
const clone = this.arena.clone(token, true);
|
|
763
|
+
const propertyName = this.propertyNames.get(token);
|
|
764
|
+
if (propertyName != null) {
|
|
765
|
+
this.propertyNames.set(clone, propertyName);
|
|
766
|
+
}
|
|
767
|
+
return clone;
|
|
768
|
+
}
|
|
756
769
|
matchTypes(declaration) {
|
|
770
|
+
const arena = this.arena;
|
|
757
771
|
const patterns = this.pattern.slice();
|
|
758
772
|
const values = [];
|
|
773
|
+
const declarationValues = arena.tokens(declaration);
|
|
759
774
|
let i;
|
|
760
775
|
let j;
|
|
761
776
|
const map = new Map();
|
|
762
|
-
for (i = 0; i <
|
|
763
|
-
values.push(
|
|
777
|
+
for (i = 0; i < declarationValues.length; i++) {
|
|
778
|
+
values.push(declarationValues[i]);
|
|
764
779
|
}
|
|
765
780
|
for (i = 0; i < patterns.length; i++) {
|
|
766
781
|
for (j = 0; j < values.length; j++) {
|
|
@@ -769,34 +784,36 @@ class PropertyMap {
|
|
|
769
784
|
map.set(patterns[i], this.config.properties?.[patterns[i]]?.constraints?.mapping?.max ?? 1);
|
|
770
785
|
}
|
|
771
786
|
let count = map.get(patterns[i]);
|
|
772
|
-
if (count > 0 && matchType(values[j], this.config.properties[patterns[i]])) {
|
|
773
|
-
|
|
774
|
-
values[j][PROPERTYNAME] = patterns[i];
|
|
787
|
+
if (count > 0 && matchType(arena, values[j], this.config.properties[patterns[i]])) {
|
|
788
|
+
this.propertyNames.set(values[j], patterns[i]);
|
|
775
789
|
map.set(patterns[i], --count);
|
|
776
790
|
values.splice(j--, 1);
|
|
777
791
|
}
|
|
778
792
|
}
|
|
779
793
|
}
|
|
780
794
|
if (this.config.set != null) {
|
|
795
|
+
let modified = false;
|
|
781
796
|
for (const [key, val] of Object.entries(this.config.set)) {
|
|
782
797
|
if (map.has(key)) {
|
|
783
798
|
for (const v of val) {
|
|
784
799
|
// missing
|
|
785
800
|
if (map.get(v) == 1) {
|
|
786
|
-
let i =
|
|
801
|
+
let i = declarationValues.length;
|
|
787
802
|
while (i--) {
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
declaration.val.splice(i, 0, val, { typ: EnumToken.WhitespaceTokenType });
|
|
803
|
+
if (this.propertyNames.get(declarationValues[i]) == key) {
|
|
804
|
+
const val = arena.clone(declarationValues[i], true);
|
|
805
|
+
this.propertyNames.set(val, v);
|
|
806
|
+
declarationValues.splice(i, 0, val, arena.createToken(EnumToken.WhitespaceTokenType));
|
|
807
|
+
modified = true;
|
|
794
808
|
}
|
|
795
809
|
}
|
|
796
810
|
}
|
|
797
811
|
}
|
|
798
812
|
}
|
|
799
813
|
}
|
|
814
|
+
if (modified) {
|
|
815
|
+
arena.setTokenList(declaration, declarationValues);
|
|
816
|
+
}
|
|
800
817
|
}
|
|
801
818
|
}
|
|
802
819
|
removeDefaults(map, value) {
|
|
@@ -813,14 +830,10 @@ class PropertyMap {
|
|
|
813
830
|
value.splice(index, 1);
|
|
814
831
|
if (config.prefix != null) {
|
|
815
832
|
while (index-- > 0) {
|
|
816
|
-
if (value[index]
|
|
833
|
+
if (this.arena.dataTypes[value[index]] == EnumToken.WhitespaceTokenType) {
|
|
817
834
|
continue;
|
|
818
835
|
}
|
|
819
|
-
if (
|
|
820
|
-
// @ts-expect-error
|
|
821
|
-
value[index].typ == EnumToken[config.prefix.typ] &&
|
|
822
|
-
// @ts-ignore
|
|
823
|
-
value[index].val == config.prefix.val) {
|
|
836
|
+
if (matchConfigToken(this.arena, value[index], config.prefix)) {
|
|
824
837
|
value.splice(index, 1);
|
|
825
838
|
break;
|
|
826
839
|
}
|