Skip to content

Commit eb05a1d

Browse files
committed
Refactor code-style
1 parent 1d0e9e1 commit eb05a1d

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

index.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,28 @@
1010
* @returns {string}
1111
*/
1212
export function toString(node, separator = '') {
13-
var index = -1
14-
/** @type {Array.<Node>} */
15-
var children
16-
/** @type {Array.<string>} */
17-
var values
13+
let index = -1
1814

19-
// @ts-ignore Looks like an object.
15+
// @ts-expect-error Looks like an object.
2016
if (!node || (!Array.isArray(node) && !node.type)) {
2117
throw new Error('Expected node, not `' + node + '`')
2218
}
2319

24-
// @ts-ignore Looks like a literal.
20+
// @ts-expect-error Looks like a literal.
2521
if (typeof node.value === 'string') return node.value
2622

27-
// @ts-ignore Looks like a list of nodes or parent.
28-
children = ('length' in node ? node : node.children) || []
23+
/** @type {Array.<Node>} */
24+
// @ts-expect-error Looks like a list of nodes or parent.
25+
const children = (Array.isArray(node) ? node : node.children) || []
2926

3027
// Shortcut: This is pretty common, and a small performance win.
3128
if (children.length === 1 && 'value' in children[0]) {
32-
// @ts-ignore Looks like a literal.
29+
// @ts-expect-error Looks like a literal.
3330
return children[0].value
3431
}
3532

36-
values = []
33+
/** @type {Array.<string>} */
34+
const values = []
3735

3836
while (++index < children.length) {
3937
values[index] = toString(children[index], separator)

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@
6565
"trailingComma": "none"
6666
},
6767
"xo": {
68-
"prettier": true,
69-
"rules": {
70-
"no-var": "off",
71-
"prefer-arrow-callback": "off"
72-
}
68+
"prettier": true
7369
},
7470
"remarkConfig": {
7571
"plugins": [

test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import test from 'tape'
22
import {u} from 'unist-builder'
33
import {toString} from './index.js'
44

5-
test('toString()', function (t) {
5+
test('toString()', (t) => {
66
t.throws(
7-
function () {
7+
() => {
88
// @ts-expect-error: runtime.
99
toString()
1010
},
@@ -13,7 +13,7 @@ test('toString()', function (t) {
1313
)
1414

1515
t.throws(
16-
function () {
16+
() => {
1717
toString({value: 'foo'})
1818
},
1919
/\[object Object]/,

0 commit comments

Comments
 (0)