@markuplint/types 3.10.0 → 4.0.0-alpha.2
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/lib/check-multi-types.d.ts +2 -2
- package/lib/check-multi-types.js +9 -14
- package/lib/check.d.ts +1 -1
- package/lib/check.js +20 -30
- package/lib/css-syntax.d.ts +1 -1
- package/lib/css-syntax.js +18 -23
- package/lib/debug.js +2 -6
- package/lib/defs.d.ts +1 -1
- package/lib/defs.js +91 -94
- package/lib/enum.d.ts +2 -2
- package/lib/enum.js +6 -11
- 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 -22
- package/lib/list.d.ts +2 -2
- package/lib/list.js +9 -14
- package/lib/match-result.d.ts +2 -2
- package/lib/match-result.js +6 -13
- package/lib/number.d.ts +2 -2
- 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.js +9 -13
- 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 +4 -5
- package/lib/token/token-collection.js +35 -43
- package/lib/token/token.d.ts +3 -3
- package/lib/token/token.js +6 -13
- package/lib/token/types.js +1 -2
- package/lib/types.d.ts +2 -2
- package/lib/types.js +1 -2
- package/lib/types.schema.js +1 -2
- 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 +24 -28
- 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 +40 -46
- package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/duration-string.js +38 -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 +20 -25
- 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 -22
- 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 +11 -17
- 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 +1 -1
- package/lib/whatwg/is-browser-context-name.js +1 -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 +1 -5
- package/lib/whatwg/is-navigable-target-name.d.ts +1 -1
- package/lib/whatwg/is-navigable-target-name.js +1 -5
- package/package.json +12 -7
- package/test/check.spec.js +0 -89
- package/test/css-syntax.spec.js +0 -170
- package/test/list.spec.js +0 -133
- package/test/primitive/index.spec.js +0 -65
- package/test/rfc/is-bcp-47.spec.js +0 -23
- package/test/token/token-collection.spec.js +0 -146
- package/test/w3c/check-serialized-permissions-policy.spec.js +0 -36
- package/test/whatwg/check-autocomplete.spec.js +0 -387
- package/test/whatwg/check-datetime/index.spec.js +0 -336
- package/test/whatwg/check-mime-type.spec.js +0 -59
- package/test/whatwg/is-abs-url.spec.js +0 -8
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const match_result_1 = require("../match-result");
|
|
5
|
-
const token_1 = require("./token");
|
|
6
|
-
class TokenCollection extends Array {
|
|
1
|
+
import { matched, unmatched } from '../match-result.js';
|
|
2
|
+
import { Token } from './token.js';
|
|
3
|
+
export class TokenCollection extends Array {
|
|
7
4
|
static fromPatterns(value, patterns,
|
|
8
5
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
9
6
|
typeOptions) {
|
|
10
|
-
var _c;
|
|
11
7
|
const originalValue = typeof value === 'string' ? value : value.originalValue;
|
|
12
8
|
let strings = typeof value === 'string' ? value : value.value;
|
|
13
9
|
let cumulativeOffset = typeof value === 'string' ? 0 : value.offset;
|
|
14
10
|
const tokens = [];
|
|
15
11
|
function addToken(tokenValue) {
|
|
16
|
-
const token = new
|
|
12
|
+
const token = new Token(tokenValue, cumulativeOffset, originalValue);
|
|
17
13
|
tokens.push(token);
|
|
18
14
|
strings = strings.slice(tokenValue.length);
|
|
19
15
|
cumulativeOffset += tokenValue.length;
|
|
@@ -34,7 +30,7 @@ class TokenCollection extends Array {
|
|
|
34
30
|
value = strings.slice(res.index + res[0].length);
|
|
35
31
|
}
|
|
36
32
|
else {
|
|
37
|
-
value =
|
|
33
|
+
value = res[0] ?? '';
|
|
38
34
|
}
|
|
39
35
|
}
|
|
40
36
|
const token = addToken(value);
|
|
@@ -44,7 +40,7 @@ class TokenCollection extends Array {
|
|
|
44
40
|
if (isBroken) {
|
|
45
41
|
addToken(strings);
|
|
46
42
|
}
|
|
47
|
-
} while (
|
|
43
|
+
} while (typeOptions?.repeat && strings);
|
|
48
44
|
if (strings) {
|
|
49
45
|
addToken(strings);
|
|
50
46
|
}
|
|
@@ -56,15 +52,14 @@ class TokenCollection extends Array {
|
|
|
56
52
|
constructor(value,
|
|
57
53
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
58
54
|
typeOptions) {
|
|
59
|
-
var _c, _d, _e, _f, _g, _h;
|
|
60
55
|
super();
|
|
61
|
-
this.disallowToSurroundBySpaces =
|
|
62
|
-
this.allowEmpty =
|
|
63
|
-
this.ordered =
|
|
64
|
-
this.unique =
|
|
65
|
-
this.caseInsensitive =
|
|
66
|
-
this.number = typeOptions
|
|
67
|
-
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';
|
|
68
63
|
if (typeof value === 'number') {
|
|
69
64
|
this.length = value;
|
|
70
65
|
return;
|
|
@@ -76,7 +71,7 @@ class TokenCollection extends Array {
|
|
|
76
71
|
if (this.separator === 'comma') {
|
|
77
72
|
separators.push(',');
|
|
78
73
|
}
|
|
79
|
-
if (
|
|
74
|
+
if (typeOptions?.specificSeparator != null) {
|
|
80
75
|
if (typeof typeOptions.specificSeparator === 'string') {
|
|
81
76
|
separators.push(typeOptions.specificSeparator);
|
|
82
77
|
}
|
|
@@ -97,8 +92,8 @@ class TokenCollection extends Array {
|
|
|
97
92
|
if (lastChar &&
|
|
98
93
|
!separators.includes(char) &&
|
|
99
94
|
!separators.includes(lastChar) &&
|
|
100
|
-
((
|
|
101
|
-
(!
|
|
95
|
+
((Token.whitespace.includes(lastChar) && Token.whitespace.includes(char)) ||
|
|
96
|
+
(!Token.whitespace.includes(lastChar) && !Token.whitespace.includes(char)))) {
|
|
102
97
|
values.push(last + char);
|
|
103
98
|
}
|
|
104
99
|
else {
|
|
@@ -108,7 +103,7 @@ class TokenCollection extends Array {
|
|
|
108
103
|
}
|
|
109
104
|
let offset = 0;
|
|
110
105
|
values.forEach(v => {
|
|
111
|
-
const token = new
|
|
106
|
+
const token = new Token(v, offset, value, separators);
|
|
112
107
|
this.push(token);
|
|
113
108
|
offset += v.length;
|
|
114
109
|
});
|
|
@@ -118,7 +113,6 @@ class TokenCollection extends Array {
|
|
|
118
113
|
return value;
|
|
119
114
|
}
|
|
120
115
|
check(options = {}) {
|
|
121
|
-
var _c;
|
|
122
116
|
const { expects, ref } = options;
|
|
123
117
|
if (this.disallowToSurroundBySpaces) {
|
|
124
118
|
for (const token of this) {
|
|
@@ -132,8 +126,8 @@ class TokenCollection extends Array {
|
|
|
132
126
|
}
|
|
133
127
|
}
|
|
134
128
|
if (this.separator === 'comma') {
|
|
135
|
-
const tokensWithoutWP = this.filter(token => token.type !==
|
|
136
|
-
const consecutiveComma = tokensWithoutWP.getConsecutiveToken(
|
|
129
|
+
const tokensWithoutWP = this.filter(token => token.type !== Token.WhiteSpace);
|
|
130
|
+
const consecutiveComma = tokensWithoutWP.getConsecutiveToken(Token.Comma);
|
|
137
131
|
if (consecutiveComma) {
|
|
138
132
|
return consecutiveComma.unmatched({
|
|
139
133
|
reason: 'unexpected-comma',
|
|
@@ -141,14 +135,14 @@ class TokenCollection extends Array {
|
|
|
141
135
|
expects,
|
|
142
136
|
});
|
|
143
137
|
}
|
|
144
|
-
if (tokensWithoutWP[0] && tokensWithoutWP[0].type ===
|
|
138
|
+
if (tokensWithoutWP[0] && tokensWithoutWP[0].type === Token.Comma) {
|
|
145
139
|
return tokensWithoutWP[0].unmatched({
|
|
146
140
|
reason: 'unexpected-comma',
|
|
147
141
|
ref,
|
|
148
142
|
expects,
|
|
149
143
|
});
|
|
150
144
|
}
|
|
151
|
-
const takeTurnsError = tokensWithoutWP.takeTurns([
|
|
145
|
+
const takeTurnsError = tokensWithoutWP.takeTurns([Token.Ident, Token.Comma], Token.Ident);
|
|
152
146
|
if (takeTurnsError) {
|
|
153
147
|
if (takeTurnsError.unexpectedLastToken) {
|
|
154
148
|
return takeTurnsError.token.unmatched({
|
|
@@ -174,9 +168,9 @@ class TokenCollection extends Array {
|
|
|
174
168
|
}
|
|
175
169
|
}
|
|
176
170
|
const identTokens = this.getIdentTokens();
|
|
177
|
-
const allowEmpty =
|
|
171
|
+
const allowEmpty = this.allowEmpty ?? true;
|
|
178
172
|
if (!allowEmpty && identTokens.length === 0) {
|
|
179
|
-
return
|
|
173
|
+
return unmatched(this.value, 'empty-token', {
|
|
180
174
|
ref,
|
|
181
175
|
expects,
|
|
182
176
|
});
|
|
@@ -192,7 +186,7 @@ class TokenCollection extends Array {
|
|
|
192
186
|
});
|
|
193
187
|
}
|
|
194
188
|
}
|
|
195
|
-
return
|
|
189
|
+
return matched();
|
|
196
190
|
}
|
|
197
191
|
chunk(split) {
|
|
198
192
|
const chunks = [];
|
|
@@ -228,7 +222,6 @@ class TokenCollection extends Array {
|
|
|
228
222
|
return [a, b];
|
|
229
223
|
}
|
|
230
224
|
eachCheck(...callbacks) {
|
|
231
|
-
var _c, _d;
|
|
232
225
|
let headAndTail = this.headAndTail();
|
|
233
226
|
let head = headAndTail.head;
|
|
234
227
|
let tail = headAndTail.tail;
|
|
@@ -241,10 +234,10 @@ class TokenCollection extends Array {
|
|
|
241
234
|
wait--;
|
|
242
235
|
const result = callback.call(this, head, tail);
|
|
243
236
|
if (result && !result.matched) {
|
|
244
|
-
passCount +=
|
|
237
|
+
passCount += result.passCount ?? 0;
|
|
245
238
|
if (prev && result.offset === 0 && result.length === 0) {
|
|
246
|
-
const { offset, line, column } =
|
|
247
|
-
firstUnmatched = firstUnmatched
|
|
239
|
+
const { offset, line, column } = Token.shiftLocation(prev, cumulativeOffset);
|
|
240
|
+
firstUnmatched = firstUnmatched ?? {
|
|
248
241
|
...result,
|
|
249
242
|
offset,
|
|
250
243
|
line,
|
|
@@ -252,7 +245,7 @@ class TokenCollection extends Array {
|
|
|
252
245
|
};
|
|
253
246
|
}
|
|
254
247
|
if (!prev && this.value.length === 0) {
|
|
255
|
-
firstUnmatched = firstUnmatched
|
|
248
|
+
firstUnmatched = firstUnmatched ?? {
|
|
256
249
|
...result,
|
|
257
250
|
reason: 'empty-token',
|
|
258
251
|
expects: undefined,
|
|
@@ -269,17 +262,17 @@ class TokenCollection extends Array {
|
|
|
269
262
|
}
|
|
270
263
|
}
|
|
271
264
|
}
|
|
272
|
-
firstUnmatched = firstUnmatched
|
|
265
|
+
firstUnmatched = firstUnmatched ?? result;
|
|
273
266
|
}
|
|
274
267
|
else if (result && !firstUnmatched && result.matched) {
|
|
275
268
|
return result;
|
|
276
269
|
}
|
|
277
270
|
else {
|
|
278
|
-
if (
|
|
271
|
+
if (head?.value && !head.match(/^\s*$/)) {
|
|
279
272
|
passCount += 4 * wait;
|
|
280
273
|
}
|
|
281
274
|
}
|
|
282
|
-
cumulativeOffset =
|
|
275
|
+
cumulativeOffset = head?.length ?? 0;
|
|
283
276
|
headAndTail = tail.headAndTail();
|
|
284
277
|
prev = head;
|
|
285
278
|
head = headAndTail.head;
|
|
@@ -292,7 +285,7 @@ class TokenCollection extends Array {
|
|
|
292
285
|
};
|
|
293
286
|
return res;
|
|
294
287
|
}
|
|
295
|
-
return
|
|
288
|
+
return matched();
|
|
296
289
|
}
|
|
297
290
|
filter(callback) {
|
|
298
291
|
return TokenCollection._new(super.filter(callback), this);
|
|
@@ -303,7 +296,7 @@ class TokenCollection extends Array {
|
|
|
303
296
|
return current;
|
|
304
297
|
}
|
|
305
298
|
});
|
|
306
|
-
return resultToken
|
|
299
|
+
return resultToken ?? null;
|
|
307
300
|
}
|
|
308
301
|
getDuplicated() {
|
|
309
302
|
const aList = this.slice();
|
|
@@ -327,7 +320,7 @@ class TokenCollection extends Array {
|
|
|
327
320
|
return null;
|
|
328
321
|
}
|
|
329
322
|
getIdentTokens() {
|
|
330
|
-
return this.filter(token => token.type ===
|
|
323
|
+
return this.filter(token => token.type === Token.Ident);
|
|
331
324
|
}
|
|
332
325
|
/**
|
|
333
326
|
*
|
|
@@ -340,7 +333,7 @@ class TokenCollection extends Array {
|
|
|
340
333
|
const copy = this.slice();
|
|
341
334
|
const head = copy.shift();
|
|
342
335
|
if (!head) {
|
|
343
|
-
return { head: head
|
|
336
|
+
return { head: head ?? null, tail: TokenCollection._new([], this) };
|
|
344
337
|
}
|
|
345
338
|
const tail = TokenCollection._new(copy, this);
|
|
346
339
|
return { head, tail };
|
|
@@ -393,4 +386,3 @@ class TokenCollection extends Array {
|
|
|
393
386
|
return newCollection;
|
|
394
387
|
}
|
|
395
388
|
}
|
|
396
|
-
exports.TokenCollection = TokenCollection;
|
package/lib/token/token.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { TokenValue } from './types';
|
|
2
|
-
import type { UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from '../types';
|
|
1
|
+
import type { TokenValue } from './types.js';
|
|
2
|
+
import type { UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from '../types.js';
|
|
3
3
|
export declare class Token {
|
|
4
4
|
/**
|
|
5
5
|
* @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
|
|
@@ -20,7 +20,7 @@ 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?: readonly string[]): 1 |
|
|
23
|
+
static getType(value: string, separators?: readonly string[]): 1 | 13 | 18;
|
|
24
24
|
static shiftLocation(token: Readonly<Token>, offset: number): {
|
|
25
25
|
offset: number;
|
|
26
26
|
line: number;
|
package/lib/token/token.js
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Token = void 0;
|
|
4
|
-
class Token {
|
|
1
|
+
export class Token {
|
|
5
2
|
static getCol(value, offset) {
|
|
6
|
-
var _a;
|
|
7
3
|
const lines = value.slice(0, offset).split(/\n/g);
|
|
8
|
-
return (
|
|
4
|
+
return (lines[lines.length - 1] ?? '').length + 1;
|
|
9
5
|
}
|
|
10
6
|
static getLine(value, offset) {
|
|
11
7
|
return value.slice(0, offset).split(/\n/g).length;
|
|
12
8
|
}
|
|
13
9
|
static getType(value, separators) {
|
|
14
|
-
|
|
15
|
-
if (Token.whitespace.includes((_a = value[0]) !== null && _a !== void 0 ? _a : '')) {
|
|
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;
|
|
@@ -93,21 +88,19 @@ class Token {
|
|
|
93
88
|
return isNaN(num) ? 0 : num;
|
|
94
89
|
}
|
|
95
90
|
unmatched(options) {
|
|
96
|
-
var _a, _b;
|
|
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
98
|
line: Token.getLine(this.originalValue, this.offset),
|
|
105
99
|
column: Token.getCol(this.originalValue, this.offset),
|
|
106
|
-
reason:
|
|
100
|
+
reason: options?.reason ?? 'syntax-error',
|
|
107
101
|
};
|
|
108
102
|
}
|
|
109
103
|
}
|
|
110
|
-
exports.Token = Token;
|
|
111
104
|
/**
|
|
112
105
|
* @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
|
|
113
106
|
*/
|
package/lib/token/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
5
|
readonly matched: false;
|
package/lib/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/lib/types.schema.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* This file was automatically generated by json-schema-to-typescript.
|
|
4
3
|
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
5
4
|
* and run json-schema-to-typescript to regenerate this file.
|
|
6
5
|
*/
|
|
7
|
-
|
|
6
|
+
export {};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const debug_1 = require("../debug");
|
|
5
|
-
const match_result_1 = require("../match-result");
|
|
6
|
-
const token_1 = require("../token");
|
|
1
|
+
import { log } from '../debug.js';
|
|
2
|
+
import { matched, unmatched } from '../match-result.js';
|
|
3
|
+
import { TokenCollection } from '../token/index.js';
|
|
7
4
|
/**
|
|
8
5
|
* @see https://w3c.github.io/webappsec-permissions-policy/#serialized-permissions-policy
|
|
9
6
|
*
|
|
@@ -25,14 +22,13 @@ const token_1 = require("../token");
|
|
|
25
22
|
*
|
|
26
23
|
* `allow-list` is optional.
|
|
27
24
|
*/
|
|
28
|
-
const checkSerializedPermissionsPolicy = () => value => {
|
|
25
|
+
export const checkSerializedPermissionsPolicy = () => value => {
|
|
29
26
|
const res = _checkSerializedPermissionsPolicy(value);
|
|
30
27
|
if (!res.matched) {
|
|
31
|
-
|
|
28
|
+
log('Failed: %O', res);
|
|
32
29
|
}
|
|
33
30
|
return res;
|
|
34
31
|
};
|
|
35
|
-
exports.checkSerializedPermissionsPolicy = checkSerializedPermissionsPolicy;
|
|
36
32
|
function _checkSerializedPermissionsPolicy(value) {
|
|
37
33
|
/**
|
|
38
34
|
* The list of serialized-policy-directive
|
|
@@ -51,14 +47,14 @@ function _checkSerializedPermissionsPolicy(value) {
|
|
|
51
47
|
*/
|
|
52
48
|
/;?/,
|
|
53
49
|
];
|
|
54
|
-
const tokens =
|
|
50
|
+
const tokens = TokenCollection.fromPatterns(value, patterns, { repeat: true });
|
|
55
51
|
const serializedPolicyDirectives = tokens.chunk(patterns.length);
|
|
56
|
-
|
|
52
|
+
log('Serialized Permissions Policy: %s => %O', value, serializedPolicyDirectives);
|
|
57
53
|
for (const [serializedPolicyDirective] of serializedPolicyDirectives) {
|
|
58
54
|
if (!serializedPolicyDirective || !serializedPolicyDirective.value) {
|
|
59
|
-
return
|
|
55
|
+
return unmatched('', 'empty-token');
|
|
60
56
|
}
|
|
61
|
-
const [aw, featureIdentifier, rws, allowListValue] =
|
|
57
|
+
const [aw, featureIdentifier, rws, allowListValue] = TokenCollection.fromPatterns(serializedPolicyDirective, [
|
|
62
58
|
/**
|
|
63
59
|
* Any whitespace
|
|
64
60
|
*/
|
|
@@ -82,7 +78,7 @@ function _checkSerializedPermissionsPolicy(value) {
|
|
|
82
78
|
*/
|
|
83
79
|
/.*/,
|
|
84
80
|
]);
|
|
85
|
-
|
|
81
|
+
log('Serialized Policy Directive: %s => %O', serializedPolicyDirective.value, {
|
|
86
82
|
aw,
|
|
87
83
|
featureIdentifier,
|
|
88
84
|
rws,
|
|
@@ -120,12 +116,12 @@ function _checkSerializedPermissionsPolicy(value) {
|
|
|
120
116
|
// Separator
|
|
121
117
|
/\s*/,
|
|
122
118
|
];
|
|
123
|
-
const allowListTokens =
|
|
119
|
+
const allowListTokens = TokenCollection.fromPatterns(allowListValue, allowListPatterns, { repeat: true });
|
|
124
120
|
const allowList = allowListTokens.chunk(allowListPatterns.length);
|
|
125
|
-
|
|
121
|
+
log('Allow List: %s => %O', allowListTokens.value, allowList);
|
|
126
122
|
for (const [allow] of allowList) {
|
|
127
123
|
if (!allow || !allow.value) {
|
|
128
|
-
return
|
|
124
|
+
return unmatched('', 'missing-token', {
|
|
129
125
|
expects: [
|
|
130
126
|
{ type: 'const', value: '*' },
|
|
131
127
|
{ type: 'const', value: "'self'" },
|
|
@@ -166,7 +162,7 @@ function _checkSerializedPermissionsPolicy(value) {
|
|
|
166
162
|
});
|
|
167
163
|
}
|
|
168
164
|
}
|
|
169
|
-
return
|
|
165
|
+
return matched();
|
|
170
166
|
}
|
|
171
167
|
/**
|
|
172
168
|
* serialized-origin
|
|
@@ -179,7 +175,7 @@ function _checkSerializedPermissionsPolicy(value) {
|
|
|
179
175
|
*/
|
|
180
176
|
function checkSerializedOrigin(token) {
|
|
181
177
|
const url = parseUrl(token.value);
|
|
182
|
-
|
|
178
|
+
log('Parse URL: "%s" => %O', token.value, url);
|
|
183
179
|
if (!url) {
|
|
184
180
|
return token.unmatched({
|
|
185
181
|
expects: [{ type: 'common', value: 'serialized-origin' }],
|
|
@@ -254,7 +250,7 @@ function checkSerializedOrigin(token) {
|
|
|
254
250
|
partName: 'serialized-origin',
|
|
255
251
|
});
|
|
256
252
|
}
|
|
257
|
-
return
|
|
253
|
+
return matched();
|
|
258
254
|
}
|
|
259
255
|
function parseUrl(value) {
|
|
260
256
|
try {
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const match_result_1 = require("../match-result");
|
|
7
|
-
const token_1 = require("../token");
|
|
8
|
-
const acLog = debug_1.log.extend('autocomplete');
|
|
1
|
+
import { log } from '../debug.js';
|
|
2
|
+
import { getCandidate } from '../get-candidate.js';
|
|
3
|
+
import { matched } from '../match-result.js';
|
|
4
|
+
import { TokenCollection } from '../token/index.js';
|
|
5
|
+
const acLog = log.extend('autocomplete');
|
|
9
6
|
/**
|
|
10
7
|
* https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-section
|
|
11
8
|
*/
|
|
@@ -95,11 +92,11 @@ const URL_CONTACTABLE_FIELD = 'https://html.spec.whatwg.org/multipage/form-contr
|
|
|
95
92
|
/**
|
|
96
93
|
* @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete
|
|
97
94
|
*/
|
|
98
|
-
const checkAutoComplete = () => value => {
|
|
95
|
+
export const checkAutoComplete = () => value => {
|
|
99
96
|
let hasNamedGroup = false;
|
|
100
97
|
let hasPartOfAddress = false;
|
|
101
98
|
let hasContactingToken = false;
|
|
102
|
-
const tokens = new
|
|
99
|
+
const tokens = new TokenCollection(value, {
|
|
103
100
|
disallowToSurroundBySpaces: false,
|
|
104
101
|
allowEmpty: false,
|
|
105
102
|
ordered: true,
|
|
@@ -145,7 +142,7 @@ const checkAutoComplete = () => value => {
|
|
|
145
142
|
ref: URL_ON_OFF,
|
|
146
143
|
});
|
|
147
144
|
}
|
|
148
|
-
return
|
|
145
|
+
return matched();
|
|
149
146
|
}
|
|
150
147
|
// > Optionally, a token whose first eight characters are
|
|
151
148
|
// > an ASCII case-insensitive match for the string "section-",
|
|
@@ -166,7 +163,7 @@ const checkAutoComplete = () => value => {
|
|
|
166
163
|
tail = headAndTail2.tail;
|
|
167
164
|
if (!head) {
|
|
168
165
|
// Missing autofill field name but it is valid
|
|
169
|
-
return
|
|
166
|
+
return matched();
|
|
170
167
|
}
|
|
171
168
|
}
|
|
172
169
|
// > Optionally, a token that is an ASCII case-insensitive match for
|
|
@@ -194,7 +191,7 @@ const checkAutoComplete = () => value => {
|
|
|
194
191
|
tail = headAndTail3.tail;
|
|
195
192
|
if (!head) {
|
|
196
193
|
// Missing autofill field name but it is valid
|
|
197
|
-
return
|
|
194
|
+
return matched();
|
|
198
195
|
}
|
|
199
196
|
}
|
|
200
197
|
if (head.match(contactingTokens, true)) {
|
|
@@ -202,10 +199,10 @@ const checkAutoComplete = () => value => {
|
|
|
202
199
|
const contactableFiledToken = tail[0];
|
|
203
200
|
if (!contactableFiledToken) {
|
|
204
201
|
// Missing autofill field name but it is valid
|
|
205
|
-
return
|
|
202
|
+
return matched();
|
|
206
203
|
}
|
|
207
204
|
if (!contactableFiledToken.match(contactableFieldNames, true)) {
|
|
208
|
-
const candidate =
|
|
205
|
+
const candidate = getCandidate(contactableFiledToken.value, contactableFieldNames);
|
|
209
206
|
acLog('[Unmatched ("%s")] Unexpected token: "%s"', value, contactableFiledToken.value);
|
|
210
207
|
return contactableFiledToken.unmatched({
|
|
211
208
|
reason: 'unexpected-token',
|
|
@@ -219,9 +216,9 @@ const checkAutoComplete = () => value => {
|
|
|
219
216
|
}
|
|
220
217
|
if (tail[1]) {
|
|
221
218
|
if (tail[1].match(webauthnFieldNames)) {
|
|
222
|
-
return
|
|
219
|
+
return matched();
|
|
223
220
|
}
|
|
224
|
-
const candidate =
|
|
221
|
+
const candidate = getCandidate(tail[1].value, webauthnFieldNames);
|
|
225
222
|
if (candidate) {
|
|
226
223
|
acLog('[Unmatched ("%s")] Unnecessarily token: "%s", Do you mean "%s"? ', value, tail[1].value, candidate);
|
|
227
224
|
}
|
|
@@ -239,14 +236,14 @@ const checkAutoComplete = () => value => {
|
|
|
239
236
|
ref: URL_AUTOFILL_FIELD,
|
|
240
237
|
});
|
|
241
238
|
}
|
|
242
|
-
return
|
|
239
|
+
return matched();
|
|
243
240
|
}
|
|
244
241
|
if (head.match([...autofillFieldNames, ...contactableFieldNames], true)) {
|
|
245
242
|
if (tail[0]) {
|
|
246
243
|
if (tail[0].match(webauthnFieldNames)) {
|
|
247
|
-
return
|
|
244
|
+
return matched();
|
|
248
245
|
}
|
|
249
|
-
const candidate =
|
|
246
|
+
const candidate = getCandidate(tail[0].value, webauthnFieldNames);
|
|
250
247
|
if (candidate) {
|
|
251
248
|
acLog('[Unmatched ("%s")] Unnecessarily token: "%s", Do you mean "%s"? ', value, tail[0].value, candidate);
|
|
252
249
|
}
|
|
@@ -264,10 +261,10 @@ const checkAutoComplete = () => value => {
|
|
|
264
261
|
ref: URL_AUTOFILL_FIELD,
|
|
265
262
|
});
|
|
266
263
|
}
|
|
267
|
-
return
|
|
264
|
+
return matched();
|
|
268
265
|
}
|
|
269
266
|
if (head.match(webauthnFieldNames)) {
|
|
270
|
-
return
|
|
267
|
+
return matched();
|
|
271
268
|
}
|
|
272
269
|
const expects = [
|
|
273
270
|
{
|
|
@@ -283,9 +280,9 @@ const checkAutoComplete = () => value => {
|
|
|
283
280
|
});
|
|
284
281
|
// Potentially typo a named group
|
|
285
282
|
const [prefix, namedGroupStr] = head.value.split('-');
|
|
286
|
-
const candidatePrefix =
|
|
283
|
+
const candidatePrefix = getCandidate(prefix, 'section');
|
|
287
284
|
if (candidatePrefix) {
|
|
288
|
-
candidate = `${candidatePrefix}-${namedGroupStr
|
|
285
|
+
candidate = `${candidatePrefix}-${namedGroupStr ?? ''}`;
|
|
289
286
|
}
|
|
290
287
|
}
|
|
291
288
|
else if (!hasPartOfAddress) {
|
|
@@ -296,16 +293,16 @@ const checkAutoComplete = () => value => {
|
|
|
296
293
|
type: 'const',
|
|
297
294
|
value: token,
|
|
298
295
|
})));
|
|
299
|
-
candidate =
|
|
296
|
+
candidate = getCandidate(head.value, partOfAddress, autofillFieldNames, contactingTokens, contactableFieldNames);
|
|
300
297
|
}
|
|
301
298
|
else if (!hasContactingToken) {
|
|
302
299
|
expects.push(...contactingTokens.map(token => ({
|
|
303
300
|
type: 'const',
|
|
304
301
|
value: token,
|
|
305
302
|
})));
|
|
306
|
-
candidate =
|
|
303
|
+
candidate = getCandidate(head.value, autofillFieldNames, contactingTokens, contactableFieldNames);
|
|
307
304
|
}
|
|
308
|
-
candidate = candidate
|
|
305
|
+
candidate = candidate ?? getCandidate(head.value, autofillFieldNames);
|
|
309
306
|
if (candidate) {
|
|
310
307
|
acLog('[Unmatched ("%s")] Unexpected token: "%s", Do you mean "%s"? ', value, head.value, candidate);
|
|
311
308
|
}
|
|
@@ -319,4 +316,3 @@ const checkAutoComplete = () => value => {
|
|
|
319
316
|
ref: URL_AUTOFILL_FIELD,
|
|
320
317
|
});
|
|
321
318
|
};
|
|
322
|
-
exports.checkAutoComplete = checkAutoComplete;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const debug_1 = require("../../debug");
|
|
5
|
-
const token_1 = require("../../token");
|
|
6
|
-
const datetime_tokens_1 = require("./datetime-tokens");
|
|
1
|
+
import { log } from '../../debug.js';
|
|
2
|
+
import { TokenCollection } from '../../token/index.js';
|
|
3
|
+
import { datetimeTokenCheck } from './datetime-tokens.js';
|
|
7
4
|
/**
|
|
8
5
|
* @see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#dates
|
|
9
6
|
*/
|
|
10
|
-
const checkDateString = () => function checkDateString(value) {
|
|
11
|
-
|
|
12
|
-
const tokens =
|
|
7
|
+
export const checkDateString = () => function checkDateString(value) {
|
|
8
|
+
log('CHECK: date-string');
|
|
9
|
+
const tokens = TokenCollection.fromPatterns(value, [
|
|
13
10
|
// YYYY
|
|
14
11
|
/[^-]*/,
|
|
15
12
|
// -
|
|
@@ -21,11 +18,10 @@ const checkDateString = () => function checkDateString(value) {
|
|
|
21
18
|
// DD
|
|
22
19
|
/.[0-9]*/,
|
|
23
20
|
]);
|
|
24
|
-
|
|
25
|
-
const res = tokens.eachCheck(
|
|
21
|
+
log('Date: "%s" => %O', tokens.value, tokens);
|
|
22
|
+
const res = tokens.eachCheck(datetimeTokenCheck.year, datetimeTokenCheck.hyphen, datetimeTokenCheck.month, datetimeTokenCheck.hyphen, datetimeTokenCheck.date, datetimeTokenCheck.extra);
|
|
26
23
|
if (!res.matched) {
|
|
27
|
-
|
|
24
|
+
log('Failed: %O', res);
|
|
28
25
|
}
|
|
29
26
|
return res;
|
|
30
27
|
};
|
|
31
|
-
exports.checkDateString = checkDateString;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { TokenEachCheck } from '../../token/token-collection';
|
|
1
|
+
import type { TokenEachCheck } from '../../token/token-collection.js';
|
|
2
2
|
export declare const datetimeTokenCheck: Record<'year' | 'month' | 'date' | 'hour' | 'minute' | 'second' | 'secondFractionalPart' | 'week' | 'hyphen' | 'colon' | 'extra' | 'colonOrEnd' | 'decimalPointOrEnd' | 'localDateTimeSeparator' | 'normalizedlocalDateTimeSeparator' | 'plusOrMinusSign' | 'weekSign', TokenEachCheck> & Record<'_year' | '_month', number | null>;
|
|
3
3
|
export declare function getMaxWeekNum(year: number): number;
|