webpipe-js 0.1.9 → 0.1.11
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 +131 -25
- package/dist/index.d.cts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.mjs +130 -25
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -30,6 +30,7 @@ __export(index_exports, {
|
|
|
30
30
|
parseProgram: () => parseProgram,
|
|
31
31
|
parseProgramWithDiagnostics: () => parseProgramWithDiagnostics,
|
|
32
32
|
prettyPrint: () => prettyPrint,
|
|
33
|
+
printComment: () => printComment,
|
|
33
34
|
printCondition: () => printCondition,
|
|
34
35
|
printConfig: () => printConfig,
|
|
35
36
|
printDescribe: () => printDescribe,
|
|
@@ -76,17 +77,74 @@ var Parser = class {
|
|
|
76
77
|
getLineNumber(pos) {
|
|
77
78
|
return this.text.slice(0, pos).split("\n").length;
|
|
78
79
|
}
|
|
80
|
+
parseInlineComment() {
|
|
81
|
+
this.skipInlineSpaces();
|
|
82
|
+
const start = this.pos;
|
|
83
|
+
if (this.text.startsWith("#", this.pos)) {
|
|
84
|
+
this.pos++;
|
|
85
|
+
const text = this.consumeWhile((ch) => ch !== "\n");
|
|
86
|
+
return {
|
|
87
|
+
type: "inline",
|
|
88
|
+
text,
|
|
89
|
+
style: "#",
|
|
90
|
+
lineNumber: this.getLineNumber(start)
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (this.text.startsWith("//", this.pos)) {
|
|
94
|
+
this.pos += 2;
|
|
95
|
+
const text = this.consumeWhile((ch) => ch !== "\n");
|
|
96
|
+
return {
|
|
97
|
+
type: "inline",
|
|
98
|
+
text,
|
|
99
|
+
style: "//",
|
|
100
|
+
lineNumber: this.getLineNumber(start)
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
parseStandaloneComment() {
|
|
106
|
+
const start = this.pos;
|
|
107
|
+
if (this.text.startsWith("#", this.pos)) {
|
|
108
|
+
const originalPos = this.pos;
|
|
109
|
+
this.pos++;
|
|
110
|
+
const restOfLine = this.consumeWhile((ch) => ch !== "\n");
|
|
111
|
+
return {
|
|
112
|
+
type: "standalone",
|
|
113
|
+
text: restOfLine,
|
|
114
|
+
style: "#",
|
|
115
|
+
lineNumber: this.getLineNumber(start)
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (this.text.startsWith("//", this.pos)) {
|
|
119
|
+
this.pos += 2;
|
|
120
|
+
const text = this.consumeWhile((ch) => ch !== "\n");
|
|
121
|
+
return {
|
|
122
|
+
type: "standalone",
|
|
123
|
+
text,
|
|
124
|
+
style: "//",
|
|
125
|
+
lineNumber: this.getLineNumber(start)
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
79
130
|
parseProgram() {
|
|
80
|
-
this.
|
|
131
|
+
this.skipWhitespaceOnly();
|
|
81
132
|
const configs = [];
|
|
82
133
|
const pipelines = [];
|
|
83
134
|
const variables = [];
|
|
84
135
|
const routes = [];
|
|
85
136
|
const describes = [];
|
|
137
|
+
const comments = [];
|
|
86
138
|
while (!this.eof()) {
|
|
87
|
-
this.
|
|
139
|
+
this.skipWhitespaceOnly();
|
|
88
140
|
if (this.eof()) break;
|
|
89
141
|
const start = this.pos;
|
|
142
|
+
const comment = this.tryParse(() => this.parseStandaloneComment());
|
|
143
|
+
if (comment) {
|
|
144
|
+
comments.push(comment);
|
|
145
|
+
if (this.cur() === "\n") this.pos++;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
90
148
|
const cfg = this.tryParse(() => this.parseConfig());
|
|
91
149
|
if (cfg) {
|
|
92
150
|
cfg.lineNumber = this.getLineNumber(start);
|
|
@@ -132,7 +190,7 @@ var Parser = class {
|
|
|
132
190
|
const start = Math.max(0, idx);
|
|
133
191
|
this.report("Unclosed backtick-delimited string", start, start + 1, "warning");
|
|
134
192
|
}
|
|
135
|
-
return { configs, pipelines, variables, routes, describes };
|
|
193
|
+
return { configs, pipelines, variables, routes, describes, comments };
|
|
136
194
|
}
|
|
137
195
|
eof() {
|
|
138
196
|
return this.pos >= this.len;
|
|
@@ -172,6 +230,9 @@ var Parser = class {
|
|
|
172
230
|
break;
|
|
173
231
|
}
|
|
174
232
|
}
|
|
233
|
+
skipWhitespaceOnly() {
|
|
234
|
+
this.consumeWhile((ch) => ch === " " || ch === " " || ch === "\r" || ch === "\n");
|
|
235
|
+
}
|
|
175
236
|
skipInlineSpaces() {
|
|
176
237
|
this.consumeWhile((ch) => ch === " " || ch === " " || ch === "\r");
|
|
177
238
|
}
|
|
@@ -299,6 +360,7 @@ var Parser = class {
|
|
|
299
360
|
const name = this.parseIdentifier();
|
|
300
361
|
this.skipInlineSpaces();
|
|
301
362
|
this.expect("{");
|
|
363
|
+
const inlineComment = this.parseInlineComment();
|
|
302
364
|
this.skipSpaces();
|
|
303
365
|
const properties = [];
|
|
304
366
|
while (true) {
|
|
@@ -309,8 +371,8 @@ var Parser = class {
|
|
|
309
371
|
}
|
|
310
372
|
this.skipSpaces();
|
|
311
373
|
this.expect("}");
|
|
312
|
-
this.
|
|
313
|
-
return { name, properties };
|
|
374
|
+
this.skipWhitespaceOnly();
|
|
375
|
+
return { name, properties, inlineComment: inlineComment || void 0 };
|
|
314
376
|
}
|
|
315
377
|
parsePipelineStep() {
|
|
316
378
|
const result = this.tryParse(() => this.parseResultStep());
|
|
@@ -318,22 +380,22 @@ var Parser = class {
|
|
|
318
380
|
return this.parseRegularStep();
|
|
319
381
|
}
|
|
320
382
|
parseRegularStep() {
|
|
321
|
-
this.
|
|
383
|
+
this.skipWhitespaceOnly();
|
|
322
384
|
this.expect("|>");
|
|
323
385
|
this.skipInlineSpaces();
|
|
324
386
|
const name = this.parseIdentifier();
|
|
325
387
|
this.expect(":");
|
|
326
388
|
this.skipInlineSpaces();
|
|
327
389
|
const { config, configType } = this.parseStepConfig();
|
|
328
|
-
this.
|
|
390
|
+
this.skipWhitespaceOnly();
|
|
329
391
|
return { kind: "Regular", name, config, configType };
|
|
330
392
|
}
|
|
331
393
|
parseResultStep() {
|
|
332
|
-
this.
|
|
394
|
+
this.skipWhitespaceOnly();
|
|
333
395
|
this.expect("|>");
|
|
334
396
|
this.skipInlineSpaces();
|
|
335
397
|
this.expect("result");
|
|
336
|
-
this.
|
|
398
|
+
this.skipWhitespaceOnly();
|
|
337
399
|
const branches = [];
|
|
338
400
|
while (true) {
|
|
339
401
|
const br = this.tryParse(() => this.parseResultBranch());
|
|
@@ -369,7 +431,7 @@ var Parser = class {
|
|
|
369
431
|
const steps = [];
|
|
370
432
|
while (true) {
|
|
371
433
|
const save = this.pos;
|
|
372
|
-
this.
|
|
434
|
+
this.skipWhitespaceOnly();
|
|
373
435
|
if (!this.text.startsWith("|>", this.pos)) {
|
|
374
436
|
this.pos = save;
|
|
375
437
|
break;
|
|
@@ -386,19 +448,20 @@ var Parser = class {
|
|
|
386
448
|
const name = this.parseIdentifier();
|
|
387
449
|
this.skipInlineSpaces();
|
|
388
450
|
this.expect("=");
|
|
451
|
+
const inlineComment = this.parseInlineComment();
|
|
389
452
|
this.skipInlineSpaces();
|
|
390
453
|
const beforePipeline = this.pos;
|
|
391
454
|
const pipeline = this.parsePipeline();
|
|
392
455
|
const end = this.pos;
|
|
393
456
|
this.pipelineRanges.set(name, { start, end });
|
|
394
|
-
this.
|
|
395
|
-
return { name, pipeline };
|
|
457
|
+
this.skipWhitespaceOnly();
|
|
458
|
+
return { name, pipeline, inlineComment: inlineComment || void 0 };
|
|
396
459
|
}
|
|
397
460
|
parsePipelineRef() {
|
|
398
461
|
const inline = this.tryParse(() => this.parsePipeline());
|
|
399
462
|
if (inline && inline.steps.length > 0) return { kind: "Inline", pipeline: inline };
|
|
400
463
|
const named = this.tryParse(() => {
|
|
401
|
-
this.
|
|
464
|
+
this.skipWhitespaceOnly();
|
|
402
465
|
this.expect("|>");
|
|
403
466
|
this.skipInlineSpaces();
|
|
404
467
|
this.expect("pipeline:");
|
|
@@ -418,19 +481,21 @@ var Parser = class {
|
|
|
418
481
|
this.expect("=");
|
|
419
482
|
this.skipInlineSpaces();
|
|
420
483
|
const value = this.parseBacktickString();
|
|
484
|
+
const inlineComment = this.parseInlineComment();
|
|
421
485
|
const end = this.pos;
|
|
422
486
|
this.variableRanges.set(`${varType}::${name}`, { start, end });
|
|
423
|
-
this.
|
|
424
|
-
return { varType, name, value };
|
|
487
|
+
this.skipWhitespaceOnly();
|
|
488
|
+
return { varType, name, value, inlineComment: inlineComment || void 0 };
|
|
425
489
|
}
|
|
426
490
|
parseRoute() {
|
|
427
491
|
const method = this.parseMethod();
|
|
428
492
|
this.skipInlineSpaces();
|
|
429
|
-
const path = this.consumeWhile((c) => c !== " " && c !== "\n");
|
|
493
|
+
const path = this.consumeWhile((c) => c !== " " && c !== "\n" && c !== "#");
|
|
494
|
+
const inlineComment = this.parseInlineComment();
|
|
430
495
|
this.skipSpaces();
|
|
431
496
|
const pipeline = this.parsePipelineRef();
|
|
432
|
-
this.
|
|
433
|
-
return { method, path, pipeline };
|
|
497
|
+
this.skipWhitespaceOnly();
|
|
498
|
+
return { method, path, pipeline, inlineComment: inlineComment || void 0 };
|
|
434
499
|
}
|
|
435
500
|
parseWhen() {
|
|
436
501
|
const calling = this.tryParse(() => {
|
|
@@ -556,6 +621,7 @@ var Parser = class {
|
|
|
556
621
|
this.expect('"');
|
|
557
622
|
const name = this.consumeWhile((c) => c !== '"');
|
|
558
623
|
this.expect('"');
|
|
624
|
+
const inlineComment = this.parseInlineComment();
|
|
559
625
|
this.skipSpaces();
|
|
560
626
|
const mocks = [];
|
|
561
627
|
while (true) {
|
|
@@ -570,7 +636,7 @@ var Parser = class {
|
|
|
570
636
|
if (!it) break;
|
|
571
637
|
tests.push(it);
|
|
572
638
|
}
|
|
573
|
-
return { name, mocks, tests };
|
|
639
|
+
return { name, mocks, tests, inlineComment: inlineComment || void 0 };
|
|
574
640
|
}
|
|
575
641
|
};
|
|
576
642
|
function parseProgram(text) {
|
|
@@ -600,14 +666,24 @@ var ParseFailure = class extends Error {
|
|
|
600
666
|
};
|
|
601
667
|
function printRoute(route) {
|
|
602
668
|
const lines = [];
|
|
603
|
-
|
|
669
|
+
const routeLine = `${route.method} ${route.path}`;
|
|
670
|
+
if (route.inlineComment) {
|
|
671
|
+
lines.push(`${routeLine} ${printComment(route.inlineComment)}`);
|
|
672
|
+
} else {
|
|
673
|
+
lines.push(routeLine);
|
|
674
|
+
}
|
|
604
675
|
const pipelineLines = formatPipelineRef(route.pipeline);
|
|
605
676
|
pipelineLines.forEach((line) => lines.push(line));
|
|
606
677
|
return lines.join("\n");
|
|
607
678
|
}
|
|
608
679
|
function printConfig(config) {
|
|
609
680
|
const lines = [];
|
|
610
|
-
|
|
681
|
+
const configLine = `config ${config.name} {`;
|
|
682
|
+
if (config.inlineComment) {
|
|
683
|
+
lines.push(`${configLine} ${printComment(config.inlineComment)}`);
|
|
684
|
+
} else {
|
|
685
|
+
lines.push(configLine);
|
|
686
|
+
}
|
|
611
687
|
config.properties.forEach((prop) => {
|
|
612
688
|
const value = formatConfigValue(prop.value);
|
|
613
689
|
lines.push(` ${prop.key}: ${value}`);
|
|
@@ -617,14 +693,23 @@ function printConfig(config) {
|
|
|
617
693
|
}
|
|
618
694
|
function printPipeline(pipeline) {
|
|
619
695
|
const lines = [];
|
|
620
|
-
|
|
696
|
+
const pipelineLine = `pipeline ${pipeline.name} =`;
|
|
697
|
+
if (pipeline.inlineComment) {
|
|
698
|
+
lines.push(`${pipelineLine} ${printComment(pipeline.inlineComment)}`);
|
|
699
|
+
} else {
|
|
700
|
+
lines.push(pipelineLine);
|
|
701
|
+
}
|
|
621
702
|
pipeline.pipeline.steps.forEach((step) => {
|
|
622
703
|
lines.push(formatPipelineStep(step));
|
|
623
704
|
});
|
|
624
705
|
return lines.join("\n");
|
|
625
706
|
}
|
|
626
707
|
function printVariable(variable) {
|
|
627
|
-
|
|
708
|
+
const variableLine = `${variable.varType} ${variable.name} = \`${variable.value}\``;
|
|
709
|
+
if (variable.inlineComment) {
|
|
710
|
+
return `${variableLine} ${printComment(variable.inlineComment)}`;
|
|
711
|
+
}
|
|
712
|
+
return variableLine;
|
|
628
713
|
}
|
|
629
714
|
function printMock(mock, indent = " ") {
|
|
630
715
|
return `${indent}with mock ${mock.target} returning \`${mock.returnValue}\``;
|
|
@@ -650,9 +735,23 @@ function printTest(test) {
|
|
|
650
735
|
});
|
|
651
736
|
return lines.join("\n");
|
|
652
737
|
}
|
|
738
|
+
function printComment(comment) {
|
|
739
|
+
if (comment.style === "#" && comment.text.startsWith("#")) {
|
|
740
|
+
return `${comment.style}${comment.text}`;
|
|
741
|
+
}
|
|
742
|
+
if (comment.text === "" || comment.text.startsWith(" ")) {
|
|
743
|
+
return `${comment.style}${comment.text}`;
|
|
744
|
+
}
|
|
745
|
+
return `${comment.style} ${comment.text}`;
|
|
746
|
+
}
|
|
653
747
|
function printDescribe(describe) {
|
|
654
748
|
const lines = [];
|
|
655
|
-
|
|
749
|
+
const describeLine = `describe "${describe.name}"`;
|
|
750
|
+
if (describe.inlineComment) {
|
|
751
|
+
lines.push(`${describeLine} ${printComment(describe.inlineComment)}`);
|
|
752
|
+
} else {
|
|
753
|
+
lines.push(describeLine);
|
|
754
|
+
}
|
|
656
755
|
describe.mocks.forEach((mock) => {
|
|
657
756
|
lines.push(printMock(mock));
|
|
658
757
|
});
|
|
@@ -683,6 +782,9 @@ function prettyPrint(program) {
|
|
|
683
782
|
program.describes.forEach((describe) => {
|
|
684
783
|
allItems.push({ type: "describe", item: describe, lineNumber: describe.lineNumber || 0 });
|
|
685
784
|
});
|
|
785
|
+
program.comments.forEach((comment) => {
|
|
786
|
+
allItems.push({ type: "comment", item: comment, lineNumber: comment.lineNumber || 0 });
|
|
787
|
+
});
|
|
686
788
|
allItems.sort((a, b) => a.lineNumber - b.lineNumber);
|
|
687
789
|
let hasConfigs = false;
|
|
688
790
|
allItems.forEach((entry, index) => {
|
|
@@ -691,6 +793,9 @@ function prettyPrint(program) {
|
|
|
691
793
|
hasConfigs = true;
|
|
692
794
|
}
|
|
693
795
|
switch (entry.type) {
|
|
796
|
+
case "comment":
|
|
797
|
+
lines.push(printComment(entry.item));
|
|
798
|
+
break;
|
|
694
799
|
case "config":
|
|
695
800
|
lines.push(printConfig(entry.item));
|
|
696
801
|
lines.push("");
|
|
@@ -714,7 +819,7 @@ function prettyPrint(program) {
|
|
|
714
819
|
break;
|
|
715
820
|
}
|
|
716
821
|
});
|
|
717
|
-
return lines.join("\n").trim();
|
|
822
|
+
return lines.join("\n").trim() + "\n";
|
|
718
823
|
}
|
|
719
824
|
function formatConfigValue(value) {
|
|
720
825
|
switch (value.kind) {
|
|
@@ -786,6 +891,7 @@ function formatWhen(when) {
|
|
|
786
891
|
parseProgram,
|
|
787
892
|
parseProgramWithDiagnostics,
|
|
788
893
|
prettyPrint,
|
|
894
|
+
printComment,
|
|
789
895
|
printCondition,
|
|
790
896
|
printConfig,
|
|
791
897
|
printDescribe,
|
package/dist/index.d.cts
CHANGED
|
@@ -4,11 +4,19 @@ interface Program {
|
|
|
4
4
|
variables: Variable[];
|
|
5
5
|
routes: Route[];
|
|
6
6
|
describes: Describe[];
|
|
7
|
+
comments: Comment[];
|
|
8
|
+
}
|
|
9
|
+
interface Comment {
|
|
10
|
+
type: 'standalone' | 'inline';
|
|
11
|
+
text: string;
|
|
12
|
+
style: '#' | '//';
|
|
13
|
+
lineNumber?: number;
|
|
7
14
|
}
|
|
8
15
|
interface Config {
|
|
9
16
|
name: string;
|
|
10
17
|
properties: ConfigProperty[];
|
|
11
18
|
lineNumber?: number;
|
|
19
|
+
inlineComment?: Comment;
|
|
12
20
|
}
|
|
13
21
|
interface ConfigProperty {
|
|
14
22
|
key: string;
|
|
@@ -32,18 +40,21 @@ interface NamedPipeline {
|
|
|
32
40
|
name: string;
|
|
33
41
|
pipeline: Pipeline;
|
|
34
42
|
lineNumber?: number;
|
|
43
|
+
inlineComment?: Comment;
|
|
35
44
|
}
|
|
36
45
|
interface Variable {
|
|
37
46
|
varType: string;
|
|
38
47
|
name: string;
|
|
39
48
|
value: string;
|
|
40
49
|
lineNumber?: number;
|
|
50
|
+
inlineComment?: Comment;
|
|
41
51
|
}
|
|
42
52
|
interface Route {
|
|
43
53
|
method: string;
|
|
44
54
|
path: string;
|
|
45
55
|
pipeline: PipelineRef;
|
|
46
56
|
lineNumber?: number;
|
|
57
|
+
inlineComment?: Comment;
|
|
47
58
|
}
|
|
48
59
|
type PipelineRef = {
|
|
49
60
|
kind: 'Inline';
|
|
@@ -83,6 +94,7 @@ interface Describe {
|
|
|
83
94
|
mocks: Mock[];
|
|
84
95
|
tests: It[];
|
|
85
96
|
lineNumber?: number;
|
|
97
|
+
inlineComment?: Comment;
|
|
86
98
|
}
|
|
87
99
|
interface Mock {
|
|
88
100
|
target: string;
|
|
@@ -141,6 +153,7 @@ declare function printVariable(variable: Variable): string;
|
|
|
141
153
|
declare function printMock(mock: Mock, indent?: string): string;
|
|
142
154
|
declare function printCondition(condition: Condition, indent?: string): string;
|
|
143
155
|
declare function printTest(test: It): string;
|
|
156
|
+
declare function printComment(comment: Comment): string;
|
|
144
157
|
declare function printDescribe(describe: Describe): string;
|
|
145
158
|
declare function prettyPrint(program: Program): string;
|
|
146
159
|
declare function formatConfigValue(value: ConfigValue): string;
|
|
@@ -149,4 +162,4 @@ declare function formatStepConfig(config: string, configType: ConfigType): strin
|
|
|
149
162
|
declare function formatPipelineRef(ref: PipelineRef): string[];
|
|
150
163
|
declare function formatWhen(when: When): string;
|
|
151
164
|
|
|
152
|
-
export { type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type It, type Mock, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type ResultBranch, type ResultBranchType, type Route, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatWhen, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printCondition, printConfig, printDescribe, printMock, printPipeline, printRoute, printTest, printVariable };
|
|
165
|
+
export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type It, type Mock, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type ResultBranch, type ResultBranchType, type Route, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatWhen, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printMock, printPipeline, printRoute, printTest, printVariable };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,11 +4,19 @@ interface Program {
|
|
|
4
4
|
variables: Variable[];
|
|
5
5
|
routes: Route[];
|
|
6
6
|
describes: Describe[];
|
|
7
|
+
comments: Comment[];
|
|
8
|
+
}
|
|
9
|
+
interface Comment {
|
|
10
|
+
type: 'standalone' | 'inline';
|
|
11
|
+
text: string;
|
|
12
|
+
style: '#' | '//';
|
|
13
|
+
lineNumber?: number;
|
|
7
14
|
}
|
|
8
15
|
interface Config {
|
|
9
16
|
name: string;
|
|
10
17
|
properties: ConfigProperty[];
|
|
11
18
|
lineNumber?: number;
|
|
19
|
+
inlineComment?: Comment;
|
|
12
20
|
}
|
|
13
21
|
interface ConfigProperty {
|
|
14
22
|
key: string;
|
|
@@ -32,18 +40,21 @@ interface NamedPipeline {
|
|
|
32
40
|
name: string;
|
|
33
41
|
pipeline: Pipeline;
|
|
34
42
|
lineNumber?: number;
|
|
43
|
+
inlineComment?: Comment;
|
|
35
44
|
}
|
|
36
45
|
interface Variable {
|
|
37
46
|
varType: string;
|
|
38
47
|
name: string;
|
|
39
48
|
value: string;
|
|
40
49
|
lineNumber?: number;
|
|
50
|
+
inlineComment?: Comment;
|
|
41
51
|
}
|
|
42
52
|
interface Route {
|
|
43
53
|
method: string;
|
|
44
54
|
path: string;
|
|
45
55
|
pipeline: PipelineRef;
|
|
46
56
|
lineNumber?: number;
|
|
57
|
+
inlineComment?: Comment;
|
|
47
58
|
}
|
|
48
59
|
type PipelineRef = {
|
|
49
60
|
kind: 'Inline';
|
|
@@ -83,6 +94,7 @@ interface Describe {
|
|
|
83
94
|
mocks: Mock[];
|
|
84
95
|
tests: It[];
|
|
85
96
|
lineNumber?: number;
|
|
97
|
+
inlineComment?: Comment;
|
|
86
98
|
}
|
|
87
99
|
interface Mock {
|
|
88
100
|
target: string;
|
|
@@ -141,6 +153,7 @@ declare function printVariable(variable: Variable): string;
|
|
|
141
153
|
declare function printMock(mock: Mock, indent?: string): string;
|
|
142
154
|
declare function printCondition(condition: Condition, indent?: string): string;
|
|
143
155
|
declare function printTest(test: It): string;
|
|
156
|
+
declare function printComment(comment: Comment): string;
|
|
144
157
|
declare function printDescribe(describe: Describe): string;
|
|
145
158
|
declare function prettyPrint(program: Program): string;
|
|
146
159
|
declare function formatConfigValue(value: ConfigValue): string;
|
|
@@ -149,4 +162,4 @@ declare function formatStepConfig(config: string, configType: ConfigType): strin
|
|
|
149
162
|
declare function formatPipelineRef(ref: PipelineRef): string[];
|
|
150
163
|
declare function formatWhen(when: When): string;
|
|
151
164
|
|
|
152
|
-
export { type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type It, type Mock, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type ResultBranch, type ResultBranchType, type Route, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatWhen, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printCondition, printConfig, printDescribe, printMock, printPipeline, printRoute, printTest, printVariable };
|
|
165
|
+
export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type It, type Mock, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type ResultBranch, type ResultBranchType, type Route, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatWhen, getPipelineRanges, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printMock, printPipeline, printRoute, printTest, printVariable };
|
package/dist/index.mjs
CHANGED
|
@@ -33,17 +33,74 @@ var Parser = class {
|
|
|
33
33
|
getLineNumber(pos) {
|
|
34
34
|
return this.text.slice(0, pos).split("\n").length;
|
|
35
35
|
}
|
|
36
|
+
parseInlineComment() {
|
|
37
|
+
this.skipInlineSpaces();
|
|
38
|
+
const start = this.pos;
|
|
39
|
+
if (this.text.startsWith("#", this.pos)) {
|
|
40
|
+
this.pos++;
|
|
41
|
+
const text = this.consumeWhile((ch) => ch !== "\n");
|
|
42
|
+
return {
|
|
43
|
+
type: "inline",
|
|
44
|
+
text,
|
|
45
|
+
style: "#",
|
|
46
|
+
lineNumber: this.getLineNumber(start)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (this.text.startsWith("//", this.pos)) {
|
|
50
|
+
this.pos += 2;
|
|
51
|
+
const text = this.consumeWhile((ch) => ch !== "\n");
|
|
52
|
+
return {
|
|
53
|
+
type: "inline",
|
|
54
|
+
text,
|
|
55
|
+
style: "//",
|
|
56
|
+
lineNumber: this.getLineNumber(start)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
parseStandaloneComment() {
|
|
62
|
+
const start = this.pos;
|
|
63
|
+
if (this.text.startsWith("#", this.pos)) {
|
|
64
|
+
const originalPos = this.pos;
|
|
65
|
+
this.pos++;
|
|
66
|
+
const restOfLine = this.consumeWhile((ch) => ch !== "\n");
|
|
67
|
+
return {
|
|
68
|
+
type: "standalone",
|
|
69
|
+
text: restOfLine,
|
|
70
|
+
style: "#",
|
|
71
|
+
lineNumber: this.getLineNumber(start)
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (this.text.startsWith("//", this.pos)) {
|
|
75
|
+
this.pos += 2;
|
|
76
|
+
const text = this.consumeWhile((ch) => ch !== "\n");
|
|
77
|
+
return {
|
|
78
|
+
type: "standalone",
|
|
79
|
+
text,
|
|
80
|
+
style: "//",
|
|
81
|
+
lineNumber: this.getLineNumber(start)
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
36
86
|
parseProgram() {
|
|
37
|
-
this.
|
|
87
|
+
this.skipWhitespaceOnly();
|
|
38
88
|
const configs = [];
|
|
39
89
|
const pipelines = [];
|
|
40
90
|
const variables = [];
|
|
41
91
|
const routes = [];
|
|
42
92
|
const describes = [];
|
|
93
|
+
const comments = [];
|
|
43
94
|
while (!this.eof()) {
|
|
44
|
-
this.
|
|
95
|
+
this.skipWhitespaceOnly();
|
|
45
96
|
if (this.eof()) break;
|
|
46
97
|
const start = this.pos;
|
|
98
|
+
const comment = this.tryParse(() => this.parseStandaloneComment());
|
|
99
|
+
if (comment) {
|
|
100
|
+
comments.push(comment);
|
|
101
|
+
if (this.cur() === "\n") this.pos++;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
47
104
|
const cfg = this.tryParse(() => this.parseConfig());
|
|
48
105
|
if (cfg) {
|
|
49
106
|
cfg.lineNumber = this.getLineNumber(start);
|
|
@@ -89,7 +146,7 @@ var Parser = class {
|
|
|
89
146
|
const start = Math.max(0, idx);
|
|
90
147
|
this.report("Unclosed backtick-delimited string", start, start + 1, "warning");
|
|
91
148
|
}
|
|
92
|
-
return { configs, pipelines, variables, routes, describes };
|
|
149
|
+
return { configs, pipelines, variables, routes, describes, comments };
|
|
93
150
|
}
|
|
94
151
|
eof() {
|
|
95
152
|
return this.pos >= this.len;
|
|
@@ -129,6 +186,9 @@ var Parser = class {
|
|
|
129
186
|
break;
|
|
130
187
|
}
|
|
131
188
|
}
|
|
189
|
+
skipWhitespaceOnly() {
|
|
190
|
+
this.consumeWhile((ch) => ch === " " || ch === " " || ch === "\r" || ch === "\n");
|
|
191
|
+
}
|
|
132
192
|
skipInlineSpaces() {
|
|
133
193
|
this.consumeWhile((ch) => ch === " " || ch === " " || ch === "\r");
|
|
134
194
|
}
|
|
@@ -256,6 +316,7 @@ var Parser = class {
|
|
|
256
316
|
const name = this.parseIdentifier();
|
|
257
317
|
this.skipInlineSpaces();
|
|
258
318
|
this.expect("{");
|
|
319
|
+
const inlineComment = this.parseInlineComment();
|
|
259
320
|
this.skipSpaces();
|
|
260
321
|
const properties = [];
|
|
261
322
|
while (true) {
|
|
@@ -266,8 +327,8 @@ var Parser = class {
|
|
|
266
327
|
}
|
|
267
328
|
this.skipSpaces();
|
|
268
329
|
this.expect("}");
|
|
269
|
-
this.
|
|
270
|
-
return { name, properties };
|
|
330
|
+
this.skipWhitespaceOnly();
|
|
331
|
+
return { name, properties, inlineComment: inlineComment || void 0 };
|
|
271
332
|
}
|
|
272
333
|
parsePipelineStep() {
|
|
273
334
|
const result = this.tryParse(() => this.parseResultStep());
|
|
@@ -275,22 +336,22 @@ var Parser = class {
|
|
|
275
336
|
return this.parseRegularStep();
|
|
276
337
|
}
|
|
277
338
|
parseRegularStep() {
|
|
278
|
-
this.
|
|
339
|
+
this.skipWhitespaceOnly();
|
|
279
340
|
this.expect("|>");
|
|
280
341
|
this.skipInlineSpaces();
|
|
281
342
|
const name = this.parseIdentifier();
|
|
282
343
|
this.expect(":");
|
|
283
344
|
this.skipInlineSpaces();
|
|
284
345
|
const { config, configType } = this.parseStepConfig();
|
|
285
|
-
this.
|
|
346
|
+
this.skipWhitespaceOnly();
|
|
286
347
|
return { kind: "Regular", name, config, configType };
|
|
287
348
|
}
|
|
288
349
|
parseResultStep() {
|
|
289
|
-
this.
|
|
350
|
+
this.skipWhitespaceOnly();
|
|
290
351
|
this.expect("|>");
|
|
291
352
|
this.skipInlineSpaces();
|
|
292
353
|
this.expect("result");
|
|
293
|
-
this.
|
|
354
|
+
this.skipWhitespaceOnly();
|
|
294
355
|
const branches = [];
|
|
295
356
|
while (true) {
|
|
296
357
|
const br = this.tryParse(() => this.parseResultBranch());
|
|
@@ -326,7 +387,7 @@ var Parser = class {
|
|
|
326
387
|
const steps = [];
|
|
327
388
|
while (true) {
|
|
328
389
|
const save = this.pos;
|
|
329
|
-
this.
|
|
390
|
+
this.skipWhitespaceOnly();
|
|
330
391
|
if (!this.text.startsWith("|>", this.pos)) {
|
|
331
392
|
this.pos = save;
|
|
332
393
|
break;
|
|
@@ -343,19 +404,20 @@ var Parser = class {
|
|
|
343
404
|
const name = this.parseIdentifier();
|
|
344
405
|
this.skipInlineSpaces();
|
|
345
406
|
this.expect("=");
|
|
407
|
+
const inlineComment = this.parseInlineComment();
|
|
346
408
|
this.skipInlineSpaces();
|
|
347
409
|
const beforePipeline = this.pos;
|
|
348
410
|
const pipeline = this.parsePipeline();
|
|
349
411
|
const end = this.pos;
|
|
350
412
|
this.pipelineRanges.set(name, { start, end });
|
|
351
|
-
this.
|
|
352
|
-
return { name, pipeline };
|
|
413
|
+
this.skipWhitespaceOnly();
|
|
414
|
+
return { name, pipeline, inlineComment: inlineComment || void 0 };
|
|
353
415
|
}
|
|
354
416
|
parsePipelineRef() {
|
|
355
417
|
const inline = this.tryParse(() => this.parsePipeline());
|
|
356
418
|
if (inline && inline.steps.length > 0) return { kind: "Inline", pipeline: inline };
|
|
357
419
|
const named = this.tryParse(() => {
|
|
358
|
-
this.
|
|
420
|
+
this.skipWhitespaceOnly();
|
|
359
421
|
this.expect("|>");
|
|
360
422
|
this.skipInlineSpaces();
|
|
361
423
|
this.expect("pipeline:");
|
|
@@ -375,19 +437,21 @@ var Parser = class {
|
|
|
375
437
|
this.expect("=");
|
|
376
438
|
this.skipInlineSpaces();
|
|
377
439
|
const value = this.parseBacktickString();
|
|
440
|
+
const inlineComment = this.parseInlineComment();
|
|
378
441
|
const end = this.pos;
|
|
379
442
|
this.variableRanges.set(`${varType}::${name}`, { start, end });
|
|
380
|
-
this.
|
|
381
|
-
return { varType, name, value };
|
|
443
|
+
this.skipWhitespaceOnly();
|
|
444
|
+
return { varType, name, value, inlineComment: inlineComment || void 0 };
|
|
382
445
|
}
|
|
383
446
|
parseRoute() {
|
|
384
447
|
const method = this.parseMethod();
|
|
385
448
|
this.skipInlineSpaces();
|
|
386
|
-
const path = this.consumeWhile((c) => c !== " " && c !== "\n");
|
|
449
|
+
const path = this.consumeWhile((c) => c !== " " && c !== "\n" && c !== "#");
|
|
450
|
+
const inlineComment = this.parseInlineComment();
|
|
387
451
|
this.skipSpaces();
|
|
388
452
|
const pipeline = this.parsePipelineRef();
|
|
389
|
-
this.
|
|
390
|
-
return { method, path, pipeline };
|
|
453
|
+
this.skipWhitespaceOnly();
|
|
454
|
+
return { method, path, pipeline, inlineComment: inlineComment || void 0 };
|
|
391
455
|
}
|
|
392
456
|
parseWhen() {
|
|
393
457
|
const calling = this.tryParse(() => {
|
|
@@ -513,6 +577,7 @@ var Parser = class {
|
|
|
513
577
|
this.expect('"');
|
|
514
578
|
const name = this.consumeWhile((c) => c !== '"');
|
|
515
579
|
this.expect('"');
|
|
580
|
+
const inlineComment = this.parseInlineComment();
|
|
516
581
|
this.skipSpaces();
|
|
517
582
|
const mocks = [];
|
|
518
583
|
while (true) {
|
|
@@ -527,7 +592,7 @@ var Parser = class {
|
|
|
527
592
|
if (!it) break;
|
|
528
593
|
tests.push(it);
|
|
529
594
|
}
|
|
530
|
-
return { name, mocks, tests };
|
|
595
|
+
return { name, mocks, tests, inlineComment: inlineComment || void 0 };
|
|
531
596
|
}
|
|
532
597
|
};
|
|
533
598
|
function parseProgram(text) {
|
|
@@ -557,14 +622,24 @@ var ParseFailure = class extends Error {
|
|
|
557
622
|
};
|
|
558
623
|
function printRoute(route) {
|
|
559
624
|
const lines = [];
|
|
560
|
-
|
|
625
|
+
const routeLine = `${route.method} ${route.path}`;
|
|
626
|
+
if (route.inlineComment) {
|
|
627
|
+
lines.push(`${routeLine} ${printComment(route.inlineComment)}`);
|
|
628
|
+
} else {
|
|
629
|
+
lines.push(routeLine);
|
|
630
|
+
}
|
|
561
631
|
const pipelineLines = formatPipelineRef(route.pipeline);
|
|
562
632
|
pipelineLines.forEach((line) => lines.push(line));
|
|
563
633
|
return lines.join("\n");
|
|
564
634
|
}
|
|
565
635
|
function printConfig(config) {
|
|
566
636
|
const lines = [];
|
|
567
|
-
|
|
637
|
+
const configLine = `config ${config.name} {`;
|
|
638
|
+
if (config.inlineComment) {
|
|
639
|
+
lines.push(`${configLine} ${printComment(config.inlineComment)}`);
|
|
640
|
+
} else {
|
|
641
|
+
lines.push(configLine);
|
|
642
|
+
}
|
|
568
643
|
config.properties.forEach((prop) => {
|
|
569
644
|
const value = formatConfigValue(prop.value);
|
|
570
645
|
lines.push(` ${prop.key}: ${value}`);
|
|
@@ -574,14 +649,23 @@ function printConfig(config) {
|
|
|
574
649
|
}
|
|
575
650
|
function printPipeline(pipeline) {
|
|
576
651
|
const lines = [];
|
|
577
|
-
|
|
652
|
+
const pipelineLine = `pipeline ${pipeline.name} =`;
|
|
653
|
+
if (pipeline.inlineComment) {
|
|
654
|
+
lines.push(`${pipelineLine} ${printComment(pipeline.inlineComment)}`);
|
|
655
|
+
} else {
|
|
656
|
+
lines.push(pipelineLine);
|
|
657
|
+
}
|
|
578
658
|
pipeline.pipeline.steps.forEach((step) => {
|
|
579
659
|
lines.push(formatPipelineStep(step));
|
|
580
660
|
});
|
|
581
661
|
return lines.join("\n");
|
|
582
662
|
}
|
|
583
663
|
function printVariable(variable) {
|
|
584
|
-
|
|
664
|
+
const variableLine = `${variable.varType} ${variable.name} = \`${variable.value}\``;
|
|
665
|
+
if (variable.inlineComment) {
|
|
666
|
+
return `${variableLine} ${printComment(variable.inlineComment)}`;
|
|
667
|
+
}
|
|
668
|
+
return variableLine;
|
|
585
669
|
}
|
|
586
670
|
function printMock(mock, indent = " ") {
|
|
587
671
|
return `${indent}with mock ${mock.target} returning \`${mock.returnValue}\``;
|
|
@@ -607,9 +691,23 @@ function printTest(test) {
|
|
|
607
691
|
});
|
|
608
692
|
return lines.join("\n");
|
|
609
693
|
}
|
|
694
|
+
function printComment(comment) {
|
|
695
|
+
if (comment.style === "#" && comment.text.startsWith("#")) {
|
|
696
|
+
return `${comment.style}${comment.text}`;
|
|
697
|
+
}
|
|
698
|
+
if (comment.text === "" || comment.text.startsWith(" ")) {
|
|
699
|
+
return `${comment.style}${comment.text}`;
|
|
700
|
+
}
|
|
701
|
+
return `${comment.style} ${comment.text}`;
|
|
702
|
+
}
|
|
610
703
|
function printDescribe(describe) {
|
|
611
704
|
const lines = [];
|
|
612
|
-
|
|
705
|
+
const describeLine = `describe "${describe.name}"`;
|
|
706
|
+
if (describe.inlineComment) {
|
|
707
|
+
lines.push(`${describeLine} ${printComment(describe.inlineComment)}`);
|
|
708
|
+
} else {
|
|
709
|
+
lines.push(describeLine);
|
|
710
|
+
}
|
|
613
711
|
describe.mocks.forEach((mock) => {
|
|
614
712
|
lines.push(printMock(mock));
|
|
615
713
|
});
|
|
@@ -640,6 +738,9 @@ function prettyPrint(program) {
|
|
|
640
738
|
program.describes.forEach((describe) => {
|
|
641
739
|
allItems.push({ type: "describe", item: describe, lineNumber: describe.lineNumber || 0 });
|
|
642
740
|
});
|
|
741
|
+
program.comments.forEach((comment) => {
|
|
742
|
+
allItems.push({ type: "comment", item: comment, lineNumber: comment.lineNumber || 0 });
|
|
743
|
+
});
|
|
643
744
|
allItems.sort((a, b) => a.lineNumber - b.lineNumber);
|
|
644
745
|
let hasConfigs = false;
|
|
645
746
|
allItems.forEach((entry, index) => {
|
|
@@ -648,6 +749,9 @@ function prettyPrint(program) {
|
|
|
648
749
|
hasConfigs = true;
|
|
649
750
|
}
|
|
650
751
|
switch (entry.type) {
|
|
752
|
+
case "comment":
|
|
753
|
+
lines.push(printComment(entry.item));
|
|
754
|
+
break;
|
|
651
755
|
case "config":
|
|
652
756
|
lines.push(printConfig(entry.item));
|
|
653
757
|
lines.push("");
|
|
@@ -671,7 +775,7 @@ function prettyPrint(program) {
|
|
|
671
775
|
break;
|
|
672
776
|
}
|
|
673
777
|
});
|
|
674
|
-
return lines.join("\n").trim();
|
|
778
|
+
return lines.join("\n").trim() + "\n";
|
|
675
779
|
}
|
|
676
780
|
function formatConfigValue(value) {
|
|
677
781
|
switch (value.kind) {
|
|
@@ -742,6 +846,7 @@ export {
|
|
|
742
846
|
parseProgram,
|
|
743
847
|
parseProgramWithDiagnostics,
|
|
744
848
|
prettyPrint,
|
|
849
|
+
printComment,
|
|
745
850
|
printCondition,
|
|
746
851
|
printConfig,
|
|
747
852
|
printDescribe,
|