webpipe-js 0.1.9 → 0.1.10

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