webpipe-js 2.0.50 → 2.0.52

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
@@ -127,21 +127,27 @@ var Parser = class {
127
127
  const originalPos = this.pos;
128
128
  this.pos++;
129
129
  const restOfLine = this.consumeWhile((ch) => ch !== "\n");
130
+ const end = this.pos;
130
131
  return {
131
132
  type: "standalone",
132
133
  text: restOfLine,
133
134
  style: "#",
134
- lineNumber: this.getLineNumber(start)
135
+ lineNumber: this.getLineNumber(start),
136
+ start,
137
+ end
135
138
  };
136
139
  }
137
140
  if (this.text.startsWith("//", this.pos)) {
138
141
  this.pos += 2;
139
142
  const text = this.consumeWhile((ch) => ch !== "\n");
143
+ const end = this.pos;
140
144
  return {
141
145
  type: "standalone",
142
146
  text,
143
147
  style: "//",
144
- lineNumber: this.getLineNumber(start)
148
+ lineNumber: this.getLineNumber(start),
149
+ start,
150
+ end
145
151
  };
146
152
  }
147
153
  return null;
@@ -889,14 +895,20 @@ var Parser = class {
889
895
  parseIfPipeline(...stopKeywords) {
890
896
  const start = this.pos;
891
897
  const steps = [];
898
+ const comments = [];
892
899
  while (true) {
893
900
  const save = this.pos;
894
901
  this.skipSpaces();
902
+ const comment = this.tryParse(() => this.parseStandaloneComment());
903
+ if (comment) {
904
+ comments.push(comment);
905
+ continue;
906
+ }
895
907
  for (const keyword of stopKeywords) {
896
908
  if (this.text.startsWith(keyword, this.pos)) {
897
909
  this.pos = save;
898
910
  const end2 = this.pos;
899
- return { steps, start, end: end2 };
911
+ return { steps, comments, start, end: end2 };
900
912
  }
901
913
  }
902
914
  if (!this.text.startsWith("|>", this.pos)) {
@@ -907,14 +919,20 @@ var Parser = class {
907
919
  steps.push(step);
908
920
  }
909
921
  const end = this.pos;
910
- return { steps, start, end };
922
+ return { steps, comments, start, end };
911
923
  }
912
924
  parsePipeline() {
913
925
  const start = this.pos;
914
926
  const steps = [];
927
+ const comments = [];
915
928
  while (true) {
916
929
  const save = this.pos;
917
930
  this.skipSpaces();
931
+ const comment = this.tryParse(() => this.parseStandaloneComment());
932
+ if (comment) {
933
+ comments.push(comment);
934
+ continue;
935
+ }
918
936
  if (!this.text.startsWith("|>", this.pos)) {
919
937
  this.pos = save;
920
938
  break;
@@ -923,7 +941,7 @@ var Parser = class {
923
941
  steps.push(step);
924
942
  }
925
943
  const end = this.pos;
926
- return { steps, start, end };
944
+ return { steps, comments, start, end };
927
945
  }
928
946
  parseNamedPipeline() {
929
947
  const start = this.pos;
@@ -1597,8 +1615,22 @@ function printPipeline(pipeline) {
1597
1615
  } else {
1598
1616
  lines.push(pipelineLine);
1599
1617
  }
1618
+ const items = [];
1600
1619
  pipeline.pipeline.steps.forEach((step) => {
1601
- lines.push(formatPipelineStep(step));
1620
+ items.push({ type: "step", item: step, position: step.start });
1621
+ });
1622
+ pipeline.pipeline.comments.forEach((comment) => {
1623
+ if (comment.start !== void 0) {
1624
+ items.push({ type: "comment", item: comment, position: comment.start });
1625
+ }
1626
+ });
1627
+ items.sort((a, b) => a.position - b.position);
1628
+ items.forEach((entry) => {
1629
+ if (entry.type === "step") {
1630
+ lines.push(formatPipelineStep(entry.item));
1631
+ } else {
1632
+ lines.push(` ${printComment(entry.item)}`);
1633
+ }
1602
1634
  });
1603
1635
  return lines.join("\n");
1604
1636
  }
@@ -1997,8 +2029,22 @@ function formatPipelineRef(ref) {
1997
2029
  return [` |> pipeline: ${ref.name}`];
1998
2030
  } else {
1999
2031
  const lines = [];
2032
+ const items = [];
2000
2033
  ref.pipeline.steps.forEach((step) => {
2001
- lines.push(formatPipelineStep(step));
2034
+ items.push({ type: "step", item: step, position: step.start });
2035
+ });
2036
+ ref.pipeline.comments.forEach((comment) => {
2037
+ if (comment.start !== void 0) {
2038
+ items.push({ type: "comment", item: comment, position: comment.start });
2039
+ }
2040
+ });
2041
+ items.sort((a, b) => a.position - b.position);
2042
+ items.forEach((entry) => {
2043
+ if (entry.type === "step") {
2044
+ lines.push(formatPipelineStep(entry.item));
2045
+ } else {
2046
+ lines.push(` ${printComment(entry.item)}`);
2047
+ }
2002
2048
  });
2003
2049
  return lines;
2004
2050
  }
package/dist/index.d.cts CHANGED
@@ -16,6 +16,8 @@ interface Comment {
16
16
  text: string;
17
17
  style: '#' | '//';
18
18
  lineNumber?: number;
19
+ start?: number;
20
+ end?: number;
19
21
  }
20
22
  interface Config {
21
23
  name: string;
@@ -116,6 +118,7 @@ type PipelineRef = {
116
118
  };
117
119
  interface Pipeline {
118
120
  steps: PipelineStep[];
121
+ comments: Comment[];
119
122
  start: number;
120
123
  end: number;
121
124
  }
package/dist/index.d.ts CHANGED
@@ -16,6 +16,8 @@ interface Comment {
16
16
  text: string;
17
17
  style: '#' | '//';
18
18
  lineNumber?: number;
19
+ start?: number;
20
+ end?: number;
19
21
  }
20
22
  interface Config {
21
23
  name: string;
@@ -116,6 +118,7 @@ type PipelineRef = {
116
118
  };
117
119
  interface Pipeline {
118
120
  steps: PipelineStep[];
121
+ comments: Comment[];
119
122
  start: number;
120
123
  end: number;
121
124
  }
package/dist/index.mjs CHANGED
@@ -74,21 +74,27 @@ var Parser = class {
74
74
  const originalPos = this.pos;
75
75
  this.pos++;
76
76
  const restOfLine = this.consumeWhile((ch) => ch !== "\n");
77
+ const end = this.pos;
77
78
  return {
78
79
  type: "standalone",
79
80
  text: restOfLine,
80
81
  style: "#",
81
- lineNumber: this.getLineNumber(start)
82
+ lineNumber: this.getLineNumber(start),
83
+ start,
84
+ end
82
85
  };
83
86
  }
84
87
  if (this.text.startsWith("//", this.pos)) {
85
88
  this.pos += 2;
86
89
  const text = this.consumeWhile((ch) => ch !== "\n");
90
+ const end = this.pos;
87
91
  return {
88
92
  type: "standalone",
89
93
  text,
90
94
  style: "//",
91
- lineNumber: this.getLineNumber(start)
95
+ lineNumber: this.getLineNumber(start),
96
+ start,
97
+ end
92
98
  };
93
99
  }
94
100
  return null;
@@ -836,14 +842,20 @@ var Parser = class {
836
842
  parseIfPipeline(...stopKeywords) {
837
843
  const start = this.pos;
838
844
  const steps = [];
845
+ const comments = [];
839
846
  while (true) {
840
847
  const save = this.pos;
841
848
  this.skipSpaces();
849
+ const comment = this.tryParse(() => this.parseStandaloneComment());
850
+ if (comment) {
851
+ comments.push(comment);
852
+ continue;
853
+ }
842
854
  for (const keyword of stopKeywords) {
843
855
  if (this.text.startsWith(keyword, this.pos)) {
844
856
  this.pos = save;
845
857
  const end2 = this.pos;
846
- return { steps, start, end: end2 };
858
+ return { steps, comments, start, end: end2 };
847
859
  }
848
860
  }
849
861
  if (!this.text.startsWith("|>", this.pos)) {
@@ -854,14 +866,20 @@ var Parser = class {
854
866
  steps.push(step);
855
867
  }
856
868
  const end = this.pos;
857
- return { steps, start, end };
869
+ return { steps, comments, start, end };
858
870
  }
859
871
  parsePipeline() {
860
872
  const start = this.pos;
861
873
  const steps = [];
874
+ const comments = [];
862
875
  while (true) {
863
876
  const save = this.pos;
864
877
  this.skipSpaces();
878
+ const comment = this.tryParse(() => this.parseStandaloneComment());
879
+ if (comment) {
880
+ comments.push(comment);
881
+ continue;
882
+ }
865
883
  if (!this.text.startsWith("|>", this.pos)) {
866
884
  this.pos = save;
867
885
  break;
@@ -870,7 +888,7 @@ var Parser = class {
870
888
  steps.push(step);
871
889
  }
872
890
  const end = this.pos;
873
- return { steps, start, end };
891
+ return { steps, comments, start, end };
874
892
  }
875
893
  parseNamedPipeline() {
876
894
  const start = this.pos;
@@ -1544,8 +1562,22 @@ function printPipeline(pipeline) {
1544
1562
  } else {
1545
1563
  lines.push(pipelineLine);
1546
1564
  }
1565
+ const items = [];
1547
1566
  pipeline.pipeline.steps.forEach((step) => {
1548
- lines.push(formatPipelineStep(step));
1567
+ items.push({ type: "step", item: step, position: step.start });
1568
+ });
1569
+ pipeline.pipeline.comments.forEach((comment) => {
1570
+ if (comment.start !== void 0) {
1571
+ items.push({ type: "comment", item: comment, position: comment.start });
1572
+ }
1573
+ });
1574
+ items.sort((a, b) => a.position - b.position);
1575
+ items.forEach((entry) => {
1576
+ if (entry.type === "step") {
1577
+ lines.push(formatPipelineStep(entry.item));
1578
+ } else {
1579
+ lines.push(` ${printComment(entry.item)}`);
1580
+ }
1549
1581
  });
1550
1582
  return lines.join("\n");
1551
1583
  }
@@ -1944,8 +1976,22 @@ function formatPipelineRef(ref) {
1944
1976
  return [` |> pipeline: ${ref.name}`];
1945
1977
  } else {
1946
1978
  const lines = [];
1979
+ const items = [];
1947
1980
  ref.pipeline.steps.forEach((step) => {
1948
- lines.push(formatPipelineStep(step));
1981
+ items.push({ type: "step", item: step, position: step.start });
1982
+ });
1983
+ ref.pipeline.comments.forEach((comment) => {
1984
+ if (comment.start !== void 0) {
1985
+ items.push({ type: "comment", item: comment, position: comment.start });
1986
+ }
1987
+ });
1988
+ items.sort((a, b) => a.position - b.position);
1989
+ items.forEach((entry) => {
1990
+ if (entry.type === "step") {
1991
+ lines.push(formatPipelineStep(entry.item));
1992
+ } else {
1993
+ lines.push(` ${printComment(entry.item)}`);
1994
+ }
1949
1995
  });
1950
1996
  return lines;
1951
1997
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "2.0.50",
3
+ "version": "2.0.52",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",