webpipe-js 2.0.69 → 2.0.81

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
@@ -299,6 +299,32 @@ var Parser = class {
299
299
  skipWhitespaceOnly() {
300
300
  this.consumeWhile((ch) => ch === " " || ch === " " || ch === "\r" || ch === "\n");
301
301
  }
302
+ skipStandaloneCommentsBeforeKeywords(keywords) {
303
+ while (true) {
304
+ this.skipWhitespaceOnly();
305
+ const commentStart = this.pos;
306
+ const comment = this.tryParse(() => this.parseStandaloneComment());
307
+ if (!comment) {
308
+ this.pos = commentStart;
309
+ return;
310
+ }
311
+ const afterComment = this.pos;
312
+ if (this.cur() === "\n") this.pos++;
313
+ while (true) {
314
+ this.skipWhitespaceOnly();
315
+ const nestedComment = this.tryParse(() => this.parseStandaloneComment());
316
+ if (!nestedComment) break;
317
+ if (this.cur() === "\n") this.pos++;
318
+ }
319
+ const followedByKeyword = keywords.some((keyword) => this.text.startsWith(keyword, this.pos));
320
+ this.pos = afterComment;
321
+ if (!followedByKeyword) {
322
+ this.pos = commentStart;
323
+ return;
324
+ }
325
+ if (this.cur() === "\n") this.pos++;
326
+ }
327
+ }
302
328
  skipInlineSpaces() {
303
329
  this.consumeWhile((ch) => ch === " " || ch === " " || ch === "\r");
304
330
  }
@@ -563,13 +589,17 @@ var Parser = class {
563
589
  const nameStart = this.pos;
564
590
  const name = this.parseIdentifier();
565
591
  const nameEnd = this.pos;
566
- const args = this.parseInlineArgs();
592
+ const inlineArgs = this.parseInlineArgs();
593
+ const args = inlineArgs.args;
594
+ const argSpans = inlineArgs.argSpans;
567
595
  this.skipInlineSpaces();
568
596
  let config = "";
569
597
  let configType = "quoted";
598
+ let hasConfig = false;
570
599
  let configStart = void 0;
571
600
  let configEnd = void 0;
572
601
  if (this.cur() === ":") {
602
+ hasConfig = true;
573
603
  this.pos++;
574
604
  this.skipInlineSpaces();
575
605
  configStart = this.pos;
@@ -582,7 +612,7 @@ var Parser = class {
582
612
  const parsedJoinTargets = name === "join" ? this.parseJoinTaskNames(config) : void 0;
583
613
  this.skipWhitespaceOnly();
584
614
  const end = this.pos;
585
- return { kind: "Regular", name, nameStart, nameEnd, args, config, configType, configStart, configEnd, condition, parsedJoinTargets, start, end };
615
+ return { kind: "Regular", name, nameStart, nameEnd, args, argSpans, config, configType, hasConfig, configStart, configEnd, condition, parsedJoinTargets, start, end };
586
616
  }
587
617
  /**
588
618
  * Parse optional step condition (tag expression after the config)
@@ -640,58 +670,58 @@ var Parser = class {
640
670
  * Split argument content by commas while respecting nesting depth and strings
641
671
  * Example: `"url", {a:1, b:2}` -> [`"url"`, `{a:1, b:2}`]
642
672
  */
643
- splitBalancedArgs(content) {
673
+ splitBalancedArgs(content, baseOffset) {
644
674
  const args = [];
645
- let current = "";
675
+ const argSpans = [];
676
+ let segmentStart = 0;
646
677
  let depth = 0;
647
678
  let inString = false;
648
679
  let stringChar = "";
649
680
  let escapeNext = false;
681
+ const pushArg = (segmentEnd) => {
682
+ let start = segmentStart;
683
+ let end = segmentEnd;
684
+ while (start < end && /\s/.test(content[start])) start++;
685
+ while (end > start && /\s/.test(content[end - 1])) end--;
686
+ if (start < end) {
687
+ args.push(content.slice(start, end));
688
+ argSpans.push({ start: baseOffset + start, end: baseOffset + end });
689
+ }
690
+ };
650
691
  for (let i = 0; i < content.length; i++) {
651
692
  const ch = content[i];
652
693
  if (escapeNext) {
653
- current += ch;
654
694
  escapeNext = false;
655
695
  continue;
656
696
  }
657
697
  if (ch === "\\" && inString) {
658
- current += ch;
659
698
  escapeNext = true;
660
699
  continue;
661
700
  }
662
- if ((ch === '"' || ch === "`") && !inString) {
701
+ if ((ch === '"' || ch === "'" || ch === "`") && !inString) {
663
702
  inString = true;
664
703
  stringChar = ch;
665
- current += ch;
666
704
  continue;
667
705
  }
668
706
  if (ch === stringChar && inString) {
669
707
  inString = false;
670
708
  stringChar = "";
671
- current += ch;
672
709
  continue;
673
710
  }
674
711
  if (inString) {
675
- current += ch;
676
712
  continue;
677
713
  }
678
714
  if (ch === "(" || ch === "[" || ch === "{") {
679
715
  depth++;
680
- current += ch;
681
716
  } else if (ch === ")" || ch === "]" || ch === "}") {
682
717
  depth--;
683
- current += ch;
684
718
  } else if (ch === "," && depth === 0) {
685
- args.push(current.trim());
686
- current = "";
687
- } else {
688
- current += ch;
719
+ pushArg(i);
720
+ segmentStart = i + 1;
689
721
  }
690
722
  }
691
- if (current.trim().length > 0) {
692
- args.push(current.trim());
693
- }
694
- return args;
723
+ pushArg(content.length);
724
+ return { args, argSpans };
695
725
  }
696
726
  /**
697
727
  * Parse inline arguments: middleware(arg1, arg2) or middleware[arg1, arg2]
@@ -703,7 +733,7 @@ var Parser = class {
703
733
  const ch = this.cur();
704
734
  if (ch !== "(" && ch !== "[") {
705
735
  this.pos = trimmedStart;
706
- return [];
736
+ return { args: [], argSpans: [] };
707
737
  }
708
738
  const openChar = ch;
709
739
  const closeChar = openChar === "(" ? ")" : "]";
@@ -755,9 +785,9 @@ var Parser = class {
755
785
  const argsContent = this.text.slice(contentStart, this.pos);
756
786
  this.pos++;
757
787
  if (argsContent.trim().length === 0) {
758
- return [];
788
+ return { args: [], argSpans: [] };
759
789
  }
760
- return this.splitBalancedArgs(argsContent);
790
+ return this.splitBalancedArgs(argsContent, contentStart);
761
791
  }
762
792
  parseResultStep() {
763
793
  this.skipWhitespaceOnly();
@@ -835,11 +865,13 @@ var Parser = class {
835
865
  this.skipWhitespaceOnly();
836
866
  const branches = [];
837
867
  while (true) {
868
+ this.skipStandaloneCommentsBeforeKeywords(["case", "default:", "end"]);
838
869
  const branch = this.tryParse(() => this.parseDispatchBranch());
839
870
  if (!branch) break;
840
871
  branches.push(branch);
841
872
  this.skipWhitespaceOnly();
842
873
  }
874
+ this.skipStandaloneCommentsBeforeKeywords(["default:", "end"]);
843
875
  const defaultBranch = this.tryParse(() => {
844
876
  this.expect("default:");
845
877
  this.skipWhitespaceOnly();
@@ -2073,9 +2105,9 @@ function formatConfigValue(value) {
2073
2105
  function formatPipelineStep(step, indent = " ", isLastStep = false) {
2074
2106
  if (step.kind === "Regular") {
2075
2107
  const argsPart = step.args.length > 0 ? `(${step.args.join(", ")})` : "";
2076
- const configPart = formatStepConfig(step.config, step.configType);
2077
2108
  const conditionPart = step.condition ? " " + formatTagExpr(step.condition) : "";
2078
- return `${indent}|> ${step.name}${argsPart}: ${configPart}${conditionPart}`;
2109
+ const configPart = step.hasConfig ? `: ${formatStepConfig(step.config, step.configType)}` : "";
2110
+ return `${indent}|> ${step.name}${argsPart}${configPart}${conditionPart}`;
2079
2111
  } else if (step.kind === "Result") {
2080
2112
  const lines = [`${indent}|> result`];
2081
2113
  step.branches.forEach((branch) => {
package/dist/index.d.cts CHANGED
@@ -129,6 +129,10 @@ interface Pipeline {
129
129
  end: number;
130
130
  }
131
131
  type ConfigType = 'backtick' | 'quoted' | 'identifier';
132
+ interface SourceSpan {
133
+ start: number;
134
+ end: number;
135
+ }
132
136
  type LetValueFormat = 'quoted' | 'backtick' | 'bare';
133
137
  interface LetVariable {
134
138
  name: string;
@@ -166,8 +170,10 @@ type PipelineStep = {
166
170
  nameStart: number;
167
171
  nameEnd: number;
168
172
  args: string[];
173
+ argSpans: SourceSpan[];
169
174
  config: string;
170
175
  configType: ConfigType;
176
+ hasConfig: boolean;
171
177
  configStart?: number;
172
178
  configEnd?: number;
173
179
  condition?: TagExpr;
@@ -356,4 +362,4 @@ declare function formatTagExpr(expr: TagExpr): string;
356
362
  declare function formatPipelineRef(ref: PipelineRef): string[];
357
363
  declare function formatWhen(when: When): string;
358
364
 
359
- export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type DispatchBranch, type DomAssertType, type GraphQLSchema, type Import, type It, type LetValueFormat, type LetVariable, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type Tag, type TagExpr, type TestLetVariable, type TypeResolver, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTagExpr, formatTags, formatWhen, getPipelineRanges, getTestLetVariableRanges, getTestLetVariables, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printFeatureFlags, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printTypeResolver, printVariable };
365
+ export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type DispatchBranch, type DomAssertType, type GraphQLSchema, type Import, type It, type LetValueFormat, type LetVariable, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type SourceSpan, 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
@@ -129,6 +129,10 @@ interface Pipeline {
129
129
  end: number;
130
130
  }
131
131
  type ConfigType = 'backtick' | 'quoted' | 'identifier';
132
+ interface SourceSpan {
133
+ start: number;
134
+ end: number;
135
+ }
132
136
  type LetValueFormat = 'quoted' | 'backtick' | 'bare';
133
137
  interface LetVariable {
134
138
  name: string;
@@ -166,8 +170,10 @@ type PipelineStep = {
166
170
  nameStart: number;
167
171
  nameEnd: number;
168
172
  args: string[];
173
+ argSpans: SourceSpan[];
169
174
  config: string;
170
175
  configType: ConfigType;
176
+ hasConfig: boolean;
171
177
  configStart?: number;
172
178
  configEnd?: number;
173
179
  condition?: TagExpr;
@@ -356,4 +362,4 @@ declare function formatTagExpr(expr: TagExpr): string;
356
362
  declare function formatPipelineRef(ref: PipelineRef): string[];
357
363
  declare function formatWhen(when: When): string;
358
364
 
359
- export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type DispatchBranch, type DomAssertType, type GraphQLSchema, type Import, type It, type LetValueFormat, type LetVariable, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type Tag, type TagExpr, type TestLetVariable, type TypeResolver, type Variable, type When, formatConfigValue, formatPipelineRef, formatPipelineStep, formatStepConfig, formatTag, formatTagExpr, formatTags, formatWhen, getPipelineRanges, getTestLetVariableRanges, getTestLetVariables, getVariableRanges, parseProgram, parseProgramWithDiagnostics, prettyPrint, printComment, printCondition, printConfig, printDescribe, printFeatureFlags, printGraphQLSchema, printMock, printMutationResolver, printPipeline, printQueryResolver, printRoute, printTest, printTypeResolver, printVariable };
365
+ export { type Comment, type Condition, type Config, type ConfigProperty, type ConfigType, type ConfigValue, type Describe, type DiagnosticSeverity, type DispatchBranch, type DomAssertType, type GraphQLSchema, type Import, type It, type LetValueFormat, type LetVariable, type Mock, type MutationResolver, type NamedPipeline, type ParseDiagnostic, type Pipeline, type PipelineRef, type PipelineStep, type Program, type QueryResolver, type ResultBranch, type ResultBranchType, type Route, type SourceSpan, 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
@@ -245,6 +245,32 @@ var Parser = class {
245
245
  skipWhitespaceOnly() {
246
246
  this.consumeWhile((ch) => ch === " " || ch === " " || ch === "\r" || ch === "\n");
247
247
  }
248
+ skipStandaloneCommentsBeforeKeywords(keywords) {
249
+ while (true) {
250
+ this.skipWhitespaceOnly();
251
+ const commentStart = this.pos;
252
+ const comment = this.tryParse(() => this.parseStandaloneComment());
253
+ if (!comment) {
254
+ this.pos = commentStart;
255
+ return;
256
+ }
257
+ const afterComment = this.pos;
258
+ if (this.cur() === "\n") this.pos++;
259
+ while (true) {
260
+ this.skipWhitespaceOnly();
261
+ const nestedComment = this.tryParse(() => this.parseStandaloneComment());
262
+ if (!nestedComment) break;
263
+ if (this.cur() === "\n") this.pos++;
264
+ }
265
+ const followedByKeyword = keywords.some((keyword) => this.text.startsWith(keyword, this.pos));
266
+ this.pos = afterComment;
267
+ if (!followedByKeyword) {
268
+ this.pos = commentStart;
269
+ return;
270
+ }
271
+ if (this.cur() === "\n") this.pos++;
272
+ }
273
+ }
248
274
  skipInlineSpaces() {
249
275
  this.consumeWhile((ch) => ch === " " || ch === " " || ch === "\r");
250
276
  }
@@ -509,13 +535,17 @@ var Parser = class {
509
535
  const nameStart = this.pos;
510
536
  const name = this.parseIdentifier();
511
537
  const nameEnd = this.pos;
512
- const args = this.parseInlineArgs();
538
+ const inlineArgs = this.parseInlineArgs();
539
+ const args = inlineArgs.args;
540
+ const argSpans = inlineArgs.argSpans;
513
541
  this.skipInlineSpaces();
514
542
  let config = "";
515
543
  let configType = "quoted";
544
+ let hasConfig = false;
516
545
  let configStart = void 0;
517
546
  let configEnd = void 0;
518
547
  if (this.cur() === ":") {
548
+ hasConfig = true;
519
549
  this.pos++;
520
550
  this.skipInlineSpaces();
521
551
  configStart = this.pos;
@@ -528,7 +558,7 @@ var Parser = class {
528
558
  const parsedJoinTargets = name === "join" ? this.parseJoinTaskNames(config) : void 0;
529
559
  this.skipWhitespaceOnly();
530
560
  const end = this.pos;
531
- return { kind: "Regular", name, nameStart, nameEnd, args, config, configType, configStart, configEnd, condition, parsedJoinTargets, start, end };
561
+ return { kind: "Regular", name, nameStart, nameEnd, args, argSpans, config, configType, hasConfig, configStart, configEnd, condition, parsedJoinTargets, start, end };
532
562
  }
533
563
  /**
534
564
  * Parse optional step condition (tag expression after the config)
@@ -586,58 +616,58 @@ var Parser = class {
586
616
  * Split argument content by commas while respecting nesting depth and strings
587
617
  * Example: `"url", {a:1, b:2}` -> [`"url"`, `{a:1, b:2}`]
588
618
  */
589
- splitBalancedArgs(content) {
619
+ splitBalancedArgs(content, baseOffset) {
590
620
  const args = [];
591
- let current = "";
621
+ const argSpans = [];
622
+ let segmentStart = 0;
592
623
  let depth = 0;
593
624
  let inString = false;
594
625
  let stringChar = "";
595
626
  let escapeNext = false;
627
+ const pushArg = (segmentEnd) => {
628
+ let start = segmentStart;
629
+ let end = segmentEnd;
630
+ while (start < end && /\s/.test(content[start])) start++;
631
+ while (end > start && /\s/.test(content[end - 1])) end--;
632
+ if (start < end) {
633
+ args.push(content.slice(start, end));
634
+ argSpans.push({ start: baseOffset + start, end: baseOffset + end });
635
+ }
636
+ };
596
637
  for (let i = 0; i < content.length; i++) {
597
638
  const ch = content[i];
598
639
  if (escapeNext) {
599
- current += ch;
600
640
  escapeNext = false;
601
641
  continue;
602
642
  }
603
643
  if (ch === "\\" && inString) {
604
- current += ch;
605
644
  escapeNext = true;
606
645
  continue;
607
646
  }
608
- if ((ch === '"' || ch === "`") && !inString) {
647
+ if ((ch === '"' || ch === "'" || ch === "`") && !inString) {
609
648
  inString = true;
610
649
  stringChar = ch;
611
- current += ch;
612
650
  continue;
613
651
  }
614
652
  if (ch === stringChar && inString) {
615
653
  inString = false;
616
654
  stringChar = "";
617
- current += ch;
618
655
  continue;
619
656
  }
620
657
  if (inString) {
621
- current += ch;
622
658
  continue;
623
659
  }
624
660
  if (ch === "(" || ch === "[" || ch === "{") {
625
661
  depth++;
626
- current += ch;
627
662
  } else if (ch === ")" || ch === "]" || ch === "}") {
628
663
  depth--;
629
- current += ch;
630
664
  } else if (ch === "," && depth === 0) {
631
- args.push(current.trim());
632
- current = "";
633
- } else {
634
- current += ch;
665
+ pushArg(i);
666
+ segmentStart = i + 1;
635
667
  }
636
668
  }
637
- if (current.trim().length > 0) {
638
- args.push(current.trim());
639
- }
640
- return args;
669
+ pushArg(content.length);
670
+ return { args, argSpans };
641
671
  }
642
672
  /**
643
673
  * Parse inline arguments: middleware(arg1, arg2) or middleware[arg1, arg2]
@@ -649,7 +679,7 @@ var Parser = class {
649
679
  const ch = this.cur();
650
680
  if (ch !== "(" && ch !== "[") {
651
681
  this.pos = trimmedStart;
652
- return [];
682
+ return { args: [], argSpans: [] };
653
683
  }
654
684
  const openChar = ch;
655
685
  const closeChar = openChar === "(" ? ")" : "]";
@@ -701,9 +731,9 @@ var Parser = class {
701
731
  const argsContent = this.text.slice(contentStart, this.pos);
702
732
  this.pos++;
703
733
  if (argsContent.trim().length === 0) {
704
- return [];
734
+ return { args: [], argSpans: [] };
705
735
  }
706
- return this.splitBalancedArgs(argsContent);
736
+ return this.splitBalancedArgs(argsContent, contentStart);
707
737
  }
708
738
  parseResultStep() {
709
739
  this.skipWhitespaceOnly();
@@ -781,11 +811,13 @@ var Parser = class {
781
811
  this.skipWhitespaceOnly();
782
812
  const branches = [];
783
813
  while (true) {
814
+ this.skipStandaloneCommentsBeforeKeywords(["case", "default:", "end"]);
784
815
  const branch = this.tryParse(() => this.parseDispatchBranch());
785
816
  if (!branch) break;
786
817
  branches.push(branch);
787
818
  this.skipWhitespaceOnly();
788
819
  }
820
+ this.skipStandaloneCommentsBeforeKeywords(["default:", "end"]);
789
821
  const defaultBranch = this.tryParse(() => {
790
822
  this.expect("default:");
791
823
  this.skipWhitespaceOnly();
@@ -2019,9 +2051,9 @@ function formatConfigValue(value) {
2019
2051
  function formatPipelineStep(step, indent = " ", isLastStep = false) {
2020
2052
  if (step.kind === "Regular") {
2021
2053
  const argsPart = step.args.length > 0 ? `(${step.args.join(", ")})` : "";
2022
- const configPart = formatStepConfig(step.config, step.configType);
2023
2054
  const conditionPart = step.condition ? " " + formatTagExpr(step.condition) : "";
2024
- return `${indent}|> ${step.name}${argsPart}: ${configPart}${conditionPart}`;
2055
+ const configPart = step.hasConfig ? `: ${formatStepConfig(step.config, step.configType)}` : "";
2056
+ return `${indent}|> ${step.name}${argsPart}${configPart}${conditionPart}`;
2025
2057
  } else if (step.kind === "Result") {
2026
2058
  const lines = [`${indent}|> result`];
2027
2059
  step.branches.forEach((branch) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "2.0.69",
3
+ "version": "2.0.81",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",