@markuplint/types 3.0.0-dev.24 → 3.0.0-dev.290
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/README.md +63 -61
- package/lib/check-multi-types.d.ts +2 -2
- package/lib/check-multi-types.js +9 -13
- package/lib/check.d.ts +7 -6
- package/lib/check.js +20 -30
- package/lib/css-syntax.d.ts +1 -1
- package/lib/css-syntax.js +60 -63
- package/lib/debug.js +2 -6
- package/lib/defs.d.ts +1 -1
- package/lib/defs.js +163 -91
- package/lib/enum.d.ts +4 -3
- package/lib/enum.js +7 -12
- package/lib/get-candidate.d.ts +1 -1
- package/lib/get-candidate.js +3 -8
- package/lib/index.d.ts +3 -3
- package/lib/index.js +3 -6
- package/lib/keyword-type.d.ts +2 -2
- package/lib/keyword-type.js +17 -21
- package/lib/list.d.ts +4 -3
- package/lib/list.js +9 -13
- package/lib/match-result.d.ts +4 -4
- package/lib/match-result.js +6 -12
- package/lib/number.d.ts +3 -3
- package/lib/number.js +11 -15
- package/lib/primitive/index.d.ts +7 -7
- package/lib/primitive/index.js +7 -17
- package/lib/primitive/is-float.js +1 -5
- package/lib/primitive/is-int.js +1 -5
- package/lib/primitive/is-non-zero-uint.js +1 -5
- package/lib/primitive/is-quantity.d.ts +1 -1
- package/lib/primitive/is-quantity.js +9 -13
- package/lib/primitive/is-uint.d.ts +1 -1
- package/lib/primitive/is-uint.js +1 -5
- package/lib/primitive/range.js +1 -5
- package/lib/primitive/split-unit.js +3 -7
- package/lib/rfc/is-bcp-47.d.ts +1 -1
- package/lib/rfc/is-bcp-47.js +3 -7
- package/lib/token/index.d.ts +2 -2
- package/lib/token/index.js +2 -7
- package/lib/token/token-collection.d.ts +13 -13
- package/lib/token/token-collection.js +55 -50
- package/lib/token/token.d.ts +11 -10
- package/lib/token/token.js +16 -24
- package/lib/token/types.d.ts +3 -0
- package/lib/types.d.ts +47 -46
- package/lib/types.js +1 -2
- package/lib/types.schema.d.ts +2 -2
- package/lib/types.schema.js +1 -3
- package/lib/w3c/check-serialized-permissions-policy.d.ts +1 -1
- package/lib/w3c/check-serialized-permissions-policy.js +16 -20
- package/lib/whatwg/check-autocomplete.d.ts +1 -1
- package/lib/whatwg/check-autocomplete.js +28 -32
- package/lib/whatwg/check-datetime/date-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/date-string.js +9 -13
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +1 -1
- package/lib/whatwg/check-datetime/datetime-tokens.js +43 -46
- package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/duration-string.js +48 -44
- package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/global-date-and-time-string.js +17 -21
- package/lib/whatwg/check-datetime/index.d.ts +1 -1
- package/lib/whatwg/check-datetime/index.js +25 -29
- package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/local-date-and-time-string.js +25 -26
- package/lib/whatwg/check-datetime/month-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/month-string.js +9 -13
- package/lib/whatwg/check-datetime/time-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/time-string.js +9 -13
- package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +3 -3
- package/lib/whatwg/check-datetime/time-zone-offset-string.js +16 -21
- package/lib/whatwg/check-datetime/week-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/week-string.js +9 -13
- package/lib/whatwg/check-datetime/year-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/year-string.js +9 -13
- package/lib/whatwg/check-datetime/yearless-date-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/yearless-date-string.js +9 -13
- package/lib/whatwg/check-mime-type.d.ts +1 -1
- package/lib/whatwg/check-mime-type.js +12 -18
- package/lib/whatwg/is-abs-url.d.ts +1 -1
- package/lib/whatwg/is-abs-url.js +1 -5
- package/lib/whatwg/is-browser-context-name.d.ts +3 -1
- package/lib/whatwg/is-browser-context-name.js +3 -5
- package/lib/whatwg/is-custom-element-name.d.ts +1 -1
- package/lib/whatwg/is-custom-element-name.js +1 -5
- package/lib/whatwg/is-itemprop-name.d.ts +1 -1
- package/lib/whatwg/is-itemprop-name.js +2 -6
- package/lib/whatwg/is-navigable-target-name.d.ts +11 -0
- package/lib/whatwg/is-navigable-target-name.js +20 -0
- package/package.json +19 -13
- package/types.schema.json +314 -311
- package/gen/specific-schema.json +0 -98
- package/gen/types.ts +0 -66
- package/lib/check.spec.js +0 -76
- package/lib/css-syntax.spec.d.ts +0 -1
- package/lib/css-syntax.spec.js +0 -157
- package/lib/list.spec.d.ts +0 -1
- package/lib/list.spec.js +0 -129
- package/lib/primitive/index.spec.d.ts +0 -1
- package/lib/primitive/index.spec.js +0 -62
- package/lib/rfc/is-bcp-47.spec.d.ts +0 -1
- package/lib/rfc/is-bcp-47.spec.js +0 -19
- package/lib/token/token-collection.spec.d.ts +0 -1
- package/lib/token/token-collection.spec.js +0 -144
- package/lib/w3c/check-serialized-permissions-policy.spec.d.ts +0 -1
- package/lib/w3c/check-serialized-permissions-policy.spec.js +0 -34
- package/lib/whatwg/check-autocomplete.spec.d.ts +0 -1
- package/lib/whatwg/check-autocomplete.spec.js +0 -379
- package/lib/whatwg/check-datetime/index.spec.d.ts +0 -1
- package/lib/whatwg/check-datetime/index.spec.js +0 -318
- package/lib/whatwg/check-mime-type.spec.d.ts +0 -1
- package/lib/whatwg/check-mime-type.spec.js +0 -58
- package/lib/whatwg/is-abs-url.spec.d.ts +0 -1
- package/lib/whatwg/is-abs-url.spec.js +0 -8
- package/patches/css-tree+2.3.1.patch +0 -23
- package/src/check-multi-types.ts +0 -35
- package/src/check.spec.ts +0 -83
- package/src/check.ts +0 -48
- package/src/css-syntax.spec.ts +0 -167
- package/src/css-syntax.ts +0 -188
- package/src/debug.ts +0 -3
- package/src/defs.ts +0 -811
- package/src/enum.ts +0 -25
- package/src/get-candidate.ts +0 -24
- package/src/index.ts +0 -3
- package/src/keyword-type.ts +0 -64
- package/src/list.spec.ts +0 -133
- package/src/list.ts +0 -34
- package/src/match-result.ts +0 -49
- package/src/number.ts +0 -46
- package/src/primitive/index.spec.ts +0 -65
- package/src/primitive/index.ts +0 -7
- package/src/primitive/is-float.ts +0 -8
- package/src/primitive/is-int.ts +0 -8
- package/src/primitive/is-non-zero-uint.ts +0 -8
- package/src/primitive/is-quantity.ts +0 -38
- package/src/primitive/is-uint.ts +0 -15
- package/src/primitive/range.ts +0 -14
- package/src/primitive/split-unit.ts +0 -20
- package/src/rfc/is-bcp-47.spec.ts +0 -23
- package/src/rfc/is-bcp-47.ts +0 -13
- package/src/token/index.ts +0 -2
- package/src/token/token-collection.spec.ts +0 -147
- package/src/token/token-collection.ts +0 -444
- package/src/token/token.ts +0 -144
- package/src/types.schema.ts +0 -1113
- package/src/types.ts +0 -118
- package/src/w3c/check-serialized-permissions-policy.spec.ts +0 -38
- package/src/w3c/check-serialized-permissions-policy.ts +0 -303
- package/src/whatwg/check-autocomplete.spec.ts +0 -387
- package/src/whatwg/check-autocomplete.ts +0 -380
- package/src/whatwg/check-datetime/date-string.ts +0 -44
- package/src/whatwg/check-datetime/datetime-tokens.ts +0 -600
- package/src/whatwg/check-datetime/duration-string.ts +0 -399
- package/src/whatwg/check-datetime/global-date-and-time-string.ts +0 -96
- package/src/whatwg/check-datetime/index.spec.ts +0 -333
- package/src/whatwg/check-datetime/index.ts +0 -36
- package/src/whatwg/check-datetime/local-date-and-time-string.ts +0 -163
- package/src/whatwg/check-datetime/month-string.ts +0 -31
- package/src/whatwg/check-datetime/time-string.ts +0 -49
- package/src/whatwg/check-datetime/time-zone-offset-string.ts +0 -93
- package/src/whatwg/check-datetime/week-string.ts +0 -41
- package/src/whatwg/check-datetime/year-string.ts +0 -26
- package/src/whatwg/check-datetime/yearless-date-string.ts +0 -38
- package/src/whatwg/check-mime-type.spec.ts +0 -59
- package/src/whatwg/check-mime-type.ts +0 -46
- package/src/whatwg/is-abs-url.spec.ts +0 -8
- package/src/whatwg/is-abs-url.ts +0 -31
- package/src/whatwg/is-browser-context-name.ts +0 -16
- package/src/whatwg/is-custom-element-name.ts +0 -76
- package/src/whatwg/is-itemprop-name.ts +0 -17
- package/tsconfig.test.json +0 -3
- package/tsconfig.tsbuildinfo +0 -1
- /package/lib/{check.spec.d.ts → token/types.js} +0 -0
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const origin = typeof value === 'string' ? value : value.origin;
|
|
1
|
+
import { matched, unmatched } from '../match-result.js';
|
|
2
|
+
import { Token } from './token.js';
|
|
3
|
+
export class TokenCollection extends Array {
|
|
4
|
+
static fromPatterns(value, patterns,
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
6
|
+
typeOptions) {
|
|
7
|
+
const originalValue = typeof value === 'string' ? value : value.originalValue;
|
|
9
8
|
let strings = typeof value === 'string' ? value : value.value;
|
|
10
9
|
let cumulativeOffset = typeof value === 'string' ? 0 : value.offset;
|
|
11
10
|
const tokens = [];
|
|
12
11
|
function addToken(tokenValue) {
|
|
13
|
-
const token = new
|
|
12
|
+
const token = new Token(tokenValue, cumulativeOffset, originalValue);
|
|
14
13
|
tokens.push(token);
|
|
15
14
|
strings = strings.slice(tokenValue.length);
|
|
16
15
|
cumulativeOffset += tokenValue.length;
|
|
@@ -31,7 +30,7 @@ class TokenCollection extends Array {
|
|
|
31
30
|
value = strings.slice(res.index + res[0].length);
|
|
32
31
|
}
|
|
33
32
|
else {
|
|
34
|
-
value = res[0]
|
|
33
|
+
value = res[0] ?? '';
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
36
|
const token = addToken(value);
|
|
@@ -41,7 +40,7 @@ class TokenCollection extends Array {
|
|
|
41
40
|
if (isBroken) {
|
|
42
41
|
addToken(strings);
|
|
43
42
|
}
|
|
44
|
-
} while (
|
|
43
|
+
} while (typeOptions?.repeat && strings);
|
|
45
44
|
if (strings) {
|
|
46
45
|
addToken(strings);
|
|
47
46
|
}
|
|
@@ -50,15 +49,17 @@ class TokenCollection extends Array {
|
|
|
50
49
|
static get [Symbol.species]() {
|
|
51
50
|
return Array;
|
|
52
51
|
}
|
|
53
|
-
constructor(value,
|
|
52
|
+
constructor(value,
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
54
|
+
typeOptions) {
|
|
54
55
|
super();
|
|
55
|
-
this.disallowToSurroundBySpaces =
|
|
56
|
-
this.allowEmpty =
|
|
57
|
-
this.ordered =
|
|
58
|
-
this.unique =
|
|
59
|
-
this.caseInsensitive =
|
|
60
|
-
this.number = typeOptions
|
|
61
|
-
this.separator =
|
|
56
|
+
this.disallowToSurroundBySpaces = typeOptions?.disallowToSurroundBySpaces ?? false;
|
|
57
|
+
this.allowEmpty = typeOptions?.allowEmpty ?? true;
|
|
58
|
+
this.ordered = typeOptions?.ordered ?? false;
|
|
59
|
+
this.unique = typeOptions?.unique ?? false;
|
|
60
|
+
this.caseInsensitive = typeOptions?.caseInsensitive ?? true;
|
|
61
|
+
this.number = typeOptions?.number;
|
|
62
|
+
this.separator = typeOptions?.separator ?? 'space';
|
|
62
63
|
if (typeof value === 'number') {
|
|
63
64
|
this.length = value;
|
|
64
65
|
return;
|
|
@@ -70,12 +71,12 @@ class TokenCollection extends Array {
|
|
|
70
71
|
if (this.separator === 'comma') {
|
|
71
72
|
separators.push(',');
|
|
72
73
|
}
|
|
73
|
-
if (typeOptions
|
|
74
|
-
if (
|
|
75
|
-
separators.push(
|
|
74
|
+
if (typeOptions?.specificSeparator != null) {
|
|
75
|
+
if (typeof typeOptions.specificSeparator === 'string') {
|
|
76
|
+
separators.push(typeOptions.specificSeparator);
|
|
76
77
|
}
|
|
77
78
|
else {
|
|
78
|
-
separators.push(typeOptions.specificSeparator);
|
|
79
|
+
separators.push(...typeOptions.specificSeparator);
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
const chars = value.split('');
|
|
@@ -88,10 +89,11 @@ class TokenCollection extends Array {
|
|
|
88
89
|
continue;
|
|
89
90
|
}
|
|
90
91
|
const lastChar = last[0];
|
|
91
|
-
if (
|
|
92
|
-
!separators.includes(
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
if (lastChar &&
|
|
93
|
+
!separators.includes(char) &&
|
|
94
|
+
!separators.includes(lastChar) &&
|
|
95
|
+
((Token.whitespace.includes(lastChar) && Token.whitespace.includes(char)) ||
|
|
96
|
+
(!Token.whitespace.includes(lastChar) && !Token.whitespace.includes(char)))) {
|
|
95
97
|
values.push(last + char);
|
|
96
98
|
}
|
|
97
99
|
else {
|
|
@@ -101,7 +103,7 @@ class TokenCollection extends Array {
|
|
|
101
103
|
}
|
|
102
104
|
let offset = 0;
|
|
103
105
|
values.forEach(v => {
|
|
104
|
-
const token = new
|
|
106
|
+
const token = new Token(v, offset, value, separators);
|
|
105
107
|
this.push(token);
|
|
106
108
|
offset += v.length;
|
|
107
109
|
});
|
|
@@ -111,7 +113,6 @@ class TokenCollection extends Array {
|
|
|
111
113
|
return value;
|
|
112
114
|
}
|
|
113
115
|
check(options = {}) {
|
|
114
|
-
var _c;
|
|
115
116
|
const { expects, ref } = options;
|
|
116
117
|
if (this.disallowToSurroundBySpaces) {
|
|
117
118
|
for (const token of this) {
|
|
@@ -125,8 +126,8 @@ class TokenCollection extends Array {
|
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
128
|
if (this.separator === 'comma') {
|
|
128
|
-
const tokensWithoutWP = this.filter(token => token.type !==
|
|
129
|
-
const consecutiveComma = tokensWithoutWP.getConsecutiveToken(
|
|
129
|
+
const tokensWithoutWP = this.filter(token => token.type !== Token.WhiteSpace);
|
|
130
|
+
const consecutiveComma = tokensWithoutWP.getConsecutiveToken(Token.Comma);
|
|
130
131
|
if (consecutiveComma) {
|
|
131
132
|
return consecutiveComma.unmatched({
|
|
132
133
|
reason: 'unexpected-comma',
|
|
@@ -134,14 +135,14 @@ class TokenCollection extends Array {
|
|
|
134
135
|
expects,
|
|
135
136
|
});
|
|
136
137
|
}
|
|
137
|
-
if (tokensWithoutWP[0] && tokensWithoutWP[0].type ===
|
|
138
|
+
if (tokensWithoutWP[0] && tokensWithoutWP[0].type === Token.Comma) {
|
|
138
139
|
return tokensWithoutWP[0].unmatched({
|
|
139
140
|
reason: 'unexpected-comma',
|
|
140
141
|
ref,
|
|
141
142
|
expects,
|
|
142
143
|
});
|
|
143
144
|
}
|
|
144
|
-
const takeTurnsError = tokensWithoutWP.takeTurns([
|
|
145
|
+
const takeTurnsError = tokensWithoutWP.takeTurns([Token.Ident, Token.Comma], Token.Ident);
|
|
145
146
|
if (takeTurnsError) {
|
|
146
147
|
if (takeTurnsError.unexpectedLastToken) {
|
|
147
148
|
return takeTurnsError.token.unmatched({
|
|
@@ -167,9 +168,9 @@ class TokenCollection extends Array {
|
|
|
167
168
|
}
|
|
168
169
|
}
|
|
169
170
|
const identTokens = this.getIdentTokens();
|
|
170
|
-
const allowEmpty =
|
|
171
|
+
const allowEmpty = this.allowEmpty ?? true;
|
|
171
172
|
if (!allowEmpty && identTokens.length === 0) {
|
|
172
|
-
return
|
|
173
|
+
return unmatched(this.value, 'empty-token', {
|
|
173
174
|
ref,
|
|
174
175
|
expects,
|
|
175
176
|
});
|
|
@@ -185,12 +186,12 @@ class TokenCollection extends Array {
|
|
|
185
186
|
});
|
|
186
187
|
}
|
|
187
188
|
}
|
|
188
|
-
return
|
|
189
|
+
return matched();
|
|
189
190
|
}
|
|
190
191
|
chunk(split) {
|
|
191
192
|
const chunks = [];
|
|
192
193
|
const tokens = this.slice();
|
|
193
|
-
while (tokens.length) {
|
|
194
|
+
while (tokens.length > 0) {
|
|
194
195
|
const chunkTokens = tokens.splice(0, split);
|
|
195
196
|
const chunk = TokenCollection._new(chunkTokens, this);
|
|
196
197
|
chunks.push(chunk);
|
|
@@ -233,10 +234,10 @@ class TokenCollection extends Array {
|
|
|
233
234
|
wait--;
|
|
234
235
|
const result = callback.call(this, head, tail);
|
|
235
236
|
if (result && !result.matched) {
|
|
236
|
-
passCount += result.passCount
|
|
237
|
+
passCount += result.passCount ?? 0;
|
|
237
238
|
if (prev && result.offset === 0 && result.length === 0) {
|
|
238
|
-
const { offset, line, column } =
|
|
239
|
-
firstUnmatched = firstUnmatched
|
|
239
|
+
const { offset, line, column } = Token.shiftLocation(prev, cumulativeOffset);
|
|
240
|
+
firstUnmatched = firstUnmatched ?? {
|
|
240
241
|
...result,
|
|
241
242
|
offset,
|
|
242
243
|
line,
|
|
@@ -244,7 +245,7 @@ class TokenCollection extends Array {
|
|
|
244
245
|
};
|
|
245
246
|
}
|
|
246
247
|
if (!prev && this.value.length === 0) {
|
|
247
|
-
firstUnmatched = firstUnmatched
|
|
248
|
+
firstUnmatched = firstUnmatched ?? {
|
|
248
249
|
...result,
|
|
249
250
|
reason: 'empty-token',
|
|
250
251
|
expects: undefined,
|
|
@@ -261,17 +262,17 @@ class TokenCollection extends Array {
|
|
|
261
262
|
}
|
|
262
263
|
}
|
|
263
264
|
}
|
|
264
|
-
firstUnmatched = firstUnmatched
|
|
265
|
+
firstUnmatched = firstUnmatched ?? result;
|
|
265
266
|
}
|
|
266
267
|
else if (result && !firstUnmatched && result.matched) {
|
|
267
268
|
return result;
|
|
268
269
|
}
|
|
269
270
|
else {
|
|
270
|
-
if (
|
|
271
|
+
if (head?.value && !head.match(/^\s*$/)) {
|
|
271
272
|
passCount += 4 * wait;
|
|
272
273
|
}
|
|
273
274
|
}
|
|
274
|
-
cumulativeOffset =
|
|
275
|
+
cumulativeOffset = head?.length ?? 0;
|
|
275
276
|
headAndTail = tail.headAndTail();
|
|
276
277
|
prev = head;
|
|
277
278
|
head = headAndTail.head;
|
|
@@ -284,7 +285,7 @@ class TokenCollection extends Array {
|
|
|
284
285
|
};
|
|
285
286
|
return res;
|
|
286
287
|
}
|
|
287
|
-
return
|
|
288
|
+
return matched();
|
|
288
289
|
}
|
|
289
290
|
filter(callback) {
|
|
290
291
|
return TokenCollection._new(super.filter(callback), this);
|
|
@@ -295,7 +296,7 @@ class TokenCollection extends Array {
|
|
|
295
296
|
return current;
|
|
296
297
|
}
|
|
297
298
|
});
|
|
298
|
-
return resultToken
|
|
299
|
+
return resultToken ?? null;
|
|
299
300
|
}
|
|
300
301
|
getDuplicated() {
|
|
301
302
|
const aList = this.slice();
|
|
@@ -319,7 +320,7 @@ class TokenCollection extends Array {
|
|
|
319
320
|
return null;
|
|
320
321
|
}
|
|
321
322
|
getIdentTokens() {
|
|
322
|
-
return this.filter(token => token.type ===
|
|
323
|
+
return this.filter(token => token.type === Token.Ident);
|
|
323
324
|
}
|
|
324
325
|
/**
|
|
325
326
|
*
|
|
@@ -332,7 +333,7 @@ class TokenCollection extends Array {
|
|
|
332
333
|
const copy = this.slice();
|
|
333
334
|
const head = copy.shift();
|
|
334
335
|
if (!head) {
|
|
335
|
-
return { head: head
|
|
336
|
+
return { head: head ?? null, tail: TokenCollection._new([], this) };
|
|
336
337
|
}
|
|
337
338
|
const tail = TokenCollection._new(copy, this);
|
|
338
339
|
return { head, tail };
|
|
@@ -353,6 +354,9 @@ class TokenCollection extends Array {
|
|
|
353
354
|
const tokens = this.slice();
|
|
354
355
|
for (let i = 0; i < tokens.length; i++) {
|
|
355
356
|
const token = tokens[i];
|
|
357
|
+
if (!token) {
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
356
360
|
const expectedTokenNumber = tokenNumbers[i % tokenNumbers.length];
|
|
357
361
|
if (token.type !== expectedTokenNumber) {
|
|
358
362
|
return {
|
|
@@ -374,10 +378,11 @@ class TokenCollection extends Array {
|
|
|
374
378
|
toJSON() {
|
|
375
379
|
return this.map(t => t.toJSON());
|
|
376
380
|
}
|
|
377
|
-
static _new(tokens,
|
|
381
|
+
static _new(tokens,
|
|
382
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
383
|
+
old) {
|
|
378
384
|
const newCollection = new TokenCollection('', old);
|
|
379
385
|
newCollection.push(...tokens);
|
|
380
386
|
return newCollection;
|
|
381
387
|
}
|
|
382
388
|
}
|
|
383
|
-
exports.TokenCollection = TokenCollection;
|
package/lib/token/token.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TokenValue } from './types.js';
|
|
2
|
+
import type { UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from '../types.js';
|
|
2
3
|
export declare class Token {
|
|
3
|
-
#private;
|
|
4
4
|
/**
|
|
5
5
|
* @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
|
|
6
6
|
*/
|
|
@@ -20,28 +20,29 @@ export declare class Token {
|
|
|
20
20
|
static readonly whitespace: ReadonlyArray<string>;
|
|
21
21
|
static getCol(value: string, offset: number): number;
|
|
22
22
|
static getLine(value: string, offset: number): number;
|
|
23
|
-
static getType(value: string, separators?: string[]): 1 | 13 | 18;
|
|
24
|
-
static shiftLocation(token: Token
|
|
23
|
+
static getType(value: string, separators?: readonly string[]): 1 | 13 | 18;
|
|
24
|
+
static shiftLocation(token: Readonly<Token>, offset: number): {
|
|
25
25
|
offset: number;
|
|
26
26
|
line: number;
|
|
27
27
|
column: number;
|
|
28
28
|
};
|
|
29
29
|
readonly offset: number;
|
|
30
|
+
readonly originalValue: string;
|
|
30
31
|
readonly type: number;
|
|
31
32
|
readonly value: string;
|
|
32
|
-
constructor(value: string, offset: number, originalValue: string, separators?: string[]);
|
|
33
|
+
constructor(value: string, offset: number, originalValue: string, separators?: readonly string[]);
|
|
33
34
|
get length(): number;
|
|
34
|
-
|
|
35
|
+
clone(): Token;
|
|
35
36
|
/**
|
|
36
37
|
*
|
|
37
38
|
* @param value The token value or the token type or its list
|
|
38
39
|
*/
|
|
39
|
-
includes(value:
|
|
40
|
+
includes(value: TokenValue, caseInsensitive?: boolean): boolean;
|
|
40
41
|
/**
|
|
41
42
|
*
|
|
42
43
|
* @param value The token value or the token type or its list
|
|
43
44
|
*/
|
|
44
|
-
match(value:
|
|
45
|
+
match(value: TokenValue, caseInsensitive?: boolean): boolean;
|
|
45
46
|
toJSON(): {
|
|
46
47
|
type: number;
|
|
47
48
|
value: string;
|
|
@@ -49,7 +50,7 @@ export declare class Token {
|
|
|
49
50
|
};
|
|
50
51
|
toNumber(): number;
|
|
51
52
|
unmatched(options?: UnmatchedResultOptions & {
|
|
52
|
-
ref?: string;
|
|
53
|
-
reason?: UnmatchedResultReason;
|
|
53
|
+
readonly ref?: string;
|
|
54
|
+
readonly reason?: UnmatchedResultReason;
|
|
54
55
|
}): UnmatchedResult;
|
|
55
56
|
}
|
package/lib/token/token.js
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
var _Token_originalValue;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.Token = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
class Token {
|
|
1
|
+
export class Token {
|
|
7
2
|
static getCol(value, offset) {
|
|
8
3
|
const lines = value.slice(0, offset).split(/\n/g);
|
|
9
|
-
return lines[lines.length - 1].length + 1;
|
|
4
|
+
return (lines[lines.length - 1] ?? '').length + 1;
|
|
10
5
|
}
|
|
11
6
|
static getLine(value, offset) {
|
|
12
7
|
return value.slice(0, offset).split(/\n/g).length;
|
|
13
8
|
}
|
|
14
9
|
static getType(value, separators) {
|
|
15
|
-
if (Token.whitespace.includes(value[0])) {
|
|
10
|
+
if (Token.whitespace.includes(value[0] ?? '')) {
|
|
16
11
|
return Token.WhiteSpace;
|
|
17
12
|
}
|
|
18
|
-
if (separators
|
|
13
|
+
if (separators?.includes(value[0] ?? '')) {
|
|
19
14
|
switch (value[0]) {
|
|
20
15
|
case ',':
|
|
21
16
|
return Token.Comma;
|
|
@@ -27,22 +22,21 @@ class Token {
|
|
|
27
22
|
const shifted = token.offset + offset;
|
|
28
23
|
return {
|
|
29
24
|
offset: shifted,
|
|
30
|
-
line: Token.getLine(
|
|
31
|
-
column: Token.getCol(
|
|
25
|
+
line: Token.getLine(token.originalValue, shifted),
|
|
26
|
+
column: Token.getCol(token.originalValue, shifted),
|
|
32
27
|
};
|
|
33
28
|
}
|
|
34
29
|
constructor(value, offset, originalValue, separators) {
|
|
35
|
-
_Token_originalValue.set(this, void 0);
|
|
36
30
|
this.type = Token.getType(value, separators);
|
|
37
31
|
this.value = value;
|
|
38
32
|
this.offset = offset;
|
|
39
|
-
|
|
33
|
+
this.originalValue = originalValue;
|
|
40
34
|
}
|
|
41
35
|
get length() {
|
|
42
36
|
return this.value.length;
|
|
43
37
|
}
|
|
44
|
-
|
|
45
|
-
return
|
|
38
|
+
clone() {
|
|
39
|
+
return new Token(this.value, this.offset, this.originalValue);
|
|
46
40
|
}
|
|
47
41
|
/**
|
|
48
42
|
*
|
|
@@ -55,7 +49,7 @@ class Token {
|
|
|
55
49
|
if (typeof value === 'string') {
|
|
56
50
|
const a = caseInsensitive ? this.value.toLowerCase() : this.value;
|
|
57
51
|
const b = caseInsensitive ? value.toLowerCase() : value;
|
|
58
|
-
return a.
|
|
52
|
+
return a.includes(b);
|
|
59
53
|
}
|
|
60
54
|
if (value instanceof RegExp) {
|
|
61
55
|
const pattern = new RegExp(value, caseInsensitive ? 'i' : '');
|
|
@@ -90,25 +84,23 @@ class Token {
|
|
|
90
84
|
};
|
|
91
85
|
}
|
|
92
86
|
toNumber() {
|
|
93
|
-
|
|
87
|
+
const num = parseFloat(this.value);
|
|
88
|
+
return isNaN(num) ? 0 : num;
|
|
94
89
|
}
|
|
95
90
|
unmatched(options) {
|
|
96
|
-
var _a;
|
|
97
91
|
return {
|
|
98
92
|
...options,
|
|
99
93
|
matched: false,
|
|
100
|
-
ref:
|
|
94
|
+
ref: options?.ref ?? null,
|
|
101
95
|
raw: this.value,
|
|
102
96
|
offset: this.offset,
|
|
103
97
|
length: this.value.length,
|
|
104
|
-
line: Token.getLine(
|
|
105
|
-
column: Token.getCol(
|
|
106
|
-
reason:
|
|
98
|
+
line: Token.getLine(this.originalValue, this.offset),
|
|
99
|
+
column: Token.getCol(this.originalValue, this.offset),
|
|
100
|
+
reason: options?.reason ?? 'syntax-error',
|
|
107
101
|
};
|
|
108
102
|
}
|
|
109
103
|
}
|
|
110
|
-
exports.Token = Token;
|
|
111
|
-
_Token_originalValue = new WeakMap();
|
|
112
104
|
/**
|
|
113
105
|
* @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
|
|
114
106
|
*/
|
package/lib/types.d.ts
CHANGED
|
@@ -1,78 +1,79 @@
|
|
|
1
|
-
import type { cssSyntaxMatch } from './css-syntax';
|
|
2
|
-
export type { Type, List, Enum, CssSyntax, KeywordDefinedType, Number } from './types.schema';
|
|
1
|
+
import type { cssSyntaxMatch } from './css-syntax.js';
|
|
2
|
+
export type { Type, List, Enum, CssSyntax, KeywordDefinedType, Number } from './types.schema.js';
|
|
3
3
|
export type Result = UnmatchedResult | MatchedResult;
|
|
4
4
|
export type UnmatchedResult = {
|
|
5
|
-
matched: false;
|
|
6
|
-
ref: string | null;
|
|
7
|
-
raw: string;
|
|
8
|
-
length: number;
|
|
9
|
-
offset: number;
|
|
10
|
-
line: number;
|
|
11
|
-
column: number;
|
|
12
|
-
reason: UnmatchedResultReason;
|
|
13
|
-
passCount?: number;
|
|
5
|
+
readonly matched: false;
|
|
6
|
+
readonly ref: string | null;
|
|
7
|
+
readonly raw: string;
|
|
8
|
+
readonly length: number;
|
|
9
|
+
readonly offset: number;
|
|
10
|
+
readonly line: number;
|
|
11
|
+
readonly column: number;
|
|
12
|
+
readonly reason: UnmatchedResultReason;
|
|
13
|
+
readonly passCount?: number;
|
|
14
14
|
} & UnmatchedResultOptions;
|
|
15
15
|
export type UnmatchedResultOptions = {
|
|
16
|
-
partName?: string;
|
|
17
|
-
expects?: Expect[];
|
|
18
|
-
extra?: Expect;
|
|
19
|
-
candidate?: string;
|
|
16
|
+
readonly partName?: string;
|
|
17
|
+
readonly expects?: readonly Expect[];
|
|
18
|
+
readonly extra?: Expect;
|
|
19
|
+
readonly candidate?: string;
|
|
20
|
+
readonly fallbackTo?: string;
|
|
20
21
|
};
|
|
21
22
|
export type UnmatchedResultReason = 'syntax-error' | 'typo' | 'missing-token' | 'missing-comma' | 'unexpected-token' | 'unexpected-space' | 'unexpected-newline' | 'unexpected-comma' | 'empty-token' | 'out-of-range' | 'doesnt-exist-in-enum' | 'duplicated' | 'illegal-combination' | 'illegal-order' | 'extra-token' | 'must-be-percent-encoded' | 'must-be-serialized' | {
|
|
22
|
-
type: 'out-of-range';
|
|
23
|
-
gt?: number;
|
|
24
|
-
gte?: number;
|
|
25
|
-
lt?: number;
|
|
26
|
-
lte?: number;
|
|
23
|
+
readonly type: 'out-of-range';
|
|
24
|
+
readonly gt?: number;
|
|
25
|
+
readonly gte?: number;
|
|
26
|
+
readonly lt?: number;
|
|
27
|
+
readonly lte?: number;
|
|
27
28
|
} | {
|
|
28
|
-
type: 'out-of-range-length-char';
|
|
29
|
-
gte: number;
|
|
30
|
-
lte?: number;
|
|
29
|
+
readonly type: 'out-of-range-length-char';
|
|
30
|
+
readonly gte: number;
|
|
31
|
+
readonly lte?: number;
|
|
31
32
|
} | {
|
|
32
|
-
type: 'out-of-range-length-digit';
|
|
33
|
-
gte: number;
|
|
34
|
-
lte?: number;
|
|
33
|
+
readonly type: 'out-of-range-length-digit';
|
|
34
|
+
readonly gte: number;
|
|
35
|
+
readonly lte?: number;
|
|
35
36
|
};
|
|
36
37
|
export type MatchedResult = {
|
|
37
|
-
matched: true;
|
|
38
|
+
readonly matched: true;
|
|
38
39
|
};
|
|
39
40
|
export type Expect = {
|
|
40
|
-
type: 'const' | 'format' | 'syntax' | 'regexp' | 'common';
|
|
41
|
-
value: string;
|
|
41
|
+
readonly type: 'const' | 'format' | 'syntax' | 'regexp' | 'common';
|
|
42
|
+
readonly value: string;
|
|
42
43
|
};
|
|
43
44
|
export type FormattedPrimitiveTypeCheck = (value: string) => boolean;
|
|
44
45
|
export type FormattedPrimitiveTypeCreator<O = never> = (options?: O) => FormattedPrimitiveTypeCheck;
|
|
45
46
|
export type Defs = Record<string, CustomCssSyntax | CustomSyntax>;
|
|
46
47
|
export type CustomSyntax = {
|
|
47
|
-
ref: string;
|
|
48
|
-
expects?: Expect[];
|
|
49
|
-
is: CustomSyntaxCheck;
|
|
48
|
+
readonly ref: string;
|
|
49
|
+
readonly expects?: readonly Expect[];
|
|
50
|
+
readonly is: CustomSyntaxCheck;
|
|
50
51
|
};
|
|
51
52
|
export type CustomSyntaxCheck = (value: string) => Result;
|
|
52
53
|
export type CustomSyntaxChecker<O = {}> = (options?: O) => CustomSyntaxCheck;
|
|
53
54
|
export type CustomCssSyntax = {
|
|
54
|
-
ref: string;
|
|
55
|
-
caseSensitive?: boolean;
|
|
56
|
-
expects?: Expect[];
|
|
57
|
-
syntax: {
|
|
58
|
-
apply: `<${string}>`;
|
|
59
|
-
def: Record<string, string | CssSyntaxTokenizer
|
|
55
|
+
readonly ref: string;
|
|
56
|
+
readonly caseSensitive?: boolean;
|
|
57
|
+
readonly expects?: readonly Expect[];
|
|
58
|
+
readonly syntax: {
|
|
59
|
+
readonly apply: `<${string}>`;
|
|
60
|
+
readonly def: Readonly<Record<string, string | CssSyntaxTokenizer>>;
|
|
60
61
|
/**
|
|
61
62
|
* @deprecated
|
|
62
63
|
*/
|
|
63
|
-
ebnf?: Record<string, string | string[]
|
|
64
|
+
readonly ebnf?: Readonly<Record<string, string | readonly string[]>>;
|
|
64
65
|
/**
|
|
65
66
|
* @deprecated
|
|
66
67
|
*/
|
|
67
|
-
properties?: Record<string, string
|
|
68
|
+
readonly properties?: Readonly<Record<string, string>>;
|
|
68
69
|
};
|
|
69
70
|
};
|
|
70
71
|
export type CSSSyntaxToken = {
|
|
71
|
-
type: number;
|
|
72
|
-
value: string;
|
|
73
|
-
index: number;
|
|
74
|
-
balance: number;
|
|
75
|
-
node?: any;
|
|
72
|
+
readonly type: number;
|
|
73
|
+
readonly value: string;
|
|
74
|
+
readonly index: number;
|
|
75
|
+
readonly balance: number;
|
|
76
|
+
readonly node?: any;
|
|
76
77
|
};
|
|
77
|
-
export type CssSyntaxTokenizer = (token: CSSSyntaxToken | null, getNextToken: GetNextToken, match: typeof cssSyntaxMatch) => number;
|
|
78
|
+
export type CssSyntaxTokenizer = (token: Readonly<CSSSyntaxToken> | null, getNextToken: GetNextToken, match: typeof cssSyntaxMatch) => number;
|
|
78
79
|
export type GetNextToken = (length: number) => CSSSyntaxToken | null;
|
package/lib/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|