This repository has been archived by the owner on Feb 7, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: cleanup unused attribute in themes and langs
- Loading branch information
Showing
8 changed files
with
179 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import type { LanguageRegistration, ThemeRegistration } from 'shikiji-core' | ||
|
||
export function objectPick<T extends Record<any, any>>( | ||
obj: T, | ||
keys: (keyof T)[], | ||
onRemoval?: (obj: T, key: string, value: any) => void, | ||
): T { | ||
return Object.fromEntries( | ||
Array.from( | ||
Object.entries(obj) | ||
.filter((i) => { | ||
if (keys.includes(i[0])) | ||
return true | ||
onRemoval?.(obj, ...i) | ||
return false | ||
}), | ||
), | ||
) as T | ||
} | ||
|
||
export function cleanupLanguageReg(lang: LanguageRegistration) { | ||
return objectPick( | ||
lang, | ||
[ | ||
'aliases', | ||
'balancedBracketSelectors', | ||
'displayName', | ||
'embeddedLangs', | ||
'fileTypes', | ||
'firstLineMatch', | ||
'injections', | ||
'injectionSelector', | ||
'injectTo', | ||
'name', | ||
'patterns', | ||
'repository', | ||
'scopeName', | ||
'foldingStopMarker', | ||
'foldingStartMarker', | ||
'unbalancedBracketSelectors', | ||
], | ||
// (_, key, value) => console.log('lang key removal', key, '|', value), | ||
) | ||
} | ||
|
||
export function cleanupThemeReg(theme: ThemeRegistration) { | ||
return objectPick( | ||
theme, | ||
[ | ||
'name', | ||
'type', | ||
'colors', | ||
'fg', | ||
'bg', | ||
'include', | ||
'settings', | ||
|
||
'tokenColors', | ||
'semanticHighlighting', | ||
'semanticTokenColors', | ||
], | ||
// (_, key, value) => console.log('theme key removal', key, value), | ||
) | ||
} |
Oops, something went wrong.