@markuplint/types 3.0.0-alpha.6 → 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.
Files changed (107) hide show
  1. package/README.md +12 -8
  2. package/lib/check-multi-types.d.ts +1 -1
  3. package/lib/check-multi-types.js +5 -4
  4. package/lib/check.d.ts +6 -5
  5. package/lib/check.spec.js +64 -58
  6. package/lib/css-syntax.js +49 -47
  7. package/lib/css-syntax.spec.js +152 -149
  8. package/lib/defs.js +2 -2
  9. package/lib/enum.d.ts +2 -1
  10. package/lib/enum.js +1 -1
  11. package/lib/get-candidate.d.ts +1 -1
  12. package/lib/keyword-type.js +3 -2
  13. package/lib/list.d.ts +2 -1
  14. package/lib/list.js +2 -1
  15. package/lib/list.spec.js +118 -117
  16. package/lib/match-result.d.ts +3 -3
  17. package/lib/match-result.js +2 -1
  18. package/lib/number.d.ts +1 -1
  19. package/lib/primitive/index.spec.js +53 -52
  20. package/lib/primitive/is-quantity.d.ts +5 -1
  21. package/lib/primitive/is-uint.d.ts +1 -1
  22. package/lib/primitive/split-unit.js +2 -2
  23. package/lib/rfc/is-bcp-47.spec.js +9 -8
  24. package/lib/token/token-collection.d.ts +20 -14
  25. package/lib/token/token-collection.js +30 -23
  26. package/lib/token/token-collection.spec.js +156 -134
  27. package/lib/token/token.d.ts +10 -9
  28. package/lib/token/token.js +19 -20
  29. package/lib/token/types.d.ts +3 -0
  30. package/lib/token/types.js +2 -0
  31. package/lib/types.d.ts +44 -44
  32. package/lib/types.schema.d.ts +369 -318
  33. package/lib/w3c/check-serialized-permissions-policy.spec.js +30 -28
  34. package/lib/whatwg/check-autocomplete.js +6 -6
  35. package/lib/whatwg/check-autocomplete.spec.js +361 -360
  36. package/lib/whatwg/check-datetime/datetime-tokens.js +9 -6
  37. package/lib/whatwg/check-datetime/duration-string.js +12 -2
  38. package/lib/whatwg/check-datetime/index.spec.js +277 -276
  39. package/lib/whatwg/check-datetime/local-date-and-time-string.js +6 -2
  40. package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +1 -1
  41. package/lib/whatwg/check-datetime/time-zone-offset-string.js +3 -2
  42. package/lib/whatwg/check-mime-type.js +1 -1
  43. package/lib/whatwg/check-mime-type.spec.js +53 -52
  44. package/lib/whatwg/is-abs-url.spec.js +6 -5
  45. package/lib/whatwg/is-itemprop-name.js +1 -1
  46. package/package.json +13 -11
  47. package/{src/check.spec.ts → test/check.spec.js} +7 -1
  48. package/{src/css-syntax.spec.ts → test/css-syntax.spec.js} +10 -12
  49. package/{src/list.spec.ts → test/list.spec.js} +7 -7
  50. package/{src/primitive/index.spec.ts → test/primitive/index.spec.js} +1 -1
  51. package/{src/rfc/is-bcp-47.spec.ts → test/rfc/is-bcp-47.spec.js} +1 -1
  52. package/{src/token/token-collection.spec.ts → test/token/token-collection.spec.js} +2 -3
  53. package/{src/w3c/check-serialized-permissions-policy.spec.ts → test/w3c/check-serialized-permissions-policy.spec.js} +1 -3
  54. package/{src/whatwg/check-autocomplete.spec.ts → test/whatwg/check-autocomplete.spec.js} +1 -1
  55. package/{src/whatwg/check-datetime/index.spec.ts → test/whatwg/check-datetime/index.spec.js} +18 -15
  56. package/{src/whatwg/check-mime-type.spec.ts → test/whatwg/check-mime-type.spec.js} +1 -1
  57. package/{src/whatwg/is-abs-url.spec.ts → test/whatwg/is-abs-url.spec.js} +1 -1
  58. package/types.schema.json +369 -318
  59. package/gen/specific-schema.json +0 -98
  60. package/gen/types.ts +0 -66
  61. package/src/check-multi-types.ts +0 -35
  62. package/src/check.ts +0 -48
  63. package/src/css-syntax.ts +0 -188
  64. package/src/debug.ts +0 -3
  65. package/src/defs.ts +0 -811
  66. package/src/enum.ts +0 -25
  67. package/src/get-candidate.ts +0 -24
  68. package/src/index.ts +0 -3
  69. package/src/keyword-type.ts +0 -64
  70. package/src/list.ts +0 -34
  71. package/src/match-result.ts +0 -49
  72. package/src/number.ts +0 -46
  73. package/src/primitive/index.ts +0 -7
  74. package/src/primitive/is-float.ts +0 -8
  75. package/src/primitive/is-int.ts +0 -8
  76. package/src/primitive/is-non-zero-uint.ts +0 -8
  77. package/src/primitive/is-quantity.ts +0 -38
  78. package/src/primitive/is-uint.ts +0 -15
  79. package/src/primitive/range.ts +0 -14
  80. package/src/primitive/split-unit.ts +0 -20
  81. package/src/rfc/is-bcp-47.ts +0 -13
  82. package/src/token/index.ts +0 -2
  83. package/src/token/token-collection.ts +0 -444
  84. package/src/token/token.ts +0 -144
  85. package/src/types.schema.ts +0 -1062
  86. package/src/types.ts +0 -118
  87. package/src/w3c/check-serialized-permissions-policy.ts +0 -303
  88. package/src/whatwg/check-autocomplete.ts +0 -380
  89. package/src/whatwg/check-datetime/date-string.ts +0 -44
  90. package/src/whatwg/check-datetime/datetime-tokens.ts +0 -600
  91. package/src/whatwg/check-datetime/duration-string.ts +0 -399
  92. package/src/whatwg/check-datetime/global-date-and-time-string.ts +0 -96
  93. package/src/whatwg/check-datetime/index.ts +0 -36
  94. package/src/whatwg/check-datetime/local-date-and-time-string.ts +0 -163
  95. package/src/whatwg/check-datetime/month-string.ts +0 -31
  96. package/src/whatwg/check-datetime/time-string.ts +0 -49
  97. package/src/whatwg/check-datetime/time-zone-offset-string.ts +0 -93
  98. package/src/whatwg/check-datetime/week-string.ts +0 -41
  99. package/src/whatwg/check-datetime/year-string.ts +0 -26
  100. package/src/whatwg/check-datetime/yearless-date-string.ts +0 -38
  101. package/src/whatwg/check-mime-type.ts +0 -46
  102. package/src/whatwg/is-abs-url.ts +0 -31
  103. package/src/whatwg/is-browser-context-name.ts +0 -16
  104. package/src/whatwg/is-custom-element-name.ts +0 -76
  105. package/src/whatwg/is-itemprop-name.ts +0 -17
  106. package/tsconfig.test.json +0 -3
  107. package/tsconfig.tsbuildinfo +0 -1
package/README.md CHANGED
@@ -1,18 +1,14 @@
1
1
  # @markuplint/types
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/%40markuplint%2Ftypes.svg)](https://www.npmjs.com/package/@markuplint/types)
4
- [![Build Status](https://travis-ci.org/markuplint/markuplint.svg?branch=main)](https://travis-ci.org/markuplint/markuplint)
5
- [![Coverage Status](https://coveralls.io/repos/github/markuplint/markuplint/badge.svg?branch=main)](https://coveralls.io/github/markuplint/markuplint?branch=main)
6
4
 
7
- ## Install
5
+ **Type declaration and value checker**
8
6
 
9
- ```sh
10
- $ npm install @markuplint/types
7
+ ## Type declaration
11
8
 
12
- $ yarn add @markuplint/types
13
- ```
9
+ - [types.schema.json](./types.schema.json)
14
10
 
15
- ## Usage
11
+ ## API
16
12
 
17
13
  ```ts
18
14
  import { check } from '@markuplint/types';
@@ -100,3 +96,11 @@ check('2020-02-30', 'DateTime');
100
96
  | `<number-optional-number>` | Some attributes for SVG | | ✅ |
101
97
 
102
98
  In addition, you can use types **[CSSTree](https://github.com/csstree/csstree)** defined.
99
+
100
+ ## Install
101
+
102
+ ```shell
103
+ $ npm install @markuplint/types
104
+
105
+ $ yarn add @markuplint/types
106
+ ```
@@ -1,5 +1,5 @@
1
1
  import type { CustomSyntaxCheck, UnmatchedResult } from './types';
2
2
  export declare function checkMultiTypes(
3
3
  value: string,
4
- checks: CustomSyntaxCheck[],
4
+ checks: readonly CustomSyntaxCheck[],
5
5
  ): import('./types').MatchedResult | UnmatchedResult;
@@ -4,6 +4,7 @@ exports.checkMultiTypes = void 0;
4
4
  const debug_1 = require("./debug");
5
5
  const match_result_1 = require("./match-result");
6
6
  function checkMultiTypes(value, checks) {
7
+ var _a, _b, _c;
7
8
  let unmatched;
8
9
  for (const check of checks) {
9
10
  const res = check(value);
@@ -14,15 +15,15 @@ function checkMultiTypes(value, checks) {
14
15
  res._fn = check.name;
15
16
  // @ts-ignore
16
17
  (0, debug_1.log)('%s(%d) vs %s(%d)', unmatched === null || unmatched === void 0 ? void 0 : unmatched._fn, unmatched === null || unmatched === void 0 ? void 0 : unmatched.passCount, res._fn, res.passCount);
17
- const passedA = (unmatched === null || unmatched === void 0 ? void 0 : unmatched.passCount) || 0;
18
- const passedB = res.passCount || 0;
19
- const offsetA = (unmatched === null || unmatched === void 0 ? void 0 : unmatched.offset) || 0;
18
+ const passedA = (_a = unmatched === null || unmatched === void 0 ? void 0 : unmatched.passCount) !== null && _a !== void 0 ? _a : 0;
19
+ const passedB = (_b = res.passCount) !== null && _b !== void 0 ? _b : 0;
20
+ const offsetA = (_c = unmatched === null || unmatched === void 0 ? void 0 : unmatched.offset) !== null && _c !== void 0 ? _c : 0;
20
21
  const offsetB = res.offset;
21
22
  if (passedA < passedB || (passedA === passedB && offsetA <= offsetB)) {
22
23
  unmatched = res;
23
24
  }
24
25
  }
25
- const result = unmatched || (0, match_result_1.matched)();
26
+ const result = unmatched !== null && unmatched !== void 0 ? unmatched : (0, match_result_1.matched)();
26
27
  (0, debug_1.log)('%d checks result: %O', checks.length, result);
27
28
  return result;
28
29
  }
package/lib/check.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import type { Type, Result, List, CustomSyntax, CustomCssSyntax, Enum, KeywordDefinedType, Number } from './types';
2
- export declare function check(value: string, type: Type, ref?: string, cache?: boolean): Result;
3
- export declare function isKeyword(type: Type): type is KeywordDefinedType;
4
- export declare function isList(type: Type): type is List;
5
- export declare function isEnum(type: Type): type is Enum;
6
- export declare function isNumber(type: Type): type is Number;
2
+ import type { ReadonlyDeep } from 'type-fest';
3
+ export declare function check(value: string, type: ReadonlyDeep<Type>, ref?: string, cache?: boolean): Result;
4
+ export declare function isKeyword(type: ReadonlyDeep<Type>): type is ReadonlyDeep<KeywordDefinedType>;
5
+ export declare function isList(type: ReadonlyDeep<Type>): type is ReadonlyDeep<List>;
6
+ export declare function isEnum(type: ReadonlyDeep<Type>): type is ReadonlyDeep<Enum>;
7
+ export declare function isNumber(type: ReadonlyDeep<Type>): type is ReadonlyDeep<Number>;
7
8
  export declare function isCSSSyntax(type: CustomSyntax | CustomCssSyntax): type is CustomCssSyntax;
8
9
  export declare function isCustomSyntax(type: CustomSyntax | CustomCssSyntax): type is CustomSyntax;
package/lib/check.spec.js CHANGED
@@ -1,76 +1,82 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const check_1 = require("./check");
1
+ 'use strict';
2
+ // @ts-nocheck
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+ const check_1 = require('./check');
4
5
  test('Any', () => {
5
- expect((0, check_1.check)('', 'Any').matched).toBe(true);
6
- expect((0, check_1.check)(' ', 'Any').matched).toBe(true);
7
- expect((0, check_1.check)('a', 'Any').matched).toBe(true);
6
+ expect((0, check_1.check)('', 'Any').matched).toBe(true);
7
+ expect((0, check_1.check)(' ', 'Any').matched).toBe(true);
8
+ expect((0, check_1.check)('a', 'Any').matched).toBe(true);
8
9
  });
9
10
  test('NoEmptyAny', () => {
10
- expect((0, check_1.check)('', 'NoEmptyAny').matched).toBe(false);
11
- expect((0, check_1.check)(' ', 'NoEmptyAny').matched).toBe(true);
12
- expect((0, check_1.check)('a', 'NoEmptyAny').matched).toBe(true);
11
+ expect((0, check_1.check)('', 'NoEmptyAny').matched).toBe(false);
12
+ expect((0, check_1.check)(' ', 'NoEmptyAny').matched).toBe(true);
13
+ expect((0, check_1.check)('a', 'NoEmptyAny').matched).toBe(true);
13
14
  });
14
15
  test('OneLineAny', () => {
15
- expect((0, check_1.check)('', 'OneLineAny').matched).toBe(true);
16
- expect((0, check_1.check)(' ', 'OneLineAny').matched).toBe(true);
17
- expect((0, check_1.check)('a', 'OneLineAny').matched).toBe(true);
18
- expect((0, check_1.check)('a ', 'OneLineAny').matched).toBe(true);
19
- expect((0, check_1.check)('a b', 'OneLineAny').matched).toBe(true);
20
- expect((0, check_1.check)('a\n', 'OneLineAny').matched).toBe(false);
21
- expect((0, check_1.check)('a\nb', 'OneLineAny').matched).toBe(false);
22
- expect((0, check_1.check)('a\r\nb', 'OneLineAny').matched).toBe(false);
23
- expect((0, check_1.check)('a\rb', 'OneLineAny').matched).toBe(false);
16
+ expect((0, check_1.check)('', 'OneLineAny').matched).toBe(true);
17
+ expect((0, check_1.check)(' ', 'OneLineAny').matched).toBe(true);
18
+ expect((0, check_1.check)('a', 'OneLineAny').matched).toBe(true);
19
+ expect((0, check_1.check)('a ', 'OneLineAny').matched).toBe(true);
20
+ expect((0, check_1.check)('a b', 'OneLineAny').matched).toBe(true);
21
+ expect((0, check_1.check)('a\n', 'OneLineAny').matched).toBe(false);
22
+ expect((0, check_1.check)('a\nb', 'OneLineAny').matched).toBe(false);
23
+ expect((0, check_1.check)('a\r\nb', 'OneLineAny').matched).toBe(false);
24
+ expect((0, check_1.check)('a\rb', 'OneLineAny').matched).toBe(false);
24
25
  });
25
26
  test('Pattern', () => {
26
- expect((0, check_1.check)('.*', 'Pattern').matched).toBe(true);
27
- expect((0, check_1.check)('[a-z]+', 'Pattern').matched).toBe(true);
28
- expect((0, check_1.check)(']//[()?!+*', 'Pattern').matched).toBe(false);
27
+ expect((0, check_1.check)('.*', 'Pattern').matched).toBe(true);
28
+ expect((0, check_1.check)('[a-z]+', 'Pattern').matched).toBe(true);
29
+ expect((0, check_1.check)(']//[()?!+*', 'Pattern').matched).toBe(false);
29
30
  });
30
31
  test('BCP47', () => {
31
- expect((0, check_1.check)('en', 'BCP47').matched).toBe(true);
32
- expect((0, check_1.check)('en-US', 'BCP47').matched).toBe(true);
33
- expect((0, check_1.check)('ja', 'BCP47').matched).toBe(true);
34
- expect((0, check_1.check)(' ja ', 'BCP47').matched).toBe(false);
35
- expect((0, check_1.check)('', 'BCP47').matched).toBe(false);
36
- expect((0, check_1.check)('zh/cn', 'BCP47').matched).toBe(false);
32
+ expect((0, check_1.check)('en', 'BCP47').matched).toBe(true);
33
+ expect((0, check_1.check)('en-US', 'BCP47').matched).toBe(true);
34
+ expect((0, check_1.check)('ja', 'BCP47').matched).toBe(true);
35
+ expect((0, check_1.check)(' ja ', 'BCP47').matched).toBe(false);
36
+ expect((0, check_1.check)('', 'BCP47').matched).toBe(false);
37
+ expect((0, check_1.check)('zh/cn', 'BCP47').matched).toBe(false);
37
38
  });
38
39
  test('Srcset', () => {
39
- expect((0, check_1.check)('a/bb/ccc/dddd', 'Srcset').matched).toBe(true);
40
- expect((0, check_1.check)('a/bb/ccc/dddd 200w', 'Srcset').matched).toBe(true);
41
- expect((0, check_1.check)('a/bb/ccc/dddd 200w, b/cc/ddd/eeee 1.5x', 'Srcset').matched).toBe(true);
42
- expect((0, check_1.check)('a/bb/ccc/dddd 200w, b/cc/ddd/eeee 1.5a', 'Srcset').matched).toBe(false);
40
+ expect((0, check_1.check)('a/bb/ccc/dddd', 'Srcset').matched).toBe(true);
41
+ expect((0, check_1.check)('a/bb/ccc/dddd 200w', 'Srcset').matched).toBe(true);
42
+ expect((0, check_1.check)('a/bb/ccc/dddd 200w, b/cc/ddd/eeee 1.5x', 'Srcset').matched).toBe(true);
43
+ expect((0, check_1.check)('a/bb/ccc/dddd 200w, b/cc/ddd/eeee 1.5a', 'Srcset').matched).toBe(false);
43
44
  });
44
45
  test('IconSize', () => {
45
- expect((0, check_1.check)('any', 'IconSize').matched).toBe(true);
46
- expect((0, check_1.check)('Any', 'IconSize').matched).toBe(true);
47
- expect((0, check_1.check)('10x10', 'IconSize').matched).toBe(true);
48
- expect((0, check_1.check)('1x1', 'IconSize').matched).toBe(true);
49
- expect((0, check_1.check)('1x0', 'IconSize').matched).toBe(false);
50
- expect((0, check_1.check)('0x1', 'IconSize').matched).toBe(false);
51
- expect((0, check_1.check)('0x0', 'IconSize').matched).toBe(false);
52
- expect((0, check_1.check)('', 'IconSize').matched).toBe(false);
53
- expect((0, check_1.check)(' ', 'IconSize').matched).toBe(false);
54
- expect((0, check_1.check)('1', 'IconSize').matched).toBe(false);
55
- expect((0, check_1.check)('1x', 'IconSize').matched).toBe(false);
56
- expect((0, check_1.check)('x1', 'IconSize').matched).toBe(false);
46
+ expect((0, check_1.check)('any', 'IconSize').matched).toBe(true);
47
+ expect((0, check_1.check)('Any', 'IconSize').matched).toBe(true);
48
+ expect((0, check_1.check)('10x10', 'IconSize').matched).toBe(true);
49
+ expect((0, check_1.check)('1x1', 'IconSize').matched).toBe(true);
50
+ expect((0, check_1.check)('1x0', 'IconSize').matched).toBe(false);
51
+ expect((0, check_1.check)('0x1', 'IconSize').matched).toBe(false);
52
+ expect((0, check_1.check)('0x0', 'IconSize').matched).toBe(false);
53
+ expect((0, check_1.check)('', 'IconSize').matched).toBe(false);
54
+ expect((0, check_1.check)(' ', 'IconSize').matched).toBe(false);
55
+ expect((0, check_1.check)('1', 'IconSize').matched).toBe(false);
56
+ expect((0, check_1.check)('1x', 'IconSize').matched).toBe(false);
57
+ expect((0, check_1.check)('x1', 'IconSize').matched).toBe(false);
57
58
  });
58
59
  test('Number', () => {
59
- expect((0, check_1.check)('10', { type: 'integer', gt: 0 }).matched).toBe(true);
60
- expect((0, check_1.check)('0', { type: 'integer', gt: 0 }).matched).toBe(false);
61
- expect((0, check_1.check)('0', { type: 'integer', gte: 0 }).matched).toBe(true);
62
- expect((0, check_1.check)('9', { type: 'integer', lt: 10 }).matched).toBe(true);
63
- expect((0, check_1.check)('10', { type: 'integer', lt: 10 }).matched).toBe(false);
60
+ expect((0, check_1.check)('10', { type: 'integer', gt: 0 }).matched).toBe(true);
61
+ expect((0, check_1.check)('0', { type: 'integer', gt: 0 }).matched).toBe(false);
62
+ expect((0, check_1.check)('0', { type: 'integer', gte: 0 }).matched).toBe(true);
63
+ expect((0, check_1.check)('9', { type: 'integer', lt: 10 }).matched).toBe(true);
64
+ expect((0, check_1.check)('10', { type: 'integer', lt: 10 }).matched).toBe(false);
64
65
  });
65
66
  test('Non-exist types', () => {
66
- // @ts-ignore
67
- expect((0, check_1.check)('abc', 'String').matched).toBe(true);
68
- // @ts-ignore
69
- expect((0, check_1.check)('abc', 'FooBar').matched).toBe(true);
70
- // @ts-ignore
71
- expect((0, check_1.check)('abc', ' ').matched).toBe(true);
72
- // @ts-ignore
73
- expect((0, check_1.check)('abc', '\n').matched).toBe(true);
74
- // @ts-ignore
75
- expect((0, check_1.check)('abc', '').matched).toBe(true);
67
+ // @ts-ignore
68
+ expect((0, check_1.check)('abc', 'String').matched).toBe(true);
69
+ // @ts-ignore
70
+ expect((0, check_1.check)('abc', 'FooBar').matched).toBe(true);
71
+ // @ts-ignore
72
+ expect((0, check_1.check)('abc', ' ').matched).toBe(true);
73
+ // @ts-ignore
74
+ expect((0, check_1.check)('abc', '\n').matched).toBe(true);
75
+ // @ts-ignore
76
+ expect((0, check_1.check)('abc', '').matched).toBe(true);
77
+ });
78
+ test('ItemProp', () => {
79
+ expect((0, check_1.check)('itemListElement', 'ItemProp').matched).toBe(true);
80
+ expect((0, check_1.check)('item', 'ItemProp').matched).toBe(true);
81
+ expect((0, check_1.check)('position', 'ItemProp').matched).toBe(true);
76
82
  });
package/lib/css-syntax.js CHANGED
@@ -1,19 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.cssSyntaxMatch = void 0;
4
- const tslib_1 = require("tslib");
5
- // @ts-ignore
6
- const css_tree_1 = tslib_1.__importDefault(require("css-tree"));
7
- // @ts-ignore
8
- const error_js_1 = require("css-tree/lib/lexer/error.js");
9
- // @ts-ignore
10
- const match_js_1 = require("css-tree/lib/lexer/match.js");
11
- // @ts-ignore
12
- const prepare_tokens_js_1 = tslib_1.__importDefault(require("css-tree/lib/lexer/prepare-tokens.js"));
4
+ const css_tree_1 = require("css-tree");
13
5
  const debug_1 = require("./debug");
14
6
  const defs_1 = require("./defs");
15
7
  const match_result_1 = require("./match-result");
8
+ const MIMIC_TAG_L = 'mimiccases---';
9
+ const MIMIC_TAG_R = '---mimiccases';
10
+ const MIMIC_LENGTH = (MIMIC_TAG_L + MIMIC_TAG_R).length;
16
11
  function cssSyntaxMatch(value, type) {
12
+ var _a;
17
13
  (0, debug_1.log)('Search CSS Syntax: "%s"', type);
18
14
  const origin = value;
19
15
  let defName;
@@ -29,7 +25,7 @@ function cssSyntaxMatch(value, type) {
29
25
  }
30
26
  else {
31
27
  defName = type.syntax.apply;
32
- ebnf = type.syntax.ebnf || null;
28
+ ebnf = (_a = type.syntax.ebnf) !== null && _a !== void 0 ? _a : null;
33
29
  if (ebnf) {
34
30
  // Work in progress
35
31
  return (0, match_result_1.matched)();
@@ -43,7 +39,7 @@ function cssSyntaxMatch(value, type) {
43
39
  if (typeof valueOrChecker === 'string') {
44
40
  typesExtended[key] = valueOrChecker;
45
41
  }
46
- else {
42
+ else if (valueOrChecker) {
47
43
  typesCheckers[key] = valueOrChecker;
48
44
  }
49
45
  });
@@ -57,52 +53,51 @@ function cssSyntaxMatch(value, type) {
57
53
  ref = type.ref;
58
54
  }
59
55
  // @ts-ignore
60
- const lexer = css_tree_1.default.fork({
56
+ const lexer = (0, css_tree_1.fork)({
61
57
  types: typesExtended,
62
58
  properties: propsExtended,
63
59
  }).lexer;
64
60
  Object.keys(typesCheckers).forEach(key => {
65
61
  const checker = typesCheckers[key];
66
- lexer.addType_(key, (token, getNextToken) => checker(token, getNextToken, cssSyntaxMatch));
62
+ // @ts-ignore
63
+ lexer.addType_(key, (token, getNextToken) => checker === null || checker === void 0 ? void 0 : checker(token, getNextToken, cssSyntaxMatch));
67
64
  });
68
- const { isProp, name, matcher } = defToMatcher(lexer, defName);
65
+ const { isProp, name } = detectName(defName);
66
+ // @ts-ignore
67
+ const matcher = isProp ? lexer.properties[name] : lexer.types[name];
68
+ if (!matcher) {
69
+ (0, debug_1.log)('"%s" CSS syntax not found', defName);
70
+ throw new Error('MARKUPLINT_TYPE_NO_EXIST');
71
+ }
69
72
  const refParam = isProp ? 'Property' : 'Type';
70
- ref = ref || `https://csstree.github.io/docs/syntax/#${refParam}:${name}`;
73
+ ref = ref !== null && ref !== void 0 ? ref : `https://csstree.github.io/docs/syntax/#${refParam}:${name}`;
71
74
  // eslint-disable-next-line no-console
72
75
  const _w = console.warn;
73
76
  if (debug_1.log.enabled) {
74
77
  // eslint-disable-next-line no-console
75
78
  console.warn = warn => (0, debug_1.log)('WARNING: %s (by %s => %s)', warn, value, type);
76
79
  }
77
- const tokens = (0, prepare_tokens_js_1.default)(value, lexer.syntax);
78
- const result = (0, match_js_1.matchAsTree)(tokens, matcher.match, lexer);
79
- if (caseSensitive) {
80
- if (result.tokens && Array.isArray(result.tokens)) {
81
- let reducer = 0;
82
- result.tokens = result.tokens.map((token) => {
83
- const value = token.value;
84
- const originValue = deMimicCases(value || '');
85
- const isMimiced = value !== originValue;
86
- reducer += isMimiced ? 'mimiccases------mimiccases'.length : 0;
87
- token.value = originValue;
88
- token.balance = token.balance - reducer;
89
- return token;
90
- });
91
- }
92
- }
80
+ const result = lexer.match(defName, value);
93
81
  (0, debug_1.log)('css-tree/result: %O', result);
94
82
  // eslint-disable-next-line no-console
95
83
  console.warn = _w;
96
- if (result.match) {
97
- if (debug_1.log.enabled) {
98
- (0, debug_1.log)('css-tree/result.match: %s', JSON.stringify(result.match, null, 2));
99
- }
84
+ if (!result.error) {
100
85
  return (0, match_result_1.matched)();
101
86
  }
102
- const error = new error_js_1.SyntaxMatchError(result.reason, matcher.syntax, value, result);
87
+ if (!('css' in result.error)) {
88
+ throw result.error;
89
+ }
90
+ const error = result.error;
103
91
  if (caseSensitive) {
104
- error.message = deMimicCases(error.message);
92
+ const offset = error.mismatchOffset % MIMIC_LENGTH;
93
+ const diff = error.mismatchOffset - offset;
94
+ error.message = deMimicCases(error.message).replace('-'.repeat(diff), '');
105
95
  error.syntax = deMimicCases(error.syntax);
96
+ error.css = deMimicCases(error.css);
97
+ error.mismatchOffset = offset;
98
+ error.column = error.column % MIMIC_LENGTH;
99
+ const mismatchLength = error.mismatchLength - MIMIC_LENGTH;
100
+ error.mismatchLength = mismatchLength < 0 ? error.mismatchLength : mismatchLength;
106
101
  }
107
102
  (0, debug_1.log)('css-tree/SyntaxMatchError: %O', error);
108
103
  return {
@@ -124,27 +119,34 @@ function cssSyntaxMatch(value, type) {
124
119
  };
125
120
  }
126
121
  exports.cssSyntaxMatch = cssSyntaxMatch;
127
- function defToMatcher(lexer, def) {
122
+ function detectName(def) {
128
123
  const isProp = def.search("<'") === 0;
129
124
  const name = def.replace(/^<'?|'?>$/g, '');
130
- const matcher = isProp ? lexer.properties[name] : lexer.types[name];
131
- if (!matcher) {
132
- (0, debug_1.log)('"%s" CSS syntax not found', def);
133
- throw new Error('MARKUPLINT_TYPE_NO_EXIST');
134
- }
135
125
  return {
136
126
  isProp,
137
127
  name,
138
- matcher,
139
128
  };
140
129
  }
141
- function eachMimicCases(key, obj) {
130
+ /**
131
+ *
132
+ * @param key
133
+ * @param obj
134
+ * @modifies obj
135
+ * @returns
136
+ */
137
+ function eachMimicCases(key,
138
+ // Mutable
139
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
140
+ obj) {
142
141
  const value = obj[key];
142
+ if (!value) {
143
+ return;
144
+ }
143
145
  obj[key] = mimicCases(value);
144
146
  }
145
147
  function mimicCases(value) {
146
- return value.replace(/[A-Z]/g, $0 => `mimiccases---${$0}---mimiccases`);
148
+ return value.replace(/[A-Z]/g, $0 => `${MIMIC_TAG_L}${$0}${MIMIC_TAG_R}`);
147
149
  }
148
150
  function deMimicCases(value) {
149
- return value.replace(/mimiccases---([A-Z])---mimiccases/g, (_, $1) => $1);
151
+ return value.replace(new RegExp(`${MIMIC_TAG_L}([A-Z])${MIMIC_TAG_R}`, 'g'), (_, $1) => $1);
150
152
  }