Skip to content

Commit c855be8

Browse files
committed
Update vfile
1 parent 343fae5 commit c855be8

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

Diff for: lib/index.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* @typedef {Parent['children'][number]} Child
77
* @typedef {Element['children'][number]} ElementChild
88
* @typedef {Child|Root} Node
9-
* @typedef {import('vfile-location').Location} Location
109
* @typedef {import('vfile').VFile} VFile
1110
*
1211
* @typedef {{
@@ -27,7 +26,7 @@ import toString from 'hast-util-to-string'
2726
import {whitespace} from 'hast-util-whitespace'
2827
import {toString as nlcstToString} from 'nlcst-to-string'
2928
import {pointStart} from 'unist-util-position'
30-
import vfileLocation from 'vfile-location'
29+
import {location} from 'vfile-location'
3130

3231
const source = convertElement(['code', dataNlcstSourced])
3332
const ignore = convertElement([
@@ -96,7 +95,7 @@ export function toNlcst(tree, file, Parser) {
9695
}
9796

9897
const doc = String(file)
99-
const location = vfileLocation(doc)
98+
const loc = location(doc)
10099
const parser = 'parse' in Parser ? Parser : new Parser()
101100
/** @type {Array.<UnistNode>} */
102101
const results = []
@@ -106,7 +105,7 @@ export function toNlcst(tree, file, Parser) {
106105
return {
107106
type: 'RootNode',
108107
children: results,
109-
position: {start: location.toPoint(0), end: location.toPoint(doc.length)}
108+
position: {start: loc.toPoint(0), end: loc.toPoint(doc.length)}
110109
}
111110

112111
/**
@@ -239,7 +238,7 @@ export function toNlcst(tree, file, Parser) {
239238
}
240239

241240
return change && replacement
242-
? patch(replacement, location, location.toOffset(pointStart(node)))
241+
? patch(replacement, loc, loc.toOffset(pointStart(node)))
243242
: replacement
244243
}
245244

@@ -270,7 +269,7 @@ export function toNlcst(tree, file, Parser) {
270269
*
271270
* @template {Array.<UnistNode>} T
272271
* @param {T} nodes
273-
* @param {Location} location
272+
* @param {ReturnType<location>} location
274273
* @param {number} offset
275274
* @returns {T}
276275
*/

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
"hast-util-whitespace": "^2.0.0",
4646
"nlcst-to-string": "^3.0.0",
4747
"unist-util-position": "^4.0.0",
48-
"vfile": "^4.0.0",
49-
"vfile-location": "^3.1.0"
48+
"vfile": "^5.0.0",
49+
"vfile-location": "^4.0.0"
5050
},
5151
"devDependencies": {
5252
"@types/tape": "^4.0.0",

Diff for: test/index.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs'
22
import path from 'path'
33
import test from 'tape'
44
import rehype from 'rehype'
5-
import vfile from 'vfile'
5+
import {VFile} from 'vfile'
66
// @ts-expect-error: to do type.
77
import {ParseLatin} from 'parse-latin'
88
// @ts-expect-error: to do type.
@@ -61,15 +61,15 @@ test('hast-util-to-nlcst', (t) => {
6161
t.throws(
6262
() => {
6363
// @ts-ignore runtime.
64-
toNlcst({type: 'text', value: 'foo'}, vfile('foo'))
64+
toNlcst({type: 'text', value: 'foo'}, new VFile('foo'))
6565
},
6666
/hast-util-to-nlcst expected parser/,
6767
'should fail without parser'
6868
)
6969

7070
t.throws(
7171
() => {
72-
toNlcst({type: 'text', value: 'foo'}, vfile(), ParseLatin)
72+
toNlcst({type: 'text', value: 'foo'}, new VFile(), ParseLatin)
7373
},
7474
/hast-util-to-nlcst expected position on nodes/,
7575
'should fail when not given positional information'
@@ -85,7 +85,7 @@ test('hast-util-to-nlcst', (t) => {
8585
end: {line: 1, column: 4}
8686
}
8787
},
88-
vfile(),
88+
new VFile(),
8989
ParseEnglish
9090
)
9191
}, 'should accept a parser constructor')
@@ -100,7 +100,7 @@ test('hast-util-to-nlcst', (t) => {
100100
end: {line: 1, column: 4}
101101
}
102102
},
103-
vfile(),
103+
new VFile(),
104104
new ParseDutch()
105105
)
106106
}, 'should accept a parser instance')
@@ -114,7 +114,7 @@ test('hast-util-to-nlcst', (t) => {
114114
// @ts-ignore runtime.
115115
position: {start: {}, end: {}}
116116
},
117-
vfile(),
117+
new VFile(),
118118
ParseLatin
119119
)
120120
},
@@ -132,7 +132,7 @@ test('hast-util-to-nlcst', (t) => {
132132
end: {line: 1, column: 4}
133133
}
134134
},
135-
vfile('foo'),
135+
new VFile('foo'),
136136
ParseLatin
137137
)
138138

@@ -149,7 +149,7 @@ test('hast-util-to-nlcst', (t) => {
149149
value: 'a',
150150
position: {start: {line: 1, column: 1}, end: {line: 1, column: 9}}
151151
},
152-
vfile('<!--a-->'),
152+
new VFile('<!--a-->'),
153153
ParseLatin
154154
)
155155

@@ -192,7 +192,7 @@ test('Fixtures', (t) => {
192192

193193
input = path.join(root, files[index], 'input.html')
194194
output = path.join(root, files[index], 'output.json')
195-
file = vfile(fs.readFileSync(input))
195+
file = new VFile(fs.readFileSync(input))
196196
// @ts-ignore Assume hast.
197197
actual = toNlcst(rehype().parse(file), file, ParseLatin)
198198

0 commit comments

Comments
 (0)