Skip to content

Commit 79822f7

Browse files
committed
fix typescript issues #46
1 parent c0aee08 commit 79822f7

26 files changed

+187
-37
lines changed

src/@types/validation.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {ValidationLevel, ValidationSyntaxGroupEnum} from "../lib";
22
import {AstNode} from "./ast.d.ts";
33
import {Token} from "./token.d.ts";
4+
import type {ValidationToken} from "../lib/validation/parser";
45

56
export declare interface ValidationSyntaxNode {
67

@@ -26,13 +27,13 @@ export interface ValidationResult {
2627

2728
valid: ValidationLevel;
2829
node: AstNode | Token | null;
29-
syntax: ValidationToken | null;
30+
syntax: ValidationToken | string | null;
3031
error: string;
3132
}
3233

3334
export interface ValidationSyntaxResult extends ValidationResult {
3435

35-
syntax: ValidationToken;
36+
syntax: ValidationToken | string | null;
3637
tokens: Token[] | AstNode[];
3738
matches: Token[] | AstNode[];
3839
}

src/@types/walker.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {AstNode, AstRuleList} from "./ast.d.ts";
22
import {BinaryExpressionToken, FunctionToken, ParensToken, Token} from "./token.d.ts";
3+
import {WalkerValueEvent} from '../lib/ast/walk';
34

45
export declare type WalkerOption = 'ignore' | 'stop' | 'children' | 'ignore-children' | Token | null;
56
/**

src/lib/ast/features/calc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export class ComputeCalcExpressionFeature {
7878
return null;
7979
}
8080

81+
// @ts-ignore
8182
const slice: Token[] = (node.typ == EnumToken.FunctionTokenType ? (node as FunctionToken).chi : (node.typ == EnumToken.DeclarationNodeType ? (<AstDeclaration>node).val : (node as FunctionToken).chi))?.slice();
8283

8384
if (slice != null && node.typ == EnumToken.FunctionTokenType && mathFuncs.includes((node as FunctionToken).val)) {

src/lib/parser/parse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ import type {
101101
} from "../../@types";
102102
import {deprecatedSystemColors, systemColors} from "../renderer/color/utils";
103103
import {validateAtRule, validateSelector} from "../validation";
104-
import {ValidationResult} from "../../@types/validation";
104+
import type {ValidationResult} from "../../@types/validation.d.ts";
105105

106106
export const urlTokenMatcher: RegExp = /^(["']?)[a-zA-Z0-9_/.-][a-zA-Z0-9_/:.#?-]+(\1)$/;
107107
const trimWhiteSpace: EnumToken[] = [EnumToken.CommentTokenType, EnumToken.GtTokenType, EnumToken.GteTokenType, EnumToken.LtTokenType, EnumToken.LteTokenType, EnumToken.ColumnCombinatorTokenType];

src/lib/validation/at-rules/counter-style.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import type {AstAtRule, AstNode, Token, ValidationOptions} from "../../../@types";
2-
import {ValidationSyntaxResult} from "../../../@types/validation";
2+
import type {ValidationSyntaxResult} from "../../../@types/validation.d.ts";
33
import {EnumToken, ValidationLevel} from "../../ast";
44

55
export function validateAtRuleCounterStyle(atRule: AstAtRule, options: ValidationOptions, root?: AstNode): ValidationSyntaxResult {
66

77
// media-query-list
88
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
99

10+
// @ts-ignore
1011
return {
1112
valid: ValidationLevel.Drop,
1213
matches: [],
@@ -17,10 +18,11 @@ export function validateAtRuleCounterStyle(atRule: AstAtRule, options: Validatio
1718
} as ValidationSyntaxResult;
1819
}
1920

20-
const tokens: Token[] = atRule.tokens.filter((t: Token):boolean => ![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType].includes(t.typ));
21+
const tokens: Token[] = atRule.tokens.filter((t: Token): boolean => ![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType].includes(t.typ));
2122

2223
if (tokens.length == 0) {
2324

25+
// @ts-ignore
2426
return {
2527
valid: ValidationLevel.Valid,
2628
matches: [],
@@ -33,6 +35,7 @@ export function validateAtRuleCounterStyle(atRule: AstAtRule, options: Validatio
3335

3436
if (tokens.length > 1) {
3537

38+
// @ts-ignore
3639
return {
3740
valid: ValidationLevel.Drop,
3841
matches: [],
@@ -45,6 +48,7 @@ export function validateAtRuleCounterStyle(atRule: AstAtRule, options: Validatio
4548

4649
if (![EnumToken.IdenTokenType, EnumToken.DashedIdenTokenType].includes(tokens[0].typ)) {
4750

51+
// @ts-ignore
4852
return {
4953
valid: ValidationLevel.Drop,
5054
matches: [],
@@ -57,6 +61,7 @@ export function validateAtRuleCounterStyle(atRule: AstAtRule, options: Validatio
5761

5862
if (!('chi' in atRule)) {
5963

64+
// @ts-ignore
6065
return {
6166
valid: ValidationLevel.Drop,
6267
matches: [],
@@ -67,6 +72,7 @@ export function validateAtRuleCounterStyle(atRule: AstAtRule, options: Validatio
6772
} as ValidationSyntaxResult;
6873
}
6974

75+
// @ts-ignore
7076
return {
7177
valid: ValidationLevel.Valid,
7278
matches: [],

src/lib/validation/at-rules/document.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {AstAtRule, AstNode, FunctionToken, Token, ValidationOptions} from "../../../@types";
2-
import {ValidationSyntaxResult} from "../../../@types/validation";
2+
import type {ValidationSyntaxResult} from "../../../@types/validation.d.ts";
33
import {EnumToken, ValidationLevel} from "../../ast";
44
import {consumeWhitespace} from "../utils";
55
import {validateURL} from "../syntaxes/url";
@@ -9,6 +9,7 @@ export function validateAtRuleDocument(atRule: AstAtRule, options: ValidationOpt
99

1010
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
1111

12+
// @ts-ignore
1213
return {
1314
valid: ValidationLevel.Drop,
1415
matches: [],
@@ -26,6 +27,7 @@ export function validateAtRuleDocument(atRule: AstAtRule, options: ValidationOpt
2627

2728
if (tokens.length == 0) {
2829

30+
// @ts-ignore
2931
return {
3032
valid: ValidationLevel.Drop,
3133
matches: [],
@@ -38,6 +40,7 @@ export function validateAtRuleDocument(atRule: AstAtRule, options: ValidationOpt
3840

3941
if (tokens[0].typ == EnumToken.CommaTokenType) {
4042

43+
// @ts-ignore
4144
return {
4245
valid: ValidationLevel.Drop,
4346
matches: [],
@@ -69,6 +72,7 @@ export function validateAtRuleDocument(atRule: AstAtRule, options: ValidationOpt
6972

7073
if (!['url-prefix', 'domain', 'media-document', 'regexp'].some((t) => t.localeCompare((tokens[0] as FunctionToken).val, undefined, {sensitivity: 'base'}) == 0)) {
7174

75+
// @ts-ignore
7276
return {
7377
valid: ValidationLevel.Drop,
7478
matches: [],
@@ -85,6 +89,7 @@ export function validateAtRuleDocument(atRule: AstAtRule, options: ValidationOpt
8589

8690
if (children.length == 0) {
8791

92+
// @ts-ignore
8893
return {
8994
valid: ValidationLevel.Drop,
9095
matches: [],
@@ -103,6 +108,7 @@ export function validateAtRuleDocument(atRule: AstAtRule, options: ValidationOpt
103108

104109
if (children.length > 0) {
105110

111+
// @ts-ignore
106112
return {
107113
valid: ValidationLevel.Drop,
108114
matches: [],
@@ -118,6 +124,7 @@ export function validateAtRuleDocument(atRule: AstAtRule, options: ValidationOpt
118124
}
119125
}
120126

127+
// @ts-ignore
121128
return {
122129
valid: ValidationLevel.Valid,
123130
matches: [],

src/lib/validation/at-rules/font-feature-values.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {AstAtRule, AstNode, ValidationOptions} from "../../../@types";
2-
import {ValidationSyntaxResult} from "../../../@types/validation";
2+
import type {ValidationSyntaxResult} from "../../../@types/validation.d.ts";
33
import {ValidationLevel} from "../../ast";
44
import {validateFamilyName} from "../syntaxes";
55

@@ -8,6 +8,7 @@ export function validateAtRuleFontFeatureValues(atRule: AstAtRule, options: Vali
88

99
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
1010

11+
// @ts-ignore
1112
return {
1213
valid: ValidationLevel.Drop,
1314
matches: [],
@@ -27,6 +28,7 @@ export function validateAtRuleFontFeatureValues(atRule: AstAtRule, options: Vali
2728

2829
if (!('chi' in atRule)) {
2930

31+
// @ts-ignore
3032
return {
3133
valid: ValidationLevel.Drop,
3234
matches: [],
@@ -37,6 +39,7 @@ export function validateAtRuleFontFeatureValues(atRule: AstAtRule, options: Vali
3739
} as ValidationSyntaxResult;
3840
}
3941

42+
// @ts-ignore
4043
return {
4144
valid: ValidationLevel.Valid,
4245
matches: [],

src/lib/validation/at-rules/import.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {AstAtRule, AstNode, Token, ValidationOptions} from "../../../@types";
2-
import {ValidationSyntaxResult} from "../../../@types/validation";
2+
import type {ValidationSyntaxResult} from "../../../@types/validation.d.ts";
33
import {EnumToken, ValidationLevel} from "../../ast";
44
import {validateAtRuleSupports} from "./supports";
55
import {validateAtRuleMediaQueryList} from "./media";
@@ -10,6 +10,7 @@ export function validateAtRuleImport(atRule: AstAtRule, options: ValidationOptio
1010

1111
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
1212

13+
// @ts-ignore
1314
return {
1415
valid: ValidationLevel.Drop,
1516
matches: [],
@@ -22,6 +23,7 @@ export function validateAtRuleImport(atRule: AstAtRule, options: ValidationOptio
2223

2324
if ('chi' in atRule) {
2425

26+
// @ts-ignore
2527
return {
2628
valid: ValidationLevel.Drop,
2729
matches: [],
@@ -36,6 +38,7 @@ export function validateAtRuleImport(atRule: AstAtRule, options: ValidationOptio
3638

3739
if (tokens.length == 0) {
3840

41+
// @ts-ignore
3942
return {
4043
valid: ValidationLevel.Drop,
4144
matches: [],
@@ -57,6 +60,7 @@ export function validateAtRuleImport(atRule: AstAtRule, options: ValidationOptio
5760

5861
if (slice.length != 1 || ![EnumToken.StringTokenType, EnumToken.UrlTokenTokenType].includes(slice[0].typ)) {
5962

63+
// @ts-ignore
6064
return {
6165
valid: ValidationLevel.Drop,
6266
matches: [],
@@ -71,6 +75,7 @@ export function validateAtRuleImport(atRule: AstAtRule, options: ValidationOptio
7175
// @ts-ignore
7276
if (!consumeWhitespace(tokens)) {
7377

78+
// @ts-ignore
7479
return {
7580
valid: ValidationLevel.Drop,
7681
matches: [],
@@ -83,6 +88,7 @@ export function validateAtRuleImport(atRule: AstAtRule, options: ValidationOptio
8388
}
8489
} else {
8590

91+
// @ts-ignore
8692
return {
8793
valid: ValidationLevel.Drop,
8894
matches: [],
@@ -106,6 +112,7 @@ export function validateAtRuleImport(atRule: AstAtRule, options: ValidationOptio
106112
// @ts-ignore
107113
if (!consumeWhitespace(tokens)) {
108114

115+
// @ts-ignore
109116
return {
110117
valid: ValidationLevel.Drop,
111118
matches: [],
@@ -124,6 +131,7 @@ export function validateAtRuleImport(atRule: AstAtRule, options: ValidationOptio
124131
// @ts-ignore
125132
if ('layer'.localeCompare(tokens[0].val, undefined, {sensitivity: 'base'}) != 0) {
126133

134+
// @ts-ignore
127135
return {
128136
valid: ValidationLevel.Drop,
129137
matches: [],
@@ -147,6 +155,7 @@ export function validateAtRuleImport(atRule: AstAtRule, options: ValidationOptio
147155
// @ts-ignore
148156
if (!consumeWhitespace(tokens)) {
149157

158+
// @ts-ignore
150159
return {
151160
valid: ValidationLevel.Drop,
152161
matches: [],
@@ -166,6 +175,7 @@ export function validateAtRuleImport(atRule: AstAtRule, options: ValidationOptio
166175

167176
if ((tokens[0] as AstAtRule).nam != 'supports') {
168177

178+
// @ts-ignore
169179
return {
170180
valid: ValidationLevel.Drop,
171181
matches: [],
@@ -189,6 +199,7 @@ export function validateAtRuleImport(atRule: AstAtRule, options: ValidationOptio
189199
// @ts-ignore
190200
if (!consumeWhitespace(tokens)) {
191201

202+
// @ts-ignore
192203
return {
193204
valid: ValidationLevel.Drop,
194205
matches: [],
@@ -206,6 +217,7 @@ export function validateAtRuleImport(atRule: AstAtRule, options: ValidationOptio
206217
return validateAtRuleMediaQueryList(tokens, atRule);
207218
}
208219

220+
// @ts-ignore
209221
return {
210222
valid: ValidationLevel.Valid,
211223
matches: [],

src/lib/validation/at-rules/keyframes.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import type {AstAtRule, AstNode, Token, ValidationOptions} from "../../../@types";
2-
import {ValidationSyntaxResult} from "../../../@types/validation";
2+
import type {ValidationSyntaxResult} from "../../../@types/validation.d.ts";
33
import {EnumToken, ValidationLevel} from "../../ast";
44
import {consumeWhitespace} from "../utils";
55

66
export function validateAtRuleKeyframes(atRule: AstAtRule, options: ValidationOptions, root?: AstNode): ValidationSyntaxResult {
77

88
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
99

10+
// @ts-ignore
1011
return {
1112
valid: ValidationLevel.Drop,
1213
matches: [],
@@ -23,6 +24,7 @@ export function validateAtRuleKeyframes(atRule: AstAtRule, options: ValidationOp
2324

2425
if (tokens.length == 0) {
2526

27+
// @ts-ignore
2628
return {
2729
valid: ValidationLevel.Drop,
2830
matches: [],
@@ -35,6 +37,7 @@ export function validateAtRuleKeyframes(atRule: AstAtRule, options: ValidationOp
3537

3638
if (![EnumToken.StringTokenType, EnumToken.IdenTokenType].includes(tokens[0].typ)) {
3739

40+
// @ts-ignore
3841
return {
3942
valid: ValidationLevel.Drop,
4043
matches: [],
@@ -50,6 +53,7 @@ export function validateAtRuleKeyframes(atRule: AstAtRule, options: ValidationOp
5053

5154
if (tokens.length > 0) {
5255

56+
// @ts-ignore
5357
return {
5458
valid: ValidationLevel.Drop,
5559
matches: [],
@@ -60,6 +64,7 @@ export function validateAtRuleKeyframes(atRule: AstAtRule, options: ValidationOp
6064
}
6165
}
6266

67+
// @ts-ignore
6368
return {
6469
valid: ValidationLevel.Valid,
6570
matches: [],

src/lib/validation/at-rules/layer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {AstAtRule, AstNode, ValidationOptions} from "../../../@types";
2-
import {ValidationSyntaxResult} from "../../../@types/validation";
2+
import type {ValidationSyntaxResult} from "../../../@types/validation.d.ts";
33
import {ValidationLevel} from "../../ast";
44
import {validateLayerName} from "../syntaxes";
55

@@ -9,6 +9,7 @@ export function validateAtRuleLayer(atRule: AstAtRule, options: ValidationOption
99
// media-query-list
1010
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
1111

12+
// @ts-ignore
1213
return {
1314
valid: ValidationLevel.Valid,
1415
matches: [],

0 commit comments

Comments
 (0)