webpipe-js 2.0.65 → 2.0.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +74 -30
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.mjs +74 -30
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -152,6 +152,7 @@ var Parser = class {
|
|
|
152
152
|
parseProgram() {
|
|
153
153
|
this.skipWhitespaceOnly();
|
|
154
154
|
const configs = [];
|
|
155
|
+
const imports = [];
|
|
155
156
|
const pipelines = [];
|
|
156
157
|
const variables = [];
|
|
157
158
|
const routes = [];
|
|
@@ -178,6 +179,15 @@ var Parser = class {
|
|
|
178
179
|
configs.push(cfg);
|
|
179
180
|
continue;
|
|
180
181
|
}
|
|
182
|
+
const importStmt = this.tryParse(() => this.parseImport());
|
|
183
|
+
if (importStmt) {
|
|
184
|
+
const duplicateAlias = imports.find((i) => i.alias === importStmt.alias);
|
|
185
|
+
if (duplicateAlias) {
|
|
186
|
+
this.report(`Duplicate import alias '${importStmt.alias}'`, importStmt.start, importStmt.end, "error");
|
|
187
|
+
}
|
|
188
|
+
imports.push(importStmt);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
181
191
|
const schema = this.tryParse(() => this.parseGraphQLSchema());
|
|
182
192
|
if (schema) {
|
|
183
193
|
schema.lineNumber = this.getLineNumber(start);
|
|
@@ -246,7 +256,7 @@ var Parser = class {
|
|
|
246
256
|
const start = Math.max(0, idx);
|
|
247
257
|
this.report("Unclosed backtick-delimited string", start, start + 1, "warning");
|
|
248
258
|
}
|
|
249
|
-
return { configs, pipelines, variables, routes, describes, comments, graphqlSchema, queries, mutations, resolvers, featureFlags };
|
|
259
|
+
return { configs, imports, pipelines, variables, routes, describes, comments, graphqlSchema, queries, mutations, resolvers, featureFlags };
|
|
250
260
|
}
|
|
251
261
|
eof() {
|
|
252
262
|
return this.pos >= this.len;
|
|
@@ -489,6 +499,30 @@ var Parser = class {
|
|
|
489
499
|
const end = this.pos;
|
|
490
500
|
return { name, properties, inlineComment: inlineComment || void 0, start, end };
|
|
491
501
|
}
|
|
502
|
+
parseImport() {
|
|
503
|
+
const start = this.pos;
|
|
504
|
+
this.expect("import");
|
|
505
|
+
this.skipInlineSpaces();
|
|
506
|
+
this.expect('"');
|
|
507
|
+
const path = this.consumeWhile((c) => c !== '"');
|
|
508
|
+
this.expect('"');
|
|
509
|
+
this.skipInlineSpaces();
|
|
510
|
+
this.expect("as");
|
|
511
|
+
this.skipInlineSpaces();
|
|
512
|
+
const alias = this.parseIdentifier();
|
|
513
|
+
this.skipWhitespaceOnly();
|
|
514
|
+
const end = this.pos;
|
|
515
|
+
return { path, alias, start, end };
|
|
516
|
+
}
|
|
517
|
+
parseScopedIdentifier() {
|
|
518
|
+
const first = this.parseIdentifier();
|
|
519
|
+
if (this.text.startsWith("::", this.pos)) {
|
|
520
|
+
this.pos += 2;
|
|
521
|
+
const second = this.parseIdentifier();
|
|
522
|
+
return `${first}::${second}`;
|
|
523
|
+
}
|
|
524
|
+
return first;
|
|
525
|
+
}
|
|
492
526
|
parsePipelineStep() {
|
|
493
527
|
const result = this.tryParse(() => this.parseResultStep());
|
|
494
528
|
if (result) return result;
|
|
@@ -798,20 +832,20 @@ var Parser = class {
|
|
|
798
832
|
this.expect("|>");
|
|
799
833
|
this.skipInlineSpaces();
|
|
800
834
|
this.expect("dispatch");
|
|
801
|
-
this.
|
|
835
|
+
this.skipWhitespaceOnly();
|
|
802
836
|
const branches = [];
|
|
803
837
|
while (true) {
|
|
804
838
|
const branch = this.tryParse(() => this.parseDispatchBranch());
|
|
805
839
|
if (!branch) break;
|
|
806
840
|
branches.push(branch);
|
|
807
|
-
this.
|
|
841
|
+
this.skipWhitespaceOnly();
|
|
808
842
|
}
|
|
809
843
|
const defaultBranch = this.tryParse(() => {
|
|
810
844
|
this.expect("default:");
|
|
811
|
-
this.
|
|
845
|
+
this.skipWhitespaceOnly();
|
|
812
846
|
return this.parseIfPipeline("end");
|
|
813
847
|
});
|
|
814
|
-
this.
|
|
848
|
+
this.skipWhitespaceOnly();
|
|
815
849
|
this.tryParse(() => {
|
|
816
850
|
this.expect("end");
|
|
817
851
|
return true;
|
|
@@ -820,14 +854,14 @@ var Parser = class {
|
|
|
820
854
|
return { kind: "Dispatch", branches, default: defaultBranch || void 0, start, end };
|
|
821
855
|
}
|
|
822
856
|
parseDispatchBranch() {
|
|
823
|
-
this.
|
|
857
|
+
this.skipWhitespaceOnly();
|
|
824
858
|
const start = this.pos;
|
|
825
859
|
this.expect("case");
|
|
826
860
|
this.skipInlineSpaces();
|
|
827
861
|
const condition = this.parseTagExpr();
|
|
828
862
|
this.skipInlineSpaces();
|
|
829
863
|
this.expect(":");
|
|
830
|
-
this.
|
|
864
|
+
this.skipWhitespaceOnly();
|
|
831
865
|
const pipeline = this.parseIfPipeline("case", "default:", "end");
|
|
832
866
|
const end = this.pos;
|
|
833
867
|
return { condition, pipeline, start, end };
|
|
@@ -1185,8 +1219,8 @@ var Parser = class {
|
|
|
1185
1219
|
}
|
|
1186
1220
|
this.skipInlineSpaces();
|
|
1187
1221
|
const value2 = (() => {
|
|
1188
|
-
const
|
|
1189
|
-
if (
|
|
1222
|
+
const v12 = this.tryParse(() => this.parseBacktickString());
|
|
1223
|
+
if (v12 !== null) return v12;
|
|
1190
1224
|
const v2 = this.tryParse(() => this.parseQuotedString());
|
|
1191
1225
|
if (v2 !== null) return v2;
|
|
1192
1226
|
return this.consumeWhile((c) => c !== "\n");
|
|
@@ -1234,8 +1268,8 @@ var Parser = class {
|
|
|
1234
1268
|
comparison2 = this.consumeWhile((c) => c !== " " && c !== "\n");
|
|
1235
1269
|
this.skipInlineSpaces();
|
|
1236
1270
|
value2 = (() => {
|
|
1237
|
-
const
|
|
1238
|
-
if (
|
|
1271
|
+
const v12 = this.tryParse(() => this.parseBacktickString());
|
|
1272
|
+
if (v12 !== null) return v12;
|
|
1239
1273
|
const v2 = this.tryParse(() => this.parseQuotedString());
|
|
1240
1274
|
if (v2 !== null) return v2;
|
|
1241
1275
|
return this.consumeWhile((c) => c !== "\n");
|
|
@@ -1263,8 +1297,8 @@ var Parser = class {
|
|
|
1263
1297
|
comparison2 = this.consumeWhile((c) => c !== " " && c !== "\n");
|
|
1264
1298
|
this.skipInlineSpaces();
|
|
1265
1299
|
value2 = (() => {
|
|
1266
|
-
const
|
|
1267
|
-
if (
|
|
1300
|
+
const v12 = this.tryParse(() => this.parseBacktickString());
|
|
1301
|
+
if (v12 !== null) return v12;
|
|
1268
1302
|
const v2 = this.tryParse(() => this.parseQuotedString());
|
|
1269
1303
|
if (v2 !== null) return v2;
|
|
1270
1304
|
return this.consumeWhile((c) => c !== "\n");
|
|
@@ -1302,15 +1336,24 @@ var Parser = class {
|
|
|
1302
1336
|
this.skipInlineSpaces();
|
|
1303
1337
|
const comparison = this.consumeWhile((c) => c !== " " && c !== "\n");
|
|
1304
1338
|
this.skipInlineSpaces();
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1339
|
+
let value;
|
|
1340
|
+
let valueFormat;
|
|
1341
|
+
const v1 = this.tryParse(() => this.parseBacktickString());
|
|
1342
|
+
if (v1 !== null) {
|
|
1343
|
+
value = v1;
|
|
1344
|
+
valueFormat = "backtick";
|
|
1345
|
+
} else {
|
|
1308
1346
|
const v2 = this.tryParse(() => this.parseQuotedString());
|
|
1309
|
-
if (v2 !== null)
|
|
1310
|
-
|
|
1311
|
-
|
|
1347
|
+
if (v2 !== null) {
|
|
1348
|
+
value = v2;
|
|
1349
|
+
valueFormat = "quoted";
|
|
1350
|
+
} else {
|
|
1351
|
+
value = this.consumeWhile((c) => c !== "\n");
|
|
1352
|
+
valueFormat = "bare";
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1312
1355
|
const end = this.pos;
|
|
1313
|
-
return { conditionType: ct, field, headerName: headerName ?? void 0, jqExpr: jqExpr ?? void 0, comparison, value, start, end };
|
|
1356
|
+
return { conditionType: ct, field, headerName: headerName ?? void 0, jqExpr: jqExpr ?? void 0, comparison, value, valueFormat, start, end };
|
|
1314
1357
|
}
|
|
1315
1358
|
parseMockHead(prefixWord) {
|
|
1316
1359
|
const start = this.pos;
|
|
@@ -1758,6 +1801,13 @@ function printMock(mock, indent = " ") {
|
|
|
1758
1801
|
function printCondition(condition, indent = " ") {
|
|
1759
1802
|
const condType = condition.conditionType.toLowerCase();
|
|
1760
1803
|
const formatConditionValue = (val) => {
|
|
1804
|
+
if (condition.valueFormat) {
|
|
1805
|
+
if (condition.valueFormat === "quoted") return `"${val}"`;
|
|
1806
|
+
if (condition.valueFormat === "backtick") return `\`${val}\``;
|
|
1807
|
+
const isBareTemplate2 = /^\{\{[^}]+\}\}$/.test(val);
|
|
1808
|
+
if (isBareTemplate2) return val;
|
|
1809
|
+
return val;
|
|
1810
|
+
}
|
|
1761
1811
|
if (val.startsWith("`") || val.startsWith('"')) return val;
|
|
1762
1812
|
const isBareTemplate = /^\{\{[^}]+\}\}$/.test(val);
|
|
1763
1813
|
if (isBareTemplate) return val;
|
|
@@ -2083,16 +2133,10 @@ function formatPipelineStep(step, indent = " ", isLastStep = false) {
|
|
|
2083
2133
|
} else if (step.kind === "Dispatch") {
|
|
2084
2134
|
const lines = [`${indent}|> dispatch`];
|
|
2085
2135
|
step.branches.forEach((branch) => {
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
} else {
|
|
2091
|
-
lines.push(`${indent} case ${formatTagExpr(branch.condition)}:`);
|
|
2092
|
-
branch.pipeline.steps.forEach((branchStep) => {
|
|
2093
|
-
lines.push(formatPipelineStep(branchStep, indent + " "));
|
|
2094
|
-
});
|
|
2095
|
-
}
|
|
2136
|
+
lines.push(`${indent} case ${formatTagExpr(branch.condition)}:`);
|
|
2137
|
+
branch.pipeline.steps.forEach((branchStep) => {
|
|
2138
|
+
lines.push(formatPipelineStep(branchStep, indent + " "));
|
|
2139
|
+
});
|
|
2096
2140
|
});
|
|
2097
2141
|
if (step.default) {
|
|
2098
2142
|
lines.push(`${indent} default:`);
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
interface Import {
|
|
2
|
+
path: string;
|
|
3
|
+
alias: string;
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
}
|
|
1
7
|
interface Program {
|
|
2
8
|
configs: Config[];
|
|
9
|
+
imports: Import[];
|
|
3
10
|
pipelines: NamedPipeline[];
|
|
4
11
|
variables: Variable[];
|
|
5
12
|
routes: Route[];
|
|
@@ -285,6 +292,7 @@ interface Condition {
|
|
|
285
292
|
jqExpr?: string;
|
|
286
293
|
comparison: string;
|
|
287
294
|
value: string;
|
|
295
|
+
valueFormat?: 'quoted' | 'backtick' | 'bare';
|
|
288
296
|
isCallAssertion?: boolean;
|
|
289
297
|
callTarget?: string;
|
|
290
298
|
selector?: string;
|
|
@@ -348,4 +356,4 @@ declare function formatTagExpr(expr: TagExpr): string;
|
|
|
348
356
|
declare function formatPipelineRef(ref: PipelineRef): string[];
|
|
349
357
|
declare function formatWhen(when: When): string;
|
|
350
358
|
|
|
351
|
-
export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type DispatchBranch, type DomAssertType, type GraphQLSchema, type It, type LetValueFormat, type LetVariable, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type Tag, type TagExpr, type TestLetVariable, type TypeResolver, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTagExpr, formatTags, formatWhen, getPipelineRanges, getTestLetVariableRanges, getTestLetVariables, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printFeatureFlags, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printTypeResolver, printVariable };
|
|
359
|
+
export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type DispatchBranch, type DomAssertType, type GraphQLSchema, type Import, type It, type LetValueFormat, type LetVariable, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type Tag, type TagExpr, type TestLetVariable, type TypeResolver, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTagExpr, formatTags, formatWhen, getPipelineRanges, getTestLetVariableRanges, getTestLetVariables, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printFeatureFlags, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printTypeResolver, printVariable };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
interface Import {
|
|
2
|
+
path: string;
|
|
3
|
+
alias: string;
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
}
|
|
1
7
|
interface Program {
|
|
2
8
|
configs: Config[];
|
|
9
|
+
imports: Import[];
|
|
3
10
|
pipelines: NamedPipeline[];
|
|
4
11
|
variables: Variable[];
|
|
5
12
|
routes: Route[];
|
|
@@ -285,6 +292,7 @@ interface Condition {
|
|
|
285
292
|
jqExpr?: string;
|
|
286
293
|
comparison: string;
|
|
287
294
|
value: string;
|
|
295
|
+
valueFormat?: 'quoted' | 'backtick' | 'bare';
|
|
288
296
|
isCallAssertion?: boolean;
|
|
289
297
|
callTarget?: string;
|
|
290
298
|
selector?: string;
|
|
@@ -348,4 +356,4 @@ declare function formatTagExpr(expr: TagExpr): string;
|
|
|
348
356
|
declare function formatPipelineRef(ref: PipelineRef): string[];
|
|
349
357
|
declare function formatWhen(when: When): string;
|
|
350
358
|
|
|
351
|
-
export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type DispatchBranch, type DomAssertType, type GraphQLSchema, type It, type LetValueFormat, type LetVariable, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type Tag, type TagExpr, type TestLetVariable, type TypeResolver, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTagExpr, formatTags, formatWhen, getPipelineRanges, getTestLetVariableRanges, getTestLetVariables, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printFeatureFlags, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printTypeResolver, printVariable };
|
|
359
|
+
export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type DispatchBranch, type DomAssertType, type GraphQLSchema, type Import, type It, type LetValueFormat, type LetVariable, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type Tag, type TagExpr, type TestLetVariable, type TypeResolver, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTagExpr, formatTags, formatWhen, getPipelineRanges, getTestLetVariableRanges, getTestLetVariables, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printFeatureFlags, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printTypeResolver, printVariable };
|
package/dist/index.mjs
CHANGED
|
@@ -98,6 +98,7 @@ var Parser = class {
|
|
|
98
98
|
parseProgram() {
|
|
99
99
|
this.skipWhitespaceOnly();
|
|
100
100
|
const configs = [];
|
|
101
|
+
const imports = [];
|
|
101
102
|
const pipelines = [];
|
|
102
103
|
const variables = [];
|
|
103
104
|
const routes = [];
|
|
@@ -124,6 +125,15 @@ var Parser = class {
|
|
|
124
125
|
configs.push(cfg);
|
|
125
126
|
continue;
|
|
126
127
|
}
|
|
128
|
+
const importStmt = this.tryParse(() => this.parseImport());
|
|
129
|
+
if (importStmt) {
|
|
130
|
+
const duplicateAlias = imports.find((i) => i.alias === importStmt.alias);
|
|
131
|
+
if (duplicateAlias) {
|
|
132
|
+
this.report(`Duplicate import alias '${importStmt.alias}'`, importStmt.start, importStmt.end, "error");
|
|
133
|
+
}
|
|
134
|
+
imports.push(importStmt);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
127
137
|
const schema = this.tryParse(() => this.parseGraphQLSchema());
|
|
128
138
|
if (schema) {
|
|
129
139
|
schema.lineNumber = this.getLineNumber(start);
|
|
@@ -192,7 +202,7 @@ var Parser = class {
|
|
|
192
202
|
const start = Math.max(0, idx);
|
|
193
203
|
this.report("Unclosed backtick-delimited string", start, start + 1, "warning");
|
|
194
204
|
}
|
|
195
|
-
return { configs, pipelines, variables, routes, describes, comments, graphqlSchema, queries, mutations, resolvers, featureFlags };
|
|
205
|
+
return { configs, imports, pipelines, variables, routes, describes, comments, graphqlSchema, queries, mutations, resolvers, featureFlags };
|
|
196
206
|
}
|
|
197
207
|
eof() {
|
|
198
208
|
return this.pos >= this.len;
|
|
@@ -435,6 +445,30 @@ var Parser = class {
|
|
|
435
445
|
const end = this.pos;
|
|
436
446
|
return { name, properties, inlineComment: inlineComment || void 0, start, end };
|
|
437
447
|
}
|
|
448
|
+
parseImport() {
|
|
449
|
+
const start = this.pos;
|
|
450
|
+
this.expect("import");
|
|
451
|
+
this.skipInlineSpaces();
|
|
452
|
+
this.expect('"');
|
|
453
|
+
const path = this.consumeWhile((c) => c !== '"');
|
|
454
|
+
this.expect('"');
|
|
455
|
+
this.skipInlineSpaces();
|
|
456
|
+
this.expect("as");
|
|
457
|
+
this.skipInlineSpaces();
|
|
458
|
+
const alias = this.parseIdentifier();
|
|
459
|
+
this.skipWhitespaceOnly();
|
|
460
|
+
const end = this.pos;
|
|
461
|
+
return { path, alias, start, end };
|
|
462
|
+
}
|
|
463
|
+
parseScopedIdentifier() {
|
|
464
|
+
const first = this.parseIdentifier();
|
|
465
|
+
if (this.text.startsWith("::", this.pos)) {
|
|
466
|
+
this.pos += 2;
|
|
467
|
+
const second = this.parseIdentifier();
|
|
468
|
+
return `${first}::${second}`;
|
|
469
|
+
}
|
|
470
|
+
return first;
|
|
471
|
+
}
|
|
438
472
|
parsePipelineStep() {
|
|
439
473
|
const result = this.tryParse(() => this.parseResultStep());
|
|
440
474
|
if (result) return result;
|
|
@@ -744,20 +778,20 @@ var Parser = class {
|
|
|
744
778
|
this.expect("|>");
|
|
745
779
|
this.skipInlineSpaces();
|
|
746
780
|
this.expect("dispatch");
|
|
747
|
-
this.
|
|
781
|
+
this.skipWhitespaceOnly();
|
|
748
782
|
const branches = [];
|
|
749
783
|
while (true) {
|
|
750
784
|
const branch = this.tryParse(() => this.parseDispatchBranch());
|
|
751
785
|
if (!branch) break;
|
|
752
786
|
branches.push(branch);
|
|
753
|
-
this.
|
|
787
|
+
this.skipWhitespaceOnly();
|
|
754
788
|
}
|
|
755
789
|
const defaultBranch = this.tryParse(() => {
|
|
756
790
|
this.expect("default:");
|
|
757
|
-
this.
|
|
791
|
+
this.skipWhitespaceOnly();
|
|
758
792
|
return this.parseIfPipeline("end");
|
|
759
793
|
});
|
|
760
|
-
this.
|
|
794
|
+
this.skipWhitespaceOnly();
|
|
761
795
|
this.tryParse(() => {
|
|
762
796
|
this.expect("end");
|
|
763
797
|
return true;
|
|
@@ -766,14 +800,14 @@ var Parser = class {
|
|
|
766
800
|
return { kind: "Dispatch", branches, default: defaultBranch || void 0, start, end };
|
|
767
801
|
}
|
|
768
802
|
parseDispatchBranch() {
|
|
769
|
-
this.
|
|
803
|
+
this.skipWhitespaceOnly();
|
|
770
804
|
const start = this.pos;
|
|
771
805
|
this.expect("case");
|
|
772
806
|
this.skipInlineSpaces();
|
|
773
807
|
const condition = this.parseTagExpr();
|
|
774
808
|
this.skipInlineSpaces();
|
|
775
809
|
this.expect(":");
|
|
776
|
-
this.
|
|
810
|
+
this.skipWhitespaceOnly();
|
|
777
811
|
const pipeline = this.parseIfPipeline("case", "default:", "end");
|
|
778
812
|
const end = this.pos;
|
|
779
813
|
return { condition, pipeline, start, end };
|
|
@@ -1131,8 +1165,8 @@ var Parser = class {
|
|
|
1131
1165
|
}
|
|
1132
1166
|
this.skipInlineSpaces();
|
|
1133
1167
|
const value2 = (() => {
|
|
1134
|
-
const
|
|
1135
|
-
if (
|
|
1168
|
+
const v12 = this.tryParse(() => this.parseBacktickString());
|
|
1169
|
+
if (v12 !== null) return v12;
|
|
1136
1170
|
const v2 = this.tryParse(() => this.parseQuotedString());
|
|
1137
1171
|
if (v2 !== null) return v2;
|
|
1138
1172
|
return this.consumeWhile((c) => c !== "\n");
|
|
@@ -1180,8 +1214,8 @@ var Parser = class {
|
|
|
1180
1214
|
comparison2 = this.consumeWhile((c) => c !== " " && c !== "\n");
|
|
1181
1215
|
this.skipInlineSpaces();
|
|
1182
1216
|
value2 = (() => {
|
|
1183
|
-
const
|
|
1184
|
-
if (
|
|
1217
|
+
const v12 = this.tryParse(() => this.parseBacktickString());
|
|
1218
|
+
if (v12 !== null) return v12;
|
|
1185
1219
|
const v2 = this.tryParse(() => this.parseQuotedString());
|
|
1186
1220
|
if (v2 !== null) return v2;
|
|
1187
1221
|
return this.consumeWhile((c) => c !== "\n");
|
|
@@ -1209,8 +1243,8 @@ var Parser = class {
|
|
|
1209
1243
|
comparison2 = this.consumeWhile((c) => c !== " " && c !== "\n");
|
|
1210
1244
|
this.skipInlineSpaces();
|
|
1211
1245
|
value2 = (() => {
|
|
1212
|
-
const
|
|
1213
|
-
if (
|
|
1246
|
+
const v12 = this.tryParse(() => this.parseBacktickString());
|
|
1247
|
+
if (v12 !== null) return v12;
|
|
1214
1248
|
const v2 = this.tryParse(() => this.parseQuotedString());
|
|
1215
1249
|
if (v2 !== null) return v2;
|
|
1216
1250
|
return this.consumeWhile((c) => c !== "\n");
|
|
@@ -1248,15 +1282,24 @@ var Parser = class {
|
|
|
1248
1282
|
this.skipInlineSpaces();
|
|
1249
1283
|
const comparison = this.consumeWhile((c) => c !== " " && c !== "\n");
|
|
1250
1284
|
this.skipInlineSpaces();
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1285
|
+
let value;
|
|
1286
|
+
let valueFormat;
|
|
1287
|
+
const v1 = this.tryParse(() => this.parseBacktickString());
|
|
1288
|
+
if (v1 !== null) {
|
|
1289
|
+
value = v1;
|
|
1290
|
+
valueFormat = "backtick";
|
|
1291
|
+
} else {
|
|
1254
1292
|
const v2 = this.tryParse(() => this.parseQuotedString());
|
|
1255
|
-
if (v2 !== null)
|
|
1256
|
-
|
|
1257
|
-
|
|
1293
|
+
if (v2 !== null) {
|
|
1294
|
+
value = v2;
|
|
1295
|
+
valueFormat = "quoted";
|
|
1296
|
+
} else {
|
|
1297
|
+
value = this.consumeWhile((c) => c !== "\n");
|
|
1298
|
+
valueFormat = "bare";
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1258
1301
|
const end = this.pos;
|
|
1259
|
-
return { conditionType: ct, field, headerName: headerName ?? void 0, jqExpr: jqExpr ?? void 0, comparison, value, start, end };
|
|
1302
|
+
return { conditionType: ct, field, headerName: headerName ?? void 0, jqExpr: jqExpr ?? void 0, comparison, value, valueFormat, start, end };
|
|
1260
1303
|
}
|
|
1261
1304
|
parseMockHead(prefixWord) {
|
|
1262
1305
|
const start = this.pos;
|
|
@@ -1704,6 +1747,13 @@ function printMock(mock, indent = " ") {
|
|
|
1704
1747
|
function printCondition(condition, indent = " ") {
|
|
1705
1748
|
const condType = condition.conditionType.toLowerCase();
|
|
1706
1749
|
const formatConditionValue = (val) => {
|
|
1750
|
+
if (condition.valueFormat) {
|
|
1751
|
+
if (condition.valueFormat === "quoted") return `"${val}"`;
|
|
1752
|
+
if (condition.valueFormat === "backtick") return `\`${val}\``;
|
|
1753
|
+
const isBareTemplate2 = /^\{\{[^}]+\}\}$/.test(val);
|
|
1754
|
+
if (isBareTemplate2) return val;
|
|
1755
|
+
return val;
|
|
1756
|
+
}
|
|
1707
1757
|
if (val.startsWith("`") || val.startsWith('"')) return val;
|
|
1708
1758
|
const isBareTemplate = /^\{\{[^}]+\}\}$/.test(val);
|
|
1709
1759
|
if (isBareTemplate) return val;
|
|
@@ -2029,16 +2079,10 @@ function formatPipelineStep(step, indent = " ", isLastStep = false) {
|
|
|
2029
2079
|
} else if (step.kind === "Dispatch") {
|
|
2030
2080
|
const lines = [`${indent}|> dispatch`];
|
|
2031
2081
|
step.branches.forEach((branch) => {
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
} else {
|
|
2037
|
-
lines.push(`${indent} case ${formatTagExpr(branch.condition)}:`);
|
|
2038
|
-
branch.pipeline.steps.forEach((branchStep) => {
|
|
2039
|
-
lines.push(formatPipelineStep(branchStep, indent + " "));
|
|
2040
|
-
});
|
|
2041
|
-
}
|
|
2082
|
+
lines.push(`${indent} case ${formatTagExpr(branch.condition)}:`);
|
|
2083
|
+
branch.pipeline.steps.forEach((branchStep) => {
|
|
2084
|
+
lines.push(formatPipelineStep(branchStep, indent + " "));
|
|
2085
|
+
});
|
|
2042
2086
|
});
|
|
2043
2087
|
if (step.default) {
|
|
2044
2088
|
lines.push(`${indent} default:`);
|