Skip to content

Commit fd07510

Browse files
committed
Refactor to simplify some internal code
1 parent d13f7ad commit fd07510

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

lib/core.js

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Attributes.
2424
* @property {Array<string>} classes
2525
* Classes.
26-
* @property {Array<RefractorElement | Text> | RefractorElement | Text} content
26+
* @property {Array<Element | Text> | Element | Text} content
2727
* Content.
2828
* @property {string} language
2929
* Language.
@@ -33,16 +33,6 @@
3333
* Type.
3434
*/
3535

36-
/**
37-
* @typedef {Omit<Element, 'children'> & {children: Array<RefractorElement | Text>}} RefractorElement
38-
* Element; narrowed down to what’s used here.
39-
*/
40-
41-
/**
42-
* @typedef {Omit<Root, 'children'> & {children: Array<RefractorElement | Text>}} RefractorRoot
43-
* Root; narrowed down to what’s used here.
44-
*/
45-
4636
/**
4737
* @typedef {((prism: Refractor) => undefined | void) & {aliases?: Array<string> | undefined, displayName: string}} Syntax
4838
* Refractor syntax function.
@@ -96,7 +86,7 @@ refractor.Token.stringify = stringify
9686
* Code to highlight.
9787
* @param {Grammar | string} language
9888
* Programming language name, alias, or grammar.
99-
* @returns {RefractorRoot}
89+
* @returns {Root}
10090
* Node representing highlighted code.
10191
*/
10292
function highlight(value, language) {
@@ -242,7 +232,7 @@ function listLanguages() {
242232
* Token to stringify.
243233
* @param {string} language
244234
* Language of the token.
245-
* @returns {Array<RefractorElement | Text> | RefractorElement | Text}
235+
* @returns {Array<Element | Text> | Element | Text}
246236
* Node representing the token.
247237
*/
248238
function stringify(value, language) {
@@ -251,7 +241,7 @@ function stringify(value, language) {
251241
}
252242

253243
if (Array.isArray(value)) {
254-
/** @type {Array<RefractorElement | Text>} */
244+
/** @type {Array<Element | Text>} */
255245
const result = []
256246
let index = -1
257247

@@ -261,8 +251,10 @@ function stringify(value, language) {
261251
value[index] !== undefined &&
262252
value[index] !== ''
263253
) {
264-
// @ts-expect-error Assume no sub-arrays.
265-
result.push(stringify(value[index], language))
254+
// Cast because we assume no sub-arrays.
255+
result.push(
256+
/** @type {Element | Text} */ (stringify(value[index], language))
257+
)
266258
}
267259
}
268260

@@ -288,7 +280,6 @@ function stringify(value, language) {
288280
// @ts-expect-error Prism.
289281
refractor.hooks.run('wrap', env)
290282

291-
// @ts-expect-error Hush, it’s fine.
292283
return h(
293284
env.tag + '.' + env.classes.join('.'),
294285
attributes(env.attributes),

0 commit comments

Comments
 (0)