@markuplint/types 3.0.0-canary.5 → 3.0.0-dev.176
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 +1 -1
- package/lib/check-multi-types.d.ts +4 -1
- package/lib/check-multi-types.js +5 -4
- package/lib/check.d.ts +6 -5
- package/lib/check.spec.js +64 -58
- package/lib/css-syntax.js +49 -47
- package/lib/css-syntax.spec.js +152 -149
- package/lib/defs.js +2 -2
- package/lib/enum.d.ts +2 -1
- package/lib/enum.js +1 -1
- package/lib/get-candidate.d.ts +4 -1
- package/lib/keyword-type.js +3 -2
- package/lib/list.d.ts +2 -1
- package/lib/list.js +2 -1
- package/lib/list.spec.js +118 -117
- package/lib/match-result.d.ts +21 -8
- package/lib/match-result.js +2 -1
- package/lib/number.d.ts +1 -1
- package/lib/primitive/index.spec.js +53 -52
- package/lib/primitive/is-quantity.d.ts +5 -1
- package/lib/primitive/is-uint.d.ts +6 -3
- package/lib/primitive/split-unit.d.ts +2 -2
- package/lib/primitive/split-unit.js +2 -2
- package/lib/rfc/is-bcp-47.spec.js +9 -8
- package/lib/token/token-collection.d.ts +71 -56
- package/lib/token/token-collection.js +30 -23
- package/lib/token/token-collection.spec.js +156 -134
- package/lib/token/token.d.ts +58 -52
- package/lib/token/token.js +19 -20
- package/lib/token/types.d.ts +3 -0
- package/lib/token/types.js +2 -0
- package/lib/types.d.ts +79 -55
- package/lib/types.schema.d.ts +1084 -31
- package/lib/w3c/check-serialized-permissions-policy.spec.js +30 -28
- package/lib/whatwg/check-autocomplete.js +6 -6
- package/lib/whatwg/check-autocomplete.spec.js +361 -360
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +21 -1
- package/lib/whatwg/check-datetime/datetime-tokens.js +9 -6
- package/lib/whatwg/check-datetime/duration-string.js +12 -2
- package/lib/whatwg/check-datetime/index.spec.js +277 -276
- package/lib/whatwg/check-datetime/local-date-and-time-string.js +6 -2
- package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +1 -1
- package/lib/whatwg/check-datetime/time-zone-offset-string.js +3 -2
- package/lib/whatwg/check-mime-type.d.ts +4 -4
- package/lib/whatwg/check-mime-type.js +1 -1
- package/lib/whatwg/check-mime-type.spec.js +53 -52
- package/lib/whatwg/is-abs-url.spec.js +6 -5
- package/lib/whatwg/is-itemprop-name.js +1 -1
- package/package.json +12 -10
- package/{src/check.spec.ts → test/check.spec.js} +7 -1
- package/{src/css-syntax.spec.ts → test/css-syntax.spec.js} +10 -12
- package/{src/list.spec.ts → test/list.spec.js} +7 -7
- package/{src/primitive/index.spec.ts → test/primitive/index.spec.js} +1 -1
- package/{src/rfc/is-bcp-47.spec.ts → test/rfc/is-bcp-47.spec.js} +1 -1
- package/{src/token/token-collection.spec.ts → test/token/token-collection.spec.js} +2 -3
- package/{src/w3c/check-serialized-permissions-policy.spec.ts → test/w3c/check-serialized-permissions-policy.spec.js} +1 -3
- package/{src/whatwg/check-autocomplete.spec.ts → test/whatwg/check-autocomplete.spec.js} +1 -1
- package/{src/whatwg/check-datetime/index.spec.ts → test/whatwg/check-datetime/index.spec.js} +18 -15
- package/{src/whatwg/check-mime-type.spec.ts → test/whatwg/check-mime-type.spec.js} +1 -1
- package/{src/whatwg/is-abs-url.spec.ts → test/whatwg/is-abs-url.spec.js} +1 -1
- package/types.schema.json +369 -318
- package/gen/specific-schema.json +0 -98
- package/gen/types.ts +0 -66
- package/src/check-multi-types.ts +0 -35
- package/src/check.ts +0 -48
- 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.ts +0 -34
- package/src/match-result.ts +0 -49
- package/src/number.ts +0 -46
- 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.ts +0 -13
- package/src/token/index.ts +0 -2
- package/src/token/token-collection.ts +0 -444
- package/src/token/token.ts +0 -144
- package/src/types.schema.ts +0 -1062
- package/src/types.ts +0 -118
- package/src/w3c/check-serialized-permissions-policy.ts +0 -303
- 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.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.ts +0 -46
- 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/gen/specific-schema.json
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
-
"definitions": {
|
|
4
|
-
"list": {
|
|
5
|
-
"description": "- [Space-separated tokens](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#space-separated-tokens)\n- [Comma-separated tokens](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#comma-separated-tokens)",
|
|
6
|
-
"type": "object",
|
|
7
|
-
"additionalProperties": false,
|
|
8
|
-
"required": ["token", "separator"],
|
|
9
|
-
"properties": {
|
|
10
|
-
"token": {
|
|
11
|
-
"oneOf": [
|
|
12
|
-
{
|
|
13
|
-
"$ref": "#/definitions/extended-type"
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"$ref": "#/definitions/enum"
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
},
|
|
20
|
-
"disallowToSurroundBySpaces": { "type": "boolean" },
|
|
21
|
-
"allowEmpty": { "type": "boolean" },
|
|
22
|
-
"ordered": { "type": "boolean" },
|
|
23
|
-
"unique": { "type": "boolean" },
|
|
24
|
-
"caseInsensitive": { "type": "boolean" },
|
|
25
|
-
"number": {
|
|
26
|
-
"oneOf": [
|
|
27
|
-
{
|
|
28
|
-
"type": "string",
|
|
29
|
-
"enum": ["zeroOrMore", "oneOrMore"]
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
"type": "object",
|
|
33
|
-
"additionalProperties": false,
|
|
34
|
-
"required": ["min", "max"],
|
|
35
|
-
"properties": {
|
|
36
|
-
"min": { "type": "number" },
|
|
37
|
-
"max": { "type": "number" }
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
]
|
|
41
|
-
},
|
|
42
|
-
"separator": {
|
|
43
|
-
"type": "string",
|
|
44
|
-
"enum": ["space", "comma"]
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
"enum": {
|
|
49
|
-
"description": "[Enumerated attributes](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#enumerated-attribute)",
|
|
50
|
-
"type": "object",
|
|
51
|
-
"additionalProperties": false,
|
|
52
|
-
"required": ["enum"],
|
|
53
|
-
"properties": {
|
|
54
|
-
"enum": {
|
|
55
|
-
"type": "array",
|
|
56
|
-
"minItems": 1,
|
|
57
|
-
"uniqueItems": true,
|
|
58
|
-
"items": {
|
|
59
|
-
"type": "string"
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
"disallowToSurroundBySpaces": { "type": "boolean" },
|
|
63
|
-
"caseInsensitive": { "type": "boolean" },
|
|
64
|
-
"invalidValueDefault": { "type": "string" },
|
|
65
|
-
"missingValueDefault": { "type": "string" },
|
|
66
|
-
"sameStates": {
|
|
67
|
-
"type": "object",
|
|
68
|
-
"additionalProperties": true,
|
|
69
|
-
"patternProperties": {
|
|
70
|
-
".*": {
|
|
71
|
-
"type": "array",
|
|
72
|
-
"minItems": 1,
|
|
73
|
-
"uniqueItems": true,
|
|
74
|
-
"items": { "type": "string" }
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
"number": {
|
|
81
|
-
"description": "[Numbers](https://html.spec.whatwg.org/dev/common-microsyntaxes.html#numbers)",
|
|
82
|
-
"type": "object",
|
|
83
|
-
"required": ["type"],
|
|
84
|
-
"additionalProperties": false,
|
|
85
|
-
"properties": {
|
|
86
|
-
"type": {
|
|
87
|
-
"type": "string",
|
|
88
|
-
"enum": ["float", "integer"]
|
|
89
|
-
},
|
|
90
|
-
"gt": { "type": "number" },
|
|
91
|
-
"gte": { "type": "number" },
|
|
92
|
-
"lt": { "type": "number" },
|
|
93
|
-
"lte": { "type": "number" },
|
|
94
|
-
"clampable": { "type": "boolean" }
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
package/gen/types.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
import { lexer } from 'css-tree';
|
|
6
|
-
|
|
7
|
-
import { types as extendedTypes, tokenizers } from '../src/defs';
|
|
8
|
-
|
|
9
|
-
const props = Object.keys(lexer.properties).map(p => `<'${p}'>`);
|
|
10
|
-
const types = Object.keys(lexer.types).map(t => `<${t}>`);
|
|
11
|
-
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
13
|
-
const specific = require('./specific-schema.json');
|
|
14
|
-
|
|
15
|
-
fs.writeFileSync(
|
|
16
|
-
path.resolve(__dirname, '..', 'types.schema.json'),
|
|
17
|
-
JSON.stringify({
|
|
18
|
-
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
19
|
-
type: 'object',
|
|
20
|
-
additionalProperties: false,
|
|
21
|
-
definitions: {
|
|
22
|
-
'css-syntax': {
|
|
23
|
-
type: 'string',
|
|
24
|
-
enum: [...Array.from(new Set([...props, ...types])), ...Object.keys(tokenizers).map(t => `<${t}>`)],
|
|
25
|
-
},
|
|
26
|
-
'extended-type': {
|
|
27
|
-
type: 'string',
|
|
28
|
-
enum: Object.keys(extendedTypes),
|
|
29
|
-
},
|
|
30
|
-
'html-attr-requirement': {
|
|
31
|
-
type: 'string',
|
|
32
|
-
enum: ['Boolean'],
|
|
33
|
-
},
|
|
34
|
-
'keyword-defined-type': {
|
|
35
|
-
...oneOf(
|
|
36
|
-
//
|
|
37
|
-
'css-syntax',
|
|
38
|
-
'extended-type',
|
|
39
|
-
'html-attr-requirement',
|
|
40
|
-
),
|
|
41
|
-
},
|
|
42
|
-
...specific.definitions,
|
|
43
|
-
type: {
|
|
44
|
-
...oneOf(
|
|
45
|
-
//
|
|
46
|
-
'keyword-defined-type',
|
|
47
|
-
...Object.keys(specific.definitions),
|
|
48
|
-
),
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
properties: {
|
|
52
|
-
type: {
|
|
53
|
-
$ref: '#/definitions/type',
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
}),
|
|
57
|
-
{ encoding: 'utf-8' },
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
function oneOf(...keys: string[]) {
|
|
61
|
-
return {
|
|
62
|
-
oneOf: keys.map(key => ({
|
|
63
|
-
$ref: `#/definitions/${key}`,
|
|
64
|
-
})),
|
|
65
|
-
};
|
|
66
|
-
}
|
package/src/check-multi-types.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { CustomSyntaxCheck, UnmatchedResult } from './types';
|
|
2
|
-
|
|
3
|
-
import { log } from './debug';
|
|
4
|
-
import { matched } from './match-result';
|
|
5
|
-
|
|
6
|
-
export function checkMultiTypes(value: string, checks: CustomSyntaxCheck[]) {
|
|
7
|
-
let unmatched: UnmatchedResult | undefined;
|
|
8
|
-
|
|
9
|
-
for (const check of checks) {
|
|
10
|
-
const res = check(value);
|
|
11
|
-
if (res.matched) {
|
|
12
|
-
return res;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
res._fn = check.name;
|
|
17
|
-
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
log('%s(%d) vs %s(%d)', unmatched?._fn, unmatched?.passCount, res._fn, res.passCount);
|
|
20
|
-
const passedA = unmatched?.passCount || 0;
|
|
21
|
-
const passedB = res.passCount || 0;
|
|
22
|
-
const offsetA = unmatched?.offset || 0;
|
|
23
|
-
const offsetB = res.offset;
|
|
24
|
-
|
|
25
|
-
if (passedA < passedB || (passedA === passedB && offsetA <= offsetB)) {
|
|
26
|
-
unmatched = res;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const result = unmatched || matched();
|
|
31
|
-
|
|
32
|
-
log('%d checks result: %O', checks.length, result);
|
|
33
|
-
|
|
34
|
-
return result;
|
|
35
|
-
}
|
package/src/check.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { Type, Result, List, CustomSyntax, CustomCssSyntax, Enum, KeywordDefinedType, Number } from './types';
|
|
2
|
-
|
|
3
|
-
import { log } from './debug';
|
|
4
|
-
import { checkEnum } from './enum';
|
|
5
|
-
import { checkKeywordType } from './keyword-type';
|
|
6
|
-
import { checkList } from './list';
|
|
7
|
-
import { checkNumber } from './number';
|
|
8
|
-
|
|
9
|
-
export function check(value: string, type: Type, ref?: string, cache = true): Result {
|
|
10
|
-
if (isKeyword(type)) {
|
|
11
|
-
log('Check keyword: %s', type);
|
|
12
|
-
return checkKeywordType(value, type, cache);
|
|
13
|
-
}
|
|
14
|
-
if (isList(type)) {
|
|
15
|
-
log('Check list: %O', type);
|
|
16
|
-
return checkList(value, type, ref, cache);
|
|
17
|
-
}
|
|
18
|
-
if (isEnum(type)) {
|
|
19
|
-
log('Check enum: %O', type);
|
|
20
|
-
return checkEnum(value, type, ref);
|
|
21
|
-
}
|
|
22
|
-
log('Check number: %O', type);
|
|
23
|
-
return checkNumber(value, type, ref);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function isKeyword(type: Type): type is KeywordDefinedType {
|
|
27
|
-
return typeof type === 'string';
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function isList(type: Type): type is List {
|
|
31
|
-
return typeof type !== 'string' && 'token' in type;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function isEnum(type: Type): type is Enum {
|
|
35
|
-
return typeof type !== 'string' && 'enum' in type;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function isNumber(type: Type): type is Number {
|
|
39
|
-
return typeof type !== 'string' && 'enum' in type;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function isCSSSyntax(type: CustomSyntax | CustomCssSyntax): type is CustomCssSyntax {
|
|
43
|
-
return typeof type === 'string' || 'syntax' in type;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function isCustomSyntax(type: CustomSyntax | CustomCssSyntax): type is CustomSyntax {
|
|
47
|
-
return !isCSSSyntax(type);
|
|
48
|
-
}
|
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/lib/lexer/error.js';
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
import { matchAsTree } from 'css-tree/lib/lexer/match.js';
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
import prepareTokens from 'css-tree/lib/lexer/prepare-tokens.js';
|
|
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