Skip to content

Commit 81cde21

Browse files
committed
Remove support for passing file directly
1 parent ca404c7 commit 81cde21

File tree

3 files changed

+9
-165
lines changed

3 files changed

+9
-165
lines changed

lib/index.js

+3-27
Original file line numberDiff line numberDiff line change
@@ -77,29 +77,17 @@ const proto = Object.prototype
7777
*
7878
* @param {P5Node} tree
7979
* `parse5` tree to transform.
80-
* @param {Options | VFile | null | undefined} [options]
80+
* @param {Options | null | undefined} [options]
8181
* Configuration (optional).
8282
* @returns {Nodes}
8383
* hast tree.
8484
*/
8585
export function fromParse5(tree, options) {
86-
const options_ = options || {}
87-
/** @type {Options} */
88-
let settings
89-
/** @type {VFile | undefined} */
90-
let file
91-
92-
if (isFile(options_)) {
93-
file = options_
94-
settings = {}
95-
} else {
96-
file = options_.file || undefined
97-
settings = options_
98-
}
86+
const settings = options || {}
9987

10088
return one(
10189
{
102-
file,
90+
file: settings.file || undefined,
10391
location: false,
10492
schema: settings.space === 'svg' ? svg : html,
10593
verbose: settings.verbose
@@ -381,15 +369,3 @@ function position(loc) {
381369
function point(point) {
382370
return point.line && point.column ? point : undefined
383371
}
384-
385-
/**
386-
* Check if something is a file.
387-
*
388-
* @param {VFile | Options} value
389-
* File or options.
390-
* @returns {value is VFile}
391-
* Whether `value` is a file.
392-
*/
393-
function isFile(value) {
394-
return 'messages' in value
395-
}

readme.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* [Install](#install)
1818
* [Use](#use)
1919
* [API](#api)
20-
* [`fromParse5(tree[, file|options])`](#fromparse5tree-fileoptions)
20+
* [`fromParse5(tree[, options])`](#fromparse5tree-options)
2121
* [`Options`](#options)
2222
* [`Space`](#space-1)
2323
* [Types](#types)
@@ -84,7 +84,7 @@ import {fromParse5} from 'hast-util-from-parse5'
8484

8585
const file = await read('example.html')
8686
const p5ast = parse(String(file), {sourceCodeLocationInfo: true})
87-
const hast = fromParse5(p5ast, file)
87+
const hast = fromParse5(p5ast, {file})
8888

8989
console.log(inspect(hast))
9090
```
@@ -118,16 +118,14 @@ root[2] (1:1-2:1, 0-70)
118118
This package exports the identifier [`fromParse5`][fromparse5].
119119
There is no default export.
120120

121-
### `fromParse5(tree[, file|options])`
121+
### `fromParse5(tree[, options])`
122122

123123
Transform a `parse5` AST to hast.
124124

125125
###### Parameters
126126

127127
* `tree` ([`Parse5Node`][parse5-node])
128128
`parse5` tree to transform
129-
* `file` ([`VFile`][vfile], optional)
130-
— corresponding file (treated as `{file: file}`)
131129
* `options` ([`Options`][options], optional)
132130
— configuration
133131

@@ -326,7 +324,7 @@ abide by its terms.
326324
327325
[hast-node]: https://github.com/syntax-tree/hast#nodes
328326
329-
[fromparse5]: #fromparse5tree-fileoptions
327+
[fromparse5]: #fromparse5tree-options
330328
331329
[options]: #options
332330

test/index.js

+2-132
Original file line numberDiff line numberDiff line change
@@ -93,136 +93,6 @@ test('fromParse5', async function (t) {
9393
})
9494
})
9595

96-
await t.test('should accept a file as options', async function () {
97-
assert.deepEqual(
98-
fromParse5(parse(String(file), {sourceCodeLocationInfo: true}), file),
99-
{
100-
type: 'root',
101-
children: [
102-
{
103-
type: 'element',
104-
tagName: 'html',
105-
properties: {},
106-
children: [
107-
{
108-
type: 'element',
109-
tagName: 'head',
110-
properties: {},
111-
children: [
112-
{
113-
type: 'element',
114-
tagName: 'title',
115-
properties: {},
116-
children: [
117-
{
118-
type: 'text',
119-
value: 'Hello!',
120-
position: {
121-
start: {line: 1, column: 8, offset: 7},
122-
end: {line: 1, column: 14, offset: 13}
123-
}
124-
}
125-
],
126-
position: {
127-
start: {line: 1, column: 1, offset: 0},
128-
end: {line: 1, column: 22, offset: 21}
129-
}
130-
}
131-
]
132-
},
133-
{
134-
type: 'element',
135-
tagName: 'body',
136-
properties: {},
137-
children: [
138-
{
139-
type: 'element',
140-
tagName: 'h1',
141-
properties: {},
142-
children: [
143-
{
144-
type: 'text',
145-
value: 'World!',
146-
position: {
147-
start: {line: 1, column: 26, offset: 25},
148-
end: {line: 1, column: 32, offset: 31}
149-
}
150-
}
151-
],
152-
position: {
153-
start: {line: 1, column: 22, offset: 21},
154-
end: {line: 1, column: 32, offset: 31}
155-
}
156-
}
157-
]
158-
}
159-
]
160-
}
161-
],
162-
data: {quirksMode: true},
163-
position: {
164-
start: {line: 1, column: 1, offset: 0},
165-
end: {line: 1, column: 32, offset: 31}
166-
}
167-
}
168-
)
169-
})
170-
171-
await t.test(
172-
'should accept a file as options (without location info)',
173-
async function () {
174-
assert.deepEqual(fromParse5(parse(String(file)), file), {
175-
type: 'root',
176-
children: [
177-
{
178-
type: 'element',
179-
tagName: 'html',
180-
properties: {},
181-
children: [
182-
{
183-
type: 'element',
184-
tagName: 'head',
185-
properties: {},
186-
children: [
187-
{
188-
type: 'element',
189-
tagName: 'title',
190-
properties: {},
191-
children: [
192-
{
193-
type: 'text',
194-
value: 'Hello!'
195-
}
196-
]
197-
}
198-
]
199-
},
200-
{
201-
type: 'element',
202-
tagName: 'body',
203-
properties: {},
204-
children: [
205-
{
206-
type: 'element',
207-
tagName: 'h1',
208-
properties: {},
209-
children: [
210-
{
211-
type: 'text',
212-
value: 'World!'
213-
}
214-
]
215-
}
216-
]
217-
}
218-
]
219-
}
220-
],
221-
data: {quirksMode: true}
222-
})
223-
}
224-
)
225-
22696
await t.test('should support synthetic locations', async function () {
22797
assert.deepEqual(
22898
fromParse5(
@@ -246,7 +116,7 @@ test('fromParse5', async function (t) {
246116
startOffset: 0
247117
}
248118
},
249-
file
119+
{file}
250120
),
251121
{
252122
type: 'element',
@@ -295,7 +165,7 @@ test('fromParse5', async function (t) {
295165
startOffset: 0
296166
}
297167
},
298-
file
168+
{file}
299169
),
300170
{
301171
type: 'element',

0 commit comments

Comments
 (0)