(token: any)
| 7 | */ |
| 8 | |
| 9 | export function stringify(token: any): string { |
| 10 | if (typeof token === 'string') { |
| 11 | return token; |
| 12 | } |
| 13 | |
| 14 | if (Array.isArray(token)) { |
| 15 | return `[${token.map(stringify).join(', ')}]`; |
| 16 | } |
| 17 | |
| 18 | if (token == null) { |
| 19 | return '' + token; |
| 20 | } |
| 21 | |
| 22 | const name = token.overriddenName || token.name; |
| 23 | if (name) { |
| 24 | return `${name}`; |
| 25 | } |
| 26 | |
| 27 | const result = token.toString(); |
| 28 | |
| 29 | if (result == null) { |
| 30 | return '' + result; |
| 31 | } |
| 32 | |
| 33 | const newLineIndex = result.indexOf('\n'); |
| 34 | return newLineIndex >= 0 ? result.slice(0, newLineIndex) : result; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Concatenates two strings with separator, allocating new strings only when necessary. |
no test coverage detected
searching dependent graphs…