@markuplint/types 3.12.0 → 4.0.0-alpha.10
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/LICENSE +1 -1
- package/lib/check-multi-types.d.ts +2 -5
- 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 +33 -33
- package/lib/debug.js +2 -6
- package/lib/defs.d.ts +2 -1
- package/lib/defs.js +188 -138
- package/lib/enum.d.ts +2 -2
- package/lib/enum.js +7 -12
- package/lib/get-candidate.d.ts +1 -4
- package/lib/get-candidate.js +5 -10
- 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 +20 -25
- package/lib/list.d.ts +2 -2
- package/lib/list.js +9 -14
- package/lib/match-result.d.ts +8 -21
- package/lib/match-result.js +6 -13
- package/lib/number.d.ts +3 -3
- package/lib/number.js +13 -17
- package/lib/primitive/index.d.ts +7 -7
- package/lib/primitive/index.js +7 -17
- package/lib/primitive/is-float.js +2 -6
- package/lib/primitive/is-int.js +2 -6
- package/lib/primitive/is-non-zero-uint.js +2 -6
- package/lib/primitive/is-quantity.d.ts +1 -5
- package/lib/primitive/is-quantity.js +9 -13
- package/lib/primitive/is-uint.d.ts +3 -6
- package/lib/primitive/is-uint.js +4 -8
- package/lib/primitive/range.js +3 -7
- package/lib/primitive/split-unit.d.ts +2 -2
- package/lib/primitive/split-unit.js +4 -8
- 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 +58 -70
- package/lib/token/token-collection.js +47 -56
- package/lib/token/token.d.ts +54 -59
- package/lib/token/token.js +14 -20
- package/lib/token/types.js +1 -2
- package/lib/types.d.ts +58 -82
- package/lib/types.js +1 -2
- package/lib/types.schema.d.ts +31 -1087
- 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 +21 -25
- package/lib/whatwg/check-autocomplete.d.ts +1 -1
- package/lib/whatwg/check-autocomplete.js +34 -41
- package/lib/whatwg/check-datetime/date-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/date-string.js +12 -16
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +2 -22
- package/lib/whatwg/check-datetime/datetime-tokens.js +58 -64
- package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/duration-string.js +64 -69
- 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 +24 -28
- 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 +37 -41
- 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 +13 -17
- package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +3 -3
- package/lib/whatwg/check-datetime/time-zone-offset-string.js +22 -28
- package/lib/whatwg/check-datetime/week-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/week-string.js +11 -15
- 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 +11 -15
- package/lib/whatwg/check-mime-type.d.ts +5 -5
- 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 +8 -12
- 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 +10 -5
- package/lib/whatwg/is-custom-element-name.js +22 -38
- 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 +17 -9
- 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
package/lib/rfc/is-bcp-47.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isBCP47 = void 0;
|
|
4
|
-
const bcp_47_1 = require("bcp-47");
|
|
1
|
+
import { parse } from 'bcp-47';
|
|
5
2
|
/**
|
|
6
3
|
* @see https://tools.ietf.org/rfc/bcp/bcp47.html
|
|
7
4
|
*/
|
|
8
|
-
const isBCP47 = () => {
|
|
5
|
+
export const isBCP47 = () => {
|
|
9
6
|
return value => {
|
|
10
|
-
const { language } =
|
|
7
|
+
const { language } = parse(value);
|
|
11
8
|
return !!language;
|
|
12
9
|
};
|
|
13
10
|
};
|
|
14
|
-
exports.isBCP47 = isBCP47;
|
package/lib/token/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Token } from './token';
|
|
2
|
-
export { TokenCollection } from './token-collection';
|
|
1
|
+
export { Token } from './token.js';
|
|
2
|
+
export { TokenCollection } from './token-collection.js';
|
package/lib/token/index.js
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.TokenCollection = exports.Token = void 0;
|
|
4
|
-
var token_1 = require("./token");
|
|
5
|
-
Object.defineProperty(exports, "Token", { enumerable: true, get: function () { return token_1.Token; } });
|
|
6
|
-
var token_collection_1 = require("./token-collection");
|
|
7
|
-
Object.defineProperty(exports, "TokenCollection", { enumerable: true, get: function () { return token_collection_1.TokenCollection; } });
|
|
1
|
+
export { Token } from './token.js';
|
|
2
|
+
export { TokenCollection } from './token-collection.js';
|
|
@@ -1,74 +1,62 @@
|
|
|
1
|
-
import type { TokenValue } from './types';
|
|
2
|
-
import type { UnmatchedResult } from '
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
specificSeparator: string | string[];
|
|
8
|
-
}
|
|
9
|
-
>;
|
|
1
|
+
import type { TokenValue } from './types.js';
|
|
2
|
+
import type { Expect, Result, List, UnmatchedResult } from '../types.js';
|
|
3
|
+
import { Token } from './token.js';
|
|
4
|
+
type TokenCollectionOptions = Partial<Omit<List, 'token'> & {
|
|
5
|
+
specificSeparator: string | string[];
|
|
6
|
+
}>;
|
|
10
7
|
export type TokenEachCheck = (head: Readonly<Token> | null, tail: TokenCollection) => Result | void;
|
|
11
8
|
export declare class TokenCollection extends Array<Token> {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
expectedTokenNumber: number | undefined;
|
|
65
|
-
token: Token;
|
|
66
|
-
} | null;
|
|
67
|
-
toJSON(): {
|
|
68
|
-
type: number;
|
|
69
|
-
value: string;
|
|
70
|
-
offset: number;
|
|
71
|
-
}[];
|
|
72
|
-
private static _new;
|
|
9
|
+
static fromPatterns(value: Readonly<Token> | string, patterns: readonly Readonly<RegExp>[], typeOptions?: Omit<TokenCollectionOptions, 'specificSeparator'> & {
|
|
10
|
+
repeat?: boolean;
|
|
11
|
+
}): TokenCollection;
|
|
12
|
+
static get [Symbol.species](): ArrayConstructor;
|
|
13
|
+
readonly allowEmpty: NonNullable<List['allowEmpty']>;
|
|
14
|
+
readonly caseInsensitive: NonNullable<List['caseInsensitive']>;
|
|
15
|
+
readonly disallowToSurroundBySpaces: NonNullable<List['disallowToSurroundBySpaces']>;
|
|
16
|
+
readonly number: List['number'];
|
|
17
|
+
readonly ordered: NonNullable<List['ordered']>;
|
|
18
|
+
readonly separator: NonNullable<List['separator']>;
|
|
19
|
+
readonly unique: NonNullable<List['unique']>;
|
|
20
|
+
constructor(value?: string, typeOptions?: TokenCollectionOptions);
|
|
21
|
+
constructor(value?: number);
|
|
22
|
+
get value(): string;
|
|
23
|
+
check(options?: {
|
|
24
|
+
expects?: Expect[];
|
|
25
|
+
ref?: string;
|
|
26
|
+
cache?: boolean;
|
|
27
|
+
}): import("../types.js").MatchedResult | UnmatchedResult;
|
|
28
|
+
chunk(split: number): TokenCollection[];
|
|
29
|
+
compareTokens(callback: (prev: Readonly<Token>, current: Readonly<Token>) => Readonly<Token> | null | void): Readonly<Token> | null | undefined;
|
|
30
|
+
divide(position: number): readonly [TokenCollection, TokenCollection];
|
|
31
|
+
eachCheck(...callbacks: readonly TokenEachCheck[]): Result;
|
|
32
|
+
filter(callback: Parameters<Array<Token>['filter']>[0]): TokenCollection;
|
|
33
|
+
getConsecutiveToken(tokenType: number): Readonly<Token> | null;
|
|
34
|
+
getDuplicated(): Token | null;
|
|
35
|
+
getIdentTokens(): TokenCollection;
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @param value The token value or the token type or its list
|
|
39
|
+
*/
|
|
40
|
+
has(value: TokenValue): boolean;
|
|
41
|
+
headAndTail(): {
|
|
42
|
+
head: Token | null;
|
|
43
|
+
tail: TokenCollection;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param value The token value or the token type or its list
|
|
48
|
+
*/
|
|
49
|
+
search(value: TokenValue): Token | null;
|
|
50
|
+
takeTurns(tokenNumbers: ReadonlyArray<number>, lastTokenNumber?: number): {
|
|
51
|
+
unexpectedLastToken: boolean;
|
|
52
|
+
expectedTokenNumber: number | undefined;
|
|
53
|
+
token: Token;
|
|
54
|
+
} | null;
|
|
55
|
+
toJSON(): {
|
|
56
|
+
type: number;
|
|
57
|
+
value: string;
|
|
58
|
+
offset: number;
|
|
59
|
+
}[];
|
|
60
|
+
private static _new;
|
|
73
61
|
}
|
|
74
62
|
export {};
|
|
@@ -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;
|
|
@@ -25,18 +21,18 @@ class TokenCollection extends Array {
|
|
|
25
21
|
for (const pattern of patterns) {
|
|
26
22
|
const res = pattern.exec(strings);
|
|
27
23
|
let value;
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
if (res.index !== 0) {
|
|
34
|
-
value = strings.slice(res.index + res[0].length);
|
|
24
|
+
if (res) {
|
|
25
|
+
if (res.index === 0) {
|
|
26
|
+
value = res[0] ?? '';
|
|
35
27
|
}
|
|
36
28
|
else {
|
|
37
|
-
value = (
|
|
29
|
+
value = strings.slice(res.index + res[0].length);
|
|
38
30
|
}
|
|
39
31
|
}
|
|
32
|
+
else {
|
|
33
|
+
isBroken = true;
|
|
34
|
+
value = '';
|
|
35
|
+
}
|
|
40
36
|
const token = addToken(value);
|
|
41
37
|
// @ts-ignore
|
|
42
38
|
token._ = pattern;
|
|
@@ -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
|
}
|
|
@@ -84,7 +79,7 @@ class TokenCollection extends Array {
|
|
|
84
79
|
separators.push(...typeOptions.specificSeparator);
|
|
85
80
|
}
|
|
86
81
|
}
|
|
87
|
-
const chars = value
|
|
82
|
+
const chars = [...value];
|
|
88
83
|
const values = [];
|
|
89
84
|
let char;
|
|
90
85
|
while ((char = chars.shift())) {
|
|
@@ -97,28 +92,26 @@ 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 {
|
|
105
|
-
values.push(last);
|
|
106
|
-
values.push(char);
|
|
100
|
+
values.push(last, char);
|
|
107
101
|
}
|
|
108
102
|
}
|
|
109
103
|
let offset = 0;
|
|
110
|
-
|
|
111
|
-
const token = new
|
|
104
|
+
for (const v of values) {
|
|
105
|
+
const token = new Token(v, offset, value, separators);
|
|
112
106
|
this.push(token);
|
|
113
107
|
offset += v.length;
|
|
114
|
-
}
|
|
108
|
+
}
|
|
115
109
|
}
|
|
116
110
|
get value() {
|
|
117
111
|
const value = this.map(t => t.value).join('');
|
|
118
112
|
return value;
|
|
119
113
|
}
|
|
120
114
|
check(options = {}) {
|
|
121
|
-
var _c;
|
|
122
115
|
const { expects, ref } = options;
|
|
123
116
|
if (this.disallowToSurroundBySpaces) {
|
|
124
117
|
for (const token of this) {
|
|
@@ -132,8 +125,8 @@ class TokenCollection extends Array {
|
|
|
132
125
|
}
|
|
133
126
|
}
|
|
134
127
|
if (this.separator === 'comma') {
|
|
135
|
-
const tokensWithoutWP = this.filter(token => token.type !==
|
|
136
|
-
const consecutiveComma = tokensWithoutWP.getConsecutiveToken(
|
|
128
|
+
const tokensWithoutWP = this.filter(token => token.type !== Token.WhiteSpace);
|
|
129
|
+
const consecutiveComma = tokensWithoutWP.getConsecutiveToken(Token.Comma);
|
|
137
130
|
if (consecutiveComma) {
|
|
138
131
|
return consecutiveComma.unmatched({
|
|
139
132
|
reason: 'unexpected-comma',
|
|
@@ -141,14 +134,14 @@ class TokenCollection extends Array {
|
|
|
141
134
|
expects,
|
|
142
135
|
});
|
|
143
136
|
}
|
|
144
|
-
if (tokensWithoutWP[0] && tokensWithoutWP[0].type ===
|
|
137
|
+
if (tokensWithoutWP[0] && tokensWithoutWP[0].type === Token.Comma) {
|
|
145
138
|
return tokensWithoutWP[0].unmatched({
|
|
146
139
|
reason: 'unexpected-comma',
|
|
147
140
|
ref,
|
|
148
141
|
expects,
|
|
149
142
|
});
|
|
150
143
|
}
|
|
151
|
-
const takeTurnsError = tokensWithoutWP.takeTurns([
|
|
144
|
+
const takeTurnsError = tokensWithoutWP.takeTurns([Token.Ident, Token.Comma], Token.Ident);
|
|
152
145
|
if (takeTurnsError) {
|
|
153
146
|
if (takeTurnsError.unexpectedLastToken) {
|
|
154
147
|
return takeTurnsError.token.unmatched({
|
|
@@ -174,9 +167,9 @@ class TokenCollection extends Array {
|
|
|
174
167
|
}
|
|
175
168
|
}
|
|
176
169
|
const identTokens = this.getIdentTokens();
|
|
177
|
-
const allowEmpty =
|
|
170
|
+
const allowEmpty = this.allowEmpty ?? true;
|
|
178
171
|
if (!allowEmpty && identTokens.length === 0) {
|
|
179
|
-
return
|
|
172
|
+
return unmatched(this.value, 'empty-token', {
|
|
180
173
|
ref,
|
|
181
174
|
expects,
|
|
182
175
|
});
|
|
@@ -192,7 +185,7 @@ class TokenCollection extends Array {
|
|
|
192
185
|
});
|
|
193
186
|
}
|
|
194
187
|
}
|
|
195
|
-
return
|
|
188
|
+
return matched();
|
|
196
189
|
}
|
|
197
190
|
chunk(split) {
|
|
198
191
|
const chunks = [];
|
|
@@ -228,7 +221,6 @@ class TokenCollection extends Array {
|
|
|
228
221
|
return [a, b];
|
|
229
222
|
}
|
|
230
223
|
eachCheck(...callbacks) {
|
|
231
|
-
var _c, _d;
|
|
232
224
|
let headAndTail = this.headAndTail();
|
|
233
225
|
let head = headAndTail.head;
|
|
234
226
|
let tail = headAndTail.tail;
|
|
@@ -241,10 +233,10 @@ class TokenCollection extends Array {
|
|
|
241
233
|
wait--;
|
|
242
234
|
const result = callback.call(this, head, tail);
|
|
243
235
|
if (result && !result.matched) {
|
|
244
|
-
passCount +=
|
|
236
|
+
passCount += result.passCount ?? 0;
|
|
245
237
|
if (prev && result.offset === 0 && result.length === 0) {
|
|
246
|
-
const { offset, line, column } =
|
|
247
|
-
firstUnmatched = firstUnmatched
|
|
238
|
+
const { offset, line, column } = Token.shiftLocation(prev, cumulativeOffset);
|
|
239
|
+
firstUnmatched = firstUnmatched ?? {
|
|
248
240
|
...result,
|
|
249
241
|
offset,
|
|
250
242
|
line,
|
|
@@ -252,7 +244,7 @@ class TokenCollection extends Array {
|
|
|
252
244
|
};
|
|
253
245
|
}
|
|
254
246
|
if (!prev && this.value.length === 0) {
|
|
255
|
-
firstUnmatched = firstUnmatched
|
|
247
|
+
firstUnmatched = firstUnmatched ?? {
|
|
256
248
|
...result,
|
|
257
249
|
reason: 'empty-token',
|
|
258
250
|
expects: undefined,
|
|
@@ -269,17 +261,17 @@ class TokenCollection extends Array {
|
|
|
269
261
|
}
|
|
270
262
|
}
|
|
271
263
|
}
|
|
272
|
-
firstUnmatched = firstUnmatched
|
|
264
|
+
firstUnmatched = firstUnmatched ?? result;
|
|
273
265
|
}
|
|
274
266
|
else if (result && !firstUnmatched && result.matched) {
|
|
275
267
|
return result;
|
|
276
268
|
}
|
|
277
269
|
else {
|
|
278
|
-
if (
|
|
270
|
+
if (head?.value && !head.matches(/^\s*$/)) {
|
|
279
271
|
passCount += 4 * wait;
|
|
280
272
|
}
|
|
281
273
|
}
|
|
282
|
-
cumulativeOffset =
|
|
274
|
+
cumulativeOffset = head?.length ?? 0;
|
|
283
275
|
headAndTail = tail.headAndTail();
|
|
284
276
|
prev = head;
|
|
285
277
|
head = headAndTail.head;
|
|
@@ -292,7 +284,7 @@ class TokenCollection extends Array {
|
|
|
292
284
|
};
|
|
293
285
|
return res;
|
|
294
286
|
}
|
|
295
|
-
return
|
|
287
|
+
return matched();
|
|
296
288
|
}
|
|
297
289
|
filter(callback) {
|
|
298
290
|
return TokenCollection._new(super.filter(callback), this);
|
|
@@ -303,7 +295,7 @@ class TokenCollection extends Array {
|
|
|
303
295
|
return current;
|
|
304
296
|
}
|
|
305
297
|
});
|
|
306
|
-
return resultToken
|
|
298
|
+
return resultToken ?? null;
|
|
307
299
|
}
|
|
308
300
|
getDuplicated() {
|
|
309
301
|
const aList = this.slice();
|
|
@@ -327,20 +319,20 @@ class TokenCollection extends Array {
|
|
|
327
319
|
return null;
|
|
328
320
|
}
|
|
329
321
|
getIdentTokens() {
|
|
330
|
-
return this.filter(token => token.type ===
|
|
322
|
+
return this.filter(token => token.type === Token.Ident);
|
|
331
323
|
}
|
|
332
324
|
/**
|
|
333
325
|
*
|
|
334
326
|
* @param value The token value or the token type or its list
|
|
335
327
|
*/
|
|
336
328
|
has(value) {
|
|
337
|
-
return this.some(t => t.
|
|
329
|
+
return this.some(t => t.matches(value));
|
|
338
330
|
}
|
|
339
331
|
headAndTail() {
|
|
340
332
|
const copy = this.slice();
|
|
341
333
|
const head = copy.shift();
|
|
342
334
|
if (!head) {
|
|
343
|
-
return { head: head
|
|
335
|
+
return { head: head ?? null, tail: TokenCollection._new([], this) };
|
|
344
336
|
}
|
|
345
337
|
const tail = TokenCollection._new(copy, this);
|
|
346
338
|
return { head, tail };
|
|
@@ -393,4 +385,3 @@ class TokenCollection extends Array {
|
|
|
393
385
|
return newCollection;
|
|
394
386
|
}
|
|
395
387
|
}
|
|
396
|
-
exports.TokenCollection = TokenCollection;
|
package/lib/token/token.d.ts
CHANGED
|
@@ -1,61 +1,56 @@
|
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
options?: UnmatchedResultOptions & {
|
|
57
|
-
readonly ref?: string;
|
|
58
|
-
readonly reason?: UnmatchedResultReason;
|
|
59
|
-
},
|
|
60
|
-
): UnmatchedResult;
|
|
4
|
+
/**
|
|
5
|
+
* @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
|
|
6
|
+
*/
|
|
7
|
+
static readonly Comma = 18;
|
|
8
|
+
static readonly Ident = 1;
|
|
9
|
+
static readonly WhiteSpace = 13;
|
|
10
|
+
/**
|
|
11
|
+
* ASCII whitespace is
|
|
12
|
+
* - U+0009 TAB
|
|
13
|
+
* - U+000A LF
|
|
14
|
+
* - U+000C FF
|
|
15
|
+
* - U+000D CR
|
|
16
|
+
* - U+0020 SPACE.
|
|
17
|
+
*
|
|
18
|
+
* @see https://infra.spec.whatwg.org/#ascii-whitespace
|
|
19
|
+
*/
|
|
20
|
+
static readonly whitespace: ReadonlyArray<string>;
|
|
21
|
+
static getCol(value: string, offset: number): number;
|
|
22
|
+
static getLine(value: string, offset: number): number;
|
|
23
|
+
static getType(value: string, separators?: readonly string[]): 1 | 13 | 18;
|
|
24
|
+
static shiftLocation(token: Readonly<Token>, offset: number): {
|
|
25
|
+
offset: number;
|
|
26
|
+
line: number;
|
|
27
|
+
column: number;
|
|
28
|
+
};
|
|
29
|
+
readonly offset: number;
|
|
30
|
+
readonly originalValue: string;
|
|
31
|
+
readonly type: number;
|
|
32
|
+
readonly value: string;
|
|
33
|
+
constructor(value: string, offset: number, originalValue: string, separators?: readonly string[]);
|
|
34
|
+
get length(): number;
|
|
35
|
+
clone(): Token;
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @param value The token value or the token type or its list
|
|
39
|
+
*/
|
|
40
|
+
includes(value: TokenValue, caseInsensitive?: boolean): boolean;
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* @param value The token value or the token type or its list
|
|
44
|
+
*/
|
|
45
|
+
matches(value: TokenValue, caseInsensitive?: boolean): boolean;
|
|
46
|
+
toJSON(): {
|
|
47
|
+
type: number;
|
|
48
|
+
value: string;
|
|
49
|
+
offset: number;
|
|
50
|
+
};
|
|
51
|
+
toNumber(): number;
|
|
52
|
+
unmatched(options?: UnmatchedResultOptions & {
|
|
53
|
+
readonly ref?: string;
|
|
54
|
+
readonly reason?: UnmatchedResultReason;
|
|
55
|
+
}): UnmatchedResult;
|
|
61
56
|
}
|
package/lib/token/token.js
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
return ((_a = lines[lines.length - 1]) !== null && _a !== void 0 ? _a : '').length + 1;
|
|
3
|
+
const lines = value.slice(0, offset).split(/\n/);
|
|
4
|
+
return (lines.at(-1) ?? '').length + 1;
|
|
9
5
|
}
|
|
10
6
|
static getLine(value, offset) {
|
|
11
|
-
return value.slice(0, offset).split(/\n/
|
|
7
|
+
return value.slice(0, offset).split(/\n/).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
|
-
case ',':
|
|
15
|
+
case ',': {
|
|
21
16
|
return Token.Comma;
|
|
17
|
+
}
|
|
22
18
|
}
|
|
23
19
|
}
|
|
24
20
|
return Token.Ident;
|
|
@@ -66,9 +62,9 @@ class Token {
|
|
|
66
62
|
*
|
|
67
63
|
* @param value The token value or the token type or its list
|
|
68
64
|
*/
|
|
69
|
-
|
|
65
|
+
matches(value, caseInsensitive) {
|
|
70
66
|
if (Array.isArray(value)) {
|
|
71
|
-
return value.some(v => this.
|
|
67
|
+
return value.some(v => this.matches(v));
|
|
72
68
|
}
|
|
73
69
|
if (typeof value === 'string') {
|
|
74
70
|
const a = caseInsensitive ? this.value.toLowerCase() : this.value;
|
|
@@ -89,25 +85,23 @@ class Token {
|
|
|
89
85
|
};
|
|
90
86
|
}
|
|
91
87
|
toNumber() {
|
|
92
|
-
const num = parseFloat(this.value);
|
|
93
|
-
return isNaN(num) ? 0 : num;
|
|
88
|
+
const num = Number.parseFloat(this.value);
|
|
89
|
+
return Number.isNaN(num) ? 0 : num;
|
|
94
90
|
}
|
|
95
91
|
unmatched(options) {
|
|
96
|
-
var _a, _b;
|
|
97
92
|
return {
|
|
98
93
|
...options,
|
|
99
94
|
matched: false,
|
|
100
|
-
ref:
|
|
95
|
+
ref: options?.ref ?? null,
|
|
101
96
|
raw: this.value,
|
|
102
97
|
offset: this.offset,
|
|
103
98
|
length: this.value.length,
|
|
104
99
|
line: Token.getLine(this.originalValue, this.offset),
|
|
105
100
|
column: Token.getCol(this.originalValue, this.offset),
|
|
106
|
-
reason:
|
|
101
|
+
reason: options?.reason ?? 'syntax-error',
|
|
107
102
|
};
|
|
108
103
|
}
|
|
109
104
|
}
|
|
110
|
-
exports.Token = Token;
|
|
111
105
|
/**
|
|
112
106
|
* @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
|
|
113
107
|
*/
|
package/lib/token/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|