Skip to content

Commit 9aaa1d4

Browse files
committed
Update @types/hast, @types/nlcst, utilities
1 parent bc67eea commit 9aaa1d4

File tree

2 files changed

+42
-34
lines changed

2 files changed

+42
-34
lines changed

Diff for: lib/index.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export function toNlcst(tree, file, Parser) {
152152
throw new Error('hast-util-to-nlcst expected parser')
153153
}
154154

155-
if (!pointStart(tree).line || !pointStart(tree).column) {
155+
if (!pointStart(tree)) {
156156
throw new Error('hast-util-to-nlcst expected position on nodes')
157157
}
158158

@@ -164,10 +164,14 @@ export function toNlcst(tree, file, Parser) {
164164

165165
find(tree)
166166

167+
const start = loc.toPoint(0)
168+
const end = loc.toPoint(doc.length)
169+
167170
return {
168171
type: 'RootNode',
169172
children: results,
170-
position: {start: loc.toPoint(0), end: loc.toPoint(doc.length)}
173+
/* c8 ignore next - prevent crashes if some nodes don’t have positional info */
174+
position: start && end ? {start, end} : undefined
171175
}
172176

173177
/**
@@ -354,6 +358,7 @@ export function toNlcst(tree, file, Parser) {
354358
replacement = [{type: 'WhiteSpaceNode', value: '\n'}]
355359
change = true
356360
} else if (source(node)) {
361+
// @ts-expect-error: remove when `to-string` is updated.
357362
replacement = [{type: 'SourceNode', value: toString(node)}]
358363
change = true
359364
} else {
@@ -403,30 +408,30 @@ export function toNlcst(tree, file, Parser) {
403408
* Nodes to patch.
404409
* @param {ReturnType<location>} location
405410
* Location info.
406-
* @param {number} offset
411+
* @param {number | undefined} offset
407412
* Current offset.
408413
* @returns {void}
409414
* Nothing.
410415
*/
411416
function patch(nodes, location, offset) {
412417
let index = -1
413-
let start = offset
418+
let from = offset
414419

415-
while (++index < nodes.length) {
420+
while (from !== undefined && ++index < nodes.length) {
416421
const node = nodes[index]
417422

418423
if ('children' in node) {
419-
patch(node.children, location, start)
424+
patch(node.children, location, from)
420425
}
421426

422-
const end = start + nlcstToString(node).length
427+
const to = from + nlcstToString(node).length
428+
const start = location.toPoint(from)
429+
const end = location.toPoint(to)
423430

424-
node.position = {
425-
start: location.toPoint(start),
426-
end: location.toPoint(end)
427-
}
431+
/* c8 ignore next - prevent crashes if some nodes don’t have positional info */
432+
node.position = start && end ? {start, end} : undefined
428433

429-
start = end
434+
from = to
430435
}
431436
}
432437
}

Diff for: package.json

+25-22
Original file line numberDiff line numberDiff line change
@@ -36,38 +36,38 @@
3636
"index.js"
3737
],
3838
"dependencies": {
39-
"@types/hast": "^2.0.0",
40-
"@types/nlcst": "^1.0.0",
41-
"@types/unist": "^2.0.0",
42-
"hast-util-embedded": "^2.0.0",
43-
"hast-util-is-element": "^2.0.0",
44-
"hast-util-phrasing": "^2.0.0",
39+
"@types/hast": "^3.0.0",
40+
"@types/nlcst": "^2.0.0",
41+
"@types/unist": "^3.0.0",
42+
"hast-util-embedded": "^3.0.0",
43+
"hast-util-is-element": "^3.0.0",
44+
"hast-util-phrasing": "^3.0.0",
4545
"hast-util-to-string": "^2.0.0",
46-
"hast-util-whitespace": "^2.0.0",
47-
"nlcst-to-string": "^3.0.0",
48-
"unist-util-position": "^4.0.0",
49-
"vfile": "^5.0.0",
50-
"vfile-location": "^4.0.0"
46+
"hast-util-whitespace": "^3.0.0",
47+
"nlcst-to-string": "^4.0.0",
48+
"unist-util-position": "^5.0.0",
49+
"vfile": "^6.0.0",
50+
"vfile-location": "^5.0.0"
5151
},
5252
"devDependencies": {
53-
"@types/node": "^18.0.0",
54-
"c8": "^7.0.0",
55-
"hast-util-from-html": "^1.0.0",
53+
"@types/node": "^20.0.0",
54+
"c8": "^8.0.0",
55+
"hast-util-from-html": "^2.0.0",
5656
"is-hidden": "^2.0.0",
57-
"parse-dutch": "^6.0.0",
58-
"parse-english": "^6.0.0",
59-
"parse-latin": "^6.0.0",
60-
"prettier": "^2.0.0",
57+
"parse-dutch": "^7.0.0",
58+
"parse-english": "^7.0.0",
59+
"parse-latin": "^7.0.0",
60+
"prettier": "^3.0.0",
6161
"remark-cli": "^11.0.0",
6262
"remark-preset-wooorm": "^9.0.0",
6363
"type-coverage": "^2.0.0",
64-
"typescript": "^4.0.0",
65-
"xo": "^0.53.0"
64+
"typescript": "^5.0.0",
65+
"xo": "^0.55.0"
6666
},
6767
"scripts": {
6868
"prepack": "npm run build && npm run format",
6969
"build": "tsc --build --clean && tsc --build && type-coverage",
70-
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
70+
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
7171
"test-api": "node --conditions development test/index.js",
7272
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
7373
"test": "npm run build && npm run format && npm run test-coverage"
@@ -89,7 +89,10 @@
8989
"no-await-in-loop": 0
9090
}
9191
}
92-
]
92+
],
93+
"rules": {
94+
"unicorn/prefer-at": "off"
95+
}
9396
},
9497
"remarkConfig": {
9598
"plugins": [

0 commit comments

Comments
 (0)