(commandNode: Node)
| 187 | } |
| 188 | |
| 189 | export function extractCommandArguments(commandNode: Node): string[] { |
| 190 | // Declaration commands |
| 191 | if (commandNode.type === 'declaration_command') { |
| 192 | const firstChild = commandNode.children[0] |
| 193 | return firstChild && DECLARATION_COMMANDS.has(firstChild.text) |
| 194 | ? [firstChild.text] |
| 195 | : [] |
| 196 | } |
| 197 | |
| 198 | const args: string[] = [] |
| 199 | let foundCommandName = false |
| 200 | |
| 201 | for (const child of commandNode.children) { |
| 202 | if (child.type === 'variable_assignment') continue |
| 203 | |
| 204 | // Command name |
| 205 | if ( |
| 206 | child.type === 'command_name' || |
| 207 | (!foundCommandName && child.type === 'word') |
| 208 | ) { |
| 209 | foundCommandName = true |
| 210 | args.push(child.text) |
| 211 | continue |
| 212 | } |
| 213 | |
| 214 | // Arguments |
| 215 | if (ARGUMENT_TYPES.has(child.type)) { |
| 216 | args.push(stripQuotes(child.text)) |
| 217 | } else if (SUBSTITUTION_TYPES.has(child.type)) { |
| 218 | break |
| 219 | } |
| 220 | } |
| 221 | return args |
| 222 | } |
| 223 | |
| 224 | function stripQuotes(text: string): string { |
| 225 | return text.length >= 2 && |
no test coverage detected