(commandNode: Node)
| 205 | } |
| 206 | |
| 207 | export function extractCommandArguments(commandNode: Node): string[] { |
| 208 | // Declaration commands |
| 209 | if (commandNode.type === 'declaration_command') { |
| 210 | const firstChild = commandNode.children[0] |
| 211 | return firstChild && DECLARATION_COMMANDS.has(firstChild.text) |
| 212 | ? [firstChild.text] |
| 213 | : [] |
| 214 | } |
| 215 | |
| 216 | const args: string[] = [] |
| 217 | let foundCommandName = false |
| 218 | |
| 219 | for (const child of commandNode.children) { |
| 220 | if (child.type === 'variable_assignment') continue |
| 221 | |
| 222 | // Command name |
| 223 | if ( |
| 224 | child.type === 'command_name' || |
| 225 | (!foundCommandName && child.type === 'word') |
| 226 | ) { |
| 227 | foundCommandName = true |
| 228 | args.push(child.text) |
| 229 | continue |
| 230 | } |
| 231 | |
| 232 | // Arguments |
| 233 | if (ARGUMENT_TYPES.has(child.type)) { |
| 234 | args.push(stripQuotes(child.text)) |
| 235 | } else if (SUBSTITUTION_TYPES.has(child.type)) { |
| 236 | break |
| 237 | } |
| 238 | } |
| 239 | return args |
| 240 | } |
| 241 | |
| 242 | function stripQuotes(text: string): string { |
| 243 | return text.length >= 2 && |
no test coverage detected