@markuplint/types 3.0.0-dev.24 → 3.0.0-dev.38
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/package.json +3 -2
- package/gen/specific-schema.json +0 -98
- package/gen/types.ts +0 -66
- 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/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