Skip to content

Commit

Permalink
Update vfile-location
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed May 6, 2021
1 parent ee40d1a commit 7b3aac7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @typedef {import('unist').Point} Point
* @typedef {import('mdast').Content} Content
* @typedef {import('vfile').VFile} VFile
* @typedef {import('vfile-location').Location} LocationInterface
* @typedef {ReturnType<import('vfile-location').location>} Location
* @typedef {{
* parse(nodes: Node[]): Node
* tokenizeSource(value: string): Node
Expand All @@ -19,7 +19,7 @@
*
* @typedef Context
* @property {string} doc
* @property {LocationInterface} location
* @property {Location} place
* @property {ParserInstance} parser
* @property {Array.<string>} ignore
* @property {Array.<string>} source
Expand All @@ -28,7 +28,7 @@
import repeat from 'repeat-string'
import {toString} from 'nlcst-to-string'
import {pointStart, pointEnd} from 'unist-util-position'
import vfileLocation from 'vfile-location'
import {location} from 'vfile-location'

/**
* Transform a `tree` in mdast to nlcst.
Expand Down Expand Up @@ -73,7 +73,7 @@ export function toNlcst(tree, file, Parser, options = {}) {
one(
{
doc: String(file),
location: vfileLocation(file),
place: location(file),
parser,
ignore: [].concat(
'table',
Expand Down Expand Up @@ -210,8 +210,8 @@ function patch(config, nodes, offset) {
end = start + toString(node).length

node.position = {
start: config.location.toPoint(start),
end: config.location.toPoint(end)
start: config.place.toPoint(start),
end: config.place.toPoint(end)
}

start = end
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"nlcst-to-string": "^3.0.0",
"repeat-string": "^1.0.0",
"unist-util-position": "^4.0.0",
"vfile-location": "^3.1.0"
"vfile-location": "^4.0.0"
},
"devDependencies": {
"@types/tape": "^4.0.0",
Expand All @@ -57,7 +57,7 @@
"remark-preset-wooorm": "^8.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"to-vfile": "^6.0.0",
"to-vfile": "^7.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.39.0"
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ npm install mdast-util-to-nlcst
## Use

```js
import vfile from 'vfile'
import {VFile} from 'vfile'
import {ParseEnglish} from 'parse-english'
import {inspect} from 'unist-util-inspect'
import fromMarkdown from 'mdast-util-from-markdown'
import {toNlcst} from 'mdast-util-to-nlcst'

var file = vfile('Some *foo*sball.')
var file = new VFile('Some *foo*sball.')
var mdast = fromMarkdown(file)
var nlcst = toNlcst(mdast, file, ParseEnglish)

Expand Down
8 changes: 5 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import test from 'tape'
import remark from 'remark'
import gfm from 'remark-gfm'
import frontmatter from 'remark-frontmatter'
import vfile from 'to-vfile'
import {toVFile as vfile} from 'to-vfile'
import {ParseLatin} from 'parse-latin'
import {ParseDutch} from 'parse-dutch'
import {ParseEnglish} from 'parse-english'
Expand Down Expand Up @@ -144,11 +144,13 @@ test('Fixtures', function (t) {
if (isHidden(name)) continue

input = vfile.readSync(path.join(base, name, 'input.md'))
expected = JSON.parse(vfile.readSync(path.join(base, name, 'output.json')))
expected = JSON.parse(
String(vfile.readSync(path.join(base, name, 'output.json')))
)

try {
options = JSON.parse(
vfile.readSync(path.join(base, name, 'options.json'))
String(vfile.readSync(path.join(base, name, 'options.json')))
)
} catch {
options = undefined
Expand Down

0 comments on commit 7b3aac7

Please sign in to comment.