-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): handle 'array' arguments correctly
Jest supports passing certain arguments multiple times. For instance, in the following example: ``` jest --coverage --reporters="default" --reporters="jest-junit" ``` all of the values for the `--reporters` flag ("default" and "jest-junit") should be collected into an array of values, instead of simply recording whichever value is farther to the right (Stencil's behavior before this commit). To support passing such arguments to the `stencil test` subcommand this commit adds a new recursive-descent parser in `src/cli/parse-flags.ts` to replace the somewhat ad-hoc approach that was there previously. It parses the following grammar: ``` CLIArgments → "" | CLITerm ( " " CLITerm )* ; CLITerm → EqualsArg | AliasEqualsArg | AliasArg | NegativeDashArg | NegativeArg | SimpleArg ; EqualsArg → "--" ArgName "=" CLIValue ; AliasEqualsArg → "-" AliasName "=" CLIValue ; AliasArg → "-" AliasName ( " " CLIValue )? ; NegativeDashArg → "--no-" ArgName ; NegativeArg → "--no" ArgName ; SimpleArg → "--" ArgName ( " " CLIValue )? ; ArgName → /^[a-zA-Z-]+$/ ; AliasName → /^[a-z]{1}$/ ; CLIValue → '"' /^[a-zA-Z0-9]+$/ ('"')? ; ``` (the regexes are a little fuzzy, but this is sort of an informal presentation). Refactoring this to use a proper parser (albeit a pretty simple one) allows our implementation to much more clearly conform to this defined grammar, and should hopefully both help us avoid other bugs in the future and be easier to maintain.
- Loading branch information
1 parent
8c1c35c
commit 8d54c0e
Showing
6 changed files
with
408 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.