@@ -503,16 +503,17 @@ function toTypeScript(
503
503
const values: Array<${ this . func . returnType . unwrap ( ) . toCode ( ) } > = [];
504
504
const failedExpectations: runtime.FailedExpectation[] = [];
505
505
let remainder = ${ this . remainder . toCode ( ) } ;
506
- let result;
507
506
508
- do {
507
+ while (
508
+ ${ this . max !== undefined ? `&& values.length < ${ this . max } ` : `true` }
509
+ ) {
509
510
let r = remainder;
510
511
${
511
512
this . delimiter
512
513
? `
513
514
if (values.length > 0) {
514
- result = ${ this . delimiter . toCode ( ) } (r);
515
-
515
+ const result = ${ this . delimiter . toCode ( ) } (r);
516
+ failedExpectations.push(...result.failedExpectations);
516
517
if (result.success === false) {
517
518
break;
518
519
}
@@ -522,23 +523,23 @@ function toTypeScript(
522
523
: ``
523
524
}
524
525
525
- result = ${ this . func . toCode ( ) } (r);
526
+ const result = ${ this . func . toCode ( ) } (r);
526
527
failedExpectations.push(...result.failedExpectations);
527
528
if (result.success === false) {
528
529
break;
529
530
}
530
531
531
532
remainder = result.remainder;
532
533
values.push(result.value);
533
- } while ( ${ this . max !== undefined ? `values.length < ${ this . max } ` : `true` } );
534
+ }
534
535
535
536
${
536
537
this . min
537
- ? `if (values.length < ${ this . min } && result.success === false /* technically redundant */ ) {
538
- return { success: false, remainder: result .remainder, failedExpectations };
539
- } else {
540
- return { success: true, value: values, remainder, failedExpectations };
541
- } `
538
+ ? `if (values.length < ${ this . min } ) {
539
+ return { success: false, remainder: ${ this . remainder . toCode ( ) } , failedExpectations };
540
+ }
541
+
542
+ return { success: true, value: values, remainder, failedExpectations }; `
542
543
: `return { success: true, value: values, remainder, failedExpectations };`
543
544
} `;
544
545
}
@@ -2193,14 +2194,14 @@ function toTypeScript(
2193
2194
remainder: ${ this . remainder . toCode ( ) } ,
2194
2195
failedExpectations: [],
2195
2196
}
2196
- } else {
2197
- return {
2198
- success: true,
2199
- value: undefined,
2200
- remainder: ${ this . remainder . toCode ( ) } ,
2201
- failedExpectations: [],
2202
- };
2203
2197
}
2198
+
2199
+ return {
2200
+ success: true,
2201
+ value: undefined,
2202
+ remainder: ${ this . remainder . toCode ( ) } ,
2203
+ failedExpectations: [],
2204
+ };
2204
2205
})()
2205
2206
` ;
2206
2207
}
@@ -2265,12 +2266,12 @@ function toTypeScript(
2265
2266
remainder: ${ this . value . toCode ( ) } .slice(matches[0].length),
2266
2267
failedExpectations: [],
2267
2268
};
2268
- } else {
2269
- return {
2270
- success: false,
2271
- remainder: ${ this . value . toCode ( ) } ,
2272
- failedExpectations: [ ${ failedExpectations . map ( ( e ) => e . toCode ( ) ) . join ( ) } ] ,
2273
- }
2269
+ }
2270
+
2271
+ return {
2272
+ success: false ,
2273
+ remainder: ${ this . value . toCode ( ) } ,
2274
+ failedExpectations: [ ${ failedExpectations . map ( ( e ) => e . toCode ( ) ) . join ( ) } ],
2274
2275
}
2275
2276
` ;
2276
2277
}
@@ -2317,9 +2318,9 @@ function toTypeScript(
2317
2318
remainder: result.remainder,
2318
2319
failedExpectations: result.failedExpectations,
2319
2320
}
2320
- } else {
2321
- return result;
2322
2321
}
2322
+
2323
+ return result;
2323
2324
` ;
2324
2325
}
2325
2326
@@ -2533,9 +2534,9 @@ function toTypeScript(
2533
2534
return `
2534
2535
if (${ this . condition . toCode ( ) } ) {
2535
2536
${ new Return ( this . ifTrue ) . toCode ( ) } ;
2536
- } else {
2537
- ${ new Return ( this . elseFalse ) . toCode ( ) } ;
2538
2537
}
2538
+
2539
+ ${ new Return ( this . elseFalse ) . toCode ( ) } ;
2539
2540
` ;
2540
2541
}
2541
2542
@@ -3117,9 +3118,9 @@ function toTypeScript(
3117
3118
remainder: result${ i } .remainder,
3118
3119
failedExpectations,
3119
3120
}
3120
- } else {
3121
- remainder = result${ i } .remainder;
3122
3121
}
3122
+
3123
+ remainder = result${ i } .remainder;
3123
3124
` ;
3124
3125
} else {
3125
3126
const failedExpectations = e . expectations . map (
@@ -3136,9 +3137,9 @@ function toTypeScript(
3136
3137
remainder,
3137
3138
failedExpectations,
3138
3139
}
3139
- } else {
3140
- remainder = remainder.slice(result${ i } [0].length);
3141
3140
}
3141
+
3142
+ remainder = remainder.slice(result${ i } [0].length);
3142
3143
` ;
3143
3144
}
3144
3145
} )
@@ -3219,33 +3220,33 @@ function toTypeScript(
3219
3220
3220
3221
if (result.success === true) {
3221
3222
return result.value;
3222
- } else {
3223
- let remainder = input;
3224
- let failedExpectations: runtime.FailedExpectation[] = [];
3223
+ }
3225
3224
3226
- for (const e of result.failedExpectations) {
3227
- if (e.remainder.length < remainder.length) {
3228
- remainder = e.remainder;
3229
- failedExpectations = [];
3230
- }
3225
+ let remainder = input;
3226
+ let failedExpectations: runtime.FailedExpectation[] = [];
3231
3227
3232
- if (e.remainder.length === remainder.length) {
3233
- failedExpectations.push(e);
3234
- }
3228
+ for (const e of result.failedExpectations) {
3229
+ if (e.remainder.length < remainder.length) {
3230
+ remainder = e.remainder;
3231
+ failedExpectations = [];
3235
3232
}
3236
3233
3237
- throw new SyntaxError(
3238
- failedExpectations.map(e => e.expectation),
3239
- remainder.slice(0, 1),
3240
- runtime.getLocation(
3241
- parse$source,
3242
- input,
3243
- remainder,
3244
- remainder
3245
- )
3246
- );
3234
+ if (e.remainder.length === remainder.length) {
3235
+ failedExpectations.push(e);
3236
+ }
3247
3237
}
3248
3238
3239
+ throw new ParseSyntaxError(
3240
+ failedExpectations.map(e => e.expectation),
3241
+ remainder.slice(0, 1),
3242
+ runtime.getLocation(
3243
+ parse$source,
3244
+ input,
3245
+ remainder,
3246
+ remainder
3247
+ )
3248
+ );
3249
+
3249
3250
${ reusables
3250
3251
. filter ( ( r ) => r instanceof Code )
3251
3252
. filter ( ( r ) => referencedNodes . includes ( r ) )
0 commit comments