Skip to content

Commit eb37f48

Browse files
committed
Refactor code-style
1 parent 7db865f commit eb37f48

File tree

3 files changed

+23
-29
lines changed

3 files changed

+23
-29
lines changed

index.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import {h, s} from 'hastscript'
2222
import {zwitch} from 'zwitch'
2323
import {CssSelectorParser} from 'css-selector-parser'
2424

25-
var compile = zwitch('type', {handlers: {selectors, ruleSet, rule}})
25+
const compile = zwitch('type', {handlers: {selectors, ruleSet, rule}})
2626

27-
var parser = new CssSelectorParser()
27+
const parser = new CssSelectorParser()
2828

2929
parser.registerNestingOperators('>', '+', '~')
3030
// Register these so we can throw nicer errors.
@@ -37,7 +37,7 @@ parser.registerAttrEqualityMods('~', '|', '^', '$', '*')
3737
*/
3838
export function fromSelector(selector, space) {
3939
/** @type {Context} */
40-
var config = {
40+
const config = {
4141
space:
4242
(space && typeof space === 'object' && space.space) ||
4343
(typeof space === 'string' && space) ||
@@ -74,13 +74,11 @@ function ruleSet(query, config) {
7474
* @returns {HastElement|Array.<HastElement>}
7575
*/
7676
function rule(query, config) {
77-
var parentSpace = config.space
78-
var name = query.tagName === '*' ? '' : query.tagName || ''
79-
var space = parentSpace === 'html' && name === 'svg' ? 'svg' : parentSpace
77+
const parentSpace = config.space
78+
const name = query.tagName === '*' ? '' : query.tagName || ''
79+
const space = parentSpace === 'html' && name === 'svg' ? 'svg' : parentSpace
8080
/** @type {boolean} */
81-
var sibling
82-
/** @type {HastElement} */
83-
var node
81+
let sibling
8482

8583
if (query.rule) {
8684
sibling =
@@ -96,7 +94,7 @@ function rule(query, config) {
9694
}
9795

9896
// @ts-ignore Assume one or more elements is returned.
99-
node = build(space)(
97+
const node = build(space)(
10098
name,
10199
Object.assign(
102100
{id: query.id, className: query.classNames},
@@ -115,7 +113,7 @@ function rule(query, config) {
115113
* @returns {HastProperties}
116114
*/
117115
function pseudosToHast(pseudos) {
118-
var pseudo = pseudos[0]
116+
const pseudo = pseudos[0]
119117

120118
if (pseudo) {
121119
if (pseudo.name) {
@@ -133,11 +131,11 @@ function pseudosToHast(pseudos) {
133131
* @returns {HastProperties}
134132
*/
135133
function attrsToHast(attrs) {
136-
var index = -1
134+
let index = -1
137135
/** @type {HastProperties} */
138-
var props = {}
136+
const props = {}
139137
/** @type {CssRuleAttr} */
140-
var attr
138+
let attr
141139

142140
while (++index < attrs.length) {
143141
attr = attrs[index]

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@
7070
"trailingComma": "none"
7171
},
7272
"xo": {
73-
"prettier": true,
74-
"rules": {
75-
"no-var": "off",
76-
"prefer-arrow-callback": "off"
77-
}
73+
"prettier": true
7874
},
7975
"remarkConfig": {
8076
"plugins": [

test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,73 @@ import test from 'tape'
22
import {h, s} from 'hastscript'
33
import {fromSelector} from './index.js'
44

5-
test('fromSelector()', function (t) {
5+
test('fromSelector()', (t) => {
66
t.throws(
7-
function () {
7+
() => {
88
fromSelector('@supports (transform-origin: 5% 5%) {}')
99
},
1010
/Error: Rule expected but "@" found/,
1111
'should throw w/ invalid selector'
1212
)
1313

1414
t.throws(
15-
function () {
15+
() => {
1616
fromSelector('a, b')
1717
},
1818
/Error: Cannot handle selector list/,
1919
'should throw w/ multiple selector'
2020
)
2121

2222
t.throws(
23-
function () {
23+
() => {
2424
fromSelector('a + b')
2525
},
2626
/Error: Cannot handle sibling combinator `\+` at root/,
2727
'should throw w/ next-sibling combinator at root'
2828
)
2929

3030
t.throws(
31-
function () {
31+
() => {
3232
fromSelector('a ~ b')
3333
},
3434
/Error: Cannot handle sibling combinator `~` at root/,
3535
'should throw w/ subsequent-sibling combinator at root'
3636
)
3737

3838
t.throws(
39-
function () {
39+
() => {
4040
fromSelector('[foo%=bar]')
4141
},
4242
/Error: Expected "=" but "%" found./,
4343
'should throw w/ attribute modifiers'
4444
)
4545

4646
t.throws(
47-
function () {
47+
() => {
4848
fromSelector('[foo~=bar]')
4949
},
5050
/Error: Cannot handle attribute equality modifier `~=`/,
5151
'should throw w/ attribute modifiers'
5252
)
5353

5454
t.throws(
55-
function () {
55+
() => {
5656
fromSelector(':active')
5757
},
5858
/Error: Cannot handle pseudo-selector `active`/,
5959
'should throw on pseudo classes'
6060
)
6161

6262
t.throws(
63-
function () {
63+
() => {
6464
fromSelector(':nth-foo(2n+1)')
6565
},
6666
/Error: Cannot handle pseudo-selector `nth-foo`/,
6767
'should throw on pseudo class “functions”'
6868
)
6969

7070
t.throws(
71-
function () {
71+
() => {
7272
fromSelector('::before')
7373
},
7474
/Error: Cannot handle pseudo-element or empty pseudo-class/,

0 commit comments

Comments
 (0)