Skip to content

Commit

Permalink
feat: optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
bk1012 committed Oct 25, 2024
1 parent e972360 commit 5c631ac
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions packages/extension/src/common/vscode/ext-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,18 +1026,17 @@ export enum SyntaxTokenType {
RegEx = 3,
}
export namespace SyntaxTokenType {
export function toString(v: SyntaxTokenType | unknown): 'other' | 'comment' | 'string' | 'regex' {
switch (v) {
case SyntaxTokenType.Other:
return 'other';
case SyntaxTokenType.Comment:
return 'comment';
case SyntaxTokenType.String:
return 'string';
case SyntaxTokenType.RegEx:
return 'regex';
}
return 'other';
type returnType = 'other' | 'comment' | 'string' | 'regex';

const tokenTypeMap: Record<SyntaxTokenType, returnType> = {
[SyntaxTokenType.Other]: 'other',
[SyntaxTokenType.Comment]: 'comment',
[SyntaxTokenType.String]: 'string',
[SyntaxTokenType.RegEx]: 'regex',
};

export function toString(v: SyntaxTokenType | unknown): returnType {
return tokenTypeMap[v as SyntaxTokenType] || 'other';
}
}

Expand Down

0 comments on commit 5c631ac

Please sign in to comment.