| 405 | * @internal |
| 406 | */ |
| 407 | export class AlphaTexAstNodePlugin implements PrettyFormatNewPlugin { |
| 408 | public static readonly instance = new AlphaTexAstNodePlugin(); |
| 409 | |
| 410 | /** |
| 411 | * @partial |
| 412 | * @target web |
| 413 | */ |
| 414 | test(arg0: unknown): boolean { |
| 415 | return !!arg0 && typeof arg0 === 'object' && 'nodeType' in arg0; |
| 416 | } |
| 417 | |
| 418 | serialize( |
| 419 | val: unknown, |
| 420 | config: PrettyFormatConfig, |
| 421 | indentation: string, |
| 422 | depth: number, |
| 423 | refs: unknown[], |
| 424 | printer: PrettyFormatPrinter |
| 425 | ): string { |
| 426 | const node = val as AlphaTexAstNode; |
| 427 | let value: string | undefined = undefined; |
| 428 | switch (node.nodeType) { |
| 429 | case AlphaTexNodeType.Ident: |
| 430 | value = (node as AlphaTexIdentifier).text; |
| 431 | break; |
| 432 | case AlphaTexNodeType.Tag: |
| 433 | value = (node as AlphaTexMetaDataTagNode).tag.text; |
| 434 | break; |
| 435 | case AlphaTexNodeType.Number: |
| 436 | value = (node as AlphaTexNumberLiteral).value.toString(); |
| 437 | break; |
| 438 | case AlphaTexNodeType.String: |
| 439 | value = (node as AlphaTexStringLiteral).text; |
| 440 | break; |
| 441 | } |
| 442 | const serializedValue = value !== undefined ? ` ${JSON.stringify(value)}` : ''; |
| 443 | |
| 444 | // children |
| 445 | const children: [string, unknown][] = []; |
| 446 | |
| 447 | if (node.leadingComments && node.leadingComments.length > 0) { |
| 448 | const comments: string[] = []; |
| 449 | for (const c of node.leadingComments) { |
| 450 | if (c.multiLine) { |
| 451 | comments.push(`/*${c.text}*/`); |
| 452 | } else { |
| 453 | comments.push(`//${c.text}`); |
| 454 | } |
| 455 | } |
| 456 | children.push(['leadingComments', comments]); |
| 457 | } |
| 458 | |
| 459 | if (node.trailingComments && node.trailingComments.length > 0) { |
| 460 | const comments: string[] = []; |
| 461 | for (const c of node.trailingComments) { |
| 462 | if (c.multiLine) { |
| 463 | comments.push(`/*${c.text}*/`); |
| 464 | } else { |
nothing calls this directly
no outgoing calls
no test coverage detected