Skip to content

Commit

Permalink
Refactor some types
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Mar 22, 2023
1 parent 2b7359c commit e72a129
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
* > To solve this, you could for example use an npm script called `dependencies`
* > (which runs everytime `node_modules` is changed) which copies
* > `vscode-oniguruma/release/onig.wasm` to the place you want to host it.
* @returns {URL|Promise<URL>}
* @returns {URL | Promise<URL>}
* URL object to a WASM binary.
*/

Expand Down Expand Up @@ -111,7 +111,7 @@ export async function createStarryNight(grammars, options) {
* @param {string} flag
* Grammar name (such as `'markdown'` or `'pandoc'`) or grammar extension
* (such as `'.md'` or `'.rmd'`).
* @returns {string|undefined}
* @returns {string | undefined}
* Grammar scope (such as `'source.gfm'`).
*/
function flagToScope(flag) {
Expand Down Expand Up @@ -183,7 +183,7 @@ export async function createStarryNight(grammars, options) {

/**
* @param {Array<Grammar>} grammars
* @param {Options} [options]
* @param {Options | undefined} [options]
*/
async function createRegistry(grammars, options) {
for (const grammar of grammars) {
Expand Down Expand Up @@ -223,7 +223,7 @@ export async function createStarryNight(grammars, options) {
* Idea: as this seems to be a singleton, would it help if we call it once and
* keep the promise?
*
* @param {Options} [options]
* @param {Options | undefined} [options]
*/
async function createOniguruma(options) {
const wasmBin = await getOniguruma(options)
Expand Down
14 changes: 7 additions & 7 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function parse(value, grammar, colors) {
const bg = (metadata & BACKGROUND_MASK) >>> BACKGROUND_OFFSET
const fs = (metadata & FONT_STYLE_MASK) >>> FONT_STYLE_OFFSET

/** @type {Root|Element} */
/** @type {Root | Element} */
let scope = tree
scope = delveIfClassName(scope, fontStyleToClass(fs))
scope = delveIfClassName(scope, colorToClass(colors[bg]))
Expand All @@ -77,9 +77,9 @@ export function parse(value, grammar, colors) {
}

/**
* @param {Root|Element} scope
* @param {string|undefined} className
* @returns {Root|Element}
* @param {Root | Element} scope
* @param {string | undefined} className
* @returns {Root | Element}
*/
function delveIfClassName(scope, className) {
if (!className) return scope
Expand All @@ -106,7 +106,7 @@ function delveIfClassName(scope, className) {
}

/**
* @param {Root|Element} scope
* @param {Root | Element} scope
* @param {string} value
*/
function appendText(scope, value) {
Expand All @@ -124,15 +124,15 @@ function appendText(scope, value) {
* Note: there’s only one grandparent.
* We could encode more grandparents in `fontStyle` if needed.
* @param {number} fontStyle
* @returns {string|undefined}
* @returns {string | undefined}
*/
function fontStyleToClass(fontStyle) {
return fontStyle ? grandparents[0] : undefined
}

/**
* @param {string} color
* @returns {string|undefined}
* @returns {string | undefined}
*/
function colorToClass(color) {
if (color === transparent) return undefined
Expand Down

0 comments on commit e72a129

Please sign in to comment.