(node: TSNode, code: string)
| 73 | * Parse dictionary argument (for keys, pull_keys, push_keys) |
| 74 | */ |
| 75 | export function parseDictArgument(node: TSNode, code: string): { [key: string]: string } | null { |
| 76 | if (node.type === 'dictionary') { |
| 77 | const result: { [key: string]: string } = {}; |
| 78 | for (const child of node.namedChildren) { |
| 79 | if (!child) {continue;} |
| 80 | if (child.type === 'pair') { |
| 81 | const key = child.childForFieldName('key'); |
| 82 | const value = child.childForFieldName('value'); |
| 83 | if (key && value) { |
| 84 | const keyText = getNodeText(key, code).replace(/^["']|["']$/g, ''); |
| 85 | const valueText = getNodeText(value, code).replace(/^["']|["']$/g, ''); |
| 86 | result[keyText] = valueText; |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | return Object.keys(result).length > 0 ? result : null; |
| 91 | } |
| 92 | return null; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Parse keys-like argument for Node pull_keys/push_keys semantics. |
no test coverage detected