Skip to content

Commit a0e1140

Browse files
committed
Change to remove support for passing a space directly
1 parent 70ba240 commit a0e1140

File tree

3 files changed

+9
-31
lines changed

3 files changed

+9
-31
lines changed

lib/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ import {stringify as spaces} from 'space-separated-tokens'
4242
import {webNamespaces} from 'web-namespaces'
4343
import {zwitch} from 'zwitch'
4444

45+
/** @type {Options} */
46+
const emptyOptions = {}
47+
4548
const own = {}.hasOwnProperty
4649

4750
const one = zwitch('type', {handlers: {root, element, text, comment, doctype}})
@@ -51,13 +54,14 @@ const one = zwitch('type', {handlers: {root, element, text, comment, doctype}})
5154
*
5255
* @param {Nodes} tree
5356
* Tree to transform.
54-
* @param {Options | Space | null | undefined} [options]
57+
* @param {Options | null | undefined} [options]
5558
* Configuration (optional).
5659
* @returns {Parse5Nodes}
5760
* `parse5` node.
5861
*/
5962
export function toParse5(tree, options) {
60-
const space = options && typeof options === 'object' ? options.space : options
63+
const settings = options || emptyOptions
64+
const space = settings.space
6165
return one(tree, space === 'svg' ? svg : html)
6266
}
6367

readme.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* [Install](#install)
1818
* [Use](#use)
1919
* [API](#api)
20-
* [`toParse5(tree[, space|options])`](#toparse5tree-spaceoptions)
20+
* [`toParse5(tree[, options])`](#toparse5tree-options)
2121
* [`Options`](#options)
2222
* [`Space`](#space)
2323
* [Types](#types)
@@ -93,16 +93,14 @@ Yields:
9393
This package exports the identifier [`toParse5`][toparse5].
9494
There is no default export.
9595

96-
### `toParse5(tree[, space|options])`
96+
### `toParse5(tree[, options])`
9797

9898
Transform a hast tree to Parse5’s AST.
9999

100100
###### Parameters
101101

102102
* `tree` ([`HastNode`][hast-node])
103103
— tree to transform
104-
* `space` ([`Space`][space], optional)
105-
— same as `{space: space}`
106104
* `options` ([`Options`][options], optional)
107105
— configuration
108106

@@ -235,7 +233,7 @@ abide by its terms.
235233
236234
[hast-util-from-parse5]: https://github.com/syntax-tree/hast-util-from-parse5
237235
238-
[toparse5]: #toparse5tree-spaceoptions
236+
[toparse5]: #toparse5tree-options
239237
240238
[options]: #options
241239

test.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -396,30 +396,6 @@ test('svg', async function (t) {
396396
)
397397
})
398398

399-
await t.test('should transform SVG (given a space)', async function () {
400-
const expected = parseFragment(
401-
'<svg><circle cx="60" cy="60" r="50" fill="red"/></svg>'
402-
).childNodes[0]
403-
assert(expected && 'childNodes' in expected)
404-
const expectedChild = expected.childNodes[0]
405-
expectedChild.parentNode = null
406-
407-
assert.deepEqual(
408-
json(
409-
toParse5(
410-
{
411-
type: 'element',
412-
tagName: 'circle',
413-
properties: {cx: '60', cy: '60', r: '50', fill: 'red'},
414-
children: []
415-
},
416-
'svg'
417-
)
418-
),
419-
json(expectedChild)
420-
)
421-
})
422-
423399
await t.test('should transform SVG (given options)', async function () {
424400
const expected = parseFragment(
425401
'<svg><circle cx="60" cy="60" r="50" fill="red"/></svg>'

0 commit comments

Comments
 (0)