Skip to content

Commit c95de39

Browse files
committed
Remove support for passing space directly
1 parent c15a644 commit c95de39

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

lib/index.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,21 @@ import {h, s} from 'hastscript'
3030

3131
const cssSelectorParse = createParser({syntax: 'selectors-4'})
3232

33-
// To do: remove `space` shortcut.
33+
/** @type {Options} */
34+
const emptyOptions = {}
35+
3436
/**
3537
* Create one or more `Element`s from a CSS selector.
3638
*
3739
* @param {string | null | undefined} [selector='']
3840
* CSS selector (default: `''`).
39-
* @param {Options | Space | null | undefined} [options]
41+
* @param {Options | null | undefined} [options]
4042
* Configuration (optional).
4143
* @returns {HastElement}
4244
* Built tree.
4345
*/
4446
export function fromSelector(selector, options) {
45-
/** @type {State} */
46-
const state = {
47-
space:
48-
(options && typeof options === 'object' && options.space) ||
49-
(typeof options === 'string' && options) ||
50-
'html'
51-
}
47+
const settings = options || emptyOptions
5248

5349
const query = cssSelectorParse(selector || '*')
5450

@@ -70,7 +66,7 @@ export function fromSelector(selector, options) {
7066
)
7167
}
7268

73-
const result = rule(head, state)
69+
const result = rule(head, {space: settings.space || 'html'})
7470

7571
return result[0]
7672
}

readme.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* [Install](#install)
1818
* [Use](#use)
1919
* [API](#api)
20-
* [`fromSelector(selector?[, options|space])`](#fromselectorselector-optionsspace)
20+
* [`fromSelector(selector?[, options])`](#fromselectorselector-options)
2121
* [`Options`](#options)
2222
* [`Space`](#space)
2323
* [Support](#support)
@@ -68,7 +68,7 @@ In browsers with [`esm.sh`][esmsh]:
6868
```js
6969
import {fromSelector} from 'hast-util-from-selector'
7070

71-
console.log(fromSelector('p svg[viewbox=0 0 10 10] circle[cx=10][cy=10][r=10]'))
71+
console.log(fromSelector('p svg[viewbox="0 0 10 10"] circle[cx=10][cy=10][r=10]'))
7272
```
7373

7474
Yields:
@@ -101,7 +101,7 @@ Yields:
101101
This package exports the identifier [`fromSelector`][fromselector].
102102
There is no default export.
103103

104-
### `fromSelector(selector?[, options|space])`
104+
### `fromSelector(selector?[, options])`
105105

106106
Create one or more [`Element`][element]s from a CSS selector.
107107

@@ -111,8 +111,6 @@ Create one or more [`Element`][element]s from a CSS selector.
111111
— CSS selector
112112
* `options` ([`Options`][options], optional)
113113
— configuration
114-
* `space` ([`Space`][space], optional)
115-
— treated as `options.space`
116114

117115
###### Returns
118116

@@ -252,7 +250,7 @@ abide by its terms.
252250
253251
[hastscript]: https://github.com/syntax-tree/hastscript
254252
255-
[fromselector]: #fromselectorselector-optionsspace
253+
[fromselector]: #fromselectorselector-options
256254
257255
[options]: #options
258256

test.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,28 +150,24 @@ test('fromSelector', async function (t) {
150150
})
151151

152152
await t.test('should support space (#2)', async function () {
153-
assert.equal(fromSelector('altGlyph', 'svg').tagName, 'altGlyph')
154-
})
155-
156-
await t.test('should support space (#3)', async function () {
157153
assert.equal(fromSelector('altGlyph', {space: 'svg'}).tagName, 'altGlyph')
158154
})
159155

160-
await t.test('should support space (#4)', async function () {
156+
await t.test('should support space (#3)', async function () {
161157
const result = fromSelector('svg altGlyph')
162158
const child = result.children[0]
163159
assert(child.type === 'element')
164160
assert.equal(child.tagName, 'altGlyph')
165161
})
166162

167-
await t.test('should support space (#5)', async function () {
163+
await t.test('should support space (#4)', async function () {
168164
const result = fromSelector('div svg + altGlyph')
169165
const child = result.children[1]
170166
assert(child.type === 'element')
171167
assert.equal(child.tagName, 'altglyph')
172168
})
173169

174-
await t.test('should support space (#6)', async function () {
170+
await t.test('should support space (#5)', async function () {
175171
assert.deepEqual(
176172
fromSelector(
177173
'p svg[viewbox="0 0 10 10"] circle[cx=10][cy=10][r=10] altGlyph'

0 commit comments

Comments
 (0)