@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
package/src/css-syntax.spec.ts
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import type { CustomCssSyntax } from './types';
|
|
2
|
-
|
|
3
|
-
import { cssSyntaxMatch } from './css-syntax';
|
|
4
|
-
|
|
5
|
-
test('CSS Standard', () => {
|
|
6
|
-
expect(cssSyntaxMatch('10px', '<length>').matched).toBe(true);
|
|
7
|
-
expect(cssSyntaxMatch('one-pixel', '<length>').matched).toBe(false);
|
|
8
|
-
expect(cssSyntaxMatch('(prefers-color-scheme: dark)', '<media-query-list>').matched).toBe(true);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test('Extends', () => {
|
|
12
|
-
const sourceSizeList: CustomCssSyntax = {
|
|
13
|
-
ref: 'https://html.spec.whatwg.org/multipage/images.html#sizes-attributes',
|
|
14
|
-
syntax: {
|
|
15
|
-
apply: '<source-size-list>',
|
|
16
|
-
def: {
|
|
17
|
-
'source-size-list': '[ <source-size># , ]? <source-size-value>',
|
|
18
|
-
'source-size': '<media-condition> <source-size-value>',
|
|
19
|
-
'source-size-value': '<length>',
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
expect(cssSyntaxMatch('50vw', sourceSizeList).matched).toBe(true);
|
|
24
|
-
expect(cssSyntaxMatch('(max-width: 600px) 200px, 50vw', sourceSizeList).matched).toBe(true);
|
|
25
|
-
expect(cssSyntaxMatch('print 300vw', sourceSizeList).matched).toBe(false);
|
|
26
|
-
expect(cssSyntaxMatch('(max-width: 600px) 200px', sourceSizeList).matched).toBe(false);
|
|
27
|
-
expect(
|
|
28
|
-
cssSyntaxMatch('(max-width: 600px) 200px', {
|
|
29
|
-
...sourceSizeList,
|
|
30
|
-
syntax: {
|
|
31
|
-
...sourceSizeList.syntax,
|
|
32
|
-
apply: '<source-size>',
|
|
33
|
-
},
|
|
34
|
-
}).matched,
|
|
35
|
-
).toBe(true);
|
|
36
|
-
|
|
37
|
-
const keyTimes: CustomCssSyntax = {
|
|
38
|
-
ref: 'https://svgwg.org/specs/animations/#KeyTimesAttribute',
|
|
39
|
-
syntax: {
|
|
40
|
-
apply: '<key-times>',
|
|
41
|
-
def: {
|
|
42
|
-
'key-times': '<number> [; <number>]* [;]?',
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
expect(cssSyntaxMatch('20; 20; 30', keyTimes).matched).toBe(true);
|
|
47
|
-
expect(cssSyntaxMatch('20; 20; 30;', keyTimes).matched).toBe(true);
|
|
48
|
-
expect(cssSyntaxMatch('20; 20; abc;', keyTimes).matched).toBe(false);
|
|
49
|
-
expect(cssSyntaxMatch('20; 20; ;', keyTimes).matched).toBe(false);
|
|
50
|
-
|
|
51
|
-
const SVGViewBox: CustomCssSyntax = {
|
|
52
|
-
ref: 'https://svgwg.org/svg2-draft/coords.html#ViewBoxAttribute',
|
|
53
|
-
syntax: {
|
|
54
|
-
apply: '<view-box>',
|
|
55
|
-
def: {
|
|
56
|
-
'view-box': '<min-x> [,]? <min-y> [,]? <width> [,]? <height>',
|
|
57
|
-
'min-x': '<number>',
|
|
58
|
-
'min-y': '<number>',
|
|
59
|
-
width: '<number>',
|
|
60
|
-
height: '<number>',
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
expect(cssSyntaxMatch('0 0 30 10', SVGViewBox).matched).toBe(true);
|
|
65
|
-
expect(cssSyntaxMatch('0 0, 30, 10', SVGViewBox).matched).toBe(true);
|
|
66
|
-
expect(cssSyntaxMatch('0 0, 30', SVGViewBox).matched).toBe(false);
|
|
67
|
-
|
|
68
|
-
const percentageList: CustomCssSyntax = {
|
|
69
|
-
ref: 'https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#percentage',
|
|
70
|
-
syntax: {
|
|
71
|
-
apply: '<percentage-list>',
|
|
72
|
-
def: {
|
|
73
|
-
'percentage-list': '[ <number> [,]? ]* <number>',
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
expect(cssSyntaxMatch('0 0 30 10', percentageList).matched).toBe(true);
|
|
78
|
-
expect(cssSyntaxMatch('0, 0, 30 10', percentageList).matched).toBe(true);
|
|
79
|
-
expect(cssSyntaxMatch('0', percentageList).matched).toBe(true);
|
|
80
|
-
expect(cssSyntaxMatch('', percentageList).matched).toBe(false);
|
|
81
|
-
|
|
82
|
-
const custom: CustomCssSyntax = {
|
|
83
|
-
ref: 'n/a',
|
|
84
|
-
syntax: {
|
|
85
|
-
apply: '<custom>',
|
|
86
|
-
def: {
|
|
87
|
-
custom: '0 | 1 | .',
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
expect(cssSyntaxMatch('0', custom).matched).toBe(true);
|
|
92
|
-
expect(cssSyntaxMatch('1', custom).matched).toBe(true);
|
|
93
|
-
expect(cssSyntaxMatch('.', custom).matched).toBe(true);
|
|
94
|
-
expect(cssSyntaxMatch('2', custom).matched).toBe(false);
|
|
95
|
-
expect(cssSyntaxMatch(':', custom).matched).toBe(false);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test('custom-type-checking', () => {
|
|
99
|
-
const custom: CustomCssSyntax = {
|
|
100
|
-
ref: 'n/a',
|
|
101
|
-
caseSensitive: true,
|
|
102
|
-
syntax: {
|
|
103
|
-
apply: '<custom>',
|
|
104
|
-
def: {
|
|
105
|
-
custom: '<custom-type>',
|
|
106
|
-
'custom-type': token => {
|
|
107
|
-
if (!token) {
|
|
108
|
-
return 0;
|
|
109
|
-
}
|
|
110
|
-
return token.value === '1' ? 1 : 0;
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
expect(cssSyntaxMatch('1', custom).matched).toBe(true);
|
|
116
|
-
expect(cssSyntaxMatch('0', custom).matched).toBe(false);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test('case-sensitive', () => {
|
|
120
|
-
const custom: CustomCssSyntax = {
|
|
121
|
-
ref: 'n/a',
|
|
122
|
-
caseSensitive: true,
|
|
123
|
-
syntax: {
|
|
124
|
-
apply: '<custom>',
|
|
125
|
-
def: {
|
|
126
|
-
custom: 'CaSeS [a | B | aBc]',
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
};
|
|
130
|
-
expect(cssSyntaxMatch('CaSeS a', custom).matched).toBe(true);
|
|
131
|
-
expect(cssSyntaxMatch('CaSeS B', custom).matched).toBe(true);
|
|
132
|
-
expect(cssSyntaxMatch('CaSeS aBc', custom).matched).toBe(true);
|
|
133
|
-
expect(cssSyntaxMatch('CaSeS A', custom)).toStrictEqual({
|
|
134
|
-
column: 7,
|
|
135
|
-
line: 1,
|
|
136
|
-
matched: false,
|
|
137
|
-
length: 1,
|
|
138
|
-
offset: 6,
|
|
139
|
-
partName: 'value',
|
|
140
|
-
raw: 'A',
|
|
141
|
-
reason: 'syntax-error',
|
|
142
|
-
ref: 'n/a',
|
|
143
|
-
expects: [
|
|
144
|
-
{
|
|
145
|
-
type: 'syntax',
|
|
146
|
-
value: 'CaSeS [ a | B | aBc ]',
|
|
147
|
-
},
|
|
148
|
-
],
|
|
149
|
-
});
|
|
150
|
-
expect(cssSyntaxMatch('CaSeS abc', custom)).toStrictEqual({
|
|
151
|
-
column: 7,
|
|
152
|
-
line: 1,
|
|
153
|
-
matched: false,
|
|
154
|
-
length: 3,
|
|
155
|
-
offset: 6,
|
|
156
|
-
partName: 'value',
|
|
157
|
-
raw: 'abc',
|
|
158
|
-
reason: 'syntax-error',
|
|
159
|
-
ref: 'n/a',
|
|
160
|
-
expects: [
|
|
161
|
-
{
|
|
162
|
-
type: 'syntax',
|
|
163
|
-
value: 'CaSeS [ a | B | aBc ]',
|
|
164
|
-
},
|
|
165
|
-
],
|
|
166
|
-
});
|
|
167
|
-
});
|
package/src/css-syntax.ts
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import type { CustomCssSyntax, CssSyntaxTokenizer, CSSSyntaxToken, GetNextToken, Result, CssSyntax } from './types';
|
|
2
|
-
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
import csstree from 'css-tree';
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import { SyntaxMatchError } from 'css-tree/lexer/error';
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
import { matchAsTree } from 'css-tree/lexer/match';
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
import prepareTokens from 'css-tree/lexer/prepare-tokens';
|
|
11
|
-
|
|
12
|
-
import { log } from './debug';
|
|
13
|
-
import { tokenizers } from './defs';
|
|
14
|
-
import { matched } from './match-result';
|
|
15
|
-
|
|
16
|
-
// eslint-disable-next-line no-redeclare
|
|
17
|
-
interface SyntaxMatchError {
|
|
18
|
-
message: string;
|
|
19
|
-
rawMessage: 'Mismatch';
|
|
20
|
-
syntax: string;
|
|
21
|
-
css: string;
|
|
22
|
-
mismatchOffset: number;
|
|
23
|
-
mismatchLength: number;
|
|
24
|
-
offset: number;
|
|
25
|
-
line: number;
|
|
26
|
-
column: number;
|
|
27
|
-
loc: {
|
|
28
|
-
source: '<unknown>';
|
|
29
|
-
start: { offset: number; line: number; column: number };
|
|
30
|
-
end: { offset: number; line: number; column: number };
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function cssSyntaxMatch(value: string, type: CssSyntax | CustomCssSyntax): Result {
|
|
35
|
-
log('Search CSS Syntax: "%s"', type);
|
|
36
|
-
|
|
37
|
-
const origin = value;
|
|
38
|
-
let defName: `<${string}>`;
|
|
39
|
-
const typesExtended: Record<string, string> = {};
|
|
40
|
-
const typesCheckers: Record<string, CssSyntaxTokenizer> = {};
|
|
41
|
-
let propsExtended: Record<string, string>;
|
|
42
|
-
let ref: string | undefined = undefined;
|
|
43
|
-
let caseSensitive = false;
|
|
44
|
-
let ebnf: Record<string, string | string[]> | null = null;
|
|
45
|
-
|
|
46
|
-
if (typeof type === 'string') {
|
|
47
|
-
defName = type;
|
|
48
|
-
propsExtended = {};
|
|
49
|
-
} else {
|
|
50
|
-
defName = type.syntax.apply;
|
|
51
|
-
ebnf = type.syntax.ebnf || null;
|
|
52
|
-
|
|
53
|
-
if (ebnf) {
|
|
54
|
-
// Work in progress
|
|
55
|
-
return matched();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const types = {
|
|
59
|
-
...tokenizers,
|
|
60
|
-
...type.syntax.def,
|
|
61
|
-
};
|
|
62
|
-
Object.keys(types).forEach(key => {
|
|
63
|
-
const valueOrChecker = types[key];
|
|
64
|
-
if (typeof valueOrChecker === 'string') {
|
|
65
|
-
typesExtended[key] = valueOrChecker;
|
|
66
|
-
} else {
|
|
67
|
-
typesCheckers[key] = valueOrChecker;
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
propsExtended = { ...type.syntax.properties };
|
|
71
|
-
if (type.caseSensitive) {
|
|
72
|
-
caseSensitive = true;
|
|
73
|
-
Object.keys(typesExtended).forEach(key => eachMimicCases(key, typesExtended));
|
|
74
|
-
Object.keys(propsExtended).forEach(key => eachMimicCases(key, propsExtended));
|
|
75
|
-
value = mimicCases(value);
|
|
76
|
-
}
|
|
77
|
-
ref = type.ref;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// @ts-ignore
|
|
81
|
-
const lexer = csstree.fork({
|
|
82
|
-
types: typesExtended,
|
|
83
|
-
properties: propsExtended,
|
|
84
|
-
}).lexer;
|
|
85
|
-
|
|
86
|
-
Object.keys(typesCheckers).forEach(key => {
|
|
87
|
-
const checker = typesCheckers[key];
|
|
88
|
-
lexer.addType_(key, (token: CSSSyntaxToken, getNextToken: GetNextToken) =>
|
|
89
|
-
checker(token, getNextToken, cssSyntaxMatch),
|
|
90
|
-
);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
const { isProp, name, matcher } = defToMatcher(lexer, defName);
|
|
94
|
-
const refParam = isProp ? 'Property' : 'Type';
|
|
95
|
-
ref = ref || `https://csstree.github.io/docs/syntax/#${refParam}:${name}`;
|
|
96
|
-
|
|
97
|
-
// eslint-disable-next-line no-console
|
|
98
|
-
const _w = console.warn;
|
|
99
|
-
|
|
100
|
-
if (log.enabled) {
|
|
101
|
-
// eslint-disable-next-line no-console
|
|
102
|
-
console.warn = warn => log('WARNING: %s (by %s => %s)', warn, value, type);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const tokens = prepareTokens(value, lexer.syntax);
|
|
106
|
-
const result = matchAsTree(tokens, matcher.match, lexer);
|
|
107
|
-
|
|
108
|
-
if (caseSensitive) {
|
|
109
|
-
if (result.tokens && Array.isArray(result.tokens)) {
|
|
110
|
-
let reducer = 0;
|
|
111
|
-
result.tokens = result.tokens.map((token: CSSSyntaxToken) => {
|
|
112
|
-
const value = token.value;
|
|
113
|
-
const originValue = deMimicCases(value || '');
|
|
114
|
-
const isMimiced = value !== originValue;
|
|
115
|
-
reducer += isMimiced ? 'mimiccases------mimiccases'.length : 0;
|
|
116
|
-
token.value = originValue;
|
|
117
|
-
token.balance = token.balance - reducer;
|
|
118
|
-
return token;
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
log('css-tree/result: %O', result);
|
|
124
|
-
// eslint-disable-next-line no-console
|
|
125
|
-
console.warn = _w;
|
|
126
|
-
|
|
127
|
-
if (result.match) {
|
|
128
|
-
if (log.enabled) {
|
|
129
|
-
log('css-tree/result.match: %s', JSON.stringify(result.match, null, 2));
|
|
130
|
-
}
|
|
131
|
-
return matched();
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const error: SyntaxMatchError = new SyntaxMatchError(result.reason, matcher.syntax, value, result);
|
|
135
|
-
|
|
136
|
-
if (caseSensitive) {
|
|
137
|
-
error.message = deMimicCases(error.message);
|
|
138
|
-
error.syntax = deMimicCases(error.syntax);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
log('css-tree/SyntaxMatchError: %O', error);
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
matched: false,
|
|
145
|
-
ref,
|
|
146
|
-
raw: origin.slice(error.mismatchOffset, error.mismatchOffset + error.mismatchLength),
|
|
147
|
-
offset: error.mismatchOffset,
|
|
148
|
-
length: error.mismatchLength,
|
|
149
|
-
line: error.line,
|
|
150
|
-
column: error.column,
|
|
151
|
-
expects: [
|
|
152
|
-
{
|
|
153
|
-
type: 'syntax',
|
|
154
|
-
value: error.syntax,
|
|
155
|
-
},
|
|
156
|
-
],
|
|
157
|
-
partName: error.mismatchOffset === 0 ? undefined : 'value',
|
|
158
|
-
reason: 'syntax-error',
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function defToMatcher(lexer: any, def: `<${string}>`) {
|
|
163
|
-
const isProp = def.search("<'") === 0;
|
|
164
|
-
const name = def.replace(/^<'?|'?>$/g, '');
|
|
165
|
-
const matcher = isProp ? lexer.properties[name] : lexer.types[name];
|
|
166
|
-
if (!matcher) {
|
|
167
|
-
log('"%s" CSS syntax not found', def);
|
|
168
|
-
throw new Error('MARKUPLINT_TYPE_NO_EXIST');
|
|
169
|
-
}
|
|
170
|
-
return {
|
|
171
|
-
isProp,
|
|
172
|
-
name,
|
|
173
|
-
matcher,
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function eachMimicCases(key: string, obj: Record<string, string>) {
|
|
178
|
-
const value = obj[key];
|
|
179
|
-
obj[key] = mimicCases(value);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function mimicCases(value: string) {
|
|
183
|
-
return value.replace(/[A-Z]/g, $0 => `mimiccases---${$0}---mimiccases`);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function deMimicCases(value: string) {
|
|
187
|
-
return value.replace(/mimiccases---([A-Z])---mimiccases/g, (_, $1) => $1);
|
|
188
|
-
}
|
package/src/debug.ts
DELETED