File tree 3 files changed +13
-19
lines changed
3 files changed +13
-19
lines changed Original file line number Diff line number Diff line change 10
10
* @returns {string }
11
11
*/
12
12
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
18
14
19
- // @ts -ignore Looks like an object.
15
+ // @ts -expect-error Looks like an object.
20
16
if ( ! node || ( ! Array . isArray ( node ) && ! node . type ) ) {
21
17
throw new Error ( 'Expected node, not `' + node + '`' )
22
18
}
23
19
24
- // @ts -ignore Looks like a literal.
20
+ // @ts -expect-error Looks like a literal.
25
21
if ( typeof node . value === 'string' ) return node . value
26
22
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 ) || [ ]
29
26
30
27
// Shortcut: This is pretty common, and a small performance win.
31
28
if ( children . length === 1 && 'value' in children [ 0 ] ) {
32
- // @ts -ignore Looks like a literal.
29
+ // @ts -expect-error Looks like a literal.
33
30
return children [ 0 ] . value
34
31
}
35
32
36
- values = [ ]
33
+ /** @type {Array.<string> } */
34
+ const values = [ ]
37
35
38
36
while ( ++ index < children . length ) {
39
37
values [ index ] = toString ( children [ index ] , separator )
Original file line number Diff line number Diff line change 65
65
"trailingComma" : " none"
66
66
},
67
67
"xo" : {
68
- "prettier" : true ,
69
- "rules" : {
70
- "no-var" : " off" ,
71
- "prefer-arrow-callback" : " off"
72
- }
68
+ "prettier" : true
73
69
},
74
70
"remarkConfig" : {
75
71
"plugins" : [
Original file line number Diff line number Diff line change @@ -2,9 +2,9 @@ import test from 'tape'
2
2
import { u } from 'unist-builder'
3
3
import { toString } from './index.js'
4
4
5
- test ( 'toString()' , function ( t ) {
5
+ test ( 'toString()' , ( t ) => {
6
6
t . throws (
7
- function ( ) {
7
+ ( ) => {
8
8
// @ts -expect-error: runtime.
9
9
toString ( )
10
10
} ,
@@ -13,7 +13,7 @@ test('toString()', function (t) {
13
13
)
14
14
15
15
t . throws (
16
- function ( ) {
16
+ ( ) => {
17
17
toString ( { value : 'foo' } )
18
18
} ,
19
19
/ \[ o b j e c t O b j e c t ] / ,
You can’t perform that action at this time.
0 commit comments