File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ export const getTreeItem = (value) => {
4141
4242 nodes . append (
4343 typeof value === 'symbol'
44- ? value . description
44+ ? escapeSymbol ( value . description )
4545 : typeof value === 'string'
4646 ? `"${ value } "`
4747 : value ,
@@ -66,15 +66,21 @@ const printListItem = (list, depth = -1) =>
6666 ? ''
6767 : ! Array . isArray ( list )
6868 ? '. ' + print ( list , depth )
69- : print ( list [ 0 ] , depth ) + ' ' + printListItem ( list [ 1 ] , depth ) . trim ( )
69+ : ( print ( list [ 0 ] , depth ) + ' ' + printListItem ( list [ 1 ] , depth ) ) . trim ( )
7070
7171const print = ( value , depth = - 1 ) =>
7272 typeof value === 'symbol'
73- ? value . description
73+ ? escapeSymbol ( value . description )
7474 : typeof value === 'string'
7575 ? `"${ value } "`
7676 : Array . isArray ( value )
7777 ? depth === 0
7878 ? '(...)'
7979 : '(' + printListItem ( value , depth - 1 ) + ')'
8080 : value
81+
82+ const symbolRequiresEscape = ( name ) =>
83+ name . match ( / [ ' " ] | ^ ( [ + - ] ? ( \d + ( \. \d * ) ? | \. \d + ) ( [ e E ] [ + - ] ? \d + ) ? ) $ / ) !== null
84+
85+ const escapeSymbol = ( name ) =>
86+ symbolRequiresEscape ( name ) ? `|${ name . replaceAll ( '|' , '\\|' ) } |` : name
You can’t perform that action at this time.
0 commit comments