Skip to content

Commit 018b30c

Browse files
committed
Replace some dev-dependencies
1 parent 235164a commit 018b30c

File tree

5 files changed

+75
-50
lines changed

5 files changed

+75
-50
lines changed

lib/core.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @typedef {import('hast').ElementContent} ElementContent
44
* @typedef {import('hast').Root} Root
55
* @typedef {import('hast').RootData} RootData
6-
* @typedef {import('hast').Text} Text
76
* @typedef {import('highlight.js').HighlightResult} HighlightResult
87
* @typedef {import('highlight.js').HLJSOptions} HighlightOptions
98
* @typedef {import('highlight.js').LanguageFn} HighlightSyntax
@@ -22,7 +21,6 @@
2221
*/
2322

2423
import highlightCore from 'highlight.js/lib/core'
25-
import {fault} from 'fault'
2624

2725
// Create an own instance to not be in conflict with the global object
2826
const high = highlightCore.newInstance()
@@ -47,15 +45,17 @@ function highlight(language, value, options = {}) {
4745
let prefix = options.prefix
4846

4947
if (typeof language !== 'string') {
50-
throw fault('Expected `string` for name, got `%s`', language)
48+
// eslint-disable-next-line unicorn/prefer-type-error
49+
throw new Error('Expected `string` for name, got `' + language + '`')
5150
}
5251

5352
if (!high.getLanguage(language)) {
54-
throw fault('Unknown language: `%s` is not registered', language)
53+
throw new Error('Unknown language: `' + language + '` is not registered')
5554
}
5655

5756
if (typeof value !== 'string') {
58-
throw fault('Expected `string` for value, got `%s`', value)
57+
// eslint-disable-next-line unicorn/prefer-type-error
58+
throw new Error('Expected `string` for value, got `' + value + '`')
5959
}
6060

6161
if (prefix === null || prefix === undefined) {
@@ -114,7 +114,8 @@ function highlightAuto(value, options = {}) {
114114
}
115115

116116
if (typeof value !== 'string') {
117-
throw fault('Expected `string` for value, got `%s`', value)
117+
// eslint-disable-next-line unicorn/prefer-type-error
118+
throw new Error('Expected `string` for value, got `' + value + '`')
118119
}
119120

120121
while (++index < subset.length) {

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
],
4040
"dependencies": {
4141
"@types/hast": "^3.0.0",
42-
"fault": "^2.0.0",
4342
"highlight.js": "~11.8.0"
4443
},
4544
"devDependencies": {
@@ -49,15 +48,15 @@
4948
"c8": "^8.0.0",
5049
"chalk": "^5.0.0",
5150
"estree-util-is-identifier-name": "^3.0.0",
51+
"hast-util-from-html": "^2.0.0",
52+
"hast-util-to-html": "^9.0.0",
5253
"mdast-zone": "^6.0.0",
5354
"prettier": "^3.0.0",
54-
"rehype": "^13.0.0",
5555
"remark-cli": "^11.0.0",
5656
"remark-preset-wooorm": "^9.0.0",
5757
"type-coverage": "^2.0.0",
5858
"typescript": "^5.0.0",
59-
"unified": "^11.0.2",
60-
"unist-builder": "^4.0.0",
59+
"unified": "^11.0.0",
6160
"unist-util-remove-position": "^5.0.0",
6261
"xo": "^0.56.0"
6362
},

script/count.js

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import fs from 'node:fs/promises'
77
import {zone} from 'mdast-zone'
8-
import {u} from 'unist-builder'
98

109
/** @type {{common: Array<string>, uncommon: Array<string>}} */
1110
const data = JSON.parse(
@@ -18,26 +17,55 @@ export default function count() {
1817
zone(tree, 'index', (start, _, end) => {
1918
const {common, uncommon} = data
2019
/** @type {List} */
21-
const list = u('list', {spread: false}, [
22-
u('listItem', [
23-
u('paragraph', [
24-
u('inlineCode', 'lib/core.js'),
25-
u('text', ' — 0 languages')
26-
])
27-
]),
28-
u('listItem', [
29-
u('paragraph', [
30-
u('inlineCode', 'lib/common.js'),
31-
u('text', ' (default) — ' + common.length + ' languages')
32-
])
33-
]),
34-
u('listItem', [
35-
u('paragraph', [
36-
u('inlineCode', 'lib/all.js'),
37-
u('text', ' — ' + (common.length + uncommon.length) + ' languages')
38-
])
39-
])
40-
])
20+
const list = {
21+
type: 'list',
22+
spread: false,
23+
children: [
24+
{
25+
type: 'listItem',
26+
children: [
27+
{
28+
type: 'paragraph',
29+
children: [
30+
{type: 'inlineCode', value: 'lib/core.js'},
31+
{type: 'text', value: ' — 0 languages'}
32+
]
33+
}
34+
]
35+
},
36+
{
37+
type: 'listItem',
38+
children: [
39+
{
40+
type: 'paragraph',
41+
children: [
42+
{type: 'inlineCode', value: 'lib/common.js'},
43+
{
44+
type: 'text',
45+
value: ' (default) — ' + common.length + ' languages'
46+
}
47+
]
48+
}
49+
]
50+
},
51+
{
52+
type: 'listItem',
53+
children: [
54+
{
55+
type: 'paragraph',
56+
children: [
57+
{type: 'inlineCode', value: 'lib/all.js'},
58+
{
59+
type: 'text',
60+
value:
61+
' — ' + (common.length + uncommon.length) + ' languages'
62+
}
63+
]
64+
}
65+
]
66+
}
67+
]
68+
}
4169

4270
return [start, list, end]
4371
})

script/support.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import fs from 'node:fs/promises'
99
import hljs from 'highlight.js'
1010
import {zone} from 'mdast-zone'
11-
import {u} from 'unist-builder'
1211

1312
/** @type {{common: Array<string>, uncommon: Array<string>}} */
1413
const data = JSON.parse(
@@ -28,7 +27,7 @@ export default function support() {
2827

2928
zone(tree, 'support', (start, _, end) => [
3029
start,
31-
u('list', {spread: false}, items),
30+
{type: 'list', spread: false, children: items},
3231
end
3332
])
3433
}
@@ -45,23 +44,25 @@ async function item(name) {
4544
const fn = mod.default
4645
const language = fn(hljs)
4746
/** @type {Array<PhrasingContent>} */
48-
const content = [u('inlineCode', name)]
47+
const content = [{type: 'inlineCode', value: name}]
4948
let index = -1
5049

5150
if (language.aliases) {
52-
content.push(u('text', ' ('))
51+
content.push({type: 'text', value: ' ('})
5352

5453
while (++index < language.aliases.length) {
55-
if (index) content.push(u('text', ', '))
56-
content.push(u('inlineCode', language.aliases[index]))
54+
if (index) content.push({type: 'text', value: ', '})
55+
content.push({type: 'inlineCode', value: language.aliases[index]})
5756
}
5857

59-
content.push(u('text', ')'))
58+
content.push({type: 'text', value: ')'})
6059
}
6160

62-
content.push(u('text', ' — ' + language.name))
61+
content.push({type: 'text', value: ' — ' + language.name})
6362

64-
return u('listItem', {checked: data.common.includes(name)}, [
65-
u('paragraph', content)
66-
])
63+
return {
64+
type: 'listItem',
65+
checked: data.common.includes(name),
66+
children: [{type: 'paragraph', children: content}]
67+
}
6768
}

test/index.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import coffeescript from 'highlight.js/lib/languages/coffeescript'
1111
import haskell from 'highlight.js/lib/languages/haskell'
1212
import http from 'highlight.js/lib/languages/http'
1313
import pgsql from 'highlight.js/lib/languages/pgsql'
14-
import {rehype} from 'rehype'
14+
import {fromHtml} from 'hast-util-from-html'
15+
import {toHtml} from 'hast-util-to-html'
1516
import {removePosition} from 'unist-util-remove-position'
1617
import {lowlight} from '../index.js'
1718

@@ -411,17 +412,12 @@ async function subtest(directory, transform) {
411412
out = String(await fs.readFile(output))
412413
} catch {
413414
out =
414-
rehype()
415-
.data('settings', {
416-
characterReferences: {useNamedReferences: true},
417-
fragment: true
418-
})
419-
.stringify(actual) + '\n'
415+
toHtml(actual, {characterReferences: {useNamedReferences: true}}) + '\n'
420416

421417
await fs.writeFile(output, out)
422418
}
423419

424-
const expected = rehype().data('settings', {fragment: true}).parse(out.trim())
420+
const expected = fromHtml(out.trim(), {fragment: true})
425421

426422
removePosition(expected, {force: true})
427423

0 commit comments

Comments
 (0)