Skip to content

Commit 7ea2392

Browse files
committed
fix(parser): should peek next value instead of eat immediately
1 parent e188320 commit 7ea2392

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

packages/parser/src/parse.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,9 @@ export function createParser<T extends FlagsDefinition>(
211211
break;
212212
} else {
213213
// -ab foo, we are on "b"
214-
const nextValue = eat();
215-
if (nextValue && !shouldProcessAsFlag(nextValue)) {
216-
setValueByType(result.flags, key, nextValue, config);
217-
}
214+
const value =
215+
hasNext && !shouldProcessAsFlag(next) ? (eat() ?? "") : "";
216+
setValueByType(result.flags, key, value, config);
218217
}
219218
}
220219
}

packages/parser/test/parser.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ describe("parser", () => {
318318
"-5",
319319
"--eq=",
320320
"---three",
321+
"--string",
322+
"-a",
321323
"--not-given",
322324
],
323325
{
@@ -332,6 +334,8 @@ describe("parser", () => {
332334
},
333335
3: Boolean,
334336
4: Boolean,
337+
string: String,
338+
a: String,
335339
notGiven: String,
336340
},
337341
},
@@ -345,6 +349,8 @@ describe("parser", () => {
345349
alias2: true,
346350
3: true,
347351
4: true,
352+
string: "",
353+
a: "",
348354
notGiven: "",
349355
});
350356
expect(unknown).toEqual({});

0 commit comments

Comments
 (0)