webpipe-js 2.0.63 → 2.0.65

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
@@ -39,6 +39,7 @@ __export(index_exports, {
39
39
  printCondition: () => printCondition,
40
40
  printConfig: () => printConfig,
41
41
  printDescribe: () => printDescribe,
42
+ printFeatureFlags: () => printFeatureFlags,
42
43
  printGraphQLSchema: () => printGraphQLSchema,
43
44
  printMock: () => printMock,
44
45
  printMutationResolver: () => printMutationResolver,
@@ -131,7 +132,8 @@ var Parser = class {
131
132
  type: "standalone",
132
133
  text: restOfLine,
133
134
  style: "#",
134
- lineNumber: this.getLineNumber(start)
135
+ lineNumber: this.getLineNumber(start),
136
+ start
135
137
  };
136
138
  }
137
139
  if (this.text.startsWith("//", this.pos)) {
@@ -141,7 +143,8 @@ var Parser = class {
141
143
  type: "standalone",
142
144
  text,
143
145
  style: "//",
144
- lineNumber: this.getLineNumber(start)
146
+ lineNumber: this.getLineNumber(start),
147
+ start
145
148
  };
146
149
  }
147
150
  return null;
@@ -773,15 +776,15 @@ var Parser = class {
773
776
  const condition = this.parseIfPipeline("then:");
774
777
  this.skipSpaces();
775
778
  this.expect("then:");
776
- this.skipSpaces();
779
+ this.skipWhitespaceOnly();
777
780
  const thenBranch = this.parseIfPipeline("else:", "end");
778
- this.skipSpaces();
781
+ this.skipWhitespaceOnly();
779
782
  const elseBranch = this.tryParse(() => {
780
783
  this.expect("else:");
781
- this.skipSpaces();
784
+ this.skipWhitespaceOnly();
782
785
  return this.parseIfPipeline("end");
783
786
  });
784
- this.skipSpaces();
787
+ this.skipWhitespaceOnly();
785
788
  this.tryParse(() => {
786
789
  this.expect("end");
787
790
  return true;
@@ -908,8 +911,15 @@ var Parser = class {
908
911
  break;
909
912
  }
910
913
  const hasFollowingStep = this.text.startsWith("|>", this.pos);
914
+ let hasStopKeyword = false;
915
+ for (const keyword of stopKeywords) {
916
+ if (this.text.startsWith(keyword, this.pos)) {
917
+ hasStopKeyword = true;
918
+ break;
919
+ }
920
+ }
911
921
  this.pos = lookAheadPos;
912
- if (hasFollowingStep || steps.length === 0) {
922
+ if (hasFollowingStep || hasStopKeyword || steps.length === 0) {
913
923
  comments.push(comment);
914
924
  if (this.cur() === "\n") this.pos++;
915
925
  continue;
@@ -1659,7 +1669,7 @@ function printPipeline(pipeline) {
1659
1669
  items.push({ type: "step", item: step, position: step.start });
1660
1670
  });
1661
1671
  pipeline.pipeline.comments.forEach((comment) => {
1662
- items.push({ type: "comment", item: comment, position: comment.lineNumber || 0 });
1672
+ items.push({ type: "comment", item: comment, position: comment.start || 0 });
1663
1673
  });
1664
1674
  items.sort((a, b) => a.position - b.position);
1665
1675
  items.forEach((entry) => {
@@ -1721,6 +1731,26 @@ function printTypeResolver(resolver) {
1721
1731
  });
1722
1732
  return lines.join("\n");
1723
1733
  }
1734
+ function printFeatureFlags(pipeline) {
1735
+ const lines = [];
1736
+ lines.push("featureFlags =");
1737
+ const items = [];
1738
+ pipeline.steps.forEach((step) => {
1739
+ items.push({ type: "step", item: step, position: step.start });
1740
+ });
1741
+ pipeline.comments.forEach((comment) => {
1742
+ items.push({ type: "comment", item: comment, position: comment.start || 0 });
1743
+ });
1744
+ items.sort((a, b) => a.position - b.position);
1745
+ items.forEach((entry) => {
1746
+ if (entry.type === "step") {
1747
+ lines.push(formatPipelineStep(entry.item));
1748
+ } else {
1749
+ lines.push(` ${printComment(entry.item)}`);
1750
+ }
1751
+ });
1752
+ return lines.join("\n");
1753
+ }
1724
1754
  function printMock(mock, indent = " ") {
1725
1755
  const target = mock.target.replace(/^(query|mutation)\.(.*)$/, "$1 $2");
1726
1756
  return `${indent}with mock ${target} returning \`${mock.returnValue}\``;
@@ -1898,6 +1928,9 @@ function prettyPrint(program) {
1898
1928
  program.variables.forEach((variable) => {
1899
1929
  allItems.push({ type: "variable", item: variable, lineNumber: variable.lineNumber || 0 });
1900
1930
  });
1931
+ if (program.featureFlags) {
1932
+ allItems.push({ type: "featureFlags", item: program.featureFlags, lineNumber: program.featureFlags.start || 0 });
1933
+ }
1901
1934
  program.describes.forEach((describe) => {
1902
1935
  allItems.push({ type: "describe", item: describe, lineNumber: describe.lineNumber || 0 });
1903
1936
  });
@@ -1951,6 +1984,9 @@ function prettyPrint(program) {
1951
1984
  case "variable":
1952
1985
  lines.push(printVariable(entry.item));
1953
1986
  break;
1987
+ case "featureFlags":
1988
+ lines.push(printFeatureFlags(entry.item));
1989
+ break;
1954
1990
  case "describe":
1955
1991
  lines.push(printDescribe(entry.item));
1956
1992
  break;
@@ -1973,7 +2009,7 @@ function formatConfigValue(value) {
1973
2009
  return value.value.toString();
1974
2010
  }
1975
2011
  }
1976
- function formatPipelineStep(step, indent = " ") {
2012
+ function formatPipelineStep(step, indent = " ", isLastStep = false) {
1977
2013
  if (step.kind === "Regular") {
1978
2014
  const argsPart = step.args.length > 0 ? `(${step.args.join(", ")})` : "";
1979
2015
  const configPart = formatStepConfig(step.config, step.configType);
@@ -1991,19 +2027,58 @@ function formatPipelineStep(step, indent = " ") {
1991
2027
  return lines.join("\n");
1992
2028
  } else if (step.kind === "If") {
1993
2029
  const lines = [`${indent}|> if`];
1994
- step.condition.steps.forEach((condStep) => {
1995
- lines.push(formatPipelineStep(condStep, indent + " "));
2030
+ const conditionItems = [];
2031
+ step.condition.steps.forEach((s) => {
2032
+ conditionItems.push({ type: "step", item: s, position: s.start });
2033
+ });
2034
+ step.condition.comments.forEach((c) => {
2035
+ conditionItems.push({ type: "comment", item: c, position: c.start || 0 });
2036
+ });
2037
+ conditionItems.sort((a, b) => a.position - b.position);
2038
+ conditionItems.forEach((entry) => {
2039
+ if (entry.type === "step") {
2040
+ lines.push(formatPipelineStep(entry.item, indent + " "));
2041
+ } else {
2042
+ lines.push(`${indent} ${printComment(entry.item)}`);
2043
+ }
1996
2044
  });
1997
2045
  lines.push(`${indent} then:`);
1998
- step.thenBranch.steps.forEach((thenStep) => {
1999
- lines.push(formatPipelineStep(thenStep, indent + " "));
2046
+ const thenItems = [];
2047
+ step.thenBranch.steps.forEach((s) => {
2048
+ thenItems.push({ type: "step", item: s, position: s.start });
2049
+ });
2050
+ step.thenBranch.comments.forEach((c) => {
2051
+ thenItems.push({ type: "comment", item: c, position: c.start || 0 });
2052
+ });
2053
+ thenItems.sort((a, b) => a.position - b.position);
2054
+ thenItems.forEach((entry) => {
2055
+ if (entry.type === "step") {
2056
+ lines.push(formatPipelineStep(entry.item, indent + " "));
2057
+ } else {
2058
+ lines.push(`${indent} ${printComment(entry.item)}`);
2059
+ }
2000
2060
  });
2001
2061
  if (step.elseBranch) {
2002
2062
  lines.push(`${indent} else:`);
2003
- step.elseBranch.steps.forEach((elseStep) => {
2004
- lines.push(formatPipelineStep(elseStep, indent + " "));
2063
+ const elseItems = [];
2064
+ step.elseBranch.steps.forEach((s) => {
2065
+ elseItems.push({ type: "step", item: s, position: s.start });
2066
+ });
2067
+ step.elseBranch.comments.forEach((c) => {
2068
+ elseItems.push({ type: "comment", item: c, position: c.start || 0 });
2069
+ });
2070
+ elseItems.sort((a, b) => a.position - b.position);
2071
+ elseItems.forEach((entry) => {
2072
+ if (entry.type === "step") {
2073
+ lines.push(formatPipelineStep(entry.item, indent + " "));
2074
+ } else {
2075
+ lines.push(`${indent} ${printComment(entry.item)}`);
2076
+ }
2005
2077
  });
2006
2078
  }
2079
+ if (!isLastStep) {
2080
+ lines.push(`${indent}end`);
2081
+ }
2007
2082
  return lines.join("\n");
2008
2083
  } else if (step.kind === "Dispatch") {
2009
2084
  const lines = [`${indent}|> dispatch`];
@@ -2082,12 +2157,20 @@ function formatPipelineRef(ref) {
2082
2157
  items.push({ type: "step", item: step, position: step.start });
2083
2158
  });
2084
2159
  ref.pipeline.comments.forEach((comment) => {
2085
- items.push({ type: "comment", item: comment, position: comment.lineNumber || 0 });
2160
+ items.push({ type: "comment", item: comment, position: comment.start || 0 });
2086
2161
  });
2087
2162
  items.sort((a, b) => a.position - b.position);
2088
- items.forEach((entry) => {
2163
+ let lastStepIndex = -1;
2164
+ for (let i = items.length - 1; i >= 0; i--) {
2165
+ if (items[i].type === "step") {
2166
+ lastStepIndex = i;
2167
+ break;
2168
+ }
2169
+ }
2170
+ items.forEach((entry, index) => {
2089
2171
  if (entry.type === "step") {
2090
- lines.push(formatPipelineStep(entry.item));
2172
+ const isLastStep = index === lastStepIndex;
2173
+ lines.push(formatPipelineStep(entry.item, " ", isLastStep));
2091
2174
  } else {
2092
2175
  lines.push(` ${printComment(entry.item)}`);
2093
2176
  }
@@ -2126,6 +2209,7 @@ function formatWhen(when) {
2126
2209
  printCondition,
2127
2210
  printConfig,
2128
2211
  printDescribe,
2212
+ printFeatureFlags,
2129
2213
  printGraphQLSchema,
2130
2214
  printMock,
2131
2215
  printMutationResolver,
package/dist/index.d.cts CHANGED
@@ -16,6 +16,7 @@ interface Comment {
16
16
  text: string;
17
17
  style: '#' | '//';
18
18
  lineNumber?: number;
19
+ start?: number;
19
20
  }
20
21
  interface Config {
21
22
  name: string;
@@ -331,6 +332,7 @@ declare function printGraphQLSchema(schema: GraphQLSchema): string;
331
332
  declare function printQueryResolver(query: QueryResolver): string;
332
333
  declare function printMutationResolver(mutation: MutationResolver): string;
333
334
  declare function printTypeResolver(resolver: TypeResolver): string;
335
+ declare function printFeatureFlags(pipeline: Pipeline): string;
334
336
  declare function printMock(mock: Mock, indent?: string): string;
335
337
  declare function printCondition(condition: Condition, indent?: string): string;
336
338
  declare function printTest(test: It): string;
@@ -338,7 +340,7 @@ declare function printComment(comment: Comment): string;
338
340
  declare function printDescribe(describe: Describe): string;
339
341
  declare function prettyPrint(program: Program): string;
340
342
  declare function formatConfigValue(value: ConfigValue): string;
341
- declare function formatPipelineStep(step: PipelineStep, indent?: string): string;
343
+ declare function formatPipelineStep(step: PipelineStep, indent?: string, isLastStep?: boolean): string;
342
344
  declare function formatStepConfig(config: string, configType: ConfigType): string;
343
345
  declare function formatTags(tags: Tag[]): string;
344
346
  declare function formatTag(tag: Tag): string;
@@ -346,4 +348,4 @@ declare function formatTagExpr(expr: TagExpr): string;
346
348
  declare function formatPipelineRef(ref: PipelineRef): string[];
347
349
  declare function formatWhen(when: When): string;
348
350
 
349
- 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, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printTypeResolver, printVariable };
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 };
package/dist/index.d.ts CHANGED
@@ -16,6 +16,7 @@ interface Comment {
16
16
  text: string;
17
17
  style: '#' | '//';
18
18
  lineNumber?: number;
19
+ start?: number;
19
20
  }
20
21
  interface Config {
21
22
  name: string;
@@ -331,6 +332,7 @@ declare function printGraphQLSchema(schema: GraphQLSchema): string;
331
332
  declare function printQueryResolver(query: QueryResolver): string;
332
333
  declare function printMutationResolver(mutation: MutationResolver): string;
333
334
  declare function printTypeResolver(resolver: TypeResolver): string;
335
+ declare function printFeatureFlags(pipeline: Pipeline): string;
334
336
  declare function printMock(mock: Mock, indent?: string): string;
335
337
  declare function printCondition(condition: Condition, indent?: string): string;
336
338
  declare function printTest(test: It): string;
@@ -338,7 +340,7 @@ declare function printComment(comment: Comment): string;
338
340
  declare function printDescribe(describe: Describe): string;
339
341
  declare function prettyPrint(program: Program): string;
340
342
  declare function formatConfigValue(value: ConfigValue): string;
341
- declare function formatPipelineStep(step: PipelineStep, indent?: string): string;
343
+ declare function formatPipelineStep(step: PipelineStep, indent?: string, isLastStep?: boolean): string;
342
344
  declare function formatStepConfig(config: string, configType: ConfigType): string;
343
345
  declare function formatTags(tags: Tag[]): string;
344
346
  declare function formatTag(tag: Tag): string;
@@ -346,4 +348,4 @@ declare function formatTagExpr(expr: TagExpr): string;
346
348
  declare function formatPipelineRef(ref: PipelineRef): string[];
347
349
  declare function formatWhen(when: When): string;
348
350
 
349
- 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, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printTypeResolver, printVariable };
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 };
package/dist/index.mjs CHANGED
@@ -78,7 +78,8 @@ var Parser = class {
78
78
  type: "standalone",
79
79
  text: restOfLine,
80
80
  style: "#",
81
- lineNumber: this.getLineNumber(start)
81
+ lineNumber: this.getLineNumber(start),
82
+ start
82
83
  };
83
84
  }
84
85
  if (this.text.startsWith("//", this.pos)) {
@@ -88,7 +89,8 @@ var Parser = class {
88
89
  type: "standalone",
89
90
  text,
90
91
  style: "//",
91
- lineNumber: this.getLineNumber(start)
92
+ lineNumber: this.getLineNumber(start),
93
+ start
92
94
  };
93
95
  }
94
96
  return null;
@@ -720,15 +722,15 @@ var Parser = class {
720
722
  const condition = this.parseIfPipeline("then:");
721
723
  this.skipSpaces();
722
724
  this.expect("then:");
723
- this.skipSpaces();
725
+ this.skipWhitespaceOnly();
724
726
  const thenBranch = this.parseIfPipeline("else:", "end");
725
- this.skipSpaces();
727
+ this.skipWhitespaceOnly();
726
728
  const elseBranch = this.tryParse(() => {
727
729
  this.expect("else:");
728
- this.skipSpaces();
730
+ this.skipWhitespaceOnly();
729
731
  return this.parseIfPipeline("end");
730
732
  });
731
- this.skipSpaces();
733
+ this.skipWhitespaceOnly();
732
734
  this.tryParse(() => {
733
735
  this.expect("end");
734
736
  return true;
@@ -855,8 +857,15 @@ var Parser = class {
855
857
  break;
856
858
  }
857
859
  const hasFollowingStep = this.text.startsWith("|>", this.pos);
860
+ let hasStopKeyword = false;
861
+ for (const keyword of stopKeywords) {
862
+ if (this.text.startsWith(keyword, this.pos)) {
863
+ hasStopKeyword = true;
864
+ break;
865
+ }
866
+ }
858
867
  this.pos = lookAheadPos;
859
- if (hasFollowingStep || steps.length === 0) {
868
+ if (hasFollowingStep || hasStopKeyword || steps.length === 0) {
860
869
  comments.push(comment);
861
870
  if (this.cur() === "\n") this.pos++;
862
871
  continue;
@@ -1606,7 +1615,7 @@ function printPipeline(pipeline) {
1606
1615
  items.push({ type: "step", item: step, position: step.start });
1607
1616
  });
1608
1617
  pipeline.pipeline.comments.forEach((comment) => {
1609
- items.push({ type: "comment", item: comment, position: comment.lineNumber || 0 });
1618
+ items.push({ type: "comment", item: comment, position: comment.start || 0 });
1610
1619
  });
1611
1620
  items.sort((a, b) => a.position - b.position);
1612
1621
  items.forEach((entry) => {
@@ -1668,6 +1677,26 @@ function printTypeResolver(resolver) {
1668
1677
  });
1669
1678
  return lines.join("\n");
1670
1679
  }
1680
+ function printFeatureFlags(pipeline) {
1681
+ const lines = [];
1682
+ lines.push("featureFlags =");
1683
+ const items = [];
1684
+ pipeline.steps.forEach((step) => {
1685
+ items.push({ type: "step", item: step, position: step.start });
1686
+ });
1687
+ pipeline.comments.forEach((comment) => {
1688
+ items.push({ type: "comment", item: comment, position: comment.start || 0 });
1689
+ });
1690
+ items.sort((a, b) => a.position - b.position);
1691
+ items.forEach((entry) => {
1692
+ if (entry.type === "step") {
1693
+ lines.push(formatPipelineStep(entry.item));
1694
+ } else {
1695
+ lines.push(` ${printComment(entry.item)}`);
1696
+ }
1697
+ });
1698
+ return lines.join("\n");
1699
+ }
1671
1700
  function printMock(mock, indent = " ") {
1672
1701
  const target = mock.target.replace(/^(query|mutation)\.(.*)$/, "$1 $2");
1673
1702
  return `${indent}with mock ${target} returning \`${mock.returnValue}\``;
@@ -1845,6 +1874,9 @@ function prettyPrint(program) {
1845
1874
  program.variables.forEach((variable) => {
1846
1875
  allItems.push({ type: "variable", item: variable, lineNumber: variable.lineNumber || 0 });
1847
1876
  });
1877
+ if (program.featureFlags) {
1878
+ allItems.push({ type: "featureFlags", item: program.featureFlags, lineNumber: program.featureFlags.start || 0 });
1879
+ }
1848
1880
  program.describes.forEach((describe) => {
1849
1881
  allItems.push({ type: "describe", item: describe, lineNumber: describe.lineNumber || 0 });
1850
1882
  });
@@ -1898,6 +1930,9 @@ function prettyPrint(program) {
1898
1930
  case "variable":
1899
1931
  lines.push(printVariable(entry.item));
1900
1932
  break;
1933
+ case "featureFlags":
1934
+ lines.push(printFeatureFlags(entry.item));
1935
+ break;
1901
1936
  case "describe":
1902
1937
  lines.push(printDescribe(entry.item));
1903
1938
  break;
@@ -1920,7 +1955,7 @@ function formatConfigValue(value) {
1920
1955
  return value.value.toString();
1921
1956
  }
1922
1957
  }
1923
- function formatPipelineStep(step, indent = " ") {
1958
+ function formatPipelineStep(step, indent = " ", isLastStep = false) {
1924
1959
  if (step.kind === "Regular") {
1925
1960
  const argsPart = step.args.length > 0 ? `(${step.args.join(", ")})` : "";
1926
1961
  const configPart = formatStepConfig(step.config, step.configType);
@@ -1938,19 +1973,58 @@ function formatPipelineStep(step, indent = " ") {
1938
1973
  return lines.join("\n");
1939
1974
  } else if (step.kind === "If") {
1940
1975
  const lines = [`${indent}|> if`];
1941
- step.condition.steps.forEach((condStep) => {
1942
- lines.push(formatPipelineStep(condStep, indent + " "));
1976
+ const conditionItems = [];
1977
+ step.condition.steps.forEach((s) => {
1978
+ conditionItems.push({ type: "step", item: s, position: s.start });
1979
+ });
1980
+ step.condition.comments.forEach((c) => {
1981
+ conditionItems.push({ type: "comment", item: c, position: c.start || 0 });
1982
+ });
1983
+ conditionItems.sort((a, b) => a.position - b.position);
1984
+ conditionItems.forEach((entry) => {
1985
+ if (entry.type === "step") {
1986
+ lines.push(formatPipelineStep(entry.item, indent + " "));
1987
+ } else {
1988
+ lines.push(`${indent} ${printComment(entry.item)}`);
1989
+ }
1943
1990
  });
1944
1991
  lines.push(`${indent} then:`);
1945
- step.thenBranch.steps.forEach((thenStep) => {
1946
- lines.push(formatPipelineStep(thenStep, indent + " "));
1992
+ const thenItems = [];
1993
+ step.thenBranch.steps.forEach((s) => {
1994
+ thenItems.push({ type: "step", item: s, position: s.start });
1995
+ });
1996
+ step.thenBranch.comments.forEach((c) => {
1997
+ thenItems.push({ type: "comment", item: c, position: c.start || 0 });
1998
+ });
1999
+ thenItems.sort((a, b) => a.position - b.position);
2000
+ thenItems.forEach((entry) => {
2001
+ if (entry.type === "step") {
2002
+ lines.push(formatPipelineStep(entry.item, indent + " "));
2003
+ } else {
2004
+ lines.push(`${indent} ${printComment(entry.item)}`);
2005
+ }
1947
2006
  });
1948
2007
  if (step.elseBranch) {
1949
2008
  lines.push(`${indent} else:`);
1950
- step.elseBranch.steps.forEach((elseStep) => {
1951
- lines.push(formatPipelineStep(elseStep, indent + " "));
2009
+ const elseItems = [];
2010
+ step.elseBranch.steps.forEach((s) => {
2011
+ elseItems.push({ type: "step", item: s, position: s.start });
2012
+ });
2013
+ step.elseBranch.comments.forEach((c) => {
2014
+ elseItems.push({ type: "comment", item: c, position: c.start || 0 });
2015
+ });
2016
+ elseItems.sort((a, b) => a.position - b.position);
2017
+ elseItems.forEach((entry) => {
2018
+ if (entry.type === "step") {
2019
+ lines.push(formatPipelineStep(entry.item, indent + " "));
2020
+ } else {
2021
+ lines.push(`${indent} ${printComment(entry.item)}`);
2022
+ }
1952
2023
  });
1953
2024
  }
2025
+ if (!isLastStep) {
2026
+ lines.push(`${indent}end`);
2027
+ }
1954
2028
  return lines.join("\n");
1955
2029
  } else if (step.kind === "Dispatch") {
1956
2030
  const lines = [`${indent}|> dispatch`];
@@ -2029,12 +2103,20 @@ function formatPipelineRef(ref) {
2029
2103
  items.push({ type: "step", item: step, position: step.start });
2030
2104
  });
2031
2105
  ref.pipeline.comments.forEach((comment) => {
2032
- items.push({ type: "comment", item: comment, position: comment.lineNumber || 0 });
2106
+ items.push({ type: "comment", item: comment, position: comment.start || 0 });
2033
2107
  });
2034
2108
  items.sort((a, b) => a.position - b.position);
2035
- items.forEach((entry) => {
2109
+ let lastStepIndex = -1;
2110
+ for (let i = items.length - 1; i >= 0; i--) {
2111
+ if (items[i].type === "step") {
2112
+ lastStepIndex = i;
2113
+ break;
2114
+ }
2115
+ }
2116
+ items.forEach((entry, index) => {
2036
2117
  if (entry.type === "step") {
2037
- lines.push(formatPipelineStep(entry.item));
2118
+ const isLastStep = index === lastStepIndex;
2119
+ lines.push(formatPipelineStep(entry.item, " ", isLastStep));
2038
2120
  } else {
2039
2121
  lines.push(` ${printComment(entry.item)}`);
2040
2122
  }
@@ -2072,6 +2154,7 @@ export {
2072
2154
  printCondition,
2073
2155
  printConfig,
2074
2156
  printDescribe,
2157
+ printFeatureFlags,
2075
2158
  printGraphQLSchema,
2076
2159
  printMock,
2077
2160
  printMutationResolver,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "2.0.63",
3
+ "version": "2.0.65",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",