Skip to content

Commit

Permalink
Fixed imports
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewlipski committed Jun 9, 2023
1 parent 46f9b85 commit 060ecaa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
26 changes: 14 additions & 12 deletions packages/rehype-parse/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
* @typedef {FromParse5Options & ParseFields & ErrorFields} Options
*/

// @ts-expect-error: remove when typed
import Parser5 from 'parse5/lib/parser/index.js'
import {Parser, parse, parseFragment} from 'parse5'

Check failure on line 30 in packages/rehype-parse/lib/index.js

View workflow job for this annotation

GitHub Actions / lts/fermium

'Parser' is defined but never used.

Check failure on line 30 in packages/rehype-parse/lib/index.js

View workflow job for this annotation

GitHub Actions / node

'Parser' is defined but never used.
import {fromParse5} from 'hast-util-from-parse5'
import {errors} from './errors.js'

Expand All @@ -48,21 +47,24 @@ export default function rehypeParse(options) {

/** @type {import('unified').ParserFunction<Root>} */
function parser(doc, file) {
const fn = settings.fragment ? 'parseFragment' : 'parse'
const onParseError = settings.emitParseErrors ? onerror : null
const parse5 = new Parser5({
const parserOptions = {
sourceCodeLocationInfo: true,
onParseError,
onParseError: settings.emitParseErrors ? onerror : null,
scriptingEnabled: false
})
}

// @ts-expect-error: `parse5` returns document or fragment, which are always
// mapped to roots.
return fromParse5(parse5[fn](doc), {
space: settings.space,
file,
verbose: settings.verbose
})
return fromParse5(
settings.fragment
? parseFragment(doc, parserOptions)
: parse(doc, parserOptions),
{
space: settings.space,
file,
verbose: settings.verbose
}
)

/**
* @param {{code: string, startLine: number, startCol: number, startOffset: number, endLine: number, endCol: number, endOffset: number}} error
Expand Down
3 changes: 1 addition & 2 deletions test/parse-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import path from 'node:path'
import test from 'tape'
import {toVFile, readSync} from 'to-vfile'
import {rehype} from 'rehype'
// @ts-expect-error: untyped.
import p5errors from 'parse5/lib/common/error-codes.js'
import {ErrorCodes as p5errors} from 'parse5'
import {errors as rerrors} from 'rehype-parse/lib/errors.js'

// Related to https://github.com/inikulin/parse5/issues/255
Expand Down

0 comments on commit 060ecaa

Please sign in to comment.